2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 * @short_description: Object contained by elements that allows links to
26 * @see_also: #GstPadTemplate, #GstElement, #GstEvent, #GstQuery, #GstBuffer
28 * A #GstElement is linked to other elements via "pads", which are extremely
29 * light-weight generic link points.
31 * Pads have a #GstPadDirection, source pads produce data, sink pads consume
34 * Pads are typically created from a #GstPadTemplate with
35 * gst_pad_new_from_template() and are then added to a #GstElement. This usually
36 * happens when the element is created but it can also happen dynamically based
37 * on the data that the element is processing or based on the pads that the
38 * application requests.
40 * Pads without pad templates can be created with gst_pad_new(),
41 * which takes a direction and a name as an argument. If the name is NULL,
42 * then a guaranteed unique name will be assigned to it.
44 * A #GstElement creating a pad will typically use the various
45 * gst_pad_set_*_function() calls to register callbacks for events, queries or
46 * dataflow on the pads.
48 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
50 * After two pads are retrieved from an element by gst_element_get_static_pad(),
51 * the pads can be linked with gst_pad_link(). (For quick links,
52 * you can also use gst_element_link(), which will make the obvious
53 * link for you if it's straightforward.). Pads can be unlinked again with
54 * gst_pad_unlink(). gst_pad_get_peer() can be used to check what the pad is
57 * Before dataflow is possible on the pads, they need to be activated with
58 * gst_pad_set_active().
60 * gst_pad_query() and gst_pad_peer_query() can be used to query various
61 * properties of the pad and the stream.
63 * To send a #GstEvent on a pad, use gst_pad_send_event() and
64 * gst_pad_push_event(). Some events will be sticky on the pad, meaning that
65 * after they pass on the pad they can be queried later with
66 * gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().
67 * gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience
68 * functions to query the current sticky CAPS event on a pad.
70 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
71 * or pull in a buffer.
73 * The dataflow, events and queries that happen on a pad can be monitored with
74 * probes that can be installed with gst_pad_add_probe(). gst_pad_is_blocked()
75 * can be used to check if a block probe is installed on the pad.
76 * gst_pad_is_blocking() checks if the blocking probe is currently blocking the
77 * pad. gst_pad_remove_probe() is used to remove a previously installed probe
78 * and unblock blocking probes if any.
80 * Pad have an offset that can be retrieved with gst_pad_get_offset(). This
81 * offset will be applied to the running_time of all data passing over the pad.
82 * gst_pad_set_offset() can be used to change the offset.
84 * Convenience functions exist to start, pause and stop the task on a pad with
85 * gst_pad_start_task(), gst_pad_pause_task() and gst_pad_stop_task()
88 * Last reviewed on 2012-03-29 (0.11.3)
91 #include "gst_private.h"
94 #include "gstpadtemplate.h"
95 #include "gstenumtypes.h"
100 #include "glib-compat-private.h"
102 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
103 #define GST_CAT_DEFAULT GST_CAT_PADS
105 /* Pad signals and args */
123 #define GST_PAD_GET_PRIVATE(obj) \
124 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
126 /* we have a pending and an active event on the pad. On source pads only the
127 * active event is used. On sinkpads, events are copied to the pending entry and
128 * moved to the active event when the eventfunc returned TRUE. */
135 struct _GstPadPrivate
142 guint probe_list_cookie;
152 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
157 GstPadProbeInfo *info;
164 static void gst_pad_dispose (GObject * object);
165 static void gst_pad_finalize (GObject * object);
166 static void gst_pad_set_property (GObject * object, guint prop_id,
167 const GValue * value, GParamSpec * pspec);
168 static void gst_pad_get_property (GObject * object, guint prop_id,
169 GValue * value, GParamSpec * pspec);
171 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
172 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
173 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
174 GstObject * parent, GstBufferList * list);
176 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
177 GstEvent * event, GstPadProbeType type);
178 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
179 GstEvent * event, GstPadProbeType type);
181 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
183 static GParamSpec *pspec_caps = NULL;
185 /* quarks for probe signals */
186 static GQuark buffer_quark;
187 static GQuark buffer_list_quark;
188 static GQuark event_quark;
197 static GstFlowQuarks flow_quarks[] = {
198 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
199 {GST_FLOW_OK, "ok", 0},
200 {GST_FLOW_NOT_LINKED, "not-linked", 0},
201 {GST_FLOW_FLUSHING, "flushing", 0},
202 {GST_FLOW_EOS, "eos", 0},
203 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
204 {GST_FLOW_ERROR, "error", 0},
205 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
206 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
211 * @ret: a #GstFlowReturn to get the name of.
213 * Gets a string representing the given flow return.
215 * Returns: a static string with the name of the flow return.
218 gst_flow_get_name (GstFlowReturn ret)
222 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
224 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
225 if (ret == flow_quarks[i].ret)
226 return flow_quarks[i].name;
233 * @ret: a #GstFlowReturn to get the quark of.
235 * Get the unique quark for the given GstFlowReturn.
237 * Returns: the quark associated with the flow return or 0 if an
238 * invalid return was specified.
241 gst_flow_to_quark (GstFlowReturn ret)
245 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
247 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
248 if (ret == flow_quarks[i].ret)
249 return flow_quarks[i].quark;
258 buffer_quark = g_quark_from_static_string ("buffer"); \
259 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
260 event_quark = g_quark_from_static_string ("event"); \
262 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
263 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
266 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
267 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
270 #define gst_pad_parent_class parent_class
271 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
274 gst_pad_class_init (GstPadClass * klass)
276 GObjectClass *gobject_class;
277 GstObjectClass *gstobject_class;
279 gobject_class = G_OBJECT_CLASS (klass);
280 gstobject_class = GST_OBJECT_CLASS (klass);
282 g_type_class_add_private (klass, sizeof (GstPadPrivate));
284 gobject_class->dispose = gst_pad_dispose;
285 gobject_class->finalize = gst_pad_finalize;
286 gobject_class->set_property = gst_pad_set_property;
287 gobject_class->get_property = gst_pad_get_property;
291 * @pad: the pad that emitted the signal
292 * @peer: the peer pad that has been connected
294 * Signals that a pad has been linked to the peer pad.
296 gst_pad_signals[PAD_LINKED] =
297 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
298 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
299 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
302 * @pad: the pad that emitted the signal
303 * @peer: the peer pad that has been disconnected
305 * Signals that a pad has been unlinked from the peer pad.
307 gst_pad_signals[PAD_UNLINKED] =
308 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
309 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
310 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
312 pspec_caps = g_param_spec_boxed ("caps", "Caps",
313 "The capabilities of the pad", GST_TYPE_CAPS,
314 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
315 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
317 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
318 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
319 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
320 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
322 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
323 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
324 g_param_spec_object ("template", "Template",
325 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
326 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
328 gstobject_class->path_string_separator = ".";
330 /* Register common function pointer descriptions */
331 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
332 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
333 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
334 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
335 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
339 gst_pad_init (GstPad * pad)
341 pad->priv = GST_PAD_GET_PRIVATE (pad);
343 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
345 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
346 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
347 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
348 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
349 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
351 GST_PAD_SET_FLUSHING (pad);
353 g_rec_mutex_init (&pad->stream_rec_lock);
355 g_cond_init (&pad->block_cond);
357 g_hook_list_init (&pad->probes, sizeof (GstProbe));
359 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
360 pad->priv->events_cookie = 0;
361 pad->priv->last_cookie = -1;
364 /* called when setting the pad inactive. It removes all sticky events from
365 * the pad. must be called with object lock */
367 remove_events (GstPad * pad)
372 events = pad->priv->events;
375 for (i = 0; i < len; i++) {
376 PadEvent *ev = &g_array_index (events, PadEvent, i);
377 GstEvent *event = ev->event;
381 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS) {
382 GST_OBJECT_UNLOCK (pad);
384 GST_DEBUG_OBJECT (pad, "notify caps");
385 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
387 GST_OBJECT_LOCK (pad);
389 gst_event_unref (event);
391 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
392 g_array_set_size (events, 0);
393 pad->priv->events_cookie++;
396 /* should be called with object lock */
398 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
404 events = pad->priv->events;
407 for (i = 0; i < len; i++) {
408 ev = &g_array_index (events, PadEvent, i);
409 if (ev->event == NULL)
412 if (GST_EVENT_TYPE (ev->event) == type) {
423 /* should be called with OBJECT lock */
425 find_event (GstPad * pad, GstEvent * event)
431 events = pad->priv->events;
434 for (i = 0; i < len; i++) {
435 ev = &g_array_index (events, PadEvent, i);
436 if (event == ev->event)
444 /* should be called with OBJECT lock */
446 remove_event_by_type (GstPad * pad, GstEventType type)
452 events = pad->priv->events;
457 ev = &g_array_index (events, PadEvent, i);
458 if (ev->event == NULL)
461 if (GST_EVENT_TYPE (ev->event) != type)
464 gst_event_unref (ev->event);
465 g_array_remove_index (events, i);
467 pad->priv->events_cookie++;
475 /* check all events on srcpad against those on sinkpad. All events that are not
476 * on sinkpad are marked as received=FALSE and the PENDING_EVENTS is set on the
477 * srcpad so that the events will be sent next time */
478 /* should be called with srcpad and sinkpad LOCKS */
480 schedule_events (GstPad * srcpad, GstPad * sinkpad)
485 gboolean pending = FALSE;
487 events = srcpad->priv->events;
490 for (i = 0; i < len; i++) {
491 ev = &g_array_index (events, PadEvent, i);
492 if (ev->event == NULL)
495 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
496 ev->received = FALSE;
501 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
504 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
507 /* should be called with pad LOCK */
509 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
516 events = pad->priv->events;
519 cookie = pad->priv->events_cookie;
523 PadEvent *ev, ev_ret;
525 ev = &g_array_index (events, PadEvent, i);
526 if (G_UNLIKELY (ev->event == NULL))
529 /* take aditional ref, func might release the lock */
530 ev_ret.event = gst_event_ref (ev->event);
531 ev_ret.received = ev->received;
533 ret = func (pad, &ev_ret, user_data);
535 /* recheck the cookie, lock might have been released and the list could have
537 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
538 if (G_LIKELY (ev_ret.event))
539 gst_event_unref (ev_ret.event);
543 /* store the received state */
544 ev->received = ev_ret.received;
546 /* if the event changed, we need to do something */
547 if (G_UNLIKELY (ev->event != ev_ret.event)) {
548 if (G_UNLIKELY (ev_ret.event == NULL)) {
549 /* function unreffed and set the event to NULL, remove it */
550 g_array_remove_index (events, i);
552 cookie = ++pad->priv->events_cookie;
555 /* function gave a new event for us */
556 gst_event_take (&ev->event, ev_ret.event);
559 /* just unref, nothing changed */
560 gst_event_unref (ev_ret.event);
569 /* should be called with LOCK */
571 apply_pad_offset (GstPad * pad, GstEvent * event)
573 /* check if we need to adjust the segment */
574 if (pad->offset != 0) {
577 /* copy segment values */
578 gst_event_copy_segment (event, &segment);
579 gst_event_unref (event);
581 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_TIME_FORMAT,
582 GST_TIME_ARGS (pad->offset));
583 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
584 event = gst_event_new_segment (&segment);
589 /* should be called with the OBJECT_LOCK */
591 get_pad_caps (GstPad * pad)
593 GstCaps *caps = NULL;
596 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
598 gst_event_parse_caps (ev->event, &caps);
604 gst_pad_dispose (GObject * object)
606 GstPad *pad = GST_PAD_CAST (object);
609 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
611 /* unlink the peer pad */
612 if ((peer = gst_pad_get_peer (pad))) {
613 /* window for MT unsafeness, someone else could unlink here
614 * and then we call unlink with wrong pads. The unlink
615 * function would catch this and safely return failed. */
616 if (GST_PAD_IS_SRC (pad))
617 gst_pad_unlink (pad, peer);
619 gst_pad_unlink (peer, pad);
621 gst_object_unref (peer);
624 gst_pad_set_pad_template (pad, NULL);
626 GST_OBJECT_LOCK (pad);
628 GST_OBJECT_UNLOCK (pad);
630 g_hook_list_clear (&pad->probes);
632 G_OBJECT_CLASS (parent_class)->dispose (object);
636 gst_pad_finalize (GObject * object)
638 GstPad *pad = GST_PAD_CAST (object);
641 /* in case the task is still around, clean it up */
642 if ((task = GST_PAD_TASK (pad))) {
643 gst_task_join (task);
644 GST_PAD_TASK (pad) = NULL;
645 gst_object_unref (task);
648 if (pad->activatenotify)
649 pad->activatenotify (pad->activatedata);
650 if (pad->activatemodenotify)
651 pad->activatemodenotify (pad->activatemodedata);
653 pad->linknotify (pad->linkdata);
654 if (pad->unlinknotify)
655 pad->unlinknotify (pad->unlinkdata);
656 if (pad->chainnotify)
657 pad->chainnotify (pad->chaindata);
658 if (pad->chainlistnotify)
659 pad->chainlistnotify (pad->chainlistdata);
660 if (pad->getrangenotify)
661 pad->getrangenotify (pad->getrangedata);
662 if (pad->eventnotify)
663 pad->eventnotify (pad->eventdata);
664 if (pad->querynotify)
665 pad->querynotify (pad->querydata);
666 if (pad->iterintlinknotify)
667 pad->iterintlinknotify (pad->iterintlinkdata);
669 g_rec_mutex_clear (&pad->stream_rec_lock);
670 g_cond_clear (&pad->block_cond);
671 g_array_free (pad->priv->events, TRUE);
673 G_OBJECT_CLASS (parent_class)->finalize (object);
677 gst_pad_set_property (GObject * object, guint prop_id,
678 const GValue * value, GParamSpec * pspec)
680 g_return_if_fail (GST_IS_PAD (object));
683 case PAD_PROP_DIRECTION:
684 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
686 case PAD_PROP_TEMPLATE:
687 gst_pad_set_pad_template (GST_PAD_CAST (object),
688 (GstPadTemplate *) g_value_get_object (value));
691 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
697 gst_pad_get_property (GObject * object, guint prop_id,
698 GValue * value, GParamSpec * pspec)
700 g_return_if_fail (GST_IS_PAD (object));
704 GST_OBJECT_LOCK (object);
705 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
706 GST_OBJECT_UNLOCK (object);
708 case PAD_PROP_DIRECTION:
709 g_value_set_enum (value, GST_PAD_DIRECTION (object));
711 case PAD_PROP_TEMPLATE:
712 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
715 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
722 * @name: the name of the new pad.
723 * @direction: the #GstPadDirection of the pad.
725 * Creates a new pad with the given name in the given direction.
726 * If name is NULL, a guaranteed unique name (across all pads)
728 * This function makes a copy of the name so you can safely free the name.
730 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
735 gst_pad_new (const gchar * name, GstPadDirection direction)
737 return g_object_new (GST_TYPE_PAD,
738 "name", name, "direction", direction, NULL);
742 * gst_pad_new_from_template:
743 * @templ: the pad template to use
744 * @name: the name of the element
746 * Creates a new pad with the given name from the given template.
747 * If name is NULL, a guaranteed unique name (across all pads)
749 * This function makes a copy of the name so you can safely free the name.
751 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
754 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
756 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
758 return g_object_new (GST_TYPE_PAD,
759 "name", name, "direction", templ->direction, "template", templ, NULL);
763 * gst_pad_new_from_static_template:
764 * @templ: the #GstStaticPadTemplate to use
765 * @name: the name of the element
767 * Creates a new pad with the given name from the given static template.
768 * If name is NULL, a guaranteed unique name (across all pads)
770 * This function makes a copy of the name so you can safely free the name.
772 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
775 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
779 GstPadTemplate *template;
781 template = gst_static_pad_template_get (templ);
782 pad = gst_pad_new_from_template (template, name);
783 gst_object_unref (template);
787 #define ACQUIRE_PARENT(pad, parent, label) \
789 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
790 gst_object_ref (parent); \
791 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
795 #define RELEASE_PARENT(parent) \
797 if (G_LIKELY (parent)) \
798 gst_object_unref (parent); \
802 * gst_pad_get_direction:
803 * @pad: a #GstPad to get the direction of.
805 * Gets the direction of the pad. The direction of the pad is
806 * decided at construction time so this function does not take
809 * Returns: the #GstPadDirection of the pad.
814 gst_pad_get_direction (GstPad * pad)
816 GstPadDirection result;
818 /* PAD_UNKNOWN is a little silly but we need some sort of
819 * error return value */
820 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
822 result = GST_PAD_DIRECTION (pad);
828 gst_pad_activate_default (GstPad * pad, GstObject * parent)
830 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
834 * gst_pad_mode_get_name:
835 * @mode: the pad mode
837 * Return the name of a pad mode, for use in debug messages mostly.
839 * Returns: short mnemonic for pad mode @mode
842 gst_pad_mode_get_name (GstPadMode mode)
845 case GST_PAD_MODE_NONE:
847 case GST_PAD_MODE_PUSH:
849 case GST_PAD_MODE_PULL:
858 pre_activate (GstPad * pad, GstPadMode new_mode)
861 case GST_PAD_MODE_NONE:
862 GST_OBJECT_LOCK (pad);
863 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
864 GST_PAD_SET_FLUSHING (pad);
865 GST_PAD_MODE (pad) = new_mode;
866 /* unlock blocked pads so element can resume and stop */
867 GST_PAD_BLOCK_BROADCAST (pad);
868 GST_OBJECT_UNLOCK (pad);
870 case GST_PAD_MODE_PUSH:
871 case GST_PAD_MODE_PULL:
872 GST_OBJECT_LOCK (pad);
873 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
874 gst_pad_mode_get_name (new_mode));
875 GST_PAD_UNSET_FLUSHING (pad);
876 GST_PAD_MODE (pad) = new_mode;
877 if (GST_PAD_IS_SINK (pad)) {
879 /* make sure the peer src pad sends us all events */
880 if ((peer = GST_PAD_PEER (pad))) {
881 gst_object_ref (peer);
882 GST_OBJECT_UNLOCK (pad);
884 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
885 GST_DEBUG_PAD_NAME (peer));
887 GST_OBJECT_LOCK (peer);
888 schedule_events (peer, NULL);
889 GST_OBJECT_UNLOCK (peer);
891 gst_object_unref (peer);
893 GST_OBJECT_UNLOCK (pad);
896 GST_OBJECT_UNLOCK (pad);
903 post_activate (GstPad * pad, GstPadMode new_mode)
906 case GST_PAD_MODE_NONE:
907 /* ensures that streaming stops */
908 GST_PAD_STREAM_LOCK (pad);
909 GST_DEBUG_OBJECT (pad, "stopped streaming");
910 GST_OBJECT_LOCK (pad);
912 GST_OBJECT_UNLOCK (pad);
913 GST_PAD_STREAM_UNLOCK (pad);
915 case GST_PAD_MODE_PUSH:
916 case GST_PAD_MODE_PULL:
923 * gst_pad_set_active:
924 * @pad: the #GstPad to activate or deactivate.
925 * @active: whether or not the pad should be active.
927 * Activates or deactivates the given pad.
928 * Normally called from within core state change functions.
930 * If @active, makes sure the pad is active. If it is already active, either in
931 * push or pull mode, just return. Otherwise dispatches to the pad's activate
932 * function to perform the actual activation.
934 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
935 * and a FALSE argument.
937 * Returns: #TRUE if the operation was successful.
942 gst_pad_set_active (GstPad * pad, gboolean active)
946 gboolean ret = FALSE;
948 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
950 GST_OBJECT_LOCK (pad);
951 old = GST_PAD_MODE (pad);
952 ACQUIRE_PARENT (pad, parent, no_parent);
953 GST_OBJECT_UNLOCK (pad);
956 if (old == GST_PAD_MODE_NONE) {
957 GST_DEBUG_OBJECT (pad, "activating pad from none");
958 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
960 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
961 gst_pad_mode_get_name (old));
965 if (old == GST_PAD_MODE_NONE) {
966 GST_DEBUG_OBJECT (pad, "pad was inactive");
969 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
970 gst_pad_mode_get_name (old));
971 ret = gst_pad_activate_mode (pad, old, FALSE);
975 RELEASE_PARENT (parent);
977 if (G_UNLIKELY (!ret))
985 GST_DEBUG_OBJECT (pad, "no parent");
986 GST_OBJECT_UNLOCK (pad);
991 GST_OBJECT_LOCK (pad);
993 g_critical ("Failed to deactivate pad %s:%s, very bad",
994 GST_DEBUG_PAD_NAME (pad));
996 GST_WARNING_OBJECT (pad, "Failed to activate pad");
998 GST_OBJECT_UNLOCK (pad);
1004 * gst_pad_activate_mode:
1005 * @pad: the #GstPad to activate or deactivate.
1006 * @mode: the requested activation mode
1007 * @active: whether or not the pad should be active.
1009 * Activates or deactivates the given pad in @mode via dispatching to the
1010 * pad's activatemodefunc. For use from within pad activation functions only.
1012 * If you don't know what this is, you probably don't want to call it.
1014 * Returns: TRUE if the operation was successful.
1019 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1021 gboolean res = FALSE;
1023 GstPadMode old, new;
1024 GstPadDirection dir;
1027 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1029 GST_OBJECT_LOCK (pad);
1030 old = GST_PAD_MODE (pad);
1031 dir = GST_PAD_DIRECTION (pad);
1032 ACQUIRE_PARENT (pad, parent, no_parent);
1033 GST_OBJECT_UNLOCK (pad);
1035 new = active ? mode : GST_PAD_MODE_NONE;
1040 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1041 /* pad was activate in the wrong direction, deactivate it
1042 * and reactivate it in the requested mode */
1043 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1044 gst_pad_mode_get_name (old));
1046 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1047 goto deactivate_failed;
1051 case GST_PAD_MODE_PULL:
1053 if (dir == GST_PAD_SINK) {
1054 if ((peer = gst_pad_get_peer (pad))) {
1055 GST_DEBUG_OBJECT (pad, "calling peer");
1056 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1058 gst_object_unref (peer);
1060 /* there is no peer, this is only fatal when we activate. When we
1061 * deactivate, we must assume the application has unlinked the peer and
1062 * will deactivate it eventually. */
1066 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1069 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1070 goto failure; /* Can't activate pull on a src without a
1071 getrange function */
1079 /* Mark pad as needing reconfiguration */
1081 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1082 pre_activate (pad, new);
1084 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1085 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1089 /* can happen for sinks of passthrough elements */
1092 post_activate (pad, new);
1094 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1095 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1100 /* Clear sticky flags on deactivation */
1102 GST_OBJECT_LOCK (pad);
1103 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1104 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1105 GST_OBJECT_UNLOCK (pad);
1109 RELEASE_PARENT (parent);
1115 GST_DEBUG_OBJECT (pad, "no parent");
1116 GST_OBJECT_UNLOCK (pad);
1121 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1122 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1127 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1128 "failed to %s in switch to %s mode from %s mode",
1129 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1130 gst_pad_mode_get_name (old));
1135 GST_OBJECT_LOCK (peer);
1136 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1137 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1138 GST_OBJECT_UNLOCK (peer);
1139 gst_object_unref (peer);
1144 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1145 "pad in pull mode");
1150 GST_OBJECT_LOCK (pad);
1151 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1152 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1153 GST_PAD_SET_FLUSHING (pad);
1154 GST_PAD_MODE (pad) = old;
1155 GST_OBJECT_UNLOCK (pad);
1161 * gst_pad_is_active:
1162 * @pad: the #GstPad to query
1164 * Query if a pad is active
1166 * Returns: TRUE if the pad is active.
1171 gst_pad_is_active (GstPad * pad)
1173 gboolean result = FALSE;
1175 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1177 GST_OBJECT_LOCK (pad);
1178 result = GST_PAD_IS_ACTIVE (pad);
1179 GST_OBJECT_UNLOCK (pad);
1185 cleanup_hook (GstPad * pad, GHook * hook)
1187 GstPadProbeType type;
1189 if (!G_HOOK_IS_VALID (hook))
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",
1200 /* Might have new probes now that want to be called */
1201 GST_PAD_BLOCK_BROADCAST (pad);
1203 if (pad->num_blocked == 0) {
1204 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1205 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1208 g_hook_destroy_link (&pad->probes, hook);
1213 * gst_pad_add_probe:
1214 * @pad: the #GstPad to add the probe to
1215 * @mask: the probe mask
1216 * @callback: #GstPadProbeCallback that will be called with notifications of
1218 * @user_data: (closure): user data passed to the callback
1219 * @destroy_data: #GDestroyNotify for user_data
1221 * Be notified of different states of pads. The provided callback is called for
1222 * every state that matches @mask.
1224 * Returns: an id or 0 on error. The id can be used to remove the probe with
1225 * gst_pad_remove_probe().
1230 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1231 GstPadProbeCallback callback, gpointer user_data,
1232 GDestroyNotify destroy_data)
1237 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1238 g_return_val_if_fail (mask != 0, 0);
1240 GST_OBJECT_LOCK (pad);
1242 /* make a new probe */
1243 hook = g_hook_alloc (&pad->probes);
1245 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1248 /* when no contraints are given for the types, assume all types are
1250 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1251 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1252 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1253 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1255 /* store our flags and other fields */
1256 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1257 hook->func = callback;
1258 hook->data = user_data;
1259 hook->destroy = destroy_data;
1260 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1263 g_hook_prepend (&pad->probes, hook);
1265 /* incremenent cookie so that the new hook get's called */
1266 pad->priv->probe_list_cookie++;
1268 /* get the id of the hook, we return this and it can be used to remove the
1270 res = hook->hook_id;
1272 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1274 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1275 /* we have a block probe */
1277 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1278 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1279 "now %d blocking probes", pad->num_blocked);
1281 /* Might have new probes now that want to be called */
1282 GST_PAD_BLOCK_BROADCAST (pad);
1285 /* call the callback if we need to be called for idle callbacks */
1286 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1287 if (pad->priv->using > 0) {
1288 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1289 * flag above, the last thread to leave the push will do the callback. New
1290 * threads going into the push will block. */
1291 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1292 "pad is in use, delay idle callback");
1293 GST_OBJECT_UNLOCK (pad);
1295 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1296 GstPadProbeReturn ret;
1298 /* Keep another ref, the callback could destroy the pad */
1299 gst_object_ref (pad);
1301 /* the pad is idle now, we can signal the idle callback now */
1302 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1303 "pad is idle, trigger idle callback");
1304 GST_OBJECT_UNLOCK (pad);
1306 ret = callback (pad, &info, user_data);
1308 GST_OBJECT_LOCK (pad);
1310 case GST_PAD_PROBE_REMOVE:
1311 /* remove the probe */
1312 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1313 cleanup_hook (pad, hook);
1316 case GST_PAD_PROBE_DROP:
1317 GST_DEBUG_OBJECT (pad, "asked to drop item");
1319 case GST_PAD_PROBE_PASS:
1320 GST_DEBUG_OBJECT (pad, "asked to pass item");
1322 case GST_PAD_PROBE_OK:
1323 GST_DEBUG_OBJECT (pad, "probe returned OK");
1326 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1329 GST_OBJECT_UNLOCK (pad);
1331 gst_object_unref (pad);
1334 GST_OBJECT_UNLOCK (pad);
1340 * gst_pad_remove_probe:
1341 * @pad: the #GstPad with the probe
1342 * @id: the probe id to remove
1344 * Remove the probe with @id from @pad.
1349 gst_pad_remove_probe (GstPad * pad, gulong id)
1353 g_return_if_fail (GST_IS_PAD (pad));
1355 GST_OBJECT_LOCK (pad);
1357 hook = g_hook_get (&pad->probes, id);
1361 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1363 cleanup_hook (pad, hook);
1364 GST_OBJECT_UNLOCK (pad);
1370 GST_OBJECT_UNLOCK (pad);
1371 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1377 * gst_pad_is_blocked:
1378 * @pad: the #GstPad to query
1380 * Checks if the pad is blocked or not. This function returns the
1381 * last requested state of the pad. It is not certain that the pad
1382 * is actually blocking at this point (see gst_pad_is_blocking()).
1384 * Returns: TRUE if the pad is blocked.
1389 gst_pad_is_blocked (GstPad * pad)
1391 gboolean result = FALSE;
1393 g_return_val_if_fail (GST_IS_PAD (pad), result);
1395 GST_OBJECT_LOCK (pad);
1396 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1397 GST_OBJECT_UNLOCK (pad);
1403 * gst_pad_is_blocking:
1404 * @pad: the #GstPad to query
1406 * Checks if the pad is blocking or not. This is a guaranteed state
1407 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1409 * Returns: TRUE if the pad is blocking.
1414 gst_pad_is_blocking (GstPad * pad)
1416 gboolean result = FALSE;
1418 g_return_val_if_fail (GST_IS_PAD (pad), result);
1420 GST_OBJECT_LOCK (pad);
1421 /* the blocking flag is only valid if the pad is not flushing */
1422 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1423 GST_OBJECT_UNLOCK (pad);
1429 * gst_pad_needs_reconfigure:
1430 * @pad: the #GstPad to check
1432 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1433 * if the flag was set.
1435 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1438 gst_pad_needs_reconfigure (GstPad * pad)
1440 gboolean reconfigure;
1442 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1444 GST_OBJECT_LOCK (pad);
1445 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1446 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1447 GST_OBJECT_UNLOCK (pad);
1453 * gst_pad_check_reconfigure:
1454 * @pad: the #GstPad to check
1456 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1457 * if the flag was set.
1459 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1462 gst_pad_check_reconfigure (GstPad * pad)
1464 gboolean reconfigure;
1466 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1468 GST_OBJECT_LOCK (pad);
1469 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1471 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1472 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1474 GST_OBJECT_UNLOCK (pad);
1480 * gst_pad_mark_reconfigure:
1481 * @pad: the #GstPad to mark
1483 * Mark a pad for needing reconfiguration. The next call to
1484 * gst_pad_check_reconfigure() will return %TRUE after this call.
1487 gst_pad_mark_reconfigure (GstPad * pad)
1489 g_return_if_fail (GST_IS_PAD (pad));
1491 GST_OBJECT_LOCK (pad);
1492 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1493 GST_OBJECT_UNLOCK (pad);
1497 * gst_pad_set_activate_function:
1499 * @f: the #GstPadActivateFunction to set.
1501 * Calls gst_pad_set_activate_function_full() with NULL for the user_data and
1505 * gst_pad_set_activate_function_full:
1507 * @activate: the #GstPadActivateFunction to set.
1508 * @user_data: user_data passed to @notify
1509 * @notify: notify called when @activate will not be used anymore.
1511 * Sets the given activate function for @pad. The activate function will
1512 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1513 * Only makes sense to set on sink pads.
1515 * Call this function if your sink pad can start a pull-based task.
1518 gst_pad_set_activate_function_full (GstPad * pad,
1519 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1521 g_return_if_fail (GST_IS_PAD (pad));
1523 if (pad->activatenotify)
1524 pad->activatenotify (pad->activatedata);
1525 GST_PAD_ACTIVATEFUNC (pad) = activate;
1526 pad->activatedata = user_data;
1527 pad->activatenotify = notify;
1529 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1530 GST_DEBUG_FUNCPTR_NAME (activate));
1534 * gst_pad_set_activatemode_function:
1536 * @f: the #GstPadActivateModeFunction to set.
1538 * Calls gst_pad_set_activatemode_function_full() with NULL for the user_data and
1542 * gst_pad_set_activatemode_function_full:
1544 * @activatemode: the #GstPadActivateModeFunction to set.
1545 * @user_data: user_data passed to @notify
1546 * @notify: notify called when @activatemode will not be used anymore.
1548 * Sets the given activate_mode function for the pad. An activate_mode function
1549 * prepares the element for data passing.
1552 gst_pad_set_activatemode_function_full (GstPad * pad,
1553 GstPadActivateModeFunction activatemode, gpointer user_data,
1554 GDestroyNotify notify)
1556 g_return_if_fail (GST_IS_PAD (pad));
1558 if (pad->activatemodenotify)
1559 pad->activatemodenotify (pad->activatemodedata);
1560 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1561 pad->activatemodedata = user_data;
1562 pad->activatemodenotify = notify;
1564 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1565 GST_DEBUG_FUNCPTR_NAME (activatemode));
1569 * gst_pad_set_chain_function:
1570 * @p: a sink #GstPad.
1571 * @f: the #GstPadChainFunction to set.
1573 * Calls gst_pad_set_chain_function_full() with NULL for the user_data and
1577 * gst_pad_set_chain_function_full:
1578 * @pad: a sink #GstPad.
1579 * @chain: the #GstPadChainFunction to set.
1580 * @user_data: user_data passed to @notify
1581 * @notify: notify called when @chain will not be used anymore.
1583 * Sets the given chain function for the pad. The chain function is called to
1584 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1587 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1588 gpointer user_data, GDestroyNotify notify)
1590 g_return_if_fail (GST_IS_PAD (pad));
1591 g_return_if_fail (GST_PAD_IS_SINK (pad));
1593 if (pad->chainnotify)
1594 pad->chainnotify (pad->chaindata);
1595 GST_PAD_CHAINFUNC (pad) = chain;
1596 pad->chaindata = user_data;
1597 pad->chainnotify = notify;
1599 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1600 GST_DEBUG_FUNCPTR_NAME (chain));
1604 * gst_pad_set_chain_list_function:
1605 * @p: a sink #GstPad.
1606 * @f: the #GstPadChainListFunction to set.
1608 * Calls gst_pad_set_chain_list_function_full() with NULL for the user_data and
1612 * gst_pad_set_chain_list_function_full:
1613 * @pad: a sink #GstPad.
1614 * @chainlist: the #GstPadChainListFunction to set.
1615 * @user_data: user_data passed to @notify
1616 * @notify: notify called when @chainlist will not be used anymore.
1618 * Sets the given chain list function for the pad. The chainlist function is
1619 * called to process a #GstBufferList input buffer list. See
1620 * #GstPadChainListFunction for more details.
1623 gst_pad_set_chain_list_function_full (GstPad * pad,
1624 GstPadChainListFunction chainlist, gpointer user_data,
1625 GDestroyNotify notify)
1627 g_return_if_fail (GST_IS_PAD (pad));
1628 g_return_if_fail (GST_PAD_IS_SINK (pad));
1630 if (pad->chainlistnotify)
1631 pad->chainlistnotify (pad->chainlistdata);
1632 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1633 pad->chainlistdata = user_data;
1634 pad->chainlistnotify = notify;
1636 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1637 GST_DEBUG_FUNCPTR_NAME (chainlist));
1641 * gst_pad_set_getrange_function:
1642 * @p: a source #GstPad.
1643 * @f: the #GstPadGetRangeFunction to set.
1645 * Calls gst_pad_set_getrange_function_full() with NULL for the user_data and
1649 * gst_pad_set_getrange_function_full:
1650 * @pad: a source #GstPad.
1651 * @get: the #GstPadGetRangeFunction to set.
1652 * @user_data: user_data passed to @notify
1653 * @notify: notify called when @get will not be used anymore.
1655 * Sets the given getrange function for the pad. The getrange function is
1656 * called to produce a new #GstBuffer to start the processing pipeline. see
1657 * #GstPadGetRangeFunction for a description of the getrange function.
1660 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1661 gpointer user_data, GDestroyNotify notify)
1663 g_return_if_fail (GST_IS_PAD (pad));
1664 g_return_if_fail (GST_PAD_IS_SRC (pad));
1666 if (pad->getrangenotify)
1667 pad->getrangenotify (pad->getrangedata);
1668 GST_PAD_GETRANGEFUNC (pad) = get;
1669 pad->getrangedata = user_data;
1670 pad->getrangenotify = notify;
1672 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1673 GST_DEBUG_FUNCPTR_NAME (get));
1677 * gst_pad_set_event_function:
1678 * @p: a #GstPad of either direction.
1679 * @f: the #GstPadEventFunction to set.
1681 * Calls gst_pad_set_event_function_full() with NULL for the user_data and
1685 * gst_pad_set_event_function_full:
1686 * @pad: a #GstPad of either direction.
1687 * @event: the #GstPadEventFunction to set.
1688 * @user_data: user_data passed to @notify
1689 * @notify: notify called when @event will not be used anymore.
1691 * Sets the given event handler for the pad.
1694 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1695 gpointer user_data, GDestroyNotify notify)
1697 g_return_if_fail (GST_IS_PAD (pad));
1699 if (pad->eventnotify)
1700 pad->eventnotify (pad->eventdata);
1701 GST_PAD_EVENTFUNC (pad) = event;
1702 pad->eventdata = user_data;
1703 pad->eventnotify = notify;
1705 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1706 GST_DEBUG_FUNCPTR_NAME (event));
1710 * gst_pad_set_query_function:
1711 * @p: a #GstPad of either direction.
1712 * @f: the #GstPadQueryFunction to set.
1714 * Calls gst_pad_set_query_function_full() with NULL for the user_data and
1718 * gst_pad_set_query_function_full:
1719 * @pad: a #GstPad of either direction.
1720 * @query: the #GstPadQueryFunction to set.
1721 * @user_data: user_data passed to @notify
1722 * @notify: notify called when @query will not be used anymore.
1724 * Set the given query function for the pad.
1727 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1728 gpointer user_data, GDestroyNotify notify)
1730 g_return_if_fail (GST_IS_PAD (pad));
1732 if (pad->querynotify)
1733 pad->querynotify (pad->querydata);
1734 GST_PAD_QUERYFUNC (pad) = query;
1735 pad->querydata = user_data;
1736 pad->querynotify = notify;
1738 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1739 GST_DEBUG_FUNCPTR_NAME (query));
1743 * gst_pad_set_iterate_internal_links_function:
1744 * @p: a #GstPad of either direction.
1745 * @f: the #GstPadIterIntLinkFunction to set.
1747 * Calls gst_pad_set_iterate_internal_links_function_full() with NULL
1748 * for the user_data and notify.
1751 * gst_pad_set_iterate_internal_links_function_full:
1752 * @pad: a #GstPad of either direction.
1753 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1754 * @user_data: user_data passed to @notify
1755 * @notify: notify called when @iterintlink will not be used anymore.
1757 * Sets the given internal link iterator function for the pad.
1760 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1761 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1762 GDestroyNotify notify)
1764 g_return_if_fail (GST_IS_PAD (pad));
1766 if (pad->iterintlinknotify)
1767 pad->iterintlinknotify (pad->iterintlinkdata);
1768 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1769 pad->iterintlinkdata = user_data;
1770 pad->iterintlinknotify = notify;
1772 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1773 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1777 * gst_pad_set_link_function:
1779 * @f: the #GstPadLinkFunction to set.
1781 * Calls gst_pad_set_link_function_full() with NULL
1782 * for the user_data and notify.
1785 * gst_pad_set_link_function_full:
1787 * @link: the #GstPadLinkFunction to set.
1788 * @user_data: user_data passed to @notify
1789 * @notify: notify called when @link will not be used anymore.
1791 * Sets the given link function for the pad. It will be called when
1792 * the pad is linked with another pad.
1794 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1797 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1798 * cannot be made for some reason.
1800 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1801 * of the peer sink pad, if present.
1804 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1805 gpointer user_data, GDestroyNotify notify)
1807 g_return_if_fail (GST_IS_PAD (pad));
1809 if (pad->linknotify)
1810 pad->linknotify (pad->linkdata);
1811 GST_PAD_LINKFUNC (pad) = link;
1812 pad->linkdata = user_data;
1813 pad->linknotify = notify;
1815 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1816 GST_DEBUG_FUNCPTR_NAME (link));
1820 * gst_pad_set_unlink_function:
1822 * @f: the #GstPadUnlinkFunction to set.
1824 * Calls gst_pad_set_unlink_function_full() with NULL
1825 * for the user_data and notify.
1828 * gst_pad_set_unlink_function_full:
1830 * @unlink: the #GstPadUnlinkFunction to set.
1831 * @user_data: user_data passed to @notify
1832 * @notify: notify called when @unlink will not be used anymore.
1834 * Sets the given unlink function for the pad. It will be called
1835 * when the pad is unlinked.
1838 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1839 gpointer user_data, GDestroyNotify notify)
1841 g_return_if_fail (GST_IS_PAD (pad));
1843 if (pad->unlinknotify)
1844 pad->unlinknotify (pad->unlinkdata);
1845 GST_PAD_UNLINKFUNC (pad) = unlink;
1846 pad->unlinkdata = user_data;
1847 pad->unlinknotify = notify;
1849 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1850 GST_DEBUG_FUNCPTR_NAME (unlink));
1855 * @srcpad: the source #GstPad to unlink.
1856 * @sinkpad: the sink #GstPad to unlink.
1858 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1859 * signal on both pads.
1861 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1862 * the pads were not linked together.
1867 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1869 gboolean result = FALSE;
1870 GstElement *parent = NULL;
1872 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1873 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1874 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1875 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1877 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1878 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1879 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1881 /* We need to notify the parent before taking any pad locks as the bin in
1882 * question might be waiting for a lock on the pad while holding its lock
1883 * that our message will try to take. */
1884 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1885 if (GST_IS_ELEMENT (parent)) {
1886 gst_element_post_message (parent,
1887 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1888 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1890 gst_object_unref (parent);
1895 GST_OBJECT_LOCK (srcpad);
1896 GST_OBJECT_LOCK (sinkpad);
1898 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1899 goto not_linked_together;
1901 if (GST_PAD_UNLINKFUNC (srcpad)) {
1902 GstObject *tmpparent;
1904 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1906 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1907 RELEASE_PARENT (tmpparent);
1910 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1911 GstObject *tmpparent;
1913 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1915 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1916 RELEASE_PARENT (tmpparent);
1920 /* first clear peers */
1921 GST_PAD_PEER (srcpad) = NULL;
1922 GST_PAD_PEER (sinkpad) = NULL;
1924 GST_OBJECT_UNLOCK (sinkpad);
1925 GST_OBJECT_UNLOCK (srcpad);
1927 /* fire off a signal to each of the pads telling them
1928 * that they've been unlinked */
1929 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1930 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1932 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1933 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1938 if (parent != NULL) {
1939 gst_element_post_message (parent,
1940 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1941 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1942 gst_object_unref (parent);
1947 not_linked_together:
1949 /* we do not emit a warning in this case because unlinking cannot
1950 * be made MT safe.*/
1951 GST_OBJECT_UNLOCK (sinkpad);
1952 GST_OBJECT_UNLOCK (srcpad);
1958 * gst_pad_is_linked:
1959 * @pad: pad to check
1961 * Checks if a @pad is linked to another pad or not.
1963 * Returns: TRUE if the pad is linked, FALSE otherwise.
1968 gst_pad_is_linked (GstPad * pad)
1972 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1974 GST_OBJECT_LOCK (pad);
1975 result = (GST_PAD_PEER (pad) != NULL);
1976 GST_OBJECT_UNLOCK (pad);
1981 /* get the caps from both pads and see if the intersection
1984 * This function should be called with the pad LOCK on both
1988 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1989 GstPadLinkCheck flags)
1991 GstCaps *srccaps = NULL;
1992 GstCaps *sinkcaps = NULL;
1993 gboolean compatible = FALSE;
1995 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1998 /* Doing the expensive caps checking takes priority over only checking the template caps */
1999 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2000 GST_OBJECT_UNLOCK (sink);
2001 GST_OBJECT_UNLOCK (src);
2003 srccaps = gst_pad_query_caps (src, NULL);
2004 sinkcaps = gst_pad_query_caps (sink, NULL);
2006 GST_OBJECT_LOCK (src);
2007 GST_OBJECT_LOCK (sink);
2009 /* If one of the two pads doesn't have a template, consider the intersection
2011 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2012 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2016 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2018 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2021 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2023 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2026 /* if we have caps on both pads we can check the intersection. If one
2027 * of the caps is NULL, we return TRUE. */
2028 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2030 gst_caps_unref (srccaps);
2032 gst_caps_unref (sinkcaps);
2036 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2037 gst_caps_unref (srccaps);
2038 gst_caps_unref (sinkcaps);
2041 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2042 (compatible ? "" : "not"));
2047 /* check if the grandparents of both pads are the same.
2048 * This check is required so that we don't try to link
2049 * pads from elements in different bins without ghostpads.
2051 * The LOCK should be held on both pads
2054 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2056 GstObject *psrc, *psink;
2058 psrc = GST_OBJECT_PARENT (src);
2059 psink = GST_OBJECT_PARENT (sink);
2061 /* if one of the pads has no parent, we allow the link */
2062 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2065 /* only care about parents that are elements */
2066 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2067 goto no_element_parent;
2069 /* if the parents are the same, we have a loop */
2070 if (G_UNLIKELY (psrc == psink))
2073 /* if they both have a parent, we check the grandparents. We can not lock
2074 * the parent because we hold on the child (pad) and the locking order is
2075 * parent >> child. */
2076 psrc = GST_OBJECT_PARENT (psrc);
2077 psink = GST_OBJECT_PARENT (psink);
2079 /* if they have grandparents but they are not the same */
2080 if (G_UNLIKELY (psrc != psink))
2081 goto wrong_grandparents;
2088 GST_CAT_DEBUG (GST_CAT_CAPS,
2089 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2090 GST_PTR_FORMAT, psrc, psink);
2095 GST_CAT_DEBUG (GST_CAT_CAPS,
2096 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2097 GST_PTR_FORMAT, psrc, psink);
2102 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2108 GST_CAT_DEBUG (GST_CAT_CAPS,
2109 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2110 GST_PTR_FORMAT, psrc, psink);
2115 /* FIXME leftover from an attempt at refactoring... */
2116 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2117 * the two pads will be locked in the srcpad, sinkpad order. */
2118 static GstPadLinkReturn
2119 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2121 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2122 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2124 GST_OBJECT_LOCK (srcpad);
2126 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2127 goto src_was_linked;
2129 GST_OBJECT_LOCK (sinkpad);
2131 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2132 goto sink_was_linked;
2134 /* check hierarchy, pads can only be linked if the grandparents
2136 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2137 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2138 goto wrong_hierarchy;
2140 /* check pad caps for non-empty intersection */
2141 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2144 /* FIXME check pad scheduling for non-empty intersection */
2146 return GST_PAD_LINK_OK;
2150 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2151 GST_DEBUG_PAD_NAME (srcpad),
2152 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2153 /* we do not emit a warning in this case because unlinking cannot
2154 * be made MT safe.*/
2155 GST_OBJECT_UNLOCK (srcpad);
2156 return GST_PAD_LINK_WAS_LINKED;
2160 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2161 GST_DEBUG_PAD_NAME (sinkpad),
2162 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2163 /* we do not emit a warning in this case because unlinking cannot
2164 * be made MT safe.*/
2165 GST_OBJECT_UNLOCK (sinkpad);
2166 GST_OBJECT_UNLOCK (srcpad);
2167 return GST_PAD_LINK_WAS_LINKED;
2171 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2172 GST_OBJECT_UNLOCK (sinkpad);
2173 GST_OBJECT_UNLOCK (srcpad);
2174 return GST_PAD_LINK_WRONG_HIERARCHY;
2178 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2179 GST_OBJECT_UNLOCK (sinkpad);
2180 GST_OBJECT_UNLOCK (srcpad);
2181 return GST_PAD_LINK_NOFORMAT;
2187 * @srcpad: the source #GstPad.
2188 * @sinkpad: the sink #GstPad.
2190 * Checks if the source pad and the sink pad are compatible so they can be
2193 * Returns: TRUE if the pads can be linked.
2196 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2198 GstPadLinkReturn result;
2200 /* generic checks */
2201 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2202 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2204 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2205 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2207 /* gst_pad_link_prepare does everything for us, we only release the locks
2208 * on the pads that it gets us. If this function returns !OK the locks are not
2210 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2211 if (result != GST_PAD_LINK_OK)
2214 GST_OBJECT_UNLOCK (srcpad);
2215 GST_OBJECT_UNLOCK (sinkpad);
2218 return result == GST_PAD_LINK_OK;
2222 * gst_pad_link_full:
2223 * @srcpad: the source #GstPad to link.
2224 * @sinkpad: the sink #GstPad to link.
2225 * @flags: the checks to validate when linking
2227 * Links the source pad and the sink pad.
2229 * This variant of #gst_pad_link provides a more granular control on the
2230 * checks being done when linking. While providing some considerable speedups
2231 * the caller of this method must be aware that wrong usage of those flags
2232 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2233 * for more information.
2237 * Returns: A result code indicating if the connection worked or
2241 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2243 GstPadLinkReturn result;
2245 GstPadLinkFunction srcfunc, sinkfunc;
2247 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2248 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2249 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2250 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2251 GST_PAD_LINK_WRONG_DIRECTION);
2253 /* Notify the parent early. See gst_pad_unlink for details. */
2254 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2255 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2256 gst_element_post_message (parent,
2257 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2258 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2260 gst_object_unref (parent);
2265 /* prepare will also lock the two pads */
2266 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2268 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2271 /* must set peers before calling the link function */
2272 GST_PAD_PEER (srcpad) = sinkpad;
2273 GST_PAD_PEER (sinkpad) = srcpad;
2275 /* check events, when something is different, mark pending */
2276 schedule_events (srcpad, sinkpad);
2278 /* get the link functions */
2279 srcfunc = GST_PAD_LINKFUNC (srcpad);
2280 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2282 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2283 /* custom link functions, execute them */
2284 GST_OBJECT_UNLOCK (sinkpad);
2285 GST_OBJECT_UNLOCK (srcpad);
2288 GstObject *tmpparent;
2290 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2291 /* this one will call the peer link function */
2292 result = srcfunc (srcpad, tmpparent, sinkpad);
2293 RELEASE_PARENT (tmpparent);
2294 } else if (sinkfunc) {
2295 GstObject *tmpparent;
2297 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2298 /* if no source link function, we need to call the sink link
2299 * function ourselves. */
2300 result = sinkfunc (sinkpad, tmpparent, srcpad);
2301 RELEASE_PARENT (tmpparent);
2305 GST_OBJECT_LOCK (srcpad);
2306 GST_OBJECT_LOCK (sinkpad);
2308 /* we released the lock, check if the same pads are linked still */
2309 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2310 goto concurrent_link;
2312 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2315 GST_OBJECT_UNLOCK (sinkpad);
2316 GST_OBJECT_UNLOCK (srcpad);
2318 /* fire off a signal to each of the pads telling them
2319 * that they've been linked */
2320 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2321 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2323 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2324 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2326 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2329 if (G_LIKELY (parent)) {
2330 gst_element_post_message (parent,
2331 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2332 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2333 gst_object_unref (parent);
2341 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2342 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2343 GST_OBJECT_UNLOCK (sinkpad);
2344 GST_OBJECT_UNLOCK (srcpad);
2346 /* The other link operation succeeded first */
2347 result = GST_PAD_LINK_WAS_LINKED;
2352 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2353 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2355 GST_PAD_PEER (srcpad) = NULL;
2356 GST_PAD_PEER (sinkpad) = NULL;
2358 GST_OBJECT_UNLOCK (sinkpad);
2359 GST_OBJECT_UNLOCK (srcpad);
2367 * @srcpad: the source #GstPad to link.
2368 * @sinkpad: the sink #GstPad to link.
2370 * Links the source pad and the sink pad.
2372 * Returns: A result code indicating if the connection worked or
2378 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2380 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2384 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2386 GstPadTemplate **template_p;
2388 /* this function would need checks if it weren't static */
2390 GST_OBJECT_LOCK (pad);
2391 template_p = &pad->padtemplate;
2392 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2393 GST_OBJECT_UNLOCK (pad);
2396 gst_pad_template_pad_created (templ, pad);
2400 * gst_pad_get_pad_template:
2403 * Gets the template for @pad.
2405 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2406 * instantiated, or %NULL if this pad has no template. Unref after
2410 gst_pad_get_pad_template (GstPad * pad)
2412 GstPadTemplate *templ;
2414 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2416 templ = GST_PAD_PAD_TEMPLATE (pad);
2418 return (templ ? gst_object_ref (templ) : NULL);
2422 * gst_pad_has_current_caps:
2423 * @pad: a #GstPad to check
2425 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2427 * Returns: TRUE when @pad has caps associated with it.
2430 gst_pad_has_current_caps (GstPad * pad)
2435 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2437 GST_OBJECT_LOCK (pad);
2438 caps = get_pad_caps (pad);
2439 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2440 "check current pad caps %" GST_PTR_FORMAT, caps);
2441 result = (caps != NULL);
2442 GST_OBJECT_UNLOCK (pad);
2448 * gst_pad_get_current_caps:
2449 * @pad: a #GstPad to get the current capabilities of.
2451 * Gets the capabilities currently configured on @pad with the last
2452 * #GST_EVENT_CAPS event.
2454 * Returns: the current caps of the pad with incremented ref-count.
2457 gst_pad_get_current_caps (GstPad * pad)
2461 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2463 GST_OBJECT_LOCK (pad);
2464 if ((result = get_pad_caps (pad)))
2465 gst_caps_ref (result);
2466 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2467 "get current pad caps %" GST_PTR_FORMAT, result);
2468 GST_OBJECT_UNLOCK (pad);
2474 * gst_pad_get_pad_template_caps:
2475 * @pad: a #GstPad to get the template capabilities from.
2477 * Gets the capabilities for @pad's template.
2479 * Returns: (transfer full): the #GstCaps of this pad template.
2480 * Unref after usage.
2483 gst_pad_get_pad_template_caps (GstPad * pad)
2485 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2487 if (GST_PAD_PAD_TEMPLATE (pad))
2488 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2490 return gst_caps_ref (GST_CAPS_ANY);
2495 * @pad: a #GstPad to get the peer of.
2497 * Gets the peer of @pad. This function refs the peer pad so
2498 * you need to unref it after use.
2500 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2505 gst_pad_get_peer (GstPad * pad)
2509 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2511 GST_OBJECT_LOCK (pad);
2512 result = GST_PAD_PEER (pad);
2514 gst_object_ref (result);
2515 GST_OBJECT_UNLOCK (pad);
2521 * gst_pad_get_allowed_caps:
2524 * Gets the capabilities of the allowed media types that can flow through
2525 * @pad and its peer.
2527 * The allowed capabilities is calculated as the intersection of the results of
2528 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2529 * on the resulting caps.
2531 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2532 * caps when you no longer need it. This function returns NULL when @pad
2538 gst_pad_get_allowed_caps (GstPad * pad)
2544 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2546 GST_OBJECT_LOCK (pad);
2547 peer = GST_PAD_PEER (pad);
2548 if (G_UNLIKELY (peer == NULL))
2551 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2553 gst_object_ref (peer);
2554 GST_OBJECT_UNLOCK (pad);
2555 mycaps = gst_pad_query_caps (pad, NULL);
2557 caps = gst_pad_query_caps (peer, mycaps);
2558 gst_object_unref (peer);
2560 gst_caps_unref (mycaps);
2562 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2569 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2570 GST_OBJECT_UNLOCK (pad);
2577 * gst_pad_iterate_internal_links_default:
2578 * @pad: the #GstPad to get the internal links of.
2579 * @parent: (allow-none): the parent of @pad or NULL
2581 * Iterate the list of pads to which the given pad is linked to inside of
2582 * the parent element.
2583 * This is the default handler, and thus returns an iterator of all of the
2584 * pads inside the parent element with opposite direction.
2586 * The caller must free this iterator after use with gst_iterator_free().
2588 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2589 * returned pad with gst_object_unref().
2592 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2599 GstElement *eparent;
2601 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2603 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2604 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2606 GST_OBJECT_LOCK (pad);
2607 eparent = GST_PAD_PARENT (pad);
2608 if (!eparent || !GST_IS_ELEMENT (eparent))
2611 gst_object_ref (eparent);
2612 GST_OBJECT_UNLOCK (pad);
2615 if (pad->direction == GST_PAD_SRC)
2616 padlist = &eparent->sinkpads;
2618 padlist = &eparent->srcpads;
2620 GST_DEBUG_OBJECT (pad, "Making iterator");
2622 cookie = &eparent->pads_cookie;
2624 lock = GST_OBJECT_GET_LOCK (eparent);
2626 res = gst_iterator_new_list (GST_TYPE_PAD,
2627 lock, cookie, padlist, (GObject *) owner, NULL);
2629 gst_object_unref (owner);
2636 GST_OBJECT_UNLOCK (pad);
2637 GST_DEBUG_OBJECT (pad, "no parent element");
2643 * gst_pad_iterate_internal_links:
2644 * @pad: the GstPad to get the internal links of.
2646 * Gets an iterator for the pads to which the given pad is linked to inside
2647 * of the parent element.
2649 * Each #GstPad element yielded by the iterator will have its refcount increased,
2650 * so unref after use.
2652 * Free-function: gst_iterator_free
2654 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2655 * pad does not have an iterator function configured. Use
2656 * gst_iterator_free() after usage.
2659 gst_pad_iterate_internal_links (GstPad * pad)
2661 GstIterator *res = NULL;
2664 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2666 GST_OBJECT_LOCK (pad);
2667 ACQUIRE_PARENT (pad, parent, no_parent);
2668 GST_OBJECT_UNLOCK (pad);
2670 if (GST_PAD_ITERINTLINKFUNC (pad))
2671 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2673 RELEASE_PARENT (parent);
2680 GST_DEBUG_OBJECT (pad, "no parent");
2681 GST_OBJECT_UNLOCK (pad);
2689 * @forward: (scope call): a #GstPadForwardFunction
2690 * @user_data: user data passed to @forward
2692 * Calls @forward for all internally linked pads of @pad. This function deals with
2693 * dynamically changing internal pads and will make sure that the @forward
2694 * function is only called once for each pad.
2696 * When @forward returns TRUE, no further pads will be processed.
2698 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2701 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2704 gboolean result = FALSE;
2706 gboolean done = FALSE;
2707 GValue item = { 0, };
2708 GList *pushed_pads = NULL;
2710 iter = gst_pad_iterate_internal_links (pad);
2716 switch (gst_iterator_next (iter, &item)) {
2717 case GST_ITERATOR_OK:
2721 intpad = g_value_get_object (&item);
2723 /* if already pushed, skip. FIXME, find something faster to tag pads */
2724 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2725 g_value_reset (&item);
2729 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2730 GST_DEBUG_PAD_NAME (intpad));
2731 done = result = forward (intpad, user_data);
2733 pushed_pads = g_list_prepend (pushed_pads, intpad);
2735 g_value_reset (&item);
2738 case GST_ITERATOR_RESYNC:
2739 /* We don't reset the result here because we don't push the event
2740 * again on pads that got the event already and because we need
2741 * to consider the result of the previous pushes */
2742 gst_iterator_resync (iter);
2744 case GST_ITERATOR_ERROR:
2745 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2748 case GST_ITERATOR_DONE:
2753 g_value_unset (&item);
2754 gst_iterator_free (iter);
2756 g_list_free (pushed_pads);
2766 gboolean dispatched;
2770 event_forward_func (GstPad * pad, EventData * data)
2772 /* for each pad we send to, we should ref the event; it's up
2773 * to downstream to unref again when handled. */
2774 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2775 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2777 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2779 data->dispatched = TRUE;
2786 * gst_pad_event_default:
2787 * @pad: a #GstPad to call the default event handler on.
2788 * @parent: (allow-none): the parent of @pad or NULL
2789 * @event: (transfer full): the #GstEvent to handle.
2791 * Invokes the default event handler for the given pad.
2793 * The EOS event will pause the task associated with @pad before it is forwarded
2794 * to all internally linked pads,
2796 * The the event is sent to all pads internally linked to @pad. This function
2797 * takes ownership of @event.
2799 * Returns: TRUE if the event was sent successfully.
2802 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2804 gboolean result, forward = TRUE;
2806 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2807 g_return_val_if_fail (event != NULL, FALSE);
2809 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2812 switch (GST_EVENT_TYPE (event)) {
2813 case GST_EVENT_CAPS:
2814 forward = GST_PAD_IS_PROXY_CAPS (pad);
2825 data.dispatched = FALSE;
2826 data.result = FALSE;
2828 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2830 /* for sinkpads without a parent element or without internal links, nothing
2831 * will be dispatched but we still want to return TRUE. */
2832 if (data.dispatched)
2833 result = data.result;
2838 gst_event_unref (event);
2843 /* Default accept caps implementation just checks against
2844 * the allowed caps for the pad */
2846 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2848 /* get the caps and see if it intersects to something not empty */
2849 GstCaps *caps, *allowed;
2852 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2854 /* first forward the query to internally linked pads when we are dealing with
2856 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2857 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2862 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2863 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2865 gst_query_parse_accept_caps (query, &caps);
2866 allowed = gst_pad_query_caps (pad, caps);
2869 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
2870 GST_DEBUG_OBJECT (pad,
2871 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
2873 result = gst_caps_can_intersect (caps, allowed);
2875 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
2876 GST_PTR_FORMAT, allowed, caps);
2877 result = gst_caps_is_subset (caps, allowed);
2879 gst_caps_unref (allowed);
2881 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
2884 gst_query_set_accept_caps_result (query, result);
2890 /* Default caps implementation */
2892 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2894 GstCaps *result = NULL, *filter;
2895 GstPadTemplate *templ;
2896 gboolean fixed_caps;
2898 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2901 /* first try to proxy if we must */
2902 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2903 if ((gst_pad_proxy_query_caps (pad, query))) {
2908 gst_query_parse_caps (query, &filter);
2910 /* no proxy or it failed, do default handling */
2911 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2913 GST_OBJECT_LOCK (pad);
2915 /* fixed caps, try the negotiated caps first */
2916 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2917 if ((result = get_pad_caps (pad)))
2918 goto filter_done_unlock;
2921 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2922 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2923 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2924 goto filter_done_unlock;
2928 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2929 "non-fixed pad caps: trying pad caps");
2930 /* non fixed caps, try the negotiated caps */
2931 if ((result = get_pad_caps (pad)))
2932 goto filter_done_unlock;
2935 /* this almost never happens */
2936 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2937 result = GST_CAPS_ANY;
2940 GST_OBJECT_UNLOCK (pad);
2942 /* run the filter on the result */
2944 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2945 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2946 GST_PTR_FORMAT, result, result, filter, filter);
2947 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2948 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2951 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2952 "using caps %p %" GST_PTR_FORMAT, result, result);
2953 result = gst_caps_ref (result);
2955 gst_query_set_caps_result (query, result);
2956 gst_caps_unref (result);
2966 gboolean dispatched;
2970 query_forward_func (GstPad * pad, QueryData * data)
2972 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
2973 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
2975 data->result |= gst_pad_peer_query (pad, data->query);
2977 data->dispatched = TRUE;
2979 /* stop on first successful reply */
2980 return data->result;
2984 * gst_pad_query_default:
2985 * @pad: a #GstPad to call the default query handler on.
2986 * @parent: (allow-none): the parent of @pad or NULL
2987 * @query: (transfer none): the #GstQuery to handle.
2989 * Invokes the default query handler for the given pad.
2990 * The query is sent to all pads internally linked to @pad. Note that
2991 * if there are many possible sink pads that are internally linked to
2992 * @pad, only one will be sent the query.
2993 * Multi-sinkpad elements should implement custom query handlers.
2995 * Returns: TRUE if the query was performed successfully.
2998 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3000 gboolean forward, ret = FALSE;
3002 switch (GST_QUERY_TYPE (query)) {
3003 case GST_QUERY_SCHEDULING:
3004 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3006 case GST_QUERY_ALLOCATION:
3007 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3009 case GST_QUERY_ACCEPT_CAPS:
3010 ret = gst_pad_query_accept_caps_default (pad, query);
3013 case GST_QUERY_CAPS:
3014 ret = gst_pad_query_caps_default (pad, query);
3017 case GST_QUERY_POSITION:
3018 case GST_QUERY_SEEKING:
3019 case GST_QUERY_FORMATS:
3020 case GST_QUERY_LATENCY:
3021 case GST_QUERY_JITTER:
3022 case GST_QUERY_RATE:
3023 case GST_QUERY_CONVERT:
3029 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3030 query, GST_QUERY_TYPE_NAME (query));
3036 data.dispatched = FALSE;
3037 data.result = FALSE;
3039 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3041 if (data.dispatched) {
3044 /* nothing dispatched, assume drained */
3045 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3055 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3057 GstPad *pad = data->pad;
3058 GstPadProbeInfo *info = data->info;
3059 GstPadProbeType type, flags;
3060 GstPadProbeCallback callback;
3061 GstPadProbeReturn ret;
3063 /* if we have called this callback, do nothing */
3064 if (PROBE_COOKIE (hook) == data->cookie) {
3065 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3066 "hook %lu, cookie %u already called", hook->hook_id,
3067 PROBE_COOKIE (hook));
3071 PROBE_COOKIE (hook) = data->cookie;
3073 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3076 /* one of the data types for non-idle probes */
3077 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3078 && (flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3080 /* one of the scheduling types */
3081 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3083 /* one of the blocking types must match */
3084 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3085 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3087 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3088 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3090 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3091 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3092 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3095 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3096 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3097 PROBE_COOKIE (hook), flags);
3099 data->marshalled = TRUE;
3101 callback = (GstPadProbeCallback) hook->func;
3102 if (callback == NULL)
3105 info->id = hook->hook_id;
3107 GST_OBJECT_UNLOCK (pad);
3109 ret = callback (pad, info, hook->data);
3111 GST_OBJECT_LOCK (pad);
3114 case GST_PAD_PROBE_REMOVE:
3115 /* remove the probe */
3116 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3117 cleanup_hook (pad, hook);
3119 case GST_PAD_PROBE_DROP:
3120 /* need to drop the data, make sure other probes don't get called
3122 GST_DEBUG_OBJECT (pad, "asked to drop item");
3123 info->type = GST_PAD_PROBE_TYPE_INVALID;
3124 data->dropped = TRUE;
3126 case GST_PAD_PROBE_PASS:
3127 /* inform the pad block to let things pass */
3128 GST_DEBUG_OBJECT (pad, "asked to pass item");
3131 case GST_PAD_PROBE_OK:
3132 GST_DEBUG_OBJECT (pad, "probe returned OK");
3135 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3142 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3143 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3144 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3149 /* a probe that does not take or return any data */
3150 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3152 if (G_UNLIKELY (pad->num_probes)) { \
3153 /* pass NULL as the data item */ \
3154 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3155 ret = do_probe_callbacks (pad, &info, defaultval); \
3156 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3161 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3163 if (G_UNLIKELY (pad->num_probes)) { \
3164 /* pass the data item */ \
3165 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3166 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3167 /* store the possibly updated data item */ \
3168 data = GST_PAD_PROBE_INFO_DATA (&info); \
3169 /* if something went wrong, exit */ \
3170 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3175 #define PROBE_PUSH(pad,mask,data,label) \
3176 PROBE_FULL(pad, mask, data, -1, -1, label);
3177 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3178 PROBE_FULL(pad, mask, data, offs, size, label);
3180 static GstFlowReturn
3181 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3182 GstFlowReturn defaultval)
3191 data.marshalled = FALSE;
3192 data.dropped = FALSE;
3193 data.cookie = ++pad->priv->probe_cookie;
3196 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3199 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3200 "do probes cookie %u", data.cookie);
3201 cookie = pad->priv->probe_list_cookie;
3203 g_hook_list_marshal (&pad->probes, TRUE,
3204 (GHookMarshaller) probe_hook_marshal, &data);
3206 /* if the list changed, call the new callbacks (they will not have their
3207 * cookie set to data.cookie */
3208 if (cookie != pad->priv->probe_list_cookie) {
3209 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3210 "probe list changed, restarting");
3214 /* the first item that dropped will stop the hooks and then we drop here */
3218 /* if no handler matched and we are blocking, let the item pass */
3219 if (!data.marshalled && is_block)
3222 /* At this point, all handlers returned either OK or PASS. If one handler
3223 * returned PASS, let the item pass */
3228 while (GST_PAD_IS_BLOCKED (pad)) {
3229 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3230 "we are blocked %d times", pad->num_blocked);
3232 /* we might have released the lock */
3233 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3236 /* now we block the streaming thread. It can be unlocked when we
3237 * deactivate the pad (which will also set the FLUSHING flag) or
3238 * when the pad is unblocked. A flushing event will also unblock
3239 * the pad after setting the FLUSHING flag. */
3240 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3241 "Waiting to be unblocked or set flushing");
3242 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3243 GST_PAD_BLOCK_WAIT (pad);
3244 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3245 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3247 /* if the list changed, call the new callbacks (they will not have their
3248 * cookie set to data.cookie */
3249 if (cookie != pad->priv->probe_list_cookie) {
3250 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3251 "probe list changed, restarting");
3255 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3265 GST_DEBUG_OBJECT (pad, "pad is flushing");
3266 return GST_FLOW_FLUSHING;
3270 GST_DEBUG_OBJECT (pad, "data is dropped");
3271 return GST_FLOW_CUSTOM_SUCCESS;
3275 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3276 GST_DEBUG_OBJECT (pad, "data is passed");
3284 * gst_pad_get_offset:
3287 * Get the offset applied to the running time of @pad. @pad has to be a source
3290 * Returns: the offset.
3293 gst_pad_get_offset (GstPad * pad)
3297 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3299 GST_OBJECT_LOCK (pad);
3300 result = pad->offset;
3301 GST_OBJECT_UNLOCK (pad);
3307 * gst_pad_set_offset:
3309 * @offset: the offset
3311 * Set the offset that will be applied to the running time of @pad.
3314 gst_pad_set_offset (GstPad * pad, gint64 offset)
3318 g_return_if_fail (GST_IS_PAD (pad));
3320 GST_OBJECT_LOCK (pad);
3321 /* if nothing changed, do nothing */
3322 if (pad->offset == offset)
3325 pad->offset = offset;
3326 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3328 /* sinkpads will apply their offset the next time a segment
3329 * event is received. */
3330 if (GST_PAD_IS_SINK (pad))
3333 /* resend the last segment event on next buffer push */
3334 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3335 ev->received = FALSE;
3336 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3340 GST_OBJECT_UNLOCK (pad);
3347 /* If TRUE and ret is not OK this means
3348 * that pushing the EOS event failed
3352 /* If called for an event this is
3353 * the event that would be pushed
3354 * next. Don't forward sticky events
3355 * that would come after that */
3359 /* should be called with pad LOCK */
3361 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3363 PushStickyData *data = user_data;
3364 GstEvent *event = ev->event;
3367 GST_DEBUG_OBJECT (pad, "event %s was already received",
3368 GST_EVENT_TYPE_NAME (event));
3372 /* If we're called because of an sticky event, only forward
3373 * events that would come before this new event and the
3375 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3376 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3377 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3378 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3380 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3381 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3384 switch (data->ret) {
3386 ev->received = TRUE;
3387 GST_DEBUG_OBJECT (pad, "event %s marked received",
3388 GST_EVENT_TYPE_NAME (event));
3390 case GST_FLOW_CUSTOM_SUCCESS:
3391 /* we can't assume the event is received when it was dropped */
3392 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3393 GST_EVENT_TYPE_NAME (event));
3394 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3395 data->ret = GST_FLOW_OK;
3397 case GST_FLOW_CUSTOM_SUCCESS_1:
3398 /* event was ignored and should be sent later */
3399 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3400 GST_EVENT_TYPE_NAME (event));
3401 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3402 data->ret = GST_FLOW_OK;
3404 case GST_FLOW_NOT_LINKED:
3405 /* not linked is not a problem, we are sticky so the event will be
3406 * sent later but only for non-EOS events */
3407 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3408 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3409 data->ret = GST_FLOW_OK;
3410 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3413 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3414 gst_flow_get_name (data->ret));
3415 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3419 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3420 data->was_eos = TRUE;
3422 return data->ret == GST_FLOW_OK;
3425 /* check sticky events and push them when needed. should be called
3427 static inline GstFlowReturn
3428 check_sticky (GstPad * pad, GstEvent * event)
3430 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3432 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3433 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3435 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3436 events_foreach (pad, push_sticky, &data);
3438 /* If there's an EOS event we must push it downstream
3439 * even if sending a previous sticky event failed.
3440 * Otherwise the pipeline might wait forever for EOS.
3442 * Only do this if pushing another event than the EOS
3445 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3446 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3448 if (ev && !ev->received) {
3449 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3450 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3451 /* the event could have been dropped. Because this can only
3452 * happen if the user asked for it, it's not an error */
3453 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3454 data.ret = GST_FLOW_OK;
3464 * @pad: a #GstPad to invoke the default query on.
3465 * @query: (transfer none): the #GstQuery to perform.
3467 * Dispatches a query to a pad. The query should have been allocated by the
3468 * caller via one of the type-specific allocation functions. The element that
3469 * the pad belongs to is responsible for filling the query with an appropriate
3470 * response, which should then be parsed with a type-specific query parsing
3473 * Again, the caller is responsible for both the allocation and deallocation of
3474 * the query structure.
3476 * Please also note that some queries might need a running pipeline to work.
3478 * Returns: TRUE if the query could be performed.
3481 gst_pad_query (GstPad * pad, GstQuery * query)
3484 gboolean res, serialized;
3485 GstPadQueryFunction func;
3486 GstPadProbeType type;
3489 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3490 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3492 if (GST_PAD_IS_SRC (pad)) {
3493 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3494 goto wrong_direction;
3495 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3496 } else if (GST_PAD_IS_SINK (pad)) {
3497 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3498 goto wrong_direction;
3499 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3501 goto unknown_direction;
3503 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3504 GST_QUERY_TYPE_NAME (query));
3506 serialized = GST_QUERY_IS_SERIALIZED (query);
3507 if (G_UNLIKELY (serialized))
3508 GST_PAD_STREAM_LOCK (pad);
3510 GST_OBJECT_LOCK (pad);
3511 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3512 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3513 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3515 ACQUIRE_PARENT (pad, parent, no_parent);
3516 GST_OBJECT_UNLOCK (pad);
3518 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3521 res = func (pad, parent, query);
3523 RELEASE_PARENT (parent);
3525 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3526 GST_QUERY_TYPE_NAME (query), res);
3531 GST_OBJECT_LOCK (pad);
3532 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3533 GST_OBJECT_UNLOCK (pad);
3535 if (G_UNLIKELY (serialized))
3536 GST_PAD_STREAM_UNLOCK (pad);
3543 g_warning ("pad %s:%s query %s in wrong direction",
3544 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3549 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3554 GST_DEBUG_OBJECT (pad, "had no parent");
3555 GST_OBJECT_UNLOCK (pad);
3556 if (G_UNLIKELY (serialized))
3557 GST_PAD_STREAM_UNLOCK (pad);
3562 GST_DEBUG_OBJECT (pad, "had no query function");
3563 RELEASE_PARENT (parent);
3564 if (G_UNLIKELY (serialized))
3565 GST_PAD_STREAM_UNLOCK (pad);
3570 GST_DEBUG_OBJECT (pad, "query failed");
3571 if (G_UNLIKELY (serialized))
3572 GST_PAD_STREAM_UNLOCK (pad);
3577 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3578 GST_OBJECT_UNLOCK (pad);
3579 if (G_UNLIKELY (serialized))
3580 GST_PAD_STREAM_UNLOCK (pad);
3582 /* if a probe dropped, we don't sent it further but assume that the probe
3583 * answered the query and return TRUE */
3584 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3594 * gst_pad_peer_query:
3595 * @pad: a #GstPad to invoke the peer query on.
3596 * @query: (transfer none): the #GstQuery to perform.
3598 * Performs gst_pad_query() on the peer of @pad.
3600 * The caller is responsible for both the allocation and deallocation of
3601 * the query structure.
3603 * Returns: TRUE if the query could be performed. This function returns %FALSE
3604 * if @pad has no peer.
3607 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3610 GstPadProbeType type;
3611 gboolean res, serialized;
3614 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3615 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3617 if (GST_PAD_IS_SRC (pad)) {
3618 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3619 goto wrong_direction;
3620 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3621 } else if (GST_PAD_IS_SINK (pad)) {
3622 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3623 goto wrong_direction;
3624 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3626 goto unknown_direction;
3628 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3629 GST_QUERY_TYPE_NAME (query));
3631 serialized = GST_QUERY_IS_SERIALIZED (query);
3633 GST_OBJECT_LOCK (pad);
3634 if (GST_PAD_IS_SRC (pad) && serialized) {
3635 /* all serialized queries on the srcpad trigger push of
3637 if (!check_sticky (pad, NULL) == GST_FLOW_OK)
3641 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3642 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3643 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3645 peerpad = GST_PAD_PEER (pad);
3646 if (G_UNLIKELY (peerpad == NULL))
3649 gst_object_ref (peerpad);
3650 GST_OBJECT_UNLOCK (pad);
3652 res = gst_pad_query (peerpad, query);
3654 gst_object_unref (peerpad);
3659 GST_OBJECT_LOCK (pad);
3660 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3661 GST_OBJECT_UNLOCK (pad);
3668 g_warning ("pad %s:%s query %s in wrong direction",
3669 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3674 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3679 GST_WARNING_OBJECT (pad, "could not send sticky events");
3680 GST_OBJECT_UNLOCK (pad);
3685 GST_INFO_OBJECT (pad, "pad has no peer");
3686 GST_OBJECT_UNLOCK (pad);
3691 GST_DEBUG_OBJECT (pad, "query failed");
3696 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3697 GST_OBJECT_UNLOCK (pad);
3699 /* if a probe dropped, we don't sent it further but assume that the probe
3700 * answered the query and return TRUE */
3701 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3710 /**********************************************************************
3711 * Data passing functions
3714 /* this is the chain function that does not perform the additional argument
3715 * checking for that little extra speed.
3717 static inline GstFlowReturn
3718 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3723 GST_PAD_STREAM_LOCK (pad);
3725 GST_OBJECT_LOCK (pad);
3726 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3729 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3732 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3735 #ifndef G_DISABLE_ASSERT
3736 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3737 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3739 ":%s:<%s:%s> Got data flow before stream-start event",
3740 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3742 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3744 ":%s:<%s:%s> Got data flow before segment event",
3745 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3747 pad->priv->last_cookie = pad->priv->events_cookie;
3751 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3753 PROBE_PUSH (pad, type, data, probe_stopped);
3755 parent = GST_OBJECT_PARENT (pad);
3756 GST_OBJECT_UNLOCK (pad);
3758 /* NOTE: we read the chainfunc unlocked.
3759 * we cannot hold the lock for the pad so we might send
3760 * the data to the wrong function. This is not really a
3761 * problem since functions are assigned at creation time
3762 * and don't change that often... */
3763 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3764 GstPadChainFunction chainfunc;
3766 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3769 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3770 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3771 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3773 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3775 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3776 "called chainfunction &%s with buffer %p, returned %s",
3777 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3779 GstPadChainListFunction chainlistfunc;
3781 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3784 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3785 "calling chainlistfunction &%s",
3786 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3788 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3790 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3791 "called chainlistfunction &%s, returned %s",
3792 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3795 GST_PAD_STREAM_UNLOCK (pad);
3802 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3803 "chaining, but pad was flushing");
3804 GST_OBJECT_UNLOCK (pad);
3805 GST_PAD_STREAM_UNLOCK (pad);
3806 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3807 return GST_FLOW_FLUSHING;
3811 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3812 GST_OBJECT_UNLOCK (pad);
3813 GST_PAD_STREAM_UNLOCK (pad);
3814 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3815 return GST_FLOW_EOS;
3819 g_critical ("chain on pad %s:%s but it was not in push mode",
3820 GST_DEBUG_PAD_NAME (pad));
3821 GST_OBJECT_UNLOCK (pad);
3822 GST_PAD_STREAM_UNLOCK (pad);
3823 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3824 return GST_FLOW_ERROR;
3828 GST_OBJECT_UNLOCK (pad);
3829 GST_PAD_STREAM_UNLOCK (pad);
3830 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3833 case GST_FLOW_CUSTOM_SUCCESS:
3834 GST_DEBUG_OBJECT (pad, "dropped buffer");
3838 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
3845 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3846 g_critical ("chain on pad %s:%s but it has no chainfunction",
3847 GST_DEBUG_PAD_NAME (pad));
3848 GST_PAD_STREAM_UNLOCK (pad);
3849 return GST_FLOW_NOT_SUPPORTED;
3855 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3856 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3859 * Chain a buffer to @pad.
3861 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3863 * If the buffer type is not acceptable for @pad (as negotiated with a
3864 * preceding GST_EVENT_CAPS event), this function returns
3865 * #GST_FLOW_NOT_NEGOTIATED.
3867 * The function proceeds calling the chain function installed on @pad (see
3868 * gst_pad_set_chain_function()) and the return value of that function is
3869 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3872 * In all cases, success or failure, the caller loses its reference to @buffer
3873 * after calling this function.
3875 * Returns: a #GstFlowReturn from the pad.
3880 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3882 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3883 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3884 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3886 return gst_pad_chain_data_unchecked (pad,
3887 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3890 static GstFlowReturn
3891 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3892 GstBufferList * list)
3898 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3900 len = gst_buffer_list_length (list);
3903 for (i = 0; i < len; i++) {
3904 buffer = gst_buffer_list_get (list, i);
3906 gst_pad_chain_data_unchecked (pad,
3907 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3908 gst_buffer_ref (buffer));
3909 if (ret != GST_FLOW_OK)
3912 gst_buffer_list_unref (list);
3918 * gst_pad_chain_list:
3919 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3920 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3923 * Chain a bufferlist to @pad.
3925 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3927 * If @pad was not negotiated properly with a CAPS event, this function
3928 * returns #GST_FLOW_NOT_NEGOTIATED.
3930 * The function proceeds calling the chainlist function installed on @pad (see
3931 * gst_pad_set_chain_list_function()) and the return value of that function is
3932 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3933 * chainlist function.
3935 * In all cases, success or failure, the caller loses its reference to @list
3936 * after calling this function.
3940 * Returns: a #GstFlowReturn from the pad.
3943 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3945 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3946 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3947 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3949 return gst_pad_chain_data_unchecked (pad,
3950 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3953 static GstFlowReturn
3954 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3959 GST_OBJECT_LOCK (pad);
3960 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3963 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3966 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3969 #ifndef G_DISABLE_ASSERT
3970 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3971 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3973 ":%s:<%s:%s> Got data flow before stream-start event",
3974 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3976 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3978 ":%s:<%s:%s> Got data flow before segment event",
3979 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3981 pad->priv->last_cookie = pad->priv->events_cookie;
3985 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3988 /* do block probes */
3989 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3991 /* recheck sticky events because the probe might have cause a relink */
3992 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3995 /* do post-blocking probes */
3996 PROBE_PUSH (pad, type, data, probe_stopped);
3998 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4001 /* take ref to peer pad before releasing the lock */
4002 gst_object_ref (peer);
4004 GST_OBJECT_UNLOCK (pad);
4006 ret = gst_pad_chain_data_unchecked (peer, type, data);
4008 gst_object_unref (peer);
4010 GST_OBJECT_LOCK (pad);
4012 if (pad->priv->using == 0) {
4013 /* pad is not active anymore, trigger idle callbacks */
4014 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4015 probe_stopped, ret);
4017 GST_OBJECT_UNLOCK (pad);
4021 /* ERROR recovery here */
4025 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4026 "pushing, but pad was flushing");
4027 GST_OBJECT_UNLOCK (pad);
4028 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4029 return GST_FLOW_FLUSHING;
4033 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4034 GST_OBJECT_UNLOCK (pad);
4035 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4036 return GST_FLOW_EOS;
4040 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4041 GST_DEBUG_PAD_NAME (pad));
4042 GST_OBJECT_UNLOCK (pad);
4043 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4044 return GST_FLOW_ERROR;
4048 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4049 "error pushing events, return %s", gst_flow_get_name (ret));
4050 GST_OBJECT_UNLOCK (pad);
4051 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4056 GST_OBJECT_UNLOCK (pad);
4057 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4060 case GST_FLOW_CUSTOM_SUCCESS:
4061 GST_DEBUG_OBJECT (pad, "dropped buffer");
4065 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4072 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4073 "pushing, but it was not linked");
4074 GST_OBJECT_UNLOCK (pad);
4075 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4076 return GST_FLOW_NOT_LINKED;
4082 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4083 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4086 * Pushes a buffer to the peer of @pad.
4088 * This function will call installed block probes before triggering any
4089 * installed data probes.
4091 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4092 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4095 * In all cases, success or failure, the caller loses its reference to @buffer
4096 * after calling this function.
4098 * Returns: a #GstFlowReturn from the peer pad.
4103 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4105 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4106 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4107 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4109 return gst_pad_push_data (pad,
4110 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4114 * gst_pad_push_list:
4115 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4116 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4119 * Pushes a buffer list to the peer of @pad.
4121 * This function will call installed block probes before triggering any
4122 * installed data probes.
4124 * The function proceeds calling the chain function on the peer pad and returns
4125 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4126 * be returned. If the peer pad does not have any installed chainlist function
4127 * every group buffer of the list will be merged into a normal #GstBuffer and
4128 * chained via gst_pad_chain().
4130 * In all cases, success or failure, the caller loses its reference to @list
4131 * after calling this function.
4133 * Returns: a #GstFlowReturn from the peer pad.
4138 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4140 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4141 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4142 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4144 return gst_pad_push_data (pad,
4145 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4148 static GstFlowReturn
4149 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4150 GstBuffer ** buffer)
4153 GstPadGetRangeFunction getrangefunc;
4157 GST_PAD_STREAM_LOCK (pad);
4159 GST_OBJECT_LOCK (pad);
4160 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4163 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4166 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4171 /* when one of the probes returns DROPPED, probe_stopped will be called
4172 * and we skip calling the getrange function, res_buf should then contain a
4173 * valid result buffer */
4174 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4175 res_buf, offset, size, probe_stopped);
4177 /* recheck sticky events because the probe might have cause a relink */
4178 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4181 ACQUIRE_PARENT (pad, parent, no_parent);
4182 GST_OBJECT_UNLOCK (pad);
4184 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4187 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4188 "calling getrangefunc %s, offset %"
4189 G_GUINT64_FORMAT ", size %u",
4190 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4192 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4194 RELEASE_PARENT (parent);
4196 if (G_UNLIKELY (ret != GST_FLOW_OK))
4197 goto get_range_failed;
4199 /* can only fire the signal if we have a valid buffer */
4200 GST_OBJECT_LOCK (pad);
4202 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4203 res_buf, offset, size, probe_stopped_unref);
4204 GST_OBJECT_UNLOCK (pad);
4206 GST_PAD_STREAM_UNLOCK (pad);
4215 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4216 "getrange, but pad was flushing");
4217 GST_OBJECT_UNLOCK (pad);
4218 GST_PAD_STREAM_UNLOCK (pad);
4219 return GST_FLOW_FLUSHING;
4223 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4224 GST_DEBUG_PAD_NAME (pad));
4225 GST_OBJECT_UNLOCK (pad);
4226 GST_PAD_STREAM_UNLOCK (pad);
4227 return GST_FLOW_ERROR;
4231 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4232 GST_OBJECT_UNLOCK (pad);
4233 GST_PAD_STREAM_UNLOCK (pad);
4238 GST_DEBUG_OBJECT (pad, "no parent");
4239 GST_OBJECT_UNLOCK (pad);
4240 GST_PAD_STREAM_UNLOCK (pad);
4241 return GST_FLOW_FLUSHING;
4245 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4246 GST_DEBUG_PAD_NAME (pad));
4247 RELEASE_PARENT (parent);
4248 GST_PAD_STREAM_UNLOCK (pad);
4249 return GST_FLOW_NOT_SUPPORTED;
4253 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4254 "probe returned %s", gst_flow_get_name (ret));
4255 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4257 /* the probe filled the buffer and asks us to not call the getrange
4258 * anymore, we continue with the post probes then. */
4259 GST_DEBUG_OBJECT (pad, "handled buffer");
4263 /* no buffer, we are EOS */
4264 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4268 GST_OBJECT_UNLOCK (pad);
4269 GST_PAD_STREAM_UNLOCK (pad);
4273 probe_stopped_unref:
4275 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4276 "probe returned %s", gst_flow_get_name (ret));
4277 /* if we drop here, it signals EOS */
4278 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4280 GST_OBJECT_UNLOCK (pad);
4281 GST_PAD_STREAM_UNLOCK (pad);
4282 if (*buffer == NULL)
4283 gst_buffer_unref (res_buf);
4288 GST_PAD_STREAM_UNLOCK (pad);
4289 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4290 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4291 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4297 * gst_pad_get_range:
4298 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4299 * @offset: The start offset of the buffer
4300 * @size: The length of the buffer
4301 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4302 * returns #GST_FLOW_ERROR if %NULL.
4304 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4305 * immediately and @buffer is %NULL.
4307 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4308 * description of a getrange function. If @pad has no getrange function
4309 * installed (see gst_pad_set_getrange_function()) this function returns
4310 * #GST_FLOW_NOT_SUPPORTED.
4312 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4313 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4314 * must be freed with gst_buffer_unref() after usage.
4316 * When @buffer points to a variable that points to a valid #GstBuffer, the
4317 * buffer will be filled with the result data when this function returns
4318 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4319 * @size bytes will be filled in the result buffer and its size will be updated
4322 * Note that less than @size bytes can be returned in @buffer when, for example,
4323 * an EOS condition is near or when @buffer is not large enough to hold @size
4324 * bytes. The caller should check the result buffer size to get the result size.
4326 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4327 * will be unchanged.
4329 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4331 * Returns: a #GstFlowReturn from the pad.
4336 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4337 GstBuffer ** buffer)
4339 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4340 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4341 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4342 g_return_val_if_fail (*buffer == NULL
4343 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4345 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4349 * gst_pad_pull_range:
4350 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4351 * @offset: The start offset of the buffer
4352 * @size: The length of the buffer
4353 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4354 * GST_FLOW_ERROR if %NULL.
4356 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4358 * This function will first trigger the pad block signal if it was
4361 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4362 * function returns the result of gst_pad_get_range() on the peer pad.
4363 * See gst_pad_get_range() for a list of return values and for the
4364 * semantics of the arguments of this function.
4366 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4367 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4368 * must be freed with gst_buffer_unref() after usage. When this function
4369 * returns any other result value, @buffer will still point to NULL.
4371 * When @buffer points to a variable that points to a valid #GstBuffer, the
4372 * buffer will be filled with the result data when this function returns
4373 * #GST_FLOW_OK. When this function returns any other result value,
4374 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4375 * @size bytes will be filled in the result buffer and its size will be updated
4378 * Note that less than @size bytes can be returned in @buffer when, for example,
4379 * an EOS condition is near or when @buffer is not large enough to hold @size
4380 * bytes. The caller should check the result buffer size to get the result size.
4382 * Returns: a #GstFlowReturn from the peer pad.
4387 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4388 GstBuffer ** buffer)
4394 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4395 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4396 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4397 g_return_val_if_fail (*buffer == NULL
4398 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4400 GST_OBJECT_LOCK (pad);
4401 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4404 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4409 /* when one of the probes returns DROPPED, probe_stopped will be
4410 * called and we skip calling the peer getrange function. *buffer should then
4411 * contain a valid buffer */
4412 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4413 res_buf, offset, size, probe_stopped);
4415 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4418 gst_object_ref (peer);
4420 GST_OBJECT_UNLOCK (pad);
4422 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4424 gst_object_unref (peer);
4426 GST_OBJECT_LOCK (pad);
4428 if (pad->priv->using == 0) {
4429 /* pad is not active anymore, trigger idle callbacks */
4430 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4431 probe_stopped_unref, ret);
4434 if (G_UNLIKELY (ret != GST_FLOW_OK))
4435 goto pull_range_failed;
4438 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4439 res_buf, offset, size, probe_stopped_unref);
4441 GST_OBJECT_UNLOCK (pad);
4447 /* ERROR recovery here */
4450 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4451 "pullrange, but pad was flushing");
4452 GST_OBJECT_UNLOCK (pad);
4453 return GST_FLOW_FLUSHING;
4457 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4458 GST_DEBUG_PAD_NAME (pad));
4459 GST_OBJECT_UNLOCK (pad);
4460 return GST_FLOW_ERROR;
4464 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4465 gst_flow_get_name (ret));
4466 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4468 /* the probe filled the buffer and asks us to not forward to the peer
4469 * anymore, we continue with the post probes then */
4470 GST_DEBUG_OBJECT (pad, "handled buffer");
4474 /* no buffer, we are EOS then */
4475 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4479 GST_OBJECT_UNLOCK (pad);
4484 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4485 "pulling range, but it was not linked");
4486 GST_OBJECT_UNLOCK (pad);
4487 return GST_FLOW_NOT_LINKED;
4491 GST_OBJECT_UNLOCK (pad);
4492 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4493 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4494 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4497 probe_stopped_unref:
4499 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4500 "post probe returned %s", gst_flow_get_name (ret));
4501 GST_OBJECT_UNLOCK (pad);
4502 /* if we drop here, it signals EOS */
4503 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4505 if (*buffer == NULL)
4506 gst_buffer_unref (res_buf);
4511 /* must be called with pad object lock */
4512 static GstFlowReturn
4513 store_sticky_event (GstPad * pad, GstEvent * event)
4518 gboolean res = FALSE;
4519 const gchar *name = NULL;
4520 gboolean insert = TRUE;
4522 type = GST_EVENT_TYPE (event);
4524 /* Store all sticky events except SEGMENT/SEGMENT when we're flushing,
4525 * otherwise they can be dropped and nothing would ever resend them.
4526 * Only do that for activated pads though, everything else is a bug!
4528 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4529 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4530 || type == GST_EVENT_EOS))))
4533 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4536 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4537 name = gst_structure_get_name (gst_event_get_structure (event));
4539 events = pad->priv->events;
4542 for (i = 0; i < len; i++) {
4543 PadEvent *ev = &g_array_index (events, PadEvent, i);
4545 if (ev->event == NULL)
4548 if (type == GST_EVENT_TYPE (ev->event)) {
4549 /* matching types, check matching name if needed */
4550 if (name && !gst_event_has_name (ev->event, name))
4554 if ((res = gst_event_replace (&ev->event, event)))
4555 ev->received = FALSE;
4561 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4562 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4563 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4564 * storing the sticky ordered we can check that this is respected. */
4565 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4566 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4568 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4569 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4570 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4571 gst_event_type_get_name (type));
4577 ev.event = gst_event_ref (event);
4578 ev.received = FALSE;
4579 g_array_insert_val (events, i, ev);
4584 pad->priv->events_cookie++;
4585 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4587 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4589 switch (GST_EVENT_TYPE (event)) {
4590 case GST_EVENT_CAPS:
4591 GST_OBJECT_UNLOCK (pad);
4593 GST_DEBUG_OBJECT (pad, "notify caps");
4594 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4596 GST_OBJECT_LOCK (pad);
4602 if (type == GST_EVENT_EOS)
4603 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4605 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4610 GST_DEBUG_OBJECT (pad, "pad is flushing");
4611 return GST_FLOW_FLUSHING;
4615 GST_DEBUG_OBJECT (pad, "pad is EOS");
4616 return GST_FLOW_EOS;
4621 * gst_pad_store_sticky_event:
4623 * @event: a #GstEvent
4625 * Store the sticky @event on @pad
4627 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4628 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4633 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4637 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4638 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4640 GST_OBJECT_LOCK (pad);
4641 ret = store_sticky_event (pad, event);
4642 GST_OBJECT_UNLOCK (pad);
4648 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
4650 PushStickyData *data = user_data;
4652 /* Forward all sticky events before our current one that are pending */
4653 if (ev->event != data->event
4654 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
4655 return push_sticky (pad, ev, data);
4660 /* should be called with pad LOCK */
4661 static GstFlowReturn
4662 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4663 GstPadProbeType type)
4667 GstEventType event_type;
4669 /* Two checks to be made:
4670 * . (un)set the FLUSHING flag for flushing events,
4671 * . handle pad blocking */
4672 event_type = GST_EVENT_TYPE (event);
4673 switch (event_type) {
4674 case GST_EVENT_FLUSH_START:
4675 GST_PAD_SET_FLUSHING (pad);
4677 GST_PAD_BLOCK_BROADCAST (pad);
4678 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4680 case GST_EVENT_FLUSH_STOP:
4681 GST_PAD_UNSET_FLUSHING (pad);
4683 /* Remove sticky EOS events */
4684 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4685 remove_event_by_type (pad, GST_EVENT_EOS);
4686 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4687 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4689 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4693 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4696 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4697 * checked already or this is called as part of pushing sticky events,
4698 * in which case we still want to forward the EOS event downstream.
4701 switch (GST_EVENT_TYPE (event)) {
4702 case GST_EVENT_SEGMENT:
4703 /* pass the adjusted segment event on. We need to do this even if
4704 * there is no peer pad because of the probes. */
4705 event = apply_pad_offset (pad, event);
4707 case GST_EVENT_RECONFIGURE:
4708 if (GST_PAD_IS_SINK (pad))
4709 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4714 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4715 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4720 /* send probes after modifying the events above */
4721 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4723 /* recheck sticky events because the probe might have cause a relink */
4724 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
4725 && (GST_EVENT_IS_SERIALIZED (event)
4726 || GST_EVENT_IS_STICKY (event))) {
4727 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4728 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4730 /* Push all sticky events before our current one
4731 * that have changed */
4732 events_foreach (pad, sticky_changed, &data);
4735 /* now check the peer pad */
4736 peerpad = GST_PAD_PEER (pad);
4737 if (peerpad == NULL)
4740 gst_object_ref (peerpad);
4742 GST_OBJECT_UNLOCK (pad);
4744 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4745 event, GST_EVENT_TYPE_NAME (event), peerpad);
4747 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4749 /* Note: we gave away ownership of the event at this point but we can still
4750 * print the old pointer */
4751 GST_LOG_OBJECT (pad, "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s",
4752 event, peerpad, gst_flow_get_name (ret));
4754 gst_object_unref (peerpad);
4756 GST_OBJECT_LOCK (pad);
4758 if (pad->priv->using == 0) {
4759 /* pad is not active anymore, trigger idle callbacks */
4760 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4761 idle_probe_stopped, ret);
4765 /* ERROR handling */
4768 GST_DEBUG_OBJECT (pad, "We're flushing");
4769 gst_event_unref (event);
4770 return GST_FLOW_FLUSHING;
4774 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4775 gst_event_unref (event);
4778 case GST_FLOW_CUSTOM_SUCCESS:
4779 GST_DEBUG_OBJECT (pad, "dropped event");
4782 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4789 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4790 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4791 gst_event_unref (event);
4793 /* unlinked pads should not influence latency configuration */
4794 if (event_type == GST_EVENT_LATENCY)
4797 return GST_FLOW_NOT_LINKED;
4801 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4807 * gst_pad_push_event:
4808 * @pad: a #GstPad to push the event to.
4809 * @event: (transfer full): the #GstEvent to send to the pad.
4811 * Sends the event to the peer of the given pad. This function is
4812 * mainly used by elements to send events to their peer
4815 * This function takes ownership of the provided event so you should
4816 * gst_event_ref() it if you want to reuse the event after this call.
4818 * Returns: TRUE if the event was handled.
4823 gst_pad_push_event (GstPad * pad, GstEvent * event)
4825 gboolean res = FALSE;
4826 GstPadProbeType type;
4827 gboolean sticky, serialized;
4829 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4830 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4832 if (GST_PAD_IS_SRC (pad)) {
4833 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4834 goto wrong_direction;
4835 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4836 } else if (GST_PAD_IS_SINK (pad)) {
4837 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4838 goto wrong_direction;
4839 /* events pushed on sinkpad never are sticky */
4840 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4842 goto unknown_direction;
4844 GST_OBJECT_LOCK (pad);
4845 sticky = GST_EVENT_IS_STICKY (event);
4846 serialized = GST_EVENT_IS_SERIALIZED (event);
4849 /* srcpad sticky events are stored immediately, the received flag is set
4850 * to FALSE and will be set to TRUE when we can successfully push the
4851 * event to the peer pad */
4852 switch (store_sticky_event (pad, event)) {
4853 case GST_FLOW_FLUSHING:
4861 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4862 /* all serialized or sticky events on the srcpad trigger push of
4864 res = (check_sticky (pad, event) == GST_FLOW_OK);
4869 /* other events are pushed right away */
4870 ret = gst_pad_push_event_unchecked (pad, event, type);
4871 /* dropped events by a probe are not an error */
4872 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4874 /* Errors in sticky event pushing are no problem and ignored here
4875 * as they will cause more meaningful errors during data flow.
4876 * For EOS events, that are not followed by data flow, we still
4877 * return FALSE here though.
4879 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4881 gst_event_unref (event);
4883 GST_OBJECT_UNLOCK (pad);
4887 /* ERROR handling */
4890 g_warning ("pad %s:%s pushing %s event in wrong direction",
4891 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4892 gst_event_unref (event);
4897 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4898 gst_event_unref (event);
4903 GST_DEBUG_OBJECT (pad, "We're flushing");
4904 GST_OBJECT_UNLOCK (pad);
4905 gst_event_unref (event);
4910 GST_DEBUG_OBJECT (pad, "We're EOS");
4911 GST_OBJECT_UNLOCK (pad);
4912 gst_event_unref (event);
4917 /* Check if we can call the event function with the given event */
4918 static GstFlowReturn
4919 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4923 switch (GST_EVENT_TYPE (event)) {
4924 case GST_EVENT_CAPS:
4926 /* backwards compatibility mode for caps */
4927 gst_event_parse_caps (event, &caps);
4929 if (!gst_pad_query_accept_caps (pad, caps))
4941 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4942 "caps %" GST_PTR_FORMAT " not accepted", caps);
4943 return GST_FLOW_NOT_NEGOTIATED;
4947 static GstFlowReturn
4948 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4949 GstPadProbeType type)
4952 GstEventType event_type;
4953 gboolean serialized, need_unlock = FALSE, sticky;
4954 GstPadEventFunction eventfunc;
4957 GST_OBJECT_LOCK (pad);
4958 if (GST_PAD_IS_SINK (pad))
4959 serialized = GST_EVENT_IS_SERIALIZED (event);
4962 sticky = GST_EVENT_IS_STICKY (event);
4963 event_type = GST_EVENT_TYPE (event);
4964 switch (event_type) {
4965 case GST_EVENT_FLUSH_START:
4966 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4967 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4969 /* can't even accept a flush begin event when flushing */
4970 if (GST_PAD_IS_FLUSHING (pad))
4973 GST_PAD_SET_FLUSHING (pad);
4974 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4976 case GST_EVENT_FLUSH_STOP:
4977 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4978 GST_PAD_UNSET_FLUSHING (pad);
4979 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4981 /* Remove pending EOS events */
4982 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
4983 remove_event_by_type (pad, GST_EVENT_EOS);
4984 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4985 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4987 GST_OBJECT_UNLOCK (pad);
4988 /* grab stream lock */
4989 GST_PAD_STREAM_LOCK (pad);
4991 GST_OBJECT_LOCK (pad);
4992 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4995 case GST_EVENT_RECONFIGURE:
4996 if (GST_PAD_IS_SRC (pad))
4997 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4999 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5000 "have event type %" GST_PTR_FORMAT, event);
5002 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5006 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5009 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5010 GST_OBJECT_UNLOCK (pad);
5011 GST_PAD_STREAM_LOCK (pad);
5013 GST_OBJECT_LOCK (pad);
5014 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5017 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5021 switch (GST_EVENT_TYPE (event)) {
5022 case GST_EVENT_SEGMENT:
5023 event = apply_pad_offset (pad, event);
5031 /* now do the probe */
5033 type | GST_PAD_PROBE_TYPE_PUSH |
5034 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5036 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5038 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5041 ACQUIRE_PARENT (pad, parent, no_parent);
5042 GST_OBJECT_UNLOCK (pad);
5044 ret = pre_eventfunc_check (pad, event);
5045 if (G_UNLIKELY (ret != GST_FLOW_OK))
5046 goto precheck_failed;
5049 gst_event_ref (event);
5051 if (eventfunc (pad, parent, event)) {
5054 /* something went wrong */
5055 switch (event_type) {
5056 case GST_EVENT_CAPS:
5057 ret = GST_FLOW_NOT_NEGOTIATED;
5060 ret = GST_FLOW_ERROR;
5064 RELEASE_PARENT (parent);
5066 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5069 if (ret == GST_FLOW_OK) {
5070 GST_OBJECT_LOCK (pad);
5071 /* after the event function accepted the event, we can store the sticky
5072 * event on the pad */
5073 switch (store_sticky_event (pad, event)) {
5074 case GST_FLOW_FLUSHING:
5081 GST_OBJECT_UNLOCK (pad);
5083 gst_event_unref (event);
5087 GST_PAD_STREAM_UNLOCK (pad);
5091 /* ERROR handling */
5094 GST_OBJECT_UNLOCK (pad);
5096 GST_PAD_STREAM_UNLOCK (pad);
5097 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5098 "Received event on flushing pad. Discarding");
5099 gst_event_unref (event);
5100 return GST_FLOW_FLUSHING;
5104 GST_OBJECT_UNLOCK (pad);
5106 GST_PAD_STREAM_UNLOCK (pad);
5107 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5108 "Received event on EOS pad. Discarding");
5109 gst_event_unref (event);
5110 return GST_FLOW_EOS;
5114 GST_OBJECT_UNLOCK (pad);
5116 GST_PAD_STREAM_UNLOCK (pad);
5117 gst_event_unref (event);
5120 case GST_FLOW_CUSTOM_SUCCESS:
5121 GST_DEBUG_OBJECT (pad, "dropped event");
5125 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5132 g_warning ("pad %s:%s has no event handler, file a bug.",
5133 GST_DEBUG_PAD_NAME (pad));
5134 GST_OBJECT_UNLOCK (pad);
5136 GST_PAD_STREAM_UNLOCK (pad);
5137 gst_event_unref (event);
5138 return GST_FLOW_NOT_SUPPORTED;
5142 GST_DEBUG_OBJECT (pad, "no parent");
5143 GST_OBJECT_UNLOCK (pad);
5145 GST_PAD_STREAM_UNLOCK (pad);
5146 gst_event_unref (event);
5147 return GST_FLOW_FLUSHING;
5151 GST_DEBUG_OBJECT (pad, "pre event check failed");
5152 RELEASE_PARENT (parent);
5154 GST_PAD_STREAM_UNLOCK (pad);
5155 gst_event_unref (event);
5161 * gst_pad_send_event:
5162 * @pad: a #GstPad to send the event to.
5163 * @event: (transfer full): the #GstEvent to send to the pad.
5165 * Sends the event to the pad. This function can be used
5166 * by applications to send events in the pipeline.
5168 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5169 * sink pad, @event should be a downstream event. For example, you would not
5170 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5171 * Furthermore, some downstream events have to be serialized with data flow,
5172 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5173 * the event needs to be serialized with data flow, this function will take the
5174 * pad's stream lock while calling its event function.
5176 * To find out whether an event type is upstream, downstream, or downstream and
5177 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5178 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5179 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5180 * plugin doesn't need to bother itself with this information; the core handles
5181 * all necessary locks and checks.
5183 * This function takes ownership of the provided event so you should
5184 * gst_event_ref() it if you want to reuse the event after this call.
5186 * Returns: TRUE if the event was handled.
5189 gst_pad_send_event (GstPad * pad, GstEvent * event)
5192 GstPadProbeType type;
5194 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5195 g_return_val_if_fail (event != NULL, FALSE);
5197 if (GST_PAD_IS_SINK (pad)) {
5198 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5199 goto wrong_direction;
5200 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5201 } else if (GST_PAD_IS_SRC (pad)) {
5202 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5203 goto wrong_direction;
5204 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5206 goto unknown_direction;
5208 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5215 /* ERROR handling */
5218 g_warning ("pad %s:%s sending %s event in wrong direction",
5219 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5220 gst_event_unref (event);
5225 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5226 gst_event_unref (event);
5232 * gst_pad_set_element_private:
5233 * @pad: the #GstPad to set the private data of.
5234 * @priv: The private data to attach to the pad.
5236 * Set the given private data gpointer on the pad.
5237 * This function can only be used by the element that owns the pad.
5238 * No locking is performed in this function.
5241 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5243 pad->element_private = priv;
5247 * gst_pad_get_element_private:
5248 * @pad: the #GstPad to get the private data of.
5250 * Gets the private data of a pad.
5251 * No locking is performed in this function.
5253 * Returns: (transfer none): a #gpointer to the private data.
5256 gst_pad_get_element_private (GstPad * pad)
5258 return pad->element_private;
5262 * gst_pad_get_sticky_event:
5263 * @pad: the #GstPad to get the event from.
5264 * @event_type: the #GstEventType that should be retrieved.
5265 * @idx: the index of the event
5267 * Returns a new reference of the sticky event of type @event_type
5270 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
5271 * event of @event_type was on @pad. Unref after usage.
5274 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5276 GstEvent *event = NULL;
5279 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5280 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5282 GST_OBJECT_LOCK (pad);
5283 ev = find_event_by_type (pad, event_type, idx);
5284 if (ev && (event = ev->event))
5285 gst_event_ref (event);
5286 GST_OBJECT_UNLOCK (pad);
5293 GstPadStickyEventsForeachFunction func;
5298 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5300 ForeachDispatch *data = user_data;
5301 gboolean ret = TRUE;
5304 GST_OBJECT_UNLOCK (pad);
5306 ret = data->func (pad, &ev->event, data->user_data);
5308 GST_OBJECT_LOCK (pad);
5315 * gst_pad_sticky_events_foreach:
5316 * @pad: the #GstPad that should be used for iteration.
5317 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5318 * should be called for every event.
5319 * @user_data: (closure): the optional user data.
5321 * Iterates all sticky events on @pad and calls @foreach_func for every
5322 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5325 gst_pad_sticky_events_foreach (GstPad * pad,
5326 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5328 ForeachDispatch data;
5330 g_return_if_fail (GST_IS_PAD (pad));
5331 g_return_if_fail (foreach_func != NULL);
5333 data.func = foreach_func;
5334 data.user_data = user_data;
5336 GST_OBJECT_LOCK (pad);
5337 events_foreach (pad, foreach_dispatch_function, &data);
5338 GST_OBJECT_UNLOCK (pad);
5342 do_stream_status (GstPad * pad, GstStreamStatusType type,
5343 GThread * thread, GstTask * task)
5347 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5349 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5350 if (GST_IS_ELEMENT (parent)) {
5351 GstMessage *message;
5352 GValue value = { 0 };
5354 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5355 gchar *tname, *ename, *pname;
5357 /* create a good task name */
5358 ename = gst_element_get_name (parent);
5359 pname = gst_pad_get_name (pad);
5360 tname = g_strdup_printf ("%s:%s", ename, pname);
5364 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5368 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5371 g_value_init (&value, GST_TYPE_TASK);
5372 g_value_set_object (&value, task);
5373 gst_message_set_stream_status_object (message, &value);
5374 g_value_unset (&value);
5376 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5377 gst_element_post_message (parent, message);
5379 gst_object_unref (parent);
5384 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5386 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5391 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5393 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5398 * gst_pad_start_task:
5399 * @pad: the #GstPad to start the task of
5400 * @func: the task function to call
5401 * @user_data: user data passed to the task function
5402 * @notify: called when @user_data is no longer referenced
5404 * Starts a task that repeatedly calls @func with @user_data. This function
5405 * is mostly used in pad activation functions to start the dataflow.
5406 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5407 * before @func is called.
5409 * Returns: a %TRUE if the task could be started.
5412 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5413 GDestroyNotify notify)
5418 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5419 g_return_val_if_fail (func != NULL, FALSE);
5421 GST_DEBUG_OBJECT (pad, "start task");
5423 GST_OBJECT_LOCK (pad);
5424 task = GST_PAD_TASK (pad);
5426 task = gst_task_new (func, user_data, notify);
5427 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5428 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5429 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5430 GST_INFO_OBJECT (pad, "created task %p", task);
5431 GST_PAD_TASK (pad) = task;
5432 gst_object_ref (task);
5433 /* release lock to post the message */
5434 GST_OBJECT_UNLOCK (pad);
5436 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5438 gst_object_unref (task);
5440 GST_OBJECT_LOCK (pad);
5441 /* nobody else is supposed to have changed the pad now */
5442 if (GST_PAD_TASK (pad) != task)
5443 goto concurrent_stop;
5445 res = gst_task_set_state (task, GST_TASK_STARTED);
5446 GST_OBJECT_UNLOCK (pad);
5453 GST_OBJECT_UNLOCK (pad);
5459 * gst_pad_pause_task:
5460 * @pad: the #GstPad to pause the task of
5462 * Pause the task of @pad. This function will also wait until the
5463 * function executed by the task is finished if this function is not
5464 * called from the task function.
5466 * Returns: a TRUE if the task could be paused or FALSE when the pad
5470 gst_pad_pause_task (GstPad * pad)
5475 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5477 GST_DEBUG_OBJECT (pad, "pause task");
5479 GST_OBJECT_LOCK (pad);
5480 task = GST_PAD_TASK (pad);
5483 res = gst_task_set_state (task, GST_TASK_PAUSED);
5484 GST_OBJECT_UNLOCK (pad);
5486 /* wait for task function to finish, this lock is recursive so it does nothing
5487 * when the pause is called from the task itself */
5488 GST_PAD_STREAM_LOCK (pad);
5489 GST_PAD_STREAM_UNLOCK (pad);
5495 GST_DEBUG_OBJECT (pad, "pad has no task");
5496 GST_OBJECT_UNLOCK (pad);
5502 * gst_pad_stop_task:
5503 * @pad: the #GstPad to stop the task of
5505 * Stop the task of @pad. This function will also make sure that the
5506 * function executed by the task will effectively stop if not called
5507 * from the GstTaskFunction.
5509 * This function will deadlock if called from the GstTaskFunction of
5510 * the task. Use gst_task_pause() instead.
5512 * Regardless of whether the pad has a task, the stream lock is acquired and
5513 * released so as to ensure that streaming through this pad has finished.
5515 * Returns: a TRUE if the task could be stopped or FALSE on error.
5518 gst_pad_stop_task (GstPad * pad)
5523 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5525 GST_DEBUG_OBJECT (pad, "stop task");
5527 GST_OBJECT_LOCK (pad);
5528 task = GST_PAD_TASK (pad);
5531 GST_PAD_TASK (pad) = NULL;
5532 res = gst_task_set_state (task, GST_TASK_STOPPED);
5533 GST_OBJECT_UNLOCK (pad);
5535 GST_PAD_STREAM_LOCK (pad);
5536 GST_PAD_STREAM_UNLOCK (pad);
5538 if (!gst_task_join (task))
5541 gst_object_unref (task);
5547 GST_DEBUG_OBJECT (pad, "no task");
5548 GST_OBJECT_UNLOCK (pad);
5550 GST_PAD_STREAM_LOCK (pad);
5551 GST_PAD_STREAM_UNLOCK (pad);
5553 /* this is not an error */
5558 /* this is bad, possibly the application tried to join the task from
5559 * the task's thread. We install the task again so that it will be stopped
5560 * again from the right thread next time hopefully. */
5561 GST_OBJECT_LOCK (pad);
5562 GST_DEBUG_OBJECT (pad, "join failed");
5563 /* we can only install this task if there was no other task */
5564 if (GST_PAD_TASK (pad) == NULL)
5565 GST_PAD_TASK (pad) = task;
5566 GST_OBJECT_UNLOCK (pad);
5573 * gst_pad_probe_info_get_event:
5574 * @info: a #GstPadProbeInfo
5576 * Returns: (transfer none): The #GstEvent from the probe
5580 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5582 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5583 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5585 return GST_PAD_PROBE_INFO_EVENT (info);
5590 * gst_pad_probe_info_get_query:
5591 * @info: a #GstPadProbeInfo
5593 * Returns: (transfer none): The #GstQuery from the probe
5597 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5599 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5600 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5602 return GST_PAD_PROBE_INFO_QUERY (info);
5606 * gst_pad_probe_info_get_buffer:
5607 * @info: a #GstPadProbeInfo
5609 * Returns: (transfer none): The #GstBuffer from the probe
5613 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5615 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5617 return GST_PAD_PROBE_INFO_BUFFER (info);
5621 * gst_pad_probe_info_get_bufferlist:
5622 * @info: a #GstPadProbeInfo
5624 * Returns: (transfer none): The #GstBufferlist from the probe
5628 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5630 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5632 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);