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"
72 #include "glib-compat-private.h"
74 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
75 #define GST_CAT_DEFAULT GST_CAT_PADS
77 /* Pad signals and args */
95 #define GST_PAD_GET_PRIVATE(obj) \
96 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
98 /* we have a pending and an active event on the pad. On source pads only the
99 * active event is used. On sinkpads, events are copied to the pending entry and
100 * moved to the active event when the eventfunc returned TRUE. */
107 struct _GstPadPrivate
113 guint probe_list_cookie;
123 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
128 GstPadProbeInfo *info;
135 static void gst_pad_dispose (GObject * object);
136 static void gst_pad_finalize (GObject * object);
137 static void gst_pad_set_property (GObject * object, guint prop_id,
138 const GValue * value, GParamSpec * pspec);
139 static void gst_pad_get_property (GObject * object, guint prop_id,
140 GValue * value, GParamSpec * pspec);
142 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
143 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
144 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
145 GstObject * parent, GstBufferList * list);
147 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
148 GstEvent * event, GstPadProbeType type);
149 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
150 GstEvent * event, GstPadProbeType type, gboolean * stored);
152 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
154 static GParamSpec *pspec_caps = NULL;
156 /* quarks for probe signals */
157 static GQuark buffer_quark;
158 static GQuark buffer_list_quark;
159 static GQuark event_quark;
168 static GstFlowQuarks flow_quarks[] = {
169 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
170 {GST_FLOW_OK, "ok", 0},
171 {GST_FLOW_NOT_LINKED, "not-linked", 0},
172 {GST_FLOW_FLUSHING, "flushing", 0},
173 {GST_FLOW_EOS, "eos", 0},
174 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
175 {GST_FLOW_ERROR, "error", 0},
176 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
177 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
182 * @ret: a #GstFlowReturn to get the name of.
184 * Gets a string representing the given flow return.
186 * Returns: a static string with the name of the flow return.
189 gst_flow_get_name (GstFlowReturn ret)
193 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
195 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
196 if (ret == flow_quarks[i].ret)
197 return flow_quarks[i].name;
204 * @ret: a #GstFlowReturn to get the quark of.
206 * Get the unique quark for the given GstFlowReturn.
208 * Returns: the quark associated with the flow return or 0 if an
209 * invalid return was specified.
212 gst_flow_to_quark (GstFlowReturn ret)
216 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
218 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
219 if (ret == flow_quarks[i].ret)
220 return flow_quarks[i].quark;
229 buffer_quark = g_quark_from_static_string ("buffer"); \
230 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
231 event_quark = g_quark_from_static_string ("event"); \
233 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
234 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
237 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
238 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
241 #define gst_pad_parent_class parent_class
242 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
245 gst_pad_class_init (GstPadClass * klass)
247 GObjectClass *gobject_class;
248 GstObjectClass *gstobject_class;
250 gobject_class = G_OBJECT_CLASS (klass);
251 gstobject_class = GST_OBJECT_CLASS (klass);
253 g_type_class_add_private (klass, sizeof (GstPadPrivate));
255 gobject_class->dispose = gst_pad_dispose;
256 gobject_class->finalize = gst_pad_finalize;
257 gobject_class->set_property = gst_pad_set_property;
258 gobject_class->get_property = gst_pad_get_property;
262 * @pad: the pad that emitted the signal
263 * @peer: the peer pad that has been connected
265 * Signals that a pad has been linked to the peer pad.
267 gst_pad_signals[PAD_LINKED] =
268 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
269 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
270 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
273 * @pad: the pad that emitted the signal
274 * @peer: the peer pad that has been disconnected
276 * Signals that a pad has been unlinked from the peer pad.
278 gst_pad_signals[PAD_UNLINKED] =
279 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
280 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
281 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
283 pspec_caps = g_param_spec_boxed ("caps", "Caps",
284 "The capabilities of the pad", GST_TYPE_CAPS,
285 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
286 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
288 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
289 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
290 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
291 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
293 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
294 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
295 g_param_spec_object ("template", "Template",
296 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
297 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
299 gstobject_class->path_string_separator = ".";
301 /* Register common function pointer descriptions */
302 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
303 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
304 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
305 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
306 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
310 gst_pad_init (GstPad * pad)
312 pad->priv = GST_PAD_GET_PRIVATE (pad);
314 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
316 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
317 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
318 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
319 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
320 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
322 GST_PAD_SET_FLUSHING (pad);
324 g_rec_mutex_init (&pad->stream_rec_lock);
326 g_cond_init (&pad->block_cond);
328 g_hook_list_init (&pad->probes, sizeof (GstProbe));
330 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
333 /* called when setting the pad inactive. It removes all sticky events from
336 remove_events (GstPad * pad)
341 events = pad->priv->events;
344 for (i = 0; i < len; i++) {
345 PadEvent *ev = &g_array_index (events, PadEvent, i);
346 gst_event_unref (ev->event);
348 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
349 g_array_set_size (events, 0);
350 pad->priv->events_cookie++;
354 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
360 events = pad->priv->events;
363 for (i = 0; i < len; i++) {
364 ev = &g_array_index (events, PadEvent, i);
365 if (ev->event == NULL)
368 if (GST_EVENT_TYPE (ev->event) == type) {
380 find_event (GstPad * pad, GstEvent * event)
386 events = pad->priv->events;
389 for (i = 0; i < len; i++) {
390 ev = &g_array_index (events, PadEvent, i);
391 if (event == ev->event)
400 remove_event_by_type (GstPad * pad, GstEventType type)
406 events = pad->priv->events;
411 ev = &g_array_index (events, PadEvent, i);
412 if (ev->event == NULL)
415 if (GST_EVENT_TYPE (ev->event) != type)
418 gst_event_unref (ev->event);
419 g_array_remove_index (events, i);
421 pad->priv->events_cookie++;
430 schedule_events (GstPad * srcpad, GstPad * sinkpad)
435 gboolean pending = FALSE;
437 events = srcpad->priv->events;
440 for (i = 0; i < len; i++) {
441 ev = &g_array_index (events, PadEvent, i);
442 if (ev->event == NULL)
445 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
446 ev->received = FALSE;
451 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
454 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
457 /* should be called with pad LOCK */
459 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
466 events = pad->priv->events;
469 cookie = pad->priv->events_cookie;
473 PadEvent *ev, ev_ret;
475 ev = &g_array_index (events, PadEvent, i);
476 if (G_UNLIKELY (ev->event == NULL))
479 /* take aditional ref, func might release the lock */
480 ev_ret.event = gst_event_ref (ev->event);
481 ev_ret.received = ev->received;
483 ret = func (pad, &ev_ret, user_data);
485 /* recheck the cookie, lock might have been released and the list could have
487 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
488 if (G_LIKELY (ev_ret.event))
489 gst_event_unref (ev_ret.event);
493 /* if the event changed, we need to do something */
494 if (G_UNLIKELY (ev->event != ev_ret.event)) {
495 if (G_UNLIKELY (ev_ret.event == NULL)) {
496 /* function unreffed and set the event to NULL, remove it */
497 g_array_remove_index (events, i);
499 cookie = ++pad->priv->events_cookie;
502 /* function gave a new event for us */
503 gst_event_take (&ev->event, ev_ret.event);
506 /* just unref, nothing changed */
507 gst_event_unref (ev_ret.event);
516 /* should be called with LOCK */
518 apply_pad_offset (GstPad * pad, GstEvent * event)
520 /* check if we need to adjust the segment */
521 if (pad->offset != 0) {
524 /* copy segment values */
525 gst_event_copy_segment (event, &segment);
526 gst_event_unref (event);
528 /* adjust and make a new event with the offset applied */
529 segment.base += pad->offset;
530 event = gst_event_new_segment (&segment);
535 /* should be called with the OBJECT_LOCK */
537 get_pad_caps (GstPad * pad)
539 GstCaps *caps = NULL;
542 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
544 gst_event_parse_caps (ev->event, &caps);
550 gst_pad_dispose (GObject * object)
552 GstPad *pad = GST_PAD_CAST (object);
555 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
557 /* unlink the peer pad */
558 if ((peer = gst_pad_get_peer (pad))) {
559 /* window for MT unsafeness, someone else could unlink here
560 * and then we call unlink with wrong pads. The unlink
561 * function would catch this and safely return failed. */
562 if (GST_PAD_IS_SRC (pad))
563 gst_pad_unlink (pad, peer);
565 gst_pad_unlink (peer, pad);
567 gst_object_unref (peer);
570 gst_pad_set_pad_template (pad, NULL);
574 g_hook_list_clear (&pad->probes);
576 G_OBJECT_CLASS (parent_class)->dispose (object);
580 gst_pad_finalize (GObject * object)
582 GstPad *pad = GST_PAD_CAST (object);
585 /* in case the task is still around, clean it up */
586 if ((task = GST_PAD_TASK (pad))) {
587 gst_task_join (task);
588 GST_PAD_TASK (pad) = NULL;
589 gst_object_unref (task);
592 if (pad->activatenotify)
593 pad->activatenotify (pad->activatedata);
594 if (pad->activatemodenotify)
595 pad->activatemodenotify (pad->activatemodedata);
597 pad->linknotify (pad->linkdata);
598 if (pad->unlinknotify)
599 pad->unlinknotify (pad->unlinkdata);
600 if (pad->chainnotify)
601 pad->chainnotify (pad->chaindata);
602 if (pad->chainlistnotify)
603 pad->chainlistnotify (pad->chainlistdata);
604 if (pad->getrangenotify)
605 pad->getrangenotify (pad->getrangedata);
606 if (pad->eventnotify)
607 pad->eventnotify (pad->eventdata);
608 if (pad->querynotify)
609 pad->querynotify (pad->querydata);
610 if (pad->iterintlinknotify)
611 pad->iterintlinknotify (pad->iterintlinkdata);
613 g_rec_mutex_clear (&pad->stream_rec_lock);
614 g_cond_clear (&pad->block_cond);
615 g_array_free (pad->priv->events, TRUE);
617 G_OBJECT_CLASS (parent_class)->finalize (object);
621 gst_pad_set_property (GObject * object, guint prop_id,
622 const GValue * value, GParamSpec * pspec)
624 g_return_if_fail (GST_IS_PAD (object));
627 case PAD_PROP_DIRECTION:
628 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
630 case PAD_PROP_TEMPLATE:
631 gst_pad_set_pad_template (GST_PAD_CAST (object),
632 (GstPadTemplate *) g_value_get_object (value));
635 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
641 gst_pad_get_property (GObject * object, guint prop_id,
642 GValue * value, GParamSpec * pspec)
644 g_return_if_fail (GST_IS_PAD (object));
648 GST_OBJECT_LOCK (object);
649 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
650 GST_OBJECT_UNLOCK (object);
652 case PAD_PROP_DIRECTION:
653 g_value_set_enum (value, GST_PAD_DIRECTION (object));
655 case PAD_PROP_TEMPLATE:
656 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
659 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
666 * @name: the name of the new pad.
667 * @direction: the #GstPadDirection of the pad.
669 * Creates a new pad with the given name in the given direction.
670 * If name is NULL, a guaranteed unique name (across all pads)
672 * This function makes a copy of the name so you can safely free the name.
674 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
679 gst_pad_new (const gchar * name, GstPadDirection direction)
681 return g_object_new (GST_TYPE_PAD,
682 "name", name, "direction", direction, NULL);
686 * gst_pad_new_from_template:
687 * @templ: the pad template to use
688 * @name: the name of the element
690 * Creates a new pad with the given name from the given template.
691 * If name is NULL, a guaranteed unique name (across all pads)
693 * This function makes a copy of the name so you can safely free the name.
695 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
698 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
700 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
702 return g_object_new (GST_TYPE_PAD,
703 "name", name, "direction", templ->direction, "template", templ, NULL);
707 * gst_pad_new_from_static_template:
708 * @templ: the #GstStaticPadTemplate to use
709 * @name: the name of the element
711 * Creates a new pad with the given name from the given static template.
712 * If name is NULL, a guaranteed unique name (across all pads)
714 * This function makes a copy of the name so you can safely free the name.
716 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
719 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
723 GstPadTemplate *template;
725 template = gst_static_pad_template_get (templ);
726 pad = gst_pad_new_from_template (template, name);
727 gst_object_unref (template);
731 #define ACQUIRE_PARENT(pad, parent, label) \
733 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
734 gst_object_ref (parent); \
735 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
739 #define RELEASE_PARENT(parent) \
741 if (G_LIKELY (parent)) \
742 gst_object_unref (parent); \
746 * gst_pad_get_direction:
747 * @pad: a #GstPad to get the direction of.
749 * Gets the direction of the pad. The direction of the pad is
750 * decided at construction time so this function does not take
753 * Returns: the #GstPadDirection of the pad.
758 gst_pad_get_direction (GstPad * pad)
760 GstPadDirection result;
762 /* PAD_UNKNOWN is a little silly but we need some sort of
763 * error return value */
764 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
766 result = GST_PAD_DIRECTION (pad);
772 gst_pad_activate_default (GstPad * pad, GstObject * parent)
774 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
778 pre_activate (GstPad * pad, GstPadMode new_mode)
781 case GST_PAD_MODE_NONE:
782 GST_OBJECT_LOCK (pad);
783 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
784 GST_PAD_SET_FLUSHING (pad);
785 GST_PAD_MODE (pad) = new_mode;
786 /* unlock blocked pads so element can resume and stop */
787 GST_PAD_BLOCK_BROADCAST (pad);
788 GST_OBJECT_UNLOCK (pad);
790 case GST_PAD_MODE_PUSH:
791 case GST_PAD_MODE_PULL:
792 GST_OBJECT_LOCK (pad);
793 GST_DEBUG_OBJECT (pad, "setting PAD_MODE %d, unset flushing", new_mode);
794 GST_PAD_UNSET_FLUSHING (pad);
795 GST_PAD_MODE (pad) = new_mode;
796 if (GST_PAD_IS_SINK (pad)) {
798 /* make sure the peer src pad sends us all events */
799 if ((peer = GST_PAD_PEER (pad))) {
800 gst_object_ref (peer);
801 GST_OBJECT_UNLOCK (pad);
803 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
804 GST_DEBUG_PAD_NAME (peer));
806 GST_OBJECT_LOCK (peer);
807 schedule_events (peer, NULL);
808 GST_OBJECT_UNLOCK (peer);
810 gst_object_unref (peer);
812 GST_OBJECT_UNLOCK (pad);
815 GST_OBJECT_UNLOCK (pad);
822 post_activate (GstPad * pad, GstPadMode new_mode)
825 case GST_PAD_MODE_NONE:
826 /* ensures that streaming stops */
827 GST_PAD_STREAM_LOCK (pad);
828 GST_DEBUG_OBJECT (pad, "stopped streaming");
829 GST_OBJECT_LOCK (pad);
831 GST_OBJECT_UNLOCK (pad);
832 GST_PAD_STREAM_UNLOCK (pad);
834 case GST_PAD_MODE_PUSH:
835 case GST_PAD_MODE_PULL:
842 * gst_pad_set_active:
843 * @pad: the #GstPad to activate or deactivate.
844 * @active: whether or not the pad should be active.
846 * Activates or deactivates the given pad.
847 * Normally called from within core state change functions.
849 * If @active, makes sure the pad is active. If it is already active, either in
850 * push or pull mode, just return. Otherwise dispatches to the pad's activate
851 * function to perform the actual activation.
853 * If not @active, checks the pad's current mode and calls
854 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
857 * Returns: #TRUE if the operation was successful.
862 gst_pad_set_active (GstPad * pad, gboolean active)
866 gboolean ret = FALSE;
868 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
870 GST_OBJECT_LOCK (pad);
871 old = GST_PAD_MODE (pad);
872 ACQUIRE_PARENT (pad, parent, no_parent);
873 GST_OBJECT_UNLOCK (pad);
876 if (old == GST_PAD_MODE_NONE) {
877 GST_DEBUG_OBJECT (pad, "activating pad from none");
878 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
880 GST_DEBUG_OBJECT (pad, "pad was active in mode %d", old);
884 if (old == GST_PAD_MODE_NONE) {
885 GST_DEBUG_OBJECT (pad, "pad was inactive");
888 GST_DEBUG_OBJECT (pad, "deactivating pad from mode %d", old);
889 ret = gst_pad_activate_mode (pad, old, FALSE);
893 RELEASE_PARENT (parent);
895 if (G_UNLIKELY (!ret))
899 GST_OBJECT_LOCK (pad);
900 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
901 GST_OBJECT_UNLOCK (pad);
908 GST_DEBUG_OBJECT (pad, "no parent");
909 GST_OBJECT_UNLOCK (pad);
914 GST_OBJECT_LOCK (pad);
916 g_critical ("Failed to deactivate pad %s:%s, very bad",
917 GST_DEBUG_PAD_NAME (pad));
919 GST_WARNING_OBJECT (pad, "Failed to activate pad");
921 GST_OBJECT_UNLOCK (pad);
927 * gst_pad_activate_mode:
928 * @pad: the #GstPad to activate or deactivate.
929 * @mode: the requested activation mode
930 * @active: whether or not the pad should be active.
932 * Activates or deactivates the given pad in @mode via dispatching to the
933 * pad's activatemodefunc. For use from within pad activation functions only.
935 * If you don't know what this is, you probably don't want to call it.
937 * Returns: TRUE if the operation was successful.
942 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
944 gboolean res = FALSE;
950 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
952 GST_OBJECT_LOCK (pad);
953 old = GST_PAD_MODE (pad);
954 dir = GST_PAD_DIRECTION (pad);
955 ACQUIRE_PARENT (pad, parent, no_parent);
956 GST_OBJECT_UNLOCK (pad);
958 new = active ? mode : GST_PAD_MODE_NONE;
963 if (active && old != mode) {
964 /* pad was activate in the wrong direction, deactivate it
965 * and reactivate it in the requested mode */
966 GST_DEBUG_OBJECT (pad, "deactivating pad from mode %d", old);
967 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
968 goto deactivate_failed;
972 case GST_PAD_MODE_PULL:
974 if (dir == GST_PAD_SINK) {
975 if ((peer = gst_pad_get_peer (pad))) {
976 GST_DEBUG_OBJECT (pad, "calling peer");
977 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
979 gst_object_unref (peer);
981 /* there is no peer, this is only fatal when we activate. When we
982 * deactivate, we must assume the application has unlinked the peer and
983 * will deactivate it eventually. */
987 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
990 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
991 goto failure; /* Can't activate pull on a src without a
1000 pre_activate (pad, new);
1002 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1003 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1007 /* can happen for sinks of passthrough elements */
1010 post_activate (pad, new);
1012 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in mode %d",
1013 active ? "activated" : "deactivated", mode);
1018 RELEASE_PARENT (parent);
1024 GST_DEBUG_OBJECT (pad, "no parent");
1025 GST_OBJECT_UNLOCK (pad);
1030 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in mode %d",
1031 active ? "activated" : "deactivated", mode);
1036 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1037 "failed to %s in switch to mode %d from mode %d",
1038 (active ? "activate" : "deactivate"), mode, old);
1043 GST_OBJECT_LOCK (peer);
1044 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1045 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1046 GST_OBJECT_UNLOCK (peer);
1047 gst_object_unref (peer);
1052 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1053 "pad in pull mode");
1058 GST_OBJECT_LOCK (pad);
1059 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in mode %d",
1060 active ? "activate" : "deactivate", mode);
1061 GST_PAD_SET_FLUSHING (pad);
1062 GST_PAD_MODE (pad) = old;
1063 GST_OBJECT_UNLOCK (pad);
1069 * gst_pad_is_active:
1070 * @pad: the #GstPad to query
1072 * Query if a pad is active
1074 * Returns: TRUE if the pad is active.
1079 gst_pad_is_active (GstPad * pad)
1081 gboolean result = FALSE;
1083 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1085 GST_OBJECT_LOCK (pad);
1086 result = GST_PAD_IS_ACTIVE (pad);
1087 GST_OBJECT_UNLOCK (pad);
1093 * gst_pad_add_probe:
1094 * @pad: the #GstPad to add the probe to
1095 * @mask: the probe mask
1096 * @callback: #GstPadProbeCallback that will be called with notifications of
1098 * @user_data: (closure): user data passed to the callback
1099 * @destroy_data: #GDestroyNotify for user_data
1101 * Be notified of different states of pads. The provided callback is called for
1102 * every state that matches @mask.
1104 * Returns: an id or 0 on error. The id can be used to remove the probe with
1105 * gst_pad_remove_probe().
1110 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1111 GstPadProbeCallback callback, gpointer user_data,
1112 GDestroyNotify destroy_data)
1117 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1118 g_return_val_if_fail (mask != 0, 0);
1120 GST_OBJECT_LOCK (pad);
1122 /* make a new probe */
1123 hook = g_hook_alloc (&pad->probes);
1125 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1128 /* when no contraints are given for the types, assume all types are
1130 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1131 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1132 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1133 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1135 /* store our flags and other fields */
1136 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1137 hook->func = callback;
1138 hook->data = user_data;
1139 hook->destroy = destroy_data;
1140 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1143 g_hook_prepend (&pad->probes, hook);
1145 /* incremenent cookie so that the new hook get's called */
1146 pad->priv->probe_list_cookie++;
1148 /* get the id of the hook, we return this and it can be used to remove the
1150 res = hook->hook_id;
1152 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1154 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1155 /* we have a block probe */
1157 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1158 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1159 "now %d blocking probes", pad->num_blocked);
1162 /* call the callback if we need to be called for idle callbacks */
1163 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1164 if (pad->priv->using > 0) {
1165 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1166 * flag above, the last thread to leave the push will do the callback. New
1167 * threads going into the push will block. */
1168 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1169 "pad is in use, delay idle callback");
1170 GST_OBJECT_UNLOCK (pad);
1172 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1174 /* the pad is idle now, we can signal the idle callback now */
1175 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1176 "pad is idle, trigger idle callback");
1177 GST_OBJECT_UNLOCK (pad);
1179 callback (pad, &info, user_data);
1182 GST_OBJECT_UNLOCK (pad);
1188 cleanup_hook (GstPad * pad, GHook * hook)
1190 GstPadProbeType type;
1192 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1194 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1195 /* unblock when we remove the last blocking probe */
1197 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1199 if (pad->num_blocked == 0) {
1200 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1201 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1202 GST_PAD_BLOCK_BROADCAST (pad);
1205 g_hook_destroy_link (&pad->probes, hook);
1210 * gst_pad_remove_probe:
1211 * @pad: the #GstPad with the probe
1212 * @id: the probe id to remove
1214 * Remove the probe with @id from @pad.
1219 gst_pad_remove_probe (GstPad * pad, gulong id)
1223 g_return_if_fail (GST_IS_PAD (pad));
1225 GST_OBJECT_LOCK (pad);
1227 hook = g_hook_get (&pad->probes, id);
1231 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1233 cleanup_hook (pad, hook);
1234 GST_OBJECT_UNLOCK (pad);
1240 GST_OBJECT_UNLOCK (pad);
1241 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1247 * gst_pad_is_blocked:
1248 * @pad: the #GstPad to query
1250 * Checks if the pad is blocked or not. This function returns the
1251 * last requested state of the pad. It is not certain that the pad
1252 * is actually blocking at this point (see gst_pad_is_blocking()).
1254 * Returns: TRUE if the pad is blocked.
1259 gst_pad_is_blocked (GstPad * pad)
1261 gboolean result = FALSE;
1263 g_return_val_if_fail (GST_IS_PAD (pad), result);
1265 GST_OBJECT_LOCK (pad);
1266 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1267 GST_OBJECT_UNLOCK (pad);
1273 * gst_pad_is_blocking:
1274 * @pad: the #GstPad to query
1276 * Checks if the pad is blocking or not. This is a guaranteed state
1277 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1279 * Returns: TRUE if the pad is blocking.
1286 gst_pad_is_blocking (GstPad * pad)
1288 gboolean result = FALSE;
1290 g_return_val_if_fail (GST_IS_PAD (pad), result);
1292 GST_OBJECT_LOCK (pad);
1293 /* the blocking flag is only valid if the pad is not flushing */
1294 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1295 GST_OBJECT_UNLOCK (pad);
1301 * gst_pad_check_reconfigure:
1302 * @pad: the #GstPad to check
1304 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1305 * if the flag was set.
1307 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1310 gst_pad_check_reconfigure (GstPad * pad)
1312 gboolean reconfigure;
1314 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1316 GST_OBJECT_LOCK (pad);
1317 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1319 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
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 * @user_data: user_data passed to @notify
1348 * @notify: notify called when @activate will not be used anymore.
1350 * Sets the given activate function for @pad. The activate function will
1351 * dispatch to gst_pad_activate_push() or gst_pad_activate_pull() to perform
1352 * the actual activation. Only makes sense to set on sink pads.
1354 * Call this function if your sink pad can start a pull-based task.
1357 gst_pad_set_activate_function_full (GstPad * pad,
1358 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1360 g_return_if_fail (GST_IS_PAD (pad));
1362 if (pad->activatenotify)
1363 pad->activatenotify (pad->activatedata);
1364 GST_PAD_ACTIVATEFUNC (pad) = activate;
1365 pad->activatedata = user_data;
1366 pad->activatenotify = notify;
1368 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1369 GST_DEBUG_FUNCPTR_NAME (activate));
1373 * gst_pad_set_activatemode_function_full:
1375 * @activatemode: the #GstPadActivateModeFunction to set.
1376 * @user_data: user_data passed to @notify
1377 * @notify: notify called when @activatemode will not be used anymore.
1379 * Sets the given activate_mode function for the pad. An activate_mode function
1380 * prepares the element for data passing.
1383 gst_pad_set_activatemode_function_full (GstPad * pad,
1384 GstPadActivateModeFunction activatemode, gpointer user_data,
1385 GDestroyNotify notify)
1387 g_return_if_fail (GST_IS_PAD (pad));
1389 if (pad->activatemodenotify)
1390 pad->activatemodenotify (pad->activatemodedata);
1391 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1392 pad->activatemodedata = user_data;
1393 pad->activatemodenotify = notify;
1395 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1396 GST_DEBUG_FUNCPTR_NAME (activatemode));
1400 * gst_pad_set_chain_function_full:
1401 * @pad: a sink #GstPad.
1402 * @chain: the #GstPadChainFunction to set.
1403 * @user_data: user_data passed to @notify
1404 * @notify: notify called when @chain will not be used anymore.
1406 * Sets the given chain function for the pad. The chain function is called to
1407 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1410 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1411 gpointer user_data, GDestroyNotify notify)
1413 g_return_if_fail (GST_IS_PAD (pad));
1414 g_return_if_fail (GST_PAD_IS_SINK (pad));
1416 if (pad->chainnotify)
1417 pad->chainnotify (pad->chaindata);
1418 GST_PAD_CHAINFUNC (pad) = chain;
1419 pad->chaindata = user_data;
1420 pad->chainnotify = notify;
1422 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1423 GST_DEBUG_FUNCPTR_NAME (chain));
1427 * gst_pad_set_chain_list_function_full:
1428 * @pad: a sink #GstPad.
1429 * @chainlist: the #GstPadChainListFunction to set.
1430 * @user_data: user_data passed to @notify
1431 * @notify: notify called when @chainlist will not be used anymore.
1433 * Sets the given chain list function for the pad. The chainlist function is
1434 * called to process a #GstBufferList input buffer list. See
1435 * #GstPadChainListFunction for more details.
1440 gst_pad_set_chain_list_function_full (GstPad * pad,
1441 GstPadChainListFunction chainlist, gpointer user_data,
1442 GDestroyNotify notify)
1444 g_return_if_fail (GST_IS_PAD (pad));
1445 g_return_if_fail (GST_PAD_IS_SINK (pad));
1447 if (pad->chainlistnotify)
1448 pad->chainlistnotify (pad->chainlistdata);
1449 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1450 pad->chainlistdata = user_data;
1451 pad->chainlistnotify = notify;
1453 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1454 GST_DEBUG_FUNCPTR_NAME (chainlist));
1458 * gst_pad_set_getrange_function_full:
1459 * @pad: a source #GstPad.
1460 * @get: the #GstPadGetRangeFunction to set.
1461 * @user_data: user_data passed to @notify
1462 * @notify: notify called when @get will not be used anymore.
1464 * Sets the given getrange function for the pad. The getrange function is
1465 * called to produce a new #GstBuffer to start the processing pipeline. see
1466 * #GstPadGetRangeFunction for a description of the getrange function.
1469 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1470 gpointer user_data, GDestroyNotify notify)
1472 g_return_if_fail (GST_IS_PAD (pad));
1473 g_return_if_fail (GST_PAD_IS_SRC (pad));
1475 if (pad->getrangenotify)
1476 pad->getrangenotify (pad->getrangedata);
1477 GST_PAD_GETRANGEFUNC (pad) = get;
1478 pad->getrangedata = user_data;
1479 pad->getrangenotify = notify;
1481 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1482 GST_DEBUG_FUNCPTR_NAME (get));
1486 * gst_pad_set_event_function_full:
1487 * @pad: a #GstPad of either direction.
1488 * @event: the #GstPadEventFunction to set.
1489 * @user_data: user_data passed to @notify
1490 * @notify: notify called when @event will not be used anymore.
1492 * Sets the given event handler for the pad.
1495 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1496 gpointer user_data, GDestroyNotify notify)
1498 g_return_if_fail (GST_IS_PAD (pad));
1500 if (pad->eventnotify)
1501 pad->eventnotify (pad->eventdata);
1502 GST_PAD_EVENTFUNC (pad) = event;
1503 pad->eventdata = user_data;
1504 pad->eventnotify = notify;
1506 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1507 GST_DEBUG_FUNCPTR_NAME (event));
1511 * gst_pad_set_query_function_full:
1512 * @pad: a #GstPad of either direction.
1513 * @query: the #GstPadQueryFunction to set.
1514 * @user_data: user_data passed to @notify
1515 * @notify: notify called when @query will not be used anymore.
1517 * Set the given query function for the pad.
1520 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1521 gpointer user_data, GDestroyNotify notify)
1523 g_return_if_fail (GST_IS_PAD (pad));
1525 if (pad->querynotify)
1526 pad->querynotify (pad->querydata);
1527 GST_PAD_QUERYFUNC (pad) = query;
1528 pad->querydata = user_data;
1529 pad->querynotify = notify;
1531 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1532 GST_DEBUG_FUNCPTR_NAME (query));
1536 * gst_pad_set_iterate_internal_links_function_full:
1537 * @pad: a #GstPad of either direction.
1538 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1539 * @user_data: user_data passed to @notify
1540 * @notify: notify called when @iterintlink will not be used anymore.
1542 * Sets the given internal link iterator function for the pad.
1547 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1548 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1549 GDestroyNotify notify)
1551 g_return_if_fail (GST_IS_PAD (pad));
1553 if (pad->iterintlinknotify)
1554 pad->iterintlinknotify (pad->iterintlinkdata);
1555 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1556 pad->iterintlinkdata = user_data;
1557 pad->iterintlinknotify = notify;
1559 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1560 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1564 * gst_pad_set_link_function_full:
1566 * @link: the #GstPadLinkFunction to set.
1567 * @user_data: user_data passed to @notify
1568 * @notify: notify called when @link will not be used anymore.
1570 * Sets the given link function for the pad. It will be called when
1571 * the pad is linked with another pad.
1573 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1576 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1577 * cannot be made for some reason.
1579 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1580 * of the peer sink pad, if present.
1583 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1584 gpointer user_data, GDestroyNotify notify)
1586 g_return_if_fail (GST_IS_PAD (pad));
1588 if (pad->linknotify)
1589 pad->linknotify (pad->linkdata);
1590 GST_PAD_LINKFUNC (pad) = link;
1591 pad->linkdata = user_data;
1592 pad->linknotify = notify;
1594 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1595 GST_DEBUG_FUNCPTR_NAME (link));
1599 * gst_pad_set_unlink_function_full:
1601 * @unlink: the #GstPadUnlinkFunction to set.
1602 * @user_data: user_data passed to @notify
1603 * @notify: notify called when @unlink will not be used anymore.
1605 * Sets the given unlink function for the pad. It will be called
1606 * when the pad is unlinked.
1609 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1610 gpointer user_data, GDestroyNotify notify)
1612 g_return_if_fail (GST_IS_PAD (pad));
1614 if (pad->unlinknotify)
1615 pad->unlinknotify (pad->unlinkdata);
1616 GST_PAD_UNLINKFUNC (pad) = unlink;
1617 pad->unlinkdata = user_data;
1618 pad->unlinknotify = notify;
1620 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1621 GST_DEBUG_FUNCPTR_NAME (unlink));
1626 * @srcpad: the source #GstPad to unlink.
1627 * @sinkpad: the sink #GstPad to unlink.
1629 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1630 * signal on both pads.
1632 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1633 * the pads were not linked together.
1638 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1640 gboolean result = FALSE;
1641 GstElement *parent = NULL;
1643 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1644 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1645 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1646 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1648 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1649 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1650 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1652 /* We need to notify the parent before taking any pad locks as the bin in
1653 * question might be waiting for a lock on the pad while holding its lock
1654 * that our message will try to take. */
1655 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1656 if (GST_IS_ELEMENT (parent)) {
1657 gst_element_post_message (parent,
1658 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1659 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1661 gst_object_unref (parent);
1666 GST_OBJECT_LOCK (srcpad);
1667 GST_OBJECT_LOCK (sinkpad);
1669 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1670 goto not_linked_together;
1672 if (GST_PAD_UNLINKFUNC (srcpad)) {
1673 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1675 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1676 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1679 /* first clear peers */
1680 GST_PAD_PEER (srcpad) = NULL;
1681 GST_PAD_PEER (sinkpad) = NULL;
1683 GST_OBJECT_UNLOCK (sinkpad);
1684 GST_OBJECT_UNLOCK (srcpad);
1686 /* fire off a signal to each of the pads telling them
1687 * that they've been unlinked */
1688 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1689 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1691 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1692 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1697 if (parent != NULL) {
1698 gst_element_post_message (parent,
1699 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1700 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1701 gst_object_unref (parent);
1706 not_linked_together:
1708 /* we do not emit a warning in this case because unlinking cannot
1709 * be made MT safe.*/
1710 GST_OBJECT_UNLOCK (sinkpad);
1711 GST_OBJECT_UNLOCK (srcpad);
1717 * gst_pad_is_linked:
1718 * @pad: pad to check
1720 * Checks if a @pad is linked to another pad or not.
1722 * Returns: TRUE if the pad is linked, FALSE otherwise.
1727 gst_pad_is_linked (GstPad * pad)
1731 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1733 GST_OBJECT_LOCK (pad);
1734 result = (GST_PAD_PEER (pad) != NULL);
1735 GST_OBJECT_UNLOCK (pad);
1740 /* get the caps from both pads and see if the intersection
1743 * This function should be called with the pad LOCK on both
1747 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1748 GstPadLinkCheck flags)
1750 GstCaps *srccaps = NULL;
1751 GstCaps *sinkcaps = NULL;
1752 gboolean compatible = FALSE;
1754 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1757 /* Doing the expensive caps checking takes priority over only checking the template caps */
1758 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1759 GST_OBJECT_UNLOCK (sink);
1760 GST_OBJECT_UNLOCK (src);
1762 srccaps = gst_pad_query_caps (src, NULL);
1763 sinkcaps = gst_pad_query_caps (sink, NULL);
1765 GST_OBJECT_LOCK (src);
1766 GST_OBJECT_LOCK (sink);
1768 /* If one of the two pads doesn't have a template, consider the intersection
1770 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
1771 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
1775 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
1777 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
1780 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
1782 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
1785 /* if we have caps on both pads we can check the intersection. If one
1786 * of the caps is NULL, we return TRUE. */
1787 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1789 gst_caps_unref (srccaps);
1791 gst_caps_unref (sinkcaps);
1795 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
1796 gst_caps_unref (srccaps);
1797 gst_caps_unref (sinkcaps);
1800 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
1801 (compatible ? "" : "not"));
1806 /* check if the grandparents of both pads are the same.
1807 * This check is required so that we don't try to link
1808 * pads from elements in different bins without ghostpads.
1810 * The LOCK should be held on both pads
1813 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1815 GstObject *psrc, *psink;
1817 psrc = GST_OBJECT_PARENT (src);
1818 psink = GST_OBJECT_PARENT (sink);
1820 /* if one of the pads has no parent, we allow the link */
1821 if (G_UNLIKELY (psrc == NULL || psink == NULL))
1824 /* only care about parents that are elements */
1825 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
1826 goto no_element_parent;
1828 /* if the parents are the same, we have a loop */
1829 if (G_UNLIKELY (psrc == psink))
1832 /* if they both have a parent, we check the grandparents. We can not lock
1833 * the parent because we hold on the child (pad) and the locking order is
1834 * parent >> child. */
1835 psrc = GST_OBJECT_PARENT (psrc);
1836 psink = GST_OBJECT_PARENT (psink);
1838 /* if they have grandparents but they are not the same */
1839 if (G_UNLIKELY (psrc != psink))
1840 goto wrong_grandparents;
1847 GST_CAT_DEBUG (GST_CAT_CAPS,
1848 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
1849 GST_PTR_FORMAT, psrc, psink);
1854 GST_CAT_DEBUG (GST_CAT_CAPS,
1855 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
1856 GST_PTR_FORMAT, psrc, psink);
1861 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1867 GST_CAT_DEBUG (GST_CAT_CAPS,
1868 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1869 GST_PTR_FORMAT, psrc, psink);
1874 /* FIXME leftover from an attempt at refactoring... */
1875 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
1876 * the two pads will be locked in the srcpad, sinkpad order. */
1877 static GstPadLinkReturn
1878 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
1880 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1881 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1883 GST_OBJECT_LOCK (srcpad);
1885 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1886 goto src_was_linked;
1888 GST_OBJECT_LOCK (sinkpad);
1890 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1891 goto sink_was_linked;
1893 /* check hierarchy, pads can only be linked if the grandparents
1895 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
1896 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
1897 goto wrong_hierarchy;
1899 /* check pad caps for non-empty intersection */
1900 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
1903 /* FIXME check pad scheduling for non-empty intersection */
1905 return GST_PAD_LINK_OK;
1909 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
1910 GST_DEBUG_PAD_NAME (srcpad),
1911 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
1912 /* we do not emit a warning in this case because unlinking cannot
1913 * be made MT safe.*/
1914 GST_OBJECT_UNLOCK (srcpad);
1915 return GST_PAD_LINK_WAS_LINKED;
1919 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
1920 GST_DEBUG_PAD_NAME (sinkpad),
1921 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
1922 /* we do not emit a warning in this case because unlinking cannot
1923 * be made MT safe.*/
1924 GST_OBJECT_UNLOCK (sinkpad);
1925 GST_OBJECT_UNLOCK (srcpad);
1926 return GST_PAD_LINK_WAS_LINKED;
1930 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
1931 GST_OBJECT_UNLOCK (sinkpad);
1932 GST_OBJECT_UNLOCK (srcpad);
1933 return GST_PAD_LINK_WRONG_HIERARCHY;
1937 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1938 GST_OBJECT_UNLOCK (sinkpad);
1939 GST_OBJECT_UNLOCK (srcpad);
1940 return GST_PAD_LINK_NOFORMAT;
1946 * @srcpad: the source #GstPad.
1947 * @sinkpad: the sink #GstPad.
1949 * Checks if the source pad and the sink pad are compatible so they can be
1952 * Returns: TRUE if the pads can be linked.
1955 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1957 GstPadLinkReturn result;
1959 /* generic checks */
1960 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1961 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1963 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
1964 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1966 /* gst_pad_link_prepare does everything for us, we only release the locks
1967 * on the pads that it gets us. If this function returns !OK the locks are not
1969 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
1970 if (result != GST_PAD_LINK_OK)
1973 GST_OBJECT_UNLOCK (srcpad);
1974 GST_OBJECT_UNLOCK (sinkpad);
1977 return result == GST_PAD_LINK_OK;
1981 * gst_pad_link_full:
1982 * @srcpad: the source #GstPad to link.
1983 * @sinkpad: the sink #GstPad to link.
1984 * @flags: the checks to validate when linking
1986 * Links the source pad and the sink pad.
1988 * This variant of #gst_pad_link provides a more granular control on the
1989 * checks being done when linking. While providing some considerable speedups
1990 * the caller of this method must be aware that wrong usage of those flags
1991 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
1992 * for more information.
1996 * Returns: A result code indicating if the connection worked or
2002 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2004 GstPadLinkReturn result;
2006 GstPadLinkFunction srcfunc, sinkfunc;
2008 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2009 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2010 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2011 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2012 GST_PAD_LINK_WRONG_DIRECTION);
2014 /* Notify the parent early. See gst_pad_unlink for details. */
2015 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2016 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2017 gst_element_post_message (parent,
2018 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2019 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2021 gst_object_unref (parent);
2026 /* prepare will also lock the two pads */
2027 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2029 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2032 /* must set peers before calling the link function */
2033 GST_PAD_PEER (srcpad) = sinkpad;
2034 GST_PAD_PEER (sinkpad) = srcpad;
2036 /* check events, when something is different, mark pending */
2037 schedule_events (srcpad, sinkpad);
2039 /* get the link functions */
2040 srcfunc = GST_PAD_LINKFUNC (srcpad);
2041 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2043 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2044 /* custom link functions, execute them */
2045 GST_OBJECT_UNLOCK (sinkpad);
2046 GST_OBJECT_UNLOCK (srcpad);
2049 /* this one will call the peer link function */
2050 result = srcfunc (srcpad, sinkpad);
2051 } else if (sinkfunc) {
2052 /* if no source link function, we need to call the sink link
2053 * function ourselves. */
2054 result = sinkfunc (sinkpad, srcpad);
2057 GST_OBJECT_LOCK (srcpad);
2058 GST_OBJECT_LOCK (sinkpad);
2060 /* we released the lock, check if the same pads are linked still */
2061 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2062 goto concurrent_link;
2064 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2067 GST_OBJECT_UNLOCK (sinkpad);
2068 GST_OBJECT_UNLOCK (srcpad);
2070 /* fire off a signal to each of the pads telling them
2071 * that they've been linked */
2072 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2073 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2075 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2076 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2078 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2081 if (G_LIKELY (parent)) {
2082 gst_element_post_message (parent,
2083 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2084 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2085 gst_object_unref (parent);
2093 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2094 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2095 GST_OBJECT_UNLOCK (sinkpad);
2096 GST_OBJECT_UNLOCK (srcpad);
2098 /* The other link operation succeeded first */
2099 result = GST_PAD_LINK_WAS_LINKED;
2104 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2105 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2107 GST_PAD_PEER (srcpad) = NULL;
2108 GST_PAD_PEER (sinkpad) = NULL;
2110 GST_OBJECT_UNLOCK (sinkpad);
2111 GST_OBJECT_UNLOCK (srcpad);
2119 * @srcpad: the source #GstPad to link.
2120 * @sinkpad: the sink #GstPad to link.
2122 * Links the source pad and the sink pad.
2124 * Returns: A result code indicating if the connection worked or
2130 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2132 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2136 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2138 GstPadTemplate **template_p;
2140 /* this function would need checks if it weren't static */
2142 GST_OBJECT_LOCK (pad);
2143 template_p = &pad->padtemplate;
2144 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2145 GST_OBJECT_UNLOCK (pad);
2148 gst_pad_template_pad_created (templ, pad);
2152 * gst_pad_get_pad_template:
2155 * Gets the template for @pad.
2157 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2158 * instantiated, or %NULL if this pad has no template. Unref after
2162 gst_pad_get_pad_template (GstPad * pad)
2164 GstPadTemplate *templ;
2166 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2168 templ = GST_PAD_PAD_TEMPLATE (pad);
2170 return (templ ? gst_object_ref (templ) : NULL);
2174 * gst_pad_has_current_caps:
2175 * @pad: a #GstPad to check
2177 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2179 * Returns: TRUE when @pad has caps associated with it.
2182 gst_pad_has_current_caps (GstPad * pad)
2187 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2189 GST_OBJECT_LOCK (pad);
2190 caps = get_pad_caps (pad);
2191 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2192 "check current pad caps %" GST_PTR_FORMAT, caps);
2193 result = (caps != NULL);
2194 GST_OBJECT_UNLOCK (pad);
2200 * gst_pad_get_current_caps:
2201 * @pad: a #GstPad to get the current capabilities of.
2203 * Gets the capabilities currently configured on @pad with the last
2204 * #GST_EVENT_CAPS event.
2206 * Returns: the current caps of the pad with incremented ref-count.
2209 gst_pad_get_current_caps (GstPad * pad)
2213 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2215 GST_OBJECT_LOCK (pad);
2216 if ((result = get_pad_caps (pad)))
2217 gst_caps_ref (result);
2218 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2219 "get current pad caps %" GST_PTR_FORMAT, result);
2220 GST_OBJECT_UNLOCK (pad);
2227 * @pad: a #GstPad to set the capabilities of.
2228 * @caps: (transfer none): a #GstCaps to set.
2230 * Sets the capabilities of this pad. The caps must be fixed. Any previous
2231 * caps on the pad will be unreffed. This function refs the caps so you should
2232 * unref if as soon as you don't need it anymore.
2233 * It is possible to set NULL caps, which will make the pad unnegotiated
2236 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
2237 * or bad parameters were provided to this function.
2242 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
2245 gboolean res = TRUE;
2247 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2248 g_return_val_if_fail (caps != NULL && gst_caps_is_fixed (caps), FALSE);
2250 event = gst_event_new_caps (caps);
2252 if (GST_PAD_IS_SRC (pad))
2253 res = gst_pad_push_event (pad, event);
2255 res = gst_pad_send_event (pad, event);
2261 * gst_pad_get_pad_template_caps:
2262 * @pad: a #GstPad to get the template capabilities from.
2264 * Gets the capabilities for @pad's template.
2266 * Returns: (transfer full): the #GstCaps of this pad template.
2267 * Unref after usage.
2270 gst_pad_get_pad_template_caps (GstPad * pad)
2272 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2274 if (GST_PAD_PAD_TEMPLATE (pad))
2275 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2277 return gst_caps_ref (GST_CAPS_ANY);
2282 * @pad: a #GstPad to get the peer of.
2284 * Gets the peer of @pad. This function refs the peer pad so
2285 * you need to unref it after use.
2287 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2292 gst_pad_get_peer (GstPad * pad)
2296 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2298 GST_OBJECT_LOCK (pad);
2299 result = GST_PAD_PEER (pad);
2301 gst_object_ref (result);
2302 GST_OBJECT_UNLOCK (pad);
2308 * gst_pad_get_allowed_caps:
2311 * Gets the capabilities of the allowed media types that can flow through
2312 * @pad and its peer.
2314 * The allowed capabilities is calculated as the intersection of the results of
2315 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2316 * on the resulting caps.
2318 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2319 * caps when you no longer need it. This function returns NULL when @pad
2325 gst_pad_get_allowed_caps (GstPad * pad)
2332 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2334 GST_OBJECT_LOCK (pad);
2335 peer = GST_PAD_PEER (pad);
2336 if (G_UNLIKELY (peer == NULL))
2339 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2341 gst_object_ref (peer);
2342 GST_OBJECT_UNLOCK (pad);
2343 mycaps = gst_pad_query_caps (pad, NULL);
2345 peercaps = gst_pad_query_caps (peer, NULL);
2346 gst_object_unref (peer);
2348 caps = gst_caps_intersect (mycaps, peercaps);
2349 gst_caps_unref (peercaps);
2350 gst_caps_unref (mycaps);
2352 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2359 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2360 GST_OBJECT_UNLOCK (pad);
2367 * gst_pad_iterate_internal_links_default:
2368 * @pad: the #GstPad to get the internal links of.
2369 * @parent: the parent of @pad or NULL
2371 * Iterate the list of pads to which the given pad is linked to inside of
2372 * the parent element.
2373 * This is the default handler, and thus returns an iterator of all of the
2374 * pads inside the parent element with opposite direction.
2376 * The caller must free this iterator after use with gst_iterator_free().
2378 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2379 * returned pad with gst_object_unref().
2384 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2391 GstElement *eparent;
2393 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2395 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2396 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2398 GST_OBJECT_LOCK (pad);
2399 eparent = GST_PAD_PARENT (pad);
2400 if (!eparent || !GST_IS_ELEMENT (eparent))
2403 gst_object_ref (eparent);
2404 GST_OBJECT_UNLOCK (pad);
2407 if (pad->direction == GST_PAD_SRC)
2408 padlist = &eparent->sinkpads;
2410 padlist = &eparent->srcpads;
2412 GST_DEBUG_OBJECT (pad, "Making iterator");
2414 cookie = &eparent->pads_cookie;
2416 lock = GST_OBJECT_GET_LOCK (eparent);
2418 res = gst_iterator_new_list (GST_TYPE_PAD,
2419 lock, cookie, padlist, (GObject *) owner, NULL);
2421 gst_object_unref (owner);
2428 GST_OBJECT_UNLOCK (pad);
2429 GST_DEBUG_OBJECT (pad, "no parent element");
2435 * gst_pad_iterate_internal_links:
2436 * @pad: the GstPad to get the internal links of.
2438 * Gets an iterator for the pads to which the given pad is linked to inside
2439 * of the parent element.
2441 * Each #GstPad element yielded by the iterator will have its refcount increased,
2442 * so unref after use.
2444 * Free-function: gst_iterator_free
2446 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2447 * pad does not have an iterator function configured. Use
2448 * gst_iterator_free() after usage.
2453 gst_pad_iterate_internal_links (GstPad * pad)
2455 GstIterator *res = NULL;
2458 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2460 GST_OBJECT_LOCK (pad);
2461 ACQUIRE_PARENT (pad, parent, no_parent);
2462 GST_OBJECT_UNLOCK (pad);
2464 if (GST_PAD_ITERINTLINKFUNC (pad))
2465 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2467 RELEASE_PARENT (parent);
2474 GST_DEBUG_OBJECT (pad, "no parent");
2475 GST_OBJECT_UNLOCK (pad);
2483 * @forward: a #GstPadForwardFunction
2484 * @user_data: user data passed to @forward
2486 * Calls @forward for all internally linked pads of @pad. This function deals with
2487 * dynamically changing internal pads and will make sure that the @forward
2488 * function is only called once for each pad.
2490 * When @forward returns TRUE, no further pads will be processed.
2492 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2495 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2498 gboolean result = FALSE;
2500 gboolean done = FALSE;
2501 GValue item = { 0, };
2502 GList *pushed_pads = NULL;
2504 iter = gst_pad_iterate_internal_links (pad);
2510 switch (gst_iterator_next (iter, &item)) {
2511 case GST_ITERATOR_OK:
2515 intpad = g_value_get_object (&item);
2517 /* if already pushed, skip. FIXME, find something faster to tag pads */
2518 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2519 g_value_reset (&item);
2523 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2524 GST_DEBUG_PAD_NAME (intpad));
2525 done = result = forward (intpad, user_data);
2527 pushed_pads = g_list_prepend (pushed_pads, intpad);
2529 g_value_reset (&item);
2532 case GST_ITERATOR_RESYNC:
2533 /* We don't reset the result here because we don't push the event
2534 * again on pads that got the event already and because we need
2535 * to consider the result of the previous pushes */
2536 gst_iterator_resync (iter);
2538 case GST_ITERATOR_ERROR:
2539 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2542 case GST_ITERATOR_DONE:
2547 g_value_unset (&item);
2548 gst_iterator_free (iter);
2550 g_list_free (pushed_pads);
2560 gboolean dispatched;
2564 event_forward_func (GstPad * pad, EventData * data)
2566 /* for each pad we send to, we should ref the event; it's up
2567 * to downstream to unref again when handled. */
2568 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2569 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2571 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2573 data->dispatched = TRUE;
2580 * gst_pad_event_default:
2581 * @pad: a #GstPad to call the default event handler on.
2582 * @parent: the parent of @pad or NULL
2583 * @event: (transfer full): the #GstEvent to handle.
2585 * Invokes the default event handler for the given pad.
2587 * The EOS event will pause the task associated with @pad before it is forwarded
2588 * to all internally linked pads,
2590 * The the event is sent to all pads internally linked to @pad. This function
2591 * takes ownership of @event.
2593 * Returns: TRUE if the event was sent successfully.
2596 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2598 gboolean result, forward = TRUE;
2600 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2601 g_return_val_if_fail (event != NULL, FALSE);
2603 GST_LOG_OBJECT (pad, "default event handler");
2605 switch (GST_EVENT_TYPE (event)) {
2608 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
2609 gst_pad_pause_task (pad);
2612 case GST_EVENT_CAPS:
2613 forward = GST_PAD_IS_PROXY_CAPS (pad);
2624 data.dispatched = FALSE;
2625 data.result = FALSE;
2627 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2629 /* for sinkpads without a parent element or without internal links, nothing
2630 * will be dispatched but we still want to return TRUE. */
2631 if (data.dispatched)
2632 result = data.result;
2637 gst_event_unref (event);
2642 /* Default accept caps implementation just checks against
2643 * the allowed caps for the pad */
2645 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2647 /* get the caps and see if it intersects to something not empty */
2648 GstCaps *caps, *allowed;
2651 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2653 /* first forward the query to internally linked pads when we are dealing with
2655 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2656 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2661 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2662 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2664 allowed = gst_pad_query_caps (pad, NULL);
2665 gst_query_parse_accept_caps (query, &caps);
2668 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
2669 result = gst_caps_is_subset (caps, allowed);
2670 gst_caps_unref (allowed);
2672 GST_DEBUG_OBJECT (pad, "no caps allowed on the pad");
2675 gst_query_set_accept_caps_result (query, result);
2681 /* Default caps implementation */
2683 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2685 GstCaps *result = NULL, *filter;
2686 GstPadTemplate *templ;
2687 gboolean fixed_caps;
2689 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2691 gst_query_parse_caps (query, &filter);
2693 /* first try to proxy if we must */
2694 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2695 if ((gst_pad_proxy_query_caps (pad, query))) {
2696 gst_query_parse_caps_result (query, &result);
2701 /* no proxy or it failed, do default handling */
2702 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2704 GST_OBJECT_LOCK (pad);
2706 /* fixed caps, try the negotiated caps first */
2707 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2708 if ((result = get_pad_caps (pad)))
2709 goto filter_done_unlock;
2712 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2713 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2714 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2715 goto filter_done_unlock;
2719 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2720 "non-fixed pad caps: trying pad caps");
2721 /* non fixed caps, try the negotiated caps */
2722 if ((result = get_pad_caps (pad)))
2723 goto filter_done_unlock;
2726 /* this almost never happens */
2727 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2728 result = GST_CAPS_ANY;
2731 GST_OBJECT_UNLOCK (pad);
2734 /* run the filter on the result */
2736 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2737 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2738 GST_PTR_FORMAT, result, result, filter, filter);
2739 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2740 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2743 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2744 "using caps %p %" GST_PTR_FORMAT, result, result);
2745 result = gst_caps_ref (result);
2748 gst_query_set_caps_result (query, result);
2749 gst_caps_unref (result);
2755 * gst_pad_query_default:
2756 * @pad: a #GstPad to call the default query handler on.
2757 * @parent: the parent of @pad or NULL
2758 * @query: (transfer none): the #GstQuery to handle.
2760 * Invokes the default query handler for the given pad.
2761 * The query is sent to all pads internally linked to @pad. Note that
2762 * if there are many possible sink pads that are internally linked to
2763 * @pad, only one will be sent the query.
2764 * Multi-sinkpad elements should implement custom query handlers.
2766 * Returns: TRUE if the query was performed successfully.
2769 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
2771 gboolean forward, ret = FALSE;
2773 switch (GST_QUERY_TYPE (query)) {
2774 case GST_QUERY_SCHEDULING:
2777 case GST_QUERY_ALLOCATION:
2778 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
2780 case GST_QUERY_ACCEPT_CAPS:
2781 ret = gst_pad_query_accept_caps_default (pad, query);
2784 case GST_QUERY_CAPS:
2785 ret = gst_pad_query_caps_default (pad, query);
2788 case GST_QUERY_POSITION:
2789 case GST_QUERY_SEEKING:
2790 case GST_QUERY_FORMATS:
2791 case GST_QUERY_LATENCY:
2792 case GST_QUERY_JITTER:
2793 case GST_QUERY_RATE:
2794 case GST_QUERY_CONVERT:
2801 ret = gst_pad_forward
2802 (pad, (GstPadForwardFunction) gst_pad_peer_query, query);
2808 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
2810 GstPad *pad = data->pad;
2811 GstPadProbeInfo *info = data->info;
2812 GstPadProbeType type, flags;
2813 GstPadProbeCallback callback;
2814 GstPadProbeReturn ret;
2816 /* if we have called this callback, do nothing */
2817 if (PROBE_COOKIE (hook) == data->cookie) {
2818 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2819 "hook %lu, cookie %u already called", hook->hook_id,
2820 PROBE_COOKIE (hook));
2824 PROBE_COOKIE (hook) = data->cookie;
2826 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
2829 /* one of the data types */
2830 if ((flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
2832 /* one of the scheduling types */
2833 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
2835 /* one of the blocking types must match */
2836 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
2837 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
2839 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
2840 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
2841 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
2844 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2845 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
2846 PROBE_COOKIE (hook), flags);
2848 data->marshalled = TRUE;
2850 callback = (GstPadProbeCallback) hook->func;
2851 if (callback == NULL)
2854 info->id = hook->hook_id;
2856 GST_OBJECT_UNLOCK (pad);
2858 ret = callback (pad, info, hook->data);
2860 GST_OBJECT_LOCK (pad);
2863 case GST_PAD_PROBE_REMOVE:
2864 /* remove the probe */
2865 GST_DEBUG_OBJECT (pad, "asked to remove hook");
2866 cleanup_hook (pad, hook);
2868 case GST_PAD_PROBE_DROP:
2869 /* need to drop the data, make sure other probes don't get called
2871 GST_DEBUG_OBJECT (pad, "asked to drop item");
2872 info->type = GST_PAD_PROBE_TYPE_INVALID;
2873 data->dropped = TRUE;
2875 case GST_PAD_PROBE_PASS:
2876 /* inform the pad block to let things pass */
2877 GST_DEBUG_OBJECT (pad, "asked to pass item");
2881 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
2888 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2889 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
2890 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
2895 #define PROBE_PRE_PULL(pad,mask,data,offs,size,label,probed,defaultval) \
2897 if (G_UNLIKELY (pad->num_probes)) { \
2898 /* we start with passing NULL as the data item */ \
2899 GstPadProbeInfo info = { mask, 0, NULL, offs, size }; \
2900 ret = do_probe_callbacks (pad, &info, defaultval); \
2901 /* store the possibly updated data item */ \
2902 data = GST_PAD_PROBE_INFO_DATA (&info); \
2903 /* if something went wrong, exit */ \
2904 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2906 /* otherwise check if the probe retured data */ \
2907 if (G_UNLIKELY (data != NULL)) \
2913 /* a probe that does not take or return any data */
2914 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
2916 if (G_UNLIKELY (pad->num_probes)) { \
2917 /* pass NULL as the data item */ \
2918 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
2919 ret = do_probe_callbacks (pad, &info, defaultval); \
2920 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2925 #define PROBE_FULL(pad,mask,data,offs,size,label,defaultval) \
2927 if (G_UNLIKELY (pad->num_probes)) { \
2928 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
2929 ret = do_probe_callbacks (pad, &info, defaultval); \
2930 data = GST_PAD_PROBE_INFO_DATA (&info); \
2931 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2936 #define PROBE_PUSH(pad,mask,data,label) \
2937 PROBE_FULL(pad, mask, data, -1, -1, label, GST_FLOW_OK);
2938 #define PROBE_PULL(pad,mask,data,offs,size,label) \
2939 PROBE_FULL(pad, mask, data, offs, size, label, GST_FLOW_OK);
2941 static GstFlowReturn
2942 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
2943 GstFlowReturn defaultval)
2952 data.marshalled = FALSE;
2953 data.dropped = FALSE;
2954 data.cookie = ++pad->priv->probe_cookie;
2957 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
2960 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2961 "do probes cookie %u", data.cookie);
2962 cookie = pad->priv->probe_list_cookie;
2964 g_hook_list_marshal (&pad->probes, TRUE,
2965 (GHookMarshaller) probe_hook_marshal, &data);
2967 /* if the list changed, call the new callbacks (they will not have their
2968 * cookie set to data.cookie */
2969 if (cookie != pad->priv->probe_list_cookie) {
2970 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2971 "probe list changed, restarting");
2975 /* the first item that dropped will stop the hooks and then we drop here */
2979 /* if no handler matched and we are blocking, let the item pass */
2980 if (!data.marshalled && is_block)
2983 /* At this point, all handlers returned either OK or PASS. If one handler
2984 * returned PASS, let the item pass */
2989 while (GST_PAD_IS_BLOCKED (pad)) {
2990 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2991 "we are blocked %d times", pad->num_blocked);
2993 /* we might have released the lock */
2994 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2997 /* now we block the streaming thread. It can be unlocked when we
2998 * deactivate the pad (which will also set the FLUSHING flag) or
2999 * when the pad is unblocked. A flushing event will also unblock
3000 * the pad after setting the FLUSHING flag. */
3001 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3002 "Waiting to be unblocked or set flushing");
3003 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3004 GST_PAD_BLOCK_WAIT (pad);
3005 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3006 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3008 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3018 GST_DEBUG_OBJECT (pad, "pad is flushing");
3019 return GST_FLOW_FLUSHING;
3023 GST_DEBUG_OBJECT (pad, "data is dropped");
3024 return GST_FLOW_CUSTOM_SUCCESS;
3028 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3029 GST_DEBUG_OBJECT (pad, "data is passed");
3037 * gst_pad_get_offset:
3040 * Get the offset applied to the running time of @pad. @pad has to be a source
3043 * Returns: the offset.
3046 gst_pad_get_offset (GstPad * pad)
3050 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3052 GST_OBJECT_LOCK (pad);
3053 result = pad->offset;
3054 GST_OBJECT_UNLOCK (pad);
3060 * gst_pad_set_offset:
3062 * @offset: the offset
3064 * Set the offset that will be applied to the running time of @pad.
3067 gst_pad_set_offset (GstPad * pad, gint64 offset)
3071 g_return_if_fail (GST_IS_PAD (pad));
3073 GST_OBJECT_LOCK (pad);
3074 /* if nothing changed, do nothing */
3075 if (pad->offset == offset)
3078 pad->offset = offset;
3079 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3081 /* sinkpads will apply their offset the next time a segment
3082 * event is received. */
3083 if (GST_PAD_IS_SINK (pad))
3086 /* resend the last segment event on next buffer push */
3087 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3088 ev->received = FALSE;
3089 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3093 GST_OBJECT_UNLOCK (pad);
3099 * @pad: a #GstPad to invoke the default query on.
3100 * @query: (transfer none): the #GstQuery to perform.
3102 * Dispatches a query to a pad. The query should have been allocated by the
3103 * caller via one of the type-specific allocation functions. The element that
3104 * the pad belongs to is responsible for filling the query with an appropriate
3105 * response, which should then be parsed with a type-specific query parsing
3108 * Again, the caller is responsible for both the allocation and deallocation of
3109 * the query structure.
3111 * Please also note that some queries might need a running pipeline to work.
3113 * Returns: TRUE if the query could be performed.
3116 gst_pad_query (GstPad * pad, GstQuery * query)
3120 GstPadQueryFunction func;
3121 GstPadProbeType type;
3124 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3125 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3127 GST_DEBUG_OBJECT (pad, "sending query %p (%s)", query,
3128 GST_QUERY_TYPE_NAME (query));
3130 if (GST_PAD_IS_SRC (pad))
3131 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3133 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3135 GST_OBJECT_LOCK (pad);
3136 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3137 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3138 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3140 ACQUIRE_PARENT (pad, parent, no_parent);
3141 GST_OBJECT_UNLOCK (pad);
3143 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3146 res = func (pad, parent, query);
3148 RELEASE_PARENT (parent);
3150 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3151 GST_QUERY_TYPE_NAME (query), res);
3156 GST_OBJECT_LOCK (pad);
3157 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3158 GST_OBJECT_UNLOCK (pad);
3165 GST_DEBUG_OBJECT (pad, "had no parent");
3166 GST_OBJECT_UNLOCK (pad);
3171 GST_DEBUG_OBJECT (pad, "had no query function");
3172 RELEASE_PARENT (parent);
3177 GST_DEBUG_OBJECT (pad, "query failed");
3182 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3183 GST_OBJECT_UNLOCK (pad);
3189 * gst_pad_peer_query:
3190 * @pad: a #GstPad to invoke the peer query on.
3191 * @query: (transfer none): the #GstQuery to perform.
3193 * Performs gst_pad_query() on the peer of @pad.
3195 * The caller is responsible for both the allocation and deallocation of
3196 * the query structure.
3198 * Returns: TRUE if the query could be performed. This function returns %FALSE
3199 * if @pad has no peer.
3204 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3207 GstPadProbeType type;
3211 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3212 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3214 if (GST_PAD_IS_SRC (pad))
3215 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3217 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3219 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3220 GST_QUERY_TYPE_NAME (query));
3222 GST_OBJECT_LOCK (pad);
3223 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3224 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3225 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3227 peerpad = GST_PAD_PEER (pad);
3228 if (G_UNLIKELY (peerpad == NULL))
3231 gst_object_ref (peerpad);
3232 GST_OBJECT_UNLOCK (pad);
3234 res = gst_pad_query (peerpad, query);
3236 gst_object_unref (peerpad);
3241 GST_OBJECT_LOCK (pad);
3242 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3243 GST_OBJECT_UNLOCK (pad);
3250 GST_WARNING_OBJECT (pad, "pad has no peer");
3251 GST_OBJECT_UNLOCK (pad);
3256 GST_DEBUG_OBJECT (pad, "query failed");
3261 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3262 GST_OBJECT_UNLOCK (pad);
3267 /**********************************************************************
3268 * Data passing functions
3272 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3274 GstFlowReturn *data = user_data;
3278 GST_DEBUG_OBJECT (pad, "event %s was already received",
3279 GST_EVENT_TYPE_NAME (ev->event));
3282 GST_OBJECT_UNLOCK (pad);
3284 *data = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3285 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, &stored);
3287 GST_OBJECT_LOCK (pad);
3288 return *data == GST_FLOW_OK;
3291 /* this is the chain function that does not perform the additional argument
3292 * checking for that little extra speed.
3294 static inline GstFlowReturn
3295 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3300 GST_PAD_STREAM_LOCK (pad);
3302 GST_OBJECT_LOCK (pad);
3303 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3306 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3309 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3311 PROBE_PUSH (pad, type, data, probe_stopped);
3313 parent = GST_OBJECT_PARENT (pad);
3314 GST_OBJECT_UNLOCK (pad);
3316 /* NOTE: we read the chainfunc unlocked.
3317 * we cannot hold the lock for the pad so we might send
3318 * the data to the wrong function. This is not really a
3319 * problem since functions are assigned at creation time
3320 * and don't change that often... */
3321 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3322 GstPadChainFunction chainfunc;
3324 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3327 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3328 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3329 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3331 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3333 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3334 "called chainfunction &%s with buffer %p, returned %s",
3335 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3337 GstPadChainListFunction chainlistfunc;
3339 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3342 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3343 "calling chainlistfunction &%s",
3344 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3346 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3348 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3349 "called chainlistfunction &%s, returned %s",
3350 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3353 GST_PAD_STREAM_UNLOCK (pad);
3360 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3361 "chaining, but pad was flushing");
3362 GST_OBJECT_UNLOCK (pad);
3363 GST_PAD_STREAM_UNLOCK (pad);
3364 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3365 return GST_FLOW_FLUSHING;
3369 g_critical ("chain on pad %s:%s but it was not in push mode",
3370 GST_DEBUG_PAD_NAME (pad));
3371 GST_OBJECT_UNLOCK (pad);
3372 GST_PAD_STREAM_UNLOCK (pad);
3373 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3374 return GST_FLOW_ERROR;
3378 GST_OBJECT_UNLOCK (pad);
3379 GST_PAD_STREAM_UNLOCK (pad);
3380 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3383 case GST_FLOW_CUSTOM_SUCCESS:
3384 GST_DEBUG_OBJECT (pad, "dropped buffer");
3388 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
3395 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3396 g_critical ("chain on pad %s:%s but it has no chainfunction",
3397 GST_DEBUG_PAD_NAME (pad));
3398 GST_PAD_STREAM_UNLOCK (pad);
3399 return GST_FLOW_NOT_SUPPORTED;
3405 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3406 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3409 * Chain a buffer to @pad.
3411 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3413 * If the buffer type is not acceptable for @pad (as negotiated with a
3414 * preceeding GST_EVENT_CAPS event), this function returns
3415 * #GST_FLOW_NOT_NEGOTIATED.
3417 * The function proceeds calling the chain function installed on @pad (see
3418 * gst_pad_set_chain_function()) and the return value of that function is
3419 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3422 * In all cases, success or failure, the caller loses its reference to @buffer
3423 * after calling this function.
3425 * Returns: a #GstFlowReturn from the pad.
3430 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3432 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3433 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3434 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3436 return gst_pad_chain_data_unchecked (pad,
3437 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3440 static GstFlowReturn
3441 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3442 GstBufferList * list)
3448 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3450 len = gst_buffer_list_length (list);
3453 for (i = 0; i < len; i++) {
3454 buffer = gst_buffer_list_get (list, i);
3456 gst_pad_chain_data_unchecked (pad,
3457 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3458 gst_buffer_ref (buffer));
3459 if (ret != GST_FLOW_OK)
3462 gst_buffer_list_unref (list);
3468 * gst_pad_chain_list:
3469 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3470 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3473 * Chain a bufferlist to @pad.
3475 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3477 * If @pad was not negotiated properly with a CAPS event, this function
3478 * returns #GST_FLOW_NOT_NEGOTIATED.
3480 * The function proceeds calling the chainlist function installed on @pad (see
3481 * gst_pad_set_chain_list_function()) and the return value of that function is
3482 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3483 * chainlist function.
3485 * In all cases, success or failure, the caller loses its reference to @list
3486 * after calling this function.
3490 * Returns: a #GstFlowReturn from the pad.
3495 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3497 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3498 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3499 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3501 return gst_pad_chain_data_unchecked (pad,
3502 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3505 static GstFlowReturn
3506 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3511 GST_OBJECT_LOCK (pad);
3512 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3515 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3518 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3519 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3521 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3524 events_foreach (pad, push_sticky, &ret);
3525 if (ret != GST_FLOW_OK)
3529 /* do block probes */
3530 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3532 /* do post-blocking probes */
3533 PROBE_PUSH (pad, type, data, probe_stopped);
3535 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3538 /* take ref to peer pad before releasing the lock */
3539 gst_object_ref (peer);
3541 GST_OBJECT_UNLOCK (pad);
3543 ret = gst_pad_chain_data_unchecked (peer, type, data);
3545 gst_object_unref (peer);
3547 GST_OBJECT_LOCK (pad);
3549 if (pad->priv->using == 0) {
3550 /* pad is not active anymore, trigger idle callbacks */
3551 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3552 probe_stopped, ret);
3554 GST_OBJECT_UNLOCK (pad);
3558 /* ERROR recovery here */
3562 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3563 "pushing, but pad was flushing");
3564 GST_OBJECT_UNLOCK (pad);
3565 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3566 return GST_FLOW_FLUSHING;
3570 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
3571 GST_DEBUG_PAD_NAME (pad));
3572 GST_OBJECT_UNLOCK (pad);
3573 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3574 return GST_FLOW_ERROR;
3578 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3579 "error pushing events, return %s", gst_flow_get_name (ret));
3580 GST_OBJECT_UNLOCK (pad);
3581 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3586 GST_OBJECT_UNLOCK (pad);
3587 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3590 case GST_FLOW_CUSTOM_SUCCESS:
3591 GST_DEBUG_OBJECT (pad, "dropped buffer");
3595 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
3602 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3603 "pushing, but it was not linked");
3604 GST_OBJECT_UNLOCK (pad);
3605 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3606 return GST_FLOW_NOT_LINKED;
3612 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3613 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
3616 * Pushes a buffer to the peer of @pad.
3618 * This function will call installed block probes before triggering any
3619 * installed data probes.
3621 * The function proceeds calling gst_pad_chain() on the peer pad and returns
3622 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3625 * In all cases, success or failure, the caller loses its reference to @buffer
3626 * after calling this function.
3628 * Returns: a #GstFlowReturn from the peer pad.
3633 gst_pad_push (GstPad * pad, GstBuffer * buffer)
3635 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3636 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3637 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3639 return gst_pad_push_data (pad,
3640 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3644 * gst_pad_push_list:
3645 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3646 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
3649 * Pushes a buffer list to the peer of @pad.
3651 * This function will call installed block probes before triggering any
3652 * installed data probes.
3654 * The function proceeds calling the chain function on the peer pad and returns
3655 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3656 * be returned. If the peer pad does not have any installed chainlist function
3657 * every group buffer of the list will be merged into a normal #GstBuffer and
3658 * chained via gst_pad_chain().
3660 * In all cases, success or failure, the caller loses its reference to @list
3661 * after calling this function.
3663 * Returns: a #GstFlowReturn from the peer pad.
3670 gst_pad_push_list (GstPad * pad, GstBufferList * list)
3672 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3673 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3674 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3676 return gst_pad_push_data (pad,
3677 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3680 static GstFlowReturn
3681 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
3682 GstBuffer ** buffer)
3685 GstPadGetRangeFunction getrangefunc;
3688 GST_PAD_STREAM_LOCK (pad);
3690 GST_OBJECT_LOCK (pad);
3691 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3694 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
3697 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3698 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3700 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3703 events_foreach (pad, push_sticky, &ret);
3704 if (ret != GST_FLOW_OK)
3708 /* when one of the probes returns a buffer, probed_data will be called and we
3709 * skip calling the getrange function */
3710 PROBE_PRE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
3711 *buffer, offset, size, probe_stopped, probed_data, GST_FLOW_OK);
3713 ACQUIRE_PARENT (pad, parent, no_parent);
3714 GST_OBJECT_UNLOCK (pad);
3716 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
3719 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3720 "calling getrangefunc %s, offset %"
3721 G_GUINT64_FORMAT ", size %u",
3722 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
3724 ret = getrangefunc (pad, parent, offset, size, buffer);
3726 RELEASE_PARENT (parent);
3728 if (G_UNLIKELY (ret != GST_FLOW_OK))
3729 goto get_range_failed;
3731 /* can only fire the signal if we have a valid buffer */
3732 GST_OBJECT_LOCK (pad);
3734 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
3735 *buffer, offset, size, probe_stopped_unref);
3736 GST_OBJECT_UNLOCK (pad);
3738 GST_PAD_STREAM_UNLOCK (pad);
3745 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3746 "getrange, but pad was flushing");
3747 GST_OBJECT_UNLOCK (pad);
3748 GST_PAD_STREAM_UNLOCK (pad);
3749 return GST_FLOW_FLUSHING;
3753 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
3754 GST_DEBUG_PAD_NAME (pad));
3755 GST_OBJECT_UNLOCK (pad);
3756 GST_PAD_STREAM_UNLOCK (pad);
3757 return GST_FLOW_ERROR;
3761 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
3762 GST_OBJECT_UNLOCK (pad);
3763 GST_PAD_STREAM_UNLOCK (pad);
3768 GST_DEBUG_OBJECT (pad, "no parent");
3769 GST_OBJECT_UNLOCK (pad);
3770 GST_PAD_STREAM_UNLOCK (pad);
3771 return GST_FLOW_FLUSHING;
3775 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
3776 GST_DEBUG_PAD_NAME (pad));
3777 RELEASE_PARENT (parent);
3778 GST_PAD_STREAM_UNLOCK (pad);
3779 return GST_FLOW_NOT_SUPPORTED;
3783 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3784 "probe returned %s", gst_flow_get_name (ret));
3785 GST_OBJECT_UNLOCK (pad);
3786 GST_PAD_STREAM_UNLOCK (pad);
3789 probe_stopped_unref:
3791 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3792 "probe returned %s", gst_flow_get_name (ret));
3793 GST_OBJECT_UNLOCK (pad);
3794 GST_PAD_STREAM_UNLOCK (pad);
3795 gst_buffer_unref (*buffer);
3801 GST_PAD_STREAM_UNLOCK (pad);
3803 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
3804 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
3805 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
3811 * gst_pad_get_range:
3812 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
3813 * @offset: The start offset of the buffer
3814 * @size: The length of the buffer
3815 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
3816 * returns #GST_FLOW_ERROR if %NULL.
3818 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
3819 * immediately and @buffer is %NULL.
3821 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
3822 * description of a getrange function. If @pad has no getrange function
3823 * installed (see gst_pad_set_getrange_function()) this function returns
3824 * #GST_FLOW_NOT_SUPPORTED.
3826 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
3828 * Returns: a #GstFlowReturn from the pad.
3833 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
3834 GstBuffer ** buffer)
3836 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3837 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3838 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3840 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
3844 * gst_pad_pull_range:
3845 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3846 * @offset: The start offset of the buffer
3847 * @size: The length of the buffer
3848 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
3849 * GST_FLOW_ERROR if %NULL.
3851 * Pulls a @buffer from the peer pad.
3853 * This function will first trigger the pad block signal if it was
3856 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
3857 * function returns the result of gst_pad_get_range() on the peer pad.
3858 * See gst_pad_get_range() for a list of return values and for the
3859 * semantics of the arguments of this function.
3861 * Returns: a #GstFlowReturn from the peer pad.
3862 * When this function returns #GST_FLOW_OK, @buffer will contain a valid
3863 * #GstBuffer that should be freed with gst_buffer_unref() after usage.
3864 * @buffer may not be used or freed when any other return value than
3865 * #GST_FLOW_OK is returned.
3870 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
3871 GstBuffer ** buffer)
3876 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3877 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3878 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3880 GST_OBJECT_LOCK (pad);
3881 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3884 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
3887 /* when one of the probes returns a buffer, probed_data will be called and we
3888 * skip calling the peer getrange function */
3889 PROBE_PRE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
3890 *buffer, offset, size, pre_probe_stopped, probed_data, GST_FLOW_OK);
3892 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3895 gst_object_ref (peer);
3897 GST_OBJECT_UNLOCK (pad);
3899 ret = gst_pad_get_range_unchecked (peer, offset, size, buffer);
3901 gst_object_unref (peer);
3903 GST_OBJECT_LOCK (pad);
3905 if (pad->priv->using == 0) {
3906 /* pad is not active anymore, trigger idle callbacks */
3907 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
3908 post_probe_stopped, ret);
3911 if (G_UNLIKELY (ret != GST_FLOW_OK))
3912 goto pull_range_failed;
3915 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
3916 *buffer, offset, size, post_probe_stopped);
3918 GST_OBJECT_UNLOCK (pad);
3922 /* ERROR recovery here */
3925 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3926 "pullrange, but pad was flushing");
3927 GST_OBJECT_UNLOCK (pad);
3928 return GST_FLOW_FLUSHING;
3932 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
3933 GST_DEBUG_PAD_NAME (pad));
3934 GST_OBJECT_UNLOCK (pad);
3935 return GST_FLOW_ERROR;
3939 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
3940 gst_flow_get_name (ret));
3941 GST_OBJECT_UNLOCK (pad);
3946 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3947 "pulling range, but it was not linked");
3948 GST_OBJECT_UNLOCK (pad);
3949 return GST_FLOW_NOT_LINKED;
3954 GST_OBJECT_UNLOCK (pad);
3955 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
3956 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
3957 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
3962 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3963 "post probe returned %s", gst_flow_get_name (ret));
3964 GST_OBJECT_UNLOCK (pad);
3965 if (ret == GST_FLOW_OK)
3966 gst_buffer_unref (*buffer);
3973 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event, gboolean locked)
3978 gboolean res = FALSE;
3979 const gchar *name = NULL;
3981 type = GST_EVENT_TYPE (event);
3982 if (type & GST_EVENT_TYPE_STICKY_MULTI)
3983 name = gst_structure_get_name (gst_event_get_structure (event));
3985 events = pad->priv->events;
3988 for (i = 0; i < len; i++) {
3989 PadEvent *ev = &g_array_index (events, PadEvent, i);
3991 if (ev->event == NULL)
3994 if (type == GST_EVENT_TYPE (ev->event)) {
3995 /* matching types, check matching name if needed */
3996 if (name && !gst_event_has_name (ev->event, name))
4000 if ((res = gst_event_replace (&ev->event, event)))
4001 ev->received = FALSE;
4007 ev.event = gst_event_ref (event);
4008 ev.received = FALSE;
4009 g_array_append_val (events, ev);
4014 pad->priv->events_cookie++;
4015 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4017 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4019 switch (GST_EVENT_TYPE (event)) {
4020 case GST_EVENT_CAPS:
4022 GST_OBJECT_UNLOCK (pad);
4024 GST_DEBUG_OBJECT (pad, "notify caps");
4025 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4028 GST_OBJECT_LOCK (pad);
4037 static GstFlowReturn
4038 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4039 GstPadProbeType type, gboolean * stored)
4043 GstEventType event_type;
4046 sticky = GST_EVENT_IS_STICKY (event);
4048 GST_OBJECT_LOCK (pad);
4050 /* Two checks to be made:
4051 * . (un)set the FLUSHING flag for flushing events,
4052 * . handle pad blocking */
4053 event_type = GST_EVENT_TYPE (event);
4055 switch (event_type) {
4056 case GST_EVENT_FLUSH_START:
4057 GST_PAD_SET_FLUSHING (pad);
4059 GST_PAD_BLOCK_BROADCAST (pad);
4060 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4062 case GST_EVENT_FLUSH_STOP:
4063 GST_PAD_UNSET_FLUSHING (pad);
4065 /* Remove sticky EOS events */
4066 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4067 remove_event_by_type (pad, GST_EVENT_EOS);
4069 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4073 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4076 /* store the event on the pad, but only on srcpads. We always store the
4077 * event exactly how it was sent */
4079 /* srcpad sticky events are store immediately, the received flag is set
4080 * to FALSE and will be set to TRUE when we can successfully push the
4081 * event to the peer pad */
4082 if (gst_pad_store_sticky_event (pad, event, TRUE)) {
4083 GST_DEBUG_OBJECT (pad, "event %s updated",
4084 GST_EVENT_TYPE_NAME (event));
4089 switch (GST_EVENT_TYPE (event)) {
4090 case GST_EVENT_SEGMENT:
4091 /* pass the adjusted segment event on. We need to do this even if
4092 * there is no peer pad because of the probes. */
4093 event = apply_pad_offset (pad, event);
4095 case GST_EVENT_RECONFIGURE:
4096 if (GST_PAD_IS_SINK (pad))
4097 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4102 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4103 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4108 /* send probes after modifying the events above */
4109 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4111 /* now check the peer pad */
4112 peerpad = GST_PAD_PEER (pad);
4113 if (peerpad == NULL)
4116 gst_object_ref (peerpad);
4118 GST_OBJECT_UNLOCK (pad);
4120 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4121 event, GST_EVENT_TYPE_NAME (event), peerpad);
4123 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4125 /* Note: we gave away ownership of the event at this point but we can still
4126 * print the old pointer */
4127 GST_LOG_OBJECT (pad,
4128 "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s", event, peerpad,
4129 gst_flow_get_name (ret));
4131 gst_object_unref (peerpad);
4133 GST_OBJECT_LOCK (pad);
4135 if (ret == GST_FLOW_OK) {
4138 if ((ev = find_event (pad, event)))
4139 ev->received = TRUE;
4141 GST_DEBUG_OBJECT (pad, "event marked received");
4143 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4144 GST_DEBUG_OBJECT (pad, "mark pending events");
4148 if (pad->priv->using == 0) {
4149 /* pad is not active anymore, trigger idle callbacks */
4150 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4151 idle_probe_stopped, ret);
4153 GST_OBJECT_UNLOCK (pad);
4157 /* ERROR handling */
4160 GST_DEBUG_OBJECT (pad, "We're flushing");
4161 GST_OBJECT_UNLOCK (pad);
4162 gst_event_unref (event);
4163 return GST_FLOW_FLUSHING;
4167 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4168 GST_OBJECT_UNLOCK (pad);
4169 gst_event_unref (event);
4172 case GST_FLOW_CUSTOM_SUCCESS:
4173 GST_DEBUG_OBJECT (pad, "dropped event");
4177 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4184 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4185 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4186 GST_OBJECT_UNLOCK (pad);
4187 gst_event_unref (event);
4188 return sticky ? GST_FLOW_OK : GST_FLOW_NOT_LINKED;
4192 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4193 GST_OBJECT_UNLOCK (pad);
4199 * gst_pad_push_event:
4200 * @pad: a #GstPad to push the event to.
4201 * @event: (transfer full): the #GstEvent to send to the pad.
4203 * Sends the event to the peer of the given pad. This function is
4204 * mainly used by elements to send events to their peer
4207 * This function takes owership of the provided event so you should
4208 * gst_event_ref() it if you want to reuse the event after this call.
4210 * Returns: TRUE if the event was handled.
4215 gst_pad_push_event (GstPad * pad, GstEvent * event)
4218 GstPadProbeType type;
4221 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4222 g_return_val_if_fail (event != NULL, FALSE);
4223 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4225 if (GST_PAD_IS_SRC (pad)) {
4226 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4227 goto wrong_direction;
4228 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4229 } else if (GST_PAD_IS_SINK (pad)) {
4230 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4231 goto wrong_direction;
4232 /* events pushed on sinkpad never are sticky */
4233 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4235 goto unknown_direction;
4237 if (gst_pad_push_event_unchecked (pad, event, type, &stored) != GST_FLOW_OK)
4238 res = stored ? TRUE : FALSE;
4244 /* ERROR handling */
4247 g_warning ("pad %s:%s pushing %s event in wrong direction",
4248 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4249 gst_event_unref (event);
4254 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4255 gst_event_unref (event);
4260 /* Check if we can call the event function with the given event */
4261 static GstFlowReturn
4262 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4264 GstCaps *caps, *templ;
4266 switch (GST_EVENT_TYPE (event)) {
4267 case GST_EVENT_CAPS:
4269 /* backwards compatibility mode for caps */
4270 gst_event_parse_caps (event, &caps);
4272 /* See if pad accepts the caps */
4273 templ = gst_pad_get_pad_template_caps (pad);
4274 if (!gst_caps_is_subset (caps, templ))
4277 gst_caps_unref (templ);
4288 gst_caps_unref (templ);
4289 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4290 "caps %" GST_PTR_FORMAT " not accepted", caps);
4291 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4292 "no intersection with template %" GST_PTR_FORMAT, templ);
4293 return GST_FLOW_NOT_NEGOTIATED;
4297 static GstFlowReturn
4298 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4299 GstPadProbeType type)
4302 GstEventType event_type;
4303 gboolean serialized, need_unlock = FALSE, sticky;
4304 GstPadEventFunction eventfunc;
4307 GST_OBJECT_LOCK (pad);
4308 if (GST_PAD_IS_SINK (pad))
4309 serialized = GST_EVENT_IS_SERIALIZED (event);
4312 sticky = GST_EVENT_IS_STICKY (event);
4313 event_type = GST_EVENT_TYPE (event);
4314 switch (event_type) {
4315 case GST_EVENT_FLUSH_START:
4316 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4317 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4319 /* can't even accept a flush begin event when flushing */
4320 if (GST_PAD_IS_FLUSHING (pad))
4323 GST_PAD_SET_FLUSHING (pad);
4324 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4326 case GST_EVENT_FLUSH_STOP:
4327 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4328 GST_PAD_UNSET_FLUSHING (pad);
4329 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4331 /* Remove pending EOS events */
4332 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4333 remove_event_by_type (pad, GST_EVENT_EOS);
4335 GST_OBJECT_UNLOCK (pad);
4336 /* grab stream lock */
4337 GST_PAD_STREAM_LOCK (pad);
4339 GST_OBJECT_LOCK (pad);
4340 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4343 case GST_EVENT_RECONFIGURE:
4344 if (GST_PAD_IS_SRC (pad))
4345 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4347 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4348 "have event type %" GST_PTR_FORMAT, event);
4350 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4354 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4355 GST_OBJECT_UNLOCK (pad);
4356 GST_PAD_STREAM_LOCK (pad);
4358 GST_OBJECT_LOCK (pad);
4359 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4363 switch (GST_EVENT_TYPE (event)) {
4364 case GST_EVENT_SEGMENT:
4365 event = apply_pad_offset (pad, event);
4371 /* now do the probe */
4373 type | GST_PAD_PROBE_TYPE_PUSH |
4374 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4376 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4380 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4383 ACQUIRE_PARENT (pad, parent, no_parent);
4384 GST_OBJECT_UNLOCK (pad);
4386 ret = pre_eventfunc_check (pad, event);
4387 if (G_UNLIKELY (ret != GST_FLOW_OK))
4388 goto precheck_failed;
4391 gst_event_ref (event);
4393 if (eventfunc (pad, parent, event)) {
4396 /* something went wrong */
4397 switch (event_type) {
4398 case GST_EVENT_CAPS:
4399 ret = GST_FLOW_NOT_NEGOTIATED;
4402 ret = GST_FLOW_ERROR;
4406 RELEASE_PARENT (parent);
4408 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
4411 if (ret == GST_FLOW_OK) {
4412 /* after the event function accepted the event, we can store the sticky
4413 * event on the pad */
4414 gst_pad_store_sticky_event (pad, event, FALSE);
4416 gst_event_unref (event);
4420 GST_PAD_STREAM_UNLOCK (pad);
4424 /* ERROR handling */
4427 GST_OBJECT_UNLOCK (pad);
4429 GST_PAD_STREAM_UNLOCK (pad);
4430 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
4431 "Received event on flushing pad. Discarding");
4432 gst_event_unref (event);
4433 return GST_FLOW_FLUSHING;
4437 GST_OBJECT_UNLOCK (pad);
4439 GST_PAD_STREAM_UNLOCK (pad);
4440 gst_event_unref (event);
4443 case GST_FLOW_CUSTOM_SUCCESS:
4444 GST_DEBUG_OBJECT (pad, "dropped event");
4448 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4455 g_warning ("pad %s:%s has no event handler, file a bug.",
4456 GST_DEBUG_PAD_NAME (pad));
4457 GST_OBJECT_UNLOCK (pad);
4459 GST_PAD_STREAM_UNLOCK (pad);
4460 gst_event_unref (event);
4461 return GST_FLOW_NOT_SUPPORTED;
4465 GST_DEBUG_OBJECT (pad, "no parent");
4466 GST_OBJECT_UNLOCK (pad);
4468 GST_PAD_STREAM_UNLOCK (pad);
4469 gst_event_unref (event);
4470 return GST_FLOW_FLUSHING;
4474 GST_DEBUG_OBJECT (pad, "pre event check failed");
4475 RELEASE_PARENT (parent);
4477 GST_PAD_STREAM_UNLOCK (pad);
4478 gst_event_unref (event);
4484 * gst_pad_send_event:
4485 * @pad: a #GstPad to send the event to.
4486 * @event: (transfer full): the #GstEvent to send to the pad.
4488 * Sends the event to the pad. This function can be used
4489 * by applications to send events in the pipeline.
4491 * If @pad is a source pad, @event should be an upstream event. If @pad is a
4492 * sink pad, @event should be a downstream event. For example, you would not
4493 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
4494 * Furthermore, some downstream events have to be serialized with data flow,
4495 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
4496 * the event needs to be serialized with data flow, this function will take the
4497 * pad's stream lock while calling its event function.
4499 * To find out whether an event type is upstream, downstream, or downstream and
4500 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
4501 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
4502 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
4503 * plugin doesn't need to bother itself with this information; the core handles
4504 * all necessary locks and checks.
4506 * This function takes owership of the provided event so you should
4507 * gst_event_ref() it if you want to reuse the event after this call.
4509 * Returns: TRUE if the event was handled.
4512 gst_pad_send_event (GstPad * pad, GstEvent * event)
4515 GstPadProbeType type;
4517 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4518 g_return_val_if_fail (event != NULL, FALSE);
4520 if (GST_PAD_IS_SINK (pad)) {
4521 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4522 goto wrong_direction;
4523 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4524 } else if (GST_PAD_IS_SRC (pad)) {
4525 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4526 goto wrong_direction;
4527 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4529 goto unknown_direction;
4531 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
4538 /* ERROR handling */
4541 g_warning ("pad %s:%s sending %s event in wrong direction",
4542 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4543 gst_event_unref (event);
4548 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4549 gst_event_unref (event);
4555 * gst_pad_set_element_private:
4556 * @pad: the #GstPad to set the private data of.
4557 * @priv: The private data to attach to the pad.
4559 * Set the given private data gpointer on the pad.
4560 * This function can only be used by the element that owns the pad.
4561 * No locking is performed in this function.
4564 gst_pad_set_element_private (GstPad * pad, gpointer priv)
4566 pad->element_private = priv;
4570 * gst_pad_get_element_private:
4571 * @pad: the #GstPad to get the private data of.
4573 * Gets the private data of a pad.
4574 * No locking is performed in this function.
4576 * Returns: (transfer none): a #gpointer to the private data.
4579 gst_pad_get_element_private (GstPad * pad)
4581 return pad->element_private;
4585 * gst_pad_get_sticky_event:
4586 * @pad: the #GstPad to get the event from.
4587 * @event_type: the #GstEventType that should be retrieved.
4588 * @idx: the index of the event
4590 * Returns a new reference of the sticky event of type @event_type
4593 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
4594 * event of @event_type was on @pad. Unref after usage.
4597 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
4599 GstEvent *event = NULL;
4602 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4603 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
4605 GST_OBJECT_LOCK (pad);
4606 ev = find_event_by_type (pad, event_type, idx);
4607 if (ev && (event = ev->event))
4608 gst_event_ref (event);
4609 GST_OBJECT_UNLOCK (pad);
4616 GstPadStickyEventsForeachFunction func;
4621 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
4623 ForeachDispatch *data = user_data;
4626 GST_OBJECT_UNLOCK (pad);
4628 ret = data->func (pad, &ev->event, data->user_data);
4630 GST_OBJECT_LOCK (pad);
4636 * gst_pad_sticky_events_foreach:
4637 * @pad: the #GstPad that should be used for iteration.
4638 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
4639 * should be called for every event.
4640 * @user_data: (closure): the optional user data.
4642 * Iterates all sticky events on @pad and calls @foreach_func for every
4643 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
4646 gst_pad_sticky_events_foreach (GstPad * pad,
4647 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
4649 ForeachDispatch data;
4651 g_return_if_fail (GST_IS_PAD (pad));
4652 g_return_if_fail (foreach_func != NULL);
4654 data.func = foreach_func;
4655 data.user_data = user_data;
4657 GST_OBJECT_LOCK (pad);
4658 events_foreach (pad, foreach_dispatch_function, &data);
4659 GST_OBJECT_UNLOCK (pad);
4663 do_stream_status (GstPad * pad, GstStreamStatusType type,
4664 GThread * thread, GstTask * task)
4668 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
4670 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
4671 if (GST_IS_ELEMENT (parent)) {
4672 GstMessage *message;
4673 GValue value = { 0 };
4675 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
4676 gchar *tname, *ename, *pname;
4678 /* create a good task name */
4679 ename = gst_element_get_name (parent);
4680 pname = gst_pad_get_name (pad);
4681 tname = g_strdup_printf ("%s:%s", ename, pname);
4685 gst_object_set_name (GST_OBJECT_CAST (task), tname);
4689 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
4692 g_value_init (&value, GST_TYPE_TASK);
4693 g_value_set_object (&value, task);
4694 gst_message_set_stream_status_object (message, &value);
4695 g_value_unset (&value);
4697 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
4698 gst_element_post_message (parent, message);
4700 gst_object_unref (parent);
4705 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
4707 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
4712 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
4714 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
4718 static GstTaskThreadCallbacks thr_callbacks = {
4724 * gst_pad_start_task:
4725 * @pad: the #GstPad to start the task of
4726 * @func: the task function to call
4727 * @data: data passed to the task function
4729 * Starts a task that repeatedly calls @func with @data. This function
4730 * is mostly used in pad activation functions to start the dataflow.
4731 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
4732 * before @func is called.
4734 * Returns: a %TRUE if the task could be started.
4737 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
4742 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4743 g_return_val_if_fail (func != NULL, FALSE);
4745 GST_DEBUG_OBJECT (pad, "start task");
4747 GST_OBJECT_LOCK (pad);
4748 task = GST_PAD_TASK (pad);
4750 task = gst_task_new (func, data);
4751 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
4752 gst_task_set_thread_callbacks (task, &thr_callbacks, pad, NULL);
4753 GST_DEBUG_OBJECT (pad, "created task");
4754 GST_PAD_TASK (pad) = task;
4755 gst_object_ref (task);
4756 /* release lock to post the message */
4757 GST_OBJECT_UNLOCK (pad);
4759 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
4761 gst_object_unref (task);
4763 GST_OBJECT_LOCK (pad);
4764 /* nobody else is supposed to have changed the pad now */
4765 if (GST_PAD_TASK (pad) != task)
4766 goto concurrent_stop;
4768 res = gst_task_set_state (task, GST_TASK_STARTED);
4769 GST_OBJECT_UNLOCK (pad);
4776 GST_OBJECT_UNLOCK (pad);
4782 * gst_pad_pause_task:
4783 * @pad: the #GstPad to pause the task of
4785 * Pause the task of @pad. This function will also wait until the
4786 * function executed by the task is finished if this function is not
4787 * called from the task function.
4789 * Returns: a TRUE if the task could be paused or FALSE when the pad
4793 gst_pad_pause_task (GstPad * pad)
4798 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4800 GST_DEBUG_OBJECT (pad, "pause task");
4802 GST_OBJECT_LOCK (pad);
4803 task = GST_PAD_TASK (pad);
4806 res = gst_task_set_state (task, GST_TASK_PAUSED);
4807 GST_OBJECT_UNLOCK (pad);
4809 /* wait for task function to finish, this lock is recursive so it does nothing
4810 * when the pause is called from the task itself */
4811 GST_PAD_STREAM_LOCK (pad);
4812 GST_PAD_STREAM_UNLOCK (pad);
4818 GST_DEBUG_OBJECT (pad, "pad has no task");
4819 GST_OBJECT_UNLOCK (pad);
4825 * gst_pad_stop_task:
4826 * @pad: the #GstPad to stop the task of
4828 * Stop the task of @pad. This function will also make sure that the
4829 * function executed by the task will effectively stop if not called
4830 * from the GstTaskFunction.
4832 * This function will deadlock if called from the GstTaskFunction of
4833 * the task. Use gst_task_pause() instead.
4835 * Regardless of whether the pad has a task, the stream lock is acquired and
4836 * released so as to ensure that streaming through this pad has finished.
4838 * Returns: a TRUE if the task could be stopped or FALSE on error.
4841 gst_pad_stop_task (GstPad * pad)
4846 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4848 GST_DEBUG_OBJECT (pad, "stop task");
4850 GST_OBJECT_LOCK (pad);
4851 task = GST_PAD_TASK (pad);
4854 GST_PAD_TASK (pad) = NULL;
4855 res = gst_task_set_state (task, GST_TASK_STOPPED);
4856 GST_OBJECT_UNLOCK (pad);
4858 GST_PAD_STREAM_LOCK (pad);
4859 GST_PAD_STREAM_UNLOCK (pad);
4861 if (!gst_task_join (task))
4864 gst_object_unref (task);
4870 GST_DEBUG_OBJECT (pad, "no task");
4871 GST_OBJECT_UNLOCK (pad);
4873 GST_PAD_STREAM_LOCK (pad);
4874 GST_PAD_STREAM_UNLOCK (pad);
4876 /* this is not an error */
4881 /* this is bad, possibly the application tried to join the task from
4882 * the task's thread. We install the task again so that it will be stopped
4883 * again from the right thread next time hopefully. */
4884 GST_OBJECT_LOCK (pad);
4885 GST_DEBUG_OBJECT (pad, "join failed");
4886 /* we can only install this task if there was no other task */
4887 if (GST_PAD_TASK (pad) == NULL)
4888 GST_PAD_TASK (pad) = task;
4889 GST_OBJECT_UNLOCK (pad);