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 cleanup_hook (GstPad * pad, GHook * hook)
1186 GstPadProbeType type;
1188 if (!G_HOOK_IS_VALID (hook))
1191 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1193 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1194 /* unblock when we remove the last blocking probe */
1196 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1198 if (pad->num_blocked == 0) {
1199 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1200 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1201 GST_PAD_BLOCK_BROADCAST (pad);
1204 g_hook_destroy_link (&pad->probes, hook);
1209 * gst_pad_add_probe:
1210 * @pad: the #GstPad to add the probe to
1211 * @mask: the probe mask
1212 * @callback: #GstPadProbeCallback that will be called with notifications of
1214 * @user_data: (closure): user data passed to the callback
1215 * @destroy_data: #GDestroyNotify for user_data
1217 * Be notified of different states of pads. The provided callback is called for
1218 * every state that matches @mask.
1220 * Returns: an id or 0 on error. The id can be used to remove the probe with
1221 * gst_pad_remove_probe().
1226 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1227 GstPadProbeCallback callback, gpointer user_data,
1228 GDestroyNotify destroy_data)
1233 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1234 g_return_val_if_fail (mask != 0, 0);
1236 GST_OBJECT_LOCK (pad);
1238 /* make a new probe */
1239 hook = g_hook_alloc (&pad->probes);
1241 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1244 /* when no contraints are given for the types, assume all types are
1246 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1247 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1248 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1249 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1251 /* store our flags and other fields */
1252 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1253 hook->func = callback;
1254 hook->data = user_data;
1255 hook->destroy = destroy_data;
1256 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1259 g_hook_prepend (&pad->probes, hook);
1261 /* incremenent cookie so that the new hook get's called */
1262 pad->priv->probe_list_cookie++;
1264 /* get the id of the hook, we return this and it can be used to remove the
1266 res = hook->hook_id;
1268 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1270 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1271 /* we have a block probe */
1273 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1274 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1275 "now %d blocking probes", pad->num_blocked);
1278 /* call the callback if we need to be called for idle callbacks */
1279 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1280 if (pad->priv->using > 0) {
1281 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1282 * flag above, the last thread to leave the push will do the callback. New
1283 * threads going into the push will block. */
1284 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1285 "pad is in use, delay idle callback");
1286 GST_OBJECT_UNLOCK (pad);
1288 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1289 GstPadProbeReturn ret;
1291 /* the pad is idle now, we can signal the idle callback now */
1292 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1293 "pad is idle, trigger idle callback");
1294 GST_OBJECT_UNLOCK (pad);
1296 ret = callback (pad, &info, user_data);
1298 GST_OBJECT_LOCK (pad);
1300 case GST_PAD_PROBE_REMOVE:
1301 /* remove the probe */
1302 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1303 cleanup_hook (pad, hook);
1306 case GST_PAD_PROBE_DROP:
1307 GST_DEBUG_OBJECT (pad, "asked to drop item");
1309 case GST_PAD_PROBE_PASS:
1310 GST_DEBUG_OBJECT (pad, "asked to pass item");
1312 case GST_PAD_PROBE_OK:
1313 GST_DEBUG_OBJECT (pad, "probe returned OK");
1316 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1319 GST_OBJECT_UNLOCK (pad);
1322 GST_OBJECT_UNLOCK (pad);
1328 * gst_pad_remove_probe:
1329 * @pad: the #GstPad with the probe
1330 * @id: the probe id to remove
1332 * Remove the probe with @id from @pad.
1337 gst_pad_remove_probe (GstPad * pad, gulong id)
1341 g_return_if_fail (GST_IS_PAD (pad));
1343 GST_OBJECT_LOCK (pad);
1345 hook = g_hook_get (&pad->probes, id);
1349 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1351 cleanup_hook (pad, hook);
1352 GST_OBJECT_UNLOCK (pad);
1358 GST_OBJECT_UNLOCK (pad);
1359 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1365 * gst_pad_is_blocked:
1366 * @pad: the #GstPad to query
1368 * Checks if the pad is blocked or not. This function returns the
1369 * last requested state of the pad. It is not certain that the pad
1370 * is actually blocking at this point (see gst_pad_is_blocking()).
1372 * Returns: TRUE if the pad is blocked.
1377 gst_pad_is_blocked (GstPad * pad)
1379 gboolean result = FALSE;
1381 g_return_val_if_fail (GST_IS_PAD (pad), result);
1383 GST_OBJECT_LOCK (pad);
1384 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1385 GST_OBJECT_UNLOCK (pad);
1391 * gst_pad_is_blocking:
1392 * @pad: the #GstPad to query
1394 * Checks if the pad is blocking or not. This is a guaranteed state
1395 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1397 * Returns: TRUE if the pad is blocking.
1402 gst_pad_is_blocking (GstPad * pad)
1404 gboolean result = FALSE;
1406 g_return_val_if_fail (GST_IS_PAD (pad), result);
1408 GST_OBJECT_LOCK (pad);
1409 /* the blocking flag is only valid if the pad is not flushing */
1410 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1411 GST_OBJECT_UNLOCK (pad);
1417 * gst_pad_needs_reconfigure:
1418 * @pad: the #GstPad to check
1420 * Check 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 is set on @pad.
1426 gst_pad_needs_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);
1434 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1435 GST_OBJECT_UNLOCK (pad);
1441 * gst_pad_check_reconfigure:
1442 * @pad: the #GstPad to check
1444 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1445 * if the flag was set.
1447 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1450 gst_pad_check_reconfigure (GstPad * pad)
1452 gboolean reconfigure;
1454 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1456 GST_OBJECT_LOCK (pad);
1457 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1459 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1460 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1462 GST_OBJECT_UNLOCK (pad);
1468 * gst_pad_mark_reconfigure:
1469 * @pad: the #GstPad to mark
1471 * Mark a pad for needing reconfiguration. The next call to
1472 * gst_pad_check_reconfigure() will return %TRUE after this call.
1475 gst_pad_mark_reconfigure (GstPad * pad)
1477 g_return_if_fail (GST_IS_PAD (pad));
1479 GST_OBJECT_LOCK (pad);
1480 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1481 GST_OBJECT_UNLOCK (pad);
1485 * gst_pad_set_activate_function:
1487 * @f: the #GstPadActivateFunction to set.
1489 * Calls gst_pad_set_activate_function_full() with NULL for the user_data and
1493 * gst_pad_set_activate_function_full:
1495 * @activate: the #GstPadActivateFunction to set.
1496 * @user_data: user_data passed to @notify
1497 * @notify: notify called when @activate will not be used anymore.
1499 * Sets the given activate function for @pad. The activate function will
1500 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1501 * Only makes sense to set on sink pads.
1503 * Call this function if your sink pad can start a pull-based task.
1506 gst_pad_set_activate_function_full (GstPad * pad,
1507 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1509 g_return_if_fail (GST_IS_PAD (pad));
1511 if (pad->activatenotify)
1512 pad->activatenotify (pad->activatedata);
1513 GST_PAD_ACTIVATEFUNC (pad) = activate;
1514 pad->activatedata = user_data;
1515 pad->activatenotify = notify;
1517 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1518 GST_DEBUG_FUNCPTR_NAME (activate));
1522 * gst_pad_set_activatemode_function:
1524 * @f: the #GstPadActivateModeFunction to set.
1526 * Calls gst_pad_set_activatemode_function_full() with NULL for the user_data and
1530 * gst_pad_set_activatemode_function_full:
1532 * @activatemode: the #GstPadActivateModeFunction to set.
1533 * @user_data: user_data passed to @notify
1534 * @notify: notify called when @activatemode will not be used anymore.
1536 * Sets the given activate_mode function for the pad. An activate_mode function
1537 * prepares the element for data passing.
1540 gst_pad_set_activatemode_function_full (GstPad * pad,
1541 GstPadActivateModeFunction activatemode, gpointer user_data,
1542 GDestroyNotify notify)
1544 g_return_if_fail (GST_IS_PAD (pad));
1546 if (pad->activatemodenotify)
1547 pad->activatemodenotify (pad->activatemodedata);
1548 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1549 pad->activatemodedata = user_data;
1550 pad->activatemodenotify = notify;
1552 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1553 GST_DEBUG_FUNCPTR_NAME (activatemode));
1557 * gst_pad_set_chain_function:
1558 * @p: a sink #GstPad.
1559 * @f: the #GstPadChainFunction to set.
1561 * Calls gst_pad_set_chain_function_full() with NULL for the user_data and
1565 * gst_pad_set_chain_function_full:
1566 * @pad: a sink #GstPad.
1567 * @chain: the #GstPadChainFunction to set.
1568 * @user_data: user_data passed to @notify
1569 * @notify: notify called when @chain will not be used anymore.
1571 * Sets the given chain function for the pad. The chain function is called to
1572 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1575 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1576 gpointer user_data, GDestroyNotify notify)
1578 g_return_if_fail (GST_IS_PAD (pad));
1579 g_return_if_fail (GST_PAD_IS_SINK (pad));
1581 if (pad->chainnotify)
1582 pad->chainnotify (pad->chaindata);
1583 GST_PAD_CHAINFUNC (pad) = chain;
1584 pad->chaindata = user_data;
1585 pad->chainnotify = notify;
1587 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1588 GST_DEBUG_FUNCPTR_NAME (chain));
1592 * gst_pad_set_chain_list_function:
1593 * @p: a sink #GstPad.
1594 * @f: the #GstPadChainListFunction to set.
1596 * Calls gst_pad_set_chain_list_function_full() with NULL for the user_data and
1600 * gst_pad_set_chain_list_function_full:
1601 * @pad: a sink #GstPad.
1602 * @chainlist: the #GstPadChainListFunction to set.
1603 * @user_data: user_data passed to @notify
1604 * @notify: notify called when @chainlist will not be used anymore.
1606 * Sets the given chain list function for the pad. The chainlist function is
1607 * called to process a #GstBufferList input buffer list. See
1608 * #GstPadChainListFunction for more details.
1611 gst_pad_set_chain_list_function_full (GstPad * pad,
1612 GstPadChainListFunction chainlist, gpointer user_data,
1613 GDestroyNotify notify)
1615 g_return_if_fail (GST_IS_PAD (pad));
1616 g_return_if_fail (GST_PAD_IS_SINK (pad));
1618 if (pad->chainlistnotify)
1619 pad->chainlistnotify (pad->chainlistdata);
1620 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1621 pad->chainlistdata = user_data;
1622 pad->chainlistnotify = notify;
1624 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1625 GST_DEBUG_FUNCPTR_NAME (chainlist));
1629 * gst_pad_set_getrange_function:
1630 * @p: a source #GstPad.
1631 * @f: the #GstPadGetRangeFunction to set.
1633 * Calls gst_pad_set_getrange_function_full() with NULL for the user_data and
1637 * gst_pad_set_getrange_function_full:
1638 * @pad: a source #GstPad.
1639 * @get: the #GstPadGetRangeFunction to set.
1640 * @user_data: user_data passed to @notify
1641 * @notify: notify called when @get will not be used anymore.
1643 * Sets the given getrange function for the pad. The getrange function is
1644 * called to produce a new #GstBuffer to start the processing pipeline. see
1645 * #GstPadGetRangeFunction for a description of the getrange function.
1648 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1649 gpointer user_data, GDestroyNotify notify)
1651 g_return_if_fail (GST_IS_PAD (pad));
1652 g_return_if_fail (GST_PAD_IS_SRC (pad));
1654 if (pad->getrangenotify)
1655 pad->getrangenotify (pad->getrangedata);
1656 GST_PAD_GETRANGEFUNC (pad) = get;
1657 pad->getrangedata = user_data;
1658 pad->getrangenotify = notify;
1660 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1661 GST_DEBUG_FUNCPTR_NAME (get));
1665 * gst_pad_set_event_function:
1666 * @p: a #GstPad of either direction.
1667 * @f: the #GstPadEventFunction to set.
1669 * Calls gst_pad_set_event_function_full() with NULL for the user_data and
1673 * gst_pad_set_event_function_full:
1674 * @pad: a #GstPad of either direction.
1675 * @event: the #GstPadEventFunction to set.
1676 * @user_data: user_data passed to @notify
1677 * @notify: notify called when @event will not be used anymore.
1679 * Sets the given event handler for the pad.
1682 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1683 gpointer user_data, GDestroyNotify notify)
1685 g_return_if_fail (GST_IS_PAD (pad));
1687 if (pad->eventnotify)
1688 pad->eventnotify (pad->eventdata);
1689 GST_PAD_EVENTFUNC (pad) = event;
1690 pad->eventdata = user_data;
1691 pad->eventnotify = notify;
1693 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1694 GST_DEBUG_FUNCPTR_NAME (event));
1698 * gst_pad_set_query_function:
1699 * @p: a #GstPad of either direction.
1700 * @f: the #GstPadQueryFunction to set.
1702 * Calls gst_pad_set_query_function_full() with NULL for the user_data and
1706 * gst_pad_set_query_function_full:
1707 * @pad: a #GstPad of either direction.
1708 * @query: the #GstPadQueryFunction to set.
1709 * @user_data: user_data passed to @notify
1710 * @notify: notify called when @query will not be used anymore.
1712 * Set the given query function for the pad.
1715 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1716 gpointer user_data, GDestroyNotify notify)
1718 g_return_if_fail (GST_IS_PAD (pad));
1720 if (pad->querynotify)
1721 pad->querynotify (pad->querydata);
1722 GST_PAD_QUERYFUNC (pad) = query;
1723 pad->querydata = user_data;
1724 pad->querynotify = notify;
1726 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1727 GST_DEBUG_FUNCPTR_NAME (query));
1731 * gst_pad_set_iterate_internal_links_function:
1732 * @p: a #GstPad of either direction.
1733 * @f: the #GstPadIterIntLinkFunction to set.
1735 * Calls gst_pad_set_iterate_internal_links_function_full() with NULL
1736 * for the user_data and notify.
1739 * gst_pad_set_iterate_internal_links_function_full:
1740 * @pad: a #GstPad of either direction.
1741 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1742 * @user_data: user_data passed to @notify
1743 * @notify: notify called when @iterintlink will not be used anymore.
1745 * Sets the given internal link iterator function for the pad.
1748 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1749 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1750 GDestroyNotify notify)
1752 g_return_if_fail (GST_IS_PAD (pad));
1754 if (pad->iterintlinknotify)
1755 pad->iterintlinknotify (pad->iterintlinkdata);
1756 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1757 pad->iterintlinkdata = user_data;
1758 pad->iterintlinknotify = notify;
1760 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1761 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1765 * gst_pad_set_link_function:
1767 * @f: the #GstPadLinkFunction to set.
1769 * Calls gst_pad_set_link_function_full() with NULL
1770 * for the user_data and notify.
1773 * gst_pad_set_link_function_full:
1775 * @link: the #GstPadLinkFunction to set.
1776 * @user_data: user_data passed to @notify
1777 * @notify: notify called when @link will not be used anymore.
1779 * Sets the given link function for the pad. It will be called when
1780 * the pad is linked with another pad.
1782 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1785 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1786 * cannot be made for some reason.
1788 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1789 * of the peer sink pad, if present.
1792 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1793 gpointer user_data, GDestroyNotify notify)
1795 g_return_if_fail (GST_IS_PAD (pad));
1797 if (pad->linknotify)
1798 pad->linknotify (pad->linkdata);
1799 GST_PAD_LINKFUNC (pad) = link;
1800 pad->linkdata = user_data;
1801 pad->linknotify = notify;
1803 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1804 GST_DEBUG_FUNCPTR_NAME (link));
1808 * gst_pad_set_unlink_function:
1810 * @f: the #GstPadUnlinkFunction to set.
1812 * Calls gst_pad_set_unlink_function_full() with NULL
1813 * for the user_data and notify.
1816 * gst_pad_set_unlink_function_full:
1818 * @unlink: the #GstPadUnlinkFunction to set.
1819 * @user_data: user_data passed to @notify
1820 * @notify: notify called when @unlink will not be used anymore.
1822 * Sets the given unlink function for the pad. It will be called
1823 * when the pad is unlinked.
1826 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1827 gpointer user_data, GDestroyNotify notify)
1829 g_return_if_fail (GST_IS_PAD (pad));
1831 if (pad->unlinknotify)
1832 pad->unlinknotify (pad->unlinkdata);
1833 GST_PAD_UNLINKFUNC (pad) = unlink;
1834 pad->unlinkdata = user_data;
1835 pad->unlinknotify = notify;
1837 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1838 GST_DEBUG_FUNCPTR_NAME (unlink));
1843 * @srcpad: the source #GstPad to unlink.
1844 * @sinkpad: the sink #GstPad to unlink.
1846 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1847 * signal on both pads.
1849 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1850 * the pads were not linked together.
1855 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1857 gboolean result = FALSE;
1858 GstElement *parent = NULL;
1860 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1861 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1862 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1863 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1865 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1866 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1867 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1869 /* We need to notify the parent before taking any pad locks as the bin in
1870 * question might be waiting for a lock on the pad while holding its lock
1871 * that our message will try to take. */
1872 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1873 if (GST_IS_ELEMENT (parent)) {
1874 gst_element_post_message (parent,
1875 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1876 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1878 gst_object_unref (parent);
1883 GST_OBJECT_LOCK (srcpad);
1884 GST_OBJECT_LOCK (sinkpad);
1886 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1887 goto not_linked_together;
1889 if (GST_PAD_UNLINKFUNC (srcpad)) {
1890 GstObject *tmpparent;
1892 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1894 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1895 RELEASE_PARENT (tmpparent);
1898 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1899 GstObject *tmpparent;
1901 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1903 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1904 RELEASE_PARENT (tmpparent);
1908 /* first clear peers */
1909 GST_PAD_PEER (srcpad) = NULL;
1910 GST_PAD_PEER (sinkpad) = NULL;
1912 GST_OBJECT_UNLOCK (sinkpad);
1913 GST_OBJECT_UNLOCK (srcpad);
1915 /* fire off a signal to each of the pads telling them
1916 * that they've been unlinked */
1917 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1918 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1920 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1921 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1926 if (parent != NULL) {
1927 gst_element_post_message (parent,
1928 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1929 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1930 gst_object_unref (parent);
1935 not_linked_together:
1937 /* we do not emit a warning in this case because unlinking cannot
1938 * be made MT safe.*/
1939 GST_OBJECT_UNLOCK (sinkpad);
1940 GST_OBJECT_UNLOCK (srcpad);
1946 * gst_pad_is_linked:
1947 * @pad: pad to check
1949 * Checks if a @pad is linked to another pad or not.
1951 * Returns: TRUE if the pad is linked, FALSE otherwise.
1956 gst_pad_is_linked (GstPad * pad)
1960 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1962 GST_OBJECT_LOCK (pad);
1963 result = (GST_PAD_PEER (pad) != NULL);
1964 GST_OBJECT_UNLOCK (pad);
1969 /* get the caps from both pads and see if the intersection
1972 * This function should be called with the pad LOCK on both
1976 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1977 GstPadLinkCheck flags)
1979 GstCaps *srccaps = NULL;
1980 GstCaps *sinkcaps = NULL;
1981 gboolean compatible = FALSE;
1983 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1986 /* Doing the expensive caps checking takes priority over only checking the template caps */
1987 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1988 GST_OBJECT_UNLOCK (sink);
1989 GST_OBJECT_UNLOCK (src);
1991 srccaps = gst_pad_query_caps (src, NULL);
1992 sinkcaps = gst_pad_query_caps (sink, NULL);
1994 GST_OBJECT_LOCK (src);
1995 GST_OBJECT_LOCK (sink);
1997 /* If one of the two pads doesn't have a template, consider the intersection
1999 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2000 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2004 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2006 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2009 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2011 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2014 /* if we have caps on both pads we can check the intersection. If one
2015 * of the caps is NULL, we return TRUE. */
2016 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2018 gst_caps_unref (srccaps);
2020 gst_caps_unref (sinkcaps);
2024 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2025 gst_caps_unref (srccaps);
2026 gst_caps_unref (sinkcaps);
2029 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2030 (compatible ? "" : "not"));
2035 /* check if the grandparents of both pads are the same.
2036 * This check is required so that we don't try to link
2037 * pads from elements in different bins without ghostpads.
2039 * The LOCK should be held on both pads
2042 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2044 GstObject *psrc, *psink;
2046 psrc = GST_OBJECT_PARENT (src);
2047 psink = GST_OBJECT_PARENT (sink);
2049 /* if one of the pads has no parent, we allow the link */
2050 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2053 /* only care about parents that are elements */
2054 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2055 goto no_element_parent;
2057 /* if the parents are the same, we have a loop */
2058 if (G_UNLIKELY (psrc == psink))
2061 /* if they both have a parent, we check the grandparents. We can not lock
2062 * the parent because we hold on the child (pad) and the locking order is
2063 * parent >> child. */
2064 psrc = GST_OBJECT_PARENT (psrc);
2065 psink = GST_OBJECT_PARENT (psink);
2067 /* if they have grandparents but they are not the same */
2068 if (G_UNLIKELY (psrc != psink))
2069 goto wrong_grandparents;
2076 GST_CAT_DEBUG (GST_CAT_CAPS,
2077 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2078 GST_PTR_FORMAT, psrc, psink);
2083 GST_CAT_DEBUG (GST_CAT_CAPS,
2084 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2085 GST_PTR_FORMAT, psrc, psink);
2090 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2096 GST_CAT_DEBUG (GST_CAT_CAPS,
2097 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2098 GST_PTR_FORMAT, psrc, psink);
2103 /* FIXME leftover from an attempt at refactoring... */
2104 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2105 * the two pads will be locked in the srcpad, sinkpad order. */
2106 static GstPadLinkReturn
2107 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2109 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2110 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2112 GST_OBJECT_LOCK (srcpad);
2114 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2115 goto src_was_linked;
2117 GST_OBJECT_LOCK (sinkpad);
2119 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2120 goto sink_was_linked;
2122 /* check hierarchy, pads can only be linked if the grandparents
2124 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2125 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2126 goto wrong_hierarchy;
2128 /* check pad caps for non-empty intersection */
2129 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2132 /* FIXME check pad scheduling for non-empty intersection */
2134 return GST_PAD_LINK_OK;
2138 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2139 GST_DEBUG_PAD_NAME (srcpad),
2140 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2141 /* we do not emit a warning in this case because unlinking cannot
2142 * be made MT safe.*/
2143 GST_OBJECT_UNLOCK (srcpad);
2144 return GST_PAD_LINK_WAS_LINKED;
2148 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2149 GST_DEBUG_PAD_NAME (sinkpad),
2150 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2151 /* we do not emit a warning in this case because unlinking cannot
2152 * be made MT safe.*/
2153 GST_OBJECT_UNLOCK (sinkpad);
2154 GST_OBJECT_UNLOCK (srcpad);
2155 return GST_PAD_LINK_WAS_LINKED;
2159 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2160 GST_OBJECT_UNLOCK (sinkpad);
2161 GST_OBJECT_UNLOCK (srcpad);
2162 return GST_PAD_LINK_WRONG_HIERARCHY;
2166 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2167 GST_OBJECT_UNLOCK (sinkpad);
2168 GST_OBJECT_UNLOCK (srcpad);
2169 return GST_PAD_LINK_NOFORMAT;
2175 * @srcpad: the source #GstPad.
2176 * @sinkpad: the sink #GstPad.
2178 * Checks if the source pad and the sink pad are compatible so they can be
2181 * Returns: TRUE if the pads can be linked.
2184 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2186 GstPadLinkReturn result;
2188 /* generic checks */
2189 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2190 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2192 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2193 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2195 /* gst_pad_link_prepare does everything for us, we only release the locks
2196 * on the pads that it gets us. If this function returns !OK the locks are not
2198 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2199 if (result != GST_PAD_LINK_OK)
2202 GST_OBJECT_UNLOCK (srcpad);
2203 GST_OBJECT_UNLOCK (sinkpad);
2206 return result == GST_PAD_LINK_OK;
2210 * gst_pad_link_full:
2211 * @srcpad: the source #GstPad to link.
2212 * @sinkpad: the sink #GstPad to link.
2213 * @flags: the checks to validate when linking
2215 * Links the source pad and the sink pad.
2217 * This variant of #gst_pad_link provides a more granular control on the
2218 * checks being done when linking. While providing some considerable speedups
2219 * the caller of this method must be aware that wrong usage of those flags
2220 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2221 * for more information.
2225 * Returns: A result code indicating if the connection worked or
2229 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2231 GstPadLinkReturn result;
2233 GstPadLinkFunction srcfunc, sinkfunc;
2235 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2236 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2237 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2238 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2239 GST_PAD_LINK_WRONG_DIRECTION);
2241 /* Notify the parent early. See gst_pad_unlink for details. */
2242 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2243 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2244 gst_element_post_message (parent,
2245 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2246 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2248 gst_object_unref (parent);
2253 /* prepare will also lock the two pads */
2254 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2256 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2259 /* must set peers before calling the link function */
2260 GST_PAD_PEER (srcpad) = sinkpad;
2261 GST_PAD_PEER (sinkpad) = srcpad;
2263 /* check events, when something is different, mark pending */
2264 schedule_events (srcpad, sinkpad);
2266 /* get the link functions */
2267 srcfunc = GST_PAD_LINKFUNC (srcpad);
2268 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2270 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2271 /* custom link functions, execute them */
2272 GST_OBJECT_UNLOCK (sinkpad);
2273 GST_OBJECT_UNLOCK (srcpad);
2276 GstObject *tmpparent;
2278 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2279 /* this one will call the peer link function */
2280 result = srcfunc (srcpad, tmpparent, sinkpad);
2281 RELEASE_PARENT (tmpparent);
2282 } else if (sinkfunc) {
2283 GstObject *tmpparent;
2285 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2286 /* if no source link function, we need to call the sink link
2287 * function ourselves. */
2288 result = sinkfunc (sinkpad, tmpparent, srcpad);
2289 RELEASE_PARENT (tmpparent);
2293 GST_OBJECT_LOCK (srcpad);
2294 GST_OBJECT_LOCK (sinkpad);
2296 /* we released the lock, check if the same pads are linked still */
2297 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2298 goto concurrent_link;
2300 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2303 GST_OBJECT_UNLOCK (sinkpad);
2304 GST_OBJECT_UNLOCK (srcpad);
2306 /* fire off a signal to each of the pads telling them
2307 * that they've been linked */
2308 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2309 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2311 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2312 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2314 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2317 if (G_LIKELY (parent)) {
2318 gst_element_post_message (parent,
2319 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2320 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2321 gst_object_unref (parent);
2329 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2330 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2331 GST_OBJECT_UNLOCK (sinkpad);
2332 GST_OBJECT_UNLOCK (srcpad);
2334 /* The other link operation succeeded first */
2335 result = GST_PAD_LINK_WAS_LINKED;
2340 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2341 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2343 GST_PAD_PEER (srcpad) = NULL;
2344 GST_PAD_PEER (sinkpad) = NULL;
2346 GST_OBJECT_UNLOCK (sinkpad);
2347 GST_OBJECT_UNLOCK (srcpad);
2355 * @srcpad: the source #GstPad to link.
2356 * @sinkpad: the sink #GstPad to link.
2358 * Links the source pad and the sink pad.
2360 * Returns: A result code indicating if the connection worked or
2366 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2368 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2372 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2374 GstPadTemplate **template_p;
2376 /* this function would need checks if it weren't static */
2378 GST_OBJECT_LOCK (pad);
2379 template_p = &pad->padtemplate;
2380 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2381 GST_OBJECT_UNLOCK (pad);
2384 gst_pad_template_pad_created (templ, pad);
2388 * gst_pad_get_pad_template:
2391 * Gets the template for @pad.
2393 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2394 * instantiated, or %NULL if this pad has no template. Unref after
2398 gst_pad_get_pad_template (GstPad * pad)
2400 GstPadTemplate *templ;
2402 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2404 templ = GST_PAD_PAD_TEMPLATE (pad);
2406 return (templ ? gst_object_ref (templ) : NULL);
2410 * gst_pad_has_current_caps:
2411 * @pad: a #GstPad to check
2413 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2415 * Returns: TRUE when @pad has caps associated with it.
2418 gst_pad_has_current_caps (GstPad * pad)
2423 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2425 GST_OBJECT_LOCK (pad);
2426 caps = get_pad_caps (pad);
2427 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2428 "check current pad caps %" GST_PTR_FORMAT, caps);
2429 result = (caps != NULL);
2430 GST_OBJECT_UNLOCK (pad);
2436 * gst_pad_get_current_caps:
2437 * @pad: a #GstPad to get the current capabilities of.
2439 * Gets the capabilities currently configured on @pad with the last
2440 * #GST_EVENT_CAPS event.
2442 * Returns: the current caps of the pad with incremented ref-count.
2445 gst_pad_get_current_caps (GstPad * pad)
2449 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2451 GST_OBJECT_LOCK (pad);
2452 if ((result = get_pad_caps (pad)))
2453 gst_caps_ref (result);
2454 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2455 "get current pad caps %" GST_PTR_FORMAT, result);
2456 GST_OBJECT_UNLOCK (pad);
2462 * gst_pad_get_pad_template_caps:
2463 * @pad: a #GstPad to get the template capabilities from.
2465 * Gets the capabilities for @pad's template.
2467 * Returns: (transfer full): the #GstCaps of this pad template.
2468 * Unref after usage.
2471 gst_pad_get_pad_template_caps (GstPad * pad)
2473 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2475 if (GST_PAD_PAD_TEMPLATE (pad))
2476 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2478 return gst_caps_ref (GST_CAPS_ANY);
2483 * @pad: a #GstPad to get the peer of.
2485 * Gets the peer of @pad. This function refs the peer pad so
2486 * you need to unref it after use.
2488 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2493 gst_pad_get_peer (GstPad * pad)
2497 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2499 GST_OBJECT_LOCK (pad);
2500 result = GST_PAD_PEER (pad);
2502 gst_object_ref (result);
2503 GST_OBJECT_UNLOCK (pad);
2509 * gst_pad_get_allowed_caps:
2512 * Gets the capabilities of the allowed media types that can flow through
2513 * @pad and its peer.
2515 * The allowed capabilities is calculated as the intersection of the results of
2516 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2517 * on the resulting caps.
2519 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2520 * caps when you no longer need it. This function returns NULL when @pad
2526 gst_pad_get_allowed_caps (GstPad * pad)
2532 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2534 GST_OBJECT_LOCK (pad);
2535 peer = GST_PAD_PEER (pad);
2536 if (G_UNLIKELY (peer == NULL))
2539 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2541 gst_object_ref (peer);
2542 GST_OBJECT_UNLOCK (pad);
2543 mycaps = gst_pad_query_caps (pad, NULL);
2545 caps = gst_pad_query_caps (peer, mycaps);
2546 gst_object_unref (peer);
2548 gst_caps_unref (mycaps);
2550 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2557 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2558 GST_OBJECT_UNLOCK (pad);
2565 * gst_pad_iterate_internal_links_default:
2566 * @pad: the #GstPad to get the internal links of.
2567 * @parent: (allow-none): the parent of @pad or NULL
2569 * Iterate the list of pads to which the given pad is linked to inside of
2570 * the parent element.
2571 * This is the default handler, and thus returns an iterator of all of the
2572 * pads inside the parent element with opposite direction.
2574 * The caller must free this iterator after use with gst_iterator_free().
2576 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2577 * returned pad with gst_object_unref().
2580 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2587 GstElement *eparent;
2589 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2591 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2592 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2594 GST_OBJECT_LOCK (pad);
2595 eparent = GST_PAD_PARENT (pad);
2596 if (!eparent || !GST_IS_ELEMENT (eparent))
2599 gst_object_ref (eparent);
2600 GST_OBJECT_UNLOCK (pad);
2603 if (pad->direction == GST_PAD_SRC)
2604 padlist = &eparent->sinkpads;
2606 padlist = &eparent->srcpads;
2608 GST_DEBUG_OBJECT (pad, "Making iterator");
2610 cookie = &eparent->pads_cookie;
2612 lock = GST_OBJECT_GET_LOCK (eparent);
2614 res = gst_iterator_new_list (GST_TYPE_PAD,
2615 lock, cookie, padlist, (GObject *) owner, NULL);
2617 gst_object_unref (owner);
2624 GST_OBJECT_UNLOCK (pad);
2625 GST_DEBUG_OBJECT (pad, "no parent element");
2631 * gst_pad_iterate_internal_links:
2632 * @pad: the GstPad to get the internal links of.
2634 * Gets an iterator for the pads to which the given pad is linked to inside
2635 * of the parent element.
2637 * Each #GstPad element yielded by the iterator will have its refcount increased,
2638 * so unref after use.
2640 * Free-function: gst_iterator_free
2642 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2643 * pad does not have an iterator function configured. Use
2644 * gst_iterator_free() after usage.
2647 gst_pad_iterate_internal_links (GstPad * pad)
2649 GstIterator *res = NULL;
2652 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2654 GST_OBJECT_LOCK (pad);
2655 ACQUIRE_PARENT (pad, parent, no_parent);
2656 GST_OBJECT_UNLOCK (pad);
2658 if (GST_PAD_ITERINTLINKFUNC (pad))
2659 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2661 RELEASE_PARENT (parent);
2668 GST_DEBUG_OBJECT (pad, "no parent");
2669 GST_OBJECT_UNLOCK (pad);
2677 * @forward: (scope call): a #GstPadForwardFunction
2678 * @user_data: user data passed to @forward
2680 * Calls @forward for all internally linked pads of @pad. This function deals with
2681 * dynamically changing internal pads and will make sure that the @forward
2682 * function is only called once for each pad.
2684 * When @forward returns TRUE, no further pads will be processed.
2686 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2689 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2692 gboolean result = FALSE;
2694 gboolean done = FALSE;
2695 GValue item = { 0, };
2696 GList *pushed_pads = NULL;
2698 iter = gst_pad_iterate_internal_links (pad);
2704 switch (gst_iterator_next (iter, &item)) {
2705 case GST_ITERATOR_OK:
2709 intpad = g_value_get_object (&item);
2711 /* if already pushed, skip. FIXME, find something faster to tag pads */
2712 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2713 g_value_reset (&item);
2717 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2718 GST_DEBUG_PAD_NAME (intpad));
2719 done = result = forward (intpad, user_data);
2721 pushed_pads = g_list_prepend (pushed_pads, intpad);
2723 g_value_reset (&item);
2726 case GST_ITERATOR_RESYNC:
2727 /* We don't reset the result here because we don't push the event
2728 * again on pads that got the event already and because we need
2729 * to consider the result of the previous pushes */
2730 gst_iterator_resync (iter);
2732 case GST_ITERATOR_ERROR:
2733 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2736 case GST_ITERATOR_DONE:
2741 g_value_unset (&item);
2742 gst_iterator_free (iter);
2744 g_list_free (pushed_pads);
2754 gboolean dispatched;
2758 event_forward_func (GstPad * pad, EventData * data)
2760 /* for each pad we send to, we should ref the event; it's up
2761 * to downstream to unref again when handled. */
2762 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2763 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2765 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2767 data->dispatched = TRUE;
2774 * gst_pad_event_default:
2775 * @pad: a #GstPad to call the default event handler on.
2776 * @parent: (allow-none): the parent of @pad or NULL
2777 * @event: (transfer full): the #GstEvent to handle.
2779 * Invokes the default event handler for the given pad.
2781 * The EOS event will pause the task associated with @pad before it is forwarded
2782 * to all internally linked pads,
2784 * The the event is sent to all pads internally linked to @pad. This function
2785 * takes ownership of @event.
2787 * Returns: TRUE if the event was sent successfully.
2790 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2792 gboolean result, forward = TRUE;
2794 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2795 g_return_val_if_fail (event != NULL, FALSE);
2797 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2800 switch (GST_EVENT_TYPE (event)) {
2801 case GST_EVENT_CAPS:
2802 forward = GST_PAD_IS_PROXY_CAPS (pad);
2813 data.dispatched = FALSE;
2814 data.result = FALSE;
2816 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2818 /* for sinkpads without a parent element or without internal links, nothing
2819 * will be dispatched but we still want to return TRUE. */
2820 if (data.dispatched)
2821 result = data.result;
2826 gst_event_unref (event);
2831 /* Default accept caps implementation just checks against
2832 * the allowed caps for the pad */
2834 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2836 /* get the caps and see if it intersects to something not empty */
2837 GstCaps *caps, *allowed;
2840 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2842 /* first forward the query to internally linked pads when we are dealing with
2844 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2845 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2850 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2851 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2853 gst_query_parse_accept_caps (query, &caps);
2854 allowed = gst_pad_query_caps (pad, caps);
2857 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
2858 GST_DEBUG_OBJECT (pad,
2859 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
2861 result = gst_caps_can_intersect (caps, allowed);
2863 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
2864 GST_PTR_FORMAT, allowed, caps);
2865 result = gst_caps_is_subset (caps, allowed);
2867 gst_caps_unref (allowed);
2869 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
2872 gst_query_set_accept_caps_result (query, result);
2878 /* Default caps implementation */
2880 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2882 GstCaps *result = NULL, *filter;
2883 GstPadTemplate *templ;
2884 gboolean fixed_caps;
2886 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2889 /* first try to proxy if we must */
2890 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2891 if ((gst_pad_proxy_query_caps (pad, query))) {
2896 gst_query_parse_caps (query, &filter);
2898 /* no proxy or it failed, do default handling */
2899 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2901 GST_OBJECT_LOCK (pad);
2903 /* fixed caps, try the negotiated caps first */
2904 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2905 if ((result = get_pad_caps (pad)))
2906 goto filter_done_unlock;
2909 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2910 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2911 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2912 goto filter_done_unlock;
2916 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2917 "non-fixed pad caps: trying pad caps");
2918 /* non fixed caps, try the negotiated caps */
2919 if ((result = get_pad_caps (pad)))
2920 goto filter_done_unlock;
2923 /* this almost never happens */
2924 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2925 result = GST_CAPS_ANY;
2928 GST_OBJECT_UNLOCK (pad);
2930 /* run the filter on the result */
2932 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2933 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2934 GST_PTR_FORMAT, result, result, filter, filter);
2935 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2936 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2939 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2940 "using caps %p %" GST_PTR_FORMAT, result, result);
2941 result = gst_caps_ref (result);
2943 gst_query_set_caps_result (query, result);
2944 gst_caps_unref (result);
2954 gboolean dispatched;
2958 query_forward_func (GstPad * pad, QueryData * data)
2960 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
2961 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
2963 data->result |= gst_pad_peer_query (pad, data->query);
2965 data->dispatched = TRUE;
2967 /* stop on first successful reply */
2968 return data->result;
2972 * gst_pad_query_default:
2973 * @pad: a #GstPad to call the default query handler on.
2974 * @parent: (allow-none): the parent of @pad or NULL
2975 * @query: (transfer none): the #GstQuery to handle.
2977 * Invokes the default query handler for the given pad.
2978 * The query is sent to all pads internally linked to @pad. Note that
2979 * if there are many possible sink pads that are internally linked to
2980 * @pad, only one will be sent the query.
2981 * Multi-sinkpad elements should implement custom query handlers.
2983 * Returns: TRUE if the query was performed successfully.
2986 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
2988 gboolean forward, ret = FALSE;
2990 switch (GST_QUERY_TYPE (query)) {
2991 case GST_QUERY_SCHEDULING:
2992 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
2994 case GST_QUERY_ALLOCATION:
2995 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
2997 case GST_QUERY_ACCEPT_CAPS:
2998 ret = gst_pad_query_accept_caps_default (pad, query);
3001 case GST_QUERY_CAPS:
3002 ret = gst_pad_query_caps_default (pad, query);
3005 case GST_QUERY_POSITION:
3006 case GST_QUERY_SEEKING:
3007 case GST_QUERY_FORMATS:
3008 case GST_QUERY_LATENCY:
3009 case GST_QUERY_JITTER:
3010 case GST_QUERY_RATE:
3011 case GST_QUERY_CONVERT:
3017 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3018 query, GST_QUERY_TYPE_NAME (query));
3024 data.dispatched = FALSE;
3025 data.result = FALSE;
3027 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3029 if (data.dispatched) {
3032 /* nothing dispatched, assume drained */
3033 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3043 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3045 GstPad *pad = data->pad;
3046 GstPadProbeInfo *info = data->info;
3047 GstPadProbeType type, flags;
3048 GstPadProbeCallback callback;
3049 GstPadProbeReturn ret;
3051 /* if we have called this callback, do nothing */
3052 if (PROBE_COOKIE (hook) == data->cookie) {
3053 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3054 "hook %lu, cookie %u already called", hook->hook_id,
3055 PROBE_COOKIE (hook));
3059 PROBE_COOKIE (hook) = data->cookie;
3061 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3064 /* one of the data types for non-idle probes */
3065 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3066 && (flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3068 /* one of the scheduling types */
3069 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3071 /* one of the blocking types must match */
3072 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3073 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3075 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3076 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3078 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3079 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3080 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3083 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3084 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3085 PROBE_COOKIE (hook), flags);
3087 data->marshalled = TRUE;
3089 callback = (GstPadProbeCallback) hook->func;
3090 if (callback == NULL)
3093 info->id = hook->hook_id;
3095 GST_OBJECT_UNLOCK (pad);
3097 ret = callback (pad, info, hook->data);
3099 GST_OBJECT_LOCK (pad);
3102 case GST_PAD_PROBE_REMOVE:
3103 /* remove the probe */
3104 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3105 cleanup_hook (pad, hook);
3107 case GST_PAD_PROBE_DROP:
3108 /* need to drop the data, make sure other probes don't get called
3110 GST_DEBUG_OBJECT (pad, "asked to drop item");
3111 info->type = GST_PAD_PROBE_TYPE_INVALID;
3112 data->dropped = TRUE;
3114 case GST_PAD_PROBE_PASS:
3115 /* inform the pad block to let things pass */
3116 GST_DEBUG_OBJECT (pad, "asked to pass item");
3119 case GST_PAD_PROBE_OK:
3120 GST_DEBUG_OBJECT (pad, "probe returned OK");
3123 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3130 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3131 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3132 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3137 /* a probe that does not take or return any data */
3138 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3140 if (G_UNLIKELY (pad->num_probes)) { \
3141 /* pass NULL as the data item */ \
3142 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3143 ret = do_probe_callbacks (pad, &info, defaultval); \
3144 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3149 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3151 if (G_UNLIKELY (pad->num_probes)) { \
3152 /* pass the data item */ \
3153 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3154 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3155 /* store the possibly updated data item */ \
3156 data = GST_PAD_PROBE_INFO_DATA (&info); \
3157 /* if something went wrong, exit */ \
3158 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3163 #define PROBE_PUSH(pad,mask,data,label) \
3164 PROBE_FULL(pad, mask, data, -1, -1, label);
3165 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3166 PROBE_FULL(pad, mask, data, offs, size, label);
3168 static GstFlowReturn
3169 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3170 GstFlowReturn defaultval)
3179 data.marshalled = FALSE;
3180 data.dropped = FALSE;
3181 data.cookie = ++pad->priv->probe_cookie;
3184 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3187 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3188 "do probes cookie %u", data.cookie);
3189 cookie = pad->priv->probe_list_cookie;
3191 g_hook_list_marshal (&pad->probes, TRUE,
3192 (GHookMarshaller) probe_hook_marshal, &data);
3194 /* if the list changed, call the new callbacks (they will not have their
3195 * cookie set to data.cookie */
3196 if (cookie != pad->priv->probe_list_cookie) {
3197 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3198 "probe list changed, restarting");
3202 /* the first item that dropped will stop the hooks and then we drop here */
3206 /* if no handler matched and we are blocking, let the item pass */
3207 if (!data.marshalled && is_block)
3210 /* At this point, all handlers returned either OK or PASS. If one handler
3211 * returned PASS, let the item pass */
3216 while (GST_PAD_IS_BLOCKED (pad)) {
3217 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3218 "we are blocked %d times", pad->num_blocked);
3220 /* we might have released the lock */
3221 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3224 /* now we block the streaming thread. It can be unlocked when we
3225 * deactivate the pad (which will also set the FLUSHING flag) or
3226 * when the pad is unblocked. A flushing event will also unblock
3227 * the pad after setting the FLUSHING flag. */
3228 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3229 "Waiting to be unblocked or set flushing");
3230 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3231 GST_PAD_BLOCK_WAIT (pad);
3232 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3233 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3235 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3245 GST_DEBUG_OBJECT (pad, "pad is flushing");
3246 return GST_FLOW_FLUSHING;
3250 GST_DEBUG_OBJECT (pad, "data is dropped");
3251 return GST_FLOW_CUSTOM_SUCCESS;
3255 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3256 GST_DEBUG_OBJECT (pad, "data is passed");
3264 * gst_pad_get_offset:
3267 * Get the offset applied to the running time of @pad. @pad has to be a source
3270 * Returns: the offset.
3273 gst_pad_get_offset (GstPad * pad)
3277 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3279 GST_OBJECT_LOCK (pad);
3280 result = pad->offset;
3281 GST_OBJECT_UNLOCK (pad);
3287 * gst_pad_set_offset:
3289 * @offset: the offset
3291 * Set the offset that will be applied to the running time of @pad.
3294 gst_pad_set_offset (GstPad * pad, gint64 offset)
3298 g_return_if_fail (GST_IS_PAD (pad));
3300 GST_OBJECT_LOCK (pad);
3301 /* if nothing changed, do nothing */
3302 if (pad->offset == offset)
3305 pad->offset = offset;
3306 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3308 /* sinkpads will apply their offset the next time a segment
3309 * event is received. */
3310 if (GST_PAD_IS_SINK (pad))
3313 /* resend the last segment event on next buffer push */
3314 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3315 ev->received = FALSE;
3316 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3320 GST_OBJECT_UNLOCK (pad);
3327 /* If TRUE and ret is not OK this means
3328 * that pushing the EOS event failed
3332 /* If called for an event this is
3333 * the event that would be pushed
3334 * next. Don't forward sticky events
3335 * that would come after that */
3339 /* should be called with pad LOCK */
3341 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3343 PushStickyData *data = user_data;
3344 GstEvent *event = ev->event;
3347 GST_DEBUG_OBJECT (pad, "event %s was already received",
3348 GST_EVENT_TYPE_NAME (event));
3352 /* If we're called because of an sticky event, only forward
3353 * events that would come before this new event and the
3355 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3356 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3357 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3358 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3360 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3361 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3364 switch (data->ret) {
3366 ev->received = TRUE;
3367 GST_DEBUG_OBJECT (pad, "event %s marked received",
3368 GST_EVENT_TYPE_NAME (event));
3370 case GST_FLOW_CUSTOM_SUCCESS:
3371 /* we can't assume the event is received when it was dropped */
3372 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3373 GST_EVENT_TYPE_NAME (event));
3374 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3375 data->ret = GST_FLOW_OK;
3377 case GST_FLOW_CUSTOM_SUCCESS_1:
3378 /* event was ignored and should be sent later */
3379 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3380 GST_EVENT_TYPE_NAME (event));
3381 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3382 data->ret = GST_FLOW_OK;
3384 case GST_FLOW_NOT_LINKED:
3385 /* not linked is not a problem, we are sticky so the event will be
3386 * sent later but only for non-EOS events */
3387 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3388 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3389 data->ret = GST_FLOW_OK;
3390 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3393 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3394 gst_flow_get_name (data->ret));
3395 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3399 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3400 data->was_eos = TRUE;
3402 return data->ret == GST_FLOW_OK;
3405 /* check sticky events and push them when needed. should be called
3407 static inline GstFlowReturn
3408 check_sticky (GstPad * pad, GstEvent * event)
3410 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3412 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3413 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3415 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3416 events_foreach (pad, push_sticky, &data);
3418 /* If there's an EOS event we must push it downstream
3419 * even if sending a previous sticky event failed.
3420 * Otherwise the pipeline might wait forever for EOS.
3422 * Only do this if pushing another event than the EOS
3425 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3426 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3428 if (ev && !ev->received) {
3429 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3430 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3431 /* the event could have been dropped. Because this can only
3432 * happen if the user asked for it, it's not an error */
3433 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3434 data.ret = GST_FLOW_OK;
3444 * @pad: a #GstPad to invoke the default query on.
3445 * @query: (transfer none): the #GstQuery to perform.
3447 * Dispatches a query to a pad. The query should have been allocated by the
3448 * caller via one of the type-specific allocation functions. The element that
3449 * the pad belongs to is responsible for filling the query with an appropriate
3450 * response, which should then be parsed with a type-specific query parsing
3453 * Again, the caller is responsible for both the allocation and deallocation of
3454 * the query structure.
3456 * Please also note that some queries might need a running pipeline to work.
3458 * Returns: TRUE if the query could be performed.
3461 gst_pad_query (GstPad * pad, GstQuery * query)
3464 gboolean res, serialized;
3465 GstPadQueryFunction func;
3466 GstPadProbeType type;
3469 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3470 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3472 if (GST_PAD_IS_SRC (pad)) {
3473 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3474 goto wrong_direction;
3475 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3476 } else if (GST_PAD_IS_SINK (pad)) {
3477 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3478 goto wrong_direction;
3479 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3481 goto unknown_direction;
3483 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3484 GST_QUERY_TYPE_NAME (query));
3486 serialized = GST_QUERY_IS_SERIALIZED (query);
3487 if (G_UNLIKELY (serialized))
3488 GST_PAD_STREAM_LOCK (pad);
3490 GST_OBJECT_LOCK (pad);
3491 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3492 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3493 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3495 ACQUIRE_PARENT (pad, parent, no_parent);
3496 GST_OBJECT_UNLOCK (pad);
3498 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3501 res = func (pad, parent, query);
3503 RELEASE_PARENT (parent);
3505 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3506 GST_QUERY_TYPE_NAME (query), res);
3511 GST_OBJECT_LOCK (pad);
3512 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3513 GST_OBJECT_UNLOCK (pad);
3515 if (G_UNLIKELY (serialized))
3516 GST_PAD_STREAM_UNLOCK (pad);
3523 g_warning ("pad %s:%s query %s in wrong direction",
3524 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3529 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3534 GST_DEBUG_OBJECT (pad, "had no parent");
3535 GST_OBJECT_UNLOCK (pad);
3536 if (G_UNLIKELY (serialized))
3537 GST_PAD_STREAM_UNLOCK (pad);
3542 GST_DEBUG_OBJECT (pad, "had no query function");
3543 RELEASE_PARENT (parent);
3544 if (G_UNLIKELY (serialized))
3545 GST_PAD_STREAM_UNLOCK (pad);
3550 GST_DEBUG_OBJECT (pad, "query failed");
3551 if (G_UNLIKELY (serialized))
3552 GST_PAD_STREAM_UNLOCK (pad);
3557 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3558 GST_OBJECT_UNLOCK (pad);
3559 if (G_UNLIKELY (serialized))
3560 GST_PAD_STREAM_UNLOCK (pad);
3562 /* if a probe dropped, we don't sent it further but assume that the probe
3563 * answered the query and return TRUE */
3564 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3574 * gst_pad_peer_query:
3575 * @pad: a #GstPad to invoke the peer query on.
3576 * @query: (transfer none): the #GstQuery to perform.
3578 * Performs gst_pad_query() on the peer of @pad.
3580 * The caller is responsible for both the allocation and deallocation of
3581 * the query structure.
3583 * Returns: TRUE if the query could be performed. This function returns %FALSE
3584 * if @pad has no peer.
3587 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3590 GstPadProbeType type;
3591 gboolean res, serialized;
3594 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3595 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3597 if (GST_PAD_IS_SRC (pad)) {
3598 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3599 goto wrong_direction;
3600 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3601 } else if (GST_PAD_IS_SINK (pad)) {
3602 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3603 goto wrong_direction;
3604 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3606 goto unknown_direction;
3608 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3609 GST_QUERY_TYPE_NAME (query));
3611 serialized = GST_QUERY_IS_SERIALIZED (query);
3613 GST_OBJECT_LOCK (pad);
3614 if (GST_PAD_IS_SRC (pad) && serialized) {
3615 /* all serialized queries on the srcpad trigger push of
3617 if (!check_sticky (pad, NULL) == GST_FLOW_OK)
3621 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3622 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3623 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3625 peerpad = GST_PAD_PEER (pad);
3626 if (G_UNLIKELY (peerpad == NULL))
3629 gst_object_ref (peerpad);
3630 GST_OBJECT_UNLOCK (pad);
3632 res = gst_pad_query (peerpad, query);
3634 gst_object_unref (peerpad);
3639 GST_OBJECT_LOCK (pad);
3640 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3641 GST_OBJECT_UNLOCK (pad);
3648 g_warning ("pad %s:%s query %s in wrong direction",
3649 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3654 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3659 GST_WARNING_OBJECT (pad, "could not send sticky events");
3660 GST_OBJECT_UNLOCK (pad);
3665 GST_INFO_OBJECT (pad, "pad has no peer");
3666 GST_OBJECT_UNLOCK (pad);
3671 GST_DEBUG_OBJECT (pad, "query failed");
3676 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3677 GST_OBJECT_UNLOCK (pad);
3679 /* if a probe dropped, we don't sent it further but assume that the probe
3680 * answered the query and return TRUE */
3681 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3690 /**********************************************************************
3691 * Data passing functions
3694 /* this is the chain function that does not perform the additional argument
3695 * checking for that little extra speed.
3697 static inline GstFlowReturn
3698 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3703 GST_PAD_STREAM_LOCK (pad);
3705 GST_OBJECT_LOCK (pad);
3706 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3709 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3712 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3715 #ifndef G_DISABLE_ASSERT
3716 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3717 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3719 ":%s:<%s:%s> Got data flow before stream-start event",
3720 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3722 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3724 ":%s:<%s:%s> Got data flow before segment event",
3725 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3727 pad->priv->last_cookie = pad->priv->events_cookie;
3731 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3733 PROBE_PUSH (pad, type, data, probe_stopped);
3735 parent = GST_OBJECT_PARENT (pad);
3736 GST_OBJECT_UNLOCK (pad);
3738 /* NOTE: we read the chainfunc unlocked.
3739 * we cannot hold the lock for the pad so we might send
3740 * the data to the wrong function. This is not really a
3741 * problem since functions are assigned at creation time
3742 * and don't change that often... */
3743 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3744 GstPadChainFunction chainfunc;
3746 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3749 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3750 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3751 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3753 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3755 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3756 "called chainfunction &%s with buffer %p, returned %s",
3757 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3759 GstPadChainListFunction chainlistfunc;
3761 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3764 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3765 "calling chainlistfunction &%s",
3766 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3768 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3770 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3771 "called chainlistfunction &%s, returned %s",
3772 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3775 GST_PAD_STREAM_UNLOCK (pad);
3782 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3783 "chaining, but pad was flushing");
3784 GST_OBJECT_UNLOCK (pad);
3785 GST_PAD_STREAM_UNLOCK (pad);
3786 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3787 return GST_FLOW_FLUSHING;
3791 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3792 GST_OBJECT_UNLOCK (pad);
3793 GST_PAD_STREAM_UNLOCK (pad);
3794 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3795 return GST_FLOW_EOS;
3799 g_critical ("chain on pad %s:%s but it was not in push mode",
3800 GST_DEBUG_PAD_NAME (pad));
3801 GST_OBJECT_UNLOCK (pad);
3802 GST_PAD_STREAM_UNLOCK (pad);
3803 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3804 return GST_FLOW_ERROR;
3808 GST_OBJECT_UNLOCK (pad);
3809 GST_PAD_STREAM_UNLOCK (pad);
3810 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3813 case GST_FLOW_CUSTOM_SUCCESS:
3814 GST_DEBUG_OBJECT (pad, "dropped buffer");
3818 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
3825 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3826 g_critical ("chain on pad %s:%s but it has no chainfunction",
3827 GST_DEBUG_PAD_NAME (pad));
3828 GST_PAD_STREAM_UNLOCK (pad);
3829 return GST_FLOW_NOT_SUPPORTED;
3835 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3836 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3839 * Chain a buffer to @pad.
3841 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3843 * If the buffer type is not acceptable for @pad (as negotiated with a
3844 * preceding GST_EVENT_CAPS event), this function returns
3845 * #GST_FLOW_NOT_NEGOTIATED.
3847 * The function proceeds calling the chain function installed on @pad (see
3848 * gst_pad_set_chain_function()) and the return value of that function is
3849 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3852 * In all cases, success or failure, the caller loses its reference to @buffer
3853 * after calling this function.
3855 * Returns: a #GstFlowReturn from the pad.
3860 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3862 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3863 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3864 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3866 return gst_pad_chain_data_unchecked (pad,
3867 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3870 static GstFlowReturn
3871 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3872 GstBufferList * list)
3878 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3880 len = gst_buffer_list_length (list);
3883 for (i = 0; i < len; i++) {
3884 buffer = gst_buffer_list_get (list, i);
3886 gst_pad_chain_data_unchecked (pad,
3887 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3888 gst_buffer_ref (buffer));
3889 if (ret != GST_FLOW_OK)
3892 gst_buffer_list_unref (list);
3898 * gst_pad_chain_list:
3899 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3900 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3903 * Chain a bufferlist to @pad.
3905 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3907 * If @pad was not negotiated properly with a CAPS event, this function
3908 * returns #GST_FLOW_NOT_NEGOTIATED.
3910 * The function proceeds calling the chainlist function installed on @pad (see
3911 * gst_pad_set_chain_list_function()) and the return value of that function is
3912 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3913 * chainlist function.
3915 * In all cases, success or failure, the caller loses its reference to @list
3916 * after calling this function.
3920 * Returns: a #GstFlowReturn from the pad.
3923 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3925 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3926 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3927 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3929 return gst_pad_chain_data_unchecked (pad,
3930 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3933 static GstFlowReturn
3934 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3939 GST_OBJECT_LOCK (pad);
3940 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3943 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3946 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3949 #ifndef G_DISABLE_ASSERT
3950 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3951 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3953 ":%s:<%s:%s> Got data flow before stream-start event",
3954 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3956 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3958 ":%s:<%s:%s> Got data flow before segment event",
3959 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3961 pad->priv->last_cookie = pad->priv->events_cookie;
3965 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3968 /* do block probes */
3969 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3971 /* recheck sticky events because the probe might have cause a relink */
3972 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3975 /* do post-blocking probes */
3976 PROBE_PUSH (pad, type, data, probe_stopped);
3978 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3981 /* take ref to peer pad before releasing the lock */
3982 gst_object_ref (peer);
3984 GST_OBJECT_UNLOCK (pad);
3986 ret = gst_pad_chain_data_unchecked (peer, type, data);
3988 gst_object_unref (peer);
3990 GST_OBJECT_LOCK (pad);
3992 if (pad->priv->using == 0) {
3993 /* pad is not active anymore, trigger idle callbacks */
3994 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3995 probe_stopped, ret);
3997 GST_OBJECT_UNLOCK (pad);
4001 /* ERROR recovery here */
4005 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4006 "pushing, but pad was flushing");
4007 GST_OBJECT_UNLOCK (pad);
4008 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4009 return GST_FLOW_FLUSHING;
4013 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4014 GST_OBJECT_UNLOCK (pad);
4015 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4016 return GST_FLOW_EOS;
4020 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4021 GST_DEBUG_PAD_NAME (pad));
4022 GST_OBJECT_UNLOCK (pad);
4023 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4024 return GST_FLOW_ERROR;
4028 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4029 "error pushing events, return %s", gst_flow_get_name (ret));
4030 GST_OBJECT_UNLOCK (pad);
4031 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4036 GST_OBJECT_UNLOCK (pad);
4037 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4040 case GST_FLOW_CUSTOM_SUCCESS:
4041 GST_DEBUG_OBJECT (pad, "dropped buffer");
4045 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4052 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4053 "pushing, but it was not linked");
4054 GST_OBJECT_UNLOCK (pad);
4055 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4056 return GST_FLOW_NOT_LINKED;
4062 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4063 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4066 * Pushes a buffer to the peer of @pad.
4068 * This function will call installed block probes before triggering any
4069 * installed data probes.
4071 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4072 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4075 * In all cases, success or failure, the caller loses its reference to @buffer
4076 * after calling this function.
4078 * Returns: a #GstFlowReturn from the peer pad.
4083 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4085 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4086 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4087 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4089 return gst_pad_push_data (pad,
4090 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4094 * gst_pad_push_list:
4095 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4096 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4099 * Pushes a buffer list to the peer of @pad.
4101 * This function will call installed block probes before triggering any
4102 * installed data probes.
4104 * The function proceeds calling the chain function on the peer pad and returns
4105 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4106 * be returned. If the peer pad does not have any installed chainlist function
4107 * every group buffer of the list will be merged into a normal #GstBuffer and
4108 * chained via gst_pad_chain().
4110 * In all cases, success or failure, the caller loses its reference to @list
4111 * after calling this function.
4113 * Returns: a #GstFlowReturn from the peer pad.
4118 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4120 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4121 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4122 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4124 return gst_pad_push_data (pad,
4125 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4128 static GstFlowReturn
4129 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4130 GstBuffer ** buffer)
4133 GstPadGetRangeFunction getrangefunc;
4137 GST_PAD_STREAM_LOCK (pad);
4139 GST_OBJECT_LOCK (pad);
4140 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4143 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4146 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4151 /* when one of the probes returns DROPPED, probe_stopped will be called
4152 * and we skip calling the getrange function, res_buf should then contain a
4153 * valid result buffer */
4154 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4155 res_buf, offset, size, probe_stopped);
4157 /* recheck sticky events because the probe might have cause a relink */
4158 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4161 ACQUIRE_PARENT (pad, parent, no_parent);
4162 GST_OBJECT_UNLOCK (pad);
4164 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4167 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4168 "calling getrangefunc %s, offset %"
4169 G_GUINT64_FORMAT ", size %u",
4170 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4172 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4174 RELEASE_PARENT (parent);
4176 if (G_UNLIKELY (ret != GST_FLOW_OK))
4177 goto get_range_failed;
4179 /* can only fire the signal if we have a valid buffer */
4180 GST_OBJECT_LOCK (pad);
4182 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4183 res_buf, offset, size, probe_stopped_unref);
4184 GST_OBJECT_UNLOCK (pad);
4186 GST_PAD_STREAM_UNLOCK (pad);
4195 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4196 "getrange, but pad was flushing");
4197 GST_OBJECT_UNLOCK (pad);
4198 GST_PAD_STREAM_UNLOCK (pad);
4199 return GST_FLOW_FLUSHING;
4203 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4204 GST_DEBUG_PAD_NAME (pad));
4205 GST_OBJECT_UNLOCK (pad);
4206 GST_PAD_STREAM_UNLOCK (pad);
4207 return GST_FLOW_ERROR;
4211 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4212 GST_OBJECT_UNLOCK (pad);
4213 GST_PAD_STREAM_UNLOCK (pad);
4218 GST_DEBUG_OBJECT (pad, "no parent");
4219 GST_OBJECT_UNLOCK (pad);
4220 GST_PAD_STREAM_UNLOCK (pad);
4221 return GST_FLOW_FLUSHING;
4225 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4226 GST_DEBUG_PAD_NAME (pad));
4227 RELEASE_PARENT (parent);
4228 GST_PAD_STREAM_UNLOCK (pad);
4229 return GST_FLOW_NOT_SUPPORTED;
4233 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4234 "probe returned %s", gst_flow_get_name (ret));
4235 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4237 /* the probe filled the buffer and asks us to not call the getrange
4238 * anymore, we continue with the post probes then. */
4239 GST_DEBUG_OBJECT (pad, "handled buffer");
4243 /* no buffer, we are EOS */
4244 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4248 GST_OBJECT_UNLOCK (pad);
4249 GST_PAD_STREAM_UNLOCK (pad);
4253 probe_stopped_unref:
4255 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4256 "probe returned %s", gst_flow_get_name (ret));
4257 /* if we drop here, it signals EOS */
4258 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4260 GST_OBJECT_UNLOCK (pad);
4261 GST_PAD_STREAM_UNLOCK (pad);
4262 if (*buffer == NULL)
4263 gst_buffer_unref (res_buf);
4268 GST_PAD_STREAM_UNLOCK (pad);
4269 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4270 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4271 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4277 * gst_pad_get_range:
4278 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4279 * @offset: The start offset of the buffer
4280 * @size: The length of the buffer
4281 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4282 * returns #GST_FLOW_ERROR if %NULL.
4284 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4285 * immediately and @buffer is %NULL.
4287 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4288 * description of a getrange function. If @pad has no getrange function
4289 * installed (see gst_pad_set_getrange_function()) this function returns
4290 * #GST_FLOW_NOT_SUPPORTED.
4292 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4293 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4294 * must be freed with gst_buffer_unref() after usage.
4296 * When @buffer points to a variable that points to a valid #GstBuffer, the
4297 * buffer will be filled with the result data when this function returns
4298 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4299 * @size bytes will be filled in the result buffer and its size will be updated
4302 * Note that less than @size bytes can be returned in @buffer when, for example,
4303 * an EOS condition is near or when @buffer is not large enough to hold @size
4304 * bytes. The caller should check the result buffer size to get the result size.
4306 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4307 * will be unchanged.
4309 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4311 * Returns: a #GstFlowReturn from the pad.
4316 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4317 GstBuffer ** buffer)
4319 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4320 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4321 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4322 g_return_val_if_fail (*buffer == NULL
4323 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4325 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4329 * gst_pad_pull_range:
4330 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4331 * @offset: The start offset of the buffer
4332 * @size: The length of the buffer
4333 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4334 * GST_FLOW_ERROR if %NULL.
4336 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4338 * This function will first trigger the pad block signal if it was
4341 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4342 * function returns the result of gst_pad_get_range() on the peer pad.
4343 * See gst_pad_get_range() for a list of return values and for the
4344 * semantics of the arguments of this function.
4346 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4347 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4348 * must be freed with gst_buffer_unref() after usage. When this function
4349 * returns any other result value, @buffer will still point to NULL.
4351 * When @buffer points to a variable that points to a valid #GstBuffer, the
4352 * buffer will be filled with the result data when this function returns
4353 * #GST_FLOW_OK. When this function returns any other result value,
4354 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4355 * @size bytes will be filled in the result buffer and its size will be updated
4358 * Note that less than @size bytes can be returned in @buffer when, for example,
4359 * an EOS condition is near or when @buffer is not large enough to hold @size
4360 * bytes. The caller should check the result buffer size to get the result size.
4362 * Returns: a #GstFlowReturn from the peer pad.
4367 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4368 GstBuffer ** buffer)
4374 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4375 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4376 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4377 g_return_val_if_fail (*buffer == NULL
4378 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4380 GST_OBJECT_LOCK (pad);
4381 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4384 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4389 /* when one of the probes returns DROPPED, probe_stopped will be
4390 * called and we skip calling the peer getrange function. *buffer should then
4391 * contain a valid buffer */
4392 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4393 res_buf, offset, size, probe_stopped);
4395 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4398 gst_object_ref (peer);
4400 GST_OBJECT_UNLOCK (pad);
4402 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4404 gst_object_unref (peer);
4406 GST_OBJECT_LOCK (pad);
4408 if (pad->priv->using == 0) {
4409 /* pad is not active anymore, trigger idle callbacks */
4410 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4411 probe_stopped_unref, ret);
4414 if (G_UNLIKELY (ret != GST_FLOW_OK))
4415 goto pull_range_failed;
4418 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4419 res_buf, offset, size, probe_stopped_unref);
4421 GST_OBJECT_UNLOCK (pad);
4427 /* ERROR recovery here */
4430 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4431 "pullrange, but pad was flushing");
4432 GST_OBJECT_UNLOCK (pad);
4433 return GST_FLOW_FLUSHING;
4437 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4438 GST_DEBUG_PAD_NAME (pad));
4439 GST_OBJECT_UNLOCK (pad);
4440 return GST_FLOW_ERROR;
4444 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4445 gst_flow_get_name (ret));
4446 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4448 /* the probe filled the buffer and asks us to not forward to the peer
4449 * anymore, we continue with the post probes then */
4450 GST_DEBUG_OBJECT (pad, "handled buffer");
4454 /* no buffer, we are EOS then */
4455 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4459 GST_OBJECT_UNLOCK (pad);
4464 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4465 "pulling range, but it was not linked");
4466 GST_OBJECT_UNLOCK (pad);
4467 return GST_FLOW_NOT_LINKED;
4471 GST_OBJECT_UNLOCK (pad);
4472 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4473 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4474 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4477 probe_stopped_unref:
4479 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4480 "post probe returned %s", gst_flow_get_name (ret));
4481 GST_OBJECT_UNLOCK (pad);
4482 /* if we drop here, it signals EOS */
4483 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4485 if (*buffer == NULL)
4486 gst_buffer_unref (res_buf);
4491 /* must be called with pad object lock */
4492 static GstFlowReturn
4493 store_sticky_event (GstPad * pad, GstEvent * event)
4498 gboolean res = FALSE;
4499 const gchar *name = NULL;
4500 gboolean insert = TRUE;
4502 type = GST_EVENT_TYPE (event);
4504 /* Store all sticky events except SEGMENT/SEGMENT when we're flushing,
4505 * otherwise they can be dropped and nothing would ever resend them.
4506 * Only do that for activated pads though, everything else is a bug!
4508 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4509 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4510 || type == GST_EVENT_EOS))))
4513 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4516 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4517 name = gst_structure_get_name (gst_event_get_structure (event));
4519 events = pad->priv->events;
4522 for (i = 0; i < len; i++) {
4523 PadEvent *ev = &g_array_index (events, PadEvent, i);
4525 if (ev->event == NULL)
4528 if (type == GST_EVENT_TYPE (ev->event)) {
4529 /* matching types, check matching name if needed */
4530 if (name && !gst_event_has_name (ev->event, name))
4534 if ((res = gst_event_replace (&ev->event, event)))
4535 ev->received = FALSE;
4541 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4542 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4543 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4544 * storing the sticky ordered we can check that this is respected. */
4545 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4546 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4548 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4549 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4550 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4551 gst_event_type_get_name (type));
4557 ev.event = gst_event_ref (event);
4558 ev.received = FALSE;
4559 g_array_insert_val (events, i, ev);
4564 pad->priv->events_cookie++;
4565 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4567 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4569 switch (GST_EVENT_TYPE (event)) {
4570 case GST_EVENT_CAPS:
4571 GST_OBJECT_UNLOCK (pad);
4573 GST_DEBUG_OBJECT (pad, "notify caps");
4574 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4576 GST_OBJECT_LOCK (pad);
4582 if (type == GST_EVENT_EOS)
4583 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4585 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4590 GST_DEBUG_OBJECT (pad, "pad is flushing");
4591 return GST_FLOW_FLUSHING;
4595 GST_DEBUG_OBJECT (pad, "pad is EOS");
4596 return GST_FLOW_EOS;
4601 * gst_pad_store_sticky_event:
4603 * @event: a #GstEvent
4605 * Store the sticky @event on @pad
4607 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4608 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4613 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4617 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4618 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4620 GST_OBJECT_LOCK (pad);
4621 ret = store_sticky_event (pad, event);
4622 GST_OBJECT_UNLOCK (pad);
4628 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
4630 PushStickyData *data = user_data;
4632 /* Forward all sticky events before our current one that are pending */
4633 if (ev->event != data->event
4634 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
4635 return push_sticky (pad, ev, data);
4640 /* should be called with pad LOCK */
4641 static GstFlowReturn
4642 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4643 GstPadProbeType type)
4647 GstEventType event_type;
4649 /* Two checks to be made:
4650 * . (un)set the FLUSHING flag for flushing events,
4651 * . handle pad blocking */
4652 event_type = GST_EVENT_TYPE (event);
4653 switch (event_type) {
4654 case GST_EVENT_FLUSH_START:
4655 GST_PAD_SET_FLUSHING (pad);
4657 GST_PAD_BLOCK_BROADCAST (pad);
4658 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4660 case GST_EVENT_FLUSH_STOP:
4661 GST_PAD_UNSET_FLUSHING (pad);
4663 /* Remove sticky EOS events */
4664 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4665 remove_event_by_type (pad, GST_EVENT_EOS);
4666 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4667 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4669 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4673 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4676 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4677 * checked already or this is called as part of pushing sticky events,
4678 * in which case we still want to forward the EOS event downstream.
4681 switch (GST_EVENT_TYPE (event)) {
4682 case GST_EVENT_SEGMENT:
4683 /* pass the adjusted segment event on. We need to do this even if
4684 * there is no peer pad because of the probes. */
4685 event = apply_pad_offset (pad, event);
4687 case GST_EVENT_RECONFIGURE:
4688 if (GST_PAD_IS_SINK (pad))
4689 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4694 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4695 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4700 /* send probes after modifying the events above */
4701 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4703 /* recheck sticky events because the probe might have cause a relink */
4704 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
4705 && (GST_EVENT_IS_SERIALIZED (event)
4706 || GST_EVENT_IS_STICKY (event))) {
4707 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4708 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4710 /* Push all sticky events before our current one
4711 * that have changed */
4712 events_foreach (pad, sticky_changed, &data);
4715 /* now check the peer pad */
4716 peerpad = GST_PAD_PEER (pad);
4717 if (peerpad == NULL)
4720 gst_object_ref (peerpad);
4722 GST_OBJECT_UNLOCK (pad);
4724 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4725 event, GST_EVENT_TYPE_NAME (event), peerpad);
4727 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4729 /* Note: we gave away ownership of the event at this point but we can still
4730 * print the old pointer */
4731 GST_LOG_OBJECT (pad, "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s",
4732 event, peerpad, gst_flow_get_name (ret));
4734 gst_object_unref (peerpad);
4736 GST_OBJECT_LOCK (pad);
4738 if (pad->priv->using == 0) {
4739 /* pad is not active anymore, trigger idle callbacks */
4740 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4741 idle_probe_stopped, ret);
4745 /* ERROR handling */
4748 GST_DEBUG_OBJECT (pad, "We're flushing");
4749 gst_event_unref (event);
4750 return GST_FLOW_FLUSHING;
4754 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4755 gst_event_unref (event);
4758 case GST_FLOW_CUSTOM_SUCCESS:
4759 GST_DEBUG_OBJECT (pad, "dropped event");
4762 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4769 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4770 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4771 gst_event_unref (event);
4773 /* unlinked pads should not influence latency configuration */
4774 if (event_type == GST_EVENT_LATENCY)
4777 return GST_FLOW_NOT_LINKED;
4781 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4787 * gst_pad_push_event:
4788 * @pad: a #GstPad to push the event to.
4789 * @event: (transfer full): the #GstEvent to send to the pad.
4791 * Sends the event to the peer of the given pad. This function is
4792 * mainly used by elements to send events to their peer
4795 * This function takes ownership of the provided event so you should
4796 * gst_event_ref() it if you want to reuse the event after this call.
4798 * Returns: TRUE if the event was handled.
4803 gst_pad_push_event (GstPad * pad, GstEvent * event)
4805 gboolean res = FALSE;
4806 GstPadProbeType type;
4807 gboolean sticky, serialized;
4809 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4810 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4812 if (GST_PAD_IS_SRC (pad)) {
4813 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4814 goto wrong_direction;
4815 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4816 } else if (GST_PAD_IS_SINK (pad)) {
4817 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4818 goto wrong_direction;
4819 /* events pushed on sinkpad never are sticky */
4820 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4822 goto unknown_direction;
4824 GST_OBJECT_LOCK (pad);
4825 sticky = GST_EVENT_IS_STICKY (event);
4826 serialized = GST_EVENT_IS_SERIALIZED (event);
4829 /* srcpad sticky events are stored immediately, the received flag is set
4830 * to FALSE and will be set to TRUE when we can successfully push the
4831 * event to the peer pad */
4832 switch (store_sticky_event (pad, event)) {
4833 case GST_FLOW_FLUSHING:
4841 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4842 /* all serialized or sticky events on the srcpad trigger push of
4844 res = (check_sticky (pad, event) == GST_FLOW_OK);
4849 /* other events are pushed right away */
4850 ret = gst_pad_push_event_unchecked (pad, event, type);
4851 /* dropped events by a probe are not an error */
4852 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4854 /* Errors in sticky event pushing are no problem and ignored here
4855 * as they will cause more meaningful errors during data flow.
4856 * For EOS events, that are not followed by data flow, we still
4857 * return FALSE here though.
4859 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4861 gst_event_unref (event);
4863 GST_OBJECT_UNLOCK (pad);
4867 /* ERROR handling */
4870 g_warning ("pad %s:%s pushing %s event in wrong direction",
4871 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4872 gst_event_unref (event);
4877 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4878 gst_event_unref (event);
4883 GST_DEBUG_OBJECT (pad, "We're flushing");
4884 GST_OBJECT_UNLOCK (pad);
4885 gst_event_unref (event);
4890 GST_DEBUG_OBJECT (pad, "We're EOS");
4891 GST_OBJECT_UNLOCK (pad);
4892 gst_event_unref (event);
4897 /* Check if we can call the event function with the given event */
4898 static GstFlowReturn
4899 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4903 switch (GST_EVENT_TYPE (event)) {
4904 case GST_EVENT_CAPS:
4906 /* backwards compatibility mode for caps */
4907 gst_event_parse_caps (event, &caps);
4909 if (!gst_pad_query_accept_caps (pad, caps))
4921 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4922 "caps %" GST_PTR_FORMAT " not accepted", caps);
4923 return GST_FLOW_NOT_NEGOTIATED;
4927 static GstFlowReturn
4928 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4929 GstPadProbeType type)
4932 GstEventType event_type;
4933 gboolean serialized, need_unlock = FALSE, sticky;
4934 GstPadEventFunction eventfunc;
4937 GST_OBJECT_LOCK (pad);
4938 if (GST_PAD_IS_SINK (pad))
4939 serialized = GST_EVENT_IS_SERIALIZED (event);
4942 sticky = GST_EVENT_IS_STICKY (event);
4943 event_type = GST_EVENT_TYPE (event);
4944 switch (event_type) {
4945 case GST_EVENT_FLUSH_START:
4946 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4947 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4949 /* can't even accept a flush begin event when flushing */
4950 if (GST_PAD_IS_FLUSHING (pad))
4953 GST_PAD_SET_FLUSHING (pad);
4954 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4956 case GST_EVENT_FLUSH_STOP:
4957 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4958 GST_PAD_UNSET_FLUSHING (pad);
4959 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4961 /* Remove pending EOS events */
4962 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
4963 remove_event_by_type (pad, GST_EVENT_EOS);
4964 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4965 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4967 GST_OBJECT_UNLOCK (pad);
4968 /* grab stream lock */
4969 GST_PAD_STREAM_LOCK (pad);
4971 GST_OBJECT_LOCK (pad);
4972 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4975 case GST_EVENT_RECONFIGURE:
4976 if (GST_PAD_IS_SRC (pad))
4977 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4979 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4980 "have event type %" GST_PTR_FORMAT, event);
4982 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4986 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4989 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4990 GST_OBJECT_UNLOCK (pad);
4991 GST_PAD_STREAM_LOCK (pad);
4993 GST_OBJECT_LOCK (pad);
4994 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4997 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5001 switch (GST_EVENT_TYPE (event)) {
5002 case GST_EVENT_SEGMENT:
5003 event = apply_pad_offset (pad, event);
5011 /* now do the probe */
5013 type | GST_PAD_PROBE_TYPE_PUSH |
5014 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5016 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5018 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5021 ACQUIRE_PARENT (pad, parent, no_parent);
5022 GST_OBJECT_UNLOCK (pad);
5024 ret = pre_eventfunc_check (pad, event);
5025 if (G_UNLIKELY (ret != GST_FLOW_OK))
5026 goto precheck_failed;
5029 gst_event_ref (event);
5031 if (eventfunc (pad, parent, event)) {
5034 /* something went wrong */
5035 switch (event_type) {
5036 case GST_EVENT_CAPS:
5037 ret = GST_FLOW_NOT_NEGOTIATED;
5040 ret = GST_FLOW_ERROR;
5044 RELEASE_PARENT (parent);
5046 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5049 if (ret == GST_FLOW_OK) {
5050 GST_OBJECT_LOCK (pad);
5051 /* after the event function accepted the event, we can store the sticky
5052 * event on the pad */
5053 switch (store_sticky_event (pad, event)) {
5054 case GST_FLOW_FLUSHING:
5061 GST_OBJECT_UNLOCK (pad);
5063 gst_event_unref (event);
5067 GST_PAD_STREAM_UNLOCK (pad);
5071 /* ERROR handling */
5074 GST_OBJECT_UNLOCK (pad);
5076 GST_PAD_STREAM_UNLOCK (pad);
5077 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5078 "Received event on flushing pad. Discarding");
5079 gst_event_unref (event);
5080 return GST_FLOW_FLUSHING;
5084 GST_OBJECT_UNLOCK (pad);
5086 GST_PAD_STREAM_UNLOCK (pad);
5087 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5088 "Received event on EOS pad. Discarding");
5089 gst_event_unref (event);
5090 return GST_FLOW_EOS;
5094 GST_OBJECT_UNLOCK (pad);
5096 GST_PAD_STREAM_UNLOCK (pad);
5097 gst_event_unref (event);
5100 case GST_FLOW_CUSTOM_SUCCESS:
5101 GST_DEBUG_OBJECT (pad, "dropped event");
5105 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5112 g_warning ("pad %s:%s has no event handler, file a bug.",
5113 GST_DEBUG_PAD_NAME (pad));
5114 GST_OBJECT_UNLOCK (pad);
5116 GST_PAD_STREAM_UNLOCK (pad);
5117 gst_event_unref (event);
5118 return GST_FLOW_NOT_SUPPORTED;
5122 GST_DEBUG_OBJECT (pad, "no parent");
5123 GST_OBJECT_UNLOCK (pad);
5125 GST_PAD_STREAM_UNLOCK (pad);
5126 gst_event_unref (event);
5127 return GST_FLOW_FLUSHING;
5131 GST_DEBUG_OBJECT (pad, "pre event check failed");
5132 RELEASE_PARENT (parent);
5134 GST_PAD_STREAM_UNLOCK (pad);
5135 gst_event_unref (event);
5141 * gst_pad_send_event:
5142 * @pad: a #GstPad to send the event to.
5143 * @event: (transfer full): the #GstEvent to send to the pad.
5145 * Sends the event to the pad. This function can be used
5146 * by applications to send events in the pipeline.
5148 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5149 * sink pad, @event should be a downstream event. For example, you would not
5150 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5151 * Furthermore, some downstream events have to be serialized with data flow,
5152 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5153 * the event needs to be serialized with data flow, this function will take the
5154 * pad's stream lock while calling its event function.
5156 * To find out whether an event type is upstream, downstream, or downstream and
5157 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5158 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5159 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5160 * plugin doesn't need to bother itself with this information; the core handles
5161 * all necessary locks and checks.
5163 * This function takes ownership of the provided event so you should
5164 * gst_event_ref() it if you want to reuse the event after this call.
5166 * Returns: TRUE if the event was handled.
5169 gst_pad_send_event (GstPad * pad, GstEvent * event)
5172 GstPadProbeType type;
5174 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5175 g_return_val_if_fail (event != NULL, FALSE);
5177 if (GST_PAD_IS_SINK (pad)) {
5178 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5179 goto wrong_direction;
5180 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5181 } else if (GST_PAD_IS_SRC (pad)) {
5182 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5183 goto wrong_direction;
5184 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5186 goto unknown_direction;
5188 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5195 /* ERROR handling */
5198 g_warning ("pad %s:%s sending %s event in wrong direction",
5199 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5200 gst_event_unref (event);
5205 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5206 gst_event_unref (event);
5212 * gst_pad_set_element_private:
5213 * @pad: the #GstPad to set the private data of.
5214 * @priv: The private data to attach to the pad.
5216 * Set the given private data gpointer on the pad.
5217 * This function can only be used by the element that owns the pad.
5218 * No locking is performed in this function.
5221 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5223 pad->element_private = priv;
5227 * gst_pad_get_element_private:
5228 * @pad: the #GstPad to get the private data of.
5230 * Gets the private data of a pad.
5231 * No locking is performed in this function.
5233 * Returns: (transfer none): a #gpointer to the private data.
5236 gst_pad_get_element_private (GstPad * pad)
5238 return pad->element_private;
5242 * gst_pad_get_sticky_event:
5243 * @pad: the #GstPad to get the event from.
5244 * @event_type: the #GstEventType that should be retrieved.
5245 * @idx: the index of the event
5247 * Returns a new reference of the sticky event of type @event_type
5250 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
5251 * event of @event_type was on @pad. Unref after usage.
5254 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5256 GstEvent *event = NULL;
5259 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5260 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5262 GST_OBJECT_LOCK (pad);
5263 ev = find_event_by_type (pad, event_type, idx);
5264 if (ev && (event = ev->event))
5265 gst_event_ref (event);
5266 GST_OBJECT_UNLOCK (pad);
5273 GstPadStickyEventsForeachFunction func;
5278 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5280 ForeachDispatch *data = user_data;
5281 gboolean ret = TRUE;
5284 GST_OBJECT_UNLOCK (pad);
5286 ret = data->func (pad, &ev->event, data->user_data);
5288 GST_OBJECT_LOCK (pad);
5295 * gst_pad_sticky_events_foreach:
5296 * @pad: the #GstPad that should be used for iteration.
5297 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5298 * should be called for every event.
5299 * @user_data: (closure): the optional user data.
5301 * Iterates all sticky events on @pad and calls @foreach_func for every
5302 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5305 gst_pad_sticky_events_foreach (GstPad * pad,
5306 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5308 ForeachDispatch data;
5310 g_return_if_fail (GST_IS_PAD (pad));
5311 g_return_if_fail (foreach_func != NULL);
5313 data.func = foreach_func;
5314 data.user_data = user_data;
5316 GST_OBJECT_LOCK (pad);
5317 events_foreach (pad, foreach_dispatch_function, &data);
5318 GST_OBJECT_UNLOCK (pad);
5322 do_stream_status (GstPad * pad, GstStreamStatusType type,
5323 GThread * thread, GstTask * task)
5327 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5329 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5330 if (GST_IS_ELEMENT (parent)) {
5331 GstMessage *message;
5332 GValue value = { 0 };
5334 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5335 gchar *tname, *ename, *pname;
5337 /* create a good task name */
5338 ename = gst_element_get_name (parent);
5339 pname = gst_pad_get_name (pad);
5340 tname = g_strdup_printf ("%s:%s", ename, pname);
5344 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5348 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5351 g_value_init (&value, GST_TYPE_TASK);
5352 g_value_set_object (&value, task);
5353 gst_message_set_stream_status_object (message, &value);
5354 g_value_unset (&value);
5356 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5357 gst_element_post_message (parent, message);
5359 gst_object_unref (parent);
5364 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5366 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5371 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5373 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5378 * gst_pad_start_task:
5379 * @pad: the #GstPad to start the task of
5380 * @func: the task function to call
5381 * @user_data: user data passed to the task function
5382 * @notify: called when @user_data is no longer referenced
5384 * Starts a task that repeatedly calls @func with @user_data. This function
5385 * is mostly used in pad activation functions to start the dataflow.
5386 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5387 * before @func is called.
5389 * Returns: a %TRUE if the task could be started.
5392 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5393 GDestroyNotify notify)
5398 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5399 g_return_val_if_fail (func != NULL, FALSE);
5401 GST_DEBUG_OBJECT (pad, "start task");
5403 GST_OBJECT_LOCK (pad);
5404 task = GST_PAD_TASK (pad);
5406 task = gst_task_new (func, user_data, notify);
5407 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5408 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5409 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5410 GST_INFO_OBJECT (pad, "created task %p", task);
5411 GST_PAD_TASK (pad) = task;
5412 gst_object_ref (task);
5413 /* release lock to post the message */
5414 GST_OBJECT_UNLOCK (pad);
5416 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5418 gst_object_unref (task);
5420 GST_OBJECT_LOCK (pad);
5421 /* nobody else is supposed to have changed the pad now */
5422 if (GST_PAD_TASK (pad) != task)
5423 goto concurrent_stop;
5425 res = gst_task_set_state (task, GST_TASK_STARTED);
5426 GST_OBJECT_UNLOCK (pad);
5433 GST_OBJECT_UNLOCK (pad);
5439 * gst_pad_pause_task:
5440 * @pad: the #GstPad to pause the task of
5442 * Pause the task of @pad. This function will also wait until the
5443 * function executed by the task is finished if this function is not
5444 * called from the task function.
5446 * Returns: a TRUE if the task could be paused or FALSE when the pad
5450 gst_pad_pause_task (GstPad * pad)
5455 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5457 GST_DEBUG_OBJECT (pad, "pause task");
5459 GST_OBJECT_LOCK (pad);
5460 task = GST_PAD_TASK (pad);
5463 res = gst_task_set_state (task, GST_TASK_PAUSED);
5464 GST_OBJECT_UNLOCK (pad);
5466 /* wait for task function to finish, this lock is recursive so it does nothing
5467 * when the pause is called from the task itself */
5468 GST_PAD_STREAM_LOCK (pad);
5469 GST_PAD_STREAM_UNLOCK (pad);
5475 GST_DEBUG_OBJECT (pad, "pad has no task");
5476 GST_OBJECT_UNLOCK (pad);
5482 * gst_pad_stop_task:
5483 * @pad: the #GstPad to stop the task of
5485 * Stop the task of @pad. This function will also make sure that the
5486 * function executed by the task will effectively stop if not called
5487 * from the GstTaskFunction.
5489 * This function will deadlock if called from the GstTaskFunction of
5490 * the task. Use gst_task_pause() instead.
5492 * Regardless of whether the pad has a task, the stream lock is acquired and
5493 * released so as to ensure that streaming through this pad has finished.
5495 * Returns: a TRUE if the task could be stopped or FALSE on error.
5498 gst_pad_stop_task (GstPad * pad)
5503 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5505 GST_DEBUG_OBJECT (pad, "stop task");
5507 GST_OBJECT_LOCK (pad);
5508 task = GST_PAD_TASK (pad);
5511 GST_PAD_TASK (pad) = NULL;
5512 res = gst_task_set_state (task, GST_TASK_STOPPED);
5513 GST_OBJECT_UNLOCK (pad);
5515 GST_PAD_STREAM_LOCK (pad);
5516 GST_PAD_STREAM_UNLOCK (pad);
5518 if (!gst_task_join (task))
5521 gst_object_unref (task);
5527 GST_DEBUG_OBJECT (pad, "no task");
5528 GST_OBJECT_UNLOCK (pad);
5530 GST_PAD_STREAM_LOCK (pad);
5531 GST_PAD_STREAM_UNLOCK (pad);
5533 /* this is not an error */
5538 /* this is bad, possibly the application tried to join the task from
5539 * the task's thread. We install the task again so that it will be stopped
5540 * again from the right thread next time hopefully. */
5541 GST_OBJECT_LOCK (pad);
5542 GST_DEBUG_OBJECT (pad, "join failed");
5543 /* we can only install this task if there was no other task */
5544 if (GST_PAD_TASK (pad) == NULL)
5545 GST_PAD_TASK (pad) = task;
5546 GST_OBJECT_UNLOCK (pad);
5553 * gst_pad_probe_info_get_event:
5554 * @info: a #GstPadProbeInfo
5556 * Returns: (transfer none): The #GstEvent from the probe
5560 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5562 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5563 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5565 return GST_PAD_PROBE_INFO_EVENT (info);
5570 * gst_pad_probe_info_get_query:
5571 * @info: a #GstPadProbeInfo
5573 * Returns: (transfer none): The #GstQuery from the probe
5577 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5579 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5580 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5582 return GST_PAD_PROBE_INFO_QUERY (info);
5586 * gst_pad_probe_info_get_buffer:
5587 * @info: a #GstPadProbeInfo
5589 * Returns: (transfer none): The #GstBuffer from the probe
5593 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5595 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5597 return GST_PAD_PROBE_INFO_BUFFER (info);
5601 * gst_pad_probe_info_get_bufferlist:
5602 * @info: a #GstPadProbeInfo
5604 * Returns: (transfer none): The #GstBufferlist from the probe
5608 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5610 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5612 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);