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., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * @short_description: Object contained by elements that allows links to
26 * @see_also: #GstPadTemplate, #GstElement, #GstEvent
28 * A #GstElement is linked to other elements via "pads", which are extremely
29 * light-weight generic link points.
30 * After two pads are retrieved from an element with gst_element_get_pad(),
31 * the pads can be link with gst_pad_link(). (For quick links,
32 * you can also use gst_element_link(), which will make the obvious
33 * link for you if it's straightforward.)
35 * Pads are typically created from a #GstPadTemplate with
36 * gst_pad_new_from_template().
38 * Pads have #GstCaps attached to it to describe the media type they are
39 * capable of dealing with. gst_pad_query_caps() and gst_pad_set_caps() are
40 * used to manipulate the caps of the pads.
41 * Pads created from a pad template cannot set capabilities that are
42 * incompatible with the pad template capabilities.
44 * Pads without pad templates can be created with gst_pad_new(),
45 * which takes a direction and a name as an argument. If the name is NULL,
46 * then a guaranteed unique name will be assigned to it.
48 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
50 * A #GstElement creating a pad will typically use the various
51 * gst_pad_set_*_function() calls to register callbacks for various events
54 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
55 * or pull in a buffer.
57 * To send a #GstEvent on a pad, use gst_pad_send_event() and
58 * gst_pad_push_event().
60 * Last reviewed on 2006-07-06 (0.10.9)
63 #include "gst_private.h"
66 #include "gstpadtemplate.h"
67 #include "gstenumtypes.h"
68 #include "gstmarshal.h"
73 #include "glib-compat-private.h"
75 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
76 #define GST_CAT_DEFAULT GST_CAT_PADS
78 /* Pad signals and args */
96 #define GST_PAD_GET_PRIVATE(obj) \
97 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
99 /* we have a pending and an active event on the pad. On source pads only the
100 * active event is used. On sinkpads, events are copied to the pending entry and
101 * moved to the active event when the eventfunc returned TRUE. */
108 struct _GstPadPrivate
114 guint probe_list_cookie;
124 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
129 GstPadProbeInfo *info;
136 static void gst_pad_dispose (GObject * object);
137 static void gst_pad_finalize (GObject * object);
138 static void gst_pad_set_property (GObject * object, guint prop_id,
139 const GValue * value, GParamSpec * pspec);
140 static void gst_pad_get_property (GObject * object, guint prop_id,
141 GValue * value, GParamSpec * pspec);
143 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
144 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
145 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
146 GstObject * parent, GstBufferList * list);
148 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
149 GstEvent * event, GstPadProbeType type);
150 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
151 GstEvent * event, GstPadProbeType type, gboolean * stored);
153 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
155 static GParamSpec *pspec_caps = NULL;
157 /* quarks for probe signals */
158 static GQuark buffer_quark;
159 static GQuark buffer_list_quark;
160 static GQuark event_quark;
169 static GstFlowQuarks flow_quarks[] = {
170 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
171 {GST_FLOW_OK, "ok", 0},
172 {GST_FLOW_NOT_LINKED, "not-linked", 0},
173 {GST_FLOW_WRONG_STATE, "wrong-state", 0},
174 {GST_FLOW_EOS, "eos", 0},
175 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
176 {GST_FLOW_ERROR, "error", 0},
177 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
178 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
183 * @ret: a #GstFlowReturn to get the name of.
185 * Gets a string representing the given flow return.
187 * Returns: a static string with the name of the flow return.
190 gst_flow_get_name (GstFlowReturn ret)
194 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
196 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
197 if (ret == flow_quarks[i].ret)
198 return flow_quarks[i].name;
205 * @ret: a #GstFlowReturn to get the quark of.
207 * Get the unique quark for the given GstFlowReturn.
209 * Returns: the quark associated with the flow return or 0 if an
210 * invalid return was specified.
213 gst_flow_to_quark (GstFlowReturn ret)
217 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
219 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
220 if (ret == flow_quarks[i].ret)
221 return flow_quarks[i].quark;
230 buffer_quark = g_quark_from_static_string ("buffer"); \
231 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
232 event_quark = g_quark_from_static_string ("event"); \
234 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
235 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
238 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
239 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
242 #define gst_pad_parent_class parent_class
243 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
246 gst_pad_class_init (GstPadClass * klass)
248 GObjectClass *gobject_class;
249 GstObjectClass *gstobject_class;
251 gobject_class = G_OBJECT_CLASS (klass);
252 gstobject_class = GST_OBJECT_CLASS (klass);
254 g_type_class_add_private (klass, sizeof (GstPadPrivate));
256 gobject_class->dispose = gst_pad_dispose;
257 gobject_class->finalize = gst_pad_finalize;
258 gobject_class->set_property = gst_pad_set_property;
259 gobject_class->get_property = gst_pad_get_property;
263 * @pad: the pad that emitted the signal
264 * @peer: the peer pad that has been connected
266 * Signals that a pad has been linked to the peer pad.
268 gst_pad_signals[PAD_LINKED] =
269 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
270 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
271 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
274 * @pad: the pad that emitted the signal
275 * @peer: the peer pad that has been disconnected
277 * Signals that a pad has been unlinked from the peer pad.
279 gst_pad_signals[PAD_UNLINKED] =
280 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
281 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
282 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
284 pspec_caps = g_param_spec_boxed ("caps", "Caps",
285 "The capabilities of the pad", GST_TYPE_CAPS,
286 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
287 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
289 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
290 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
291 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
292 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
294 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
295 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
296 g_param_spec_object ("template", "Template",
297 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
298 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
300 gstobject_class->path_string_separator = ".";
302 /* Register common function pointer descriptions */
303 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
304 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
305 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
306 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
307 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
311 gst_pad_init (GstPad * pad)
313 pad->priv = GST_PAD_GET_PRIVATE (pad);
315 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
317 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
318 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
319 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
320 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
321 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
323 GST_PAD_SET_FLUSHING (pad);
325 g_rec_mutex_init (&pad->stream_rec_lock);
327 g_cond_init (&pad->block_cond);
329 g_hook_list_init (&pad->probes, sizeof (GstProbe));
331 pad->priv->events = g_array_sized_new (FALSE, TRUE,
332 sizeof (PadEvent), GST_EVENT_MAX_STICKY);
335 /* called when setting the pad inactive. It removes all sticky events from
338 remove_events (GstPad * pad)
343 events = pad->priv->events;
346 for (i = 0; i < len; i++) {
347 PadEvent *ev = &g_array_index (events, PadEvent, i);
348 gst_event_unref (ev->event);
350 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
351 g_array_set_size (events, 0);
352 pad->priv->events_cookie++;
356 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
362 events = pad->priv->events;
365 for (i = 0; i < len; i++) {
366 ev = &g_array_index (events, PadEvent, i);
367 if (ev->event == NULL)
370 if (GST_EVENT_TYPE (ev->event) == type) {
382 find_event (GstPad * pad, GstEvent * event)
388 events = pad->priv->events;
391 for (i = 0; i < len; i++) {
392 ev = &g_array_index (events, PadEvent, i);
393 if (event == ev->event)
402 remove_event_by_type (GstPad * pad, GstEventType type)
408 events = pad->priv->events;
413 ev = &g_array_index (events, PadEvent, i);
414 if (ev->event == NULL)
417 if (GST_EVENT_TYPE (ev->event) != type)
420 gst_event_unref (ev->event);
421 g_array_remove_index (events, i);
423 pad->priv->events_cookie++;
432 schedule_events (GstPad * srcpad, GstPad * sinkpad)
437 gboolean pending = FALSE;
439 events = srcpad->priv->events;
442 for (i = 0; i < len; i++) {
443 ev = &g_array_index (events, PadEvent, i);
444 if (ev->event == NULL)
447 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
448 ev->received = FALSE;
453 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
456 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
460 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
467 events = pad->priv->events;
470 cookie = pad->priv->events_cookie;
474 PadEvent *ev, ev_ret;
476 ev = &g_array_index (events, PadEvent, i);
477 if (G_UNLIKELY (ev->event == NULL))
480 /* take aditional ref, func might release the lock */
481 ev_ret.event = gst_event_ref (ev->event);
482 ev_ret.received = ev->received;
484 ret = func (pad, &ev_ret, user_data);
486 /* recheck the cookie, lock might have been released and the list could have
488 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
489 if (G_LIKELY (ev_ret.event))
490 gst_event_unref (ev_ret.event);
494 /* if the event changed, we need to do something */
495 if (G_UNLIKELY (ev->event != ev_ret.event)) {
496 if (G_UNLIKELY (ev_ret.event == NULL)) {
497 /* function unreffed and set the event to NULL, remove it */
498 g_array_remove_index (events, i);
500 cookie = ++pad->priv->events_cookie;
503 /* function gave a new event for us */
504 gst_event_take (&ev->event, ev_ret.event);
507 /* just unref, nothing changed */
508 gst_event_unref (ev_ret.event);
517 /* should be called with LOCK */
519 apply_pad_offset (GstPad * pad, GstEvent * event)
521 /* check if we need to adjust the segment */
522 if (pad->offset != 0) {
525 /* copy segment values */
526 gst_event_copy_segment (event, &segment);
527 gst_event_unref (event);
529 /* adjust and make a new event with the offset applied */
530 segment.base += pad->offset;
531 event = gst_event_new_segment (&segment);
536 /* should be called with the OBJECT_LOCK */
538 get_pad_caps (GstPad * pad)
540 GstCaps *caps = NULL;
543 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
545 gst_event_parse_caps (ev->event, &caps);
551 gst_pad_dispose (GObject * object)
553 GstPad *pad = GST_PAD_CAST (object);
556 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
558 /* unlink the peer pad */
559 if ((peer = gst_pad_get_peer (pad))) {
560 /* window for MT unsafeness, someone else could unlink here
561 * and then we call unlink with wrong pads. The unlink
562 * function would catch this and safely return failed. */
563 if (GST_PAD_IS_SRC (pad))
564 gst_pad_unlink (pad, peer);
566 gst_pad_unlink (peer, pad);
568 gst_object_unref (peer);
571 gst_pad_set_pad_template (pad, NULL);
575 g_hook_list_clear (&pad->probes);
577 G_OBJECT_CLASS (parent_class)->dispose (object);
581 gst_pad_finalize (GObject * object)
583 GstPad *pad = GST_PAD_CAST (object);
586 /* in case the task is still around, clean it up */
587 if ((task = GST_PAD_TASK (pad))) {
588 gst_task_join (task);
589 GST_PAD_TASK (pad) = NULL;
590 gst_object_unref (task);
593 if (pad->activatenotify)
594 pad->activatenotify (pad);
595 if (pad->activatemodenotify)
596 pad->activatemodenotify (pad);
598 pad->linknotify (pad);
599 if (pad->unlinknotify)
600 pad->unlinknotify (pad);
601 if (pad->chainnotify)
602 pad->chainnotify (pad);
603 if (pad->chainlistnotify)
604 pad->chainlistnotify (pad);
605 if (pad->getrangenotify)
606 pad->getrangenotify (pad);
607 if (pad->eventnotify)
608 pad->eventnotify (pad);
609 if (pad->querynotify)
610 pad->querynotify (pad);
611 if (pad->iterintlinknotify)
612 pad->iterintlinknotify (pad);
614 g_rec_mutex_clear (&pad->stream_rec_lock);
615 g_cond_clear (&pad->block_cond);
616 g_array_free (pad->priv->events, TRUE);
618 G_OBJECT_CLASS (parent_class)->finalize (object);
622 gst_pad_set_property (GObject * object, guint prop_id,
623 const GValue * value, GParamSpec * pspec)
625 g_return_if_fail (GST_IS_PAD (object));
628 case PAD_PROP_DIRECTION:
629 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
631 case PAD_PROP_TEMPLATE:
632 gst_pad_set_pad_template (GST_PAD_CAST (object),
633 (GstPadTemplate *) g_value_get_object (value));
636 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
642 gst_pad_get_property (GObject * object, guint prop_id,
643 GValue * value, GParamSpec * pspec)
645 g_return_if_fail (GST_IS_PAD (object));
649 GST_OBJECT_LOCK (object);
650 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
651 GST_OBJECT_UNLOCK (object);
653 case PAD_PROP_DIRECTION:
654 g_value_set_enum (value, GST_PAD_DIRECTION (object));
656 case PAD_PROP_TEMPLATE:
657 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
660 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
667 * @name: the name of the new pad.
668 * @direction: the #GstPadDirection of the pad.
670 * Creates a new pad with the given name in the given direction.
671 * If name is NULL, a guaranteed unique name (across all pads)
673 * This function makes a copy of the name so you can safely free the name.
675 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
680 gst_pad_new (const gchar * name, GstPadDirection direction)
682 return g_object_new (GST_TYPE_PAD,
683 "name", name, "direction", direction, NULL);
687 * gst_pad_new_from_template:
688 * @templ: the pad template to use
689 * @name: the name of the element
691 * Creates a new pad with the given name from the given template.
692 * If name is NULL, a guaranteed unique name (across all pads)
694 * This function makes a copy of the name so you can safely free the name.
696 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
699 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
701 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
703 return g_object_new (GST_TYPE_PAD,
704 "name", name, "direction", templ->direction, "template", templ, NULL);
708 * gst_pad_new_from_static_template:
709 * @templ: the #GstStaticPadTemplate to use
710 * @name: the name of the element
712 * Creates a new pad with the given name from the given static template.
713 * If name is NULL, a guaranteed unique name (across all pads)
715 * This function makes a copy of the name so you can safely free the name.
717 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
720 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
724 GstPadTemplate *template;
726 template = gst_static_pad_template_get (templ);
727 pad = gst_pad_new_from_template (template, name);
728 gst_object_unref (template);
732 #define ACQUIRE_PARENT(pad, parent, label) \
734 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
735 gst_object_ref (parent); \
736 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
740 #define RELEASE_PARENT(parent) \
742 if (G_LIKELY (parent)) \
743 gst_object_unref (parent); \
747 * gst_pad_get_direction:
748 * @pad: a #GstPad to get the direction of.
750 * Gets the direction of the pad. The direction of the pad is
751 * decided at construction time so this function does not take
754 * Returns: the #GstPadDirection of the pad.
759 gst_pad_get_direction (GstPad * pad)
761 GstPadDirection result;
763 /* PAD_UNKNOWN is a little silly but we need some sort of
764 * error return value */
765 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
767 result = GST_PAD_DIRECTION (pad);
773 gst_pad_activate_default (GstPad * pad, GstObject * parent)
775 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
779 pre_activate (GstPad * pad, GstPadMode new_mode)
782 case GST_PAD_MODE_NONE:
783 GST_OBJECT_LOCK (pad);
784 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
785 GST_PAD_SET_FLUSHING (pad);
786 GST_PAD_MODE (pad) = new_mode;
787 /* unlock blocked pads so element can resume and stop */
788 GST_PAD_BLOCK_BROADCAST (pad);
789 GST_OBJECT_UNLOCK (pad);
791 case GST_PAD_MODE_PUSH:
792 case GST_PAD_MODE_PULL:
793 GST_OBJECT_LOCK (pad);
794 GST_DEBUG_OBJECT (pad, "setting PAD_MODE %d, unset flushing", new_mode);
795 GST_PAD_UNSET_FLUSHING (pad);
796 GST_PAD_MODE (pad) = new_mode;
797 if (GST_PAD_IS_SINK (pad)) {
799 /* make sure the peer src pad sends us all events */
800 if ((peer = GST_PAD_PEER (pad))) {
801 gst_object_ref (peer);
802 GST_OBJECT_UNLOCK (pad);
804 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
805 GST_DEBUG_PAD_NAME (peer));
807 GST_OBJECT_LOCK (peer);
808 schedule_events (peer, NULL);
809 GST_OBJECT_UNLOCK (peer);
811 gst_object_unref (peer);
813 GST_OBJECT_UNLOCK (pad);
816 GST_OBJECT_UNLOCK (pad);
823 post_activate (GstPad * pad, GstPadMode new_mode)
826 case GST_PAD_MODE_NONE:
827 /* ensures that streaming stops */
828 GST_PAD_STREAM_LOCK (pad);
829 GST_DEBUG_OBJECT (pad, "stopped streaming");
830 GST_OBJECT_LOCK (pad);
832 GST_OBJECT_UNLOCK (pad);
833 GST_PAD_STREAM_UNLOCK (pad);
835 case GST_PAD_MODE_PUSH:
836 case GST_PAD_MODE_PULL:
843 * gst_pad_set_active:
844 * @pad: the #GstPad to activate or deactivate.
845 * @active: whether or not the pad should be active.
847 * Activates or deactivates the given pad.
848 * Normally called from within core state change functions.
850 * If @active, makes sure the pad is active. If it is already active, either in
851 * push or pull mode, just return. Otherwise dispatches to the pad's activate
852 * function to perform the actual activation.
854 * If not @active, checks the pad's current mode and calls
855 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
858 * Returns: #TRUE if the operation was successful.
863 gst_pad_set_active (GstPad * pad, gboolean active)
867 gboolean ret = FALSE;
869 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
871 GST_OBJECT_LOCK (pad);
872 old = GST_PAD_MODE (pad);
873 ACQUIRE_PARENT (pad, parent, no_parent);
874 GST_OBJECT_UNLOCK (pad);
877 if (old == GST_PAD_MODE_NONE) {
878 GST_DEBUG_OBJECT (pad, "activating pad from none");
879 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
881 GST_DEBUG_OBJECT (pad, "pad was active in mode %d", old);
885 if (old == GST_PAD_MODE_NONE) {
886 GST_DEBUG_OBJECT (pad, "pad was inactive");
889 GST_DEBUG_OBJECT (pad, "deactivating pad from mode %d", old);
890 ret = gst_pad_activate_mode (pad, old, FALSE);
894 RELEASE_PARENT (parent);
896 if (G_UNLIKELY (!ret))
900 GST_OBJECT_LOCK (pad);
901 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
902 GST_OBJECT_UNLOCK (pad);
909 GST_DEBUG_OBJECT (pad, "no parent");
910 GST_OBJECT_UNLOCK (pad);
915 GST_OBJECT_LOCK (pad);
917 g_critical ("Failed to deactivate pad %s:%s, very bad",
918 GST_DEBUG_PAD_NAME (pad));
920 GST_WARNING_OBJECT (pad, "Failed to activate pad");
922 GST_OBJECT_UNLOCK (pad);
928 * gst_pad_activate_mode:
929 * @pad: the #GstPad to activate or deactivate.
930 * @mode: the requested activation mode
931 * @active: whether or not the pad should be active.
933 * Activates or deactivates the given pad in @mode via dispatching to the
934 * pad's activatemodefunc. For use from within pad activation functions only.
936 * If you don't know what this is, you probably don't want to call it.
938 * Returns: TRUE if the operation was successful.
943 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
945 gboolean res = FALSE;
951 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
953 GST_OBJECT_LOCK (pad);
954 old = GST_PAD_MODE (pad);
955 dir = GST_PAD_DIRECTION (pad);
956 ACQUIRE_PARENT (pad, parent, no_parent);
957 GST_OBJECT_UNLOCK (pad);
959 new = active ? mode : GST_PAD_MODE_NONE;
964 if (active && old != mode) {
965 /* pad was activate in the wrong direction, deactivate it
966 * and reactivate it in the requested mode */
967 GST_DEBUG_OBJECT (pad, "deactivating pad from mode %d", old);
968 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
969 goto deactivate_failed;
973 case GST_PAD_MODE_PULL:
975 if (dir == GST_PAD_SINK) {
976 if ((peer = gst_pad_get_peer (pad))) {
977 GST_DEBUG_OBJECT (pad, "calling peer");
978 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
980 gst_object_unref (peer);
982 /* there is no peer, this is only fatal when we activate. When we
983 * deactivate, we must assume the application has unlinked the peer and
984 * will deactivate it eventually. */
988 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
991 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
992 goto failure; /* Can't activate pull on a src without a
1001 pre_activate (pad, new);
1003 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1004 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1008 /* can happen for sinks of passthrough elements */
1011 post_activate (pad, new);
1013 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in mode %d",
1014 active ? "activated" : "deactivated", mode);
1019 RELEASE_PARENT (parent);
1025 GST_DEBUG_OBJECT (pad, "no parent");
1026 GST_OBJECT_UNLOCK (pad);
1031 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in mode %d",
1032 active ? "activated" : "deactivated", mode);
1037 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1038 "failed to %s in switch to mode %d from mode %d",
1039 (active ? "activate" : "deactivate"), mode, old);
1044 GST_OBJECT_LOCK (peer);
1045 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1046 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1047 GST_OBJECT_UNLOCK (peer);
1048 gst_object_unref (peer);
1053 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1054 "pad in pull mode");
1059 GST_OBJECT_LOCK (pad);
1060 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in mode %d",
1061 active ? "activate" : "deactivate", mode);
1062 GST_PAD_SET_FLUSHING (pad);
1063 GST_PAD_MODE (pad) = old;
1064 GST_OBJECT_UNLOCK (pad);
1070 * gst_pad_is_active:
1071 * @pad: the #GstPad to query
1073 * Query if a pad is active
1075 * Returns: TRUE if the pad is active.
1080 gst_pad_is_active (GstPad * pad)
1082 gboolean result = FALSE;
1084 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1086 GST_OBJECT_LOCK (pad);
1087 result = GST_PAD_IS_ACTIVE (pad);
1088 GST_OBJECT_UNLOCK (pad);
1094 * gst_pad_add_probe:
1095 * @pad: the #GstPad to add the probe to
1096 * @mask: the probe mask
1097 * @callback: #GstPadProbeCallback that will be called with notifications of
1099 * @user_data: (closure): user data passed to the callback
1100 * @destroy_data: #GDestroyNotify for user_data
1102 * Be notified of different states of pads. The provided callback is called for
1103 * every state that matches @mask.
1105 * Returns: an id or 0 on error. The id can be used to remove the probe with
1106 * gst_pad_remove_probe().
1111 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1112 GstPadProbeCallback callback, gpointer user_data,
1113 GDestroyNotify destroy_data)
1118 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1119 g_return_val_if_fail (mask != 0, 0);
1121 GST_OBJECT_LOCK (pad);
1123 /* make a new probe */
1124 hook = g_hook_alloc (&pad->probes);
1126 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1129 /* when no contraints are given for the types, assume all types are
1131 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1132 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1133 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1134 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1136 /* store our flags and other fields */
1137 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1138 hook->func = callback;
1139 hook->data = user_data;
1140 hook->destroy = destroy_data;
1141 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1144 g_hook_prepend (&pad->probes, hook);
1146 /* incremenent cookie so that the new hook get's called */
1147 pad->priv->probe_list_cookie++;
1149 /* get the id of the hook, we return this and it can be used to remove the
1151 res = hook->hook_id;
1153 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1155 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1156 /* we have a block probe */
1158 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1159 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1160 "now %d blocking probes", pad->num_blocked);
1163 /* call the callback if we need to be called for idle callbacks */
1164 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1165 if (pad->priv->using > 0) {
1166 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1167 * flag above, the last thread to leave the push will do the callback. New
1168 * threads going into the push will block. */
1169 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1170 "pad is in use, delay idle callback");
1171 GST_OBJECT_UNLOCK (pad);
1173 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, };
1175 /* the pad is idle now, we can signal the idle callback now */
1176 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1177 "pad is idle, trigger idle callback");
1178 GST_OBJECT_UNLOCK (pad);
1180 callback (pad, &info, user_data);
1183 GST_OBJECT_UNLOCK (pad);
1189 cleanup_hook (GstPad * pad, GHook * hook)
1191 GstPadProbeType type;
1193 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1195 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1196 /* unblock when we remove the last blocking probe */
1198 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1200 if (pad->num_blocked == 0) {
1201 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1202 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1203 GST_PAD_BLOCK_BROADCAST (pad);
1206 g_hook_destroy_link (&pad->probes, hook);
1211 * gst_pad_remove_probe:
1212 * @pad: the #GstPad with the probe
1213 * @id: the probe id to remove
1215 * Remove the probe with @id from @pad.
1220 gst_pad_remove_probe (GstPad * pad, gulong id)
1224 g_return_if_fail (GST_IS_PAD (pad));
1226 GST_OBJECT_LOCK (pad);
1228 hook = g_hook_get (&pad->probes, id);
1232 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1234 cleanup_hook (pad, hook);
1235 GST_OBJECT_UNLOCK (pad);
1241 GST_OBJECT_UNLOCK (pad);
1242 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1248 * gst_pad_is_blocked:
1249 * @pad: the #GstPad to query
1251 * Checks if the pad is blocked or not. This function returns the
1252 * last requested state of the pad. It is not certain that the pad
1253 * is actually blocking at this point (see gst_pad_is_blocking()).
1255 * Returns: TRUE if the pad is blocked.
1260 gst_pad_is_blocked (GstPad * pad)
1262 gboolean result = FALSE;
1264 g_return_val_if_fail (GST_IS_PAD (pad), result);
1266 GST_OBJECT_LOCK (pad);
1267 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1268 GST_OBJECT_UNLOCK (pad);
1274 * gst_pad_is_blocking:
1275 * @pad: the #GstPad to query
1277 * Checks if the pad is blocking or not. This is a guaranteed state
1278 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1280 * Returns: TRUE if the pad is blocking.
1287 gst_pad_is_blocking (GstPad * pad)
1289 gboolean result = FALSE;
1291 g_return_val_if_fail (GST_IS_PAD (pad), result);
1293 GST_OBJECT_LOCK (pad);
1294 /* the blocking flag is only valid if the pad is not flushing */
1295 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1296 GST_OBJECT_UNLOCK (pad);
1302 * gst_pad_check_reconfigure:
1303 * @pad: the #GstPad to check
1305 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1306 * if the flag was set.
1308 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1311 gst_pad_check_reconfigure (GstPad * pad)
1313 gboolean reconfigure;
1315 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1317 GST_OBJECT_LOCK (pad);
1318 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1319 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1320 GST_OBJECT_UNLOCK (pad);
1326 * gst_pad_mark_reconfigure:
1327 * @pad: the #GstPad to mark
1329 * Mark a pad for needing reconfiguration. The next call to
1330 * gst_pad_check_reconfigure() will return %TRUE after this call.
1333 gst_pad_mark_reconfigure (GstPad * pad)
1335 g_return_if_fail (GST_IS_PAD (pad));
1337 GST_OBJECT_LOCK (pad);
1338 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1339 GST_OBJECT_UNLOCK (pad);
1343 * gst_pad_set_activate_function_full:
1345 * @activate: the #GstPadActivateFunction to set.
1346 * @notify: notify called when @activate will not be used anymore.
1348 * Sets the given activate function for @pad. The activate function will
1349 * dispatch to gst_pad_activate_push() or gst_pad_activate_pull() to perform
1350 * the actual activation. Only makes sense to set on sink pads.
1352 * Call this function if your sink pad can start a pull-based task.
1355 gst_pad_set_activate_function_full (GstPad * pad,
1356 GstPadActivateFunction activate, GDestroyNotify notify)
1358 g_return_if_fail (GST_IS_PAD (pad));
1360 if (pad->activatenotify)
1361 pad->activatenotify (pad);
1362 GST_PAD_ACTIVATEFUNC (pad) = activate;
1363 pad->activatenotify = notify;
1365 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1366 GST_DEBUG_FUNCPTR_NAME (activate));
1370 * gst_pad_set_activatemode_function_full:
1372 * @activatemode: the #GstPadActivateModeFunction to set.
1373 * @notify: notify called when @activatemode will not be used anymore.
1375 * Sets the given activate_mode function for the pad. An activate_mode function
1376 * prepares the element for data passing.
1379 gst_pad_set_activatemode_function_full (GstPad * pad,
1380 GstPadActivateModeFunction activatemode, GDestroyNotify notify)
1382 g_return_if_fail (GST_IS_PAD (pad));
1384 if (pad->activatemodenotify)
1385 pad->activatemodenotify (pad);
1386 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1387 pad->activatemodenotify = notify;
1389 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1390 GST_DEBUG_FUNCPTR_NAME (activatemode));
1394 * gst_pad_set_chain_function_full:
1395 * @pad: a sink #GstPad.
1396 * @chain: the #GstPadChainFunction to set.
1397 * @notify: notify called when @chain will not be used anymore.
1399 * Sets the given chain function for the pad. The chain function is called to
1400 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1403 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1404 GDestroyNotify notify)
1406 g_return_if_fail (GST_IS_PAD (pad));
1407 g_return_if_fail (GST_PAD_IS_SINK (pad));
1409 if (pad->chainnotify)
1410 pad->chainnotify (pad);
1411 GST_PAD_CHAINFUNC (pad) = chain;
1412 pad->chainnotify = notify;
1414 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1415 GST_DEBUG_FUNCPTR_NAME (chain));
1419 * gst_pad_set_chain_list_function_full:
1420 * @pad: a sink #GstPad.
1421 * @chainlist: the #GstPadChainListFunction to set.
1422 * @notify: notify called when @chainlist will not be used anymore.
1424 * Sets the given chain list function for the pad. The chainlist function is
1425 * called to process a #GstBufferList input buffer list. See
1426 * #GstPadChainListFunction for more details.
1431 gst_pad_set_chain_list_function_full (GstPad * pad,
1432 GstPadChainListFunction chainlist, GDestroyNotify notify)
1434 g_return_if_fail (GST_IS_PAD (pad));
1435 g_return_if_fail (GST_PAD_IS_SINK (pad));
1437 if (pad->chainlistnotify)
1438 pad->chainlistnotify (pad);
1439 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1440 pad->chainlistnotify = notify;
1442 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1443 GST_DEBUG_FUNCPTR_NAME (chainlist));
1447 * gst_pad_set_getrange_function_full:
1448 * @pad: a source #GstPad.
1449 * @get: the #GstPadGetRangeFunction to set.
1450 * @notify: notify called when @get will not be used anymore.
1452 * Sets the given getrange function for the pad. The getrange function is
1453 * called to produce a new #GstBuffer to start the processing pipeline. see
1454 * #GstPadGetRangeFunction for a description of the getrange function.
1457 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1458 GDestroyNotify notify)
1460 g_return_if_fail (GST_IS_PAD (pad));
1461 g_return_if_fail (GST_PAD_IS_SRC (pad));
1463 if (pad->getrangenotify)
1464 pad->getrangenotify (pad);
1465 GST_PAD_GETRANGEFUNC (pad) = get;
1466 pad->getrangenotify = notify;
1468 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1469 GST_DEBUG_FUNCPTR_NAME (get));
1473 * gst_pad_set_event_function_full:
1474 * @pad: a #GstPad of either direction.
1475 * @event: the #GstPadEventFunction to set.
1476 * @notify: notify called when @event will not be used anymore.
1478 * Sets the given event handler for the pad.
1481 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1482 GDestroyNotify notify)
1484 g_return_if_fail (GST_IS_PAD (pad));
1486 if (pad->eventnotify)
1487 pad->eventnotify (pad);
1488 GST_PAD_EVENTFUNC (pad) = event;
1489 pad->eventnotify = notify;
1491 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1492 GST_DEBUG_FUNCPTR_NAME (event));
1496 * gst_pad_set_query_function_full:
1497 * @pad: a #GstPad of either direction.
1498 * @query: the #GstPadQueryFunction to set.
1499 * @notify: notify called when @query will not be used anymore.
1501 * Set the given query function for the pad.
1504 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1505 GDestroyNotify notify)
1507 g_return_if_fail (GST_IS_PAD (pad));
1509 if (pad->querynotify)
1510 pad->querynotify (pad);
1511 GST_PAD_QUERYFUNC (pad) = query;
1512 pad->querynotify = notify;
1514 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1515 GST_DEBUG_FUNCPTR_NAME (query));
1519 * gst_pad_set_iterate_internal_links_function_full:
1520 * @pad: a #GstPad of either direction.
1521 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1522 * @notify: notify called when @iterintlink will not be used anymore.
1524 * Sets the given internal link iterator function for the pad.
1529 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1530 GstPadIterIntLinkFunction iterintlink, GDestroyNotify notify)
1532 g_return_if_fail (GST_IS_PAD (pad));
1534 if (pad->iterintlinknotify)
1535 pad->iterintlinknotify (pad);
1536 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1537 pad->iterintlinknotify = notify;
1539 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1540 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1544 * gst_pad_set_link_function_full:
1546 * @link: the #GstPadLinkFunction to set.
1547 * @notify: notify called when @link will not be used anymore.
1549 * Sets the given link function for the pad. It will be called when
1550 * the pad is linked with another pad.
1552 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1555 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1556 * cannot be made for some reason.
1558 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1559 * of the peer sink pad, if present.
1562 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1563 GDestroyNotify notify)
1565 g_return_if_fail (GST_IS_PAD (pad));
1567 if (pad->linknotify)
1568 pad->linknotify (pad);
1569 GST_PAD_LINKFUNC (pad) = link;
1570 pad->linknotify = notify;
1572 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1573 GST_DEBUG_FUNCPTR_NAME (link));
1577 * gst_pad_set_unlink_function_full:
1579 * @unlink: the #GstPadUnlinkFunction to set.
1580 * @notify: notify called when @unlink will not be used anymore.
1582 * Sets the given unlink function for the pad. It will be called
1583 * when the pad is unlinked.
1586 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1587 GDestroyNotify notify)
1589 g_return_if_fail (GST_IS_PAD (pad));
1591 if (pad->unlinknotify)
1592 pad->unlinknotify (pad);
1593 GST_PAD_UNLINKFUNC (pad) = unlink;
1594 pad->unlinknotify = notify;
1596 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1597 GST_DEBUG_FUNCPTR_NAME (unlink));
1602 * @srcpad: the source #GstPad to unlink.
1603 * @sinkpad: the sink #GstPad to unlink.
1605 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1606 * signal on both pads.
1608 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1609 * the pads were not linked together.
1614 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1616 gboolean result = FALSE;
1617 GstElement *parent = NULL;
1619 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1620 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1621 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1622 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1624 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1625 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1626 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1628 /* We need to notify the parent before taking any pad locks as the bin in
1629 * question might be waiting for a lock on the pad while holding its lock
1630 * that our message will try to take. */
1631 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1632 if (GST_IS_ELEMENT (parent)) {
1633 gst_element_post_message (parent,
1634 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1635 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1637 gst_object_unref (parent);
1642 GST_OBJECT_LOCK (srcpad);
1643 GST_OBJECT_LOCK (sinkpad);
1645 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1646 goto not_linked_together;
1648 if (GST_PAD_UNLINKFUNC (srcpad)) {
1649 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1651 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1652 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1655 /* first clear peers */
1656 GST_PAD_PEER (srcpad) = NULL;
1657 GST_PAD_PEER (sinkpad) = NULL;
1659 GST_OBJECT_UNLOCK (sinkpad);
1660 GST_OBJECT_UNLOCK (srcpad);
1662 /* fire off a signal to each of the pads telling them
1663 * that they've been unlinked */
1664 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1665 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1667 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1668 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1673 if (parent != NULL) {
1674 gst_element_post_message (parent,
1675 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1676 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1677 gst_object_unref (parent);
1682 not_linked_together:
1684 /* we do not emit a warning in this case because unlinking cannot
1685 * be made MT safe.*/
1686 GST_OBJECT_UNLOCK (sinkpad);
1687 GST_OBJECT_UNLOCK (srcpad);
1693 * gst_pad_is_linked:
1694 * @pad: pad to check
1696 * Checks if a @pad is linked to another pad or not.
1698 * Returns: TRUE if the pad is linked, FALSE otherwise.
1703 gst_pad_is_linked (GstPad * pad)
1707 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1709 GST_OBJECT_LOCK (pad);
1710 result = (GST_PAD_PEER (pad) != NULL);
1711 GST_OBJECT_UNLOCK (pad);
1716 /* get the caps from both pads and see if the intersection
1719 * This function should be called with the pad LOCK on both
1723 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1724 GstPadLinkCheck flags)
1726 GstCaps *srccaps = NULL;
1727 GstCaps *sinkcaps = NULL;
1728 gboolean compatible = FALSE;
1730 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1733 /* Doing the expensive caps checking takes priority over only checking the template caps */
1734 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1735 GST_OBJECT_UNLOCK (sink);
1736 GST_OBJECT_UNLOCK (src);
1738 srccaps = gst_pad_query_caps (src, NULL);
1739 sinkcaps = gst_pad_query_caps (sink, NULL);
1741 GST_OBJECT_LOCK (src);
1742 GST_OBJECT_LOCK (sink);
1744 /* If one of the two pads doesn't have a template, consider the intersection
1746 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
1747 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
1751 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
1753 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
1756 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
1758 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
1761 /* if we have caps on both pads we can check the intersection. If one
1762 * of the caps is NULL, we return TRUE. */
1763 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1765 gst_caps_unref (srccaps);
1767 gst_caps_unref (sinkcaps);
1771 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
1772 gst_caps_unref (srccaps);
1773 gst_caps_unref (sinkcaps);
1776 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
1777 (compatible ? "" : "not"));
1782 /* check if the grandparents of both pads are the same.
1783 * This check is required so that we don't try to link
1784 * pads from elements in different bins without ghostpads.
1786 * The LOCK should be held on both pads
1789 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1791 GstObject *psrc, *psink;
1793 psrc = GST_OBJECT_PARENT (src);
1794 psink = GST_OBJECT_PARENT (sink);
1796 /* if one of the pads has no parent, we allow the link */
1797 if (G_UNLIKELY (psrc == NULL || psink == NULL))
1800 /* only care about parents that are elements */
1801 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
1802 goto no_element_parent;
1804 /* if the parents are the same, we have a loop */
1805 if (G_UNLIKELY (psrc == psink))
1808 /* if they both have a parent, we check the grandparents. We can not lock
1809 * the parent because we hold on the child (pad) and the locking order is
1810 * parent >> child. */
1811 psrc = GST_OBJECT_PARENT (psrc);
1812 psink = GST_OBJECT_PARENT (psink);
1814 /* if they have grandparents but they are not the same */
1815 if (G_UNLIKELY (psrc != psink))
1816 goto wrong_grandparents;
1823 GST_CAT_DEBUG (GST_CAT_CAPS,
1824 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
1825 GST_PTR_FORMAT, psrc, psink);
1830 GST_CAT_DEBUG (GST_CAT_CAPS,
1831 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
1832 GST_PTR_FORMAT, psrc, psink);
1837 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1843 GST_CAT_DEBUG (GST_CAT_CAPS,
1844 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1845 GST_PTR_FORMAT, psrc, psink);
1850 /* FIXME leftover from an attempt at refactoring... */
1851 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
1852 * the two pads will be locked in the srcpad, sinkpad order. */
1853 static GstPadLinkReturn
1854 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
1856 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1857 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1859 GST_OBJECT_LOCK (srcpad);
1861 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1862 goto src_was_linked;
1864 GST_OBJECT_LOCK (sinkpad);
1866 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1867 goto sink_was_linked;
1869 /* check hierarchy, pads can only be linked if the grandparents
1871 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
1872 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
1873 goto wrong_hierarchy;
1875 /* check pad caps for non-empty intersection */
1876 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
1879 /* FIXME check pad scheduling for non-empty intersection */
1881 return GST_PAD_LINK_OK;
1885 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
1886 GST_DEBUG_PAD_NAME (srcpad),
1887 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
1888 /* we do not emit a warning in this case because unlinking cannot
1889 * be made MT safe.*/
1890 GST_OBJECT_UNLOCK (srcpad);
1891 return GST_PAD_LINK_WAS_LINKED;
1895 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
1896 GST_DEBUG_PAD_NAME (sinkpad),
1897 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
1898 /* we do not emit a warning in this case because unlinking cannot
1899 * be made MT safe.*/
1900 GST_OBJECT_UNLOCK (sinkpad);
1901 GST_OBJECT_UNLOCK (srcpad);
1902 return GST_PAD_LINK_WAS_LINKED;
1906 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
1907 GST_OBJECT_UNLOCK (sinkpad);
1908 GST_OBJECT_UNLOCK (srcpad);
1909 return GST_PAD_LINK_WRONG_HIERARCHY;
1913 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1914 GST_OBJECT_UNLOCK (sinkpad);
1915 GST_OBJECT_UNLOCK (srcpad);
1916 return GST_PAD_LINK_NOFORMAT;
1922 * @srcpad: the source #GstPad.
1923 * @sinkpad: the sink #GstPad.
1925 * Checks if the source pad and the sink pad are compatible so they can be
1928 * Returns: TRUE if the pads can be linked.
1931 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1933 GstPadLinkReturn result;
1935 /* generic checks */
1936 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1937 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1939 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
1940 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1942 /* gst_pad_link_prepare does everything for us, we only release the locks
1943 * on the pads that it gets us. If this function returns !OK the locks are not
1945 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
1946 if (result != GST_PAD_LINK_OK)
1949 GST_OBJECT_UNLOCK (srcpad);
1950 GST_OBJECT_UNLOCK (sinkpad);
1953 return result == GST_PAD_LINK_OK;
1957 * gst_pad_link_full:
1958 * @srcpad: the source #GstPad to link.
1959 * @sinkpad: the sink #GstPad to link.
1960 * @flags: the checks to validate when linking
1962 * Links the source pad and the sink pad.
1964 * This variant of #gst_pad_link provides a more granular control on the
1965 * checks being done when linking. While providing some considerable speedups
1966 * the caller of this method must be aware that wrong usage of those flags
1967 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
1968 * for more information.
1972 * Returns: A result code indicating if the connection worked or
1978 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
1980 GstPadLinkReturn result;
1982 GstPadLinkFunction srcfunc, sinkfunc;
1984 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
1985 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
1986 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
1987 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
1988 GST_PAD_LINK_WRONG_DIRECTION);
1990 /* Notify the parent early. See gst_pad_unlink for details. */
1991 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
1992 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
1993 gst_element_post_message (parent,
1994 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1995 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
1997 gst_object_unref (parent);
2002 /* prepare will also lock the two pads */
2003 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2005 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2008 /* must set peers before calling the link function */
2009 GST_PAD_PEER (srcpad) = sinkpad;
2010 GST_PAD_PEER (sinkpad) = srcpad;
2012 /* check events, when something is different, mark pending */
2013 schedule_events (srcpad, sinkpad);
2015 /* get the link functions */
2016 srcfunc = GST_PAD_LINKFUNC (srcpad);
2017 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2019 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2020 /* custom link functions, execute them */
2021 GST_OBJECT_UNLOCK (sinkpad);
2022 GST_OBJECT_UNLOCK (srcpad);
2025 /* this one will call the peer link function */
2026 result = srcfunc (srcpad, sinkpad);
2027 } else if (sinkfunc) {
2028 /* if no source link function, we need to call the sink link
2029 * function ourselves. */
2030 result = sinkfunc (sinkpad, srcpad);
2033 GST_OBJECT_LOCK (srcpad);
2034 GST_OBJECT_LOCK (sinkpad);
2036 /* we released the lock, check if the same pads are linked still */
2037 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2038 goto concurrent_link;
2040 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2043 GST_OBJECT_UNLOCK (sinkpad);
2044 GST_OBJECT_UNLOCK (srcpad);
2046 /* fire off a signal to each of the pads telling them
2047 * that they've been linked */
2048 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2049 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2051 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2052 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2054 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2057 if (G_LIKELY (parent)) {
2058 gst_element_post_message (parent,
2059 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2060 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2061 gst_object_unref (parent);
2069 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2070 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2071 GST_OBJECT_UNLOCK (sinkpad);
2072 GST_OBJECT_UNLOCK (srcpad);
2074 /* The other link operation succeeded first */
2075 result = GST_PAD_LINK_WAS_LINKED;
2080 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2081 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2083 GST_PAD_PEER (srcpad) = NULL;
2084 GST_PAD_PEER (sinkpad) = NULL;
2086 GST_OBJECT_UNLOCK (sinkpad);
2087 GST_OBJECT_UNLOCK (srcpad);
2095 * @srcpad: the source #GstPad to link.
2096 * @sinkpad: the sink #GstPad to link.
2098 * Links the source pad and the sink pad.
2100 * Returns: A result code indicating if the connection worked or
2106 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2108 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2112 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2114 GstPadTemplate **template_p;
2116 /* this function would need checks if it weren't static */
2118 GST_OBJECT_LOCK (pad);
2119 template_p = &pad->padtemplate;
2120 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2121 GST_OBJECT_UNLOCK (pad);
2124 gst_pad_template_pad_created (templ, pad);
2128 * gst_pad_get_pad_template:
2131 * Gets the template for @pad.
2133 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2134 * instantiated, or %NULL if this pad has no template. Unref after
2138 gst_pad_get_pad_template (GstPad * pad)
2140 GstPadTemplate *templ;
2142 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2144 templ = GST_PAD_PAD_TEMPLATE (pad);
2146 return (templ ? gst_object_ref (templ) : NULL);
2150 * gst_pad_has_current_caps:
2151 * @pad: a #GstPad to check
2153 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2155 * Returns: TRUE when @pad has caps associated with it.
2158 gst_pad_has_current_caps (GstPad * pad)
2163 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2165 GST_OBJECT_LOCK (pad);
2166 caps = get_pad_caps (pad);
2167 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2168 "check current pad caps %" GST_PTR_FORMAT, caps);
2169 result = (caps != NULL);
2170 GST_OBJECT_UNLOCK (pad);
2176 * gst_pad_get_current_caps:
2177 * @pad: a #GstPad to get the current capabilities of.
2179 * Gets the capabilities currently configured on @pad with the last
2180 * #GST_EVENT_CAPS event.
2182 * Returns: the current caps of the pad with incremented ref-count.
2185 gst_pad_get_current_caps (GstPad * pad)
2189 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2191 GST_OBJECT_LOCK (pad);
2192 if ((result = get_pad_caps (pad)))
2193 gst_caps_ref (result);
2194 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2195 "get current pad caps %" GST_PTR_FORMAT, result);
2196 GST_OBJECT_UNLOCK (pad);
2203 * @pad: a #GstPad to set the capabilities of.
2204 * @caps: (transfer none): a #GstCaps to set.
2206 * Sets the capabilities of this pad. The caps must be fixed. Any previous
2207 * caps on the pad will be unreffed. This function refs the caps so you should
2208 * unref if as soon as you don't need it anymore.
2209 * It is possible to set NULL caps, which will make the pad unnegotiated
2212 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
2213 * or bad parameters were provided to this function.
2218 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
2221 gboolean res = TRUE;
2223 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2224 g_return_val_if_fail (caps != NULL && gst_caps_is_fixed (caps), FALSE);
2226 event = gst_event_new_caps (caps);
2228 if (GST_PAD_IS_SRC (pad))
2229 res = gst_pad_push_event (pad, event);
2231 res = gst_pad_send_event (pad, event);
2237 * gst_pad_get_pad_template_caps:
2238 * @pad: a #GstPad to get the template capabilities from.
2240 * Gets the capabilities for @pad's template.
2242 * Returns: (transfer full): the #GstCaps of this pad template.
2243 * Unref after usage.
2246 gst_pad_get_pad_template_caps (GstPad * pad)
2248 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2250 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2252 if (GST_PAD_PAD_TEMPLATE (pad))
2253 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2255 return gst_static_caps_get (&anycaps);
2260 * @pad: a #GstPad to get the peer of.
2262 * Gets the peer of @pad. This function refs the peer pad so
2263 * you need to unref it after use.
2265 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2270 gst_pad_get_peer (GstPad * pad)
2274 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2276 GST_OBJECT_LOCK (pad);
2277 result = GST_PAD_PEER (pad);
2279 gst_object_ref (result);
2280 GST_OBJECT_UNLOCK (pad);
2286 * gst_pad_get_allowed_caps:
2289 * Gets the capabilities of the allowed media types that can flow through
2290 * @pad and its peer.
2292 * The allowed capabilities is calculated as the intersection of the results of
2293 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2294 * on the resulting caps.
2296 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2297 * caps when you no longer need it. This function returns NULL when @pad
2303 gst_pad_get_allowed_caps (GstPad * pad)
2310 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2312 GST_OBJECT_LOCK (pad);
2313 peer = GST_PAD_PEER (pad);
2314 if (G_UNLIKELY (peer == NULL))
2317 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2319 gst_object_ref (peer);
2320 GST_OBJECT_UNLOCK (pad);
2321 mycaps = gst_pad_query_caps (pad, NULL);
2323 peercaps = gst_pad_query_caps (peer, NULL);
2324 gst_object_unref (peer);
2326 caps = gst_caps_intersect (mycaps, peercaps);
2327 gst_caps_unref (peercaps);
2328 gst_caps_unref (mycaps);
2330 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2337 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2338 GST_OBJECT_UNLOCK (pad);
2345 * gst_pad_iterate_internal_links_default:
2346 * @pad: the #GstPad to get the internal links of.
2347 * @parent: the parent of @pad or NULL
2349 * Iterate the list of pads to which the given pad is linked to inside of
2350 * the parent element.
2351 * This is the default handler, and thus returns an iterator of all of the
2352 * pads inside the parent element with opposite direction.
2354 * The caller must free this iterator after use with gst_iterator_free().
2356 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2357 * returned pad with gst_object_unref().
2362 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2369 GstElement *eparent;
2371 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2373 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2374 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2376 GST_OBJECT_LOCK (pad);
2377 eparent = GST_PAD_PARENT (pad);
2378 if (!eparent || !GST_IS_ELEMENT (eparent))
2381 gst_object_ref (eparent);
2382 GST_OBJECT_UNLOCK (pad);
2385 if (pad->direction == GST_PAD_SRC)
2386 padlist = &eparent->sinkpads;
2388 padlist = &eparent->srcpads;
2390 GST_DEBUG_OBJECT (pad, "Making iterator");
2392 cookie = &eparent->pads_cookie;
2394 lock = GST_OBJECT_GET_LOCK (eparent);
2396 res = gst_iterator_new_list (GST_TYPE_PAD,
2397 lock, cookie, padlist, (GObject *) owner, NULL);
2399 gst_object_unref (owner);
2406 GST_OBJECT_UNLOCK (pad);
2407 GST_DEBUG_OBJECT (pad, "no parent element");
2413 * gst_pad_iterate_internal_links:
2414 * @pad: the GstPad to get the internal links of.
2416 * Gets an iterator for the pads to which the given pad is linked to inside
2417 * of the parent element.
2419 * Each #GstPad element yielded by the iterator will have its refcount increased,
2420 * so unref after use.
2422 * Free-function: gst_iterator_free
2424 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2425 * pad does not have an iterator function configured. Use
2426 * gst_iterator_free() after usage.
2431 gst_pad_iterate_internal_links (GstPad * pad)
2433 GstIterator *res = NULL;
2436 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2438 GST_OBJECT_LOCK (pad);
2439 ACQUIRE_PARENT (pad, parent, no_parent);
2440 GST_OBJECT_UNLOCK (pad);
2442 if (GST_PAD_ITERINTLINKFUNC (pad))
2443 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2445 RELEASE_PARENT (parent);
2452 GST_DEBUG_OBJECT (pad, "no parent");
2453 GST_OBJECT_UNLOCK (pad);
2461 * @forward: a #GstPadForwardFunction
2462 * @user_data: user data passed to @forward
2464 * Calls @forward for all internally linked pads of @pad. This function deals with
2465 * dynamically changing internal pads and will make sure that the @forward
2466 * function is only called once for each pad.
2468 * When @forward returns TRUE, no further pads will be processed.
2470 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2473 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2476 gboolean result = FALSE;
2478 gboolean done = FALSE;
2479 GValue item = { 0, };
2480 GList *pushed_pads = NULL;
2482 iter = gst_pad_iterate_internal_links (pad);
2488 switch (gst_iterator_next (iter, &item)) {
2489 case GST_ITERATOR_OK:
2493 intpad = g_value_get_object (&item);
2495 /* if already pushed, skip. FIXME, find something faster to tag pads */
2496 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2497 g_value_reset (&item);
2501 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2502 GST_DEBUG_PAD_NAME (intpad));
2503 done = result = forward (intpad, user_data);
2505 pushed_pads = g_list_prepend (pushed_pads, intpad);
2507 g_value_reset (&item);
2510 case GST_ITERATOR_RESYNC:
2511 /* We don't reset the result here because we don't push the event
2512 * again on pads that got the event already and because we need
2513 * to consider the result of the previous pushes */
2514 gst_iterator_resync (iter);
2516 case GST_ITERATOR_ERROR:
2517 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2520 case GST_ITERATOR_DONE:
2525 g_value_unset (&item);
2526 gst_iterator_free (iter);
2528 g_list_free (pushed_pads);
2538 gboolean dispatched;
2542 event_forward_func (GstPad * pad, EventData * data)
2544 /* for each pad we send to, we should ref the event; it's up
2545 * to downstream to unref again when handled. */
2546 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2547 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2549 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2551 data->dispatched = TRUE;
2558 * gst_pad_event_default:
2559 * @pad: a #GstPad to call the default event handler on.
2560 * @parent: the parent of @pad or NULL
2561 * @event: (transfer full): the #GstEvent to handle.
2563 * Invokes the default event handler for the given pad.
2565 * The EOS event will pause the task associated with @pad before it is forwarded
2566 * to all internally linked pads,
2568 * The the event is sent to all pads internally linked to @pad. This function
2569 * takes ownership of @event.
2571 * Returns: TRUE if the event was sent successfully.
2574 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2576 gboolean result, forward = TRUE;
2578 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2579 g_return_val_if_fail (event != NULL, FALSE);
2581 GST_LOG_OBJECT (pad, "default event handler");
2583 switch (GST_EVENT_TYPE (event)) {
2586 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
2587 gst_pad_pause_task (pad);
2590 case GST_EVENT_CAPS:
2591 forward = GST_PAD_IS_PROXY_CAPS (pad);
2602 data.dispatched = FALSE;
2603 data.result = FALSE;
2605 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2607 /* for sinkpads without a parent element or without internal links, nothing
2608 * will be dispatched but we still want to return TRUE. */
2609 if (data.dispatched)
2610 result = data.result;
2615 gst_event_unref (event);
2620 /* Default accept caps implementation just checks against
2621 * the allowed caps for the pad */
2623 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2625 /* get the caps and see if it intersects to something not empty */
2626 GstCaps *caps, *allowed;
2629 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2631 /* first forward the query to internally linked pads when we are dealing with
2633 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2634 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2639 allowed = gst_pad_query_caps (pad, NULL);
2640 gst_query_parse_accept_caps (query, &caps);
2643 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
2644 result = gst_caps_is_subset (caps, allowed);
2645 gst_caps_unref (allowed);
2647 GST_DEBUG_OBJECT (pad, "no caps allowed on the pad");
2650 gst_query_set_accept_caps_result (query, result);
2656 /* Default caps implementation */
2658 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2660 GstCaps *result = NULL, *filter;
2661 GstPadTemplate *templ;
2662 gboolean fixed_caps;
2664 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2666 gst_query_parse_caps (query, &filter);
2668 /* first try to proxy if we must */
2669 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2670 if ((gst_pad_proxy_query_caps (pad, query))) {
2671 gst_query_parse_caps_result (query, &result);
2676 /* no proxy or it failed, do default handling */
2677 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2679 GST_OBJECT_LOCK (pad);
2681 /* fixed caps, try the negotiated caps first */
2682 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2683 if ((result = get_pad_caps (pad)))
2684 goto filter_done_unlock;
2687 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2688 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2689 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2690 goto filter_done_unlock;
2694 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2695 "non-fixed pad caps: trying pad caps");
2696 /* non fixed caps, try the negotiated caps */
2697 if ((result = get_pad_caps (pad)))
2698 goto filter_done_unlock;
2700 GST_OBJECT_UNLOCK (pad);
2702 /* this almost never happens */
2703 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2704 result = gst_caps_new_empty ();
2709 GST_OBJECT_UNLOCK (pad);
2712 /* run the filter on the result */
2714 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2715 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2716 GST_PTR_FORMAT, result, result, filter, filter);
2717 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2718 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2721 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2722 "using caps %p %" GST_PTR_FORMAT, result, result);
2723 result = gst_caps_ref (result);
2727 gst_query_set_caps_result (query, result);
2728 gst_caps_unref (result);
2734 * gst_pad_query_default:
2735 * @pad: a #GstPad to call the default query handler on.
2736 * @parent: the parent of @pad or NULL
2737 * @query: (transfer none): the #GstQuery to handle.
2739 * Invokes the default query handler for the given pad.
2740 * The query is sent to all pads internally linked to @pad. Note that
2741 * if there are many possible sink pads that are internally linked to
2742 * @pad, only one will be sent the query.
2743 * Multi-sinkpad elements should implement custom query handlers.
2745 * Returns: TRUE if the query was performed successfully.
2748 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
2750 gboolean forward = TRUE, ret = FALSE;
2752 switch (GST_QUERY_TYPE (query)) {
2753 case GST_QUERY_SCHEDULING:
2754 case GST_QUERY_ALLOCATION:
2757 case GST_QUERY_ACCEPT_CAPS:
2758 ret = gst_pad_query_accept_caps_default (pad, query);
2761 case GST_QUERY_CAPS:
2762 ret = gst_pad_query_caps_default (pad, query);
2765 case GST_QUERY_POSITION:
2766 case GST_QUERY_SEEKING:
2767 case GST_QUERY_FORMATS:
2768 case GST_QUERY_LATENCY:
2769 case GST_QUERY_JITTER:
2770 case GST_QUERY_RATE:
2771 case GST_QUERY_CONVERT:
2777 ret = gst_pad_forward
2778 (pad, (GstPadForwardFunction) gst_pad_peer_query, query);
2784 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
2786 GstPad *pad = data->pad;
2787 GstPadProbeInfo *info = data->info;
2788 GstPadProbeType type, flags;
2789 GstPadProbeCallback callback;
2790 GstPadProbeReturn ret;
2792 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2793 "hook %lu, cookie %u checking", hook->hook_id, PROBE_COOKIE (hook));
2795 /* if we have called this callback, do nothing */
2796 if (PROBE_COOKIE (hook) == data->cookie) {
2797 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2798 "hook %lu, cookie %u already called", hook->hook_id,
2799 PROBE_COOKIE (hook));
2803 PROBE_COOKIE (hook) = data->cookie;
2805 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
2808 /* one of the data types */
2809 if ((flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
2811 /* one of the scheduling types */
2812 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
2814 /* one of the blocking types must match */
2815 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
2816 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
2818 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
2819 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
2820 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
2823 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2824 "hook %lu with flags 0x%08x matches", hook->hook_id, flags);
2826 callback = (GstPadProbeCallback) hook->func;
2827 if (callback == NULL)
2830 GST_OBJECT_UNLOCK (pad);
2832 ret = callback (pad, info, hook->data);
2834 GST_OBJECT_LOCK (pad);
2835 data->marshalled = TRUE;
2838 case GST_PAD_PROBE_REMOVE:
2839 /* remove the probe */
2840 GST_DEBUG_OBJECT (pad, "asked to remove hook");
2841 cleanup_hook (pad, hook);
2843 case GST_PAD_PROBE_DROP:
2844 /* need to drop the data, make sure other probes don't get called
2846 GST_DEBUG_OBJECT (pad, "asked to drop item");
2847 info->type = GST_PAD_PROBE_TYPE_INVALID;
2848 data->dropped = TRUE;
2850 case GST_PAD_PROBE_PASS:
2851 /* inform the pad block to let things pass */
2852 GST_DEBUG_OBJECT (pad, "asked to pass item");
2856 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
2863 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2864 "hook %lu with flags 0x%08x does not match %08x", hook->hook_id,
2870 #define PROBE_PRE_PULL(pad,mask,data,offs,size,label,probed,defaultval) \
2872 if (G_UNLIKELY (pad->num_probes)) { \
2873 /* we start with passing NULL as the data item */ \
2874 GstPadProbeInfo info = { mask, NULL, offs, size }; \
2875 ret = do_probe_callbacks (pad, &info, defaultval); \
2876 /* store the possibly updated data item */ \
2877 data = GST_PAD_PROBE_INFO_DATA (&info); \
2878 /* if something went wrong, exit */ \
2879 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2881 /* otherwise check if the probe retured data */ \
2882 if (G_UNLIKELY (data != NULL)) \
2888 /* a probe that does not take or return any data */
2889 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
2891 if (G_UNLIKELY (pad->num_probes)) { \
2892 /* pass NULL as the data item */ \
2893 GstPadProbeInfo info = { mask, NULL, 0, 0 }; \
2894 ret = do_probe_callbacks (pad, &info, defaultval); \
2895 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2900 #define PROBE_FULL(pad,mask,data,offs,size,label,defaultval) \
2902 if (G_UNLIKELY (pad->num_probes)) { \
2903 GstPadProbeInfo info = { mask, data, offs, size }; \
2904 ret = do_probe_callbacks (pad, &info, defaultval); \
2905 data = GST_PAD_PROBE_INFO_DATA (&info); \
2906 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2911 #define PROBE_PUSH(pad,mask,data,label) \
2912 PROBE_FULL(pad, mask, data, -1, -1, label, GST_FLOW_OK);
2913 #define PROBE_PULL(pad,mask,data,offs,size,label) \
2914 PROBE_FULL(pad, mask, data, offs, size, label, GST_FLOW_OK);
2916 static GstFlowReturn
2917 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
2918 GstFlowReturn defaultval)
2927 data.marshalled = FALSE;
2928 data.dropped = FALSE;
2929 data.cookie = ++pad->priv->probe_cookie;
2932 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
2935 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2936 "do probes cookie %u", data.cookie);
2937 cookie = pad->priv->probe_list_cookie;
2939 g_hook_list_marshal (&pad->probes, TRUE,
2940 (GHookMarshaller) probe_hook_marshal, &data);
2942 /* if the list changed, call the new callbacks (they will not have their
2943 * cookie set to data.cookie */
2944 if (cookie != pad->priv->probe_list_cookie) {
2945 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2946 "probe list changed, restarting");
2950 /* the first item that dropped will stop the hooks and then we drop here */
2954 /* if no handler matched and we are blocking, let the item pass */
2955 if (!data.marshalled && is_block)
2958 /* At this point, all handlers returned either OK or PASS. If one handler
2959 * returned PASS, let the item pass */
2964 while (GST_PAD_IS_BLOCKED (pad)) {
2965 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2966 "we are blocked %d times", pad->num_blocked);
2968 /* we might have released the lock */
2969 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2972 /* now we block the streaming thread. It can be unlocked when we
2973 * deactivate the pad (which will also set the FLUSHING flag) or
2974 * when the pad is unblocked. A flushing event will also unblock
2975 * the pad after setting the FLUSHING flag. */
2976 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2977 "Waiting to be unblocked or set flushing");
2978 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
2979 GST_PAD_BLOCK_WAIT (pad);
2980 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
2981 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
2983 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2993 GST_DEBUG_OBJECT (pad, "pad is flushing");
2994 return GST_FLOW_WRONG_STATE;
2998 GST_DEBUG_OBJECT (pad, "data is dropped");
2999 return GST_FLOW_CUSTOM_SUCCESS;
3003 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3004 GST_DEBUG_OBJECT (pad, "data is passed");
3012 * gst_pad_get_offset:
3015 * Get the offset applied to the running time of @pad. @pad has to be a source
3018 * Returns: the offset.
3021 gst_pad_get_offset (GstPad * pad)
3025 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3027 GST_OBJECT_LOCK (pad);
3028 result = pad->offset;
3029 GST_OBJECT_UNLOCK (pad);
3035 * gst_pad_set_offset:
3037 * @offset: the offset
3039 * Set the offset that will be applied to the running time of @pad.
3042 gst_pad_set_offset (GstPad * pad, gint64 offset)
3046 g_return_if_fail (GST_IS_PAD (pad));
3048 GST_OBJECT_LOCK (pad);
3049 /* if nothing changed, do nothing */
3050 if (pad->offset == offset)
3053 pad->offset = offset;
3054 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3056 /* sinkpads will apply their offset the next time a segment
3057 * event is received. */
3058 if (GST_PAD_IS_SINK (pad))
3061 /* resend the last segment event on next buffer push */
3062 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3063 ev->received = FALSE;
3064 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3068 GST_OBJECT_UNLOCK (pad);
3074 * @pad: a #GstPad to invoke the default query on.
3075 * @query: (transfer none): the #GstQuery to perform.
3077 * Dispatches a query to a pad. The query should have been allocated by the
3078 * caller via one of the type-specific allocation functions. The element that
3079 * the pad belongs to is responsible for filling the query with an appropriate
3080 * response, which should then be parsed with a type-specific query parsing
3083 * Again, the caller is responsible for both the allocation and deallocation of
3084 * the query structure.
3086 * Please also note that some queries might need a running pipeline to work.
3088 * Returns: TRUE if the query could be performed.
3091 gst_pad_query (GstPad * pad, GstQuery * query)
3095 GstPadQueryFunction func;
3096 GstPadProbeType type;
3099 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3100 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3102 GST_DEBUG_OBJECT (pad, "sending query %p (%s)", query,
3103 GST_QUERY_TYPE_NAME (query));
3105 if (GST_PAD_IS_SRC (pad))
3106 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3108 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3110 GST_OBJECT_LOCK (pad);
3111 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3112 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3113 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3115 ACQUIRE_PARENT (pad, parent, no_parent);
3116 GST_OBJECT_UNLOCK (pad);
3118 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3121 res = func (pad, parent, query);
3123 RELEASE_PARENT (parent);
3125 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3126 GST_QUERY_TYPE_NAME (query), res);
3131 GST_OBJECT_LOCK (pad);
3132 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3133 GST_OBJECT_UNLOCK (pad);
3140 GST_DEBUG_OBJECT (pad, "had no parent");
3141 GST_OBJECT_UNLOCK (pad);
3146 GST_DEBUG_OBJECT (pad, "had no query function");
3147 RELEASE_PARENT (parent);
3152 GST_DEBUG_OBJECT (pad, "query failed");
3157 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3158 GST_OBJECT_UNLOCK (pad);
3164 * gst_pad_peer_query:
3165 * @pad: a #GstPad to invoke the peer query on.
3166 * @query: (transfer none): the #GstQuery to perform.
3168 * Performs gst_pad_query() on the peer of @pad.
3170 * The caller is responsible for both the allocation and deallocation of
3171 * the query structure.
3173 * Returns: TRUE if the query could be performed. This function returns %FALSE
3174 * if @pad has no peer.
3179 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3182 GstPadProbeType type;
3186 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3187 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3189 if (GST_PAD_IS_SRC (pad))
3190 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3192 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3194 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3195 GST_QUERY_TYPE_NAME (query));
3197 GST_OBJECT_LOCK (pad);
3198 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3199 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3200 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3202 peerpad = GST_PAD_PEER (pad);
3203 if (G_UNLIKELY (peerpad == NULL))
3206 gst_object_ref (peerpad);
3207 GST_OBJECT_UNLOCK (pad);
3209 res = gst_pad_query (peerpad, query);
3211 gst_object_unref (peerpad);
3216 GST_OBJECT_LOCK (pad);
3217 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3218 GST_OBJECT_UNLOCK (pad);
3225 GST_WARNING_OBJECT (pad, "pad has no peer");
3226 GST_OBJECT_UNLOCK (pad);
3231 GST_DEBUG_OBJECT (pad, "query failed");
3236 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3237 GST_OBJECT_UNLOCK (pad);
3242 /**********************************************************************
3243 * Data passing functions
3247 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3249 GstFlowReturn *data = user_data;
3253 GST_DEBUG_OBJECT (pad, "event %s was already received",
3254 GST_EVENT_TYPE_NAME (ev->event));
3257 GST_OBJECT_UNLOCK (pad);
3259 *data = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3260 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, &stored);
3262 GST_OBJECT_LOCK (pad);
3263 return *data == GST_FLOW_OK;
3266 /* this is the chain function that does not perform the additional argument
3267 * checking for that little extra speed.
3269 static inline GstFlowReturn
3270 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3275 GST_PAD_STREAM_LOCK (pad);
3277 GST_OBJECT_LOCK (pad);
3278 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3281 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3283 PROBE_PUSH (pad, type, data, probe_stopped);
3285 parent = GST_OBJECT_PARENT (pad);
3286 GST_OBJECT_UNLOCK (pad);
3288 /* NOTE: we read the chainfunc unlocked.
3289 * we cannot hold the lock for the pad so we might send
3290 * the data to the wrong function. This is not really a
3291 * problem since functions are assigned at creation time
3292 * and don't change that often... */
3293 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3294 GstPadChainFunction chainfunc;
3296 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3299 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3300 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3301 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3303 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3305 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3306 "called chainfunction &%s with buffer %p, returned %s",
3307 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3309 GstPadChainListFunction chainlistfunc;
3311 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3314 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3315 "calling chainlistfunction &%s",
3316 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3318 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3320 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3321 "called chainlistfunction &%s, returned %s",
3322 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3325 GST_PAD_STREAM_UNLOCK (pad);
3332 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3333 "chaining, but pad was flushing");
3334 GST_OBJECT_UNLOCK (pad);
3335 GST_PAD_STREAM_UNLOCK (pad);
3336 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3337 return GST_FLOW_WRONG_STATE;
3341 GST_OBJECT_UNLOCK (pad);
3342 GST_PAD_STREAM_UNLOCK (pad);
3343 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3346 case GST_FLOW_CUSTOM_SUCCESS:
3347 GST_DEBUG_OBJECT (pad, "dropped buffer");
3351 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
3358 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3359 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3360 "pushing, but not chainhandler");
3361 GST_ELEMENT_ERROR (parent, CORE, PAD, (NULL),
3362 ("push on pad %s:%s but it has no chainfunction",
3363 GST_DEBUG_PAD_NAME (pad)));
3364 GST_PAD_STREAM_UNLOCK (pad);
3365 return GST_FLOW_NOT_SUPPORTED;
3371 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3372 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3375 * Chain a buffer to @pad.
3377 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
3379 * If the buffer type is not acceptable for @pad (as negotiated with a
3380 * preceeding GST_EVENT_CAPS event), this function returns
3381 * #GST_FLOW_NOT_NEGOTIATED.
3383 * The function proceeds calling the chain function installed on @pad (see
3384 * gst_pad_set_chain_function()) and the return value of that function is
3385 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3388 * In all cases, success or failure, the caller loses its reference to @buffer
3389 * after calling this function.
3391 * Returns: a #GstFlowReturn from the pad.
3396 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3398 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3399 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3400 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3402 return gst_pad_chain_data_unchecked (pad,
3403 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3406 static GstFlowReturn
3407 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3408 GstBufferList * list)
3414 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3416 len = gst_buffer_list_length (list);
3419 for (i = 0; i < len; i++) {
3420 buffer = gst_buffer_list_get (list, i);
3422 gst_pad_chain_data_unchecked (pad,
3423 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3424 gst_buffer_ref (buffer));
3425 if (ret != GST_FLOW_OK)
3428 gst_buffer_list_unref (list);
3434 * gst_pad_chain_list:
3435 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3436 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3439 * Chain a bufferlist to @pad.
3441 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
3443 * If @pad was not negotiated properly with a CAPS event, this function
3444 * returns #GST_FLOW_NOT_NEGOTIATED.
3446 * The function proceeds calling the chainlist function installed on @pad (see
3447 * gst_pad_set_chain_list_function()) and the return value of that function is
3448 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3449 * chainlist function.
3451 * In all cases, success or failure, the caller loses its reference to @list
3452 * after calling this function.
3456 * Returns: a #GstFlowReturn from the pad.
3461 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3463 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3464 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3465 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3467 return gst_pad_chain_data_unchecked (pad,
3468 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3471 static GstFlowReturn
3472 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3477 GST_OBJECT_LOCK (pad);
3478 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3481 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3482 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3484 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3487 events_foreach (pad, push_sticky, &ret);
3488 if (ret != GST_FLOW_OK)
3492 /* do block probes */
3493 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3495 /* do post-blocking probes */
3496 PROBE_PUSH (pad, type, data, probe_stopped);
3498 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3501 /* take ref to peer pad before releasing the lock */
3502 gst_object_ref (peer);
3504 GST_OBJECT_UNLOCK (pad);
3506 ret = gst_pad_chain_data_unchecked (peer, type, data);
3508 gst_object_unref (peer);
3510 GST_OBJECT_LOCK (pad);
3512 if (pad->priv->using == 0) {
3513 /* pad is not active anymore, trigger idle callbacks */
3514 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3515 probe_stopped, ret);
3517 GST_OBJECT_UNLOCK (pad);
3521 /* ERROR recovery here */
3525 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3526 "pushing, but pad was flushing");
3527 GST_OBJECT_UNLOCK (pad);
3528 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3529 return GST_FLOW_WRONG_STATE;
3533 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3534 "error pushing events, return %s", gst_flow_get_name (ret));
3535 GST_OBJECT_UNLOCK (pad);
3536 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3541 GST_OBJECT_UNLOCK (pad);
3542 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3545 case GST_FLOW_CUSTOM_SUCCESS:
3546 GST_DEBUG_OBJECT (pad, "dropped buffer");
3550 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
3557 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3558 "pushing, but it was not linked");
3559 GST_OBJECT_UNLOCK (pad);
3560 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3561 return GST_FLOW_NOT_LINKED;
3567 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3568 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
3571 * Pushes a buffer to the peer of @pad.
3573 * This function will call installed block probes before triggering any
3574 * installed data probes.
3576 * The function proceeds calling gst_pad_chain() on the peer pad and returns
3577 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3580 * In all cases, success or failure, the caller loses its reference to @buffer
3581 * after calling this function.
3583 * Returns: a #GstFlowReturn from the peer pad.
3588 gst_pad_push (GstPad * pad, GstBuffer * buffer)
3590 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3591 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3592 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3594 return gst_pad_push_data (pad,
3595 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3599 * gst_pad_push_list:
3600 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3601 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
3604 * Pushes a buffer list to the peer of @pad.
3606 * This function will call installed block probes before triggering any
3607 * installed data probes.
3609 * The function proceeds calling the chain function on the peer pad and returns
3610 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3611 * be returned. If the peer pad does not have any installed chainlist function
3612 * every group buffer of the list will be merged into a normal #GstBuffer and
3613 * chained via gst_pad_chain().
3615 * In all cases, success or failure, the caller loses its reference to @list
3616 * after calling this function.
3618 * Returns: a #GstFlowReturn from the peer pad.
3625 gst_pad_push_list (GstPad * pad, GstBufferList * list)
3627 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3628 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3629 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3631 return gst_pad_push_data (pad,
3632 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3635 static GstFlowReturn
3636 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
3637 GstBuffer ** buffer)
3640 GstPadGetRangeFunction getrangefunc;
3643 GST_PAD_STREAM_LOCK (pad);
3645 GST_OBJECT_LOCK (pad);
3646 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3649 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3650 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3652 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3655 events_foreach (pad, push_sticky, &ret);
3656 if (ret != GST_FLOW_OK)
3660 /* when one of the probes returns a buffer, probed_data will be called and we
3661 * skip calling the getrange function */
3662 PROBE_PRE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
3663 *buffer, offset, size, probe_stopped, probed_data, GST_FLOW_OK);
3665 ACQUIRE_PARENT (pad, parent, no_parent);
3666 GST_OBJECT_UNLOCK (pad);
3668 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
3671 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3672 "calling getrangefunc %s, offset %"
3673 G_GUINT64_FORMAT ", size %u",
3674 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
3676 ret = getrangefunc (pad, parent, offset, size, buffer);
3678 RELEASE_PARENT (parent);
3680 if (G_UNLIKELY (ret != GST_FLOW_OK))
3681 goto get_range_failed;
3683 /* can only fire the signal if we have a valid buffer */
3684 GST_OBJECT_LOCK (pad);
3686 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
3687 *buffer, offset, size, probe_stopped_unref);
3688 GST_OBJECT_UNLOCK (pad);
3690 GST_PAD_STREAM_UNLOCK (pad);
3697 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3698 "getrange, but pad was flushing");
3699 GST_OBJECT_UNLOCK (pad);
3700 GST_PAD_STREAM_UNLOCK (pad);
3701 return GST_FLOW_WRONG_STATE;
3705 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
3706 GST_OBJECT_UNLOCK (pad);
3707 GST_PAD_STREAM_UNLOCK (pad);
3712 GST_DEBUG_OBJECT (pad, "no parent");
3713 GST_OBJECT_UNLOCK (pad);
3714 GST_PAD_STREAM_UNLOCK (pad);
3715 return GST_FLOW_WRONG_STATE;
3719 GST_ELEMENT_ERROR (parent, CORE, PAD, (NULL),
3720 ("getrange on pad %s:%s but it has no getrangefunction",
3721 GST_DEBUG_PAD_NAME (pad)));
3722 RELEASE_PARENT (parent);
3723 GST_PAD_STREAM_UNLOCK (pad);
3724 return GST_FLOW_NOT_SUPPORTED;
3728 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3729 "probe returned %s", gst_flow_get_name (ret));
3730 GST_OBJECT_UNLOCK (pad);
3731 GST_PAD_STREAM_UNLOCK (pad);
3734 probe_stopped_unref:
3736 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3737 "probe returned %s", gst_flow_get_name (ret));
3738 GST_OBJECT_UNLOCK (pad);
3739 GST_PAD_STREAM_UNLOCK (pad);
3740 gst_buffer_unref (*buffer);
3746 GST_PAD_STREAM_UNLOCK (pad);
3748 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
3749 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
3750 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
3756 * gst_pad_get_range:
3757 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
3758 * @offset: The start offset of the buffer
3759 * @size: The length of the buffer
3760 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
3761 * returns #GST_FLOW_ERROR if %NULL.
3763 * When @pad is flushing this function returns #GST_FLOW_WRONG_STATE
3764 * immediately and @buffer is %NULL.
3766 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
3767 * description of a getrange function. If @pad has no getrange function
3768 * installed (see gst_pad_set_getrange_function()) this function returns
3769 * #GST_FLOW_NOT_SUPPORTED.
3771 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
3773 * Returns: a #GstFlowReturn from the pad.
3778 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
3779 GstBuffer ** buffer)
3781 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3782 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3783 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3785 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
3789 * gst_pad_pull_range:
3790 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3791 * @offset: The start offset of the buffer
3792 * @size: The length of the buffer
3793 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
3794 * GST_FLOW_ERROR if %NULL.
3796 * Pulls a @buffer from the peer pad.
3798 * This function will first trigger the pad block signal if it was
3801 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
3802 * function returns the result of gst_pad_get_range() on the peer pad.
3803 * See gst_pad_get_range() for a list of return values and for the
3804 * semantics of the arguments of this function.
3806 * Returns: a #GstFlowReturn from the peer pad.
3807 * When this function returns #GST_FLOW_OK, @buffer will contain a valid
3808 * #GstBuffer that should be freed with gst_buffer_unref() after usage.
3809 * @buffer may not be used or freed when any other return value than
3810 * #GST_FLOW_OK is returned.
3815 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
3816 GstBuffer ** buffer)
3821 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3822 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3823 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3825 GST_OBJECT_LOCK (pad);
3826 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3829 /* when one of the probes returns a buffer, probed_data will be called and we
3830 * skip calling the peer getrange function */
3831 PROBE_PRE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
3832 *buffer, offset, size, pre_probe_stopped, probed_data, GST_FLOW_OK);
3834 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3837 gst_object_ref (peer);
3839 GST_OBJECT_UNLOCK (pad);
3841 ret = gst_pad_get_range_unchecked (peer, offset, size, buffer);
3843 gst_object_unref (peer);
3845 GST_OBJECT_LOCK (pad);
3847 if (pad->priv->using == 0) {
3848 /* pad is not active anymore, trigger idle callbacks */
3849 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
3850 post_probe_stopped, ret);
3853 if (G_UNLIKELY (ret != GST_FLOW_OK))
3854 goto pull_range_failed;
3857 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
3858 *buffer, offset, size, post_probe_stopped);
3860 GST_OBJECT_UNLOCK (pad);
3864 /* ERROR recovery here */
3867 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3868 "pullrange, but pad was flushing");
3869 GST_OBJECT_UNLOCK (pad);
3870 return GST_FLOW_WRONG_STATE;
3874 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
3875 gst_flow_get_name (ret));
3876 GST_OBJECT_UNLOCK (pad);
3881 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3882 "pulling range, but it was not linked");
3883 GST_OBJECT_UNLOCK (pad);
3884 return GST_FLOW_NOT_LINKED;
3889 GST_OBJECT_UNLOCK (pad);
3890 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
3891 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
3892 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
3897 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3898 "post probe returned %s", gst_flow_get_name (ret));
3899 GST_OBJECT_UNLOCK (pad);
3900 if (ret == GST_FLOW_OK)
3901 gst_buffer_unref (*buffer);
3908 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event, gboolean locked)
3913 gboolean res = FALSE;
3914 const gchar *name = NULL;
3916 type = GST_EVENT_TYPE (event);
3917 if (type & GST_EVENT_TYPE_STICKY_MULTI)
3918 name = gst_structure_get_name (gst_event_get_structure (event));
3920 events = pad->priv->events;
3923 for (i = 0; i < len; i++) {
3924 PadEvent *ev = &g_array_index (events, PadEvent, i);
3926 if (ev->event == NULL)
3929 if (type == GST_EVENT_TYPE (ev->event)) {
3930 /* matching types, check matching name if needed */
3931 if (name && !gst_event_has_name (ev->event, name))
3935 if ((res = gst_event_replace (&ev->event, event)))
3936 ev->received = FALSE;
3942 ev.event = gst_event_ref (event);
3943 ev.received = FALSE;
3944 g_array_append_val (events, ev);
3949 pad->priv->events_cookie++;
3950 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3952 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
3954 switch (GST_EVENT_TYPE (event)) {
3955 case GST_EVENT_CAPS:
3957 GST_OBJECT_UNLOCK (pad);
3959 GST_DEBUG_OBJECT (pad, "notify caps");
3960 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
3963 GST_OBJECT_LOCK (pad);
3972 static GstFlowReturn
3973 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
3974 GstPadProbeType type, gboolean * stored)
3978 GstEventType event_type;
3981 sticky = GST_EVENT_IS_STICKY (event);
3983 GST_OBJECT_LOCK (pad);
3985 /* Two checks to be made:
3986 * . (un)set the FLUSHING flag for flushing events,
3987 * . handle pad blocking */
3988 event_type = GST_EVENT_TYPE (event);
3990 switch (event_type) {
3991 case GST_EVENT_FLUSH_START:
3992 GST_PAD_SET_FLUSHING (pad);
3994 GST_PAD_BLOCK_BROADCAST (pad);
3995 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
3997 case GST_EVENT_FLUSH_STOP:
3998 GST_PAD_UNSET_FLUSHING (pad);
4000 /* Remove sticky EOS events */
4001 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4002 remove_event_by_type (pad, GST_EVENT_EOS);
4004 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4008 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4011 /* store the event on the pad, but only on srcpads. We always store the
4012 * event exactly how it was sent */
4014 /* srcpad sticky events are store immediately, the received flag is set
4015 * to FALSE and will be set to TRUE when we can successfully push the
4016 * event to the peer pad */
4017 if (gst_pad_store_sticky_event (pad, event, TRUE)) {
4018 GST_DEBUG_OBJECT (pad, "event %s updated",
4019 GST_EVENT_TYPE_NAME (event));
4024 switch (GST_EVENT_TYPE (event)) {
4025 case GST_EVENT_SEGMENT:
4026 /* pass the adjusted segment event on. We need to do this even if
4027 * there is no peer pad because of the probes. */
4028 event = apply_pad_offset (pad, event);
4030 case GST_EVENT_RECONFIGURE:
4031 if (GST_PAD_IS_SINK (pad))
4032 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4037 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4038 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4043 /* send probes after modifying the events above */
4044 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4046 /* now check the peer pad */
4047 peerpad = GST_PAD_PEER (pad);
4048 if (peerpad == NULL)
4051 gst_object_ref (peerpad);
4053 GST_OBJECT_UNLOCK (pad);
4055 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4056 event, GST_EVENT_TYPE_NAME (event), peerpad);
4058 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4060 /* Note: we gave away ownership of the event at this point but we can still
4061 * print the old pointer */
4062 GST_LOG_OBJECT (pad,
4063 "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s", event, peerpad,
4064 gst_flow_get_name (ret));
4066 gst_object_unref (peerpad);
4068 GST_OBJECT_LOCK (pad);
4070 if (ret == GST_FLOW_OK) {
4073 if ((ev = find_event (pad, event)))
4074 ev->received = TRUE;
4076 GST_DEBUG_OBJECT (pad, "event marked received");
4078 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4079 GST_DEBUG_OBJECT (pad, "mark pending events");
4083 if (pad->priv->using == 0) {
4084 /* pad is not active anymore, trigger idle callbacks */
4085 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4086 idle_probe_stopped, ret);
4088 GST_OBJECT_UNLOCK (pad);
4092 /* ERROR handling */
4095 GST_DEBUG_OBJECT (pad, "We're flushing");
4096 GST_OBJECT_UNLOCK (pad);
4097 gst_event_unref (event);
4098 return GST_FLOW_WRONG_STATE;
4102 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4103 GST_OBJECT_UNLOCK (pad);
4104 gst_event_unref (event);
4107 case GST_FLOW_CUSTOM_SUCCESS:
4108 GST_DEBUG_OBJECT (pad, "dropped event");
4112 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
4119 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4120 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4121 GST_OBJECT_UNLOCK (pad);
4122 gst_event_unref (event);
4123 return sticky ? GST_FLOW_OK : GST_FLOW_NOT_LINKED;
4127 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4128 GST_OBJECT_UNLOCK (pad);
4134 * gst_pad_push_event:
4135 * @pad: a #GstPad to push the event to.
4136 * @event: (transfer full): the #GstEvent to send to the pad.
4138 * Sends the event to the peer of the given pad. This function is
4139 * mainly used by elements to send events to their peer
4142 * This function takes owership of the provided event so you should
4143 * gst_event_ref() it if you want to reuse the event after this call.
4145 * Returns: TRUE if the event was handled.
4150 gst_pad_push_event (GstPad * pad, GstEvent * event)
4153 GstPadProbeType type;
4156 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4157 g_return_val_if_fail (event != NULL, FALSE);
4158 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4160 if (GST_PAD_IS_SRC (pad)) {
4161 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4162 goto wrong_direction;
4163 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4164 } else if (GST_PAD_IS_SINK (pad)) {
4165 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4166 goto wrong_direction;
4167 /* events pushed on sinkpad never are sticky */
4168 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4170 goto unknown_direction;
4172 if (gst_pad_push_event_unchecked (pad, event, type, &stored) != GST_FLOW_OK)
4173 res = stored ? TRUE : FALSE;
4179 /* ERROR handling */
4182 g_warning ("pad %s:%s pushing %s event in wrong direction",
4183 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4184 gst_event_unref (event);
4189 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4190 gst_event_unref (event);
4195 /* Check if we can call the event function with the given event */
4196 static GstFlowReturn
4197 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4199 GstCaps *caps, *templ;
4201 switch (GST_EVENT_TYPE (event)) {
4202 case GST_EVENT_CAPS:
4204 /* backwards compatibility mode for caps */
4205 gst_event_parse_caps (event, &caps);
4207 /* See if pad accepts the caps */
4208 templ = gst_pad_get_pad_template_caps (pad);
4209 if (!gst_caps_is_subset (caps, templ))
4212 gst_caps_unref (templ);
4223 gst_caps_unref (templ);
4224 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4225 "caps %" GST_PTR_FORMAT " not accepted", caps);
4226 return GST_FLOW_NOT_NEGOTIATED;
4230 static GstFlowReturn
4231 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4232 GstPadProbeType type)
4235 GstEventType event_type;
4236 gboolean serialized, need_unlock = FALSE, sticky;
4237 GstPadEventFunction eventfunc;
4240 GST_OBJECT_LOCK (pad);
4241 if (GST_PAD_IS_SINK (pad))
4242 serialized = GST_EVENT_IS_SERIALIZED (event);
4245 sticky = GST_EVENT_IS_STICKY (event);
4246 event_type = GST_EVENT_TYPE (event);
4247 switch (event_type) {
4248 case GST_EVENT_FLUSH_START:
4249 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4250 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4252 /* can't even accept a flush begin event when flushing */
4253 if (GST_PAD_IS_FLUSHING (pad))
4256 GST_PAD_SET_FLUSHING (pad);
4257 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4259 case GST_EVENT_FLUSH_STOP:
4260 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4261 GST_PAD_UNSET_FLUSHING (pad);
4262 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4264 /* Remove pending EOS events */
4265 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4266 remove_event_by_type (pad, GST_EVENT_EOS);
4268 GST_OBJECT_UNLOCK (pad);
4269 /* grab stream lock */
4270 GST_PAD_STREAM_LOCK (pad);
4272 GST_OBJECT_LOCK (pad);
4273 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4276 case GST_EVENT_RECONFIGURE:
4277 if (GST_PAD_IS_SRC (pad))
4278 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4280 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "have event type %s",
4281 GST_EVENT_TYPE_NAME (event));
4283 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4287 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4288 GST_OBJECT_UNLOCK (pad);
4289 GST_PAD_STREAM_LOCK (pad);
4291 GST_OBJECT_LOCK (pad);
4292 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4296 switch (GST_EVENT_TYPE (event)) {
4297 case GST_EVENT_SEGMENT:
4298 event = apply_pad_offset (pad, event);
4304 /* now do the probe */
4306 type | GST_PAD_PROBE_TYPE_PUSH |
4307 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4309 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4313 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4316 ACQUIRE_PARENT (pad, parent, no_parent);
4317 GST_OBJECT_UNLOCK (pad);
4319 ret = pre_eventfunc_check (pad, event);
4320 if (G_UNLIKELY (ret != GST_FLOW_OK))
4321 goto precheck_failed;
4324 gst_event_ref (event);
4326 if (eventfunc (pad, parent, event)) {
4329 /* something went wrong */
4330 switch (event_type) {
4331 case GST_EVENT_CAPS:
4332 ret = GST_FLOW_NOT_NEGOTIATED;
4335 ret = GST_FLOW_ERROR;
4339 RELEASE_PARENT (parent);
4341 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
4344 if (ret == GST_FLOW_OK) {
4345 /* after the event function accepted the event, we can store the sticky
4346 * event on the pad */
4347 gst_pad_store_sticky_event (pad, event, FALSE);
4349 gst_event_unref (event);
4353 GST_PAD_STREAM_UNLOCK (pad);
4357 /* ERROR handling */
4360 GST_OBJECT_UNLOCK (pad);
4362 GST_PAD_STREAM_UNLOCK (pad);
4363 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
4364 "Received event on flushing pad. Discarding");
4365 gst_event_unref (event);
4366 return GST_FLOW_WRONG_STATE;
4370 GST_OBJECT_UNLOCK (pad);
4372 GST_PAD_STREAM_UNLOCK (pad);
4373 gst_event_unref (event);
4376 case GST_FLOW_CUSTOM_SUCCESS:
4377 GST_DEBUG_OBJECT (pad, "dropped event");
4381 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
4388 g_warning ("pad %s:%s has no event handler, file a bug.",
4389 GST_DEBUG_PAD_NAME (pad));
4390 GST_OBJECT_UNLOCK (pad);
4392 GST_PAD_STREAM_UNLOCK (pad);
4393 gst_event_unref (event);
4394 return GST_FLOW_NOT_SUPPORTED;
4398 GST_DEBUG_OBJECT (pad, "no parent");
4399 GST_OBJECT_UNLOCK (pad);
4401 GST_PAD_STREAM_UNLOCK (pad);
4402 gst_event_unref (event);
4403 return GST_FLOW_WRONG_STATE;
4407 GST_DEBUG_OBJECT (pad, "pre event check failed");
4408 RELEASE_PARENT (parent);
4410 GST_PAD_STREAM_UNLOCK (pad);
4411 gst_event_unref (event);
4417 * gst_pad_send_event:
4418 * @pad: a #GstPad to send the event to.
4419 * @event: (transfer full): the #GstEvent to send to the pad.
4421 * Sends the event to the pad. This function can be used
4422 * by applications to send events in the pipeline.
4424 * If @pad is a source pad, @event should be an upstream event. If @pad is a
4425 * sink pad, @event should be a downstream event. For example, you would not
4426 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
4427 * Furthermore, some downstream events have to be serialized with data flow,
4428 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
4429 * the event needs to be serialized with data flow, this function will take the
4430 * pad's stream lock while calling its event function.
4432 * To find out whether an event type is upstream, downstream, or downstream and
4433 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
4434 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
4435 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
4436 * plugin doesn't need to bother itself with this information; the core handles
4437 * all necessary locks and checks.
4439 * This function takes owership of the provided event so you should
4440 * gst_event_ref() it if you want to reuse the event after this call.
4442 * Returns: TRUE if the event was handled.
4445 gst_pad_send_event (GstPad * pad, GstEvent * event)
4448 GstPadProbeType type;
4450 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4451 g_return_val_if_fail (event != NULL, FALSE);
4453 if (GST_PAD_IS_SINK (pad)) {
4454 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4455 goto wrong_direction;
4456 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4457 } else if (GST_PAD_IS_SRC (pad)) {
4458 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4459 goto wrong_direction;
4460 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4462 goto unknown_direction;
4464 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
4471 /* ERROR handling */
4474 g_warning ("pad %s:%s sending %s event in wrong direction",
4475 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4476 gst_event_unref (event);
4481 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4482 gst_event_unref (event);
4488 * gst_pad_set_element_private:
4489 * @pad: the #GstPad to set the private data of.
4490 * @priv: The private data to attach to the pad.
4492 * Set the given private data gpointer on the pad.
4493 * This function can only be used by the element that owns the pad.
4494 * No locking is performed in this function.
4497 gst_pad_set_element_private (GstPad * pad, gpointer priv)
4499 pad->element_private = priv;
4503 * gst_pad_get_element_private:
4504 * @pad: the #GstPad to get the private data of.
4506 * Gets the private data of a pad.
4507 * No locking is performed in this function.
4509 * Returns: (transfer none): a #gpointer to the private data.
4512 gst_pad_get_element_private (GstPad * pad)
4514 return pad->element_private;
4518 * gst_pad_get_sticky_event:
4519 * @pad: the #GstPad to get the event from.
4520 * @event_type: the #GstEventType that should be retrieved.
4521 * @idx: the index of the event
4523 * Returns a new reference of the sticky event of type @event_type
4526 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
4527 * event of @event_type was on @pad. Unref after usage.
4530 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
4532 GstEvent *event = NULL;
4535 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4536 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
4538 GST_OBJECT_LOCK (pad);
4539 ev = find_event_by_type (pad, event_type, idx);
4540 if (ev && (event = ev->event))
4541 gst_event_ref (event);
4542 GST_OBJECT_UNLOCK (pad);
4549 GstPadStickyEventsForeachFunction func;
4554 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
4556 ForeachDispatch *data = user_data;
4559 GST_OBJECT_UNLOCK (pad);
4561 ret = data->func (pad, &ev->event, data->user_data);
4563 GST_OBJECT_LOCK (pad);
4569 * gst_pad_sticky_events_foreach:
4570 * @pad: the #GstPad that should be used for iteration.
4571 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
4572 * should be called for every event.
4573 * @user_data: (closure): the optional user data.
4575 * Iterates all sticky events on @pad and calls @foreach_func for every
4576 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
4579 gst_pad_sticky_events_foreach (GstPad * pad,
4580 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
4582 ForeachDispatch data;
4584 g_return_if_fail (GST_IS_PAD (pad));
4585 g_return_if_fail (foreach_func != NULL);
4587 data.func = foreach_func;
4588 data.user_data = user_data;
4590 GST_OBJECT_LOCK (pad);
4591 events_foreach (pad, foreach_dispatch_function, &data);
4592 GST_OBJECT_UNLOCK (pad);
4596 do_stream_status (GstPad * pad, GstStreamStatusType type,
4597 GThread * thread, GstTask * task)
4601 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
4603 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
4604 if (GST_IS_ELEMENT (parent)) {
4605 GstMessage *message;
4606 GValue value = { 0 };
4608 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
4609 gchar *tname, *ename, *pname;
4611 /* create a good task name */
4612 ename = gst_element_get_name (parent);
4613 pname = gst_pad_get_name (pad);
4614 tname = g_strdup_printf ("%s:%s", ename, pname);
4618 gst_object_set_name (GST_OBJECT_CAST (task), tname);
4622 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
4625 g_value_init (&value, GST_TYPE_TASK);
4626 g_value_set_object (&value, task);
4627 gst_message_set_stream_status_object (message, &value);
4628 g_value_unset (&value);
4630 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
4631 gst_element_post_message (parent, message);
4633 gst_object_unref (parent);
4638 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
4640 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
4645 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
4647 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
4651 static GstTaskThreadCallbacks thr_callbacks = {
4657 * gst_pad_start_task:
4658 * @pad: the #GstPad to start the task of
4659 * @func: the task function to call
4660 * @data: data passed to the task function
4662 * Starts a task that repeatedly calls @func with @data. This function
4663 * is mostly used in pad activation functions to start the dataflow.
4664 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
4665 * before @func is called.
4667 * Returns: a %TRUE if the task could be started.
4670 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
4675 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4676 g_return_val_if_fail (func != NULL, FALSE);
4678 GST_DEBUG_OBJECT (pad, "start task");
4680 GST_OBJECT_LOCK (pad);
4681 task = GST_PAD_TASK (pad);
4683 task = gst_task_new (func, data);
4684 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
4685 gst_task_set_thread_callbacks (task, &thr_callbacks, pad, NULL);
4686 GST_DEBUG_OBJECT (pad, "created task");
4687 GST_PAD_TASK (pad) = task;
4688 gst_object_ref (task);
4689 /* release lock to post the message */
4690 GST_OBJECT_UNLOCK (pad);
4692 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
4694 gst_object_unref (task);
4696 GST_OBJECT_LOCK (pad);
4697 /* nobody else is supposed to have changed the pad now */
4698 if (GST_PAD_TASK (pad) != task)
4699 goto concurrent_stop;
4701 res = gst_task_set_state (task, GST_TASK_STARTED);
4702 GST_OBJECT_UNLOCK (pad);
4709 GST_OBJECT_UNLOCK (pad);
4715 * gst_pad_pause_task:
4716 * @pad: the #GstPad to pause the task of
4718 * Pause the task of @pad. This function will also wait until the
4719 * function executed by the task is finished if this function is not
4720 * called from the task function.
4722 * Returns: a TRUE if the task could be paused or FALSE when the pad
4726 gst_pad_pause_task (GstPad * pad)
4731 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4733 GST_DEBUG_OBJECT (pad, "pause task");
4735 GST_OBJECT_LOCK (pad);
4736 task = GST_PAD_TASK (pad);
4739 res = gst_task_set_state (task, GST_TASK_PAUSED);
4740 GST_OBJECT_UNLOCK (pad);
4742 /* wait for task function to finish, this lock is recursive so it does nothing
4743 * when the pause is called from the task itself */
4744 GST_PAD_STREAM_LOCK (pad);
4745 GST_PAD_STREAM_UNLOCK (pad);
4751 GST_DEBUG_OBJECT (pad, "pad has no task");
4752 GST_OBJECT_UNLOCK (pad);
4758 * gst_pad_stop_task:
4759 * @pad: the #GstPad to stop the task of
4761 * Stop the task of @pad. This function will also make sure that the
4762 * function executed by the task will effectively stop if not called
4763 * from the GstTaskFunction.
4765 * This function will deadlock if called from the GstTaskFunction of
4766 * the task. Use gst_task_pause() instead.
4768 * Regardless of whether the pad has a task, the stream lock is acquired and
4769 * released so as to ensure that streaming through this pad has finished.
4771 * Returns: a TRUE if the task could be stopped or FALSE on error.
4774 gst_pad_stop_task (GstPad * pad)
4779 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4781 GST_DEBUG_OBJECT (pad, "stop task");
4783 GST_OBJECT_LOCK (pad);
4784 task = GST_PAD_TASK (pad);
4787 GST_PAD_TASK (pad) = NULL;
4788 res = gst_task_set_state (task, GST_TASK_STOPPED);
4789 GST_OBJECT_UNLOCK (pad);
4791 GST_PAD_STREAM_LOCK (pad);
4792 GST_PAD_STREAM_UNLOCK (pad);
4794 if (!gst_task_join (task))
4797 gst_object_unref (task);
4803 GST_DEBUG_OBJECT (pad, "no task");
4804 GST_OBJECT_UNLOCK (pad);
4806 GST_PAD_STREAM_LOCK (pad);
4807 GST_PAD_STREAM_UNLOCK (pad);
4809 /* this is not an error */
4814 /* this is bad, possibly the application tried to join the task from
4815 * the task's thread. We install the task again so that it will be stopped
4816 * again from the right thread next time hopefully. */
4817 GST_OBJECT_LOCK (pad);
4818 GST_DEBUG_OBJECT (pad, "join failed");
4819 /* we can only install this task if there was no other task */
4820 if (GST_PAD_TASK (pad) == NULL)
4821 GST_PAD_TASK (pad) = task;
4822 GST_OBJECT_UNLOCK (pad);