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_RESEND, "resend", 0},
172 {GST_FLOW_OK, "ok", 0},
173 {GST_FLOW_NOT_LINKED, "not-linked", 0},
174 {GST_FLOW_WRONG_STATE, "wrong-state", 0},
175 {GST_FLOW_EOS, "eos", 0},
176 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
177 {GST_FLOW_ERROR, "error", 0},
178 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
179 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
184 * @ret: a #GstFlowReturn to get the name of.
186 * Gets a string representing the given flow return.
188 * Returns: a static string with the name of the flow return.
191 gst_flow_get_name (GstFlowReturn ret)
195 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
197 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
198 if (ret == flow_quarks[i].ret)
199 return flow_quarks[i].name;
206 * @ret: a #GstFlowReturn to get the quark of.
208 * Get the unique quark for the given GstFlowReturn.
210 * Returns: the quark associated with the flow return or 0 if an
211 * invalid return was specified.
214 gst_flow_to_quark (GstFlowReturn ret)
218 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
220 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
221 if (ret == flow_quarks[i].ret)
222 return flow_quarks[i].quark;
231 buffer_quark = g_quark_from_static_string ("buffer"); \
232 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
233 event_quark = g_quark_from_static_string ("event"); \
235 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
236 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
239 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
240 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
243 #define gst_pad_parent_class parent_class
244 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
247 gst_pad_class_init (GstPadClass * klass)
249 GObjectClass *gobject_class;
250 GstObjectClass *gstobject_class;
252 gobject_class = G_OBJECT_CLASS (klass);
253 gstobject_class = GST_OBJECT_CLASS (klass);
255 g_type_class_add_private (klass, sizeof (GstPadPrivate));
257 gobject_class->dispose = gst_pad_dispose;
258 gobject_class->finalize = gst_pad_finalize;
259 gobject_class->set_property = gst_pad_set_property;
260 gobject_class->get_property = gst_pad_get_property;
264 * @pad: the pad that emitted the signal
265 * @peer: the peer pad that has been connected
267 * Signals that a pad has been linked to the peer pad.
269 gst_pad_signals[PAD_LINKED] =
270 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
271 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
272 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
275 * @pad: the pad that emitted the signal
276 * @peer: the peer pad that has been disconnected
278 * Signals that a pad has been unlinked from the peer pad.
280 gst_pad_signals[PAD_UNLINKED] =
281 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
282 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
283 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
285 pspec_caps = g_param_spec_boxed ("caps", "Caps",
286 "The capabilities of the pad", GST_TYPE_CAPS,
287 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
288 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
290 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
291 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
292 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
293 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
295 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
296 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
297 g_param_spec_object ("template", "Template",
298 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
299 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
301 gstobject_class->path_string_separator = ".";
303 /* Register common function pointer descriptions */
304 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
305 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
306 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
307 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
308 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
312 gst_pad_init (GstPad * pad)
314 pad->priv = GST_PAD_GET_PRIVATE (pad);
316 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
318 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
319 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
320 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
321 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
322 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
324 GST_PAD_SET_FLUSHING (pad);
326 g_static_rec_mutex_init (&pad->stream_rec_lock);
328 pad->block_cond = g_cond_new ();
330 g_hook_list_init (&pad->probes, sizeof (GstProbe));
332 pad->priv->events = g_array_sized_new (FALSE, TRUE,
333 sizeof (PadEvent), GST_EVENT_MAX_STICKY);
336 /* called when setting the pad inactive. It removes all sticky events from
339 remove_events (GstPad * pad)
344 events = pad->priv->events;
347 for (i = 0; i < len; i++) {
348 PadEvent *ev = &g_array_index (events, PadEvent, i);
349 gst_event_unref (ev->event);
351 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
352 g_array_set_size (events, 0);
353 pad->priv->events_cookie++;
357 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
363 events = pad->priv->events;
366 for (i = 0; i < len; i++) {
367 ev = &g_array_index (events, PadEvent, i);
368 if (ev->event == NULL)
371 if (GST_EVENT_TYPE (ev->event) == type) {
383 find_event (GstPad * pad, GstEvent * event)
389 events = pad->priv->events;
392 for (i = 0; i < len; i++) {
393 ev = &g_array_index (events, PadEvent, i);
394 if (event == ev->event)
403 remove_event_by_type (GstPad * pad, GstEventType type)
409 events = pad->priv->events;
414 ev = &g_array_index (events, PadEvent, i);
415 if (ev->event == NULL)
418 if (GST_EVENT_TYPE (ev->event) != type)
421 gst_event_unref (ev->event);
422 g_array_remove_index (events, i);
424 pad->priv->events_cookie++;
433 schedule_events (GstPad * srcpad, GstPad * sinkpad)
438 gboolean pending = FALSE;
440 events = srcpad->priv->events;
443 for (i = 0; i < len; i++) {
444 ev = &g_array_index (events, PadEvent, i);
445 if (ev->event == NULL)
448 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
449 ev->received = FALSE;
454 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
457 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
461 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
468 events = pad->priv->events;
471 cookie = pad->priv->events_cookie;
475 PadEvent *ev, ev_ret;
477 ev = &g_array_index (events, PadEvent, i);
478 if (G_UNLIKELY (ev->event == NULL))
481 /* take aditional ref, func might release the lock */
482 ev_ret.event = gst_event_ref (ev->event);
483 ev_ret.received = ev->received;
485 ret = func (pad, &ev_ret, user_data);
487 /* recheck the cookie, lock might have been released and the list could have
489 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
490 if (G_LIKELY (ev_ret.event))
491 gst_event_unref (ev_ret.event);
495 /* if the event changed, we need to do something */
496 if (G_UNLIKELY (ev->event != ev_ret.event)) {
497 if (G_UNLIKELY (ev_ret.event == NULL)) {
498 /* function unreffed and set the event to NULL, remove it */
499 g_array_remove_index (events, i);
501 cookie = ++pad->priv->events_cookie;
504 /* function gave a new event for us */
505 gst_event_take (&ev->event, ev_ret.event);
508 /* just unref, nothing changed */
509 gst_event_unref (ev_ret.event);
518 /* should be called with LOCK */
520 apply_pad_offset (GstPad * pad, GstEvent * event)
522 /* check if we need to adjust the segment */
523 if (pad->offset != 0) {
526 /* copy segment values */
527 gst_event_copy_segment (event, &segment);
528 gst_event_unref (event);
530 /* adjust and make a new event with the offset applied */
531 segment.base += pad->offset;
532 event = gst_event_new_segment (&segment);
537 /* should be called with the OBJECT_LOCK */
539 get_pad_caps (GstPad * pad)
541 GstCaps *caps = NULL;
544 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
546 gst_event_parse_caps (ev->event, &caps);
552 gst_pad_dispose (GObject * object)
554 GstPad *pad = GST_PAD_CAST (object);
557 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
559 /* unlink the peer pad */
560 if ((peer = gst_pad_get_peer (pad))) {
561 /* window for MT unsafeness, someone else could unlink here
562 * and then we call unlink with wrong pads. The unlink
563 * function would catch this and safely return failed. */
564 if (GST_PAD_IS_SRC (pad))
565 gst_pad_unlink (pad, peer);
567 gst_pad_unlink (peer, pad);
569 gst_object_unref (peer);
572 gst_pad_set_pad_template (pad, NULL);
576 g_hook_list_clear (&pad->probes);
578 G_OBJECT_CLASS (parent_class)->dispose (object);
582 gst_pad_finalize (GObject * object)
584 GstPad *pad = GST_PAD_CAST (object);
587 /* in case the task is still around, clean it up */
588 if ((task = GST_PAD_TASK (pad))) {
589 gst_task_join (task);
590 GST_PAD_TASK (pad) = NULL;
591 gst_object_unref (task);
594 if (pad->activatenotify)
595 pad->activatenotify (pad);
596 if (pad->activatemodenotify)
597 pad->activatemodenotify (pad);
599 pad->linknotify (pad);
600 if (pad->unlinknotify)
601 pad->unlinknotify (pad);
602 if (pad->chainnotify)
603 pad->chainnotify (pad);
604 if (pad->chainlistnotify)
605 pad->chainlistnotify (pad);
606 if (pad->getrangenotify)
607 pad->getrangenotify (pad);
608 if (pad->eventnotify)
609 pad->eventnotify (pad);
610 if (pad->querynotify)
611 pad->querynotify (pad);
612 if (pad->iterintlinknotify)
613 pad->iterintlinknotify (pad);
615 g_static_rec_mutex_free (&pad->stream_rec_lock);
616 g_cond_free (pad->block_cond);
617 g_array_free (pad->priv->events, TRUE);
619 G_OBJECT_CLASS (parent_class)->finalize (object);
623 gst_pad_set_property (GObject * object, guint prop_id,
624 const GValue * value, GParamSpec * pspec)
626 g_return_if_fail (GST_IS_PAD (object));
629 case PAD_PROP_DIRECTION:
630 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
632 case PAD_PROP_TEMPLATE:
633 gst_pad_set_pad_template (GST_PAD_CAST (object),
634 (GstPadTemplate *) g_value_get_object (value));
637 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
643 gst_pad_get_property (GObject * object, guint prop_id,
644 GValue * value, GParamSpec * pspec)
646 g_return_if_fail (GST_IS_PAD (object));
650 GST_OBJECT_LOCK (object);
651 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
652 GST_OBJECT_UNLOCK (object);
654 case PAD_PROP_DIRECTION:
655 g_value_set_enum (value, GST_PAD_DIRECTION (object));
657 case PAD_PROP_TEMPLATE:
658 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
661 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
668 * @name: the name of the new pad.
669 * @direction: the #GstPadDirection of the pad.
671 * Creates a new pad with the given name in the given direction.
672 * If name is NULL, a guaranteed unique name (across all pads)
674 * This function makes a copy of the name so you can safely free the name.
676 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
681 gst_pad_new (const gchar * name, GstPadDirection direction)
683 return g_object_new (GST_TYPE_PAD,
684 "name", name, "direction", direction, NULL);
688 * gst_pad_new_from_template:
689 * @templ: the pad template to use
690 * @name: the name of the element
692 * Creates a new pad with the given name from the given template.
693 * If name is NULL, a guaranteed unique name (across all pads)
695 * This function makes a copy of the name so you can safely free the name.
697 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
700 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
702 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
704 return g_object_new (GST_TYPE_PAD,
705 "name", name, "direction", templ->direction, "template", templ, NULL);
709 * gst_pad_new_from_static_template:
710 * @templ: the #GstStaticPadTemplate to use
711 * @name: the name of the element
713 * Creates a new pad with the given name from the given static template.
714 * If name is NULL, a guaranteed unique name (across all pads)
716 * This function makes a copy of the name so you can safely free the name.
718 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
721 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
725 GstPadTemplate *template;
727 template = gst_static_pad_template_get (templ);
728 pad = gst_pad_new_from_template (template, name);
729 gst_object_unref (template);
733 #define ACQUIRE_PARENT(pad, parent, label) \
735 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
736 gst_object_ref (parent); \
737 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
741 #define RELEASE_PARENT(parent) \
743 if (G_LIKELY (parent)) \
744 gst_object_unref (parent); \
748 * gst_pad_get_direction:
749 * @pad: a #GstPad to get the direction of.
751 * Gets the direction of the pad. The direction of the pad is
752 * decided at construction time so this function does not take
755 * Returns: the #GstPadDirection of the pad.
760 gst_pad_get_direction (GstPad * pad)
762 GstPadDirection result;
764 /* PAD_UNKNOWN is a little silly but we need some sort of
765 * error return value */
766 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
768 result = GST_PAD_DIRECTION (pad);
774 gst_pad_activate_default (GstPad * pad, GstObject * parent)
776 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
780 pre_activate (GstPad * pad, GstPadMode new_mode)
783 case GST_PAD_MODE_NONE:
784 GST_OBJECT_LOCK (pad);
785 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
786 GST_PAD_SET_FLUSHING (pad);
787 GST_PAD_MODE (pad) = new_mode;
788 /* unlock blocked pads so element can resume and stop */
789 GST_PAD_BLOCK_BROADCAST (pad);
790 GST_OBJECT_UNLOCK (pad);
792 case GST_PAD_MODE_PUSH:
793 case GST_PAD_MODE_PULL:
794 GST_OBJECT_LOCK (pad);
795 GST_DEBUG_OBJECT (pad, "setting PAD_MODE %d, unset flushing", new_mode);
796 GST_PAD_UNSET_FLUSHING (pad);
797 GST_PAD_MODE (pad) = new_mode;
798 if (GST_PAD_IS_SINK (pad)) {
800 /* make sure the peer src pad sends us all events */
801 if ((peer = GST_PAD_PEER (pad))) {
802 gst_object_ref (peer);
803 GST_OBJECT_UNLOCK (pad);
805 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
806 GST_DEBUG_PAD_NAME (peer));
808 GST_OBJECT_LOCK (peer);
809 schedule_events (peer, NULL);
810 GST_OBJECT_UNLOCK (peer);
812 gst_object_unref (peer);
814 GST_OBJECT_UNLOCK (pad);
817 GST_OBJECT_UNLOCK (pad);
824 post_activate (GstPad * pad, GstPadMode new_mode)
827 case GST_PAD_MODE_NONE:
828 /* ensures that streaming stops */
829 GST_PAD_STREAM_LOCK (pad);
830 GST_DEBUG_OBJECT (pad, "stopped streaming");
831 GST_OBJECT_LOCK (pad);
833 GST_OBJECT_UNLOCK (pad);
834 GST_PAD_STREAM_UNLOCK (pad);
836 case GST_PAD_MODE_PUSH:
837 case GST_PAD_MODE_PULL:
844 * gst_pad_set_active:
845 * @pad: the #GstPad to activate or deactivate.
846 * @active: whether or not the pad should be active.
848 * Activates or deactivates the given pad.
849 * Normally called from within core state change functions.
851 * If @active, makes sure the pad is active. If it is already active, either in
852 * push or pull mode, just return. Otherwise dispatches to the pad's activate
853 * function to perform the actual activation.
855 * If not @active, checks the pad's current mode and calls
856 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
859 * Returns: #TRUE if the operation was successful.
864 gst_pad_set_active (GstPad * pad, gboolean active)
868 gboolean ret = FALSE;
870 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
872 GST_OBJECT_LOCK (pad);
873 old = GST_PAD_MODE (pad);
874 ACQUIRE_PARENT (pad, parent, no_parent);
875 GST_OBJECT_UNLOCK (pad);
878 if (old == GST_PAD_MODE_NONE) {
879 GST_DEBUG_OBJECT (pad, "activating pad from none");
880 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
882 GST_DEBUG_OBJECT (pad, "pad was active in mode %d", old);
886 if (old == GST_PAD_MODE_NONE) {
887 GST_DEBUG_OBJECT (pad, "pad was inactive");
890 GST_DEBUG_OBJECT (pad, "deactivating pad from mode %d", old);
891 ret = gst_pad_activate_mode (pad, old, FALSE);
895 RELEASE_PARENT (parent);
897 if (G_UNLIKELY (!ret))
901 GST_OBJECT_LOCK (pad);
902 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
903 GST_OBJECT_UNLOCK (pad);
910 GST_DEBUG_OBJECT (pad, "no parent");
911 GST_OBJECT_UNLOCK (pad);
916 GST_OBJECT_LOCK (pad);
918 g_critical ("Failed to deactivate pad %s:%s, very bad",
919 GST_DEBUG_PAD_NAME (pad));
921 GST_WARNING_OBJECT (pad, "Failed to activate pad");
923 GST_OBJECT_UNLOCK (pad);
929 * gst_pad_activate_mode:
930 * @pad: the #GstPad to activate or deactivate.
931 * @mode: the requested activation mode
932 * @active: whether or not the pad should be active.
934 * Activates or deactivates the given pad in @mode via dispatching to the
935 * pad's activatemodefunc. For use from within pad activation functions only.
937 * If you don't know what this is, you probably don't want to call it.
939 * Returns: TRUE if the operation was successful.
944 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
946 gboolean res = FALSE;
952 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
954 GST_OBJECT_LOCK (pad);
955 old = GST_PAD_MODE (pad);
956 dir = GST_PAD_DIRECTION (pad);
957 ACQUIRE_PARENT (pad, parent, no_parent);
958 GST_OBJECT_UNLOCK (pad);
960 new = active ? mode : GST_PAD_MODE_NONE;
965 if (active && old != mode) {
966 /* pad was activate in the wrong direction, deactivate it
967 * and reactivate it in the requested mode */
968 GST_DEBUG_OBJECT (pad, "deactivating pad from mode %d", old);
969 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
970 goto deactivate_failed;
974 case GST_PAD_MODE_PULL:
976 if (dir == GST_PAD_SINK) {
977 if ((peer = gst_pad_get_peer (pad))) {
978 GST_DEBUG_OBJECT (pad, "calling peer");
979 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
981 gst_object_unref (peer);
983 /* there is no peer, this is only fatal when we activate. When we
984 * deactivate, we must assume the application has unlinked the peer and
985 * will deactivate it eventually. */
989 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
992 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
993 goto failure; /* Can't activate pull on a src without a
1002 pre_activate (pad, new);
1004 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1005 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1009 /* can happen for sinks of passthrough elements */
1012 post_activate (pad, new);
1014 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in mode %d",
1015 active ? "activated" : "deactivated", mode);
1020 RELEASE_PARENT (parent);
1026 GST_DEBUG_OBJECT (pad, "no parent");
1027 GST_OBJECT_UNLOCK (pad);
1032 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in mode %d",
1033 active ? "activated" : "deactivated", mode);
1038 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1039 "failed to %s in switch to mode %d from mode %d",
1040 (active ? "activate" : "deactivate"), mode, old);
1045 GST_OBJECT_LOCK (peer);
1046 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1047 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1048 GST_OBJECT_UNLOCK (peer);
1049 gst_object_unref (peer);
1054 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1055 "pad in pull mode");
1060 GST_OBJECT_LOCK (pad);
1061 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in mode %d",
1062 active ? "activate" : "deactivate", mode);
1063 GST_PAD_SET_FLUSHING (pad);
1064 GST_PAD_MODE (pad) = old;
1065 GST_OBJECT_UNLOCK (pad);
1071 * gst_pad_is_active:
1072 * @pad: the #GstPad to query
1074 * Query if a pad is active
1076 * Returns: TRUE if the pad is active.
1081 gst_pad_is_active (GstPad * pad)
1083 gboolean result = FALSE;
1085 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1087 GST_OBJECT_LOCK (pad);
1088 result = GST_PAD_IS_ACTIVE (pad);
1089 GST_OBJECT_UNLOCK (pad);
1095 * gst_pad_add_probe:
1096 * @pad: the #GstPad to add the probe to
1097 * @mask: the probe mask
1098 * @callback: #GstPadProbeCallback that will be called with notifications of
1100 * @user_data: (closure): user data passed to the callback
1101 * @destroy_data: #GDestroyNotify for user_data
1103 * Be notified of different states of pads. The provided callback is called for
1104 * every state that matches @mask.
1106 * Returns: an id or 0 on error. The id can be used to remove the probe with
1107 * gst_pad_remove_probe().
1112 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1113 GstPadProbeCallback callback, gpointer user_data,
1114 GDestroyNotify destroy_data)
1119 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1120 g_return_val_if_fail (mask != 0, 0);
1122 GST_OBJECT_LOCK (pad);
1124 /* make a new probe */
1125 hook = g_hook_alloc (&pad->probes);
1127 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1130 /* when no contraints are given for the types, assume all types are
1132 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1133 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1134 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1135 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1137 /* store our flags and other fields */
1138 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1139 hook->func = callback;
1140 hook->data = user_data;
1141 hook->destroy = destroy_data;
1142 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1145 g_hook_prepend (&pad->probes, hook);
1147 /* incremenent cookie so that the new hook get's called */
1148 pad->priv->probe_list_cookie++;
1150 /* get the id of the hook, we return this and it can be used to remove the
1152 res = hook->hook_id;
1154 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1156 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1157 /* we have a block probe */
1159 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1160 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1161 "now %d blocking probes", pad->num_blocked);
1164 /* call the callback if we need to be called for idle callbacks */
1165 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1166 if (pad->priv->using > 0) {
1167 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1168 * flag above, the last thread to leave the push will do the callback. New
1169 * threads going into the push will block. */
1170 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1171 "pad is in use, delay idle callback");
1172 GST_OBJECT_UNLOCK (pad);
1174 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, };
1176 /* the pad is idle now, we can signal the idle callback now */
1177 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1178 "pad is idle, trigger idle callback");
1179 GST_OBJECT_UNLOCK (pad);
1181 callback (pad, &info, user_data);
1184 GST_OBJECT_UNLOCK (pad);
1190 cleanup_hook (GstPad * pad, GHook * hook)
1192 GstPadProbeType type;
1194 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1196 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1197 /* unblock when we remove the last blocking probe */
1199 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1201 if (pad->num_blocked == 0) {
1202 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1203 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1204 GST_PAD_BLOCK_BROADCAST (pad);
1207 g_hook_destroy_link (&pad->probes, hook);
1212 * gst_pad_remove_probe:
1213 * @pad: the #GstPad with the probe
1214 * @id: the probe id to remove
1216 * Remove the probe with @id from @pad.
1221 gst_pad_remove_probe (GstPad * pad, gulong id)
1225 g_return_if_fail (GST_IS_PAD (pad));
1227 GST_OBJECT_LOCK (pad);
1229 hook = g_hook_get (&pad->probes, id);
1233 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1235 cleanup_hook (pad, hook);
1236 GST_OBJECT_UNLOCK (pad);
1242 GST_OBJECT_UNLOCK (pad);
1243 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1249 * gst_pad_is_blocked:
1250 * @pad: the #GstPad to query
1252 * Checks if the pad is blocked or not. This function returns the
1253 * last requested state of the pad. It is not certain that the pad
1254 * is actually blocking at this point (see gst_pad_is_blocking()).
1256 * Returns: TRUE if the pad is blocked.
1261 gst_pad_is_blocked (GstPad * pad)
1263 gboolean result = FALSE;
1265 g_return_val_if_fail (GST_IS_PAD (pad), result);
1267 GST_OBJECT_LOCK (pad);
1268 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1269 GST_OBJECT_UNLOCK (pad);
1275 * gst_pad_is_blocking:
1276 * @pad: the #GstPad to query
1278 * Checks if the pad is blocking or not. This is a guaranteed state
1279 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1281 * Returns: TRUE if the pad is blocking.
1288 gst_pad_is_blocking (GstPad * pad)
1290 gboolean result = FALSE;
1292 g_return_val_if_fail (GST_IS_PAD (pad), result);
1294 GST_OBJECT_LOCK (pad);
1295 /* the blocking flag is only valid if the pad is not flushing */
1296 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1297 GST_OBJECT_UNLOCK (pad);
1303 * gst_pad_check_reconfigure:
1304 * @pad: the #GstPad to check
1306 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1307 * if the flag was set.
1309 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1312 gst_pad_check_reconfigure (GstPad * pad)
1314 gboolean reconfigure;
1316 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1318 GST_OBJECT_LOCK (pad);
1319 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1320 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1321 GST_OBJECT_UNLOCK (pad);
1327 * gst_pad_mark_reconfigure:
1328 * @pad: the #GstPad to mark
1330 * Mark a pad for needing reconfiguration. The next call to
1331 * gst_pad_check_reconfigure() will return %TRUE after this call.
1334 gst_pad_mark_reconfigure (GstPad * pad)
1336 g_return_if_fail (GST_IS_PAD (pad));
1338 GST_OBJECT_LOCK (pad);
1339 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1340 GST_OBJECT_UNLOCK (pad);
1344 * gst_pad_set_activate_function_full:
1346 * @activate: the #GstPadActivateFunction to set.
1347 * @notify: notify called when @activate will not be used anymore.
1349 * Sets the given activate function for @pad. The activate function will
1350 * dispatch to gst_pad_activate_push() or gst_pad_activate_pull() to perform
1351 * the actual activation. Only makes sense to set on sink pads.
1353 * Call this function if your sink pad can start a pull-based task.
1356 gst_pad_set_activate_function_full (GstPad * pad,
1357 GstPadActivateFunction activate, GDestroyNotify notify)
1359 g_return_if_fail (GST_IS_PAD (pad));
1361 if (pad->activatenotify)
1362 pad->activatenotify (pad);
1363 GST_PAD_ACTIVATEFUNC (pad) = activate;
1364 pad->activatenotify = notify;
1366 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1367 GST_DEBUG_FUNCPTR_NAME (activate));
1371 * gst_pad_set_activatemode_function_full:
1373 * @activatemode: the #GstPadActivateModeFunction to set.
1374 * @notify: notify called when @activatemode will not be used anymore.
1376 * Sets the given activate_mode function for the pad. An activate_mode function
1377 * prepares the element for data passing.
1380 gst_pad_set_activatemode_function_full (GstPad * pad,
1381 GstPadActivateModeFunction activatemode, GDestroyNotify notify)
1383 g_return_if_fail (GST_IS_PAD (pad));
1385 if (pad->activatemodenotify)
1386 pad->activatemodenotify (pad);
1387 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1388 pad->activatemodenotify = notify;
1390 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1391 GST_DEBUG_FUNCPTR_NAME (activatemode));
1395 * gst_pad_set_chain_function_full:
1396 * @pad: a sink #GstPad.
1397 * @chain: the #GstPadChainFunction to set.
1398 * @notify: notify called when @chain will not be used anymore.
1400 * Sets the given chain function for the pad. The chain function is called to
1401 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1404 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1405 GDestroyNotify notify)
1407 g_return_if_fail (GST_IS_PAD (pad));
1408 g_return_if_fail (GST_PAD_IS_SINK (pad));
1410 if (pad->chainnotify)
1411 pad->chainnotify (pad);
1412 GST_PAD_CHAINFUNC (pad) = chain;
1413 pad->chainnotify = notify;
1415 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1416 GST_DEBUG_FUNCPTR_NAME (chain));
1420 * gst_pad_set_chain_list_function_full:
1421 * @pad: a sink #GstPad.
1422 * @chainlist: the #GstPadChainListFunction to set.
1423 * @notify: notify called when @chainlist will not be used anymore.
1425 * Sets the given chain list function for the pad. The chainlist function is
1426 * called to process a #GstBufferList input buffer list. See
1427 * #GstPadChainListFunction for more details.
1432 gst_pad_set_chain_list_function_full (GstPad * pad,
1433 GstPadChainListFunction chainlist, GDestroyNotify notify)
1435 g_return_if_fail (GST_IS_PAD (pad));
1436 g_return_if_fail (GST_PAD_IS_SINK (pad));
1438 if (pad->chainlistnotify)
1439 pad->chainlistnotify (pad);
1440 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1441 pad->chainlistnotify = notify;
1443 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1444 GST_DEBUG_FUNCPTR_NAME (chainlist));
1448 * gst_pad_set_getrange_function_full:
1449 * @pad: a source #GstPad.
1450 * @get: the #GstPadGetRangeFunction to set.
1451 * @notify: notify called when @get will not be used anymore.
1453 * Sets the given getrange function for the pad. The getrange function is
1454 * called to produce a new #GstBuffer to start the processing pipeline. see
1455 * #GstPadGetRangeFunction for a description of the getrange function.
1458 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1459 GDestroyNotify notify)
1461 g_return_if_fail (GST_IS_PAD (pad));
1462 g_return_if_fail (GST_PAD_IS_SRC (pad));
1464 if (pad->getrangenotify)
1465 pad->getrangenotify (pad);
1466 GST_PAD_GETRANGEFUNC (pad) = get;
1467 pad->getrangenotify = notify;
1469 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1470 GST_DEBUG_FUNCPTR_NAME (get));
1474 * gst_pad_set_event_function_full:
1475 * @pad: a #GstPad of either direction.
1476 * @event: the #GstPadEventFunction to set.
1477 * @notify: notify called when @event will not be used anymore.
1479 * Sets the given event handler for the pad.
1482 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1483 GDestroyNotify notify)
1485 g_return_if_fail (GST_IS_PAD (pad));
1487 if (pad->eventnotify)
1488 pad->eventnotify (pad);
1489 GST_PAD_EVENTFUNC (pad) = event;
1490 pad->eventnotify = notify;
1492 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1493 GST_DEBUG_FUNCPTR_NAME (event));
1497 * gst_pad_set_query_function_full:
1498 * @pad: a #GstPad of either direction.
1499 * @query: the #GstPadQueryFunction to set.
1500 * @notify: notify called when @query will not be used anymore.
1502 * Set the given query function for the pad.
1505 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1506 GDestroyNotify notify)
1508 g_return_if_fail (GST_IS_PAD (pad));
1510 if (pad->querynotify)
1511 pad->querynotify (pad);
1512 GST_PAD_QUERYFUNC (pad) = query;
1513 pad->querynotify = notify;
1515 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1516 GST_DEBUG_FUNCPTR_NAME (query));
1520 * gst_pad_set_iterate_internal_links_function_full:
1521 * @pad: a #GstPad of either direction.
1522 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1523 * @notify: notify called when @iterintlink will not be used anymore.
1525 * Sets the given internal link iterator function for the pad.
1530 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1531 GstPadIterIntLinkFunction iterintlink, GDestroyNotify notify)
1533 g_return_if_fail (GST_IS_PAD (pad));
1535 if (pad->iterintlinknotify)
1536 pad->iterintlinknotify (pad);
1537 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1538 pad->iterintlinknotify = notify;
1540 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1541 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1545 * gst_pad_set_link_function_full:
1547 * @link: the #GstPadLinkFunction to set.
1548 * @notify: notify called when @link will not be used anymore.
1550 * Sets the given link function for the pad. It will be called when
1551 * the pad is linked with another pad.
1553 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1556 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1557 * cannot be made for some reason.
1559 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1560 * of the peer sink pad, if present.
1563 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1564 GDestroyNotify notify)
1566 g_return_if_fail (GST_IS_PAD (pad));
1568 if (pad->linknotify)
1569 pad->linknotify (pad);
1570 GST_PAD_LINKFUNC (pad) = link;
1571 pad->linknotify = notify;
1573 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1574 GST_DEBUG_FUNCPTR_NAME (link));
1578 * gst_pad_set_unlink_function_full:
1580 * @unlink: the #GstPadUnlinkFunction to set.
1581 * @notify: notify called when @unlink will not be used anymore.
1583 * Sets the given unlink function for the pad. It will be called
1584 * when the pad is unlinked.
1587 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1588 GDestroyNotify notify)
1590 g_return_if_fail (GST_IS_PAD (pad));
1592 if (pad->unlinknotify)
1593 pad->unlinknotify (pad);
1594 GST_PAD_UNLINKFUNC (pad) = unlink;
1595 pad->unlinknotify = notify;
1597 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1598 GST_DEBUG_FUNCPTR_NAME (unlink));
1603 * @srcpad: the source #GstPad to unlink.
1604 * @sinkpad: the sink #GstPad to unlink.
1606 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1607 * signal on both pads.
1609 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1610 * the pads were not linked together.
1615 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1617 gboolean result = FALSE;
1618 GstElement *parent = NULL;
1620 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1621 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1622 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1623 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1625 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1626 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1627 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1629 /* We need to notify the parent before taking any pad locks as the bin in
1630 * question might be waiting for a lock on the pad while holding its lock
1631 * that our message will try to take. */
1632 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1633 if (GST_IS_ELEMENT (parent)) {
1634 gst_element_post_message (parent,
1635 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1636 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1638 gst_object_unref (parent);
1643 GST_OBJECT_LOCK (srcpad);
1644 GST_OBJECT_LOCK (sinkpad);
1646 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1647 goto not_linked_together;
1649 if (GST_PAD_UNLINKFUNC (srcpad)) {
1650 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1652 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1653 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1656 /* first clear peers */
1657 GST_PAD_PEER (srcpad) = NULL;
1658 GST_PAD_PEER (sinkpad) = NULL;
1660 GST_OBJECT_UNLOCK (sinkpad);
1661 GST_OBJECT_UNLOCK (srcpad);
1663 /* fire off a signal to each of the pads telling them
1664 * that they've been unlinked */
1665 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1666 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1668 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1669 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1674 if (parent != NULL) {
1675 gst_element_post_message (parent,
1676 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1677 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1678 gst_object_unref (parent);
1683 not_linked_together:
1685 /* we do not emit a warning in this case because unlinking cannot
1686 * be made MT safe.*/
1687 GST_OBJECT_UNLOCK (sinkpad);
1688 GST_OBJECT_UNLOCK (srcpad);
1694 * gst_pad_is_linked:
1695 * @pad: pad to check
1697 * Checks if a @pad is linked to another pad or not.
1699 * Returns: TRUE if the pad is linked, FALSE otherwise.
1704 gst_pad_is_linked (GstPad * pad)
1708 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1710 GST_OBJECT_LOCK (pad);
1711 result = (GST_PAD_PEER (pad) != NULL);
1712 GST_OBJECT_UNLOCK (pad);
1717 /* get the caps from both pads and see if the intersection
1720 * This function should be called with the pad LOCK on both
1724 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1725 GstPadLinkCheck flags)
1727 GstCaps *srccaps = NULL;
1728 GstCaps *sinkcaps = NULL;
1729 gboolean compatible = FALSE;
1731 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1734 /* Doing the expensive caps checking takes priority over only checking the template caps */
1735 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1736 GST_OBJECT_UNLOCK (sink);
1737 GST_OBJECT_UNLOCK (src);
1739 srccaps = gst_pad_query_caps (src, NULL);
1740 sinkcaps = gst_pad_query_caps (sink, NULL);
1742 GST_OBJECT_LOCK (src);
1743 GST_OBJECT_LOCK (sink);
1745 /* If one of the two pads doesn't have a template, consider the intersection
1747 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
1748 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
1752 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
1754 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
1757 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
1759 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
1762 /* if we have caps on both pads we can check the intersection. If one
1763 * of the caps is NULL, we return TRUE. */
1764 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1766 gst_caps_unref (srccaps);
1768 gst_caps_unref (sinkcaps);
1772 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
1773 gst_caps_unref (srccaps);
1774 gst_caps_unref (sinkcaps);
1777 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
1778 (compatible ? "" : "not"));
1783 /* check if the grandparents of both pads are the same.
1784 * This check is required so that we don't try to link
1785 * pads from elements in different bins without ghostpads.
1787 * The LOCK should be held on both pads
1790 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1792 GstObject *psrc, *psink;
1794 psrc = GST_OBJECT_PARENT (src);
1795 psink = GST_OBJECT_PARENT (sink);
1797 /* if one of the pads has no parent, we allow the link */
1798 if (G_UNLIKELY (psrc == NULL || psink == NULL))
1801 /* only care about parents that are elements */
1802 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
1803 goto no_element_parent;
1805 /* if the parents are the same, we have a loop */
1806 if (G_UNLIKELY (psrc == psink))
1809 /* if they both have a parent, we check the grandparents. We can not lock
1810 * the parent because we hold on the child (pad) and the locking order is
1811 * parent >> child. */
1812 psrc = GST_OBJECT_PARENT (psrc);
1813 psink = GST_OBJECT_PARENT (psink);
1815 /* if they have grandparents but they are not the same */
1816 if (G_UNLIKELY (psrc != psink))
1817 goto wrong_grandparents;
1824 GST_CAT_DEBUG (GST_CAT_CAPS,
1825 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
1826 GST_PTR_FORMAT, psrc, psink);
1831 GST_CAT_DEBUG (GST_CAT_CAPS,
1832 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
1833 GST_PTR_FORMAT, psrc, psink);
1838 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1844 GST_CAT_DEBUG (GST_CAT_CAPS,
1845 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1846 GST_PTR_FORMAT, psrc, psink);
1851 /* FIXME leftover from an attempt at refactoring... */
1852 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
1853 * the two pads will be locked in the srcpad, sinkpad order. */
1854 static GstPadLinkReturn
1855 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
1857 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1858 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1860 GST_OBJECT_LOCK (srcpad);
1862 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1863 goto src_was_linked;
1865 GST_OBJECT_LOCK (sinkpad);
1867 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1868 goto sink_was_linked;
1870 /* check hierarchy, pads can only be linked if the grandparents
1872 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
1873 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
1874 goto wrong_hierarchy;
1876 /* check pad caps for non-empty intersection */
1877 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
1880 /* FIXME check pad scheduling for non-empty intersection */
1882 return GST_PAD_LINK_OK;
1886 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
1887 GST_DEBUG_PAD_NAME (srcpad),
1888 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
1889 /* we do not emit a warning in this case because unlinking cannot
1890 * be made MT safe.*/
1891 GST_OBJECT_UNLOCK (srcpad);
1892 return GST_PAD_LINK_WAS_LINKED;
1896 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
1897 GST_DEBUG_PAD_NAME (sinkpad),
1898 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
1899 /* we do not emit a warning in this case because unlinking cannot
1900 * be made MT safe.*/
1901 GST_OBJECT_UNLOCK (sinkpad);
1902 GST_OBJECT_UNLOCK (srcpad);
1903 return GST_PAD_LINK_WAS_LINKED;
1907 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
1908 GST_OBJECT_UNLOCK (sinkpad);
1909 GST_OBJECT_UNLOCK (srcpad);
1910 return GST_PAD_LINK_WRONG_HIERARCHY;
1914 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1915 GST_OBJECT_UNLOCK (sinkpad);
1916 GST_OBJECT_UNLOCK (srcpad);
1917 return GST_PAD_LINK_NOFORMAT;
1923 * @srcpad: the source #GstPad.
1924 * @sinkpad: the sink #GstPad.
1926 * Checks if the source pad and the sink pad are compatible so they can be
1929 * Returns: TRUE if the pads can be linked.
1932 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1934 GstPadLinkReturn result;
1936 /* generic checks */
1937 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1938 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1940 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
1941 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1943 /* gst_pad_link_prepare does everything for us, we only release the locks
1944 * on the pads that it gets us. If this function returns !OK the locks are not
1946 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
1947 if (result != GST_PAD_LINK_OK)
1950 GST_OBJECT_UNLOCK (srcpad);
1951 GST_OBJECT_UNLOCK (sinkpad);
1954 return result == GST_PAD_LINK_OK;
1958 * gst_pad_link_full:
1959 * @srcpad: the source #GstPad to link.
1960 * @sinkpad: the sink #GstPad to link.
1961 * @flags: the checks to validate when linking
1963 * Links the source pad and the sink pad.
1965 * This variant of #gst_pad_link provides a more granular control on the
1966 * checks being done when linking. While providing some considerable speedups
1967 * the caller of this method must be aware that wrong usage of those flags
1968 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
1969 * for more information.
1973 * Returns: A result code indicating if the connection worked or
1979 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
1981 GstPadLinkReturn result;
1983 GstPadLinkFunction srcfunc, sinkfunc;
1985 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
1986 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
1987 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
1988 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
1989 GST_PAD_LINK_WRONG_DIRECTION);
1991 /* Notify the parent early. See gst_pad_unlink for details. */
1992 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
1993 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
1994 gst_element_post_message (parent,
1995 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1996 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
1998 gst_object_unref (parent);
2003 /* prepare will also lock the two pads */
2004 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2006 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2009 /* must set peers before calling the link function */
2010 GST_PAD_PEER (srcpad) = sinkpad;
2011 GST_PAD_PEER (sinkpad) = srcpad;
2013 /* check events, when something is different, mark pending */
2014 schedule_events (srcpad, sinkpad);
2016 /* get the link functions */
2017 srcfunc = GST_PAD_LINKFUNC (srcpad);
2018 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2020 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2021 /* custom link functions, execute them */
2022 GST_OBJECT_UNLOCK (sinkpad);
2023 GST_OBJECT_UNLOCK (srcpad);
2026 /* this one will call the peer link function */
2027 result = srcfunc (srcpad, sinkpad);
2028 } else if (sinkfunc) {
2029 /* if no source link function, we need to call the sink link
2030 * function ourselves. */
2031 result = sinkfunc (sinkpad, srcpad);
2034 GST_OBJECT_LOCK (srcpad);
2035 GST_OBJECT_LOCK (sinkpad);
2037 /* we released the lock, check if the same pads are linked still */
2038 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2039 goto concurrent_link;
2041 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2044 GST_OBJECT_UNLOCK (sinkpad);
2045 GST_OBJECT_UNLOCK (srcpad);
2047 /* fire off a signal to each of the pads telling them
2048 * that they've been linked */
2049 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2050 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2052 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2053 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2055 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2058 if (G_LIKELY (parent)) {
2059 gst_element_post_message (parent,
2060 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2061 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2062 gst_object_unref (parent);
2070 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2071 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2072 GST_OBJECT_UNLOCK (sinkpad);
2073 GST_OBJECT_UNLOCK (srcpad);
2075 /* The other link operation succeeded first */
2076 result = GST_PAD_LINK_WAS_LINKED;
2081 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2082 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2084 GST_PAD_PEER (srcpad) = NULL;
2085 GST_PAD_PEER (sinkpad) = NULL;
2087 GST_OBJECT_UNLOCK (sinkpad);
2088 GST_OBJECT_UNLOCK (srcpad);
2096 * @srcpad: the source #GstPad to link.
2097 * @sinkpad: the sink #GstPad to link.
2099 * Links the source pad and the sink pad.
2101 * Returns: A result code indicating if the connection worked or
2107 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2109 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2113 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2115 GstPadTemplate **template_p;
2117 /* this function would need checks if it weren't static */
2119 GST_OBJECT_LOCK (pad);
2120 template_p = &pad->padtemplate;
2121 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2122 GST_OBJECT_UNLOCK (pad);
2125 gst_pad_template_pad_created (templ, pad);
2129 * gst_pad_get_pad_template:
2132 * Gets the template for @pad.
2134 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2135 * instantiated, or %NULL if this pad has no template. Unref after
2139 gst_pad_get_pad_template (GstPad * pad)
2141 GstPadTemplate *templ;
2143 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2145 templ = GST_PAD_PAD_TEMPLATE (pad);
2147 return (templ ? gst_object_ref (templ) : NULL);
2151 * gst_pad_has_current_caps:
2152 * @pad: a #GstPad to check
2154 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2156 * Returns: TRUE when @pad has caps associated with it.
2159 gst_pad_has_current_caps (GstPad * pad)
2164 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2166 GST_OBJECT_LOCK (pad);
2167 caps = get_pad_caps (pad);
2168 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2169 "check current pad caps %" GST_PTR_FORMAT, caps);
2170 result = (caps != NULL);
2171 GST_OBJECT_UNLOCK (pad);
2177 * gst_pad_get_current_caps:
2178 * @pad: a #GstPad to get the current capabilities of.
2180 * Gets the capabilities currently configured on @pad with the last
2181 * #GST_EVENT_CAPS event.
2183 * Returns: the current caps of the pad with incremented ref-count.
2186 gst_pad_get_current_caps (GstPad * pad)
2190 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2192 GST_OBJECT_LOCK (pad);
2193 if ((result = get_pad_caps (pad)))
2194 gst_caps_ref (result);
2195 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2196 "get current pad caps %" GST_PTR_FORMAT, result);
2197 GST_OBJECT_UNLOCK (pad);
2204 * @pad: a #GstPad to set the capabilities of.
2205 * @caps: (transfer none): a #GstCaps to set.
2207 * Sets the capabilities of this pad. The caps must be fixed. Any previous
2208 * caps on the pad will be unreffed. This function refs the caps so you should
2209 * unref if as soon as you don't need it anymore.
2210 * It is possible to set NULL caps, which will make the pad unnegotiated
2213 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
2214 * or bad parameters were provided to this function.
2219 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
2222 gboolean res = TRUE;
2224 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2225 g_return_val_if_fail (caps != NULL && gst_caps_is_fixed (caps), FALSE);
2227 event = gst_event_new_caps (caps);
2229 if (GST_PAD_IS_SRC (pad))
2230 res = gst_pad_push_event (pad, event);
2232 res = gst_pad_send_event (pad, event);
2238 * gst_pad_get_pad_template_caps:
2239 * @pad: a #GstPad to get the template capabilities from.
2241 * Gets the capabilities for @pad's template.
2243 * Returns: (transfer full): the #GstCaps of this pad template.
2244 * Unref after usage.
2247 gst_pad_get_pad_template_caps (GstPad * pad)
2249 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2251 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2253 if (GST_PAD_PAD_TEMPLATE (pad))
2254 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2256 return gst_static_caps_get (&anycaps);
2261 * @pad: a #GstPad to get the peer of.
2263 * Gets the peer of @pad. This function refs the peer pad so
2264 * you need to unref it after use.
2266 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2271 gst_pad_get_peer (GstPad * pad)
2275 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2277 GST_OBJECT_LOCK (pad);
2278 result = GST_PAD_PEER (pad);
2280 gst_object_ref (result);
2281 GST_OBJECT_UNLOCK (pad);
2287 * gst_pad_get_allowed_caps:
2290 * Gets the capabilities of the allowed media types that can flow through
2291 * @pad and its peer.
2293 * The allowed capabilities is calculated as the intersection of the results of
2294 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2295 * on the resulting caps.
2297 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2298 * caps when you no longer need it. This function returns NULL when @pad
2304 gst_pad_get_allowed_caps (GstPad * pad)
2311 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2313 GST_OBJECT_LOCK (pad);
2314 peer = GST_PAD_PEER (pad);
2315 if (G_UNLIKELY (peer == NULL))
2318 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2320 gst_object_ref (peer);
2321 GST_OBJECT_UNLOCK (pad);
2322 mycaps = gst_pad_query_caps (pad, NULL);
2324 peercaps = gst_pad_query_caps (peer, NULL);
2325 gst_object_unref (peer);
2327 caps = gst_caps_intersect (mycaps, peercaps);
2328 gst_caps_unref (peercaps);
2329 gst_caps_unref (mycaps);
2331 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2338 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2339 GST_OBJECT_UNLOCK (pad);
2346 * gst_pad_iterate_internal_links_default:
2347 * @pad: the #GstPad to get the internal links of.
2348 * @parent: the parent of @pad or NULL
2350 * Iterate the list of pads to which the given pad is linked to inside of
2351 * the parent element.
2352 * This is the default handler, and thus returns an iterator of all of the
2353 * pads inside the parent element with opposite direction.
2355 * The caller must free this iterator after use with gst_iterator_free().
2357 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2358 * returned pad with gst_object_unref().
2363 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2370 GstElement *eparent;
2372 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2374 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2375 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2377 GST_OBJECT_LOCK (pad);
2378 eparent = GST_PAD_PARENT (pad);
2379 if (!eparent || !GST_IS_ELEMENT (eparent))
2382 gst_object_ref (eparent);
2383 GST_OBJECT_UNLOCK (pad);
2386 if (pad->direction == GST_PAD_SRC)
2387 padlist = &eparent->sinkpads;
2389 padlist = &eparent->srcpads;
2391 GST_DEBUG_OBJECT (pad, "Making iterator");
2393 cookie = &eparent->pads_cookie;
2395 lock = GST_OBJECT_GET_LOCK (eparent);
2397 res = gst_iterator_new_list (GST_TYPE_PAD,
2398 lock, cookie, padlist, (GObject *) owner, NULL);
2400 gst_object_unref (owner);
2407 GST_OBJECT_UNLOCK (pad);
2408 GST_DEBUG_OBJECT (pad, "no parent element");
2414 * gst_pad_iterate_internal_links:
2415 * @pad: the GstPad to get the internal links of.
2417 * Gets an iterator for the pads to which the given pad is linked to inside
2418 * of the parent element.
2420 * Each #GstPad element yielded by the iterator will have its refcount increased,
2421 * so unref after use.
2423 * Free-function: gst_iterator_free
2425 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2426 * pad does not have an iterator function configured. Use
2427 * gst_iterator_free() after usage.
2432 gst_pad_iterate_internal_links (GstPad * pad)
2434 GstIterator *res = NULL;
2437 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2439 GST_OBJECT_LOCK (pad);
2440 ACQUIRE_PARENT (pad, parent, no_parent);
2441 GST_OBJECT_UNLOCK (pad);
2443 if (GST_PAD_ITERINTLINKFUNC (pad))
2444 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2446 RELEASE_PARENT (parent);
2453 GST_DEBUG_OBJECT (pad, "no parent");
2454 GST_OBJECT_UNLOCK (pad);
2462 * @forward: a #GstPadForwardFunction
2463 * @user_data: user data passed to @forward
2465 * Calls @forward for all internally linked pads of @pad. This function deals with
2466 * dynamically changing internal pads and will make sure that the @forward
2467 * function is only called once for each pad.
2469 * When @forward returns TRUE, no further pads will be processed.
2471 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2474 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2477 gboolean result = FALSE;
2479 gboolean done = FALSE;
2480 GValue item = { 0, };
2481 GList *pushed_pads = NULL;
2483 iter = gst_pad_iterate_internal_links (pad);
2489 switch (gst_iterator_next (iter, &item)) {
2490 case GST_ITERATOR_OK:
2494 intpad = g_value_get_object (&item);
2496 /* if already pushed, skip. FIXME, find something faster to tag pads */
2497 if (g_list_find (pushed_pads, intpad)) {
2498 g_value_reset (&item);
2502 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2503 GST_DEBUG_PAD_NAME (intpad));
2504 done = result = forward (intpad, user_data);
2506 pushed_pads = g_list_prepend (pushed_pads, intpad);
2508 g_value_reset (&item);
2511 case GST_ITERATOR_RESYNC:
2512 /* We don't reset the result here because we don't push the event
2513 * again on pads that got the event already and because we need
2514 * to consider the result of the previous pushes */
2515 gst_iterator_resync (iter);
2517 case GST_ITERATOR_ERROR:
2518 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2521 case GST_ITERATOR_DONE:
2526 g_value_unset (&item);
2527 gst_iterator_free (iter);
2529 g_list_free (pushed_pads);
2539 gboolean dispatched;
2543 event_forward_func (GstPad * pad, EventData * data)
2545 /* for each pad we send to, we should ref the event; it's up
2546 * to downstream to unref again when handled. */
2547 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2548 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2550 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2552 data->dispatched = TRUE;
2559 * gst_pad_event_default:
2560 * @pad: a #GstPad to call the default event handler on.
2561 * @parent: the parent of @pad or NULL
2562 * @event: (transfer full): the #GstEvent to handle.
2564 * Invokes the default event handler for the given pad.
2566 * The EOS event will pause the task associated with @pad before it is forwarded
2567 * to all internally linked pads,
2569 * The the event is sent to all pads internally linked to @pad. This function
2570 * takes ownership of @event.
2572 * Returns: TRUE if the event was sent successfully.
2575 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2577 gboolean result, forward = TRUE;
2579 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2580 g_return_val_if_fail (event != NULL, FALSE);
2582 GST_LOG_OBJECT (pad, "default event handler");
2584 switch (GST_EVENT_TYPE (event)) {
2587 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
2588 gst_pad_pause_task (pad);
2591 case GST_EVENT_CAPS:
2592 forward = GST_PAD_IS_PROXY_CAPS (pad);
2603 data.dispatched = FALSE;
2604 data.result = FALSE;
2606 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2608 /* for sinkpads without a parent element or without internal links, nothing
2609 * will be dispatched but we still want to return TRUE. */
2610 if (data.dispatched)
2611 result = data.result;
2616 gst_event_unref (event);
2621 /* Default accept caps implementation just checks against
2622 * the allowed caps for the pad */
2624 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2626 /* get the caps and see if it intersects to something not empty */
2627 GstCaps *caps, *allowed;
2630 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2632 /* first forward the query to internally linked pads when we are dealing with
2634 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2635 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2640 allowed = gst_pad_query_caps (pad, NULL);
2641 gst_query_parse_accept_caps (query, &caps);
2644 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
2645 result = gst_caps_is_subset (caps, allowed);
2646 gst_caps_unref (allowed);
2648 GST_DEBUG_OBJECT (pad, "no caps allowed on the pad");
2651 gst_query_set_accept_caps_result (query, result);
2657 /* Default caps implementation */
2659 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2661 GstCaps *result = NULL, *filter;
2662 GstPadTemplate *templ;
2663 gboolean fixed_caps;
2665 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2667 gst_query_parse_caps (query, &filter);
2669 /* first try to proxy if we must */
2670 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2671 if ((gst_pad_proxy_query_caps (pad, query))) {
2672 gst_query_parse_caps_result (query, &result);
2677 /* no proxy or it failed, do default handling */
2678 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2680 GST_OBJECT_LOCK (pad);
2682 /* fixed caps, try the negotiated caps first */
2683 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2684 if ((result = get_pad_caps (pad)))
2685 goto filter_done_unlock;
2688 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2689 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2690 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2691 goto filter_done_unlock;
2695 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2696 "non-fixed pad caps: trying pad caps");
2697 /* non fixed caps, try the negotiated caps */
2698 if ((result = get_pad_caps (pad)))
2699 goto filter_done_unlock;
2701 GST_OBJECT_UNLOCK (pad);
2703 /* this almost never happens */
2704 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2705 result = gst_caps_new_empty ();
2710 GST_OBJECT_UNLOCK (pad);
2713 /* run the filter on the result */
2715 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2716 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2717 GST_PTR_FORMAT, result, result, filter, filter);
2718 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2719 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2722 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2723 "using caps %p %" GST_PTR_FORMAT, result, result);
2724 result = gst_caps_ref (result);
2728 gst_query_set_caps_result (query, result);
2729 gst_caps_unref (result);
2735 * gst_pad_query_default:
2736 * @pad: a #GstPad to call the default query handler on.
2737 * @parent: the parent of @pad or NULL
2738 * @query: (transfer none): the #GstQuery to handle.
2740 * Invokes the default query handler for the given pad.
2741 * The query is sent to all pads internally linked to @pad. Note that
2742 * if there are many possible sink pads that are internally linked to
2743 * @pad, only one will be sent the query.
2744 * Multi-sinkpad elements should implement custom query handlers.
2746 * Returns: TRUE if the query was performed successfully.
2749 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
2751 gboolean forward = TRUE, ret = FALSE;
2753 switch (GST_QUERY_TYPE (query)) {
2754 case GST_QUERY_SCHEDULING:
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:
2772 case GST_QUERY_ALLOCATION:
2778 ret = gst_pad_forward
2779 (pad, (GstPadForwardFunction) gst_pad_peer_query, query);
2785 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
2787 GstPad *pad = data->pad;
2788 GstPadProbeInfo *info = data->info;
2789 GstPadProbeType type, flags;
2790 GstPadProbeCallback callback;
2791 GstPadProbeReturn ret;
2793 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2794 "hook %lu, cookie %u checking", hook->hook_id, PROBE_COOKIE (hook));
2796 /* if we have called this callback, do nothing */
2797 if (PROBE_COOKIE (hook) == data->cookie) {
2798 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2799 "hook %lu, cookie %u already called", hook->hook_id,
2800 PROBE_COOKIE (hook));
2804 PROBE_COOKIE (hook) = data->cookie;
2806 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
2809 /* one of the data types */
2810 if ((flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
2812 /* one of the scheduling types */
2813 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
2815 /* one of the blocking types must match */
2816 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
2817 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
2820 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2821 "hook %lu with flags 0x%08x matches", hook->hook_id, flags);
2823 callback = (GstPadProbeCallback) hook->func;
2824 if (callback == NULL)
2827 GST_OBJECT_UNLOCK (pad);
2829 ret = callback (pad, info, hook->data);
2831 GST_OBJECT_LOCK (pad);
2832 data->marshalled = TRUE;
2835 case GST_PAD_PROBE_REMOVE:
2836 /* remove the probe */
2837 GST_DEBUG_OBJECT (pad, "asked to remove hook");
2838 cleanup_hook (pad, hook);
2840 case GST_PAD_PROBE_DROP:
2841 /* need to drop the data, make sure other probes don't get called
2843 GST_DEBUG_OBJECT (pad, "asked to drop item");
2844 info->type = GST_PAD_PROBE_TYPE_INVALID;
2845 data->dropped = TRUE;
2847 case GST_PAD_PROBE_PASS:
2848 /* inform the pad block to let things pass */
2849 GST_DEBUG_OBJECT (pad, "asked to pass item");
2853 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
2860 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2861 "hook %lu with flags 0x%08x does not match %08x", hook->hook_id,
2867 #define PROBE_PRE_PULL(pad,mask,data,offs,size,label,probed,defaultval) \
2869 if (G_UNLIKELY (pad->num_probes)) { \
2870 /* we start with passing NULL as the data item */ \
2871 GstPadProbeInfo info = { mask, NULL, offs, size }; \
2872 ret = do_probe_callbacks (pad, &info, defaultval); \
2873 /* store the possibly updated data item */ \
2874 data = GST_PAD_PROBE_INFO_DATA (&info); \
2875 /* if something went wrong, exit */ \
2876 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2878 /* otherwise check if the probe retured data */ \
2879 if (G_UNLIKELY (data != NULL)) \
2885 /* a probe that does not take or return any data */
2886 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
2888 if (G_UNLIKELY (pad->num_probes)) { \
2889 /* pass NULL as the data item */ \
2890 GstPadProbeInfo info = { mask, NULL, 0, 0 }; \
2891 ret = do_probe_callbacks (pad, &info, defaultval); \
2892 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2897 #define PROBE_FULL(pad,mask,data,offs,size,label,defaultval) \
2899 if (G_UNLIKELY (pad->num_probes)) { \
2900 GstPadProbeInfo info = { mask, data, offs, size }; \
2901 ret = do_probe_callbacks (pad, &info, defaultval); \
2902 data = GST_PAD_PROBE_INFO_DATA (&info); \
2903 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2908 #define PROBE_PUSH(pad,mask,data,label) \
2909 PROBE_FULL(pad, mask, data, -1, -1, label, GST_FLOW_OK);
2910 #define PROBE_PULL(pad,mask,data,offs,size,label) \
2911 PROBE_FULL(pad, mask, data, offs, size, label, GST_FLOW_OK);
2913 static GstFlowReturn
2914 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
2915 GstFlowReturn defaultval)
2924 data.marshalled = FALSE;
2925 data.dropped = FALSE;
2926 data.cookie = ++pad->priv->probe_cookie;
2929 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
2932 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2933 "do probes cookie %u", data.cookie);
2934 cookie = pad->priv->probe_list_cookie;
2936 g_hook_list_marshal (&pad->probes, TRUE,
2937 (GHookMarshaller) probe_hook_marshal, &data);
2939 /* if the list changed, call the new callbacks (they will not have their
2940 * cookie set to data.cookie */
2941 if (cookie != pad->priv->probe_list_cookie) {
2942 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2943 "probe list changed, restarting");
2947 /* the first item that dropped will stop the hooks and then we drop here */
2951 /* if no handler matched and we are blocking, let the item pass */
2952 if (!data.marshalled && is_block)
2955 /* At this point, all handlers returned either OK or PASS. If one handler
2956 * returned PASS, let the item pass */
2961 while (GST_PAD_IS_BLOCKED (pad)) {
2962 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2963 "we are blocked %d times", pad->num_blocked);
2965 /* we might have released the lock */
2966 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2969 /* now we block the streaming thread. It can be unlocked when we
2970 * deactivate the pad (which will also set the FLUSHING flag) or
2971 * when the pad is unblocked. A flushing event will also unblock
2972 * the pad after setting the FLUSHING flag. */
2973 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2974 "Waiting to be unblocked or set flushing");
2975 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
2976 GST_PAD_BLOCK_WAIT (pad);
2977 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
2978 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
2980 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2990 GST_DEBUG_OBJECT (pad, "pad is flushing");
2991 return GST_FLOW_WRONG_STATE;
2995 GST_DEBUG_OBJECT (pad, "data is dropped");
2996 return GST_FLOW_CUSTOM_SUCCESS;
3000 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3001 GST_DEBUG_OBJECT (pad, "data is passed");
3009 * gst_pad_get_offset:
3012 * Get the offset applied to the running time of @pad. @pad has to be a source
3015 * Returns: the offset.
3018 gst_pad_get_offset (GstPad * pad)
3022 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3024 GST_OBJECT_LOCK (pad);
3025 result = pad->offset;
3026 GST_OBJECT_UNLOCK (pad);
3032 * gst_pad_set_offset:
3034 * @offset: the offset
3036 * Set the offset that will be applied to the running time of @pad.
3039 gst_pad_set_offset (GstPad * pad, gint64 offset)
3043 g_return_if_fail (GST_IS_PAD (pad));
3045 GST_OBJECT_LOCK (pad);
3046 /* if nothing changed, do nothing */
3047 if (pad->offset == offset)
3050 pad->offset = offset;
3051 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3053 /* sinkpads will apply their offset the next time a segment
3054 * event is received. */
3055 if (GST_PAD_IS_SINK (pad))
3058 /* resend the last segment event on next buffer push */
3059 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3060 ev->received = FALSE;
3061 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3065 GST_OBJECT_UNLOCK (pad);
3071 * @pad: a #GstPad to invoke the default query on.
3072 * @query: (transfer none): the #GstQuery to perform.
3074 * Dispatches a query to a pad. The query should have been allocated by the
3075 * caller via one of the type-specific allocation functions. The element that
3076 * the pad belongs to is responsible for filling the query with an appropriate
3077 * response, which should then be parsed with a type-specific query parsing
3080 * Again, the caller is responsible for both the allocation and deallocation of
3081 * the query structure.
3083 * Please also note that some queries might need a running pipeline to work.
3085 * Returns: TRUE if the query could be performed.
3088 gst_pad_query (GstPad * pad, GstQuery * query)
3092 GstPadQueryFunction func;
3093 GstPadProbeType type;
3096 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3097 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3099 GST_DEBUG_OBJECT (pad, "sending query %p (%s)", query,
3100 GST_QUERY_TYPE_NAME (query));
3102 if (GST_PAD_IS_SRC (pad))
3103 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3105 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3107 GST_OBJECT_LOCK (pad);
3108 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3109 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3110 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3112 ACQUIRE_PARENT (pad, parent, no_parent);
3113 GST_OBJECT_UNLOCK (pad);
3115 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3118 res = func (pad, parent, query);
3120 RELEASE_PARENT (parent);
3122 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3123 GST_QUERY_TYPE_NAME (query), res);
3128 GST_OBJECT_LOCK (pad);
3129 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3130 GST_OBJECT_UNLOCK (pad);
3137 GST_DEBUG_OBJECT (pad, "had no parent");
3138 GST_OBJECT_UNLOCK (pad);
3143 GST_DEBUG_OBJECT (pad, "had no query function");
3144 RELEASE_PARENT (parent);
3149 GST_DEBUG_OBJECT (pad, "query failed");
3154 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3155 GST_OBJECT_UNLOCK (pad);
3161 * gst_pad_peer_query:
3162 * @pad: a #GstPad to invoke the peer query on.
3163 * @query: (transfer none): the #GstQuery to perform.
3165 * Performs gst_pad_query() on the peer of @pad.
3167 * The caller is responsible for both the allocation and deallocation of
3168 * the query structure.
3170 * Returns: TRUE if the query could be performed. This function returns %FALSE
3171 * if @pad has no peer.
3176 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3179 GstPadProbeType type;
3183 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3184 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3186 if (GST_PAD_IS_SRC (pad))
3187 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3189 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3191 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3192 GST_QUERY_TYPE_NAME (query));
3194 GST_OBJECT_LOCK (pad);
3195 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3196 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3197 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3199 peerpad = GST_PAD_PEER (pad);
3200 if (G_UNLIKELY (peerpad == NULL))
3203 gst_object_ref (peerpad);
3204 GST_OBJECT_UNLOCK (pad);
3206 res = gst_pad_query (peerpad, query);
3208 gst_object_unref (peerpad);
3213 GST_OBJECT_LOCK (pad);
3214 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3215 GST_OBJECT_UNLOCK (pad);
3222 GST_WARNING_OBJECT (pad, "pad has no peer");
3223 GST_OBJECT_UNLOCK (pad);
3228 GST_DEBUG_OBJECT (pad, "query failed");
3233 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3234 GST_OBJECT_UNLOCK (pad);
3239 /**********************************************************************
3240 * Data passing functions
3244 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3246 GstFlowReturn *data = user_data;
3250 GST_DEBUG_OBJECT (pad, "event %s was already received",
3251 GST_EVENT_TYPE_NAME (ev->event));
3254 GST_OBJECT_UNLOCK (pad);
3256 *data = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3257 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, &stored);
3259 GST_OBJECT_LOCK (pad);
3260 return *data != GST_FLOW_OK;
3263 /* this is the chain function that does not perform the additional argument
3264 * checking for that little extra speed.
3266 static inline GstFlowReturn
3267 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3272 GST_PAD_STREAM_LOCK (pad);
3274 GST_OBJECT_LOCK (pad);
3275 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3278 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3280 PROBE_PUSH (pad, type, data, probe_stopped);
3282 parent = GST_OBJECT_PARENT (pad);
3283 GST_OBJECT_UNLOCK (pad);
3285 /* NOTE: we read the chainfunc unlocked.
3286 * we cannot hold the lock for the pad so we might send
3287 * the data to the wrong function. This is not really a
3288 * problem since functions are assigned at creation time
3289 * and don't change that often... */
3290 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3291 GstPadChainFunction chainfunc;
3293 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3296 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3297 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3298 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3300 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3302 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3303 "called chainfunction &%s with buffer %p, returned %s",
3304 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3306 GstPadChainListFunction chainlistfunc;
3308 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3311 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3312 "calling chainlistfunction &%s",
3313 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3315 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3317 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3318 "called chainlistfunction &%s, returned %s",
3319 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3322 GST_PAD_STREAM_UNLOCK (pad);
3329 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3330 "chaining, but pad was flushing");
3331 GST_OBJECT_UNLOCK (pad);
3332 GST_PAD_STREAM_UNLOCK (pad);
3333 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3334 return GST_FLOW_WRONG_STATE;
3338 GST_OBJECT_UNLOCK (pad);
3339 GST_PAD_STREAM_UNLOCK (pad);
3340 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3343 case GST_FLOW_CUSTOM_SUCCESS:
3344 GST_DEBUG_OBJECT (pad, "dropped buffer");
3348 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
3355 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3356 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3357 "pushing, but not chainhandler");
3358 GST_ELEMENT_ERROR (parent, CORE, PAD, (NULL),
3359 ("push on pad %s:%s but it has no chainfunction",
3360 GST_DEBUG_PAD_NAME (pad)));
3361 GST_PAD_STREAM_UNLOCK (pad);
3362 return GST_FLOW_NOT_SUPPORTED;
3368 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3369 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3372 * Chain a buffer to @pad.
3374 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
3376 * If the buffer type is not acceptable for @pad (as negotiated with a
3377 * preceeding GST_EVENT_CAPS event), this function returns
3378 * #GST_FLOW_NOT_NEGOTIATED.
3380 * The function proceeds calling the chain function installed on @pad (see
3381 * gst_pad_set_chain_function()) and the return value of that function is
3382 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3385 * In all cases, success or failure, the caller loses its reference to @buffer
3386 * after calling this function.
3388 * Returns: a #GstFlowReturn from the pad.
3393 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3395 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3396 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3397 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3399 return gst_pad_chain_data_unchecked (pad,
3400 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3403 static GstFlowReturn
3404 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3405 GstBufferList * list)
3411 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3413 len = gst_buffer_list_length (list);
3416 for (i = 0; i < len; i++) {
3417 buffer = gst_buffer_list_get (list, i);
3419 gst_pad_chain_data_unchecked (pad,
3420 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3421 gst_buffer_ref (buffer));
3422 if (ret != GST_FLOW_OK)
3425 gst_buffer_list_unref (list);
3431 * gst_pad_chain_list:
3432 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3433 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3436 * Chain a bufferlist to @pad.
3438 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
3440 * If @pad was not negotiated properly with a CAPS event, this function
3441 * returns #GST_FLOW_NOT_NEGOTIATED.
3443 * The function proceeds calling the chainlist function installed on @pad (see
3444 * gst_pad_set_chain_list_function()) and the return value of that function is
3445 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3446 * chainlist function.
3448 * In all cases, success or failure, the caller loses its reference to @list
3449 * after calling this function.
3453 * Returns: a #GstFlowReturn from the pad.
3458 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3460 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3461 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3462 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3464 return gst_pad_chain_data_unchecked (pad,
3465 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3468 static GstFlowReturn
3469 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3474 GST_OBJECT_LOCK (pad);
3475 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3478 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3479 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3481 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3484 events_foreach (pad, push_sticky, &ret);
3485 if (ret != GST_FLOW_OK)
3489 /* do block probes */
3490 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3492 /* do post-blocking probes */
3493 PROBE_PUSH (pad, type, data, probe_stopped);
3495 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3498 /* take ref to peer pad before releasing the lock */
3499 gst_object_ref (peer);
3501 GST_OBJECT_UNLOCK (pad);
3503 ret = gst_pad_chain_data_unchecked (peer, type, data);
3505 gst_object_unref (peer);
3507 GST_OBJECT_LOCK (pad);
3509 if (pad->priv->using == 0) {
3510 /* pad is not active anymore, trigger idle callbacks */
3511 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3512 probe_stopped, ret);
3514 GST_OBJECT_UNLOCK (pad);
3518 /* ERROR recovery here */
3522 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3523 "pushing, but pad was flushing");
3524 GST_OBJECT_UNLOCK (pad);
3525 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3526 return GST_FLOW_WRONG_STATE;
3530 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3531 "error pushing events, return %s", gst_flow_get_name (ret));
3532 GST_OBJECT_UNLOCK (pad);
3533 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3538 GST_OBJECT_UNLOCK (pad);
3539 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3542 case GST_FLOW_CUSTOM_SUCCESS:
3543 GST_DEBUG_OBJECT (pad, "dropped buffer");
3547 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
3554 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3555 "pushing, but it was not linked");
3556 GST_OBJECT_UNLOCK (pad);
3557 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3558 return GST_FLOW_NOT_LINKED;
3564 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3565 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
3568 * Pushes a buffer to the peer of @pad.
3570 * This function will call installed block probes before triggering any
3571 * installed data probes.
3573 * The function proceeds calling gst_pad_chain() on the peer pad and returns
3574 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3577 * In all cases, success or failure, the caller loses its reference to @buffer
3578 * after calling this function.
3580 * Returns: a #GstFlowReturn from the peer pad.
3585 gst_pad_push (GstPad * pad, GstBuffer * buffer)
3587 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3588 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3589 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3591 return gst_pad_push_data (pad,
3592 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3596 * gst_pad_push_list:
3597 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3598 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
3601 * Pushes a buffer list to the peer of @pad.
3603 * This function will call installed block probes before triggering any
3604 * installed data probes.
3606 * The function proceeds calling the chain function on the peer pad and returns
3607 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3608 * be returned. If the peer pad does not have any installed chainlist function
3609 * every group buffer of the list will be merged into a normal #GstBuffer and
3610 * chained via gst_pad_chain().
3612 * In all cases, success or failure, the caller loses its reference to @list
3613 * after calling this function.
3615 * Returns: a #GstFlowReturn from the peer pad.
3622 gst_pad_push_list (GstPad * pad, GstBufferList * list)
3624 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3625 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3626 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3628 return gst_pad_push_data (pad,
3629 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3632 static GstFlowReturn
3633 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
3634 GstBuffer ** buffer)
3637 GstPadGetRangeFunction getrangefunc;
3640 GST_PAD_STREAM_LOCK (pad);
3642 GST_OBJECT_LOCK (pad);
3643 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3646 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3647 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3649 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3652 events_foreach (pad, push_sticky, &ret);
3653 if (ret != GST_FLOW_OK)
3657 /* when one of the probes returns a buffer, probed_data will be called and we
3658 * skip calling the getrange function */
3659 PROBE_PRE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
3660 *buffer, offset, size, probe_stopped, probed_data, GST_FLOW_OK);
3662 ACQUIRE_PARENT (pad, parent, no_parent);
3663 GST_OBJECT_UNLOCK (pad);
3665 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
3668 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3669 "calling getrangefunc %s, offset %"
3670 G_GUINT64_FORMAT ", size %u",
3671 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
3673 ret = getrangefunc (pad, parent, offset, size, buffer);
3675 RELEASE_PARENT (parent);
3677 if (G_UNLIKELY (ret != GST_FLOW_OK))
3678 goto get_range_failed;
3680 /* can only fire the signal if we have a valid buffer */
3681 GST_OBJECT_LOCK (pad);
3683 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
3684 *buffer, offset, size, probe_stopped_unref);
3685 GST_OBJECT_UNLOCK (pad);
3687 GST_PAD_STREAM_UNLOCK (pad);
3694 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3695 "getrange, but pad was flushing");
3696 GST_OBJECT_UNLOCK (pad);
3697 GST_PAD_STREAM_UNLOCK (pad);
3698 return GST_FLOW_WRONG_STATE;
3702 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
3703 GST_OBJECT_UNLOCK (pad);
3704 GST_PAD_STREAM_UNLOCK (pad);
3709 GST_DEBUG_OBJECT (pad, "no parent");
3710 GST_OBJECT_UNLOCK (pad);
3711 GST_PAD_STREAM_UNLOCK (pad);
3712 return GST_FLOW_WRONG_STATE;
3716 GST_ELEMENT_ERROR (parent, CORE, PAD, (NULL),
3717 ("getrange on pad %s:%s but it has no getrangefunction",
3718 GST_DEBUG_PAD_NAME (pad)));
3719 RELEASE_PARENT (parent);
3720 GST_PAD_STREAM_UNLOCK (pad);
3721 return GST_FLOW_NOT_SUPPORTED;
3725 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3726 "probe returned %s", gst_flow_get_name (ret));
3727 GST_OBJECT_UNLOCK (pad);
3728 GST_PAD_STREAM_UNLOCK (pad);
3731 probe_stopped_unref:
3733 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3734 "probe returned %s", gst_flow_get_name (ret));
3735 GST_OBJECT_UNLOCK (pad);
3736 GST_PAD_STREAM_UNLOCK (pad);
3737 gst_buffer_unref (*buffer);
3743 GST_PAD_STREAM_UNLOCK (pad);
3745 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
3746 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
3747 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
3753 * gst_pad_get_range:
3754 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
3755 * @offset: The start offset of the buffer
3756 * @size: The length of the buffer
3757 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
3758 * returns #GST_FLOW_ERROR if %NULL.
3760 * When @pad is flushing this function returns #GST_FLOW_WRONG_STATE
3761 * immediately and @buffer is %NULL.
3763 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
3764 * description of a getrange function. If @pad has no getrange function
3765 * installed (see gst_pad_set_getrange_function()) this function returns
3766 * #GST_FLOW_NOT_SUPPORTED.
3768 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
3770 * Returns: a #GstFlowReturn from the pad.
3775 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
3776 GstBuffer ** buffer)
3778 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3779 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3780 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3782 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
3786 * gst_pad_pull_range:
3787 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3788 * @offset: The start offset of the buffer
3789 * @size: The length of the buffer
3790 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
3791 * GST_FLOW_ERROR if %NULL.
3793 * Pulls a @buffer from the peer pad.
3795 * This function will first trigger the pad block signal if it was
3798 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
3799 * function returns the result of gst_pad_get_range() on the peer pad.
3800 * See gst_pad_get_range() for a list of return values and for the
3801 * semantics of the arguments of this function.
3803 * Returns: a #GstFlowReturn from the peer pad.
3804 * When this function returns #GST_FLOW_OK, @buffer will contain a valid
3805 * #GstBuffer that should be freed with gst_buffer_unref() after usage.
3806 * @buffer may not be used or freed when any other return value than
3807 * #GST_FLOW_OK is returned.
3812 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
3813 GstBuffer ** buffer)
3818 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3819 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3820 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3822 GST_OBJECT_LOCK (pad);
3823 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3826 /* when one of the probes returns a buffer, probed_data will be called and we
3827 * skip calling the peer getrange function */
3828 PROBE_PRE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
3829 *buffer, offset, size, pre_probe_stopped, probed_data, GST_FLOW_OK);
3831 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3834 gst_object_ref (peer);
3836 GST_OBJECT_UNLOCK (pad);
3838 ret = gst_pad_get_range_unchecked (peer, offset, size, buffer);
3840 gst_object_unref (peer);
3842 GST_OBJECT_LOCK (pad);
3844 if (pad->priv->using == 0) {
3845 /* pad is not active anymore, trigger idle callbacks */
3846 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
3847 post_probe_stopped, ret);
3850 if (G_UNLIKELY (ret != GST_FLOW_OK))
3851 goto pull_range_failed;
3854 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
3855 *buffer, offset, size, post_probe_stopped);
3857 GST_OBJECT_UNLOCK (pad);
3861 /* ERROR recovery here */
3864 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3865 "pullrange, but pad was flushing");
3866 GST_OBJECT_UNLOCK (pad);
3867 return GST_FLOW_WRONG_STATE;
3871 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
3872 gst_flow_get_name (ret));
3873 GST_OBJECT_UNLOCK (pad);
3878 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3879 "pulling range, but it was not linked");
3880 GST_OBJECT_UNLOCK (pad);
3881 return GST_FLOW_NOT_LINKED;
3886 GST_OBJECT_UNLOCK (pad);
3887 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
3888 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
3889 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
3894 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3895 "post probe returned %s", gst_flow_get_name (ret));
3896 GST_OBJECT_UNLOCK (pad);
3897 if (ret == GST_FLOW_OK)
3898 gst_buffer_unref (*buffer);
3905 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event, gboolean locked)
3910 gboolean res = FALSE;
3911 const gchar *name = NULL;
3913 type = GST_EVENT_TYPE (event);
3914 if (type & GST_EVENT_TYPE_STICKY_MULTI)
3915 name = gst_structure_get_name (gst_event_get_structure (event));
3917 events = pad->priv->events;
3920 for (i = 0; i < len; i++) {
3921 PadEvent *ev = &g_array_index (events, PadEvent, i);
3923 if (ev->event == NULL)
3926 if (type == GST_EVENT_TYPE (ev->event)) {
3927 /* matching types, check matching name if needed */
3928 if (name && !gst_event_has_name (ev->event, name))
3932 if ((res = gst_event_replace (&ev->event, event)))
3933 ev->received = FALSE;
3939 ev.event = gst_event_ref (event);
3940 ev.received = FALSE;
3941 g_array_append_val (events, ev);
3946 pad->priv->events_cookie++;
3947 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3949 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
3951 switch (GST_EVENT_TYPE (event)) {
3952 case GST_EVENT_CAPS:
3954 GST_OBJECT_UNLOCK (pad);
3956 GST_DEBUG_OBJECT (pad, "notify caps");
3957 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
3960 GST_OBJECT_LOCK (pad);
3969 static GstFlowReturn
3970 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
3971 GstPadProbeType type, gboolean * stored)
3975 GstEventType event_type;
3978 sticky = GST_EVENT_IS_STICKY (event);
3980 GST_OBJECT_LOCK (pad);
3982 /* Two checks to be made:
3983 * . (un)set the FLUSHING flag for flushing events,
3984 * . handle pad blocking */
3985 event_type = GST_EVENT_TYPE (event);
3987 switch (event_type) {
3988 case GST_EVENT_FLUSH_START:
3989 GST_PAD_SET_FLUSHING (pad);
3991 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
3992 /* flush start will have set the FLUSHING flag and will then
3993 * unlock all threads doing a GCond wait on the blocking pad. This
3994 * will typically unblock the STREAMING thread blocked on a pad. */
3995 GST_LOG_OBJECT (pad, "Pad is blocked, not forwarding flush-start, "
3996 "doing block signal.");
3997 GST_PAD_BLOCK_BROADCAST (pad);
4001 case GST_EVENT_FLUSH_STOP:
4002 GST_PAD_UNSET_FLUSHING (pad);
4004 /* Remove sticky EOS events */
4005 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4006 remove_event_by_type (pad, GST_EVENT_EOS);
4008 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4009 GST_LOG_OBJECT (pad, "Pad is blocked, not forwarding flush-stop");
4015 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4018 /* store the event on the pad, but only on srcpads. We always store the
4019 * event exactly how it was sent */
4021 /* srcpad sticky events are store immediately, the received flag is set
4022 * to FALSE and will be set to TRUE when we can successfully push the
4023 * event to the peer pad */
4024 if (gst_pad_store_sticky_event (pad, event, TRUE)) {
4025 GST_DEBUG_OBJECT (pad, "event %s updated",
4026 GST_EVENT_TYPE_NAME (event));
4031 switch (GST_EVENT_TYPE (event)) {
4032 case GST_EVENT_SEGMENT:
4033 /* pass the adjusted segment event on. We need to do this even if
4034 * there is no peer pad because of the probes. */
4035 event = apply_pad_offset (pad, event);
4037 case GST_EVENT_RECONFIGURE:
4038 if (GST_PAD_IS_SINK (pad))
4039 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4044 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4045 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4050 /* send probes after modifying the events above */
4051 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4053 /* now check the peer pad */
4054 peerpad = GST_PAD_PEER (pad);
4055 if (peerpad == NULL)
4058 gst_object_ref (peerpad);
4060 GST_OBJECT_UNLOCK (pad);
4062 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4063 event, GST_EVENT_TYPE_NAME (event), peerpad);
4065 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4067 /* Note: we gave away ownership of the event at this point but we can still
4068 * print the old pointer */
4069 GST_LOG_OBJECT (pad,
4070 "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s", event, peerpad,
4071 gst_flow_get_name (ret));
4073 gst_object_unref (peerpad);
4075 GST_OBJECT_LOCK (pad);
4077 if (ret == GST_FLOW_OK) {
4080 if ((ev = find_event (pad, event)))
4081 ev->received = TRUE;
4083 GST_DEBUG_OBJECT (pad, "event marked received");
4085 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4086 GST_DEBUG_OBJECT (pad, "mark pending events");
4090 if (pad->priv->using == 0) {
4091 /* pad is not active anymore, trigger idle callbacks */
4092 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4093 idle_probe_stopped, ret);
4095 GST_OBJECT_UNLOCK (pad);
4099 /* ERROR handling */
4102 GST_DEBUG_OBJECT (pad, "We're flushing");
4103 GST_OBJECT_UNLOCK (pad);
4104 gst_event_unref (event);
4105 return GST_FLOW_WRONG_STATE;
4109 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4110 GST_OBJECT_UNLOCK (pad);
4111 gst_event_unref (event);
4114 case GST_FLOW_CUSTOM_SUCCESS:
4115 GST_DEBUG_OBJECT (pad, "dropped event");
4119 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
4126 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4127 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4128 GST_OBJECT_UNLOCK (pad);
4129 gst_event_unref (event);
4130 return sticky ? GST_FLOW_OK : GST_FLOW_NOT_LINKED;
4134 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4135 GST_OBJECT_UNLOCK (pad);
4141 * gst_pad_push_event:
4142 * @pad: a #GstPad to push the event to.
4143 * @event: (transfer full): the #GstEvent to send to the pad.
4145 * Sends the event to the peer of the given pad. This function is
4146 * mainly used by elements to send events to their peer
4149 * This function takes owership of the provided event so you should
4150 * gst_event_ref() it if you want to reuse the event after this call.
4152 * Returns: TRUE if the event was handled.
4157 gst_pad_push_event (GstPad * pad, GstEvent * event)
4160 GstPadProbeType type;
4163 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4164 g_return_val_if_fail (event != NULL, FALSE);
4165 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4167 if (GST_PAD_IS_SRC (pad)) {
4168 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4169 goto wrong_direction;
4170 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4171 } else if (GST_PAD_IS_SINK (pad)) {
4172 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4173 goto wrong_direction;
4174 /* events pushed on sinkpad never are sticky */
4175 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4177 goto unknown_direction;
4179 if (gst_pad_push_event_unchecked (pad, event, type, &stored) != GST_FLOW_OK)
4180 res = stored ? TRUE : FALSE;
4186 /* ERROR handling */
4189 g_warning ("pad %s:%s pushing %s event in wrong direction",
4190 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4191 gst_event_unref (event);
4196 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4197 gst_event_unref (event);
4202 /* Check if we can call the event function with the given event */
4203 static GstFlowReturn
4204 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4206 GstCaps *caps, *templ;
4208 switch (GST_EVENT_TYPE (event)) {
4209 case GST_EVENT_CAPS:
4211 /* backwards compatibility mode for caps */
4212 gst_event_parse_caps (event, &caps);
4214 /* See if pad accepts the caps */
4215 templ = gst_pad_get_pad_template_caps (pad);
4216 if (!gst_caps_is_subset (caps, templ))
4219 gst_caps_unref (templ);
4230 gst_caps_unref (templ);
4231 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4232 "caps %" GST_PTR_FORMAT " not accepted", caps);
4233 return GST_FLOW_NOT_NEGOTIATED;
4237 static GstFlowReturn
4238 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4239 GstPadProbeType type)
4242 GstEventType event_type;
4243 gboolean serialized, need_unlock = FALSE, sticky;
4244 GstPadEventFunction eventfunc;
4247 GST_OBJECT_LOCK (pad);
4248 if (GST_PAD_IS_SINK (pad))
4249 serialized = GST_EVENT_IS_SERIALIZED (event);
4252 sticky = GST_EVENT_IS_STICKY (event);
4253 event_type = GST_EVENT_TYPE (event);
4254 switch (event_type) {
4255 case GST_EVENT_FLUSH_START:
4256 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4257 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4259 /* can't even accept a flush begin event when flushing */
4260 if (GST_PAD_IS_FLUSHING (pad))
4263 GST_PAD_SET_FLUSHING (pad);
4264 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4266 case GST_EVENT_FLUSH_STOP:
4267 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4268 GST_PAD_UNSET_FLUSHING (pad);
4269 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4271 /* Remove pending EOS events */
4272 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4273 remove_event_by_type (pad, GST_EVENT_EOS);
4275 GST_OBJECT_UNLOCK (pad);
4276 /* grab stream lock */
4277 GST_PAD_STREAM_LOCK (pad);
4279 GST_OBJECT_LOCK (pad);
4280 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4283 case GST_EVENT_RECONFIGURE:
4284 if (GST_PAD_IS_SRC (pad))
4285 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4287 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "have event type %s",
4288 GST_EVENT_TYPE_NAME (event));
4290 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4294 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4295 GST_OBJECT_UNLOCK (pad);
4296 GST_PAD_STREAM_LOCK (pad);
4298 GST_OBJECT_LOCK (pad);
4299 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4303 switch (GST_EVENT_TYPE (event)) {
4304 case GST_EVENT_SEGMENT:
4305 event = apply_pad_offset (pad, event);
4311 /* now do the probe */
4313 type | GST_PAD_PROBE_TYPE_PUSH |
4314 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4316 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4320 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4323 ACQUIRE_PARENT (pad, parent, no_parent);
4324 GST_OBJECT_UNLOCK (pad);
4326 ret = pre_eventfunc_check (pad, event);
4327 if (G_UNLIKELY (ret != GST_FLOW_OK))
4328 goto precheck_failed;
4331 gst_event_ref (event);
4333 if (eventfunc (pad, parent, event)) {
4336 /* something went wrong */
4337 switch (event_type) {
4338 case GST_EVENT_CAPS:
4339 ret = GST_FLOW_NOT_NEGOTIATED;
4342 ret = GST_FLOW_ERROR;
4346 RELEASE_PARENT (parent);
4348 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
4351 if (ret == GST_FLOW_OK) {
4352 /* after the event function accepted the event, we can store the sticky
4353 * event on the pad */
4354 gst_pad_store_sticky_event (pad, event, FALSE);
4356 gst_event_unref (event);
4360 GST_PAD_STREAM_UNLOCK (pad);
4364 /* ERROR handling */
4367 GST_OBJECT_UNLOCK (pad);
4369 GST_PAD_STREAM_UNLOCK (pad);
4370 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
4371 "Received event on flushing pad. Discarding");
4372 gst_event_unref (event);
4373 return GST_FLOW_WRONG_STATE;
4377 GST_OBJECT_UNLOCK (pad);
4379 GST_PAD_STREAM_UNLOCK (pad);
4380 gst_event_unref (event);
4383 case GST_FLOW_CUSTOM_SUCCESS:
4384 GST_DEBUG_OBJECT (pad, "dropped event");
4388 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
4395 g_warning ("pad %s:%s has no event handler, file a bug.",
4396 GST_DEBUG_PAD_NAME (pad));
4397 GST_OBJECT_UNLOCK (pad);
4399 GST_PAD_STREAM_UNLOCK (pad);
4400 gst_event_unref (event);
4401 return GST_FLOW_NOT_SUPPORTED;
4405 GST_DEBUG_OBJECT (pad, "no parent");
4406 GST_OBJECT_UNLOCK (pad);
4408 GST_PAD_STREAM_UNLOCK (pad);
4409 gst_event_unref (event);
4410 return GST_FLOW_WRONG_STATE;
4414 GST_DEBUG_OBJECT (pad, "pre event check failed");
4415 RELEASE_PARENT (parent);
4417 GST_PAD_STREAM_UNLOCK (pad);
4418 gst_event_unref (event);
4424 * gst_pad_send_event:
4425 * @pad: a #GstPad to send the event to.
4426 * @event: (transfer full): the #GstEvent to send to the pad.
4428 * Sends the event to the pad. This function can be used
4429 * by applications to send events in the pipeline.
4431 * If @pad is a source pad, @event should be an upstream event. If @pad is a
4432 * sink pad, @event should be a downstream event. For example, you would not
4433 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
4434 * Furthermore, some downstream events have to be serialized with data flow,
4435 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
4436 * the event needs to be serialized with data flow, this function will take the
4437 * pad's stream lock while calling its event function.
4439 * To find out whether an event type is upstream, downstream, or downstream and
4440 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
4441 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
4442 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
4443 * plugin doesn't need to bother itself with this information; the core handles
4444 * all necessary locks and checks.
4446 * This function takes owership of the provided event so you should
4447 * gst_event_ref() it if you want to reuse the event after this call.
4449 * Returns: TRUE if the event was handled.
4452 gst_pad_send_event (GstPad * pad, GstEvent * event)
4455 GstPadProbeType type;
4457 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4458 g_return_val_if_fail (event != NULL, FALSE);
4460 if (GST_PAD_IS_SINK (pad)) {
4461 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4462 goto wrong_direction;
4463 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4464 } else if (GST_PAD_IS_SRC (pad)) {
4465 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4466 goto wrong_direction;
4467 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4469 goto unknown_direction;
4471 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
4478 /* ERROR handling */
4481 g_warning ("pad %s:%s sending %s event in wrong direction",
4482 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4483 gst_event_unref (event);
4488 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4489 gst_event_unref (event);
4495 * gst_pad_set_element_private:
4496 * @pad: the #GstPad to set the private data of.
4497 * @priv: The private data to attach to the pad.
4499 * Set the given private data gpointer on the pad.
4500 * This function can only be used by the element that owns the pad.
4501 * No locking is performed in this function.
4504 gst_pad_set_element_private (GstPad * pad, gpointer priv)
4506 pad->element_private = priv;
4510 * gst_pad_get_element_private:
4511 * @pad: the #GstPad to get the private data of.
4513 * Gets the private data of a pad.
4514 * No locking is performed in this function.
4516 * Returns: (transfer none): a #gpointer to the private data.
4519 gst_pad_get_element_private (GstPad * pad)
4521 return pad->element_private;
4525 * gst_pad_get_sticky_event:
4526 * @pad: the #GstPad to get the event from.
4527 * @event_type: the #GstEventType that should be retrieved.
4528 * @idx: the index of the event
4530 * Returns a new reference of the sticky event of type @event_type
4533 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
4534 * event of @event_type was on @pad. Unref after usage.
4537 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
4539 GstEvent *event = NULL;
4542 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4543 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
4545 GST_OBJECT_LOCK (pad);
4546 ev = find_event_by_type (pad, event_type, idx);
4547 if (ev && (event = ev->event))
4548 gst_event_ref (event);
4549 GST_OBJECT_UNLOCK (pad);
4556 GstPadStickyEventsForeachFunction func;
4561 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
4563 ForeachDispatch *data = user_data;
4566 GST_OBJECT_UNLOCK (pad);
4568 ret = data->func (pad, &ev->event, data->user_data);
4570 GST_OBJECT_LOCK (pad);
4576 * gst_pad_sticky_events_foreach:
4577 * @pad: the #GstPad that should be used for iteration.
4578 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
4579 * should be called for every event.
4580 * @user_data: (closure): the optional user data.
4582 * Iterates all sticky events on @pad and calls @foreach_func for every
4583 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
4586 gst_pad_sticky_events_foreach (GstPad * pad,
4587 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
4589 ForeachDispatch data;
4591 g_return_if_fail (GST_IS_PAD (pad));
4592 g_return_if_fail (foreach_func != NULL);
4594 data.func = foreach_func;
4595 data.user_data = user_data;
4597 GST_OBJECT_LOCK (pad);
4598 events_foreach (pad, foreach_dispatch_function, &data);
4599 GST_OBJECT_UNLOCK (pad);
4603 do_stream_status (GstPad * pad, GstStreamStatusType type,
4604 GThread * thread, GstTask * task)
4608 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
4610 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
4611 if (GST_IS_ELEMENT (parent)) {
4612 GstMessage *message;
4613 GValue value = { 0 };
4615 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
4616 gchar *tname, *ename, *pname;
4618 /* create a good task name */
4619 ename = gst_element_get_name (parent);
4620 pname = gst_pad_get_name (pad);
4621 tname = g_strdup_printf ("%s:%s", ename, pname);
4625 gst_object_set_name (GST_OBJECT_CAST (task), tname);
4629 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
4632 g_value_init (&value, GST_TYPE_TASK);
4633 g_value_set_object (&value, task);
4634 gst_message_set_stream_status_object (message, &value);
4635 g_value_unset (&value);
4637 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
4638 gst_element_post_message (parent, message);
4640 gst_object_unref (parent);
4645 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
4647 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
4652 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
4654 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
4658 static GstTaskThreadCallbacks thr_callbacks = {
4664 * gst_pad_start_task:
4665 * @pad: the #GstPad to start the task of
4666 * @func: the task function to call
4667 * @data: data passed to the task function
4669 * Starts a task that repeatedly calls @func with @data. This function
4670 * is mostly used in pad activation functions to start the dataflow.
4671 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
4672 * before @func is called.
4674 * Returns: a %TRUE if the task could be started.
4677 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
4682 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4683 g_return_val_if_fail (func != NULL, FALSE);
4685 GST_DEBUG_OBJECT (pad, "start task");
4687 GST_OBJECT_LOCK (pad);
4688 task = GST_PAD_TASK (pad);
4690 task = gst_task_new (func, data);
4691 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
4692 gst_task_set_thread_callbacks (task, &thr_callbacks, pad, NULL);
4693 GST_DEBUG_OBJECT (pad, "created task");
4694 GST_PAD_TASK (pad) = task;
4695 gst_object_ref (task);
4696 /* release lock to post the message */
4697 GST_OBJECT_UNLOCK (pad);
4699 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
4701 gst_object_unref (task);
4703 GST_OBJECT_LOCK (pad);
4704 /* nobody else is supposed to have changed the pad now */
4705 if (GST_PAD_TASK (pad) != task)
4706 goto concurrent_stop;
4708 res = gst_task_set_state (task, GST_TASK_STARTED);
4709 GST_OBJECT_UNLOCK (pad);
4716 GST_OBJECT_UNLOCK (pad);
4722 * gst_pad_pause_task:
4723 * @pad: the #GstPad to pause the task of
4725 * Pause the task of @pad. This function will also wait until the
4726 * function executed by the task is finished if this function is not
4727 * called from the task function.
4729 * Returns: a TRUE if the task could be paused or FALSE when the pad
4733 gst_pad_pause_task (GstPad * pad)
4738 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4740 GST_DEBUG_OBJECT (pad, "pause task");
4742 GST_OBJECT_LOCK (pad);
4743 task = GST_PAD_TASK (pad);
4746 res = gst_task_set_state (task, GST_TASK_PAUSED);
4747 GST_OBJECT_UNLOCK (pad);
4749 /* wait for task function to finish, this lock is recursive so it does nothing
4750 * when the pause is called from the task itself */
4751 GST_PAD_STREAM_LOCK (pad);
4752 GST_PAD_STREAM_UNLOCK (pad);
4758 GST_DEBUG_OBJECT (pad, "pad has no task");
4759 GST_OBJECT_UNLOCK (pad);
4765 * gst_pad_stop_task:
4766 * @pad: the #GstPad to stop the task of
4768 * Stop the task of @pad. This function will also make sure that the
4769 * function executed by the task will effectively stop if not called
4770 * from the GstTaskFunction.
4772 * This function will deadlock if called from the GstTaskFunction of
4773 * the task. Use gst_task_pause() instead.
4775 * Regardless of whether the pad has a task, the stream lock is acquired and
4776 * released so as to ensure that streaming through this pad has finished.
4778 * Returns: a TRUE if the task could be stopped or FALSE on error.
4781 gst_pad_stop_task (GstPad * pad)
4786 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4788 GST_DEBUG_OBJECT (pad, "stop task");
4790 GST_OBJECT_LOCK (pad);
4791 task = GST_PAD_TASK (pad);
4794 GST_PAD_TASK (pad) = NULL;
4795 res = gst_task_set_state (task, GST_TASK_STOPPED);
4796 GST_OBJECT_UNLOCK (pad);
4798 GST_PAD_STREAM_LOCK (pad);
4799 GST_PAD_STREAM_UNLOCK (pad);
4801 if (!gst_task_join (task))
4804 gst_object_unref (task);
4810 GST_DEBUG_OBJECT (pad, "no task");
4811 GST_OBJECT_UNLOCK (pad);
4813 GST_PAD_STREAM_LOCK (pad);
4814 GST_PAD_STREAM_UNLOCK (pad);
4816 /* this is not an error */
4821 /* this is bad, possibly the application tried to join the task from
4822 * the task's thread. We install the task again so that it will be stopped
4823 * again from the right thread next time hopefully. */
4824 GST_OBJECT_LOCK (pad);
4825 GST_DEBUG_OBJECT (pad, "join failed");
4826 /* we can only install this task if there was no other task */
4827 if (GST_PAD_TASK (pad) == NULL)
4828 GST_PAD_TASK (pad) = task;
4829 GST_OBJECT_UNLOCK (pad);