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 /* adjust and make a new event with the offset applied */
582 segment.base += pad->offset;
583 event = gst_event_new_segment (&segment);
588 /* should be called with the OBJECT_LOCK */
590 get_pad_caps (GstPad * pad)
592 GstCaps *caps = NULL;
595 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
597 gst_event_parse_caps (ev->event, &caps);
603 gst_pad_dispose (GObject * object)
605 GstPad *pad = GST_PAD_CAST (object);
608 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
610 /* unlink the peer pad */
611 if ((peer = gst_pad_get_peer (pad))) {
612 /* window for MT unsafeness, someone else could unlink here
613 * and then we call unlink with wrong pads. The unlink
614 * function would catch this and safely return failed. */
615 if (GST_PAD_IS_SRC (pad))
616 gst_pad_unlink (pad, peer);
618 gst_pad_unlink (peer, pad);
620 gst_object_unref (peer);
623 gst_pad_set_pad_template (pad, NULL);
625 GST_OBJECT_LOCK (pad);
627 GST_OBJECT_UNLOCK (pad);
629 g_hook_list_clear (&pad->probes);
631 G_OBJECT_CLASS (parent_class)->dispose (object);
635 gst_pad_finalize (GObject * object)
637 GstPad *pad = GST_PAD_CAST (object);
640 /* in case the task is still around, clean it up */
641 if ((task = GST_PAD_TASK (pad))) {
642 gst_task_join (task);
643 GST_PAD_TASK (pad) = NULL;
644 gst_object_unref (task);
647 if (pad->activatenotify)
648 pad->activatenotify (pad->activatedata);
649 if (pad->activatemodenotify)
650 pad->activatemodenotify (pad->activatemodedata);
652 pad->linknotify (pad->linkdata);
653 if (pad->unlinknotify)
654 pad->unlinknotify (pad->unlinkdata);
655 if (pad->chainnotify)
656 pad->chainnotify (pad->chaindata);
657 if (pad->chainlistnotify)
658 pad->chainlistnotify (pad->chainlistdata);
659 if (pad->getrangenotify)
660 pad->getrangenotify (pad->getrangedata);
661 if (pad->eventnotify)
662 pad->eventnotify (pad->eventdata);
663 if (pad->querynotify)
664 pad->querynotify (pad->querydata);
665 if (pad->iterintlinknotify)
666 pad->iterintlinknotify (pad->iterintlinkdata);
668 g_rec_mutex_clear (&pad->stream_rec_lock);
669 g_cond_clear (&pad->block_cond);
670 g_array_free (pad->priv->events, TRUE);
672 G_OBJECT_CLASS (parent_class)->finalize (object);
676 gst_pad_set_property (GObject * object, guint prop_id,
677 const GValue * value, GParamSpec * pspec)
679 g_return_if_fail (GST_IS_PAD (object));
682 case PAD_PROP_DIRECTION:
683 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
685 case PAD_PROP_TEMPLATE:
686 gst_pad_set_pad_template (GST_PAD_CAST (object),
687 (GstPadTemplate *) g_value_get_object (value));
690 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
696 gst_pad_get_property (GObject * object, guint prop_id,
697 GValue * value, GParamSpec * pspec)
699 g_return_if_fail (GST_IS_PAD (object));
703 GST_OBJECT_LOCK (object);
704 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
705 GST_OBJECT_UNLOCK (object);
707 case PAD_PROP_DIRECTION:
708 g_value_set_enum (value, GST_PAD_DIRECTION (object));
710 case PAD_PROP_TEMPLATE:
711 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
714 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
721 * @name: the name of the new pad.
722 * @direction: the #GstPadDirection of the pad.
724 * Creates a new pad with the given name in the given direction.
725 * If name is NULL, a guaranteed unique name (across all pads)
727 * This function makes a copy of the name so you can safely free the name.
729 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
734 gst_pad_new (const gchar * name, GstPadDirection direction)
736 return g_object_new (GST_TYPE_PAD,
737 "name", name, "direction", direction, NULL);
741 * gst_pad_new_from_template:
742 * @templ: the pad template to use
743 * @name: the name of the element
745 * Creates a new pad with the given name from the given template.
746 * If name is NULL, a guaranteed unique name (across all pads)
748 * This function makes a copy of the name so you can safely free the name.
750 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
753 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
755 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
757 return g_object_new (GST_TYPE_PAD,
758 "name", name, "direction", templ->direction, "template", templ, NULL);
762 * gst_pad_new_from_static_template:
763 * @templ: the #GstStaticPadTemplate to use
764 * @name: the name of the element
766 * Creates a new pad with the given name from the given static template.
767 * If name is NULL, a guaranteed unique name (across all pads)
769 * This function makes a copy of the name so you can safely free the name.
771 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
774 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
778 GstPadTemplate *template;
780 template = gst_static_pad_template_get (templ);
781 pad = gst_pad_new_from_template (template, name);
782 gst_object_unref (template);
786 #define ACQUIRE_PARENT(pad, parent, label) \
788 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
789 gst_object_ref (parent); \
790 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
794 #define RELEASE_PARENT(parent) \
796 if (G_LIKELY (parent)) \
797 gst_object_unref (parent); \
801 * gst_pad_get_direction:
802 * @pad: a #GstPad to get the direction of.
804 * Gets the direction of the pad. The direction of the pad is
805 * decided at construction time so this function does not take
808 * Returns: the #GstPadDirection of the pad.
813 gst_pad_get_direction (GstPad * pad)
815 GstPadDirection result;
817 /* PAD_UNKNOWN is a little silly but we need some sort of
818 * error return value */
819 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
821 result = GST_PAD_DIRECTION (pad);
827 gst_pad_activate_default (GstPad * pad, GstObject * parent)
829 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
833 * gst_pad_mode_get_name:
834 * @mode: the pad mode
836 * Return the name of a pad mode, for use in debug messages mostly.
838 * Returns: short mnemonic for pad mode @mode
841 gst_pad_mode_get_name (GstPadMode mode)
844 case GST_PAD_MODE_NONE:
846 case GST_PAD_MODE_PUSH:
848 case GST_PAD_MODE_PULL:
857 pre_activate (GstPad * pad, GstPadMode new_mode)
860 case GST_PAD_MODE_NONE:
861 GST_OBJECT_LOCK (pad);
862 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
863 GST_PAD_SET_FLUSHING (pad);
864 GST_PAD_MODE (pad) = new_mode;
865 /* unlock blocked pads so element can resume and stop */
866 GST_PAD_BLOCK_BROADCAST (pad);
867 GST_OBJECT_UNLOCK (pad);
869 case GST_PAD_MODE_PUSH:
870 case GST_PAD_MODE_PULL:
871 GST_OBJECT_LOCK (pad);
872 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
873 gst_pad_mode_get_name (new_mode));
874 GST_PAD_UNSET_FLUSHING (pad);
875 GST_PAD_MODE (pad) = new_mode;
876 if (GST_PAD_IS_SINK (pad)) {
878 /* make sure the peer src pad sends us all events */
879 if ((peer = GST_PAD_PEER (pad))) {
880 gst_object_ref (peer);
881 GST_OBJECT_UNLOCK (pad);
883 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
884 GST_DEBUG_PAD_NAME (peer));
886 GST_OBJECT_LOCK (peer);
887 schedule_events (peer, NULL);
888 GST_OBJECT_UNLOCK (peer);
890 gst_object_unref (peer);
892 GST_OBJECT_UNLOCK (pad);
895 GST_OBJECT_UNLOCK (pad);
902 post_activate (GstPad * pad, GstPadMode new_mode)
905 case GST_PAD_MODE_NONE:
906 /* ensures that streaming stops */
907 GST_PAD_STREAM_LOCK (pad);
908 GST_DEBUG_OBJECT (pad, "stopped streaming");
909 GST_OBJECT_LOCK (pad);
911 GST_OBJECT_UNLOCK (pad);
912 GST_PAD_STREAM_UNLOCK (pad);
914 case GST_PAD_MODE_PUSH:
915 case GST_PAD_MODE_PULL:
922 * gst_pad_set_active:
923 * @pad: the #GstPad to activate or deactivate.
924 * @active: whether or not the pad should be active.
926 * Activates or deactivates the given pad.
927 * Normally called from within core state change functions.
929 * If @active, makes sure the pad is active. If it is already active, either in
930 * push or pull mode, just return. Otherwise dispatches to the pad's activate
931 * function to perform the actual activation.
933 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
934 * and a FALSE argument.
936 * Returns: #TRUE if the operation was successful.
941 gst_pad_set_active (GstPad * pad, gboolean active)
945 gboolean ret = FALSE;
947 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
949 GST_OBJECT_LOCK (pad);
950 old = GST_PAD_MODE (pad);
951 ACQUIRE_PARENT (pad, parent, no_parent);
952 GST_OBJECT_UNLOCK (pad);
955 if (old == GST_PAD_MODE_NONE) {
956 GST_DEBUG_OBJECT (pad, "activating pad from none");
957 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
959 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
960 gst_pad_mode_get_name (old));
964 if (old == GST_PAD_MODE_NONE) {
965 GST_DEBUG_OBJECT (pad, "pad was inactive");
968 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
969 gst_pad_mode_get_name (old));
970 ret = gst_pad_activate_mode (pad, old, FALSE);
974 RELEASE_PARENT (parent);
976 if (G_UNLIKELY (!ret))
984 GST_DEBUG_OBJECT (pad, "no parent");
985 GST_OBJECT_UNLOCK (pad);
990 GST_OBJECT_LOCK (pad);
992 g_critical ("Failed to deactivate pad %s:%s, very bad",
993 GST_DEBUG_PAD_NAME (pad));
995 GST_WARNING_OBJECT (pad, "Failed to activate pad");
997 GST_OBJECT_UNLOCK (pad);
1003 * gst_pad_activate_mode:
1004 * @pad: the #GstPad to activate or deactivate.
1005 * @mode: the requested activation mode
1006 * @active: whether or not the pad should be active.
1008 * Activates or deactivates the given pad in @mode via dispatching to the
1009 * pad's activatemodefunc. For use from within pad activation functions only.
1011 * If you don't know what this is, you probably don't want to call it.
1013 * Returns: TRUE if the operation was successful.
1018 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1020 gboolean res = FALSE;
1022 GstPadMode old, new;
1023 GstPadDirection dir;
1026 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1028 GST_OBJECT_LOCK (pad);
1029 old = GST_PAD_MODE (pad);
1030 dir = GST_PAD_DIRECTION (pad);
1031 ACQUIRE_PARENT (pad, parent, no_parent);
1032 GST_OBJECT_UNLOCK (pad);
1034 new = active ? mode : GST_PAD_MODE_NONE;
1039 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1040 /* pad was activate in the wrong direction, deactivate it
1041 * and reactivate it in the requested mode */
1042 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1043 gst_pad_mode_get_name (old));
1045 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1046 goto deactivate_failed;
1050 case GST_PAD_MODE_PULL:
1052 if (dir == GST_PAD_SINK) {
1053 if ((peer = gst_pad_get_peer (pad))) {
1054 GST_DEBUG_OBJECT (pad, "calling peer");
1055 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1057 gst_object_unref (peer);
1059 /* there is no peer, this is only fatal when we activate. When we
1060 * deactivate, we must assume the application has unlinked the peer and
1061 * will deactivate it eventually. */
1065 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1068 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1069 goto failure; /* Can't activate pull on a src without a
1070 getrange function */
1078 /* Mark pad as needing reconfiguration */
1080 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1081 pre_activate (pad, new);
1083 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1084 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1088 /* can happen for sinks of passthrough elements */
1091 post_activate (pad, new);
1093 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1094 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1099 /* Clear sticky flags on deactivation */
1101 GST_OBJECT_LOCK (pad);
1102 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1103 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1104 GST_OBJECT_UNLOCK (pad);
1108 RELEASE_PARENT (parent);
1114 GST_DEBUG_OBJECT (pad, "no parent");
1115 GST_OBJECT_UNLOCK (pad);
1120 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1121 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1126 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1127 "failed to %s in switch to %s mode from %s mode",
1128 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1129 gst_pad_mode_get_name (old));
1134 GST_OBJECT_LOCK (peer);
1135 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1136 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1137 GST_OBJECT_UNLOCK (peer);
1138 gst_object_unref (peer);
1143 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1144 "pad in pull mode");
1149 GST_OBJECT_LOCK (pad);
1150 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1151 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1152 GST_PAD_SET_FLUSHING (pad);
1153 GST_PAD_MODE (pad) = old;
1154 GST_OBJECT_UNLOCK (pad);
1160 * gst_pad_is_active:
1161 * @pad: the #GstPad to query
1163 * Query if a pad is active
1165 * Returns: TRUE if the pad is active.
1170 gst_pad_is_active (GstPad * pad)
1172 gboolean result = FALSE;
1174 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1176 GST_OBJECT_LOCK (pad);
1177 result = GST_PAD_IS_ACTIVE (pad);
1178 GST_OBJECT_UNLOCK (pad);
1184 * gst_pad_add_probe:
1185 * @pad: the #GstPad to add the probe to
1186 * @mask: the probe mask
1187 * @callback: #GstPadProbeCallback that will be called with notifications of
1189 * @user_data: (closure): user data passed to the callback
1190 * @destroy_data: #GDestroyNotify for user_data
1192 * Be notified of different states of pads. The provided callback is called for
1193 * every state that matches @mask.
1195 * Returns: an id or 0 on error. The id can be used to remove the probe with
1196 * gst_pad_remove_probe().
1201 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1202 GstPadProbeCallback callback, gpointer user_data,
1203 GDestroyNotify destroy_data)
1208 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1209 g_return_val_if_fail (mask != 0, 0);
1211 GST_OBJECT_LOCK (pad);
1213 /* make a new probe */
1214 hook = g_hook_alloc (&pad->probes);
1216 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1219 /* when no contraints are given for the types, assume all types are
1221 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1222 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1223 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1224 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1226 /* store our flags and other fields */
1227 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1228 hook->func = callback;
1229 hook->data = user_data;
1230 hook->destroy = destroy_data;
1231 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1234 g_hook_prepend (&pad->probes, hook);
1236 /* incremenent cookie so that the new hook get's called */
1237 pad->priv->probe_list_cookie++;
1239 /* get the id of the hook, we return this and it can be used to remove the
1241 res = hook->hook_id;
1243 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1245 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1246 /* we have a block probe */
1248 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1249 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1250 "now %d blocking probes", pad->num_blocked);
1253 /* call the callback if we need to be called for idle callbacks */
1254 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1255 if (pad->priv->using > 0) {
1256 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1257 * flag above, the last thread to leave the push will do the callback. New
1258 * threads going into the push will block. */
1259 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1260 "pad is in use, delay idle callback");
1261 GST_OBJECT_UNLOCK (pad);
1263 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1265 /* the pad is idle now, we can signal the idle callback now */
1266 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1267 "pad is idle, trigger idle callback");
1268 GST_OBJECT_UNLOCK (pad);
1270 callback (pad, &info, user_data);
1273 GST_OBJECT_UNLOCK (pad);
1279 cleanup_hook (GstPad * pad, GHook * hook)
1281 GstPadProbeType type;
1283 if (!G_HOOK_IS_VALID (hook))
1286 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1288 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1289 /* unblock when we remove the last blocking probe */
1291 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1293 if (pad->num_blocked == 0) {
1294 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1295 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1296 GST_PAD_BLOCK_BROADCAST (pad);
1299 g_hook_destroy_link (&pad->probes, hook);
1304 * gst_pad_remove_probe:
1305 * @pad: the #GstPad with the probe
1306 * @id: the probe id to remove
1308 * Remove the probe with @id from @pad.
1313 gst_pad_remove_probe (GstPad * pad, gulong id)
1317 g_return_if_fail (GST_IS_PAD (pad));
1319 GST_OBJECT_LOCK (pad);
1321 hook = g_hook_get (&pad->probes, id);
1325 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1327 cleanup_hook (pad, hook);
1328 GST_OBJECT_UNLOCK (pad);
1334 GST_OBJECT_UNLOCK (pad);
1335 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1341 * gst_pad_is_blocked:
1342 * @pad: the #GstPad to query
1344 * Checks if the pad is blocked or not. This function returns the
1345 * last requested state of the pad. It is not certain that the pad
1346 * is actually blocking at this point (see gst_pad_is_blocking()).
1348 * Returns: TRUE if the pad is blocked.
1353 gst_pad_is_blocked (GstPad * pad)
1355 gboolean result = FALSE;
1357 g_return_val_if_fail (GST_IS_PAD (pad), result);
1359 GST_OBJECT_LOCK (pad);
1360 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1361 GST_OBJECT_UNLOCK (pad);
1367 * gst_pad_is_blocking:
1368 * @pad: the #GstPad to query
1370 * Checks if the pad is blocking or not. This is a guaranteed state
1371 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1373 * Returns: TRUE if the pad is blocking.
1378 gst_pad_is_blocking (GstPad * pad)
1380 gboolean result = FALSE;
1382 g_return_val_if_fail (GST_IS_PAD (pad), result);
1384 GST_OBJECT_LOCK (pad);
1385 /* the blocking flag is only valid if the pad is not flushing */
1386 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1387 GST_OBJECT_UNLOCK (pad);
1393 * gst_pad_needs_reconfigure:
1394 * @pad: the #GstPad to check
1396 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1397 * if the flag was set.
1399 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1402 gst_pad_needs_reconfigure (GstPad * pad)
1404 gboolean reconfigure;
1406 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1408 GST_OBJECT_LOCK (pad);
1409 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1410 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1411 GST_OBJECT_UNLOCK (pad);
1417 * gst_pad_check_reconfigure:
1418 * @pad: the #GstPad to check
1420 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1421 * if the flag was set.
1423 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1426 gst_pad_check_reconfigure (GstPad * pad)
1428 gboolean reconfigure;
1430 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1432 GST_OBJECT_LOCK (pad);
1433 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1435 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1436 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1438 GST_OBJECT_UNLOCK (pad);
1444 * gst_pad_mark_reconfigure:
1445 * @pad: the #GstPad to mark
1447 * Mark a pad for needing reconfiguration. The next call to
1448 * gst_pad_check_reconfigure() will return %TRUE after this call.
1451 gst_pad_mark_reconfigure (GstPad * pad)
1453 g_return_if_fail (GST_IS_PAD (pad));
1455 GST_OBJECT_LOCK (pad);
1456 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1457 GST_OBJECT_UNLOCK (pad);
1461 * gst_pad_set_activate_function:
1463 * @f: the #GstPadActivateFunction to set.
1465 * Calls gst_pad_set_activate_function_full() with NULL for the user_data and
1469 * gst_pad_set_activate_function_full:
1471 * @activate: the #GstPadActivateFunction to set.
1472 * @user_data: user_data passed to @notify
1473 * @notify: notify called when @activate will not be used anymore.
1475 * Sets the given activate function for @pad. The activate function will
1476 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1477 * Only makes sense to set on sink pads.
1479 * Call this function if your sink pad can start a pull-based task.
1482 gst_pad_set_activate_function_full (GstPad * pad,
1483 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1485 g_return_if_fail (GST_IS_PAD (pad));
1487 if (pad->activatenotify)
1488 pad->activatenotify (pad->activatedata);
1489 GST_PAD_ACTIVATEFUNC (pad) = activate;
1490 pad->activatedata = user_data;
1491 pad->activatenotify = notify;
1493 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1494 GST_DEBUG_FUNCPTR_NAME (activate));
1498 * gst_pad_set_activatemode_function:
1500 * @f: the #GstPadActivateModeFunction to set.
1502 * Calls gst_pad_set_activatemode_function_full() with NULL for the user_data and
1506 * gst_pad_set_activatemode_function_full:
1508 * @activatemode: the #GstPadActivateModeFunction to set.
1509 * @user_data: user_data passed to @notify
1510 * @notify: notify called when @activatemode will not be used anymore.
1512 * Sets the given activate_mode function for the pad. An activate_mode function
1513 * prepares the element for data passing.
1516 gst_pad_set_activatemode_function_full (GstPad * pad,
1517 GstPadActivateModeFunction activatemode, gpointer user_data,
1518 GDestroyNotify notify)
1520 g_return_if_fail (GST_IS_PAD (pad));
1522 if (pad->activatemodenotify)
1523 pad->activatemodenotify (pad->activatemodedata);
1524 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1525 pad->activatemodedata = user_data;
1526 pad->activatemodenotify = notify;
1528 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1529 GST_DEBUG_FUNCPTR_NAME (activatemode));
1533 * gst_pad_set_chain_function:
1534 * @p: a sink #GstPad.
1535 * @f: the #GstPadChainFunction to set.
1537 * Calls gst_pad_set_chain_function_full() with NULL for the user_data and
1541 * gst_pad_set_chain_function_full:
1542 * @pad: a sink #GstPad.
1543 * @chain: the #GstPadChainFunction to set.
1544 * @user_data: user_data passed to @notify
1545 * @notify: notify called when @chain will not be used anymore.
1547 * Sets the given chain function for the pad. The chain function is called to
1548 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1551 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1552 gpointer user_data, GDestroyNotify notify)
1554 g_return_if_fail (GST_IS_PAD (pad));
1555 g_return_if_fail (GST_PAD_IS_SINK (pad));
1557 if (pad->chainnotify)
1558 pad->chainnotify (pad->chaindata);
1559 GST_PAD_CHAINFUNC (pad) = chain;
1560 pad->chaindata = user_data;
1561 pad->chainnotify = notify;
1563 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1564 GST_DEBUG_FUNCPTR_NAME (chain));
1568 * gst_pad_set_chain_list_function:
1569 * @p: a sink #GstPad.
1570 * @f: the #GstPadChainListFunction to set.
1572 * Calls gst_pad_set_chain_list_function_full() with NULL for the user_data and
1576 * gst_pad_set_chain_list_function_full:
1577 * @pad: a sink #GstPad.
1578 * @chainlist: the #GstPadChainListFunction to set.
1579 * @user_data: user_data passed to @notify
1580 * @notify: notify called when @chainlist will not be used anymore.
1582 * Sets the given chain list function for the pad. The chainlist function is
1583 * called to process a #GstBufferList input buffer list. See
1584 * #GstPadChainListFunction for more details.
1587 gst_pad_set_chain_list_function_full (GstPad * pad,
1588 GstPadChainListFunction chainlist, gpointer user_data,
1589 GDestroyNotify notify)
1591 g_return_if_fail (GST_IS_PAD (pad));
1592 g_return_if_fail (GST_PAD_IS_SINK (pad));
1594 if (pad->chainlistnotify)
1595 pad->chainlistnotify (pad->chainlistdata);
1596 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1597 pad->chainlistdata = user_data;
1598 pad->chainlistnotify = notify;
1600 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1601 GST_DEBUG_FUNCPTR_NAME (chainlist));
1605 * gst_pad_set_getrange_function:
1606 * @p: a source #GstPad.
1607 * @f: the #GstPadGetRangeFunction to set.
1609 * Calls gst_pad_set_getrange_function_full() with NULL for the user_data and
1613 * gst_pad_set_getrange_function_full:
1614 * @pad: a source #GstPad.
1615 * @get: the #GstPadGetRangeFunction to set.
1616 * @user_data: user_data passed to @notify
1617 * @notify: notify called when @get will not be used anymore.
1619 * Sets the given getrange function for the pad. The getrange function is
1620 * called to produce a new #GstBuffer to start the processing pipeline. see
1621 * #GstPadGetRangeFunction for a description of the getrange function.
1624 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1625 gpointer user_data, GDestroyNotify notify)
1627 g_return_if_fail (GST_IS_PAD (pad));
1628 g_return_if_fail (GST_PAD_IS_SRC (pad));
1630 if (pad->getrangenotify)
1631 pad->getrangenotify (pad->getrangedata);
1632 GST_PAD_GETRANGEFUNC (pad) = get;
1633 pad->getrangedata = user_data;
1634 pad->getrangenotify = notify;
1636 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1637 GST_DEBUG_FUNCPTR_NAME (get));
1641 * gst_pad_set_event_function:
1642 * @p: a #GstPad of either direction.
1643 * @f: the #GstPadEventFunction to set.
1645 * Calls gst_pad_set_event_function_full() with NULL for the user_data and
1649 * gst_pad_set_event_function_full:
1650 * @pad: a #GstPad of either direction.
1651 * @event: the #GstPadEventFunction to set.
1652 * @user_data: user_data passed to @notify
1653 * @notify: notify called when @event will not be used anymore.
1655 * Sets the given event handler for the pad.
1658 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1659 gpointer user_data, GDestroyNotify notify)
1661 g_return_if_fail (GST_IS_PAD (pad));
1663 if (pad->eventnotify)
1664 pad->eventnotify (pad->eventdata);
1665 GST_PAD_EVENTFUNC (pad) = event;
1666 pad->eventdata = user_data;
1667 pad->eventnotify = notify;
1669 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1670 GST_DEBUG_FUNCPTR_NAME (event));
1674 * gst_pad_set_query_function:
1675 * @p: a #GstPad of either direction.
1676 * @f: the #GstPadQueryFunction to set.
1678 * Calls gst_pad_set_query_function_full() with NULL for the user_data and
1682 * gst_pad_set_query_function_full:
1683 * @pad: a #GstPad of either direction.
1684 * @query: the #GstPadQueryFunction to set.
1685 * @user_data: user_data passed to @notify
1686 * @notify: notify called when @query will not be used anymore.
1688 * Set the given query function for the pad.
1691 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1692 gpointer user_data, GDestroyNotify notify)
1694 g_return_if_fail (GST_IS_PAD (pad));
1696 if (pad->querynotify)
1697 pad->querynotify (pad->querydata);
1698 GST_PAD_QUERYFUNC (pad) = query;
1699 pad->querydata = user_data;
1700 pad->querynotify = notify;
1702 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1703 GST_DEBUG_FUNCPTR_NAME (query));
1707 * gst_pad_set_iterate_internal_links_function:
1708 * @p: a #GstPad of either direction.
1709 * @f: the #GstPadIterIntLinkFunction to set.
1711 * Calls gst_pad_set_iterate_internal_links_function_full() with NULL
1712 * for the user_data and notify.
1715 * gst_pad_set_iterate_internal_links_function_full:
1716 * @pad: a #GstPad of either direction.
1717 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1718 * @user_data: user_data passed to @notify
1719 * @notify: notify called when @iterintlink will not be used anymore.
1721 * Sets the given internal link iterator function for the pad.
1724 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1725 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1726 GDestroyNotify notify)
1728 g_return_if_fail (GST_IS_PAD (pad));
1730 if (pad->iterintlinknotify)
1731 pad->iterintlinknotify (pad->iterintlinkdata);
1732 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1733 pad->iterintlinkdata = user_data;
1734 pad->iterintlinknotify = notify;
1736 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1737 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1741 * gst_pad_set_link_function:
1743 * @f: the #GstPadLinkFunction to set.
1745 * Calls gst_pad_set_link_function_full() with NULL
1746 * for the user_data and notify.
1749 * gst_pad_set_link_function_full:
1751 * @link: the #GstPadLinkFunction to set.
1752 * @user_data: user_data passed to @notify
1753 * @notify: notify called when @link will not be used anymore.
1755 * Sets the given link function for the pad. It will be called when
1756 * the pad is linked with another pad.
1758 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1761 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1762 * cannot be made for some reason.
1764 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1765 * of the peer sink pad, if present.
1768 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1769 gpointer user_data, GDestroyNotify notify)
1771 g_return_if_fail (GST_IS_PAD (pad));
1773 if (pad->linknotify)
1774 pad->linknotify (pad->linkdata);
1775 GST_PAD_LINKFUNC (pad) = link;
1776 pad->linkdata = user_data;
1777 pad->linknotify = notify;
1779 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1780 GST_DEBUG_FUNCPTR_NAME (link));
1784 * gst_pad_set_unlink_function:
1786 * @f: the #GstPadUnlinkFunction to set.
1788 * Calls gst_pad_set_unlink_function_full() with NULL
1789 * for the user_data and notify.
1792 * gst_pad_set_unlink_function_full:
1794 * @unlink: the #GstPadUnlinkFunction to set.
1795 * @user_data: user_data passed to @notify
1796 * @notify: notify called when @unlink will not be used anymore.
1798 * Sets the given unlink function for the pad. It will be called
1799 * when the pad is unlinked.
1802 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1803 gpointer user_data, GDestroyNotify notify)
1805 g_return_if_fail (GST_IS_PAD (pad));
1807 if (pad->unlinknotify)
1808 pad->unlinknotify (pad->unlinkdata);
1809 GST_PAD_UNLINKFUNC (pad) = unlink;
1810 pad->unlinkdata = user_data;
1811 pad->unlinknotify = notify;
1813 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1814 GST_DEBUG_FUNCPTR_NAME (unlink));
1819 * @srcpad: the source #GstPad to unlink.
1820 * @sinkpad: the sink #GstPad to unlink.
1822 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1823 * signal on both pads.
1825 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1826 * the pads were not linked together.
1831 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1833 gboolean result = FALSE;
1834 GstElement *parent = NULL;
1836 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1837 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1838 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1839 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1841 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1842 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1843 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1845 /* We need to notify the parent before taking any pad locks as the bin in
1846 * question might be waiting for a lock on the pad while holding its lock
1847 * that our message will try to take. */
1848 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1849 if (GST_IS_ELEMENT (parent)) {
1850 gst_element_post_message (parent,
1851 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1852 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1854 gst_object_unref (parent);
1859 GST_OBJECT_LOCK (srcpad);
1860 GST_OBJECT_LOCK (sinkpad);
1862 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1863 goto not_linked_together;
1865 if (GST_PAD_UNLINKFUNC (srcpad)) {
1866 GstObject *tmpparent;
1868 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1870 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1871 RELEASE_PARENT (tmpparent);
1874 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1875 GstObject *tmpparent;
1877 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1879 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1880 RELEASE_PARENT (tmpparent);
1884 /* first clear peers */
1885 GST_PAD_PEER (srcpad) = NULL;
1886 GST_PAD_PEER (sinkpad) = NULL;
1888 GST_OBJECT_UNLOCK (sinkpad);
1889 GST_OBJECT_UNLOCK (srcpad);
1891 /* fire off a signal to each of the pads telling them
1892 * that they've been unlinked */
1893 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1894 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1896 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1897 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1902 if (parent != NULL) {
1903 gst_element_post_message (parent,
1904 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1905 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1906 gst_object_unref (parent);
1911 not_linked_together:
1913 /* we do not emit a warning in this case because unlinking cannot
1914 * be made MT safe.*/
1915 GST_OBJECT_UNLOCK (sinkpad);
1916 GST_OBJECT_UNLOCK (srcpad);
1922 * gst_pad_is_linked:
1923 * @pad: pad to check
1925 * Checks if a @pad is linked to another pad or not.
1927 * Returns: TRUE if the pad is linked, FALSE otherwise.
1932 gst_pad_is_linked (GstPad * pad)
1936 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1938 GST_OBJECT_LOCK (pad);
1939 result = (GST_PAD_PEER (pad) != NULL);
1940 GST_OBJECT_UNLOCK (pad);
1945 /* get the caps from both pads and see if the intersection
1948 * This function should be called with the pad LOCK on both
1952 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1953 GstPadLinkCheck flags)
1955 GstCaps *srccaps = NULL;
1956 GstCaps *sinkcaps = NULL;
1957 gboolean compatible = FALSE;
1959 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1962 /* Doing the expensive caps checking takes priority over only checking the template caps */
1963 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1964 GST_OBJECT_UNLOCK (sink);
1965 GST_OBJECT_UNLOCK (src);
1967 srccaps = gst_pad_query_caps (src, NULL);
1968 sinkcaps = gst_pad_query_caps (sink, NULL);
1970 GST_OBJECT_LOCK (src);
1971 GST_OBJECT_LOCK (sink);
1973 /* If one of the two pads doesn't have a template, consider the intersection
1975 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
1976 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
1980 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
1982 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
1985 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
1987 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
1990 /* if we have caps on both pads we can check the intersection. If one
1991 * of the caps is NULL, we return TRUE. */
1992 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1994 gst_caps_unref (srccaps);
1996 gst_caps_unref (sinkcaps);
2000 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2001 gst_caps_unref (srccaps);
2002 gst_caps_unref (sinkcaps);
2005 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2006 (compatible ? "" : "not"));
2011 /* check if the grandparents of both pads are the same.
2012 * This check is required so that we don't try to link
2013 * pads from elements in different bins without ghostpads.
2015 * The LOCK should be held on both pads
2018 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2020 GstObject *psrc, *psink;
2022 psrc = GST_OBJECT_PARENT (src);
2023 psink = GST_OBJECT_PARENT (sink);
2025 /* if one of the pads has no parent, we allow the link */
2026 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2029 /* only care about parents that are elements */
2030 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2031 goto no_element_parent;
2033 /* if the parents are the same, we have a loop */
2034 if (G_UNLIKELY (psrc == psink))
2037 /* if they both have a parent, we check the grandparents. We can not lock
2038 * the parent because we hold on the child (pad) and the locking order is
2039 * parent >> child. */
2040 psrc = GST_OBJECT_PARENT (psrc);
2041 psink = GST_OBJECT_PARENT (psink);
2043 /* if they have grandparents but they are not the same */
2044 if (G_UNLIKELY (psrc != psink))
2045 goto wrong_grandparents;
2052 GST_CAT_DEBUG (GST_CAT_CAPS,
2053 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2054 GST_PTR_FORMAT, psrc, psink);
2059 GST_CAT_DEBUG (GST_CAT_CAPS,
2060 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2061 GST_PTR_FORMAT, psrc, psink);
2066 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2072 GST_CAT_DEBUG (GST_CAT_CAPS,
2073 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2074 GST_PTR_FORMAT, psrc, psink);
2079 /* FIXME leftover from an attempt at refactoring... */
2080 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2081 * the two pads will be locked in the srcpad, sinkpad order. */
2082 static GstPadLinkReturn
2083 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2085 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2086 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2088 GST_OBJECT_LOCK (srcpad);
2090 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2091 goto src_was_linked;
2093 GST_OBJECT_LOCK (sinkpad);
2095 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2096 goto sink_was_linked;
2098 /* check hierarchy, pads can only be linked if the grandparents
2100 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2101 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2102 goto wrong_hierarchy;
2104 /* check pad caps for non-empty intersection */
2105 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2108 /* FIXME check pad scheduling for non-empty intersection */
2110 return GST_PAD_LINK_OK;
2114 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2115 GST_DEBUG_PAD_NAME (srcpad),
2116 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2117 /* we do not emit a warning in this case because unlinking cannot
2118 * be made MT safe.*/
2119 GST_OBJECT_UNLOCK (srcpad);
2120 return GST_PAD_LINK_WAS_LINKED;
2124 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2125 GST_DEBUG_PAD_NAME (sinkpad),
2126 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2127 /* we do not emit a warning in this case because unlinking cannot
2128 * be made MT safe.*/
2129 GST_OBJECT_UNLOCK (sinkpad);
2130 GST_OBJECT_UNLOCK (srcpad);
2131 return GST_PAD_LINK_WAS_LINKED;
2135 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2136 GST_OBJECT_UNLOCK (sinkpad);
2137 GST_OBJECT_UNLOCK (srcpad);
2138 return GST_PAD_LINK_WRONG_HIERARCHY;
2142 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2143 GST_OBJECT_UNLOCK (sinkpad);
2144 GST_OBJECT_UNLOCK (srcpad);
2145 return GST_PAD_LINK_NOFORMAT;
2151 * @srcpad: the source #GstPad.
2152 * @sinkpad: the sink #GstPad.
2154 * Checks if the source pad and the sink pad are compatible so they can be
2157 * Returns: TRUE if the pads can be linked.
2160 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2162 GstPadLinkReturn result;
2164 /* generic checks */
2165 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2166 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2168 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2169 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2171 /* gst_pad_link_prepare does everything for us, we only release the locks
2172 * on the pads that it gets us. If this function returns !OK the locks are not
2174 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2175 if (result != GST_PAD_LINK_OK)
2178 GST_OBJECT_UNLOCK (srcpad);
2179 GST_OBJECT_UNLOCK (sinkpad);
2182 return result == GST_PAD_LINK_OK;
2186 * gst_pad_link_full:
2187 * @srcpad: the source #GstPad to link.
2188 * @sinkpad: the sink #GstPad to link.
2189 * @flags: the checks to validate when linking
2191 * Links the source pad and the sink pad.
2193 * This variant of #gst_pad_link provides a more granular control on the
2194 * checks being done when linking. While providing some considerable speedups
2195 * the caller of this method must be aware that wrong usage of those flags
2196 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2197 * for more information.
2201 * Returns: A result code indicating if the connection worked or
2205 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2207 GstPadLinkReturn result;
2209 GstPadLinkFunction srcfunc, sinkfunc;
2211 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2212 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2213 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2214 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2215 GST_PAD_LINK_WRONG_DIRECTION);
2217 /* Notify the parent early. See gst_pad_unlink for details. */
2218 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2219 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2220 gst_element_post_message (parent,
2221 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2222 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2224 gst_object_unref (parent);
2229 /* prepare will also lock the two pads */
2230 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2232 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2235 /* must set peers before calling the link function */
2236 GST_PAD_PEER (srcpad) = sinkpad;
2237 GST_PAD_PEER (sinkpad) = srcpad;
2239 /* check events, when something is different, mark pending */
2240 schedule_events (srcpad, sinkpad);
2242 /* get the link functions */
2243 srcfunc = GST_PAD_LINKFUNC (srcpad);
2244 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2246 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2247 /* custom link functions, execute them */
2248 GST_OBJECT_UNLOCK (sinkpad);
2249 GST_OBJECT_UNLOCK (srcpad);
2252 GstObject *tmpparent;
2254 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2255 /* this one will call the peer link function */
2256 result = srcfunc (srcpad, tmpparent, sinkpad);
2257 RELEASE_PARENT (tmpparent);
2258 } else if (sinkfunc) {
2259 GstObject *tmpparent;
2261 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2262 /* if no source link function, we need to call the sink link
2263 * function ourselves. */
2264 result = sinkfunc (sinkpad, tmpparent, srcpad);
2265 RELEASE_PARENT (tmpparent);
2269 GST_OBJECT_LOCK (srcpad);
2270 GST_OBJECT_LOCK (sinkpad);
2272 /* we released the lock, check if the same pads are linked still */
2273 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2274 goto concurrent_link;
2276 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2279 GST_OBJECT_UNLOCK (sinkpad);
2280 GST_OBJECT_UNLOCK (srcpad);
2282 /* fire off a signal to each of the pads telling them
2283 * that they've been linked */
2284 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2285 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2287 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2288 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2290 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2293 if (G_LIKELY (parent)) {
2294 gst_element_post_message (parent,
2295 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2296 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2297 gst_object_unref (parent);
2305 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2306 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2307 GST_OBJECT_UNLOCK (sinkpad);
2308 GST_OBJECT_UNLOCK (srcpad);
2310 /* The other link operation succeeded first */
2311 result = GST_PAD_LINK_WAS_LINKED;
2316 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2317 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2319 GST_PAD_PEER (srcpad) = NULL;
2320 GST_PAD_PEER (sinkpad) = NULL;
2322 GST_OBJECT_UNLOCK (sinkpad);
2323 GST_OBJECT_UNLOCK (srcpad);
2331 * @srcpad: the source #GstPad to link.
2332 * @sinkpad: the sink #GstPad to link.
2334 * Links the source pad and the sink pad.
2336 * Returns: A result code indicating if the connection worked or
2342 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2344 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2348 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2350 GstPadTemplate **template_p;
2352 /* this function would need checks if it weren't static */
2354 GST_OBJECT_LOCK (pad);
2355 template_p = &pad->padtemplate;
2356 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2357 GST_OBJECT_UNLOCK (pad);
2360 gst_pad_template_pad_created (templ, pad);
2364 * gst_pad_get_pad_template:
2367 * Gets the template for @pad.
2369 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2370 * instantiated, or %NULL if this pad has no template. Unref after
2374 gst_pad_get_pad_template (GstPad * pad)
2376 GstPadTemplate *templ;
2378 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2380 templ = GST_PAD_PAD_TEMPLATE (pad);
2382 return (templ ? gst_object_ref (templ) : NULL);
2386 * gst_pad_has_current_caps:
2387 * @pad: a #GstPad to check
2389 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2391 * Returns: TRUE when @pad has caps associated with it.
2394 gst_pad_has_current_caps (GstPad * pad)
2399 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2401 GST_OBJECT_LOCK (pad);
2402 caps = get_pad_caps (pad);
2403 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2404 "check current pad caps %" GST_PTR_FORMAT, caps);
2405 result = (caps != NULL);
2406 GST_OBJECT_UNLOCK (pad);
2412 * gst_pad_get_current_caps:
2413 * @pad: a #GstPad to get the current capabilities of.
2415 * Gets the capabilities currently configured on @pad with the last
2416 * #GST_EVENT_CAPS event.
2418 * Returns: the current caps of the pad with incremented ref-count.
2421 gst_pad_get_current_caps (GstPad * pad)
2425 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2427 GST_OBJECT_LOCK (pad);
2428 if ((result = get_pad_caps (pad)))
2429 gst_caps_ref (result);
2430 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2431 "get current pad caps %" GST_PTR_FORMAT, result);
2432 GST_OBJECT_UNLOCK (pad);
2438 * gst_pad_get_pad_template_caps:
2439 * @pad: a #GstPad to get the template capabilities from.
2441 * Gets the capabilities for @pad's template.
2443 * Returns: (transfer full): the #GstCaps of this pad template.
2444 * Unref after usage.
2447 gst_pad_get_pad_template_caps (GstPad * pad)
2449 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2451 if (GST_PAD_PAD_TEMPLATE (pad))
2452 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2454 return gst_caps_ref (GST_CAPS_ANY);
2459 * @pad: a #GstPad to get the peer of.
2461 * Gets the peer of @pad. This function refs the peer pad so
2462 * you need to unref it after use.
2464 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2469 gst_pad_get_peer (GstPad * pad)
2473 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2475 GST_OBJECT_LOCK (pad);
2476 result = GST_PAD_PEER (pad);
2478 gst_object_ref (result);
2479 GST_OBJECT_UNLOCK (pad);
2485 * gst_pad_get_allowed_caps:
2488 * Gets the capabilities of the allowed media types that can flow through
2489 * @pad and its peer.
2491 * The allowed capabilities is calculated as the intersection of the results of
2492 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2493 * on the resulting caps.
2495 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2496 * caps when you no longer need it. This function returns NULL when @pad
2502 gst_pad_get_allowed_caps (GstPad * pad)
2508 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2510 GST_OBJECT_LOCK (pad);
2511 peer = GST_PAD_PEER (pad);
2512 if (G_UNLIKELY (peer == NULL))
2515 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2517 gst_object_ref (peer);
2518 GST_OBJECT_UNLOCK (pad);
2519 mycaps = gst_pad_query_caps (pad, NULL);
2521 caps = gst_pad_query_caps (peer, mycaps);
2522 gst_object_unref (peer);
2524 gst_caps_unref (mycaps);
2526 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2533 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2534 GST_OBJECT_UNLOCK (pad);
2541 * gst_pad_iterate_internal_links_default:
2542 * @pad: the #GstPad to get the internal links of.
2543 * @parent: (allow-none): the parent of @pad or NULL
2545 * Iterate the list of pads to which the given pad is linked to inside of
2546 * the parent element.
2547 * This is the default handler, and thus returns an iterator of all of the
2548 * pads inside the parent element with opposite direction.
2550 * The caller must free this iterator after use with gst_iterator_free().
2552 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2553 * returned pad with gst_object_unref().
2556 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2563 GstElement *eparent;
2565 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2567 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2568 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2570 GST_OBJECT_LOCK (pad);
2571 eparent = GST_PAD_PARENT (pad);
2572 if (!eparent || !GST_IS_ELEMENT (eparent))
2575 gst_object_ref (eparent);
2576 GST_OBJECT_UNLOCK (pad);
2579 if (pad->direction == GST_PAD_SRC)
2580 padlist = &eparent->sinkpads;
2582 padlist = &eparent->srcpads;
2584 GST_DEBUG_OBJECT (pad, "Making iterator");
2586 cookie = &eparent->pads_cookie;
2588 lock = GST_OBJECT_GET_LOCK (eparent);
2590 res = gst_iterator_new_list (GST_TYPE_PAD,
2591 lock, cookie, padlist, (GObject *) owner, NULL);
2593 gst_object_unref (owner);
2600 GST_OBJECT_UNLOCK (pad);
2601 GST_DEBUG_OBJECT (pad, "no parent element");
2607 * gst_pad_iterate_internal_links:
2608 * @pad: the GstPad to get the internal links of.
2610 * Gets an iterator for the pads to which the given pad is linked to inside
2611 * of the parent element.
2613 * Each #GstPad element yielded by the iterator will have its refcount increased,
2614 * so unref after use.
2616 * Free-function: gst_iterator_free
2618 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2619 * pad does not have an iterator function configured. Use
2620 * gst_iterator_free() after usage.
2623 gst_pad_iterate_internal_links (GstPad * pad)
2625 GstIterator *res = NULL;
2628 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2630 GST_OBJECT_LOCK (pad);
2631 ACQUIRE_PARENT (pad, parent, no_parent);
2632 GST_OBJECT_UNLOCK (pad);
2634 if (GST_PAD_ITERINTLINKFUNC (pad))
2635 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2637 RELEASE_PARENT (parent);
2644 GST_DEBUG_OBJECT (pad, "no parent");
2645 GST_OBJECT_UNLOCK (pad);
2653 * @forward: (scope call): a #GstPadForwardFunction
2654 * @user_data: user data passed to @forward
2656 * Calls @forward for all internally linked pads of @pad. This function deals with
2657 * dynamically changing internal pads and will make sure that the @forward
2658 * function is only called once for each pad.
2660 * When @forward returns TRUE, no further pads will be processed.
2662 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2665 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2668 gboolean result = FALSE;
2670 gboolean done = FALSE;
2671 GValue item = { 0, };
2672 GList *pushed_pads = NULL;
2674 iter = gst_pad_iterate_internal_links (pad);
2680 switch (gst_iterator_next (iter, &item)) {
2681 case GST_ITERATOR_OK:
2685 intpad = g_value_get_object (&item);
2687 /* if already pushed, skip. FIXME, find something faster to tag pads */
2688 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2689 g_value_reset (&item);
2693 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2694 GST_DEBUG_PAD_NAME (intpad));
2695 done = result = forward (intpad, user_data);
2697 pushed_pads = g_list_prepend (pushed_pads, intpad);
2699 g_value_reset (&item);
2702 case GST_ITERATOR_RESYNC:
2703 /* We don't reset the result here because we don't push the event
2704 * again on pads that got the event already and because we need
2705 * to consider the result of the previous pushes */
2706 gst_iterator_resync (iter);
2708 case GST_ITERATOR_ERROR:
2709 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2712 case GST_ITERATOR_DONE:
2717 g_value_unset (&item);
2718 gst_iterator_free (iter);
2720 g_list_free (pushed_pads);
2730 gboolean dispatched;
2734 event_forward_func (GstPad * pad, EventData * data)
2736 /* for each pad we send to, we should ref the event; it's up
2737 * to downstream to unref again when handled. */
2738 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2739 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2741 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2743 data->dispatched = TRUE;
2750 * gst_pad_event_default:
2751 * @pad: a #GstPad to call the default event handler on.
2752 * @parent: (allow-none): the parent of @pad or NULL
2753 * @event: (transfer full): the #GstEvent to handle.
2755 * Invokes the default event handler for the given pad.
2757 * The EOS event will pause the task associated with @pad before it is forwarded
2758 * to all internally linked pads,
2760 * The the event is sent to all pads internally linked to @pad. This function
2761 * takes ownership of @event.
2763 * Returns: TRUE if the event was sent successfully.
2766 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2768 gboolean result, forward = TRUE;
2770 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2771 g_return_val_if_fail (event != NULL, FALSE);
2773 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2776 switch (GST_EVENT_TYPE (event)) {
2777 case GST_EVENT_CAPS:
2778 forward = GST_PAD_IS_PROXY_CAPS (pad);
2789 data.dispatched = FALSE;
2790 data.result = FALSE;
2792 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2794 /* for sinkpads without a parent element or without internal links, nothing
2795 * will be dispatched but we still want to return TRUE. */
2796 if (data.dispatched)
2797 result = data.result;
2802 gst_event_unref (event);
2807 /* Default accept caps implementation just checks against
2808 * the allowed caps for the pad */
2810 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2812 /* get the caps and see if it intersects to something not empty */
2813 GstCaps *caps, *allowed;
2816 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2818 /* first forward the query to internally linked pads when we are dealing with
2820 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2821 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2826 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2827 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2829 gst_query_parse_accept_caps (query, &caps);
2830 allowed = gst_pad_query_caps (pad, caps);
2833 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
2834 GST_DEBUG_OBJECT (pad,
2835 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
2837 result = gst_caps_can_intersect (caps, allowed);
2839 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
2840 GST_PTR_FORMAT, allowed, caps);
2841 result = gst_caps_is_subset (caps, allowed);
2843 gst_caps_unref (allowed);
2845 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
2848 gst_query_set_accept_caps_result (query, result);
2854 /* Default caps implementation */
2856 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2858 GstCaps *result = NULL, *filter;
2859 GstPadTemplate *templ;
2860 gboolean fixed_caps;
2862 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2865 /* first try to proxy if we must */
2866 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2867 if ((gst_pad_proxy_query_caps (pad, query))) {
2872 gst_query_parse_caps (query, &filter);
2874 /* no proxy or it failed, do default handling */
2875 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2877 GST_OBJECT_LOCK (pad);
2879 /* fixed caps, try the negotiated caps first */
2880 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2881 if ((result = get_pad_caps (pad)))
2882 goto filter_done_unlock;
2885 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2886 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2887 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2888 goto filter_done_unlock;
2892 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2893 "non-fixed pad caps: trying pad caps");
2894 /* non fixed caps, try the negotiated caps */
2895 if ((result = get_pad_caps (pad)))
2896 goto filter_done_unlock;
2899 /* this almost never happens */
2900 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2901 result = GST_CAPS_ANY;
2904 GST_OBJECT_UNLOCK (pad);
2906 /* run the filter on the result */
2908 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2909 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2910 GST_PTR_FORMAT, result, result, filter, filter);
2911 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2912 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2915 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2916 "using caps %p %" GST_PTR_FORMAT, result, result);
2917 result = gst_caps_ref (result);
2919 gst_query_set_caps_result (query, result);
2920 gst_caps_unref (result);
2930 gboolean dispatched;
2934 query_forward_func (GstPad * pad, QueryData * data)
2936 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
2937 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
2939 data->result |= gst_pad_peer_query (pad, data->query);
2941 data->dispatched = TRUE;
2943 /* stop on first successful reply */
2944 return data->result;
2948 * gst_pad_query_default:
2949 * @pad: a #GstPad to call the default query handler on.
2950 * @parent: (allow-none): the parent of @pad or NULL
2951 * @query: (transfer none): the #GstQuery to handle.
2953 * Invokes the default query handler for the given pad.
2954 * The query is sent to all pads internally linked to @pad. Note that
2955 * if there are many possible sink pads that are internally linked to
2956 * @pad, only one will be sent the query.
2957 * Multi-sinkpad elements should implement custom query handlers.
2959 * Returns: TRUE if the query was performed successfully.
2962 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
2964 gboolean forward, ret = FALSE;
2966 switch (GST_QUERY_TYPE (query)) {
2967 case GST_QUERY_SCHEDULING:
2968 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
2970 case GST_QUERY_ALLOCATION:
2971 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
2973 case GST_QUERY_ACCEPT_CAPS:
2974 ret = gst_pad_query_accept_caps_default (pad, query);
2977 case GST_QUERY_CAPS:
2978 ret = gst_pad_query_caps_default (pad, query);
2981 case GST_QUERY_POSITION:
2982 case GST_QUERY_SEEKING:
2983 case GST_QUERY_FORMATS:
2984 case GST_QUERY_LATENCY:
2985 case GST_QUERY_JITTER:
2986 case GST_QUERY_RATE:
2987 case GST_QUERY_CONVERT:
2993 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
2994 query, GST_QUERY_TYPE_NAME (query));
3000 data.dispatched = FALSE;
3001 data.result = FALSE;
3003 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3005 if (data.dispatched) {
3008 /* nothing dispatched, assume drained */
3009 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3019 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3021 GstPad *pad = data->pad;
3022 GstPadProbeInfo *info = data->info;
3023 GstPadProbeType type, flags;
3024 GstPadProbeCallback callback;
3025 GstPadProbeReturn ret;
3027 /* if we have called this callback, do nothing */
3028 if (PROBE_COOKIE (hook) == data->cookie) {
3029 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3030 "hook %lu, cookie %u already called", hook->hook_id,
3031 PROBE_COOKIE (hook));
3035 PROBE_COOKIE (hook) = data->cookie;
3037 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3040 /* one of the data types */
3041 if ((flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3043 /* one of the scheduling types */
3044 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3046 /* one of the blocking types must match */
3047 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3048 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3050 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3051 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3052 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3055 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3056 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3057 PROBE_COOKIE (hook), flags);
3059 data->marshalled = TRUE;
3061 callback = (GstPadProbeCallback) hook->func;
3062 if (callback == NULL)
3065 info->id = hook->hook_id;
3067 GST_OBJECT_UNLOCK (pad);
3069 ret = callback (pad, info, hook->data);
3071 GST_OBJECT_LOCK (pad);
3074 case GST_PAD_PROBE_REMOVE:
3075 /* remove the probe */
3076 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3077 cleanup_hook (pad, hook);
3079 case GST_PAD_PROBE_DROP:
3080 /* need to drop the data, make sure other probes don't get called
3082 GST_DEBUG_OBJECT (pad, "asked to drop item");
3083 info->type = GST_PAD_PROBE_TYPE_INVALID;
3084 data->dropped = TRUE;
3086 case GST_PAD_PROBE_PASS:
3087 /* inform the pad block to let things pass */
3088 GST_DEBUG_OBJECT (pad, "asked to pass item");
3091 case GST_PAD_PROBE_OK:
3092 GST_DEBUG_OBJECT (pad, "probe returned OK");
3095 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3102 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3103 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3104 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3109 /* a probe that does not take or return any data */
3110 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3112 if (G_UNLIKELY (pad->num_probes)) { \
3113 /* pass NULL as the data item */ \
3114 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3115 ret = do_probe_callbacks (pad, &info, defaultval); \
3116 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3121 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3123 if (G_UNLIKELY (pad->num_probes)) { \
3124 /* pass the data item */ \
3125 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3126 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3127 /* store the possibly updated data item */ \
3128 data = GST_PAD_PROBE_INFO_DATA (&info); \
3129 /* if something went wrong, exit */ \
3130 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3135 #define PROBE_PUSH(pad,mask,data,label) \
3136 PROBE_FULL(pad, mask, data, -1, -1, label);
3137 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3138 PROBE_FULL(pad, mask, data, offs, size, label);
3140 static GstFlowReturn
3141 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3142 GstFlowReturn defaultval)
3151 data.marshalled = FALSE;
3152 data.dropped = FALSE;
3153 data.cookie = ++pad->priv->probe_cookie;
3156 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3159 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3160 "do probes cookie %u", data.cookie);
3161 cookie = pad->priv->probe_list_cookie;
3163 g_hook_list_marshal (&pad->probes, TRUE,
3164 (GHookMarshaller) probe_hook_marshal, &data);
3166 /* if the list changed, call the new callbacks (they will not have their
3167 * cookie set to data.cookie */
3168 if (cookie != pad->priv->probe_list_cookie) {
3169 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3170 "probe list changed, restarting");
3174 /* the first item that dropped will stop the hooks and then we drop here */
3178 /* if no handler matched and we are blocking, let the item pass */
3179 if (!data.marshalled && is_block)
3182 /* At this point, all handlers returned either OK or PASS. If one handler
3183 * returned PASS, let the item pass */
3188 while (GST_PAD_IS_BLOCKED (pad)) {
3189 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3190 "we are blocked %d times", pad->num_blocked);
3192 /* we might have released the lock */
3193 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3196 /* now we block the streaming thread. It can be unlocked when we
3197 * deactivate the pad (which will also set the FLUSHING flag) or
3198 * when the pad is unblocked. A flushing event will also unblock
3199 * the pad after setting the FLUSHING flag. */
3200 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3201 "Waiting to be unblocked or set flushing");
3202 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3203 GST_PAD_BLOCK_WAIT (pad);
3204 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3205 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3207 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3217 GST_DEBUG_OBJECT (pad, "pad is flushing");
3218 return GST_FLOW_FLUSHING;
3222 GST_DEBUG_OBJECT (pad, "data is dropped");
3223 return GST_FLOW_CUSTOM_SUCCESS;
3227 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3228 GST_DEBUG_OBJECT (pad, "data is passed");
3236 * gst_pad_get_offset:
3239 * Get the offset applied to the running time of @pad. @pad has to be a source
3242 * Returns: the offset.
3245 gst_pad_get_offset (GstPad * pad)
3249 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3251 GST_OBJECT_LOCK (pad);
3252 result = pad->offset;
3253 GST_OBJECT_UNLOCK (pad);
3259 * gst_pad_set_offset:
3261 * @offset: the offset
3263 * Set the offset that will be applied to the running time of @pad.
3266 gst_pad_set_offset (GstPad * pad, gint64 offset)
3270 g_return_if_fail (GST_IS_PAD (pad));
3272 GST_OBJECT_LOCK (pad);
3273 /* if nothing changed, do nothing */
3274 if (pad->offset == offset)
3277 pad->offset = offset;
3278 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3280 /* sinkpads will apply their offset the next time a segment
3281 * event is received. */
3282 if (GST_PAD_IS_SINK (pad))
3285 /* resend the last segment event on next buffer push */
3286 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3287 ev->received = FALSE;
3288 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3292 GST_OBJECT_UNLOCK (pad);
3299 /* If TRUE and ret is not OK this means
3300 * that pushing the EOS event failed
3304 /* If called for an event this is
3305 * the event that would be pushed
3306 * next. Don't forward sticky events
3307 * that would come after that */
3311 /* should be called with pad LOCK */
3313 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3315 PushStickyData *data = user_data;
3316 GstEvent *event = ev->event;
3319 GST_DEBUG_OBJECT (pad, "event %s was already received",
3320 GST_EVENT_TYPE_NAME (event));
3324 /* If we're called because of an sticky event, only forward
3325 * events that would come before this new event and the
3327 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3328 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3329 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3330 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3332 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3333 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3336 switch (data->ret) {
3338 ev->received = TRUE;
3339 GST_DEBUG_OBJECT (pad, "event %s marked received",
3340 GST_EVENT_TYPE_NAME (event));
3342 case GST_FLOW_CUSTOM_SUCCESS:
3343 /* we can't assume the event is received when it was dropped */
3344 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3345 GST_EVENT_TYPE_NAME (event));
3346 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3347 data->ret = GST_FLOW_OK;
3349 case GST_FLOW_CUSTOM_SUCCESS_1:
3350 /* event was ignored and should be sent later */
3351 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3352 GST_EVENT_TYPE_NAME (event));
3353 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3354 data->ret = GST_FLOW_OK;
3356 case GST_FLOW_NOT_LINKED:
3357 /* not linked is not a problem, we are sticky so the event will be
3358 * sent later but only for non-EOS events */
3359 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3360 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3361 data->ret = GST_FLOW_OK;
3362 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3365 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3366 gst_flow_get_name (data->ret));
3367 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3371 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3372 data->was_eos = TRUE;
3374 return data->ret == GST_FLOW_OK;
3377 /* check sticky events and push them when needed. should be called
3379 static inline GstFlowReturn
3380 check_sticky (GstPad * pad, GstEvent * event)
3382 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3384 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3385 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3387 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3388 events_foreach (pad, push_sticky, &data);
3390 /* If there's an EOS event we must push it downstream
3391 * even if sending a previous sticky event failed.
3392 * Otherwise the pipeline might wait forever for EOS.
3394 * Only do this if pushing another event than the EOS
3397 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3398 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3400 if (ev && !ev->received) {
3401 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3402 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3403 /* the event could have been dropped. Because this can only
3404 * happen if the user asked for it, it's not an error */
3405 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3406 data.ret = GST_FLOW_OK;
3416 * @pad: a #GstPad to invoke the default query on.
3417 * @query: (transfer none): the #GstQuery to perform.
3419 * Dispatches a query to a pad. The query should have been allocated by the
3420 * caller via one of the type-specific allocation functions. The element that
3421 * the pad belongs to is responsible for filling the query with an appropriate
3422 * response, which should then be parsed with a type-specific query parsing
3425 * Again, the caller is responsible for both the allocation and deallocation of
3426 * the query structure.
3428 * Please also note that some queries might need a running pipeline to work.
3430 * Returns: TRUE if the query could be performed.
3433 gst_pad_query (GstPad * pad, GstQuery * query)
3436 gboolean res, serialized;
3437 GstPadQueryFunction func;
3438 GstPadProbeType type;
3441 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3442 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3444 if (GST_PAD_IS_SRC (pad)) {
3445 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3446 goto wrong_direction;
3447 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3448 } else if (GST_PAD_IS_SINK (pad)) {
3449 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3450 goto wrong_direction;
3451 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3453 goto unknown_direction;
3455 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3456 GST_QUERY_TYPE_NAME (query));
3458 serialized = GST_QUERY_IS_SERIALIZED (query);
3459 if (G_UNLIKELY (serialized))
3460 GST_PAD_STREAM_LOCK (pad);
3462 GST_OBJECT_LOCK (pad);
3463 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3464 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3465 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3467 ACQUIRE_PARENT (pad, parent, no_parent);
3468 GST_OBJECT_UNLOCK (pad);
3470 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3473 res = func (pad, parent, query);
3475 RELEASE_PARENT (parent);
3477 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3478 GST_QUERY_TYPE_NAME (query), res);
3483 GST_OBJECT_LOCK (pad);
3484 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3485 GST_OBJECT_UNLOCK (pad);
3487 if (G_UNLIKELY (serialized))
3488 GST_PAD_STREAM_UNLOCK (pad);
3495 g_warning ("pad %s:%s query %s in wrong direction",
3496 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3501 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3506 GST_DEBUG_OBJECT (pad, "had no parent");
3507 GST_OBJECT_UNLOCK (pad);
3508 if (G_UNLIKELY (serialized))
3509 GST_PAD_STREAM_UNLOCK (pad);
3514 GST_DEBUG_OBJECT (pad, "had no query function");
3515 RELEASE_PARENT (parent);
3516 if (G_UNLIKELY (serialized))
3517 GST_PAD_STREAM_UNLOCK (pad);
3522 GST_DEBUG_OBJECT (pad, "query failed");
3523 if (G_UNLIKELY (serialized))
3524 GST_PAD_STREAM_UNLOCK (pad);
3529 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3530 GST_OBJECT_UNLOCK (pad);
3531 if (G_UNLIKELY (serialized))
3532 GST_PAD_STREAM_UNLOCK (pad);
3534 /* if a probe dropped, we don't sent it further but assume that the probe
3535 * answered the query and return TRUE */
3536 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3546 * gst_pad_peer_query:
3547 * @pad: a #GstPad to invoke the peer query on.
3548 * @query: (transfer none): the #GstQuery to perform.
3550 * Performs gst_pad_query() on the peer of @pad.
3552 * The caller is responsible for both the allocation and deallocation of
3553 * the query structure.
3555 * Returns: TRUE if the query could be performed. This function returns %FALSE
3556 * if @pad has no peer.
3559 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3562 GstPadProbeType type;
3563 gboolean res, serialized;
3566 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3567 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3569 if (GST_PAD_IS_SRC (pad)) {
3570 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3571 goto wrong_direction;
3572 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3573 } else if (GST_PAD_IS_SINK (pad)) {
3574 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3575 goto wrong_direction;
3576 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3578 goto unknown_direction;
3580 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3581 GST_QUERY_TYPE_NAME (query));
3583 serialized = GST_QUERY_IS_SERIALIZED (query);
3585 GST_OBJECT_LOCK (pad);
3586 if (GST_PAD_IS_SRC (pad) && serialized) {
3587 /* all serialized queries on the srcpad trigger push of
3589 if (!check_sticky (pad, NULL) == GST_FLOW_OK)
3593 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3594 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3595 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3597 peerpad = GST_PAD_PEER (pad);
3598 if (G_UNLIKELY (peerpad == NULL))
3601 gst_object_ref (peerpad);
3602 GST_OBJECT_UNLOCK (pad);
3604 res = gst_pad_query (peerpad, query);
3606 gst_object_unref (peerpad);
3611 GST_OBJECT_LOCK (pad);
3612 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3613 GST_OBJECT_UNLOCK (pad);
3620 g_warning ("pad %s:%s query %s in wrong direction",
3621 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3626 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3631 GST_WARNING_OBJECT (pad, "could not send sticky events");
3632 GST_OBJECT_UNLOCK (pad);
3637 GST_INFO_OBJECT (pad, "pad has no peer");
3638 GST_OBJECT_UNLOCK (pad);
3643 GST_DEBUG_OBJECT (pad, "query failed");
3648 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3649 GST_OBJECT_UNLOCK (pad);
3651 /* if a probe dropped, we don't sent it further but assume that the probe
3652 * answered the query and return TRUE */
3653 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3662 /**********************************************************************
3663 * Data passing functions
3666 /* this is the chain function that does not perform the additional argument
3667 * checking for that little extra speed.
3669 static inline GstFlowReturn
3670 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3675 GST_PAD_STREAM_LOCK (pad);
3677 GST_OBJECT_LOCK (pad);
3678 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3681 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3684 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3687 #ifndef G_DISABLE_ASSERT
3688 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3689 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3691 ":%s:<%s:%s> Got data flow before stream-start event",
3692 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3694 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3696 ":%s:<%s:%s> Got data flow before segment event",
3697 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3699 pad->priv->last_cookie = pad->priv->events_cookie;
3703 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3705 PROBE_PUSH (pad, type, data, probe_stopped);
3707 parent = GST_OBJECT_PARENT (pad);
3708 GST_OBJECT_UNLOCK (pad);
3710 /* NOTE: we read the chainfunc unlocked.
3711 * we cannot hold the lock for the pad so we might send
3712 * the data to the wrong function. This is not really a
3713 * problem since functions are assigned at creation time
3714 * and don't change that often... */
3715 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3716 GstPadChainFunction chainfunc;
3718 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3721 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3722 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3723 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3725 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3727 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3728 "called chainfunction &%s with buffer %p, returned %s",
3729 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3731 GstPadChainListFunction chainlistfunc;
3733 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3736 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3737 "calling chainlistfunction &%s",
3738 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3740 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3742 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3743 "called chainlistfunction &%s, returned %s",
3744 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3747 GST_PAD_STREAM_UNLOCK (pad);
3754 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3755 "chaining, but pad was flushing");
3756 GST_OBJECT_UNLOCK (pad);
3757 GST_PAD_STREAM_UNLOCK (pad);
3758 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3759 return GST_FLOW_FLUSHING;
3763 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3764 GST_OBJECT_UNLOCK (pad);
3765 GST_PAD_STREAM_UNLOCK (pad);
3766 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3767 return GST_FLOW_EOS;
3771 g_critical ("chain on pad %s:%s but it was not in push mode",
3772 GST_DEBUG_PAD_NAME (pad));
3773 GST_OBJECT_UNLOCK (pad);
3774 GST_PAD_STREAM_UNLOCK (pad);
3775 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3776 return GST_FLOW_ERROR;
3780 GST_OBJECT_UNLOCK (pad);
3781 GST_PAD_STREAM_UNLOCK (pad);
3782 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3785 case GST_FLOW_CUSTOM_SUCCESS:
3786 GST_DEBUG_OBJECT (pad, "dropped buffer");
3790 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
3797 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3798 g_critical ("chain on pad %s:%s but it has no chainfunction",
3799 GST_DEBUG_PAD_NAME (pad));
3800 GST_PAD_STREAM_UNLOCK (pad);
3801 return GST_FLOW_NOT_SUPPORTED;
3807 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3808 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3811 * Chain a buffer to @pad.
3813 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3815 * If the buffer type is not acceptable for @pad (as negotiated with a
3816 * preceding GST_EVENT_CAPS event), this function returns
3817 * #GST_FLOW_NOT_NEGOTIATED.
3819 * The function proceeds calling the chain function installed on @pad (see
3820 * gst_pad_set_chain_function()) and the return value of that function is
3821 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3824 * In all cases, success or failure, the caller loses its reference to @buffer
3825 * after calling this function.
3827 * Returns: a #GstFlowReturn from the pad.
3832 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3834 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3835 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3836 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3838 return gst_pad_chain_data_unchecked (pad,
3839 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3842 static GstFlowReturn
3843 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3844 GstBufferList * list)
3850 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3852 len = gst_buffer_list_length (list);
3855 for (i = 0; i < len; i++) {
3856 buffer = gst_buffer_list_get (list, i);
3858 gst_pad_chain_data_unchecked (pad,
3859 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3860 gst_buffer_ref (buffer));
3861 if (ret != GST_FLOW_OK)
3864 gst_buffer_list_unref (list);
3870 * gst_pad_chain_list:
3871 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3872 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3875 * Chain a bufferlist to @pad.
3877 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3879 * If @pad was not negotiated properly with a CAPS event, this function
3880 * returns #GST_FLOW_NOT_NEGOTIATED.
3882 * The function proceeds calling the chainlist function installed on @pad (see
3883 * gst_pad_set_chain_list_function()) and the return value of that function is
3884 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3885 * chainlist function.
3887 * In all cases, success or failure, the caller loses its reference to @list
3888 * after calling this function.
3892 * Returns: a #GstFlowReturn from the pad.
3895 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3897 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3898 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3899 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3901 return gst_pad_chain_data_unchecked (pad,
3902 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3905 static GstFlowReturn
3906 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3911 GST_OBJECT_LOCK (pad);
3912 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3915 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3918 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3921 #ifndef G_DISABLE_ASSERT
3922 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3923 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3925 ":%s:<%s:%s> Got data flow before stream-start event",
3926 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3928 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3930 ":%s:<%s:%s> Got data flow before segment event",
3931 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3933 pad->priv->last_cookie = pad->priv->events_cookie;
3937 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3940 /* do block probes */
3941 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3943 /* recheck sticky events because the probe might have cause a relink */
3944 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3947 /* do post-blocking probes */
3948 PROBE_PUSH (pad, type, data, probe_stopped);
3950 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3953 /* take ref to peer pad before releasing the lock */
3954 gst_object_ref (peer);
3956 GST_OBJECT_UNLOCK (pad);
3958 ret = gst_pad_chain_data_unchecked (peer, type, data);
3960 gst_object_unref (peer);
3962 GST_OBJECT_LOCK (pad);
3964 if (pad->priv->using == 0) {
3965 /* pad is not active anymore, trigger idle callbacks */
3966 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3967 probe_stopped, ret);
3969 GST_OBJECT_UNLOCK (pad);
3973 /* ERROR recovery here */
3977 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3978 "pushing, but pad was flushing");
3979 GST_OBJECT_UNLOCK (pad);
3980 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3981 return GST_FLOW_FLUSHING;
3985 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
3986 GST_OBJECT_UNLOCK (pad);
3987 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3988 return GST_FLOW_EOS;
3992 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
3993 GST_DEBUG_PAD_NAME (pad));
3994 GST_OBJECT_UNLOCK (pad);
3995 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3996 return GST_FLOW_ERROR;
4000 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4001 "error pushing events, return %s", gst_flow_get_name (ret));
4002 GST_OBJECT_UNLOCK (pad);
4003 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4008 GST_OBJECT_UNLOCK (pad);
4009 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4012 case GST_FLOW_CUSTOM_SUCCESS:
4013 GST_DEBUG_OBJECT (pad, "dropped buffer");
4017 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4024 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4025 "pushing, but it was not linked");
4026 GST_OBJECT_UNLOCK (pad);
4027 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4028 return GST_FLOW_NOT_LINKED;
4034 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4035 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4038 * Pushes a buffer to the peer of @pad.
4040 * This function will call installed block probes before triggering any
4041 * installed data probes.
4043 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4044 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4047 * In all cases, success or failure, the caller loses its reference to @buffer
4048 * after calling this function.
4050 * Returns: a #GstFlowReturn from the peer pad.
4055 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4057 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4058 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4059 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4061 return gst_pad_push_data (pad,
4062 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4066 * gst_pad_push_list:
4067 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4068 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4071 * Pushes a buffer list to the peer of @pad.
4073 * This function will call installed block probes before triggering any
4074 * installed data probes.
4076 * The function proceeds calling the chain function on the peer pad and returns
4077 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4078 * be returned. If the peer pad does not have any installed chainlist function
4079 * every group buffer of the list will be merged into a normal #GstBuffer and
4080 * chained via gst_pad_chain().
4082 * In all cases, success or failure, the caller loses its reference to @list
4083 * after calling this function.
4085 * Returns: a #GstFlowReturn from the peer pad.
4090 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4092 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4093 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4094 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4096 return gst_pad_push_data (pad,
4097 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4100 static GstFlowReturn
4101 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4102 GstBuffer ** buffer)
4105 GstPadGetRangeFunction getrangefunc;
4109 GST_PAD_STREAM_LOCK (pad);
4111 GST_OBJECT_LOCK (pad);
4112 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4115 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4118 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4123 /* when one of the probes returns DROPPED, probe_stopped will be called
4124 * and we skip calling the getrange function, res_buf should then contain a
4125 * valid result buffer */
4126 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4127 res_buf, offset, size, probe_stopped);
4129 /* recheck sticky events because the probe might have cause a relink */
4130 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4133 ACQUIRE_PARENT (pad, parent, no_parent);
4134 GST_OBJECT_UNLOCK (pad);
4136 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4139 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4140 "calling getrangefunc %s, offset %"
4141 G_GUINT64_FORMAT ", size %u",
4142 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4144 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4146 RELEASE_PARENT (parent);
4148 if (G_UNLIKELY (ret != GST_FLOW_OK))
4149 goto get_range_failed;
4151 /* can only fire the signal if we have a valid buffer */
4152 GST_OBJECT_LOCK (pad);
4154 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4155 res_buf, offset, size, probe_stopped_unref);
4156 GST_OBJECT_UNLOCK (pad);
4158 GST_PAD_STREAM_UNLOCK (pad);
4167 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4168 "getrange, but pad was flushing");
4169 GST_OBJECT_UNLOCK (pad);
4170 GST_PAD_STREAM_UNLOCK (pad);
4171 return GST_FLOW_FLUSHING;
4175 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4176 GST_DEBUG_PAD_NAME (pad));
4177 GST_OBJECT_UNLOCK (pad);
4178 GST_PAD_STREAM_UNLOCK (pad);
4179 return GST_FLOW_ERROR;
4183 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4184 GST_OBJECT_UNLOCK (pad);
4185 GST_PAD_STREAM_UNLOCK (pad);
4190 GST_DEBUG_OBJECT (pad, "no parent");
4191 GST_OBJECT_UNLOCK (pad);
4192 GST_PAD_STREAM_UNLOCK (pad);
4193 return GST_FLOW_FLUSHING;
4197 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4198 GST_DEBUG_PAD_NAME (pad));
4199 RELEASE_PARENT (parent);
4200 GST_PAD_STREAM_UNLOCK (pad);
4201 return GST_FLOW_NOT_SUPPORTED;
4205 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4206 "probe returned %s", gst_flow_get_name (ret));
4207 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4209 /* the probe filled the buffer and asks us to not call the getrange
4210 * anymore, we continue with the post probes then. */
4211 GST_DEBUG_OBJECT (pad, "handled buffer");
4215 /* no buffer, we are EOS */
4216 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4220 GST_OBJECT_UNLOCK (pad);
4221 GST_PAD_STREAM_UNLOCK (pad);
4225 probe_stopped_unref:
4227 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4228 "probe returned %s", gst_flow_get_name (ret));
4229 /* if we drop here, it signals EOS */
4230 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4232 GST_OBJECT_UNLOCK (pad);
4233 GST_PAD_STREAM_UNLOCK (pad);
4234 if (*buffer == NULL)
4235 gst_buffer_unref (res_buf);
4240 GST_PAD_STREAM_UNLOCK (pad);
4241 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4242 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4243 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4249 * gst_pad_get_range:
4250 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4251 * @offset: The start offset of the buffer
4252 * @size: The length of the buffer
4253 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4254 * returns #GST_FLOW_ERROR if %NULL.
4256 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4257 * immediately and @buffer is %NULL.
4259 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4260 * description of a getrange function. If @pad has no getrange function
4261 * installed (see gst_pad_set_getrange_function()) this function returns
4262 * #GST_FLOW_NOT_SUPPORTED.
4264 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4265 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4266 * must be freed with gst_buffer_unref() after usage.
4268 * When @buffer points to a variable that points to a valid #GstBuffer, the
4269 * buffer will be filled with the result data when this function returns
4270 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4271 * @size bytes will be filled in the result buffer and its size will be updated
4274 * Note that less than @size bytes can be returned in @buffer when, for example,
4275 * an EOS condition is near or when @buffer is not large enough to hold @size
4276 * bytes. The caller should check the result buffer size to get the result size.
4278 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4279 * will be unchanged.
4281 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4283 * Returns: a #GstFlowReturn from the pad.
4288 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4289 GstBuffer ** buffer)
4291 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4292 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4293 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4294 g_return_val_if_fail (*buffer == NULL
4295 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4297 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4301 * gst_pad_pull_range:
4302 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4303 * @offset: The start offset of the buffer
4304 * @size: The length of the buffer
4305 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4306 * GST_FLOW_ERROR if %NULL.
4308 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4310 * This function will first trigger the pad block signal if it was
4313 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4314 * function returns the result of gst_pad_get_range() on the peer pad.
4315 * See gst_pad_get_range() for a list of return values and for the
4316 * semantics of the arguments of this function.
4318 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4319 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4320 * must be freed with gst_buffer_unref() after usage. When this function
4321 * returns any other result value, @buffer will still point to NULL.
4323 * When @buffer points to a variable that points to a valid #GstBuffer, the
4324 * buffer will be filled with the result data when this function returns
4325 * #GST_FLOW_OK. When this function returns any other result value,
4326 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4327 * @size bytes will be filled in the result buffer and its size will be updated
4330 * Note that less than @size bytes can be returned in @buffer when, for example,
4331 * an EOS condition is near or when @buffer is not large enough to hold @size
4332 * bytes. The caller should check the result buffer size to get the result size.
4334 * Returns: a #GstFlowReturn from the peer pad.
4339 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4340 GstBuffer ** buffer)
4346 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4347 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4348 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4349 g_return_val_if_fail (*buffer == NULL
4350 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4352 GST_OBJECT_LOCK (pad);
4353 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4356 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4361 /* when one of the probes returns DROPPED, probe_stopped will be
4362 * called and we skip calling the peer getrange function. *buffer should then
4363 * contain a valid buffer */
4364 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4365 res_buf, offset, size, probe_stopped);
4367 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4370 gst_object_ref (peer);
4372 GST_OBJECT_UNLOCK (pad);
4374 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4376 gst_object_unref (peer);
4378 GST_OBJECT_LOCK (pad);
4380 if (pad->priv->using == 0) {
4381 /* pad is not active anymore, trigger idle callbacks */
4382 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4383 probe_stopped_unref, ret);
4386 if (G_UNLIKELY (ret != GST_FLOW_OK))
4387 goto pull_range_failed;
4390 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4391 res_buf, offset, size, probe_stopped_unref);
4393 GST_OBJECT_UNLOCK (pad);
4399 /* ERROR recovery here */
4402 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4403 "pullrange, but pad was flushing");
4404 GST_OBJECT_UNLOCK (pad);
4405 return GST_FLOW_FLUSHING;
4409 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4410 GST_DEBUG_PAD_NAME (pad));
4411 GST_OBJECT_UNLOCK (pad);
4412 return GST_FLOW_ERROR;
4416 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4417 gst_flow_get_name (ret));
4418 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4420 /* the probe filled the buffer and asks us to not forward to the peer
4421 * anymore, we continue with the post probes then */
4422 GST_DEBUG_OBJECT (pad, "handled buffer");
4426 /* no buffer, we are EOS then */
4427 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4431 GST_OBJECT_UNLOCK (pad);
4436 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4437 "pulling range, but it was not linked");
4438 GST_OBJECT_UNLOCK (pad);
4439 return GST_FLOW_NOT_LINKED;
4443 GST_OBJECT_UNLOCK (pad);
4444 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4445 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4446 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4449 probe_stopped_unref:
4451 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4452 "post probe returned %s", gst_flow_get_name (ret));
4453 GST_OBJECT_UNLOCK (pad);
4454 /* if we drop here, it signals EOS */
4455 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4457 if (*buffer == NULL)
4458 gst_buffer_unref (res_buf);
4463 /* must be called with pad object lock */
4464 static GstFlowReturn
4465 store_sticky_event (GstPad * pad, GstEvent * event)
4470 gboolean res = FALSE;
4471 const gchar *name = NULL;
4472 gboolean insert = TRUE;
4474 type = GST_EVENT_TYPE (event);
4476 /* Store all sticky events except SEGMENT/SEGMENT when we're flushing,
4477 * otherwise they can be dropped and nothing would ever resend them.
4478 * Only do that for activated pads though, everything else is a bug!
4480 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4481 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4482 || type == GST_EVENT_EOS))))
4485 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4488 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4489 name = gst_structure_get_name (gst_event_get_structure (event));
4491 events = pad->priv->events;
4494 for (i = 0; i < len; i++) {
4495 PadEvent *ev = &g_array_index (events, PadEvent, i);
4497 if (ev->event == NULL)
4500 if (type == GST_EVENT_TYPE (ev->event)) {
4501 /* matching types, check matching name if needed */
4502 if (name && !gst_event_has_name (ev->event, name))
4506 if ((res = gst_event_replace (&ev->event, event)))
4507 ev->received = FALSE;
4513 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4514 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4515 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4516 * storing the sticky ordered we can check that this is respected. */
4517 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4518 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4520 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4521 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4522 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4523 gst_event_type_get_name (type));
4529 ev.event = gst_event_ref (event);
4530 ev.received = FALSE;
4531 g_array_insert_val (events, i, ev);
4536 pad->priv->events_cookie++;
4537 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4539 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4541 switch (GST_EVENT_TYPE (event)) {
4542 case GST_EVENT_CAPS:
4543 GST_OBJECT_UNLOCK (pad);
4545 GST_DEBUG_OBJECT (pad, "notify caps");
4546 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4548 GST_OBJECT_LOCK (pad);
4554 if (type == GST_EVENT_EOS)
4555 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4557 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4562 GST_DEBUG_OBJECT (pad, "pad is flushing");
4563 return GST_FLOW_FLUSHING;
4567 GST_DEBUG_OBJECT (pad, "pad is EOS");
4568 return GST_FLOW_EOS;
4573 * gst_pad_store_sticky_event:
4575 * @event: a #GstEvent
4577 * Store the sticky @event on @pad
4579 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4580 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4585 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4589 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4590 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4592 GST_OBJECT_LOCK (pad);
4593 ret = store_sticky_event (pad, event);
4594 GST_OBJECT_UNLOCK (pad);
4600 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
4602 PushStickyData *data = user_data;
4604 /* Forward all sticky events before our current one that are pending */
4605 if (ev->event != data->event
4606 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
4607 return push_sticky (pad, ev, data);
4612 /* should be called with pad LOCK */
4613 static GstFlowReturn
4614 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4615 GstPadProbeType type)
4619 GstEventType event_type;
4621 /* Two checks to be made:
4622 * . (un)set the FLUSHING flag for flushing events,
4623 * . handle pad blocking */
4624 event_type = GST_EVENT_TYPE (event);
4625 switch (event_type) {
4626 case GST_EVENT_FLUSH_START:
4627 GST_PAD_SET_FLUSHING (pad);
4629 GST_PAD_BLOCK_BROADCAST (pad);
4630 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4632 case GST_EVENT_FLUSH_STOP:
4633 GST_PAD_UNSET_FLUSHING (pad);
4635 /* Remove sticky EOS events */
4636 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4637 remove_event_by_type (pad, GST_EVENT_EOS);
4638 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4639 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4641 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4645 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4648 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4649 * checked already or this is called as part of pushing sticky events,
4650 * in which case we still want to forward the EOS event downstream.
4653 switch (GST_EVENT_TYPE (event)) {
4654 case GST_EVENT_SEGMENT:
4655 /* pass the adjusted segment event on. We need to do this even if
4656 * there is no peer pad because of the probes. */
4657 event = apply_pad_offset (pad, event);
4659 case GST_EVENT_RECONFIGURE:
4660 if (GST_PAD_IS_SINK (pad))
4661 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4666 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4667 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4672 /* send probes after modifying the events above */
4673 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4675 /* recheck sticky events because the probe might have cause a relink */
4676 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
4677 && (GST_EVENT_IS_SERIALIZED (event)
4678 || GST_EVENT_IS_STICKY (event))) {
4679 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4680 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4682 /* Push all sticky events before our current one
4683 * that have changed */
4684 events_foreach (pad, sticky_changed, &data);
4687 /* now check the peer pad */
4688 peerpad = GST_PAD_PEER (pad);
4689 if (peerpad == NULL)
4692 gst_object_ref (peerpad);
4694 GST_OBJECT_UNLOCK (pad);
4696 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4697 event, GST_EVENT_TYPE_NAME (event), peerpad);
4699 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4701 /* Note: we gave away ownership of the event at this point but we can still
4702 * print the old pointer */
4703 GST_LOG_OBJECT (pad, "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s",
4704 event, peerpad, gst_flow_get_name (ret));
4706 gst_object_unref (peerpad);
4708 GST_OBJECT_LOCK (pad);
4710 if (pad->priv->using == 0) {
4711 /* pad is not active anymore, trigger idle callbacks */
4712 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4713 idle_probe_stopped, ret);
4717 /* ERROR handling */
4720 GST_DEBUG_OBJECT (pad, "We're flushing");
4721 gst_event_unref (event);
4722 return GST_FLOW_FLUSHING;
4726 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4727 gst_event_unref (event);
4730 case GST_FLOW_CUSTOM_SUCCESS:
4731 GST_DEBUG_OBJECT (pad, "dropped event");
4734 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4741 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4742 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4743 gst_event_unref (event);
4745 /* unlinked pads should not influence latency configuration */
4746 if (event_type == GST_EVENT_LATENCY)
4749 return GST_FLOW_NOT_LINKED;
4753 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4759 * gst_pad_push_event:
4760 * @pad: a #GstPad to push the event to.
4761 * @event: (transfer full): the #GstEvent to send to the pad.
4763 * Sends the event to the peer of the given pad. This function is
4764 * mainly used by elements to send events to their peer
4767 * This function takes ownership of the provided event so you should
4768 * gst_event_ref() it if you want to reuse the event after this call.
4770 * Returns: TRUE if the event was handled.
4775 gst_pad_push_event (GstPad * pad, GstEvent * event)
4777 gboolean res = FALSE;
4778 GstPadProbeType type;
4779 gboolean sticky, serialized;
4781 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4782 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4784 if (GST_PAD_IS_SRC (pad)) {
4785 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4786 goto wrong_direction;
4787 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4788 } else if (GST_PAD_IS_SINK (pad)) {
4789 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4790 goto wrong_direction;
4791 /* events pushed on sinkpad never are sticky */
4792 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4794 goto unknown_direction;
4796 GST_OBJECT_LOCK (pad);
4797 sticky = GST_EVENT_IS_STICKY (event);
4798 serialized = GST_EVENT_IS_SERIALIZED (event);
4801 /* srcpad sticky events are stored immediately, the received flag is set
4802 * to FALSE and will be set to TRUE when we can successfully push the
4803 * event to the peer pad */
4804 switch (store_sticky_event (pad, event)) {
4805 case GST_FLOW_FLUSHING:
4813 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4814 /* all serialized or sticky events on the srcpad trigger push of
4816 res = (check_sticky (pad, event) == GST_FLOW_OK);
4821 /* other events are pushed right away */
4822 ret = gst_pad_push_event_unchecked (pad, event, type);
4823 /* dropped events by a probe are not an error */
4824 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4826 /* Errors in sticky event pushing are no problem and ignored here
4827 * as they will cause more meaningful errors during data flow.
4828 * For EOS events, that are not followed by data flow, we still
4829 * return FALSE here though.
4831 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4833 gst_event_unref (event);
4835 GST_OBJECT_UNLOCK (pad);
4839 /* ERROR handling */
4842 g_warning ("pad %s:%s pushing %s event in wrong direction",
4843 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4844 gst_event_unref (event);
4849 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4850 gst_event_unref (event);
4855 GST_DEBUG_OBJECT (pad, "We're flushing");
4856 GST_OBJECT_UNLOCK (pad);
4857 gst_event_unref (event);
4862 GST_DEBUG_OBJECT (pad, "We're EOS");
4863 GST_OBJECT_UNLOCK (pad);
4864 gst_event_unref (event);
4869 /* Check if we can call the event function with the given event */
4870 static GstFlowReturn
4871 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4875 switch (GST_EVENT_TYPE (event)) {
4876 case GST_EVENT_CAPS:
4878 /* backwards compatibility mode for caps */
4879 gst_event_parse_caps (event, &caps);
4881 if (!gst_pad_query_accept_caps (pad, caps))
4893 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4894 "caps %" GST_PTR_FORMAT " not accepted", caps);
4895 return GST_FLOW_NOT_NEGOTIATED;
4899 static GstFlowReturn
4900 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4901 GstPadProbeType type)
4904 GstEventType event_type;
4905 gboolean serialized, need_unlock = FALSE, sticky;
4906 GstPadEventFunction eventfunc;
4909 GST_OBJECT_LOCK (pad);
4910 if (GST_PAD_IS_SINK (pad))
4911 serialized = GST_EVENT_IS_SERIALIZED (event);
4914 sticky = GST_EVENT_IS_STICKY (event);
4915 event_type = GST_EVENT_TYPE (event);
4916 switch (event_type) {
4917 case GST_EVENT_FLUSH_START:
4918 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4919 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4921 /* can't even accept a flush begin event when flushing */
4922 if (GST_PAD_IS_FLUSHING (pad))
4925 GST_PAD_SET_FLUSHING (pad);
4926 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4928 case GST_EVENT_FLUSH_STOP:
4929 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4930 GST_PAD_UNSET_FLUSHING (pad);
4931 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4933 /* Remove pending EOS events */
4934 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
4935 remove_event_by_type (pad, GST_EVENT_EOS);
4936 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4937 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4939 GST_OBJECT_UNLOCK (pad);
4940 /* grab stream lock */
4941 GST_PAD_STREAM_LOCK (pad);
4943 GST_OBJECT_LOCK (pad);
4944 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4947 case GST_EVENT_RECONFIGURE:
4948 if (GST_PAD_IS_SRC (pad))
4949 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4951 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4952 "have event type %" GST_PTR_FORMAT, event);
4954 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4958 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4961 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4962 GST_OBJECT_UNLOCK (pad);
4963 GST_PAD_STREAM_LOCK (pad);
4965 GST_OBJECT_LOCK (pad);
4966 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4969 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4973 switch (GST_EVENT_TYPE (event)) {
4974 case GST_EVENT_SEGMENT:
4975 event = apply_pad_offset (pad, event);
4983 /* now do the probe */
4985 type | GST_PAD_PROBE_TYPE_PUSH |
4986 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4988 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4990 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4993 ACQUIRE_PARENT (pad, parent, no_parent);
4994 GST_OBJECT_UNLOCK (pad);
4996 ret = pre_eventfunc_check (pad, event);
4997 if (G_UNLIKELY (ret != GST_FLOW_OK))
4998 goto precheck_failed;
5001 gst_event_ref (event);
5003 if (eventfunc (pad, parent, event)) {
5006 /* something went wrong */
5007 switch (event_type) {
5008 case GST_EVENT_CAPS:
5009 ret = GST_FLOW_NOT_NEGOTIATED;
5012 ret = GST_FLOW_ERROR;
5016 RELEASE_PARENT (parent);
5018 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5021 if (ret == GST_FLOW_OK) {
5022 GST_OBJECT_LOCK (pad);
5023 /* after the event function accepted the event, we can store the sticky
5024 * event on the pad */
5025 switch (store_sticky_event (pad, event)) {
5026 case GST_FLOW_FLUSHING:
5033 GST_OBJECT_UNLOCK (pad);
5035 gst_event_unref (event);
5039 GST_PAD_STREAM_UNLOCK (pad);
5043 /* ERROR handling */
5046 GST_OBJECT_UNLOCK (pad);
5048 GST_PAD_STREAM_UNLOCK (pad);
5049 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5050 "Received event on flushing pad. Discarding");
5051 gst_event_unref (event);
5052 return GST_FLOW_FLUSHING;
5056 GST_OBJECT_UNLOCK (pad);
5058 GST_PAD_STREAM_UNLOCK (pad);
5059 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5060 "Received event on EOS pad. Discarding");
5061 gst_event_unref (event);
5062 return GST_FLOW_EOS;
5066 GST_OBJECT_UNLOCK (pad);
5068 GST_PAD_STREAM_UNLOCK (pad);
5069 gst_event_unref (event);
5072 case GST_FLOW_CUSTOM_SUCCESS:
5073 GST_DEBUG_OBJECT (pad, "dropped event");
5077 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5084 g_warning ("pad %s:%s has no event handler, file a bug.",
5085 GST_DEBUG_PAD_NAME (pad));
5086 GST_OBJECT_UNLOCK (pad);
5088 GST_PAD_STREAM_UNLOCK (pad);
5089 gst_event_unref (event);
5090 return GST_FLOW_NOT_SUPPORTED;
5094 GST_DEBUG_OBJECT (pad, "no parent");
5095 GST_OBJECT_UNLOCK (pad);
5097 GST_PAD_STREAM_UNLOCK (pad);
5098 gst_event_unref (event);
5099 return GST_FLOW_FLUSHING;
5103 GST_DEBUG_OBJECT (pad, "pre event check failed");
5104 RELEASE_PARENT (parent);
5106 GST_PAD_STREAM_UNLOCK (pad);
5107 gst_event_unref (event);
5113 * gst_pad_send_event:
5114 * @pad: a #GstPad to send the event to.
5115 * @event: (transfer full): the #GstEvent to send to the pad.
5117 * Sends the event to the pad. This function can be used
5118 * by applications to send events in the pipeline.
5120 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5121 * sink pad, @event should be a downstream event. For example, you would not
5122 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5123 * Furthermore, some downstream events have to be serialized with data flow,
5124 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5125 * the event needs to be serialized with data flow, this function will take the
5126 * pad's stream lock while calling its event function.
5128 * To find out whether an event type is upstream, downstream, or downstream and
5129 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5130 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5131 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5132 * plugin doesn't need to bother itself with this information; the core handles
5133 * all necessary locks and checks.
5135 * This function takes ownership of the provided event so you should
5136 * gst_event_ref() it if you want to reuse the event after this call.
5138 * Returns: TRUE if the event was handled.
5141 gst_pad_send_event (GstPad * pad, GstEvent * event)
5144 GstPadProbeType type;
5146 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5147 g_return_val_if_fail (event != NULL, FALSE);
5149 if (GST_PAD_IS_SINK (pad)) {
5150 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5151 goto wrong_direction;
5152 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5153 } else if (GST_PAD_IS_SRC (pad)) {
5154 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5155 goto wrong_direction;
5156 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5158 goto unknown_direction;
5160 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5167 /* ERROR handling */
5170 g_warning ("pad %s:%s sending %s event in wrong direction",
5171 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5172 gst_event_unref (event);
5177 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5178 gst_event_unref (event);
5184 * gst_pad_set_element_private:
5185 * @pad: the #GstPad to set the private data of.
5186 * @priv: The private data to attach to the pad.
5188 * Set the given private data gpointer on the pad.
5189 * This function can only be used by the element that owns the pad.
5190 * No locking is performed in this function.
5193 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5195 pad->element_private = priv;
5199 * gst_pad_get_element_private:
5200 * @pad: the #GstPad to get the private data of.
5202 * Gets the private data of a pad.
5203 * No locking is performed in this function.
5205 * Returns: (transfer none): a #gpointer to the private data.
5208 gst_pad_get_element_private (GstPad * pad)
5210 return pad->element_private;
5214 * gst_pad_get_sticky_event:
5215 * @pad: the #GstPad to get the event from.
5216 * @event_type: the #GstEventType that should be retrieved.
5217 * @idx: the index of the event
5219 * Returns a new reference of the sticky event of type @event_type
5222 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
5223 * event of @event_type was on @pad. Unref after usage.
5226 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5228 GstEvent *event = NULL;
5231 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5232 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5234 GST_OBJECT_LOCK (pad);
5235 ev = find_event_by_type (pad, event_type, idx);
5236 if (ev && (event = ev->event))
5237 gst_event_ref (event);
5238 GST_OBJECT_UNLOCK (pad);
5245 GstPadStickyEventsForeachFunction func;
5250 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5252 ForeachDispatch *data = user_data;
5253 gboolean ret = TRUE;
5256 GST_OBJECT_UNLOCK (pad);
5258 ret = data->func (pad, &ev->event, data->user_data);
5260 GST_OBJECT_LOCK (pad);
5267 * gst_pad_sticky_events_foreach:
5268 * @pad: the #GstPad that should be used for iteration.
5269 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5270 * should be called for every event.
5271 * @user_data: (closure): the optional user data.
5273 * Iterates all sticky events on @pad and calls @foreach_func for every
5274 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5277 gst_pad_sticky_events_foreach (GstPad * pad,
5278 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5280 ForeachDispatch data;
5282 g_return_if_fail (GST_IS_PAD (pad));
5283 g_return_if_fail (foreach_func != NULL);
5285 data.func = foreach_func;
5286 data.user_data = user_data;
5288 GST_OBJECT_LOCK (pad);
5289 events_foreach (pad, foreach_dispatch_function, &data);
5290 GST_OBJECT_UNLOCK (pad);
5294 do_stream_status (GstPad * pad, GstStreamStatusType type,
5295 GThread * thread, GstTask * task)
5299 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5301 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5302 if (GST_IS_ELEMENT (parent)) {
5303 GstMessage *message;
5304 GValue value = { 0 };
5306 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5307 gchar *tname, *ename, *pname;
5309 /* create a good task name */
5310 ename = gst_element_get_name (parent);
5311 pname = gst_pad_get_name (pad);
5312 tname = g_strdup_printf ("%s:%s", ename, pname);
5316 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5320 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5323 g_value_init (&value, GST_TYPE_TASK);
5324 g_value_set_object (&value, task);
5325 gst_message_set_stream_status_object (message, &value);
5326 g_value_unset (&value);
5328 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5329 gst_element_post_message (parent, message);
5331 gst_object_unref (parent);
5336 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5338 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5343 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5345 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5350 * gst_pad_start_task:
5351 * @pad: the #GstPad to start the task of
5352 * @func: the task function to call
5353 * @user_data: user data passed to the task function
5354 * @notify: called when @user_data is no longer referenced
5356 * Starts a task that repeatedly calls @func with @user_data. This function
5357 * is mostly used in pad activation functions to start the dataflow.
5358 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5359 * before @func is called.
5361 * Returns: a %TRUE if the task could be started.
5364 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5365 GDestroyNotify notify)
5370 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5371 g_return_val_if_fail (func != NULL, FALSE);
5373 GST_DEBUG_OBJECT (pad, "start task");
5375 GST_OBJECT_LOCK (pad);
5376 task = GST_PAD_TASK (pad);
5378 task = gst_task_new (func, user_data, notify);
5379 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5380 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5381 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5382 GST_INFO_OBJECT (pad, "created task %p", task);
5383 GST_PAD_TASK (pad) = task;
5384 gst_object_ref (task);
5385 /* release lock to post the message */
5386 GST_OBJECT_UNLOCK (pad);
5388 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5390 gst_object_unref (task);
5392 GST_OBJECT_LOCK (pad);
5393 /* nobody else is supposed to have changed the pad now */
5394 if (GST_PAD_TASK (pad) != task)
5395 goto concurrent_stop;
5397 res = gst_task_set_state (task, GST_TASK_STARTED);
5398 GST_OBJECT_UNLOCK (pad);
5405 GST_OBJECT_UNLOCK (pad);
5411 * gst_pad_pause_task:
5412 * @pad: the #GstPad to pause the task of
5414 * Pause the task of @pad. This function will also wait until the
5415 * function executed by the task is finished if this function is not
5416 * called from the task function.
5418 * Returns: a TRUE if the task could be paused or FALSE when the pad
5422 gst_pad_pause_task (GstPad * pad)
5427 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5429 GST_DEBUG_OBJECT (pad, "pause task");
5431 GST_OBJECT_LOCK (pad);
5432 task = GST_PAD_TASK (pad);
5435 res = gst_task_set_state (task, GST_TASK_PAUSED);
5436 GST_OBJECT_UNLOCK (pad);
5438 /* wait for task function to finish, this lock is recursive so it does nothing
5439 * when the pause is called from the task itself */
5440 GST_PAD_STREAM_LOCK (pad);
5441 GST_PAD_STREAM_UNLOCK (pad);
5447 GST_DEBUG_OBJECT (pad, "pad has no task");
5448 GST_OBJECT_UNLOCK (pad);
5454 * gst_pad_stop_task:
5455 * @pad: the #GstPad to stop the task of
5457 * Stop the task of @pad. This function will also make sure that the
5458 * function executed by the task will effectively stop if not called
5459 * from the GstTaskFunction.
5461 * This function will deadlock if called from the GstTaskFunction of
5462 * the task. Use gst_task_pause() instead.
5464 * Regardless of whether the pad has a task, the stream lock is acquired and
5465 * released so as to ensure that streaming through this pad has finished.
5467 * Returns: a TRUE if the task could be stopped or FALSE on error.
5470 gst_pad_stop_task (GstPad * pad)
5475 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5477 GST_DEBUG_OBJECT (pad, "stop task");
5479 GST_OBJECT_LOCK (pad);
5480 task = GST_PAD_TASK (pad);
5483 GST_PAD_TASK (pad) = NULL;
5484 res = gst_task_set_state (task, GST_TASK_STOPPED);
5485 GST_OBJECT_UNLOCK (pad);
5487 GST_PAD_STREAM_LOCK (pad);
5488 GST_PAD_STREAM_UNLOCK (pad);
5490 if (!gst_task_join (task))
5493 gst_object_unref (task);
5499 GST_DEBUG_OBJECT (pad, "no task");
5500 GST_OBJECT_UNLOCK (pad);
5502 GST_PAD_STREAM_LOCK (pad);
5503 GST_PAD_STREAM_UNLOCK (pad);
5505 /* this is not an error */
5510 /* this is bad, possibly the application tried to join the task from
5511 * the task's thread. We install the task again so that it will be stopped
5512 * again from the right thread next time hopefully. */
5513 GST_OBJECT_LOCK (pad);
5514 GST_DEBUG_OBJECT (pad, "join failed");
5515 /* we can only install this task if there was no other task */
5516 if (GST_PAD_TASK (pad) == NULL)
5517 GST_PAD_TASK (pad) = task;
5518 GST_OBJECT_UNLOCK (pad);
5525 * gst_pad_probe_info_get_event:
5526 * @info: a #GstPadProbeInfo
5528 * Returns: (transfer none): The #GstEvent from the probe
5532 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5534 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5535 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5537 return GST_PAD_PROBE_INFO_EVENT (info);
5542 * gst_pad_probe_info_get_query:
5543 * @info: a #GstPadProbeInfo
5545 * Returns: (transfer none): The #GstQuery from the probe
5549 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5551 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5552 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5554 return GST_PAD_PROBE_INFO_QUERY (info);
5558 * gst_pad_probe_info_get_buffer:
5559 * @info: a #GstPadProbeInfo
5561 * Returns: (transfer none): The #GstBuffer from the probe
5565 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5567 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5569 return GST_PAD_PROBE_INFO_BUFFER (info);
5573 * gst_pad_probe_info_get_bufferlist:
5574 * @info: a #GstPadProbeInfo
5576 * Returns: (transfer none): The #GstBufferlist from the probe
5580 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5582 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5584 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);