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, res, };
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 info->id = hook->hook_id;
2832 GST_OBJECT_UNLOCK (pad);
2834 ret = callback (pad, info, hook->data);
2836 GST_OBJECT_LOCK (pad);
2837 data->marshalled = TRUE;
2840 case GST_PAD_PROBE_REMOVE:
2841 /* remove the probe */
2842 GST_DEBUG_OBJECT (pad, "asked to remove hook");
2843 cleanup_hook (pad, hook);
2845 case GST_PAD_PROBE_DROP:
2846 /* need to drop the data, make sure other probes don't get called
2848 GST_DEBUG_OBJECT (pad, "asked to drop item");
2849 info->type = GST_PAD_PROBE_TYPE_INVALID;
2850 data->dropped = TRUE;
2852 case GST_PAD_PROBE_PASS:
2853 /* inform the pad block to let things pass */
2854 GST_DEBUG_OBJECT (pad, "asked to pass item");
2858 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
2865 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2866 "hook %lu with flags 0x%08x does not match %08x", hook->hook_id,
2872 #define PROBE_PRE_PULL(pad,mask,data,offs,size,label,probed,defaultval) \
2874 if (G_UNLIKELY (pad->num_probes)) { \
2875 /* we start with passing NULL as the data item */ \
2876 GstPadProbeInfo info = { mask, 0, NULL, offs, size }; \
2877 ret = do_probe_callbacks (pad, &info, defaultval); \
2878 /* store the possibly updated data item */ \
2879 data = GST_PAD_PROBE_INFO_DATA (&info); \
2880 /* if something went wrong, exit */ \
2881 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2883 /* otherwise check if the probe retured data */ \
2884 if (G_UNLIKELY (data != NULL)) \
2890 /* a probe that does not take or return any data */
2891 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
2893 if (G_UNLIKELY (pad->num_probes)) { \
2894 /* pass NULL as the data item */ \
2895 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
2896 ret = do_probe_callbacks (pad, &info, defaultval); \
2897 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2902 #define PROBE_FULL(pad,mask,data,offs,size,label,defaultval) \
2904 if (G_UNLIKELY (pad->num_probes)) { \
2905 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
2906 ret = do_probe_callbacks (pad, &info, defaultval); \
2907 data = GST_PAD_PROBE_INFO_DATA (&info); \
2908 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2913 #define PROBE_PUSH(pad,mask,data,label) \
2914 PROBE_FULL(pad, mask, data, -1, -1, label, GST_FLOW_OK);
2915 #define PROBE_PULL(pad,mask,data,offs,size,label) \
2916 PROBE_FULL(pad, mask, data, offs, size, label, GST_FLOW_OK);
2918 static GstFlowReturn
2919 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
2920 GstFlowReturn defaultval)
2929 data.marshalled = FALSE;
2930 data.dropped = FALSE;
2931 data.cookie = ++pad->priv->probe_cookie;
2934 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
2937 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2938 "do probes cookie %u", data.cookie);
2939 cookie = pad->priv->probe_list_cookie;
2941 g_hook_list_marshal (&pad->probes, TRUE,
2942 (GHookMarshaller) probe_hook_marshal, &data);
2944 /* if the list changed, call the new callbacks (they will not have their
2945 * cookie set to data.cookie */
2946 if (cookie != pad->priv->probe_list_cookie) {
2947 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2948 "probe list changed, restarting");
2952 /* the first item that dropped will stop the hooks and then we drop here */
2956 /* if no handler matched and we are blocking, let the item pass */
2957 if (!data.marshalled && is_block)
2960 /* At this point, all handlers returned either OK or PASS. If one handler
2961 * returned PASS, let the item pass */
2966 while (GST_PAD_IS_BLOCKED (pad)) {
2967 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2968 "we are blocked %d times", pad->num_blocked);
2970 /* we might have released the lock */
2971 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2974 /* now we block the streaming thread. It can be unlocked when we
2975 * deactivate the pad (which will also set the FLUSHING flag) or
2976 * when the pad is unblocked. A flushing event will also unblock
2977 * the pad after setting the FLUSHING flag. */
2978 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2979 "Waiting to be unblocked or set flushing");
2980 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
2981 GST_PAD_BLOCK_WAIT (pad);
2982 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
2983 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
2985 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2995 GST_DEBUG_OBJECT (pad, "pad is flushing");
2996 return GST_FLOW_WRONG_STATE;
3000 GST_DEBUG_OBJECT (pad, "data is dropped");
3001 return GST_FLOW_CUSTOM_SUCCESS;
3005 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3006 GST_DEBUG_OBJECT (pad, "data is passed");
3014 * gst_pad_get_offset:
3017 * Get the offset applied to the running time of @pad. @pad has to be a source
3020 * Returns: the offset.
3023 gst_pad_get_offset (GstPad * pad)
3027 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3029 GST_OBJECT_LOCK (pad);
3030 result = pad->offset;
3031 GST_OBJECT_UNLOCK (pad);
3037 * gst_pad_set_offset:
3039 * @offset: the offset
3041 * Set the offset that will be applied to the running time of @pad.
3044 gst_pad_set_offset (GstPad * pad, gint64 offset)
3048 g_return_if_fail (GST_IS_PAD (pad));
3050 GST_OBJECT_LOCK (pad);
3051 /* if nothing changed, do nothing */
3052 if (pad->offset == offset)
3055 pad->offset = offset;
3056 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3058 /* sinkpads will apply their offset the next time a segment
3059 * event is received. */
3060 if (GST_PAD_IS_SINK (pad))
3063 /* resend the last segment event on next buffer push */
3064 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3065 ev->received = FALSE;
3066 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3070 GST_OBJECT_UNLOCK (pad);
3076 * @pad: a #GstPad to invoke the default query on.
3077 * @query: (transfer none): the #GstQuery to perform.
3079 * Dispatches a query to a pad. The query should have been allocated by the
3080 * caller via one of the type-specific allocation functions. The element that
3081 * the pad belongs to is responsible for filling the query with an appropriate
3082 * response, which should then be parsed with a type-specific query parsing
3085 * Again, the caller is responsible for both the allocation and deallocation of
3086 * the query structure.
3088 * Please also note that some queries might need a running pipeline to work.
3090 * Returns: TRUE if the query could be performed.
3093 gst_pad_query (GstPad * pad, GstQuery * query)
3097 GstPadQueryFunction func;
3098 GstPadProbeType type;
3101 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3102 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3104 GST_DEBUG_OBJECT (pad, "sending query %p (%s)", query,
3105 GST_QUERY_TYPE_NAME (query));
3107 if (GST_PAD_IS_SRC (pad))
3108 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3110 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3112 GST_OBJECT_LOCK (pad);
3113 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3114 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3115 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3117 ACQUIRE_PARENT (pad, parent, no_parent);
3118 GST_OBJECT_UNLOCK (pad);
3120 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3123 res = func (pad, parent, query);
3125 RELEASE_PARENT (parent);
3127 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3128 GST_QUERY_TYPE_NAME (query), res);
3133 GST_OBJECT_LOCK (pad);
3134 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3135 GST_OBJECT_UNLOCK (pad);
3142 GST_DEBUG_OBJECT (pad, "had no parent");
3143 GST_OBJECT_UNLOCK (pad);
3148 GST_DEBUG_OBJECT (pad, "had no query function");
3149 RELEASE_PARENT (parent);
3154 GST_DEBUG_OBJECT (pad, "query failed");
3159 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3160 GST_OBJECT_UNLOCK (pad);
3166 * gst_pad_peer_query:
3167 * @pad: a #GstPad to invoke the peer query on.
3168 * @query: (transfer none): the #GstQuery to perform.
3170 * Performs gst_pad_query() on the peer of @pad.
3172 * The caller is responsible for both the allocation and deallocation of
3173 * the query structure.
3175 * Returns: TRUE if the query could be performed. This function returns %FALSE
3176 * if @pad has no peer.
3181 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3184 GstPadProbeType type;
3188 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3189 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3191 if (GST_PAD_IS_SRC (pad))
3192 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3194 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3196 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3197 GST_QUERY_TYPE_NAME (query));
3199 GST_OBJECT_LOCK (pad);
3200 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3201 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3202 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3204 peerpad = GST_PAD_PEER (pad);
3205 if (G_UNLIKELY (peerpad == NULL))
3208 gst_object_ref (peerpad);
3209 GST_OBJECT_UNLOCK (pad);
3211 res = gst_pad_query (peerpad, query);
3213 gst_object_unref (peerpad);
3218 GST_OBJECT_LOCK (pad);
3219 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3220 GST_OBJECT_UNLOCK (pad);
3227 GST_WARNING_OBJECT (pad, "pad has no peer");
3228 GST_OBJECT_UNLOCK (pad);
3233 GST_DEBUG_OBJECT (pad, "query failed");
3238 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3239 GST_OBJECT_UNLOCK (pad);
3244 /**********************************************************************
3245 * Data passing functions
3249 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3251 GstFlowReturn *data = user_data;
3255 GST_DEBUG_OBJECT (pad, "event %s was already received",
3256 GST_EVENT_TYPE_NAME (ev->event));
3259 GST_OBJECT_UNLOCK (pad);
3261 *data = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3262 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, &stored);
3264 GST_OBJECT_LOCK (pad);
3265 return *data == GST_FLOW_OK;
3268 /* this is the chain function that does not perform the additional argument
3269 * checking for that little extra speed.
3271 static inline GstFlowReturn
3272 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3277 GST_PAD_STREAM_LOCK (pad);
3279 GST_OBJECT_LOCK (pad);
3280 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3283 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3285 PROBE_PUSH (pad, type, data, probe_stopped);
3287 parent = GST_OBJECT_PARENT (pad);
3288 GST_OBJECT_UNLOCK (pad);
3290 /* NOTE: we read the chainfunc unlocked.
3291 * we cannot hold the lock for the pad so we might send
3292 * the data to the wrong function. This is not really a
3293 * problem since functions are assigned at creation time
3294 * and don't change that often... */
3295 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3296 GstPadChainFunction chainfunc;
3298 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3301 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3302 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3303 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3305 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3307 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3308 "called chainfunction &%s with buffer %p, returned %s",
3309 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3311 GstPadChainListFunction chainlistfunc;
3313 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3316 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3317 "calling chainlistfunction &%s",
3318 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3320 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3322 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3323 "called chainlistfunction &%s, returned %s",
3324 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3327 GST_PAD_STREAM_UNLOCK (pad);
3334 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3335 "chaining, but pad was flushing");
3336 GST_OBJECT_UNLOCK (pad);
3337 GST_PAD_STREAM_UNLOCK (pad);
3338 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3339 return GST_FLOW_WRONG_STATE;
3343 GST_OBJECT_UNLOCK (pad);
3344 GST_PAD_STREAM_UNLOCK (pad);
3345 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3348 case GST_FLOW_CUSTOM_SUCCESS:
3349 GST_DEBUG_OBJECT (pad, "dropped buffer");
3353 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
3360 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3361 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3362 "pushing, but not chainhandler");
3363 GST_ELEMENT_ERROR (parent, CORE, PAD, (NULL),
3364 ("push on pad %s:%s but it has no chainfunction",
3365 GST_DEBUG_PAD_NAME (pad)));
3366 GST_PAD_STREAM_UNLOCK (pad);
3367 return GST_FLOW_NOT_SUPPORTED;
3373 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3374 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3377 * Chain a buffer to @pad.
3379 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
3381 * If the buffer type is not acceptable for @pad (as negotiated with a
3382 * preceeding GST_EVENT_CAPS event), this function returns
3383 * #GST_FLOW_NOT_NEGOTIATED.
3385 * The function proceeds calling the chain function installed on @pad (see
3386 * gst_pad_set_chain_function()) and the return value of that function is
3387 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3390 * In all cases, success or failure, the caller loses its reference to @buffer
3391 * after calling this function.
3393 * Returns: a #GstFlowReturn from the pad.
3398 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3400 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3401 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3402 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3404 return gst_pad_chain_data_unchecked (pad,
3405 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3408 static GstFlowReturn
3409 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3410 GstBufferList * list)
3416 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3418 len = gst_buffer_list_length (list);
3421 for (i = 0; i < len; i++) {
3422 buffer = gst_buffer_list_get (list, i);
3424 gst_pad_chain_data_unchecked (pad,
3425 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3426 gst_buffer_ref (buffer));
3427 if (ret != GST_FLOW_OK)
3430 gst_buffer_list_unref (list);
3436 * gst_pad_chain_list:
3437 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3438 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3441 * Chain a bufferlist to @pad.
3443 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
3445 * If @pad was not negotiated properly with a CAPS event, this function
3446 * returns #GST_FLOW_NOT_NEGOTIATED.
3448 * The function proceeds calling the chainlist function installed on @pad (see
3449 * gst_pad_set_chain_list_function()) and the return value of that function is
3450 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3451 * chainlist function.
3453 * In all cases, success or failure, the caller loses its reference to @list
3454 * after calling this function.
3458 * Returns: a #GstFlowReturn from the pad.
3463 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3465 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3466 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3467 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3469 return gst_pad_chain_data_unchecked (pad,
3470 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3473 static GstFlowReturn
3474 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3479 GST_OBJECT_LOCK (pad);
3480 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3483 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3484 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3486 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3489 events_foreach (pad, push_sticky, &ret);
3490 if (ret != GST_FLOW_OK)
3494 /* do block probes */
3495 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3497 /* do post-blocking probes */
3498 PROBE_PUSH (pad, type, data, probe_stopped);
3500 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3503 /* take ref to peer pad before releasing the lock */
3504 gst_object_ref (peer);
3506 GST_OBJECT_UNLOCK (pad);
3508 ret = gst_pad_chain_data_unchecked (peer, type, data);
3510 gst_object_unref (peer);
3512 GST_OBJECT_LOCK (pad);
3514 if (pad->priv->using == 0) {
3515 /* pad is not active anymore, trigger idle callbacks */
3516 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3517 probe_stopped, ret);
3519 GST_OBJECT_UNLOCK (pad);
3523 /* ERROR recovery here */
3527 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3528 "pushing, but pad was flushing");
3529 GST_OBJECT_UNLOCK (pad);
3530 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3531 return GST_FLOW_WRONG_STATE;
3535 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3536 "error pushing events, return %s", gst_flow_get_name (ret));
3537 GST_OBJECT_UNLOCK (pad);
3538 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3543 GST_OBJECT_UNLOCK (pad);
3544 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3547 case GST_FLOW_CUSTOM_SUCCESS:
3548 GST_DEBUG_OBJECT (pad, "dropped buffer");
3552 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
3559 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3560 "pushing, but it was not linked");
3561 GST_OBJECT_UNLOCK (pad);
3562 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3563 return GST_FLOW_NOT_LINKED;
3569 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3570 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
3573 * Pushes a buffer to the peer of @pad.
3575 * This function will call installed block probes before triggering any
3576 * installed data probes.
3578 * The function proceeds calling gst_pad_chain() on the peer pad and returns
3579 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3582 * In all cases, success or failure, the caller loses its reference to @buffer
3583 * after calling this function.
3585 * Returns: a #GstFlowReturn from the peer pad.
3590 gst_pad_push (GstPad * pad, GstBuffer * buffer)
3592 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3593 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3594 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3596 return gst_pad_push_data (pad,
3597 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3601 * gst_pad_push_list:
3602 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3603 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
3606 * Pushes a buffer list to the peer of @pad.
3608 * This function will call installed block probes before triggering any
3609 * installed data probes.
3611 * The function proceeds calling the chain function on the peer pad and returns
3612 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3613 * be returned. If the peer pad does not have any installed chainlist function
3614 * every group buffer of the list will be merged into a normal #GstBuffer and
3615 * chained via gst_pad_chain().
3617 * In all cases, success or failure, the caller loses its reference to @list
3618 * after calling this function.
3620 * Returns: a #GstFlowReturn from the peer pad.
3627 gst_pad_push_list (GstPad * pad, GstBufferList * list)
3629 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3630 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3631 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3633 return gst_pad_push_data (pad,
3634 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3637 static GstFlowReturn
3638 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
3639 GstBuffer ** buffer)
3642 GstPadGetRangeFunction getrangefunc;
3645 GST_PAD_STREAM_LOCK (pad);
3647 GST_OBJECT_LOCK (pad);
3648 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3651 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3652 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3654 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3657 events_foreach (pad, push_sticky, &ret);
3658 if (ret != GST_FLOW_OK)
3662 /* when one of the probes returns a buffer, probed_data will be called and we
3663 * skip calling the getrange function */
3664 PROBE_PRE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
3665 *buffer, offset, size, probe_stopped, probed_data, GST_FLOW_OK);
3667 ACQUIRE_PARENT (pad, parent, no_parent);
3668 GST_OBJECT_UNLOCK (pad);
3670 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
3673 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3674 "calling getrangefunc %s, offset %"
3675 G_GUINT64_FORMAT ", size %u",
3676 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
3678 ret = getrangefunc (pad, parent, offset, size, buffer);
3680 RELEASE_PARENT (parent);
3682 if (G_UNLIKELY (ret != GST_FLOW_OK))
3683 goto get_range_failed;
3685 /* can only fire the signal if we have a valid buffer */
3686 GST_OBJECT_LOCK (pad);
3688 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
3689 *buffer, offset, size, probe_stopped_unref);
3690 GST_OBJECT_UNLOCK (pad);
3692 GST_PAD_STREAM_UNLOCK (pad);
3699 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3700 "getrange, but pad was flushing");
3701 GST_OBJECT_UNLOCK (pad);
3702 GST_PAD_STREAM_UNLOCK (pad);
3703 return GST_FLOW_WRONG_STATE;
3707 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
3708 GST_OBJECT_UNLOCK (pad);
3709 GST_PAD_STREAM_UNLOCK (pad);
3714 GST_DEBUG_OBJECT (pad, "no parent");
3715 GST_OBJECT_UNLOCK (pad);
3716 GST_PAD_STREAM_UNLOCK (pad);
3717 return GST_FLOW_WRONG_STATE;
3721 GST_ELEMENT_ERROR (parent, CORE, PAD, (NULL),
3722 ("getrange on pad %s:%s but it has no getrangefunction",
3723 GST_DEBUG_PAD_NAME (pad)));
3724 RELEASE_PARENT (parent);
3725 GST_PAD_STREAM_UNLOCK (pad);
3726 return GST_FLOW_NOT_SUPPORTED;
3730 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3731 "probe returned %s", gst_flow_get_name (ret));
3732 GST_OBJECT_UNLOCK (pad);
3733 GST_PAD_STREAM_UNLOCK (pad);
3736 probe_stopped_unref:
3738 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3739 "probe returned %s", gst_flow_get_name (ret));
3740 GST_OBJECT_UNLOCK (pad);
3741 GST_PAD_STREAM_UNLOCK (pad);
3742 gst_buffer_unref (*buffer);
3748 GST_PAD_STREAM_UNLOCK (pad);
3750 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
3751 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
3752 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
3758 * gst_pad_get_range:
3759 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
3760 * @offset: The start offset of the buffer
3761 * @size: The length of the buffer
3762 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
3763 * returns #GST_FLOW_ERROR if %NULL.
3765 * When @pad is flushing this function returns #GST_FLOW_WRONG_STATE
3766 * immediately and @buffer is %NULL.
3768 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
3769 * description of a getrange function. If @pad has no getrange function
3770 * installed (see gst_pad_set_getrange_function()) this function returns
3771 * #GST_FLOW_NOT_SUPPORTED.
3773 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
3775 * Returns: a #GstFlowReturn from the pad.
3780 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
3781 GstBuffer ** buffer)
3783 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3784 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3785 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3787 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
3791 * gst_pad_pull_range:
3792 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3793 * @offset: The start offset of the buffer
3794 * @size: The length of the buffer
3795 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
3796 * GST_FLOW_ERROR if %NULL.
3798 * Pulls a @buffer from the peer pad.
3800 * This function will first trigger the pad block signal if it was
3803 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
3804 * function returns the result of gst_pad_get_range() on the peer pad.
3805 * See gst_pad_get_range() for a list of return values and for the
3806 * semantics of the arguments of this function.
3808 * Returns: a #GstFlowReturn from the peer pad.
3809 * When this function returns #GST_FLOW_OK, @buffer will contain a valid
3810 * #GstBuffer that should be freed with gst_buffer_unref() after usage.
3811 * @buffer may not be used or freed when any other return value than
3812 * #GST_FLOW_OK is returned.
3817 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
3818 GstBuffer ** buffer)
3823 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3824 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3825 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3827 GST_OBJECT_LOCK (pad);
3828 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3831 /* when one of the probes returns a buffer, probed_data will be called and we
3832 * skip calling the peer getrange function */
3833 PROBE_PRE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
3834 *buffer, offset, size, pre_probe_stopped, probed_data, GST_FLOW_OK);
3836 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3839 gst_object_ref (peer);
3841 GST_OBJECT_UNLOCK (pad);
3843 ret = gst_pad_get_range_unchecked (peer, offset, size, buffer);
3845 gst_object_unref (peer);
3847 GST_OBJECT_LOCK (pad);
3849 if (pad->priv->using == 0) {
3850 /* pad is not active anymore, trigger idle callbacks */
3851 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
3852 post_probe_stopped, ret);
3855 if (G_UNLIKELY (ret != GST_FLOW_OK))
3856 goto pull_range_failed;
3859 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
3860 *buffer, offset, size, post_probe_stopped);
3862 GST_OBJECT_UNLOCK (pad);
3866 /* ERROR recovery here */
3869 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3870 "pullrange, but pad was flushing");
3871 GST_OBJECT_UNLOCK (pad);
3872 return GST_FLOW_WRONG_STATE;
3876 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
3877 gst_flow_get_name (ret));
3878 GST_OBJECT_UNLOCK (pad);
3883 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3884 "pulling range, but it was not linked");
3885 GST_OBJECT_UNLOCK (pad);
3886 return GST_FLOW_NOT_LINKED;
3891 GST_OBJECT_UNLOCK (pad);
3892 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
3893 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
3894 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
3899 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3900 "post probe returned %s", gst_flow_get_name (ret));
3901 GST_OBJECT_UNLOCK (pad);
3902 if (ret == GST_FLOW_OK)
3903 gst_buffer_unref (*buffer);
3910 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event, gboolean locked)
3915 gboolean res = FALSE;
3916 const gchar *name = NULL;
3918 type = GST_EVENT_TYPE (event);
3919 if (type & GST_EVENT_TYPE_STICKY_MULTI)
3920 name = gst_structure_get_name (gst_event_get_structure (event));
3922 events = pad->priv->events;
3925 for (i = 0; i < len; i++) {
3926 PadEvent *ev = &g_array_index (events, PadEvent, i);
3928 if (ev->event == NULL)
3931 if (type == GST_EVENT_TYPE (ev->event)) {
3932 /* matching types, check matching name if needed */
3933 if (name && !gst_event_has_name (ev->event, name))
3937 if ((res = gst_event_replace (&ev->event, event)))
3938 ev->received = FALSE;
3944 ev.event = gst_event_ref (event);
3945 ev.received = FALSE;
3946 g_array_append_val (events, ev);
3951 pad->priv->events_cookie++;
3952 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3954 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
3956 switch (GST_EVENT_TYPE (event)) {
3957 case GST_EVENT_CAPS:
3959 GST_OBJECT_UNLOCK (pad);
3961 GST_DEBUG_OBJECT (pad, "notify caps");
3962 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
3965 GST_OBJECT_LOCK (pad);
3974 static GstFlowReturn
3975 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
3976 GstPadProbeType type, gboolean * stored)
3980 GstEventType event_type;
3983 sticky = GST_EVENT_IS_STICKY (event);
3985 GST_OBJECT_LOCK (pad);
3987 /* Two checks to be made:
3988 * . (un)set the FLUSHING flag for flushing events,
3989 * . handle pad blocking */
3990 event_type = GST_EVENT_TYPE (event);
3992 switch (event_type) {
3993 case GST_EVENT_FLUSH_START:
3994 GST_PAD_SET_FLUSHING (pad);
3996 GST_PAD_BLOCK_BROADCAST (pad);
3997 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
3999 case GST_EVENT_FLUSH_STOP:
4000 GST_PAD_UNSET_FLUSHING (pad);
4002 /* Remove sticky EOS events */
4003 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4004 remove_event_by_type (pad, GST_EVENT_EOS);
4006 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4010 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4013 /* store the event on the pad, but only on srcpads. We always store the
4014 * event exactly how it was sent */
4016 /* srcpad sticky events are store immediately, the received flag is set
4017 * to FALSE and will be set to TRUE when we can successfully push the
4018 * event to the peer pad */
4019 if (gst_pad_store_sticky_event (pad, event, TRUE)) {
4020 GST_DEBUG_OBJECT (pad, "event %s updated",
4021 GST_EVENT_TYPE_NAME (event));
4026 switch (GST_EVENT_TYPE (event)) {
4027 case GST_EVENT_SEGMENT:
4028 /* pass the adjusted segment event on. We need to do this even if
4029 * there is no peer pad because of the probes. */
4030 event = apply_pad_offset (pad, event);
4032 case GST_EVENT_RECONFIGURE:
4033 if (GST_PAD_IS_SINK (pad))
4034 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4039 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4040 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4045 /* send probes after modifying the events above */
4046 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4048 /* now check the peer pad */
4049 peerpad = GST_PAD_PEER (pad);
4050 if (peerpad == NULL)
4053 gst_object_ref (peerpad);
4055 GST_OBJECT_UNLOCK (pad);
4057 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4058 event, GST_EVENT_TYPE_NAME (event), peerpad);
4060 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4062 /* Note: we gave away ownership of the event at this point but we can still
4063 * print the old pointer */
4064 GST_LOG_OBJECT (pad,
4065 "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s", event, peerpad,
4066 gst_flow_get_name (ret));
4068 gst_object_unref (peerpad);
4070 GST_OBJECT_LOCK (pad);
4072 if (ret == GST_FLOW_OK) {
4075 if ((ev = find_event (pad, event)))
4076 ev->received = TRUE;
4078 GST_DEBUG_OBJECT (pad, "event marked received");
4080 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4081 GST_DEBUG_OBJECT (pad, "mark pending events");
4085 if (pad->priv->using == 0) {
4086 /* pad is not active anymore, trigger idle callbacks */
4087 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4088 idle_probe_stopped, ret);
4090 GST_OBJECT_UNLOCK (pad);
4094 /* ERROR handling */
4097 GST_DEBUG_OBJECT (pad, "We're flushing");
4098 GST_OBJECT_UNLOCK (pad);
4099 gst_event_unref (event);
4100 return GST_FLOW_WRONG_STATE;
4104 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4105 GST_OBJECT_UNLOCK (pad);
4106 gst_event_unref (event);
4109 case GST_FLOW_CUSTOM_SUCCESS:
4110 GST_DEBUG_OBJECT (pad, "dropped event");
4114 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
4121 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4122 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4123 GST_OBJECT_UNLOCK (pad);
4124 gst_event_unref (event);
4125 return sticky ? GST_FLOW_OK : GST_FLOW_NOT_LINKED;
4129 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4130 GST_OBJECT_UNLOCK (pad);
4136 * gst_pad_push_event:
4137 * @pad: a #GstPad to push the event to.
4138 * @event: (transfer full): the #GstEvent to send to the pad.
4140 * Sends the event to the peer of the given pad. This function is
4141 * mainly used by elements to send events to their peer
4144 * This function takes owership of the provided event so you should
4145 * gst_event_ref() it if you want to reuse the event after this call.
4147 * Returns: TRUE if the event was handled.
4152 gst_pad_push_event (GstPad * pad, GstEvent * event)
4155 GstPadProbeType type;
4158 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4159 g_return_val_if_fail (event != NULL, FALSE);
4160 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4162 if (GST_PAD_IS_SRC (pad)) {
4163 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4164 goto wrong_direction;
4165 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4166 } else if (GST_PAD_IS_SINK (pad)) {
4167 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4168 goto wrong_direction;
4169 /* events pushed on sinkpad never are sticky */
4170 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4172 goto unknown_direction;
4174 if (gst_pad_push_event_unchecked (pad, event, type, &stored) != GST_FLOW_OK)
4175 res = stored ? TRUE : FALSE;
4181 /* ERROR handling */
4184 g_warning ("pad %s:%s pushing %s event in wrong direction",
4185 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4186 gst_event_unref (event);
4191 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4192 gst_event_unref (event);
4197 /* Check if we can call the event function with the given event */
4198 static GstFlowReturn
4199 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4201 GstCaps *caps, *templ;
4203 switch (GST_EVENT_TYPE (event)) {
4204 case GST_EVENT_CAPS:
4206 /* backwards compatibility mode for caps */
4207 gst_event_parse_caps (event, &caps);
4209 /* See if pad accepts the caps */
4210 templ = gst_pad_get_pad_template_caps (pad);
4211 if (!gst_caps_is_subset (caps, templ))
4214 gst_caps_unref (templ);
4225 gst_caps_unref (templ);
4226 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4227 "caps %" GST_PTR_FORMAT " not accepted", caps);
4228 return GST_FLOW_NOT_NEGOTIATED;
4232 static GstFlowReturn
4233 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4234 GstPadProbeType type)
4237 GstEventType event_type;
4238 gboolean serialized, need_unlock = FALSE, sticky;
4239 GstPadEventFunction eventfunc;
4242 GST_OBJECT_LOCK (pad);
4243 if (GST_PAD_IS_SINK (pad))
4244 serialized = GST_EVENT_IS_SERIALIZED (event);
4247 sticky = GST_EVENT_IS_STICKY (event);
4248 event_type = GST_EVENT_TYPE (event);
4249 switch (event_type) {
4250 case GST_EVENT_FLUSH_START:
4251 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4252 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4254 /* can't even accept a flush begin event when flushing */
4255 if (GST_PAD_IS_FLUSHING (pad))
4258 GST_PAD_SET_FLUSHING (pad);
4259 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4261 case GST_EVENT_FLUSH_STOP:
4262 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4263 GST_PAD_UNSET_FLUSHING (pad);
4264 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4266 /* Remove pending EOS events */
4267 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4268 remove_event_by_type (pad, GST_EVENT_EOS);
4270 GST_OBJECT_UNLOCK (pad);
4271 /* grab stream lock */
4272 GST_PAD_STREAM_LOCK (pad);
4274 GST_OBJECT_LOCK (pad);
4275 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4278 case GST_EVENT_RECONFIGURE:
4279 if (GST_PAD_IS_SRC (pad))
4280 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4282 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "have event type %s",
4283 GST_EVENT_TYPE_NAME (event));
4285 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4289 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4290 GST_OBJECT_UNLOCK (pad);
4291 GST_PAD_STREAM_LOCK (pad);
4293 GST_OBJECT_LOCK (pad);
4294 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4298 switch (GST_EVENT_TYPE (event)) {
4299 case GST_EVENT_SEGMENT:
4300 event = apply_pad_offset (pad, event);
4306 /* now do the probe */
4308 type | GST_PAD_PROBE_TYPE_PUSH |
4309 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4311 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4315 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4318 ACQUIRE_PARENT (pad, parent, no_parent);
4319 GST_OBJECT_UNLOCK (pad);
4321 ret = pre_eventfunc_check (pad, event);
4322 if (G_UNLIKELY (ret != GST_FLOW_OK))
4323 goto precheck_failed;
4326 gst_event_ref (event);
4328 if (eventfunc (pad, parent, event)) {
4331 /* something went wrong */
4332 switch (event_type) {
4333 case GST_EVENT_CAPS:
4334 ret = GST_FLOW_NOT_NEGOTIATED;
4337 ret = GST_FLOW_ERROR;
4341 RELEASE_PARENT (parent);
4343 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
4346 if (ret == GST_FLOW_OK) {
4347 /* after the event function accepted the event, we can store the sticky
4348 * event on the pad */
4349 gst_pad_store_sticky_event (pad, event, FALSE);
4351 gst_event_unref (event);
4355 GST_PAD_STREAM_UNLOCK (pad);
4359 /* ERROR handling */
4362 GST_OBJECT_UNLOCK (pad);
4364 GST_PAD_STREAM_UNLOCK (pad);
4365 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
4366 "Received event on flushing pad. Discarding");
4367 gst_event_unref (event);
4368 return GST_FLOW_WRONG_STATE;
4372 GST_OBJECT_UNLOCK (pad);
4374 GST_PAD_STREAM_UNLOCK (pad);
4375 gst_event_unref (event);
4378 case GST_FLOW_CUSTOM_SUCCESS:
4379 GST_DEBUG_OBJECT (pad, "dropped event");
4383 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
4390 g_warning ("pad %s:%s has no event handler, file a bug.",
4391 GST_DEBUG_PAD_NAME (pad));
4392 GST_OBJECT_UNLOCK (pad);
4394 GST_PAD_STREAM_UNLOCK (pad);
4395 gst_event_unref (event);
4396 return GST_FLOW_NOT_SUPPORTED;
4400 GST_DEBUG_OBJECT (pad, "no parent");
4401 GST_OBJECT_UNLOCK (pad);
4403 GST_PAD_STREAM_UNLOCK (pad);
4404 gst_event_unref (event);
4405 return GST_FLOW_WRONG_STATE;
4409 GST_DEBUG_OBJECT (pad, "pre event check failed");
4410 RELEASE_PARENT (parent);
4412 GST_PAD_STREAM_UNLOCK (pad);
4413 gst_event_unref (event);
4419 * gst_pad_send_event:
4420 * @pad: a #GstPad to send the event to.
4421 * @event: (transfer full): the #GstEvent to send to the pad.
4423 * Sends the event to the pad. This function can be used
4424 * by applications to send events in the pipeline.
4426 * If @pad is a source pad, @event should be an upstream event. If @pad is a
4427 * sink pad, @event should be a downstream event. For example, you would not
4428 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
4429 * Furthermore, some downstream events have to be serialized with data flow,
4430 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
4431 * the event needs to be serialized with data flow, this function will take the
4432 * pad's stream lock while calling its event function.
4434 * To find out whether an event type is upstream, downstream, or downstream and
4435 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
4436 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
4437 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
4438 * plugin doesn't need to bother itself with this information; the core handles
4439 * all necessary locks and checks.
4441 * This function takes owership of the provided event so you should
4442 * gst_event_ref() it if you want to reuse the event after this call.
4444 * Returns: TRUE if the event was handled.
4447 gst_pad_send_event (GstPad * pad, GstEvent * event)
4450 GstPadProbeType type;
4452 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4453 g_return_val_if_fail (event != NULL, FALSE);
4455 if (GST_PAD_IS_SINK (pad)) {
4456 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4457 goto wrong_direction;
4458 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4459 } else if (GST_PAD_IS_SRC (pad)) {
4460 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4461 goto wrong_direction;
4462 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4464 goto unknown_direction;
4466 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
4473 /* ERROR handling */
4476 g_warning ("pad %s:%s sending %s event in wrong direction",
4477 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4478 gst_event_unref (event);
4483 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4484 gst_event_unref (event);
4490 * gst_pad_set_element_private:
4491 * @pad: the #GstPad to set the private data of.
4492 * @priv: The private data to attach to the pad.
4494 * Set the given private data gpointer on the pad.
4495 * This function can only be used by the element that owns the pad.
4496 * No locking is performed in this function.
4499 gst_pad_set_element_private (GstPad * pad, gpointer priv)
4501 pad->element_private = priv;
4505 * gst_pad_get_element_private:
4506 * @pad: the #GstPad to get the private data of.
4508 * Gets the private data of a pad.
4509 * No locking is performed in this function.
4511 * Returns: (transfer none): a #gpointer to the private data.
4514 gst_pad_get_element_private (GstPad * pad)
4516 return pad->element_private;
4520 * gst_pad_get_sticky_event:
4521 * @pad: the #GstPad to get the event from.
4522 * @event_type: the #GstEventType that should be retrieved.
4523 * @idx: the index of the event
4525 * Returns a new reference of the sticky event of type @event_type
4528 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
4529 * event of @event_type was on @pad. Unref after usage.
4532 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
4534 GstEvent *event = NULL;
4537 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4538 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
4540 GST_OBJECT_LOCK (pad);
4541 ev = find_event_by_type (pad, event_type, idx);
4542 if (ev && (event = ev->event))
4543 gst_event_ref (event);
4544 GST_OBJECT_UNLOCK (pad);
4551 GstPadStickyEventsForeachFunction func;
4556 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
4558 ForeachDispatch *data = user_data;
4561 GST_OBJECT_UNLOCK (pad);
4563 ret = data->func (pad, &ev->event, data->user_data);
4565 GST_OBJECT_LOCK (pad);
4571 * gst_pad_sticky_events_foreach:
4572 * @pad: the #GstPad that should be used for iteration.
4573 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
4574 * should be called for every event.
4575 * @user_data: (closure): the optional user data.
4577 * Iterates all sticky events on @pad and calls @foreach_func for every
4578 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
4581 gst_pad_sticky_events_foreach (GstPad * pad,
4582 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
4584 ForeachDispatch data;
4586 g_return_if_fail (GST_IS_PAD (pad));
4587 g_return_if_fail (foreach_func != NULL);
4589 data.func = foreach_func;
4590 data.user_data = user_data;
4592 GST_OBJECT_LOCK (pad);
4593 events_foreach (pad, foreach_dispatch_function, &data);
4594 GST_OBJECT_UNLOCK (pad);
4598 do_stream_status (GstPad * pad, GstStreamStatusType type,
4599 GThread * thread, GstTask * task)
4603 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
4605 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
4606 if (GST_IS_ELEMENT (parent)) {
4607 GstMessage *message;
4608 GValue value = { 0 };
4610 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
4611 gchar *tname, *ename, *pname;
4613 /* create a good task name */
4614 ename = gst_element_get_name (parent);
4615 pname = gst_pad_get_name (pad);
4616 tname = g_strdup_printf ("%s:%s", ename, pname);
4620 gst_object_set_name (GST_OBJECT_CAST (task), tname);
4624 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
4627 g_value_init (&value, GST_TYPE_TASK);
4628 g_value_set_object (&value, task);
4629 gst_message_set_stream_status_object (message, &value);
4630 g_value_unset (&value);
4632 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
4633 gst_element_post_message (parent, message);
4635 gst_object_unref (parent);
4640 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
4642 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
4647 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
4649 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
4653 static GstTaskThreadCallbacks thr_callbacks = {
4659 * gst_pad_start_task:
4660 * @pad: the #GstPad to start the task of
4661 * @func: the task function to call
4662 * @data: data passed to the task function
4664 * Starts a task that repeatedly calls @func with @data. This function
4665 * is mostly used in pad activation functions to start the dataflow.
4666 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
4667 * before @func is called.
4669 * Returns: a %TRUE if the task could be started.
4672 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
4677 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4678 g_return_val_if_fail (func != NULL, FALSE);
4680 GST_DEBUG_OBJECT (pad, "start task");
4682 GST_OBJECT_LOCK (pad);
4683 task = GST_PAD_TASK (pad);
4685 task = gst_task_new (func, data);
4686 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
4687 gst_task_set_thread_callbacks (task, &thr_callbacks, pad, NULL);
4688 GST_DEBUG_OBJECT (pad, "created task");
4689 GST_PAD_TASK (pad) = task;
4690 gst_object_ref (task);
4691 /* release lock to post the message */
4692 GST_OBJECT_UNLOCK (pad);
4694 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
4696 gst_object_unref (task);
4698 GST_OBJECT_LOCK (pad);
4699 /* nobody else is supposed to have changed the pad now */
4700 if (GST_PAD_TASK (pad) != task)
4701 goto concurrent_stop;
4703 res = gst_task_set_state (task, GST_TASK_STARTED);
4704 GST_OBJECT_UNLOCK (pad);
4711 GST_OBJECT_UNLOCK (pad);
4717 * gst_pad_pause_task:
4718 * @pad: the #GstPad to pause the task of
4720 * Pause the task of @pad. This function will also wait until the
4721 * function executed by the task is finished if this function is not
4722 * called from the task function.
4724 * Returns: a TRUE if the task could be paused or FALSE when the pad
4728 gst_pad_pause_task (GstPad * pad)
4733 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4735 GST_DEBUG_OBJECT (pad, "pause task");
4737 GST_OBJECT_LOCK (pad);
4738 task = GST_PAD_TASK (pad);
4741 res = gst_task_set_state (task, GST_TASK_PAUSED);
4742 GST_OBJECT_UNLOCK (pad);
4744 /* wait for task function to finish, this lock is recursive so it does nothing
4745 * when the pause is called from the task itself */
4746 GST_PAD_STREAM_LOCK (pad);
4747 GST_PAD_STREAM_UNLOCK (pad);
4753 GST_DEBUG_OBJECT (pad, "pad has no task");
4754 GST_OBJECT_UNLOCK (pad);
4760 * gst_pad_stop_task:
4761 * @pad: the #GstPad to stop the task of
4763 * Stop the task of @pad. This function will also make sure that the
4764 * function executed by the task will effectively stop if not called
4765 * from the GstTaskFunction.
4767 * This function will deadlock if called from the GstTaskFunction of
4768 * the task. Use gst_task_pause() instead.
4770 * Regardless of whether the pad has a task, the stream lock is acquired and
4771 * released so as to ensure that streaming through this pad has finished.
4773 * Returns: a TRUE if the task could be stopped or FALSE on error.
4776 gst_pad_stop_task (GstPad * pad)
4781 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4783 GST_DEBUG_OBJECT (pad, "stop task");
4785 GST_OBJECT_LOCK (pad);
4786 task = GST_PAD_TASK (pad);
4789 GST_PAD_TASK (pad) = NULL;
4790 res = gst_task_set_state (task, GST_TASK_STOPPED);
4791 GST_OBJECT_UNLOCK (pad);
4793 GST_PAD_STREAM_LOCK (pad);
4794 GST_PAD_STREAM_UNLOCK (pad);
4796 if (!gst_task_join (task))
4799 gst_object_unref (task);
4805 GST_DEBUG_OBJECT (pad, "no task");
4806 GST_OBJECT_UNLOCK (pad);
4808 GST_PAD_STREAM_LOCK (pad);
4809 GST_PAD_STREAM_UNLOCK (pad);
4811 /* this is not an error */
4816 /* this is bad, possibly the application tried to join the task from
4817 * the task's thread. We install the task again so that it will be stopped
4818 * again from the right thread next time hopefully. */
4819 GST_OBJECT_LOCK (pad);
4820 GST_DEBUG_OBJECT (pad, "join failed");
4821 /* we can only install this task if there was no other task */
4822 if (GST_PAD_TASK (pad) == NULL)
4823 GST_PAD_TASK (pad) = task;
4824 GST_OBJECT_UNLOCK (pad);