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
142 guint probe_list_cookie;
152 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
157 GstPadProbeInfo *info;
164 static void gst_pad_dispose (GObject * object);
165 static void gst_pad_finalize (GObject * object);
166 static void gst_pad_set_property (GObject * object, guint prop_id,
167 const GValue * value, GParamSpec * pspec);
168 static void gst_pad_get_property (GObject * object, guint prop_id,
169 GValue * value, GParamSpec * pspec);
171 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
172 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
173 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
174 GstObject * parent, GstBufferList * list);
176 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
177 GstEvent * event, GstPadProbeType type);
178 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
179 GstEvent * event, GstPadProbeType type);
181 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
183 static GParamSpec *pspec_caps = NULL;
185 /* quarks for probe signals */
186 static GQuark buffer_quark;
187 static GQuark buffer_list_quark;
188 static GQuark event_quark;
197 static GstFlowQuarks flow_quarks[] = {
198 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
199 {GST_FLOW_OK, "ok", 0},
200 {GST_FLOW_NOT_LINKED, "not-linked", 0},
201 {GST_FLOW_FLUSHING, "flushing", 0},
202 {GST_FLOW_EOS, "eos", 0},
203 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
204 {GST_FLOW_ERROR, "error", 0},
205 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
206 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
211 * @ret: a #GstFlowReturn to get the name of.
213 * Gets a string representing the given flow return.
215 * Returns: a static string with the name of the flow return.
218 gst_flow_get_name (GstFlowReturn ret)
222 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
224 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
225 if (ret == flow_quarks[i].ret)
226 return flow_quarks[i].name;
233 * @ret: a #GstFlowReturn to get the quark of.
235 * Get the unique quark for the given GstFlowReturn.
237 * Returns: the quark associated with the flow return or 0 if an
238 * invalid return was specified.
241 gst_flow_to_quark (GstFlowReturn ret)
245 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
247 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
248 if (ret == flow_quarks[i].ret)
249 return flow_quarks[i].quark;
258 buffer_quark = g_quark_from_static_string ("buffer"); \
259 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
260 event_quark = g_quark_from_static_string ("event"); \
262 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
263 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
266 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
267 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
270 #define gst_pad_parent_class parent_class
271 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
274 gst_pad_class_init (GstPadClass * klass)
276 GObjectClass *gobject_class;
277 GstObjectClass *gstobject_class;
279 gobject_class = G_OBJECT_CLASS (klass);
280 gstobject_class = GST_OBJECT_CLASS (klass);
282 g_type_class_add_private (klass, sizeof (GstPadPrivate));
284 gobject_class->dispose = gst_pad_dispose;
285 gobject_class->finalize = gst_pad_finalize;
286 gobject_class->set_property = gst_pad_set_property;
287 gobject_class->get_property = gst_pad_get_property;
291 * @pad: the pad that emitted the signal
292 * @peer: the peer pad that has been connected
294 * Signals that a pad has been linked to the peer pad.
296 gst_pad_signals[PAD_LINKED] =
297 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
298 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
299 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
302 * @pad: the pad that emitted the signal
303 * @peer: the peer pad that has been disconnected
305 * Signals that a pad has been unlinked from the peer pad.
307 gst_pad_signals[PAD_UNLINKED] =
308 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
309 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
310 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
312 pspec_caps = g_param_spec_boxed ("caps", "Caps",
313 "The capabilities of the pad", GST_TYPE_CAPS,
314 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
315 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
317 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
318 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
319 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
320 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
322 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
323 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
324 g_param_spec_object ("template", "Template",
325 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
326 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
328 gstobject_class->path_string_separator = ".";
330 /* Register common function pointer descriptions */
331 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
332 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
333 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
334 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
335 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
339 gst_pad_init (GstPad * pad)
341 pad->priv = GST_PAD_GET_PRIVATE (pad);
343 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
345 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
346 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
347 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
348 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
349 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
351 GST_PAD_SET_FLUSHING (pad);
353 g_rec_mutex_init (&pad->stream_rec_lock);
355 g_cond_init (&pad->block_cond);
357 g_hook_list_init (&pad->probes, sizeof (GstProbe));
359 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
360 pad->priv->events_cookie = 0;
361 pad->priv->last_cookie = -1;
364 /* called when setting the pad inactive. It removes all sticky events from
365 * the pad. must be called with object lock */
367 remove_events (GstPad * pad)
372 events = pad->priv->events;
375 for (i = 0; i < len; i++) {
376 PadEvent *ev = &g_array_index (events, PadEvent, i);
377 GstEvent *event = ev->event;
381 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS) {
382 GST_OBJECT_UNLOCK (pad);
384 GST_DEBUG_OBJECT (pad, "notify caps");
385 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
387 GST_OBJECT_LOCK (pad);
389 gst_event_unref (event);
391 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
392 g_array_set_size (events, 0);
393 pad->priv->events_cookie++;
396 /* should be called with object lock */
398 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
404 events = pad->priv->events;
407 for (i = 0; i < len; i++) {
408 ev = &g_array_index (events, PadEvent, i);
409 if (ev->event == NULL)
412 if (GST_EVENT_TYPE (ev->event) == type) {
423 /* should be called with OBJECT lock */
425 find_event (GstPad * pad, GstEvent * event)
431 events = pad->priv->events;
434 for (i = 0; i < len; i++) {
435 ev = &g_array_index (events, PadEvent, i);
436 if (event == ev->event)
444 /* should be called with OBJECT lock */
446 remove_event_by_type (GstPad * pad, GstEventType type)
452 events = pad->priv->events;
457 ev = &g_array_index (events, PadEvent, i);
458 if (ev->event == NULL)
461 if (GST_EVENT_TYPE (ev->event) != type)
464 gst_event_unref (ev->event);
465 g_array_remove_index (events, i);
467 pad->priv->events_cookie++;
475 /* check all events on srcpad against those on sinkpad. All events that are not
476 * on sinkpad are marked as received=FALSE and the PENDING_EVENTS is set on the
477 * srcpad so that the events will be sent next time */
478 /* should be called with srcpad and sinkpad LOCKS */
480 schedule_events (GstPad * srcpad, GstPad * sinkpad)
485 gboolean pending = FALSE;
487 events = srcpad->priv->events;
490 for (i = 0; i < len; i++) {
491 ev = &g_array_index (events, PadEvent, i);
492 if (ev->event == NULL)
495 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
496 ev->received = FALSE;
501 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
504 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
507 /* should be called with pad LOCK */
509 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
516 events = pad->priv->events;
519 cookie = pad->priv->events_cookie;
523 PadEvent *ev, ev_ret;
525 ev = &g_array_index (events, PadEvent, i);
526 if (G_UNLIKELY (ev->event == NULL))
529 /* take aditional ref, func might release the lock */
530 ev_ret.event = gst_event_ref (ev->event);
531 ev_ret.received = ev->received;
533 ret = func (pad, &ev_ret, user_data);
535 /* recheck the cookie, lock might have been released and the list could have
537 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
538 if (G_LIKELY (ev_ret.event))
539 gst_event_unref (ev_ret.event);
543 /* store the received state */
544 ev->received = ev_ret.received;
546 /* if the event changed, we need to do something */
547 if (G_UNLIKELY (ev->event != ev_ret.event)) {
548 if (G_UNLIKELY (ev_ret.event == NULL)) {
549 /* function unreffed and set the event to NULL, remove it */
550 g_array_remove_index (events, i);
552 cookie = ++pad->priv->events_cookie;
555 /* function gave a new event for us */
556 gst_event_take (&ev->event, ev_ret.event);
559 /* just unref, nothing changed */
560 gst_event_unref (ev_ret.event);
569 /* should be called with LOCK */
571 apply_pad_offset (GstPad * pad, GstEvent * event)
573 /* check if we need to adjust the segment */
574 if (pad->offset != 0) {
577 /* copy segment values */
578 gst_event_copy_segment (event, &segment);
579 gst_event_unref (event);
581 /* adjust and make a new event with the offset applied */
582 segment.base += pad->offset;
583 event = gst_event_new_segment (&segment);
588 /* should be called with the OBJECT_LOCK */
590 get_pad_caps (GstPad * pad)
592 GstCaps *caps = NULL;
595 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
597 gst_event_parse_caps (ev->event, &caps);
603 gst_pad_dispose (GObject * object)
605 GstPad *pad = GST_PAD_CAST (object);
608 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
610 /* unlink the peer pad */
611 if ((peer = gst_pad_get_peer (pad))) {
612 /* window for MT unsafeness, someone else could unlink here
613 * and then we call unlink with wrong pads. The unlink
614 * function would catch this and safely return failed. */
615 if (GST_PAD_IS_SRC (pad))
616 gst_pad_unlink (pad, peer);
618 gst_pad_unlink (peer, pad);
620 gst_object_unref (peer);
623 gst_pad_set_pad_template (pad, NULL);
625 GST_OBJECT_LOCK (pad);
627 GST_OBJECT_UNLOCK (pad);
629 g_hook_list_clear (&pad->probes);
631 G_OBJECT_CLASS (parent_class)->dispose (object);
635 gst_pad_finalize (GObject * object)
637 GstPad *pad = GST_PAD_CAST (object);
640 /* in case the task is still around, clean it up */
641 if ((task = GST_PAD_TASK (pad))) {
642 gst_task_join (task);
643 GST_PAD_TASK (pad) = NULL;
644 gst_object_unref (task);
647 if (pad->activatenotify)
648 pad->activatenotify (pad->activatedata);
649 if (pad->activatemodenotify)
650 pad->activatemodenotify (pad->activatemodedata);
652 pad->linknotify (pad->linkdata);
653 if (pad->unlinknotify)
654 pad->unlinknotify (pad->unlinkdata);
655 if (pad->chainnotify)
656 pad->chainnotify (pad->chaindata);
657 if (pad->chainlistnotify)
658 pad->chainlistnotify (pad->chainlistdata);
659 if (pad->getrangenotify)
660 pad->getrangenotify (pad->getrangedata);
661 if (pad->eventnotify)
662 pad->eventnotify (pad->eventdata);
663 if (pad->querynotify)
664 pad->querynotify (pad->querydata);
665 if (pad->iterintlinknotify)
666 pad->iterintlinknotify (pad->iterintlinkdata);
668 g_rec_mutex_clear (&pad->stream_rec_lock);
669 g_cond_clear (&pad->block_cond);
670 g_array_free (pad->priv->events, TRUE);
672 G_OBJECT_CLASS (parent_class)->finalize (object);
676 gst_pad_set_property (GObject * object, guint prop_id,
677 const GValue * value, GParamSpec * pspec)
679 g_return_if_fail (GST_IS_PAD (object));
682 case PAD_PROP_DIRECTION:
683 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
685 case PAD_PROP_TEMPLATE:
686 gst_pad_set_pad_template (GST_PAD_CAST (object),
687 (GstPadTemplate *) g_value_get_object (value));
690 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
696 gst_pad_get_property (GObject * object, guint prop_id,
697 GValue * value, GParamSpec * pspec)
699 g_return_if_fail (GST_IS_PAD (object));
703 GST_OBJECT_LOCK (object);
704 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
705 GST_OBJECT_UNLOCK (object);
707 case PAD_PROP_DIRECTION:
708 g_value_set_enum (value, GST_PAD_DIRECTION (object));
710 case PAD_PROP_TEMPLATE:
711 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
714 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
721 * @name: the name of the new pad.
722 * @direction: the #GstPadDirection of the pad.
724 * Creates a new pad with the given name in the given direction.
725 * If name is NULL, a guaranteed unique name (across all pads)
727 * This function makes a copy of the name so you can safely free the name.
729 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
734 gst_pad_new (const gchar * name, GstPadDirection direction)
736 return g_object_new (GST_TYPE_PAD,
737 "name", name, "direction", direction, NULL);
741 * gst_pad_new_from_template:
742 * @templ: the pad template to use
743 * @name: the name of the element
745 * Creates a new pad with the given name from the given template.
746 * If name is NULL, a guaranteed unique name (across all pads)
748 * This function makes a copy of the name so you can safely free the name.
750 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
753 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
755 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
757 return g_object_new (GST_TYPE_PAD,
758 "name", name, "direction", templ->direction, "template", templ, NULL);
762 * gst_pad_new_from_static_template:
763 * @templ: the #GstStaticPadTemplate to use
764 * @name: the name of the element
766 * Creates a new pad with the given name from the given static template.
767 * If name is NULL, a guaranteed unique name (across all pads)
769 * This function makes a copy of the name so you can safely free the name.
771 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
774 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
778 GstPadTemplate *template;
780 template = gst_static_pad_template_get (templ);
781 pad = gst_pad_new_from_template (template, name);
782 gst_object_unref (template);
786 #define ACQUIRE_PARENT(pad, parent, label) \
788 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
789 gst_object_ref (parent); \
790 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
794 #define RELEASE_PARENT(parent) \
796 if (G_LIKELY (parent)) \
797 gst_object_unref (parent); \
801 * gst_pad_get_direction:
802 * @pad: a #GstPad to get the direction of.
804 * Gets the direction of the pad. The direction of the pad is
805 * decided at construction time so this function does not take
808 * Returns: the #GstPadDirection of the pad.
813 gst_pad_get_direction (GstPad * pad)
815 GstPadDirection result;
817 /* PAD_UNKNOWN is a little silly but we need some sort of
818 * error return value */
819 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
821 result = GST_PAD_DIRECTION (pad);
827 gst_pad_activate_default (GstPad * pad, GstObject * parent)
829 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
833 * gst_pad_mode_get_name:
834 * @mode: the pad mode
836 * Return the name of a pad mode, for use in debug messages mostly.
838 * Returns: short mnemonic for pad mode @mode
841 gst_pad_mode_get_name (GstPadMode mode)
844 case GST_PAD_MODE_NONE:
846 case GST_PAD_MODE_PUSH:
848 case GST_PAD_MODE_PULL:
857 pre_activate (GstPad * pad, GstPadMode new_mode)
860 case GST_PAD_MODE_NONE:
861 GST_OBJECT_LOCK (pad);
862 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
863 GST_PAD_SET_FLUSHING (pad);
864 GST_PAD_MODE (pad) = new_mode;
865 /* unlock blocked pads so element can resume and stop */
866 GST_PAD_BLOCK_BROADCAST (pad);
867 GST_OBJECT_UNLOCK (pad);
869 case GST_PAD_MODE_PUSH:
870 case GST_PAD_MODE_PULL:
871 GST_OBJECT_LOCK (pad);
872 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
873 gst_pad_mode_get_name (new_mode));
874 GST_PAD_UNSET_FLUSHING (pad);
875 GST_PAD_MODE (pad) = new_mode;
876 if (GST_PAD_IS_SINK (pad)) {
878 /* make sure the peer src pad sends us all events */
879 if ((peer = GST_PAD_PEER (pad))) {
880 gst_object_ref (peer);
881 GST_OBJECT_UNLOCK (pad);
883 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
884 GST_DEBUG_PAD_NAME (peer));
886 GST_OBJECT_LOCK (peer);
887 schedule_events (peer, NULL);
888 GST_OBJECT_UNLOCK (peer);
890 gst_object_unref (peer);
892 GST_OBJECT_UNLOCK (pad);
895 GST_OBJECT_UNLOCK (pad);
902 post_activate (GstPad * pad, GstPadMode new_mode)
905 case GST_PAD_MODE_NONE:
906 /* ensures that streaming stops */
907 GST_PAD_STREAM_LOCK (pad);
908 GST_DEBUG_OBJECT (pad, "stopped streaming");
909 GST_OBJECT_LOCK (pad);
911 GST_OBJECT_UNLOCK (pad);
912 GST_PAD_STREAM_UNLOCK (pad);
914 case GST_PAD_MODE_PUSH:
915 case GST_PAD_MODE_PULL:
922 * gst_pad_set_active:
923 * @pad: the #GstPad to activate or deactivate.
924 * @active: whether or not the pad should be active.
926 * Activates or deactivates the given pad.
927 * Normally called from within core state change functions.
929 * If @active, makes sure the pad is active. If it is already active, either in
930 * push or pull mode, just return. Otherwise dispatches to the pad's activate
931 * function to perform the actual activation.
933 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
934 * and a FALSE argument.
936 * Returns: #TRUE if the operation was successful.
941 gst_pad_set_active (GstPad * pad, gboolean active)
945 gboolean ret = FALSE;
947 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
949 GST_OBJECT_LOCK (pad);
950 old = GST_PAD_MODE (pad);
951 ACQUIRE_PARENT (pad, parent, no_parent);
952 GST_OBJECT_UNLOCK (pad);
955 if (old == GST_PAD_MODE_NONE) {
956 GST_DEBUG_OBJECT (pad, "activating pad from none");
957 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
959 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
960 gst_pad_mode_get_name (old));
964 if (old == GST_PAD_MODE_NONE) {
965 GST_DEBUG_OBJECT (pad, "pad was inactive");
968 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
969 gst_pad_mode_get_name (old));
970 ret = gst_pad_activate_mode (pad, old, FALSE);
974 RELEASE_PARENT (parent);
976 if (G_UNLIKELY (!ret))
984 GST_DEBUG_OBJECT (pad, "no parent");
985 GST_OBJECT_UNLOCK (pad);
990 GST_OBJECT_LOCK (pad);
992 g_critical ("Failed to deactivate pad %s:%s, very bad",
993 GST_DEBUG_PAD_NAME (pad));
995 GST_WARNING_OBJECT (pad, "Failed to activate pad");
997 GST_OBJECT_UNLOCK (pad);
1003 * gst_pad_activate_mode:
1004 * @pad: the #GstPad to activate or deactivate.
1005 * @mode: the requested activation mode
1006 * @active: whether or not the pad should be active.
1008 * Activates or deactivates the given pad in @mode via dispatching to the
1009 * pad's activatemodefunc. For use from within pad activation functions only.
1011 * If you don't know what this is, you probably don't want to call it.
1013 * Returns: TRUE if the operation was successful.
1018 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1020 gboolean res = FALSE;
1022 GstPadMode old, new;
1023 GstPadDirection dir;
1026 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1028 GST_OBJECT_LOCK (pad);
1029 old = GST_PAD_MODE (pad);
1030 dir = GST_PAD_DIRECTION (pad);
1031 ACQUIRE_PARENT (pad, parent, no_parent);
1032 GST_OBJECT_UNLOCK (pad);
1034 new = active ? mode : GST_PAD_MODE_NONE;
1039 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1040 /* pad was activate in the wrong direction, deactivate it
1041 * and reactivate it in the requested mode */
1042 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1043 gst_pad_mode_get_name (old));
1045 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1046 goto deactivate_failed;
1050 case GST_PAD_MODE_PULL:
1052 if (dir == GST_PAD_SINK) {
1053 if ((peer = gst_pad_get_peer (pad))) {
1054 GST_DEBUG_OBJECT (pad, "calling peer");
1055 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1057 gst_object_unref (peer);
1059 /* there is no peer, this is only fatal when we activate. When we
1060 * deactivate, we must assume the application has unlinked the peer and
1061 * will deactivate it eventually. */
1065 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1068 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1069 goto failure; /* Can't activate pull on a src without a
1070 getrange function */
1078 /* Mark pad as needing reconfiguration */
1080 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1081 pre_activate (pad, new);
1083 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1084 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1088 /* can happen for sinks of passthrough elements */
1091 post_activate (pad, new);
1093 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1094 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1099 /* Clear sticky flags on deactivation */
1101 GST_OBJECT_LOCK (pad);
1102 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1103 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1104 GST_OBJECT_UNLOCK (pad);
1108 RELEASE_PARENT (parent);
1114 GST_DEBUG_OBJECT (pad, "no parent");
1115 GST_OBJECT_UNLOCK (pad);
1120 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1121 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1126 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1127 "failed to %s in switch to %s mode from %s mode",
1128 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1129 gst_pad_mode_get_name (old));
1134 GST_OBJECT_LOCK (peer);
1135 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1136 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1137 GST_OBJECT_UNLOCK (peer);
1138 gst_object_unref (peer);
1143 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1144 "pad in pull mode");
1149 GST_OBJECT_LOCK (pad);
1150 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1151 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1152 GST_PAD_SET_FLUSHING (pad);
1153 GST_PAD_MODE (pad) = old;
1154 GST_OBJECT_UNLOCK (pad);
1160 * gst_pad_is_active:
1161 * @pad: the #GstPad to query
1163 * Query if a pad is active
1165 * Returns: TRUE if the pad is active.
1170 gst_pad_is_active (GstPad * pad)
1172 gboolean result = FALSE;
1174 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1176 GST_OBJECT_LOCK (pad);
1177 result = GST_PAD_IS_ACTIVE (pad);
1178 GST_OBJECT_UNLOCK (pad);
1184 * gst_pad_add_probe:
1185 * @pad: the #GstPad to add the probe to
1186 * @mask: the probe mask
1187 * @callback: #GstPadProbeCallback that will be called with notifications of
1189 * @user_data: (closure): user data passed to the callback
1190 * @destroy_data: #GDestroyNotify for user_data
1192 * Be notified of different states of pads. The provided callback is called for
1193 * every state that matches @mask.
1195 * Returns: an id or 0 on error. The id can be used to remove the probe with
1196 * gst_pad_remove_probe().
1201 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1202 GstPadProbeCallback callback, gpointer user_data,
1203 GDestroyNotify destroy_data)
1208 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1209 g_return_val_if_fail (mask != 0, 0);
1211 GST_OBJECT_LOCK (pad);
1213 /* make a new probe */
1214 hook = g_hook_alloc (&pad->probes);
1216 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1219 /* when no contraints are given for the types, assume all types are
1221 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1222 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1223 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1224 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1226 /* store our flags and other fields */
1227 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1228 hook->func = callback;
1229 hook->data = user_data;
1230 hook->destroy = destroy_data;
1231 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1234 g_hook_prepend (&pad->probes, hook);
1236 /* incremenent cookie so that the new hook get's called */
1237 pad->priv->probe_list_cookie++;
1239 /* get the id of the hook, we return this and it can be used to remove the
1241 res = hook->hook_id;
1243 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1245 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1246 /* we have a block probe */
1248 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1249 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1250 "now %d blocking probes", pad->num_blocked);
1253 /* call the callback if we need to be called for idle callbacks */
1254 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1255 if (pad->priv->using > 0) {
1256 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1257 * flag above, the last thread to leave the push will do the callback. New
1258 * threads going into the push will block. */
1259 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1260 "pad is in use, delay idle callback");
1261 GST_OBJECT_UNLOCK (pad);
1263 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1265 /* the pad is idle now, we can signal the idle callback now */
1266 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1267 "pad is idle, trigger idle callback");
1268 GST_OBJECT_UNLOCK (pad);
1270 callback (pad, &info, user_data);
1273 GST_OBJECT_UNLOCK (pad);
1279 cleanup_hook (GstPad * pad, GHook * hook)
1281 GstPadProbeType type;
1283 if (!G_HOOK_IS_VALID (hook))
1286 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1288 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1289 /* unblock when we remove the last blocking probe */
1291 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1293 if (pad->num_blocked == 0) {
1294 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1295 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1296 GST_PAD_BLOCK_BROADCAST (pad);
1299 g_hook_destroy_link (&pad->probes, hook);
1304 * gst_pad_remove_probe:
1305 * @pad: the #GstPad with the probe
1306 * @id: the probe id to remove
1308 * Remove the probe with @id from @pad.
1313 gst_pad_remove_probe (GstPad * pad, gulong id)
1317 g_return_if_fail (GST_IS_PAD (pad));
1319 GST_OBJECT_LOCK (pad);
1321 hook = g_hook_get (&pad->probes, id);
1325 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1327 cleanup_hook (pad, hook);
1328 GST_OBJECT_UNLOCK (pad);
1334 GST_OBJECT_UNLOCK (pad);
1335 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1341 * gst_pad_is_blocked:
1342 * @pad: the #GstPad to query
1344 * Checks if the pad is blocked or not. This function returns the
1345 * last requested state of the pad. It is not certain that the pad
1346 * is actually blocking at this point (see gst_pad_is_blocking()).
1348 * Returns: TRUE if the pad is blocked.
1353 gst_pad_is_blocked (GstPad * pad)
1355 gboolean result = FALSE;
1357 g_return_val_if_fail (GST_IS_PAD (pad), result);
1359 GST_OBJECT_LOCK (pad);
1360 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1361 GST_OBJECT_UNLOCK (pad);
1367 * gst_pad_is_blocking:
1368 * @pad: the #GstPad to query
1370 * Checks if the pad is blocking or not. This is a guaranteed state
1371 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1373 * Returns: TRUE if the pad is blocking.
1378 gst_pad_is_blocking (GstPad * pad)
1380 gboolean result = FALSE;
1382 g_return_val_if_fail (GST_IS_PAD (pad), result);
1384 GST_OBJECT_LOCK (pad);
1385 /* the blocking flag is only valid if the pad is not flushing */
1386 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1387 GST_OBJECT_UNLOCK (pad);
1393 * gst_pad_needs_reconfigure:
1394 * @pad: the #GstPad to check
1396 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1397 * if the flag was set.
1399 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1402 gst_pad_needs_reconfigure (GstPad * pad)
1404 gboolean reconfigure;
1406 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1408 GST_OBJECT_LOCK (pad);
1409 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1410 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1411 GST_OBJECT_UNLOCK (pad);
1417 * gst_pad_check_reconfigure:
1418 * @pad: the #GstPad to check
1420 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1421 * if the flag was set.
1423 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1426 gst_pad_check_reconfigure (GstPad * pad)
1428 gboolean reconfigure;
1430 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1432 GST_OBJECT_LOCK (pad);
1433 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1435 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1436 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1438 GST_OBJECT_UNLOCK (pad);
1444 * gst_pad_mark_reconfigure:
1445 * @pad: the #GstPad to mark
1447 * Mark a pad for needing reconfiguration. The next call to
1448 * gst_pad_check_reconfigure() will return %TRUE after this call.
1451 gst_pad_mark_reconfigure (GstPad * pad)
1453 g_return_if_fail (GST_IS_PAD (pad));
1455 GST_OBJECT_LOCK (pad);
1456 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1457 GST_OBJECT_UNLOCK (pad);
1461 * gst_pad_set_activate_function:
1463 * @f: the #GstPadActivateFunction to set.
1465 * Calls gst_pad_set_activate_function_full() with NULL for the user_data and
1469 * gst_pad_set_activate_function_full:
1471 * @activate: the #GstPadActivateFunction to set.
1472 * @user_data: user_data passed to @notify
1473 * @notify: notify called when @activate will not be used anymore.
1475 * Sets the given activate function for @pad. The activate function will
1476 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1477 * Only makes sense to set on sink pads.
1479 * Call this function if your sink pad can start a pull-based task.
1482 gst_pad_set_activate_function_full (GstPad * pad,
1483 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1485 g_return_if_fail (GST_IS_PAD (pad));
1487 if (pad->activatenotify)
1488 pad->activatenotify (pad->activatedata);
1489 GST_PAD_ACTIVATEFUNC (pad) = activate;
1490 pad->activatedata = user_data;
1491 pad->activatenotify = notify;
1493 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1494 GST_DEBUG_FUNCPTR_NAME (activate));
1498 * gst_pad_set_activatemode_function:
1500 * @f: the #GstPadActivateModeFunction to set.
1502 * Calls gst_pad_set_activatemode_function_full() with NULL for the user_data and
1506 * gst_pad_set_activatemode_function_full:
1508 * @activatemode: the #GstPadActivateModeFunction to set.
1509 * @user_data: user_data passed to @notify
1510 * @notify: notify called when @activatemode will not be used anymore.
1512 * Sets the given activate_mode function for the pad. An activate_mode function
1513 * prepares the element for data passing.
1516 gst_pad_set_activatemode_function_full (GstPad * pad,
1517 GstPadActivateModeFunction activatemode, gpointer user_data,
1518 GDestroyNotify notify)
1520 g_return_if_fail (GST_IS_PAD (pad));
1522 if (pad->activatemodenotify)
1523 pad->activatemodenotify (pad->activatemodedata);
1524 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1525 pad->activatemodedata = user_data;
1526 pad->activatemodenotify = notify;
1528 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1529 GST_DEBUG_FUNCPTR_NAME (activatemode));
1533 * gst_pad_set_chain_function:
1534 * @p: a sink #GstPad.
1535 * @f: the #GstPadChainFunction to set.
1537 * Calls gst_pad_set_chain_function_full() with NULL for the user_data and
1541 * gst_pad_set_chain_function_full:
1542 * @pad: a sink #GstPad.
1543 * @chain: the #GstPadChainFunction to set.
1544 * @user_data: user_data passed to @notify
1545 * @notify: notify called when @chain will not be used anymore.
1547 * Sets the given chain function for the pad. The chain function is called to
1548 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1551 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1552 gpointer user_data, GDestroyNotify notify)
1554 g_return_if_fail (GST_IS_PAD (pad));
1555 g_return_if_fail (GST_PAD_IS_SINK (pad));
1557 if (pad->chainnotify)
1558 pad->chainnotify (pad->chaindata);
1559 GST_PAD_CHAINFUNC (pad) = chain;
1560 pad->chaindata = user_data;
1561 pad->chainnotify = notify;
1563 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1564 GST_DEBUG_FUNCPTR_NAME (chain));
1568 * gst_pad_set_chain_list_function:
1569 * @p: a sink #GstPad.
1570 * @f: the #GstPadChainListFunction to set.
1572 * Calls gst_pad_set_chain_list_function_full() with NULL for the user_data and
1576 * gst_pad_set_chain_list_function_full:
1577 * @pad: a sink #GstPad.
1578 * @chainlist: the #GstPadChainListFunction to set.
1579 * @user_data: user_data passed to @notify
1580 * @notify: notify called when @chainlist will not be used anymore.
1582 * Sets the given chain list function for the pad. The chainlist function is
1583 * called to process a #GstBufferList input buffer list. See
1584 * #GstPadChainListFunction for more details.
1587 gst_pad_set_chain_list_function_full (GstPad * pad,
1588 GstPadChainListFunction chainlist, gpointer user_data,
1589 GDestroyNotify notify)
1591 g_return_if_fail (GST_IS_PAD (pad));
1592 g_return_if_fail (GST_PAD_IS_SINK (pad));
1594 if (pad->chainlistnotify)
1595 pad->chainlistnotify (pad->chainlistdata);
1596 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1597 pad->chainlistdata = user_data;
1598 pad->chainlistnotify = notify;
1600 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1601 GST_DEBUG_FUNCPTR_NAME (chainlist));
1605 * gst_pad_set_getrange_function:
1606 * @p: a source #GstPad.
1607 * @f: the #GstPadGetRangeFunction to set.
1609 * Calls gst_pad_set_getrange_function_full() with NULL for the user_data and
1613 * gst_pad_set_getrange_function_full:
1614 * @pad: a source #GstPad.
1615 * @get: the #GstPadGetRangeFunction to set.
1616 * @user_data: user_data passed to @notify
1617 * @notify: notify called when @get will not be used anymore.
1619 * Sets the given getrange function for the pad. The getrange function is
1620 * called to produce a new #GstBuffer to start the processing pipeline. see
1621 * #GstPadGetRangeFunction for a description of the getrange function.
1624 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1625 gpointer user_data, GDestroyNotify notify)
1627 g_return_if_fail (GST_IS_PAD (pad));
1628 g_return_if_fail (GST_PAD_IS_SRC (pad));
1630 if (pad->getrangenotify)
1631 pad->getrangenotify (pad->getrangedata);
1632 GST_PAD_GETRANGEFUNC (pad) = get;
1633 pad->getrangedata = user_data;
1634 pad->getrangenotify = notify;
1636 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1637 GST_DEBUG_FUNCPTR_NAME (get));
1641 * gst_pad_set_event_function:
1642 * @p: a #GstPad of either direction.
1643 * @f: the #GstPadEventFunction to set.
1645 * Calls gst_pad_set_event_function_full() with NULL for the user_data and
1649 * gst_pad_set_event_function_full:
1650 * @pad: a #GstPad of either direction.
1651 * @event: the #GstPadEventFunction to set.
1652 * @user_data: user_data passed to @notify
1653 * @notify: notify called when @event will not be used anymore.
1655 * Sets the given event handler for the pad.
1658 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1659 gpointer user_data, GDestroyNotify notify)
1661 g_return_if_fail (GST_IS_PAD (pad));
1663 if (pad->eventnotify)
1664 pad->eventnotify (pad->eventdata);
1665 GST_PAD_EVENTFUNC (pad) = event;
1666 pad->eventdata = user_data;
1667 pad->eventnotify = notify;
1669 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1670 GST_DEBUG_FUNCPTR_NAME (event));
1674 * gst_pad_set_query_function:
1675 * @p: a #GstPad of either direction.
1676 * @f: the #GstPadQueryFunction to set.
1678 * Calls gst_pad_set_query_function_full() with NULL for the user_data and
1682 * gst_pad_set_query_function_full:
1683 * @pad: a #GstPad of either direction.
1684 * @query: the #GstPadQueryFunction to set.
1685 * @user_data: user_data passed to @notify
1686 * @notify: notify called when @query will not be used anymore.
1688 * Set the given query function for the pad.
1691 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1692 gpointer user_data, GDestroyNotify notify)
1694 g_return_if_fail (GST_IS_PAD (pad));
1696 if (pad->querynotify)
1697 pad->querynotify (pad->querydata);
1698 GST_PAD_QUERYFUNC (pad) = query;
1699 pad->querydata = user_data;
1700 pad->querynotify = notify;
1702 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1703 GST_DEBUG_FUNCPTR_NAME (query));
1707 * gst_pad_set_iterate_internal_links_function:
1708 * @p: a #GstPad of either direction.
1709 * @f: the #GstPadIterIntLinkFunction to set.
1711 * Calls gst_pad_set_iterate_internal_links_function_full() with NULL
1712 * for the user_data and notify.
1715 * gst_pad_set_iterate_internal_links_function_full:
1716 * @pad: a #GstPad of either direction.
1717 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1718 * @user_data: user_data passed to @notify
1719 * @notify: notify called when @iterintlink will not be used anymore.
1721 * Sets the given internal link iterator function for the pad.
1724 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1725 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1726 GDestroyNotify notify)
1728 g_return_if_fail (GST_IS_PAD (pad));
1730 if (pad->iterintlinknotify)
1731 pad->iterintlinknotify (pad->iterintlinkdata);
1732 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1733 pad->iterintlinkdata = user_data;
1734 pad->iterintlinknotify = notify;
1736 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1737 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1741 * gst_pad_set_link_function:
1743 * @f: the #GstPadLinkFunction to set.
1745 * Calls gst_pad_set_link_function_full() with NULL
1746 * for the user_data and notify.
1749 * gst_pad_set_link_function_full:
1751 * @link: the #GstPadLinkFunction to set.
1752 * @user_data: user_data passed to @notify
1753 * @notify: notify called when @link will not be used anymore.
1755 * Sets the given link function for the pad. It will be called when
1756 * the pad is linked with another pad.
1758 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1761 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1762 * cannot be made for some reason.
1764 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1765 * of the peer sink pad, if present.
1768 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1769 gpointer user_data, GDestroyNotify notify)
1771 g_return_if_fail (GST_IS_PAD (pad));
1773 if (pad->linknotify)
1774 pad->linknotify (pad->linkdata);
1775 GST_PAD_LINKFUNC (pad) = link;
1776 pad->linkdata = user_data;
1777 pad->linknotify = notify;
1779 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1780 GST_DEBUG_FUNCPTR_NAME (link));
1784 * gst_pad_set_unlink_function:
1786 * @f: the #GstPadUnlinkFunction to set.
1788 * Calls gst_pad_set_unlink_function_full() with NULL
1789 * for the user_data and notify.
1792 * gst_pad_set_unlink_function_full:
1794 * @unlink: the #GstPadUnlinkFunction to set.
1795 * @user_data: user_data passed to @notify
1796 * @notify: notify called when @unlink will not be used anymore.
1798 * Sets the given unlink function for the pad. It will be called
1799 * when the pad is unlinked.
1802 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1803 gpointer user_data, GDestroyNotify notify)
1805 g_return_if_fail (GST_IS_PAD (pad));
1807 if (pad->unlinknotify)
1808 pad->unlinknotify (pad->unlinkdata);
1809 GST_PAD_UNLINKFUNC (pad) = unlink;
1810 pad->unlinkdata = user_data;
1811 pad->unlinknotify = notify;
1813 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1814 GST_DEBUG_FUNCPTR_NAME (unlink));
1819 * @srcpad: the source #GstPad to unlink.
1820 * @sinkpad: the sink #GstPad to unlink.
1822 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1823 * signal on both pads.
1825 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1826 * the pads were not linked together.
1831 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1833 gboolean result = FALSE;
1834 GstElement *parent = NULL;
1836 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1837 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1838 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1839 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1841 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1842 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1843 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1845 /* We need to notify the parent before taking any pad locks as the bin in
1846 * question might be waiting for a lock on the pad while holding its lock
1847 * that our message will try to take. */
1848 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1849 if (GST_IS_ELEMENT (parent)) {
1850 gst_element_post_message (parent,
1851 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1852 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1854 gst_object_unref (parent);
1859 GST_OBJECT_LOCK (srcpad);
1860 GST_OBJECT_LOCK (sinkpad);
1862 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1863 goto not_linked_together;
1865 if (GST_PAD_UNLINKFUNC (srcpad)) {
1866 GstObject *tmpparent;
1868 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1870 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1871 RELEASE_PARENT (tmpparent);
1874 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1875 GstObject *tmpparent;
1877 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1879 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1880 RELEASE_PARENT (tmpparent);
1884 /* first clear peers */
1885 GST_PAD_PEER (srcpad) = NULL;
1886 GST_PAD_PEER (sinkpad) = NULL;
1888 GST_OBJECT_UNLOCK (sinkpad);
1889 GST_OBJECT_UNLOCK (srcpad);
1891 /* fire off a signal to each of the pads telling them
1892 * that they've been unlinked */
1893 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1894 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1896 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1897 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1902 if (parent != NULL) {
1903 gst_element_post_message (parent,
1904 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1905 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1906 gst_object_unref (parent);
1911 not_linked_together:
1913 /* we do not emit a warning in this case because unlinking cannot
1914 * be made MT safe.*/
1915 GST_OBJECT_UNLOCK (sinkpad);
1916 GST_OBJECT_UNLOCK (srcpad);
1922 * gst_pad_is_linked:
1923 * @pad: pad to check
1925 * Checks if a @pad is linked to another pad or not.
1927 * Returns: TRUE if the pad is linked, FALSE otherwise.
1932 gst_pad_is_linked (GstPad * pad)
1936 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1938 GST_OBJECT_LOCK (pad);
1939 result = (GST_PAD_PEER (pad) != NULL);
1940 GST_OBJECT_UNLOCK (pad);
1945 /* get the caps from both pads and see if the intersection
1948 * This function should be called with the pad LOCK on both
1952 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1953 GstPadLinkCheck flags)
1955 GstCaps *srccaps = NULL;
1956 GstCaps *sinkcaps = NULL;
1957 gboolean compatible = FALSE;
1959 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1962 /* Doing the expensive caps checking takes priority over only checking the template caps */
1963 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1964 GST_OBJECT_UNLOCK (sink);
1965 GST_OBJECT_UNLOCK (src);
1967 srccaps = gst_pad_query_caps (src, NULL);
1968 sinkcaps = gst_pad_query_caps (sink, NULL);
1970 GST_OBJECT_LOCK (src);
1971 GST_OBJECT_LOCK (sink);
1973 /* If one of the two pads doesn't have a template, consider the intersection
1975 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
1976 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
1980 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
1982 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
1985 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
1987 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
1990 /* if we have caps on both pads we can check the intersection. If one
1991 * of the caps is NULL, we return TRUE. */
1992 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1994 gst_caps_unref (srccaps);
1996 gst_caps_unref (sinkcaps);
2000 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2001 gst_caps_unref (srccaps);
2002 gst_caps_unref (sinkcaps);
2005 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2006 (compatible ? "" : "not"));
2011 /* check if the grandparents of both pads are the same.
2012 * This check is required so that we don't try to link
2013 * pads from elements in different bins without ghostpads.
2015 * The LOCK should be held on both pads
2018 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2020 GstObject *psrc, *psink;
2022 psrc = GST_OBJECT_PARENT (src);
2023 psink = GST_OBJECT_PARENT (sink);
2025 /* if one of the pads has no parent, we allow the link */
2026 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2029 /* only care about parents that are elements */
2030 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2031 goto no_element_parent;
2033 /* if the parents are the same, we have a loop */
2034 if (G_UNLIKELY (psrc == psink))
2037 /* if they both have a parent, we check the grandparents. We can not lock
2038 * the parent because we hold on the child (pad) and the locking order is
2039 * parent >> child. */
2040 psrc = GST_OBJECT_PARENT (psrc);
2041 psink = GST_OBJECT_PARENT (psink);
2043 /* if they have grandparents but they are not the same */
2044 if (G_UNLIKELY (psrc != psink))
2045 goto wrong_grandparents;
2052 GST_CAT_DEBUG (GST_CAT_CAPS,
2053 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2054 GST_PTR_FORMAT, psrc, psink);
2059 GST_CAT_DEBUG (GST_CAT_CAPS,
2060 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2061 GST_PTR_FORMAT, psrc, psink);
2066 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2072 GST_CAT_DEBUG (GST_CAT_CAPS,
2073 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2074 GST_PTR_FORMAT, psrc, psink);
2079 /* FIXME leftover from an attempt at refactoring... */
2080 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2081 * the two pads will be locked in the srcpad, sinkpad order. */
2082 static GstPadLinkReturn
2083 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2085 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2086 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2088 GST_OBJECT_LOCK (srcpad);
2090 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2091 goto src_was_linked;
2093 GST_OBJECT_LOCK (sinkpad);
2095 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2096 goto sink_was_linked;
2098 /* check hierarchy, pads can only be linked if the grandparents
2100 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2101 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2102 goto wrong_hierarchy;
2104 /* check pad caps for non-empty intersection */
2105 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2108 /* FIXME check pad scheduling for non-empty intersection */
2110 return GST_PAD_LINK_OK;
2114 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2115 GST_DEBUG_PAD_NAME (srcpad),
2116 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2117 /* we do not emit a warning in this case because unlinking cannot
2118 * be made MT safe.*/
2119 GST_OBJECT_UNLOCK (srcpad);
2120 return GST_PAD_LINK_WAS_LINKED;
2124 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2125 GST_DEBUG_PAD_NAME (sinkpad),
2126 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2127 /* we do not emit a warning in this case because unlinking cannot
2128 * be made MT safe.*/
2129 GST_OBJECT_UNLOCK (sinkpad);
2130 GST_OBJECT_UNLOCK (srcpad);
2131 return GST_PAD_LINK_WAS_LINKED;
2135 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2136 GST_OBJECT_UNLOCK (sinkpad);
2137 GST_OBJECT_UNLOCK (srcpad);
2138 return GST_PAD_LINK_WRONG_HIERARCHY;
2142 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2143 GST_OBJECT_UNLOCK (sinkpad);
2144 GST_OBJECT_UNLOCK (srcpad);
2145 return GST_PAD_LINK_NOFORMAT;
2151 * @srcpad: the source #GstPad.
2152 * @sinkpad: the sink #GstPad.
2154 * Checks if the source pad and the sink pad are compatible so they can be
2157 * Returns: TRUE if the pads can be linked.
2160 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2162 GstPadLinkReturn result;
2164 /* generic checks */
2165 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2166 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2168 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2169 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2171 /* gst_pad_link_prepare does everything for us, we only release the locks
2172 * on the pads that it gets us. If this function returns !OK the locks are not
2174 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2175 if (result != GST_PAD_LINK_OK)
2178 GST_OBJECT_UNLOCK (srcpad);
2179 GST_OBJECT_UNLOCK (sinkpad);
2182 return result == GST_PAD_LINK_OK;
2186 * gst_pad_link_full:
2187 * @srcpad: the source #GstPad to link.
2188 * @sinkpad: the sink #GstPad to link.
2189 * @flags: the checks to validate when linking
2191 * Links the source pad and the sink pad.
2193 * This variant of #gst_pad_link provides a more granular control on the
2194 * checks being done when linking. While providing some considerable speedups
2195 * the caller of this method must be aware that wrong usage of those flags
2196 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2197 * for more information.
2201 * Returns: A result code indicating if the connection worked or
2205 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2207 GstPadLinkReturn result;
2209 GstPadLinkFunction srcfunc, sinkfunc;
2211 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2212 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2213 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2214 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2215 GST_PAD_LINK_WRONG_DIRECTION);
2217 /* Notify the parent early. See gst_pad_unlink for details. */
2218 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2219 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2220 gst_element_post_message (parent,
2221 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2222 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2224 gst_object_unref (parent);
2229 /* prepare will also lock the two pads */
2230 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2232 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2235 /* must set peers before calling the link function */
2236 GST_PAD_PEER (srcpad) = sinkpad;
2237 GST_PAD_PEER (sinkpad) = srcpad;
2239 /* check events, when something is different, mark pending */
2240 schedule_events (srcpad, sinkpad);
2242 /* get the link functions */
2243 srcfunc = GST_PAD_LINKFUNC (srcpad);
2244 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2246 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2247 /* custom link functions, execute them */
2248 GST_OBJECT_UNLOCK (sinkpad);
2249 GST_OBJECT_UNLOCK (srcpad);
2252 GstObject *tmpparent;
2254 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2255 /* this one will call the peer link function */
2256 result = srcfunc (srcpad, tmpparent, sinkpad);
2257 RELEASE_PARENT (tmpparent);
2258 } else if (sinkfunc) {
2259 GstObject *tmpparent;
2261 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2262 /* if no source link function, we need to call the sink link
2263 * function ourselves. */
2264 result = sinkfunc (sinkpad, tmpparent, srcpad);
2265 RELEASE_PARENT (tmpparent);
2269 GST_OBJECT_LOCK (srcpad);
2270 GST_OBJECT_LOCK (sinkpad);
2272 /* we released the lock, check if the same pads are linked still */
2273 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2274 goto concurrent_link;
2276 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2279 GST_OBJECT_UNLOCK (sinkpad);
2280 GST_OBJECT_UNLOCK (srcpad);
2282 /* fire off a signal to each of the pads telling them
2283 * that they've been linked */
2284 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2285 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2287 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2288 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2290 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2293 if (G_LIKELY (parent)) {
2294 gst_element_post_message (parent,
2295 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2296 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2297 gst_object_unref (parent);
2305 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2306 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2307 GST_OBJECT_UNLOCK (sinkpad);
2308 GST_OBJECT_UNLOCK (srcpad);
2310 /* The other link operation succeeded first */
2311 result = GST_PAD_LINK_WAS_LINKED;
2316 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2317 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2319 GST_PAD_PEER (srcpad) = NULL;
2320 GST_PAD_PEER (sinkpad) = NULL;
2322 GST_OBJECT_UNLOCK (sinkpad);
2323 GST_OBJECT_UNLOCK (srcpad);
2331 * @srcpad: the source #GstPad to link.
2332 * @sinkpad: the sink #GstPad to link.
2334 * Links the source pad and the sink pad.
2336 * Returns: A result code indicating if the connection worked or
2342 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2344 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2348 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2350 GstPadTemplate **template_p;
2352 /* this function would need checks if it weren't static */
2354 GST_OBJECT_LOCK (pad);
2355 template_p = &pad->padtemplate;
2356 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2357 GST_OBJECT_UNLOCK (pad);
2360 gst_pad_template_pad_created (templ, pad);
2364 * gst_pad_get_pad_template:
2367 * Gets the template for @pad.
2369 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2370 * instantiated, or %NULL if this pad has no template. Unref after
2374 gst_pad_get_pad_template (GstPad * pad)
2376 GstPadTemplate *templ;
2378 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2380 templ = GST_PAD_PAD_TEMPLATE (pad);
2382 return (templ ? gst_object_ref (templ) : NULL);
2386 * gst_pad_has_current_caps:
2387 * @pad: a #GstPad to check
2389 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2391 * Returns: TRUE when @pad has caps associated with it.
2394 gst_pad_has_current_caps (GstPad * pad)
2399 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2401 GST_OBJECT_LOCK (pad);
2402 caps = get_pad_caps (pad);
2403 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2404 "check current pad caps %" GST_PTR_FORMAT, caps);
2405 result = (caps != NULL);
2406 GST_OBJECT_UNLOCK (pad);
2412 * gst_pad_get_current_caps:
2413 * @pad: a #GstPad to get the current capabilities of.
2415 * Gets the capabilities currently configured on @pad with the last
2416 * #GST_EVENT_CAPS event.
2418 * Returns: the current caps of the pad with incremented ref-count.
2421 gst_pad_get_current_caps (GstPad * pad)
2425 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2427 GST_OBJECT_LOCK (pad);
2428 if ((result = get_pad_caps (pad)))
2429 gst_caps_ref (result);
2430 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2431 "get current pad caps %" GST_PTR_FORMAT, result);
2432 GST_OBJECT_UNLOCK (pad);
2438 * gst_pad_get_pad_template_caps:
2439 * @pad: a #GstPad to get the template capabilities from.
2441 * Gets the capabilities for @pad's template.
2443 * Returns: (transfer full): the #GstCaps of this pad template.
2444 * Unref after usage.
2447 gst_pad_get_pad_template_caps (GstPad * pad)
2449 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2451 if (GST_PAD_PAD_TEMPLATE (pad))
2452 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2454 return gst_caps_ref (GST_CAPS_ANY);
2459 * @pad: a #GstPad to get the peer of.
2461 * Gets the peer of @pad. This function refs the peer pad so
2462 * you need to unref it after use.
2464 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2469 gst_pad_get_peer (GstPad * pad)
2473 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2475 GST_OBJECT_LOCK (pad);
2476 result = GST_PAD_PEER (pad);
2478 gst_object_ref (result);
2479 GST_OBJECT_UNLOCK (pad);
2485 * gst_pad_get_allowed_caps:
2488 * Gets the capabilities of the allowed media types that can flow through
2489 * @pad and its peer.
2491 * The allowed capabilities is calculated as the intersection of the results of
2492 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2493 * on the resulting caps.
2495 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2496 * caps when you no longer need it. This function returns NULL when @pad
2502 gst_pad_get_allowed_caps (GstPad * pad)
2508 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2510 GST_OBJECT_LOCK (pad);
2511 peer = GST_PAD_PEER (pad);
2512 if (G_UNLIKELY (peer == NULL))
2515 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2517 gst_object_ref (peer);
2518 GST_OBJECT_UNLOCK (pad);
2519 mycaps = gst_pad_query_caps (pad, NULL);
2521 caps = gst_pad_query_caps (peer, mycaps);
2522 gst_object_unref (peer);
2524 gst_caps_unref (mycaps);
2526 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2533 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2534 GST_OBJECT_UNLOCK (pad);
2541 * gst_pad_iterate_internal_links_default:
2542 * @pad: the #GstPad to get the internal links of.
2543 * @parent: (allow-none): the parent of @pad or NULL
2545 * Iterate the list of pads to which the given pad is linked to inside of
2546 * the parent element.
2547 * This is the default handler, and thus returns an iterator of all of the
2548 * pads inside the parent element with opposite direction.
2550 * The caller must free this iterator after use with gst_iterator_free().
2552 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2553 * returned pad with gst_object_unref().
2556 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2563 GstElement *eparent;
2565 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2567 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2568 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2570 GST_OBJECT_LOCK (pad);
2571 eparent = GST_PAD_PARENT (pad);
2572 if (!eparent || !GST_IS_ELEMENT (eparent))
2575 gst_object_ref (eparent);
2576 GST_OBJECT_UNLOCK (pad);
2579 if (pad->direction == GST_PAD_SRC)
2580 padlist = &eparent->sinkpads;
2582 padlist = &eparent->srcpads;
2584 GST_DEBUG_OBJECT (pad, "Making iterator");
2586 cookie = &eparent->pads_cookie;
2588 lock = GST_OBJECT_GET_LOCK (eparent);
2590 res = gst_iterator_new_list (GST_TYPE_PAD,
2591 lock, cookie, padlist, (GObject *) owner, NULL);
2593 gst_object_unref (owner);
2600 GST_OBJECT_UNLOCK (pad);
2601 GST_DEBUG_OBJECT (pad, "no parent element");
2607 * gst_pad_iterate_internal_links:
2608 * @pad: the GstPad to get the internal links of.
2610 * Gets an iterator for the pads to which the given pad is linked to inside
2611 * of the parent element.
2613 * Each #GstPad element yielded by the iterator will have its refcount increased,
2614 * so unref after use.
2616 * Free-function: gst_iterator_free
2618 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2619 * pad does not have an iterator function configured. Use
2620 * gst_iterator_free() after usage.
2623 gst_pad_iterate_internal_links (GstPad * pad)
2625 GstIterator *res = NULL;
2628 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2630 GST_OBJECT_LOCK (pad);
2631 ACQUIRE_PARENT (pad, parent, no_parent);
2632 GST_OBJECT_UNLOCK (pad);
2634 if (GST_PAD_ITERINTLINKFUNC (pad))
2635 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2637 RELEASE_PARENT (parent);
2644 GST_DEBUG_OBJECT (pad, "no parent");
2645 GST_OBJECT_UNLOCK (pad);
2653 * @forward: (scope call): a #GstPadForwardFunction
2654 * @user_data: user data passed to @forward
2656 * Calls @forward for all internally linked pads of @pad. This function deals with
2657 * dynamically changing internal pads and will make sure that the @forward
2658 * function is only called once for each pad.
2660 * When @forward returns TRUE, no further pads will be processed.
2662 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2665 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2668 gboolean result = FALSE;
2670 gboolean done = FALSE;
2671 GValue item = { 0, };
2672 GList *pushed_pads = NULL;
2674 iter = gst_pad_iterate_internal_links (pad);
2680 switch (gst_iterator_next (iter, &item)) {
2681 case GST_ITERATOR_OK:
2685 intpad = g_value_get_object (&item);
2687 /* if already pushed, skip. FIXME, find something faster to tag pads */
2688 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2689 g_value_reset (&item);
2693 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2694 GST_DEBUG_PAD_NAME (intpad));
2695 done = result = forward (intpad, user_data);
2697 pushed_pads = g_list_prepend (pushed_pads, intpad);
2699 g_value_reset (&item);
2702 case GST_ITERATOR_RESYNC:
2703 /* We don't reset the result here because we don't push the event
2704 * again on pads that got the event already and because we need
2705 * to consider the result of the previous pushes */
2706 gst_iterator_resync (iter);
2708 case GST_ITERATOR_ERROR:
2709 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2712 case GST_ITERATOR_DONE:
2717 g_value_unset (&item);
2718 gst_iterator_free (iter);
2720 g_list_free (pushed_pads);
2730 gboolean dispatched;
2734 event_forward_func (GstPad * pad, EventData * data)
2736 /* for each pad we send to, we should ref the event; it's up
2737 * to downstream to unref again when handled. */
2738 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2739 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2741 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2743 data->dispatched = TRUE;
2750 * gst_pad_event_default:
2751 * @pad: a #GstPad to call the default event handler on.
2752 * @parent: (allow-none): the parent of @pad or NULL
2753 * @event: (transfer full): the #GstEvent to handle.
2755 * Invokes the default event handler for the given pad.
2757 * The EOS event will pause the task associated with @pad before it is forwarded
2758 * to all internally linked pads,
2760 * The the event is sent to all pads internally linked to @pad. This function
2761 * takes ownership of @event.
2763 * Returns: TRUE if the event was sent successfully.
2766 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2768 gboolean result, forward = TRUE;
2770 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2771 g_return_val_if_fail (event != NULL, FALSE);
2773 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2776 switch (GST_EVENT_TYPE (event)) {
2777 case GST_EVENT_CAPS:
2778 forward = GST_PAD_IS_PROXY_CAPS (pad);
2789 data.dispatched = FALSE;
2790 data.result = FALSE;
2792 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2794 /* for sinkpads without a parent element or without internal links, nothing
2795 * will be dispatched but we still want to return TRUE. */
2796 if (data.dispatched)
2797 result = data.result;
2802 gst_event_unref (event);
2807 /* Default accept caps implementation just checks against
2808 * the allowed caps for the pad */
2810 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2812 /* get the caps and see if it intersects to something not empty */
2813 GstCaps *caps, *allowed;
2816 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2818 /* first forward the query to internally linked pads when we are dealing with
2820 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2821 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2826 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2827 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2829 gst_query_parse_accept_caps (query, &caps);
2830 allowed = gst_pad_query_caps (pad, caps);
2833 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
2834 result = gst_caps_is_subset (caps, allowed);
2835 gst_caps_unref (allowed);
2837 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
2840 gst_query_set_accept_caps_result (query, result);
2846 /* Default caps implementation */
2848 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2850 GstCaps *result = NULL, *filter;
2851 GstPadTemplate *templ;
2852 gboolean fixed_caps;
2854 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2857 /* first try to proxy if we must */
2858 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2859 if ((gst_pad_proxy_query_caps (pad, query))) {
2864 gst_query_parse_caps (query, &filter);
2866 /* no proxy or it failed, do default handling */
2867 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2869 GST_OBJECT_LOCK (pad);
2871 /* fixed caps, try the negotiated caps first */
2872 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2873 if ((result = get_pad_caps (pad)))
2874 goto filter_done_unlock;
2877 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2878 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2879 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2880 goto filter_done_unlock;
2884 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2885 "non-fixed pad caps: trying pad caps");
2886 /* non fixed caps, try the negotiated caps */
2887 if ((result = get_pad_caps (pad)))
2888 goto filter_done_unlock;
2891 /* this almost never happens */
2892 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2893 result = GST_CAPS_ANY;
2896 GST_OBJECT_UNLOCK (pad);
2898 /* run the filter on the result */
2900 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2901 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2902 GST_PTR_FORMAT, result, result, filter, filter);
2903 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2904 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2907 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2908 "using caps %p %" GST_PTR_FORMAT, result, result);
2909 result = gst_caps_ref (result);
2911 gst_query_set_caps_result (query, result);
2912 gst_caps_unref (result);
2922 gboolean dispatched;
2926 query_forward_func (GstPad * pad, QueryData * data)
2928 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
2929 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
2931 data->result |= gst_pad_peer_query (pad, data->query);
2933 data->dispatched = TRUE;
2935 /* stop on first successful reply */
2936 return data->result;
2940 * gst_pad_query_default:
2941 * @pad: a #GstPad to call the default query handler on.
2942 * @parent: (allow-none): the parent of @pad or NULL
2943 * @query: (transfer none): the #GstQuery to handle.
2945 * Invokes the default query handler for the given pad.
2946 * The query is sent to all pads internally linked to @pad. Note that
2947 * if there are many possible sink pads that are internally linked to
2948 * @pad, only one will be sent the query.
2949 * Multi-sinkpad elements should implement custom query handlers.
2951 * Returns: TRUE if the query was performed successfully.
2954 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
2956 gboolean forward, ret = FALSE;
2958 switch (GST_QUERY_TYPE (query)) {
2959 case GST_QUERY_SCHEDULING:
2960 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
2962 case GST_QUERY_ALLOCATION:
2963 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
2965 case GST_QUERY_ACCEPT_CAPS:
2966 ret = gst_pad_query_accept_caps_default (pad, query);
2969 case GST_QUERY_CAPS:
2970 ret = gst_pad_query_caps_default (pad, query);
2973 case GST_QUERY_POSITION:
2974 case GST_QUERY_SEEKING:
2975 case GST_QUERY_FORMATS:
2976 case GST_QUERY_LATENCY:
2977 case GST_QUERY_JITTER:
2978 case GST_QUERY_RATE:
2979 case GST_QUERY_CONVERT:
2985 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
2986 query, GST_QUERY_TYPE_NAME (query));
2992 data.dispatched = FALSE;
2993 data.result = FALSE;
2995 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
2997 if (data.dispatched) {
3000 /* nothing dispatched, assume drained */
3001 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3011 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3013 GstPad *pad = data->pad;
3014 GstPadProbeInfo *info = data->info;
3015 GstPadProbeType type, flags;
3016 GstPadProbeCallback callback;
3017 GstPadProbeReturn ret;
3019 /* if we have called this callback, do nothing */
3020 if (PROBE_COOKIE (hook) == data->cookie) {
3021 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3022 "hook %lu, cookie %u already called", hook->hook_id,
3023 PROBE_COOKIE (hook));
3027 PROBE_COOKIE (hook) = data->cookie;
3029 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3032 /* one of the data types */
3033 if ((flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3035 /* one of the scheduling types */
3036 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3038 /* one of the blocking types must match */
3039 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3040 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3042 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3043 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3044 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3047 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3048 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3049 PROBE_COOKIE (hook), flags);
3051 data->marshalled = TRUE;
3053 callback = (GstPadProbeCallback) hook->func;
3054 if (callback == NULL)
3057 info->id = hook->hook_id;
3059 GST_OBJECT_UNLOCK (pad);
3061 ret = callback (pad, info, hook->data);
3063 GST_OBJECT_LOCK (pad);
3066 case GST_PAD_PROBE_REMOVE:
3067 /* remove the probe */
3068 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3069 cleanup_hook (pad, hook);
3071 case GST_PAD_PROBE_DROP:
3072 /* need to drop the data, make sure other probes don't get called
3074 GST_DEBUG_OBJECT (pad, "asked to drop item");
3075 info->type = GST_PAD_PROBE_TYPE_INVALID;
3076 data->dropped = TRUE;
3078 case GST_PAD_PROBE_PASS:
3079 /* inform the pad block to let things pass */
3080 GST_DEBUG_OBJECT (pad, "asked to pass item");
3083 case GST_PAD_PROBE_OK:
3084 GST_DEBUG_OBJECT (pad, "probe returned OK");
3087 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3094 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3095 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3096 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3101 /* a probe that does not take or return any data */
3102 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3104 if (G_UNLIKELY (pad->num_probes)) { \
3105 /* pass NULL as the data item */ \
3106 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3107 ret = do_probe_callbacks (pad, &info, defaultval); \
3108 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3113 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3115 if (G_UNLIKELY (pad->num_probes)) { \
3116 /* pass the data item */ \
3117 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3118 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3119 /* store the possibly updated data item */ \
3120 data = GST_PAD_PROBE_INFO_DATA (&info); \
3121 /* if something went wrong, exit */ \
3122 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3127 #define PROBE_PUSH(pad,mask,data,label) \
3128 PROBE_FULL(pad, mask, data, -1, -1, label);
3129 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3130 PROBE_FULL(pad, mask, data, offs, size, label);
3132 static GstFlowReturn
3133 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3134 GstFlowReturn defaultval)
3143 data.marshalled = FALSE;
3144 data.dropped = FALSE;
3145 data.cookie = ++pad->priv->probe_cookie;
3148 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3151 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3152 "do probes cookie %u", data.cookie);
3153 cookie = pad->priv->probe_list_cookie;
3155 g_hook_list_marshal (&pad->probes, TRUE,
3156 (GHookMarshaller) probe_hook_marshal, &data);
3158 /* if the list changed, call the new callbacks (they will not have their
3159 * cookie set to data.cookie */
3160 if (cookie != pad->priv->probe_list_cookie) {
3161 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3162 "probe list changed, restarting");
3166 /* the first item that dropped will stop the hooks and then we drop here */
3170 /* if no handler matched and we are blocking, let the item pass */
3171 if (!data.marshalled && is_block)
3174 /* At this point, all handlers returned either OK or PASS. If one handler
3175 * returned PASS, let the item pass */
3180 while (GST_PAD_IS_BLOCKED (pad)) {
3181 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3182 "we are blocked %d times", pad->num_blocked);
3184 /* we might have released the lock */
3185 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3188 /* now we block the streaming thread. It can be unlocked when we
3189 * deactivate the pad (which will also set the FLUSHING flag) or
3190 * when the pad is unblocked. A flushing event will also unblock
3191 * the pad after setting the FLUSHING flag. */
3192 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3193 "Waiting to be unblocked or set flushing");
3194 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3195 GST_PAD_BLOCK_WAIT (pad);
3196 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3197 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3199 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3209 GST_DEBUG_OBJECT (pad, "pad is flushing");
3210 return GST_FLOW_FLUSHING;
3214 GST_DEBUG_OBJECT (pad, "data is dropped");
3215 return GST_FLOW_CUSTOM_SUCCESS;
3219 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3220 GST_DEBUG_OBJECT (pad, "data is passed");
3228 * gst_pad_get_offset:
3231 * Get the offset applied to the running time of @pad. @pad has to be a source
3234 * Returns: the offset.
3237 gst_pad_get_offset (GstPad * pad)
3241 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3243 GST_OBJECT_LOCK (pad);
3244 result = pad->offset;
3245 GST_OBJECT_UNLOCK (pad);
3251 * gst_pad_set_offset:
3253 * @offset: the offset
3255 * Set the offset that will be applied to the running time of @pad.
3258 gst_pad_set_offset (GstPad * pad, gint64 offset)
3262 g_return_if_fail (GST_IS_PAD (pad));
3264 GST_OBJECT_LOCK (pad);
3265 /* if nothing changed, do nothing */
3266 if (pad->offset == offset)
3269 pad->offset = offset;
3270 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3272 /* sinkpads will apply their offset the next time a segment
3273 * event is received. */
3274 if (GST_PAD_IS_SINK (pad))
3277 /* resend the last segment event on next buffer push */
3278 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3279 ev->received = FALSE;
3280 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3284 GST_OBJECT_UNLOCK (pad);
3291 /* If TRUE and ret is not OK this means
3292 * that pushing the EOS event failed
3296 /* If called for an event this is
3297 * the event that would be pushed
3298 * next. Don't forward sticky events
3299 * that would come after that */
3303 /* should be called with pad LOCK */
3305 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3307 PushStickyData *data = user_data;
3308 GstEvent *event = ev->event;
3311 GST_DEBUG_OBJECT (pad, "event %s was already received",
3312 GST_EVENT_TYPE_NAME (event));
3316 /* If we're called because of an sticky event, only forward
3317 * events that would come before this new event and the
3319 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3320 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3321 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3322 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3324 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3325 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3328 switch (data->ret) {
3330 ev->received = TRUE;
3331 GST_DEBUG_OBJECT (pad, "event %s marked received",
3332 GST_EVENT_TYPE_NAME (event));
3334 case GST_FLOW_CUSTOM_SUCCESS:
3335 /* we can't assume the event is received when it was dropped */
3336 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3337 GST_EVENT_TYPE_NAME (event));
3338 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3339 data->ret = GST_FLOW_OK;
3341 case GST_FLOW_CUSTOM_SUCCESS_1:
3342 /* event was ignored and should be sent later */
3343 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3344 GST_EVENT_TYPE_NAME (event));
3345 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3346 data->ret = GST_FLOW_OK;
3348 case GST_FLOW_NOT_LINKED:
3349 /* not linked is not a problem, we are sticky so the event will be
3350 * sent later but only for non-EOS events */
3351 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3352 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3353 data->ret = GST_FLOW_OK;
3354 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3357 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3358 gst_flow_get_name (data->ret));
3359 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3363 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3364 data->was_eos = TRUE;
3366 return data->ret == GST_FLOW_OK;
3369 /* check sticky events and push them when needed. should be called
3371 static inline GstFlowReturn
3372 check_sticky (GstPad * pad, GstEvent * event)
3374 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3376 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3377 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3379 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3380 events_foreach (pad, push_sticky, &data);
3382 /* If there's an EOS event we must push it downstream
3383 * even if sending a previous sticky event failed.
3384 * Otherwise the pipeline might wait forever for EOS.
3386 * Only do this if pushing another event than the EOS
3389 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3390 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3392 if (ev && !ev->received) {
3393 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3394 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3395 /* the event could have been dropped. Because this can only
3396 * happen if the user asked for it, it's not an error */
3397 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3398 data.ret = GST_FLOW_OK;
3408 * @pad: a #GstPad to invoke the default query on.
3409 * @query: (transfer none): the #GstQuery to perform.
3411 * Dispatches a query to a pad. The query should have been allocated by the
3412 * caller via one of the type-specific allocation functions. The element that
3413 * the pad belongs to is responsible for filling the query with an appropriate
3414 * response, which should then be parsed with a type-specific query parsing
3417 * Again, the caller is responsible for both the allocation and deallocation of
3418 * the query structure.
3420 * Please also note that some queries might need a running pipeline to work.
3422 * Returns: TRUE if the query could be performed.
3425 gst_pad_query (GstPad * pad, GstQuery * query)
3428 gboolean res, serialized;
3429 GstPadQueryFunction func;
3430 GstPadProbeType type;
3433 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3434 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3436 if (GST_PAD_IS_SRC (pad)) {
3437 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3438 goto wrong_direction;
3439 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3440 } else if (GST_PAD_IS_SINK (pad)) {
3441 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3442 goto wrong_direction;
3443 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3445 goto unknown_direction;
3447 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3448 GST_QUERY_TYPE_NAME (query));
3450 serialized = GST_QUERY_IS_SERIALIZED (query);
3451 if (G_UNLIKELY (serialized))
3452 GST_PAD_STREAM_LOCK (pad);
3454 GST_OBJECT_LOCK (pad);
3455 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3456 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3457 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3459 ACQUIRE_PARENT (pad, parent, no_parent);
3460 GST_OBJECT_UNLOCK (pad);
3462 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3465 res = func (pad, parent, query);
3467 RELEASE_PARENT (parent);
3469 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3470 GST_QUERY_TYPE_NAME (query), res);
3475 GST_OBJECT_LOCK (pad);
3476 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3477 GST_OBJECT_UNLOCK (pad);
3479 if (G_UNLIKELY (serialized))
3480 GST_PAD_STREAM_UNLOCK (pad);
3487 g_warning ("pad %s:%s query %s in wrong direction",
3488 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3493 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3498 GST_DEBUG_OBJECT (pad, "had no parent");
3499 GST_OBJECT_UNLOCK (pad);
3500 if (G_UNLIKELY (serialized))
3501 GST_PAD_STREAM_UNLOCK (pad);
3506 GST_DEBUG_OBJECT (pad, "had no query function");
3507 RELEASE_PARENT (parent);
3508 if (G_UNLIKELY (serialized))
3509 GST_PAD_STREAM_UNLOCK (pad);
3514 GST_DEBUG_OBJECT (pad, "query failed");
3515 if (G_UNLIKELY (serialized))
3516 GST_PAD_STREAM_UNLOCK (pad);
3521 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3522 GST_OBJECT_UNLOCK (pad);
3523 if (G_UNLIKELY (serialized))
3524 GST_PAD_STREAM_UNLOCK (pad);
3526 /* if a probe dropped, we don't sent it further but assume that the probe
3527 * answered the query and return TRUE */
3528 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3538 * gst_pad_peer_query:
3539 * @pad: a #GstPad to invoke the peer query on.
3540 * @query: (transfer none): the #GstQuery to perform.
3542 * Performs gst_pad_query() on the peer of @pad.
3544 * The caller is responsible for both the allocation and deallocation of
3545 * the query structure.
3547 * Returns: TRUE if the query could be performed. This function returns %FALSE
3548 * if @pad has no peer.
3551 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3554 GstPadProbeType type;
3555 gboolean res, serialized;
3558 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3559 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3561 if (GST_PAD_IS_SRC (pad)) {
3562 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3563 goto wrong_direction;
3564 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3565 } else if (GST_PAD_IS_SINK (pad)) {
3566 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3567 goto wrong_direction;
3568 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3570 goto unknown_direction;
3572 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3573 GST_QUERY_TYPE_NAME (query));
3575 serialized = GST_QUERY_IS_SERIALIZED (query);
3577 GST_OBJECT_LOCK (pad);
3578 if (GST_PAD_IS_SRC (pad) && serialized) {
3579 /* all serialized queries on the srcpad trigger push of
3581 if (!check_sticky (pad, NULL) == GST_FLOW_OK)
3585 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3586 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3587 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3589 peerpad = GST_PAD_PEER (pad);
3590 if (G_UNLIKELY (peerpad == NULL))
3593 gst_object_ref (peerpad);
3594 GST_OBJECT_UNLOCK (pad);
3596 res = gst_pad_query (peerpad, query);
3598 gst_object_unref (peerpad);
3603 GST_OBJECT_LOCK (pad);
3604 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3605 GST_OBJECT_UNLOCK (pad);
3612 g_warning ("pad %s:%s query %s in wrong direction",
3613 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3618 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3623 GST_WARNING_OBJECT (pad, "could not send sticky events");
3624 GST_OBJECT_UNLOCK (pad);
3629 GST_INFO_OBJECT (pad, "pad has no peer");
3630 GST_OBJECT_UNLOCK (pad);
3635 GST_DEBUG_OBJECT (pad, "query failed");
3640 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3641 GST_OBJECT_UNLOCK (pad);
3643 /* if a probe dropped, we don't sent it further but assume that the probe
3644 * answered the query and return TRUE */
3645 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3654 /**********************************************************************
3655 * Data passing functions
3658 /* this is the chain function that does not perform the additional argument
3659 * checking for that little extra speed.
3661 static inline GstFlowReturn
3662 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3667 GST_PAD_STREAM_LOCK (pad);
3669 GST_OBJECT_LOCK (pad);
3670 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3673 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3676 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3679 #ifndef G_DISABLE_ASSERT
3680 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3681 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3683 ":%s:<%s:%s> Got data flow before stream-start event",
3684 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3686 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3688 ":%s:<%s:%s> Got data flow before segment event",
3689 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3691 pad->priv->last_cookie = pad->priv->events_cookie;
3695 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3697 PROBE_PUSH (pad, type, data, probe_stopped);
3699 parent = GST_OBJECT_PARENT (pad);
3700 GST_OBJECT_UNLOCK (pad);
3702 /* NOTE: we read the chainfunc unlocked.
3703 * we cannot hold the lock for the pad so we might send
3704 * the data to the wrong function. This is not really a
3705 * problem since functions are assigned at creation time
3706 * and don't change that often... */
3707 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3708 GstPadChainFunction chainfunc;
3710 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3713 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3714 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3715 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3717 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3719 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3720 "called chainfunction &%s with buffer %p, returned %s",
3721 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3723 GstPadChainListFunction chainlistfunc;
3725 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3728 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3729 "calling chainlistfunction &%s",
3730 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3732 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3734 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3735 "called chainlistfunction &%s, returned %s",
3736 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3739 GST_PAD_STREAM_UNLOCK (pad);
3746 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3747 "chaining, but pad was flushing");
3748 GST_OBJECT_UNLOCK (pad);
3749 GST_PAD_STREAM_UNLOCK (pad);
3750 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3751 return GST_FLOW_FLUSHING;
3755 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3756 GST_OBJECT_UNLOCK (pad);
3757 GST_PAD_STREAM_UNLOCK (pad);
3758 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3759 return GST_FLOW_EOS;
3763 g_critical ("chain on pad %s:%s but it was not in push mode",
3764 GST_DEBUG_PAD_NAME (pad));
3765 GST_OBJECT_UNLOCK (pad);
3766 GST_PAD_STREAM_UNLOCK (pad);
3767 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3768 return GST_FLOW_ERROR;
3772 GST_OBJECT_UNLOCK (pad);
3773 GST_PAD_STREAM_UNLOCK (pad);
3774 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3777 case GST_FLOW_CUSTOM_SUCCESS:
3778 GST_DEBUG_OBJECT (pad, "dropped buffer");
3782 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
3789 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3790 g_critical ("chain on pad %s:%s but it has no chainfunction",
3791 GST_DEBUG_PAD_NAME (pad));
3792 GST_PAD_STREAM_UNLOCK (pad);
3793 return GST_FLOW_NOT_SUPPORTED;
3799 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3800 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3803 * Chain a buffer to @pad.
3805 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3807 * If the buffer type is not acceptable for @pad (as negotiated with a
3808 * preceeding GST_EVENT_CAPS event), this function returns
3809 * #GST_FLOW_NOT_NEGOTIATED.
3811 * The function proceeds calling the chain function installed on @pad (see
3812 * gst_pad_set_chain_function()) and the return value of that function is
3813 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3816 * In all cases, success or failure, the caller loses its reference to @buffer
3817 * after calling this function.
3819 * Returns: a #GstFlowReturn from the pad.
3824 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3826 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3827 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3828 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3830 return gst_pad_chain_data_unchecked (pad,
3831 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3834 static GstFlowReturn
3835 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3836 GstBufferList * list)
3842 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3844 len = gst_buffer_list_length (list);
3847 for (i = 0; i < len; i++) {
3848 buffer = gst_buffer_list_get (list, i);
3850 gst_pad_chain_data_unchecked (pad,
3851 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3852 gst_buffer_ref (buffer));
3853 if (ret != GST_FLOW_OK)
3856 gst_buffer_list_unref (list);
3862 * gst_pad_chain_list:
3863 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3864 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3867 * Chain a bufferlist to @pad.
3869 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3871 * If @pad was not negotiated properly with a CAPS event, this function
3872 * returns #GST_FLOW_NOT_NEGOTIATED.
3874 * The function proceeds calling the chainlist function installed on @pad (see
3875 * gst_pad_set_chain_list_function()) and the return value of that function is
3876 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3877 * chainlist function.
3879 * In all cases, success or failure, the caller loses its reference to @list
3880 * after calling this function.
3884 * Returns: a #GstFlowReturn from the pad.
3887 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3889 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3890 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3891 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3893 return gst_pad_chain_data_unchecked (pad,
3894 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3897 static GstFlowReturn
3898 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3903 GST_OBJECT_LOCK (pad);
3904 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3907 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3910 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3913 #ifndef G_DISABLE_ASSERT
3914 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
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));
3925 pad->priv->last_cookie = pad->priv->events_cookie;
3929 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3932 /* do block probes */
3933 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3935 /* recheck sticky events because the probe might have cause a relink */
3936 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3939 /* do post-blocking probes */
3940 PROBE_PUSH (pad, type, data, probe_stopped);
3942 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3945 /* take ref to peer pad before releasing the lock */
3946 gst_object_ref (peer);
3948 GST_OBJECT_UNLOCK (pad);
3950 ret = gst_pad_chain_data_unchecked (peer, type, data);
3952 gst_object_unref (peer);
3954 GST_OBJECT_LOCK (pad);
3956 if (pad->priv->using == 0) {
3957 /* pad is not active anymore, trigger idle callbacks */
3958 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3959 probe_stopped, ret);
3961 GST_OBJECT_UNLOCK (pad);
3965 /* ERROR recovery here */
3969 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3970 "pushing, but pad was flushing");
3971 GST_OBJECT_UNLOCK (pad);
3972 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3973 return GST_FLOW_FLUSHING;
3977 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
3978 GST_OBJECT_UNLOCK (pad);
3979 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3980 return GST_FLOW_EOS;
3984 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
3985 GST_DEBUG_PAD_NAME (pad));
3986 GST_OBJECT_UNLOCK (pad);
3987 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3988 return GST_FLOW_ERROR;
3992 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3993 "error pushing events, return %s", gst_flow_get_name (ret));
3994 GST_OBJECT_UNLOCK (pad);
3995 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4000 GST_OBJECT_UNLOCK (pad);
4001 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4004 case GST_FLOW_CUSTOM_SUCCESS:
4005 GST_DEBUG_OBJECT (pad, "dropped buffer");
4009 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4016 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4017 "pushing, but it was not linked");
4018 GST_OBJECT_UNLOCK (pad);
4019 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4020 return GST_FLOW_NOT_LINKED;
4026 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4027 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4030 * Pushes a buffer to the peer of @pad.
4032 * This function will call installed block probes before triggering any
4033 * installed data probes.
4035 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4036 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4039 * In all cases, success or failure, the caller loses its reference to @buffer
4040 * after calling this function.
4042 * Returns: a #GstFlowReturn from the peer pad.
4047 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4049 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4050 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4051 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4053 return gst_pad_push_data (pad,
4054 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4058 * gst_pad_push_list:
4059 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4060 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4063 * Pushes a buffer list to the peer of @pad.
4065 * This function will call installed block probes before triggering any
4066 * installed data probes.
4068 * The function proceeds calling the chain function on the peer pad and returns
4069 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4070 * be returned. If the peer pad does not have any installed chainlist function
4071 * every group buffer of the list will be merged into a normal #GstBuffer and
4072 * chained via gst_pad_chain().
4074 * In all cases, success or failure, the caller loses its reference to @list
4075 * after calling this function.
4077 * Returns: a #GstFlowReturn from the peer pad.
4082 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4084 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4085 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4086 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4088 return gst_pad_push_data (pad,
4089 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4092 static GstFlowReturn
4093 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4094 GstBuffer ** buffer)
4097 GstPadGetRangeFunction getrangefunc;
4101 GST_PAD_STREAM_LOCK (pad);
4103 GST_OBJECT_LOCK (pad);
4104 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4107 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4110 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4115 /* when one of the probes returns DROPPED, probe_stopped will be called
4116 * and we skip calling the getrange function, res_buf should then contain a
4117 * valid result buffer */
4118 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4119 res_buf, offset, size, probe_stopped);
4121 /* recheck sticky events because the probe might have cause a relink */
4122 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4125 ACQUIRE_PARENT (pad, parent, no_parent);
4126 GST_OBJECT_UNLOCK (pad);
4128 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4131 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4132 "calling getrangefunc %s, offset %"
4133 G_GUINT64_FORMAT ", size %u",
4134 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4136 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4138 RELEASE_PARENT (parent);
4140 if (G_UNLIKELY (ret != GST_FLOW_OK))
4141 goto get_range_failed;
4143 /* can only fire the signal if we have a valid buffer */
4144 GST_OBJECT_LOCK (pad);
4146 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4147 res_buf, offset, size, probe_stopped_unref);
4148 GST_OBJECT_UNLOCK (pad);
4150 GST_PAD_STREAM_UNLOCK (pad);
4159 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4160 "getrange, but pad was flushing");
4161 GST_OBJECT_UNLOCK (pad);
4162 GST_PAD_STREAM_UNLOCK (pad);
4163 return GST_FLOW_FLUSHING;
4167 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4168 GST_DEBUG_PAD_NAME (pad));
4169 GST_OBJECT_UNLOCK (pad);
4170 GST_PAD_STREAM_UNLOCK (pad);
4171 return GST_FLOW_ERROR;
4175 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4176 GST_OBJECT_UNLOCK (pad);
4177 GST_PAD_STREAM_UNLOCK (pad);
4182 GST_DEBUG_OBJECT (pad, "no parent");
4183 GST_OBJECT_UNLOCK (pad);
4184 GST_PAD_STREAM_UNLOCK (pad);
4185 return GST_FLOW_FLUSHING;
4189 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4190 GST_DEBUG_PAD_NAME (pad));
4191 RELEASE_PARENT (parent);
4192 GST_PAD_STREAM_UNLOCK (pad);
4193 return GST_FLOW_NOT_SUPPORTED;
4197 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4198 "probe returned %s", gst_flow_get_name (ret));
4199 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4201 /* the probe filled the buffer and asks us to not call the getrange
4202 * anymore, we continue with the post probes then. */
4203 GST_DEBUG_OBJECT (pad, "handled buffer");
4207 /* no buffer, we are EOS */
4208 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4212 GST_OBJECT_UNLOCK (pad);
4213 GST_PAD_STREAM_UNLOCK (pad);
4217 probe_stopped_unref:
4219 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4220 "probe returned %s", gst_flow_get_name (ret));
4221 /* if we drop here, it signals EOS */
4222 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4224 GST_OBJECT_UNLOCK (pad);
4225 GST_PAD_STREAM_UNLOCK (pad);
4226 if (*buffer == NULL)
4227 gst_buffer_unref (res_buf);
4232 GST_PAD_STREAM_UNLOCK (pad);
4233 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4234 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4235 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4241 * gst_pad_get_range:
4242 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4243 * @offset: The start offset of the buffer
4244 * @size: The length of the buffer
4245 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4246 * returns #GST_FLOW_ERROR if %NULL.
4248 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4249 * immediately and @buffer is %NULL.
4251 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4252 * description of a getrange function. If @pad has no getrange function
4253 * installed (see gst_pad_set_getrange_function()) this function returns
4254 * #GST_FLOW_NOT_SUPPORTED.
4256 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4257 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4258 * must be freed with gst_buffer_unref() after usage.
4260 * When @buffer points to a variable that points to a valid #GstBuffer, the
4261 * buffer will be filled with the result data when this function returns
4262 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4263 * @size bytes will be filled in the result buffer and its size will be updated
4266 * Note that less than @size bytes can be returned in @buffer when, for example,
4267 * an EOS condition is near or when @buffer is not large enough to hold @size
4268 * bytes. The caller should check the result buffer size to get the result size.
4270 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4271 * will be unchanged.
4273 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
4275 * Returns: a #GstFlowReturn from the pad.
4280 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4281 GstBuffer ** buffer)
4283 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4284 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4285 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4286 g_return_val_if_fail (*buffer == NULL
4287 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4289 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4293 * gst_pad_pull_range:
4294 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4295 * @offset: The start offset of the buffer
4296 * @size: The length of the buffer
4297 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4298 * GST_FLOW_ERROR if %NULL.
4300 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4302 * This function will first trigger the pad block signal if it was
4305 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4306 * function returns the result of gst_pad_get_range() on the peer pad.
4307 * See gst_pad_get_range() for a list of return values and for the
4308 * semantics of the arguments of this function.
4310 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4311 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4312 * must be freed with gst_buffer_unref() after usage. When this function
4313 * returns any other result value, @buffer will still point to NULL.
4315 * When @buffer points to a variable that points to a valid #GstBuffer, the
4316 * buffer will be filled with the result data when this function returns
4317 * #GST_FLOW_OK. When this function returns any other result value,
4318 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4319 * @size bytes will be filled in the result buffer and its size will be updated
4322 * Note that less than @size bytes can be returned in @buffer when, for example,
4323 * an EOS condition is near or when @buffer is not large enough to hold @size
4324 * bytes. The caller should check the result buffer size to get the result size.
4326 * Returns: a #GstFlowReturn from the peer pad.
4331 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4332 GstBuffer ** buffer)
4338 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4339 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4340 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4341 g_return_val_if_fail (*buffer == NULL
4342 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4344 GST_OBJECT_LOCK (pad);
4345 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4348 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4353 /* when one of the probes returns DROPPED, probe_stopped will be
4354 * called and we skip calling the peer getrange function. *buffer should then
4355 * contain a valid buffer */
4356 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4357 res_buf, offset, size, probe_stopped);
4359 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4362 gst_object_ref (peer);
4364 GST_OBJECT_UNLOCK (pad);
4366 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4368 gst_object_unref (peer);
4370 GST_OBJECT_LOCK (pad);
4372 if (pad->priv->using == 0) {
4373 /* pad is not active anymore, trigger idle callbacks */
4374 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4375 probe_stopped_unref, ret);
4378 if (G_UNLIKELY (ret != GST_FLOW_OK))
4379 goto pull_range_failed;
4382 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4383 res_buf, offset, size, probe_stopped_unref);
4385 GST_OBJECT_UNLOCK (pad);
4391 /* ERROR recovery here */
4394 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4395 "pullrange, but pad was flushing");
4396 GST_OBJECT_UNLOCK (pad);
4397 return GST_FLOW_FLUSHING;
4401 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4402 GST_DEBUG_PAD_NAME (pad));
4403 GST_OBJECT_UNLOCK (pad);
4404 return GST_FLOW_ERROR;
4408 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4409 gst_flow_get_name (ret));
4410 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4412 /* the probe filled the buffer and asks us to not forward to the peer
4413 * anymore, we continue with the post probes then */
4414 GST_DEBUG_OBJECT (pad, "handled buffer");
4418 /* no buffer, we are EOS then */
4419 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4423 GST_OBJECT_UNLOCK (pad);
4428 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4429 "pulling range, but it was not linked");
4430 GST_OBJECT_UNLOCK (pad);
4431 return GST_FLOW_NOT_LINKED;
4435 GST_OBJECT_UNLOCK (pad);
4436 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4437 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4438 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4441 probe_stopped_unref:
4443 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4444 "post probe returned %s", gst_flow_get_name (ret));
4445 GST_OBJECT_UNLOCK (pad);
4446 /* if we drop here, it signals EOS */
4447 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4449 if (*buffer == NULL)
4450 gst_buffer_unref (res_buf);
4455 /* must be called with pad object lock */
4456 static GstFlowReturn
4457 store_sticky_event (GstPad * pad, GstEvent * event)
4462 gboolean res = FALSE;
4463 const gchar *name = NULL;
4464 gboolean insert = TRUE;
4466 type = GST_EVENT_TYPE (event);
4468 /* Store all sticky events except SEGMENT/SEGMENT when we're flushing,
4469 * otherwise they can be dropped and nothing would ever resend them.
4470 * Only do that for activated pads though, everything else is a bug!
4472 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4473 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4474 || type == GST_EVENT_EOS))))
4477 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4480 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4481 name = gst_structure_get_name (gst_event_get_structure (event));
4483 events = pad->priv->events;
4486 for (i = 0; i < len; i++) {
4487 PadEvent *ev = &g_array_index (events, PadEvent, i);
4489 if (ev->event == NULL)
4492 if (type == GST_EVENT_TYPE (ev->event)) {
4493 /* matching types, check matching name if needed */
4494 if (name && !gst_event_has_name (ev->event, name))
4498 if ((res = gst_event_replace (&ev->event, event)))
4499 ev->received = FALSE;
4505 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4506 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4507 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4508 * storing the sticky ordered we can check that this is respected. */
4509 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4510 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4512 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4513 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4514 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4515 gst_event_type_get_name (type));
4521 ev.event = gst_event_ref (event);
4522 ev.received = FALSE;
4523 g_array_insert_val (events, i, ev);
4528 pad->priv->events_cookie++;
4529 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4531 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4533 switch (GST_EVENT_TYPE (event)) {
4534 case GST_EVENT_CAPS:
4535 GST_OBJECT_UNLOCK (pad);
4537 GST_DEBUG_OBJECT (pad, "notify caps");
4538 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4540 GST_OBJECT_LOCK (pad);
4546 if (type == GST_EVENT_EOS)
4547 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4549 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4554 GST_DEBUG_OBJECT (pad, "pad is flushing");
4555 return GST_FLOW_FLUSHING;
4559 GST_DEBUG_OBJECT (pad, "pad is EOS");
4560 return GST_FLOW_EOS;
4565 * gst_pad_store_sticky_event:
4567 * @event: a #GstEvent
4569 * Store the sticky @event on @pad
4571 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4572 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4577 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4581 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4582 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4584 GST_OBJECT_LOCK (pad);
4585 ret = store_sticky_event (pad, event);
4586 GST_OBJECT_UNLOCK (pad);
4592 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
4594 PushStickyData *data = user_data;
4596 /* Forward all sticky events before our current one that are pending */
4597 if (ev->event != data->event
4598 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
4599 return push_sticky (pad, ev, data);
4604 /* should be called with pad LOCK */
4605 static GstFlowReturn
4606 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4607 GstPadProbeType type)
4611 GstEventType event_type;
4613 /* Two checks to be made:
4614 * . (un)set the FLUSHING flag for flushing events,
4615 * . handle pad blocking */
4616 event_type = GST_EVENT_TYPE (event);
4617 switch (event_type) {
4618 case GST_EVENT_FLUSH_START:
4619 GST_PAD_SET_FLUSHING (pad);
4621 GST_PAD_BLOCK_BROADCAST (pad);
4622 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4624 case GST_EVENT_FLUSH_STOP:
4625 GST_PAD_UNSET_FLUSHING (pad);
4627 /* Remove sticky EOS events */
4628 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4629 remove_event_by_type (pad, GST_EVENT_EOS);
4630 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4631 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4633 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4637 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4640 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4641 * checked already or this is called as part of pushing sticky events,
4642 * in which case we still want to forward the EOS event downstream.
4645 switch (GST_EVENT_TYPE (event)) {
4646 case GST_EVENT_SEGMENT:
4647 /* pass the adjusted segment event on. We need to do this even if
4648 * there is no peer pad because of the probes. */
4649 event = apply_pad_offset (pad, event);
4651 case GST_EVENT_RECONFIGURE:
4652 if (GST_PAD_IS_SINK (pad))
4653 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4658 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4659 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4664 /* send probes after modifying the events above */
4665 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4667 /* recheck sticky events because the probe might have cause a relink */
4668 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
4669 && (GST_EVENT_IS_SERIALIZED (event)
4670 || GST_EVENT_IS_STICKY (event))) {
4671 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4672 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4674 /* Push all sticky events before our current one
4675 * that have changed */
4676 events_foreach (pad, sticky_changed, &data);
4679 /* now check the peer pad */
4680 peerpad = GST_PAD_PEER (pad);
4681 if (peerpad == NULL)
4684 gst_object_ref (peerpad);
4686 GST_OBJECT_UNLOCK (pad);
4688 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4689 event, GST_EVENT_TYPE_NAME (event), peerpad);
4691 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4693 /* Note: we gave away ownership of the event at this point but we can still
4694 * print the old pointer */
4695 GST_LOG_OBJECT (pad, "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s",
4696 event, peerpad, gst_flow_get_name (ret));
4698 gst_object_unref (peerpad);
4700 GST_OBJECT_LOCK (pad);
4702 if (pad->priv->using == 0) {
4703 /* pad is not active anymore, trigger idle callbacks */
4704 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4705 idle_probe_stopped, ret);
4709 /* ERROR handling */
4712 GST_DEBUG_OBJECT (pad, "We're flushing");
4713 gst_event_unref (event);
4714 return GST_FLOW_FLUSHING;
4718 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4719 gst_event_unref (event);
4722 case GST_FLOW_CUSTOM_SUCCESS:
4723 GST_DEBUG_OBJECT (pad, "dropped event");
4726 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4733 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4734 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4735 gst_event_unref (event);
4737 /* unlinked pads should not influence latency configuration */
4738 if (event_type == GST_EVENT_LATENCY)
4741 return GST_FLOW_NOT_LINKED;
4745 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4751 * gst_pad_push_event:
4752 * @pad: a #GstPad to push the event to.
4753 * @event: (transfer full): the #GstEvent to send to the pad.
4755 * Sends the event to the peer of the given pad. This function is
4756 * mainly used by elements to send events to their peer
4759 * This function takes owership of the provided event so you should
4760 * gst_event_ref() it if you want to reuse the event after this call.
4762 * Returns: TRUE if the event was handled.
4767 gst_pad_push_event (GstPad * pad, GstEvent * event)
4769 gboolean res = FALSE;
4770 GstPadProbeType type;
4771 gboolean sticky, serialized;
4773 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4774 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4776 if (GST_PAD_IS_SRC (pad)) {
4777 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4778 goto wrong_direction;
4779 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4780 } else if (GST_PAD_IS_SINK (pad)) {
4781 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4782 goto wrong_direction;
4783 /* events pushed on sinkpad never are sticky */
4784 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4786 goto unknown_direction;
4788 GST_OBJECT_LOCK (pad);
4789 sticky = GST_EVENT_IS_STICKY (event);
4790 serialized = GST_EVENT_IS_SERIALIZED (event);
4793 /* srcpad sticky events are stored immediately, the received flag is set
4794 * to FALSE and will be set to TRUE when we can successfully push the
4795 * event to the peer pad */
4796 switch (store_sticky_event (pad, event)) {
4797 case GST_FLOW_FLUSHING:
4805 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4806 /* all serialized or sticky events on the srcpad trigger push of
4808 res = (check_sticky (pad, event) == GST_FLOW_OK);
4813 /* other events are pushed right away */
4814 ret = gst_pad_push_event_unchecked (pad, event, type);
4815 /* dropped events by a probe are not an error */
4816 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4818 /* Errors in sticky event pushing are no problem and ignored here
4819 * as they will cause more meaningful errors during data flow.
4820 * For EOS events, that are not followed by data flow, we still
4821 * return FALSE here though.
4823 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4825 gst_event_unref (event);
4827 GST_OBJECT_UNLOCK (pad);
4831 /* ERROR handling */
4834 g_warning ("pad %s:%s pushing %s event in wrong direction",
4835 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4836 gst_event_unref (event);
4841 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4842 gst_event_unref (event);
4847 GST_DEBUG_OBJECT (pad, "We're flushing");
4848 GST_OBJECT_UNLOCK (pad);
4849 gst_event_unref (event);
4854 GST_DEBUG_OBJECT (pad, "We're EOS");
4855 GST_OBJECT_UNLOCK (pad);
4856 gst_event_unref (event);
4861 /* Check if we can call the event function with the given event */
4862 static GstFlowReturn
4863 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4867 switch (GST_EVENT_TYPE (event)) {
4868 case GST_EVENT_CAPS:
4870 /* backwards compatibility mode for caps */
4871 gst_event_parse_caps (event, &caps);
4873 if (!gst_pad_query_accept_caps (pad, caps))
4885 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4886 "caps %" GST_PTR_FORMAT " not accepted", caps);
4887 return GST_FLOW_NOT_NEGOTIATED;
4891 static GstFlowReturn
4892 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4893 GstPadProbeType type)
4896 GstEventType event_type;
4897 gboolean serialized, need_unlock = FALSE, sticky;
4898 GstPadEventFunction eventfunc;
4901 GST_OBJECT_LOCK (pad);
4902 if (GST_PAD_IS_SINK (pad))
4903 serialized = GST_EVENT_IS_SERIALIZED (event);
4906 sticky = GST_EVENT_IS_STICKY (event);
4907 event_type = GST_EVENT_TYPE (event);
4908 switch (event_type) {
4909 case GST_EVENT_FLUSH_START:
4910 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4911 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4913 /* can't even accept a flush begin event when flushing */
4914 if (GST_PAD_IS_FLUSHING (pad))
4917 GST_PAD_SET_FLUSHING (pad);
4918 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4920 case GST_EVENT_FLUSH_STOP:
4921 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4922 GST_PAD_UNSET_FLUSHING (pad);
4923 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4925 /* Remove pending EOS events */
4926 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
4927 remove_event_by_type (pad, GST_EVENT_EOS);
4928 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4929 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4931 GST_OBJECT_UNLOCK (pad);
4932 /* grab stream lock */
4933 GST_PAD_STREAM_LOCK (pad);
4935 GST_OBJECT_LOCK (pad);
4936 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4939 case GST_EVENT_RECONFIGURE:
4940 if (GST_PAD_IS_SRC (pad))
4941 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4943 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4944 "have event type %" GST_PTR_FORMAT, event);
4946 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4950 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4953 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4954 GST_OBJECT_UNLOCK (pad);
4955 GST_PAD_STREAM_LOCK (pad);
4957 GST_OBJECT_LOCK (pad);
4958 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4961 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4965 switch (GST_EVENT_TYPE (event)) {
4966 case GST_EVENT_SEGMENT:
4967 event = apply_pad_offset (pad, event);
4975 /* now do the probe */
4977 type | GST_PAD_PROBE_TYPE_PUSH |
4978 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4980 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4982 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4985 ACQUIRE_PARENT (pad, parent, no_parent);
4986 GST_OBJECT_UNLOCK (pad);
4988 ret = pre_eventfunc_check (pad, event);
4989 if (G_UNLIKELY (ret != GST_FLOW_OK))
4990 goto precheck_failed;
4993 gst_event_ref (event);
4995 if (eventfunc (pad, parent, event)) {
4998 /* something went wrong */
4999 switch (event_type) {
5000 case GST_EVENT_CAPS:
5001 ret = GST_FLOW_NOT_NEGOTIATED;
5004 ret = GST_FLOW_ERROR;
5008 RELEASE_PARENT (parent);
5010 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5013 if (ret == GST_FLOW_OK) {
5014 GST_OBJECT_LOCK (pad);
5015 /* after the event function accepted the event, we can store the sticky
5016 * event on the pad */
5017 switch (store_sticky_event (pad, event)) {
5018 case GST_FLOW_FLUSHING:
5025 GST_OBJECT_UNLOCK (pad);
5027 gst_event_unref (event);
5031 GST_PAD_STREAM_UNLOCK (pad);
5035 /* ERROR handling */
5038 GST_OBJECT_UNLOCK (pad);
5040 GST_PAD_STREAM_UNLOCK (pad);
5041 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5042 "Received event on flushing pad. Discarding");
5043 gst_event_unref (event);
5044 return GST_FLOW_FLUSHING;
5048 GST_OBJECT_UNLOCK (pad);
5050 GST_PAD_STREAM_UNLOCK (pad);
5051 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5052 "Received event on EOS pad. Discarding");
5053 gst_event_unref (event);
5054 return GST_FLOW_EOS;
5058 GST_OBJECT_UNLOCK (pad);
5060 GST_PAD_STREAM_UNLOCK (pad);
5061 gst_event_unref (event);
5064 case GST_FLOW_CUSTOM_SUCCESS:
5065 GST_DEBUG_OBJECT (pad, "dropped event");
5069 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
5076 g_warning ("pad %s:%s has no event handler, file a bug.",
5077 GST_DEBUG_PAD_NAME (pad));
5078 GST_OBJECT_UNLOCK (pad);
5080 GST_PAD_STREAM_UNLOCK (pad);
5081 gst_event_unref (event);
5082 return GST_FLOW_NOT_SUPPORTED;
5086 GST_DEBUG_OBJECT (pad, "no parent");
5087 GST_OBJECT_UNLOCK (pad);
5089 GST_PAD_STREAM_UNLOCK (pad);
5090 gst_event_unref (event);
5091 return GST_FLOW_FLUSHING;
5095 GST_DEBUG_OBJECT (pad, "pre event check failed");
5096 RELEASE_PARENT (parent);
5098 GST_PAD_STREAM_UNLOCK (pad);
5099 gst_event_unref (event);
5105 * gst_pad_send_event:
5106 * @pad: a #GstPad to send the event to.
5107 * @event: (transfer full): the #GstEvent to send to the pad.
5109 * Sends the event to the pad. This function can be used
5110 * by applications to send events in the pipeline.
5112 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5113 * sink pad, @event should be a downstream event. For example, you would not
5114 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5115 * Furthermore, some downstream events have to be serialized with data flow,
5116 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5117 * the event needs to be serialized with data flow, this function will take the
5118 * pad's stream lock while calling its event function.
5120 * To find out whether an event type is upstream, downstream, or downstream and
5121 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5122 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5123 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5124 * plugin doesn't need to bother itself with this information; the core handles
5125 * all necessary locks and checks.
5127 * This function takes owership of the provided event so you should
5128 * gst_event_ref() it if you want to reuse the event after this call.
5130 * Returns: TRUE if the event was handled.
5133 gst_pad_send_event (GstPad * pad, GstEvent * event)
5136 GstPadProbeType type;
5138 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5139 g_return_val_if_fail (event != NULL, FALSE);
5141 if (GST_PAD_IS_SINK (pad)) {
5142 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5143 goto wrong_direction;
5144 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5145 } else if (GST_PAD_IS_SRC (pad)) {
5146 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5147 goto wrong_direction;
5148 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5150 goto unknown_direction;
5152 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5159 /* ERROR handling */
5162 g_warning ("pad %s:%s sending %s event in wrong direction",
5163 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5164 gst_event_unref (event);
5169 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5170 gst_event_unref (event);
5176 * gst_pad_set_element_private:
5177 * @pad: the #GstPad to set the private data of.
5178 * @priv: The private data to attach to the pad.
5180 * Set the given private data gpointer on the pad.
5181 * This function can only be used by the element that owns the pad.
5182 * No locking is performed in this function.
5185 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5187 pad->element_private = priv;
5191 * gst_pad_get_element_private:
5192 * @pad: the #GstPad to get the private data of.
5194 * Gets the private data of a pad.
5195 * No locking is performed in this function.
5197 * Returns: (transfer none): a #gpointer to the private data.
5200 gst_pad_get_element_private (GstPad * pad)
5202 return pad->element_private;
5206 * gst_pad_get_sticky_event:
5207 * @pad: the #GstPad to get the event from.
5208 * @event_type: the #GstEventType that should be retrieved.
5209 * @idx: the index of the event
5211 * Returns a new reference of the sticky event of type @event_type
5214 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
5215 * event of @event_type was on @pad. Unref after usage.
5218 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5220 GstEvent *event = NULL;
5223 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5224 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5226 GST_OBJECT_LOCK (pad);
5227 ev = find_event_by_type (pad, event_type, idx);
5228 if (ev && (event = ev->event))
5229 gst_event_ref (event);
5230 GST_OBJECT_UNLOCK (pad);
5237 GstPadStickyEventsForeachFunction func;
5242 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5244 ForeachDispatch *data = user_data;
5245 gboolean ret = TRUE;
5248 GST_OBJECT_UNLOCK (pad);
5250 ret = data->func (pad, &ev->event, data->user_data);
5252 GST_OBJECT_LOCK (pad);
5259 * gst_pad_sticky_events_foreach:
5260 * @pad: the #GstPad that should be used for iteration.
5261 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5262 * should be called for every event.
5263 * @user_data: (closure): the optional user data.
5265 * Iterates all sticky events on @pad and calls @foreach_func for every
5266 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5269 gst_pad_sticky_events_foreach (GstPad * pad,
5270 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5272 ForeachDispatch data;
5274 g_return_if_fail (GST_IS_PAD (pad));
5275 g_return_if_fail (foreach_func != NULL);
5277 data.func = foreach_func;
5278 data.user_data = user_data;
5280 GST_OBJECT_LOCK (pad);
5281 events_foreach (pad, foreach_dispatch_function, &data);
5282 GST_OBJECT_UNLOCK (pad);
5286 do_stream_status (GstPad * pad, GstStreamStatusType type,
5287 GThread * thread, GstTask * task)
5291 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5293 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5294 if (GST_IS_ELEMENT (parent)) {
5295 GstMessage *message;
5296 GValue value = { 0 };
5298 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5299 gchar *tname, *ename, *pname;
5301 /* create a good task name */
5302 ename = gst_element_get_name (parent);
5303 pname = gst_pad_get_name (pad);
5304 tname = g_strdup_printf ("%s:%s", ename, pname);
5308 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5312 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5315 g_value_init (&value, GST_TYPE_TASK);
5316 g_value_set_object (&value, task);
5317 gst_message_set_stream_status_object (message, &value);
5318 g_value_unset (&value);
5320 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5321 gst_element_post_message (parent, message);
5323 gst_object_unref (parent);
5328 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5330 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5335 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5337 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5342 * gst_pad_start_task:
5343 * @pad: the #GstPad to start the task of
5344 * @func: the task function to call
5345 * @user_data: user data passed to the task function
5346 * @notify: called when @user_data is no longer referenced
5348 * Starts a task that repeatedly calls @func with @user_data. This function
5349 * is mostly used in pad activation functions to start the dataflow.
5350 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5351 * before @func is called.
5353 * Returns: a %TRUE if the task could be started.
5356 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5357 GDestroyNotify notify)
5362 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5363 g_return_val_if_fail (func != NULL, FALSE);
5365 GST_DEBUG_OBJECT (pad, "start task");
5367 GST_OBJECT_LOCK (pad);
5368 task = GST_PAD_TASK (pad);
5370 task = gst_task_new (func, user_data, notify);
5371 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5372 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5373 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5374 GST_INFO_OBJECT (pad, "created task %p", task);
5375 GST_PAD_TASK (pad) = task;
5376 gst_object_ref (task);
5377 /* release lock to post the message */
5378 GST_OBJECT_UNLOCK (pad);
5380 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5382 gst_object_unref (task);
5384 GST_OBJECT_LOCK (pad);
5385 /* nobody else is supposed to have changed the pad now */
5386 if (GST_PAD_TASK (pad) != task)
5387 goto concurrent_stop;
5389 res = gst_task_set_state (task, GST_TASK_STARTED);
5390 GST_OBJECT_UNLOCK (pad);
5397 GST_OBJECT_UNLOCK (pad);
5403 * gst_pad_pause_task:
5404 * @pad: the #GstPad to pause the task of
5406 * Pause the task of @pad. This function will also wait until the
5407 * function executed by the task is finished if this function is not
5408 * called from the task function.
5410 * Returns: a TRUE if the task could be paused or FALSE when the pad
5414 gst_pad_pause_task (GstPad * pad)
5419 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5421 GST_DEBUG_OBJECT (pad, "pause task");
5423 GST_OBJECT_LOCK (pad);
5424 task = GST_PAD_TASK (pad);
5427 res = gst_task_set_state (task, GST_TASK_PAUSED);
5428 GST_OBJECT_UNLOCK (pad);
5430 /* wait for task function to finish, this lock is recursive so it does nothing
5431 * when the pause is called from the task itself */
5432 GST_PAD_STREAM_LOCK (pad);
5433 GST_PAD_STREAM_UNLOCK (pad);
5439 GST_DEBUG_OBJECT (pad, "pad has no task");
5440 GST_OBJECT_UNLOCK (pad);
5446 * gst_pad_stop_task:
5447 * @pad: the #GstPad to stop the task of
5449 * Stop the task of @pad. This function will also make sure that the
5450 * function executed by the task will effectively stop if not called
5451 * from the GstTaskFunction.
5453 * This function will deadlock if called from the GstTaskFunction of
5454 * the task. Use gst_task_pause() instead.
5456 * Regardless of whether the pad has a task, the stream lock is acquired and
5457 * released so as to ensure that streaming through this pad has finished.
5459 * Returns: a TRUE if the task could be stopped or FALSE on error.
5462 gst_pad_stop_task (GstPad * pad)
5467 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5469 GST_DEBUG_OBJECT (pad, "stop task");
5471 GST_OBJECT_LOCK (pad);
5472 task = GST_PAD_TASK (pad);
5475 GST_PAD_TASK (pad) = NULL;
5476 res = gst_task_set_state (task, GST_TASK_STOPPED);
5477 GST_OBJECT_UNLOCK (pad);
5479 GST_PAD_STREAM_LOCK (pad);
5480 GST_PAD_STREAM_UNLOCK (pad);
5482 if (!gst_task_join (task))
5485 gst_object_unref (task);
5491 GST_DEBUG_OBJECT (pad, "no task");
5492 GST_OBJECT_UNLOCK (pad);
5494 GST_PAD_STREAM_LOCK (pad);
5495 GST_PAD_STREAM_UNLOCK (pad);
5497 /* this is not an error */
5502 /* this is bad, possibly the application tried to join the task from
5503 * the task's thread. We install the task again so that it will be stopped
5504 * again from the right thread next time hopefully. */
5505 GST_OBJECT_LOCK (pad);
5506 GST_DEBUG_OBJECT (pad, "join failed");
5507 /* we can only install this task if there was no other task */
5508 if (GST_PAD_TASK (pad) == NULL)
5509 GST_PAD_TASK (pad) = task;
5510 GST_OBJECT_UNLOCK (pad);
5517 * gst_pad_probe_info_get_event:
5518 * @info: a #GstPadProbeInfo
5520 * Returns: (transfer none): The #GstEvent from the probe
5524 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5526 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5527 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5529 return GST_PAD_PROBE_INFO_EVENT (info);
5534 * gst_pad_probe_info_get_query:
5535 * @info: a #GstPadProbeInfo
5537 * Returns: (transfer none): The #GstQuery from the probe
5541 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5543 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5544 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5546 return GST_PAD_PROBE_INFO_QUERY (info);
5550 * gst_pad_probe_info_get_buffer:
5551 * @info: a #GstPadProbeInfo
5553 * Returns: (transfer none): The #GstBuffer from the probe
5557 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5559 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5561 return GST_PAD_PROBE_INFO_BUFFER (info);
5565 * gst_pad_probe_info_get_bufferlist:
5566 * @info: a #GstPadProbeInfo
5568 * Returns: (transfer none): The #GstBufferlist from the probe
5572 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5574 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5576 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);