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",
1199 /* Might have new probes now that want to be called */
1200 GST_PAD_BLOCK_BROADCAST (pad);
1202 if (pad->num_blocked == 0) {
1203 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1204 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1207 g_hook_destroy_link (&pad->probes, hook);
1212 * gst_pad_add_probe:
1213 * @pad: the #GstPad to add the probe to
1214 * @mask: the probe mask
1215 * @callback: #GstPadProbeCallback that will be called with notifications of
1217 * @user_data: (closure): user data passed to the callback
1218 * @destroy_data: #GDestroyNotify for user_data
1220 * Be notified of different states of pads. The provided callback is called for
1221 * every state that matches @mask.
1223 * Returns: an id or 0 on error. The id can be used to remove the probe with
1224 * gst_pad_remove_probe().
1229 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1230 GstPadProbeCallback callback, gpointer user_data,
1231 GDestroyNotify destroy_data)
1236 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1237 g_return_val_if_fail (mask != 0, 0);
1239 GST_OBJECT_LOCK (pad);
1241 /* make a new probe */
1242 hook = g_hook_alloc (&pad->probes);
1244 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1247 /* when no contraints are given for the types, assume all types are
1249 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1250 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1251 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1252 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1254 /* store our flags and other fields */
1255 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1256 hook->func = callback;
1257 hook->data = user_data;
1258 hook->destroy = destroy_data;
1259 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1262 g_hook_prepend (&pad->probes, hook);
1264 /* incremenent cookie so that the new hook get's called */
1265 pad->priv->probe_list_cookie++;
1267 /* get the id of the hook, we return this and it can be used to remove the
1269 res = hook->hook_id;
1271 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1273 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1274 /* we have a block probe */
1276 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1277 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1278 "now %d blocking probes", pad->num_blocked);
1280 /* Might have new probes now that want to be called */
1281 GST_PAD_BLOCK_BROADCAST (pad);
1284 /* call the callback if we need to be called for idle callbacks */
1285 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1286 if (pad->priv->using > 0) {
1287 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1288 * flag above, the last thread to leave the push will do the callback. New
1289 * threads going into the push will block. */
1290 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1291 "pad is in use, delay idle callback");
1292 GST_OBJECT_UNLOCK (pad);
1294 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1295 GstPadProbeReturn ret;
1297 /* Keep another ref, the callback could destroy the pad */
1298 gst_object_ref (pad);
1300 /* the pad is idle now, we can signal the idle callback now */
1301 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1302 "pad is idle, trigger idle callback");
1303 GST_OBJECT_UNLOCK (pad);
1305 ret = callback (pad, &info, user_data);
1307 GST_OBJECT_LOCK (pad);
1309 case GST_PAD_PROBE_REMOVE:
1310 /* remove the probe */
1311 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1312 cleanup_hook (pad, hook);
1315 case GST_PAD_PROBE_DROP:
1316 GST_DEBUG_OBJECT (pad, "asked to drop item");
1318 case GST_PAD_PROBE_PASS:
1319 GST_DEBUG_OBJECT (pad, "asked to pass item");
1321 case GST_PAD_PROBE_OK:
1322 GST_DEBUG_OBJECT (pad, "probe returned OK");
1325 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1328 GST_OBJECT_UNLOCK (pad);
1330 gst_object_unref (pad);
1333 GST_OBJECT_UNLOCK (pad);
1339 * gst_pad_remove_probe:
1340 * @pad: the #GstPad with the probe
1341 * @id: the probe id to remove
1343 * Remove the probe with @id from @pad.
1348 gst_pad_remove_probe (GstPad * pad, gulong id)
1352 g_return_if_fail (GST_IS_PAD (pad));
1354 GST_OBJECT_LOCK (pad);
1356 hook = g_hook_get (&pad->probes, id);
1360 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1362 cleanup_hook (pad, hook);
1363 GST_OBJECT_UNLOCK (pad);
1369 GST_OBJECT_UNLOCK (pad);
1370 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1376 * gst_pad_is_blocked:
1377 * @pad: the #GstPad to query
1379 * Checks if the pad is blocked or not. This function returns the
1380 * last requested state of the pad. It is not certain that the pad
1381 * is actually blocking at this point (see gst_pad_is_blocking()).
1383 * Returns: TRUE if the pad is blocked.
1388 gst_pad_is_blocked (GstPad * pad)
1390 gboolean result = FALSE;
1392 g_return_val_if_fail (GST_IS_PAD (pad), result);
1394 GST_OBJECT_LOCK (pad);
1395 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1396 GST_OBJECT_UNLOCK (pad);
1402 * gst_pad_is_blocking:
1403 * @pad: the #GstPad to query
1405 * Checks if the pad is blocking or not. This is a guaranteed state
1406 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1408 * Returns: TRUE if the pad is blocking.
1413 gst_pad_is_blocking (GstPad * pad)
1415 gboolean result = FALSE;
1417 g_return_val_if_fail (GST_IS_PAD (pad), result);
1419 GST_OBJECT_LOCK (pad);
1420 /* the blocking flag is only valid if the pad is not flushing */
1421 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1422 GST_OBJECT_UNLOCK (pad);
1428 * gst_pad_needs_reconfigure:
1429 * @pad: the #GstPad to check
1431 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1432 * if the flag was set.
1434 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1437 gst_pad_needs_reconfigure (GstPad * pad)
1439 gboolean reconfigure;
1441 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1443 GST_OBJECT_LOCK (pad);
1444 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1445 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1446 GST_OBJECT_UNLOCK (pad);
1452 * gst_pad_check_reconfigure:
1453 * @pad: the #GstPad to check
1455 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1456 * if the flag was set.
1458 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1461 gst_pad_check_reconfigure (GstPad * pad)
1463 gboolean reconfigure;
1465 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1467 GST_OBJECT_LOCK (pad);
1468 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1470 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1471 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1473 GST_OBJECT_UNLOCK (pad);
1479 * gst_pad_mark_reconfigure:
1480 * @pad: the #GstPad to mark
1482 * Mark a pad for needing reconfiguration. The next call to
1483 * gst_pad_check_reconfigure() will return %TRUE after this call.
1486 gst_pad_mark_reconfigure (GstPad * pad)
1488 g_return_if_fail (GST_IS_PAD (pad));
1490 GST_OBJECT_LOCK (pad);
1491 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1492 GST_OBJECT_UNLOCK (pad);
1496 * gst_pad_set_activate_function:
1498 * @f: the #GstPadActivateFunction to set.
1500 * Calls gst_pad_set_activate_function_full() with NULL for the user_data and
1504 * gst_pad_set_activate_function_full:
1506 * @activate: the #GstPadActivateFunction to set.
1507 * @user_data: user_data passed to @notify
1508 * @notify: notify called when @activate will not be used anymore.
1510 * Sets the given activate function for @pad. The activate function will
1511 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1512 * Only makes sense to set on sink pads.
1514 * Call this function if your sink pad can start a pull-based task.
1517 gst_pad_set_activate_function_full (GstPad * pad,
1518 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1520 g_return_if_fail (GST_IS_PAD (pad));
1522 if (pad->activatenotify)
1523 pad->activatenotify (pad->activatedata);
1524 GST_PAD_ACTIVATEFUNC (pad) = activate;
1525 pad->activatedata = user_data;
1526 pad->activatenotify = notify;
1528 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1529 GST_DEBUG_FUNCPTR_NAME (activate));
1533 * gst_pad_set_activatemode_function:
1535 * @f: the #GstPadActivateModeFunction to set.
1537 * Calls gst_pad_set_activatemode_function_full() with NULL for the user_data and
1541 * gst_pad_set_activatemode_function_full:
1543 * @activatemode: the #GstPadActivateModeFunction to set.
1544 * @user_data: user_data passed to @notify
1545 * @notify: notify called when @activatemode will not be used anymore.
1547 * Sets the given activate_mode function for the pad. An activate_mode function
1548 * prepares the element for data passing.
1551 gst_pad_set_activatemode_function_full (GstPad * pad,
1552 GstPadActivateModeFunction activatemode, gpointer user_data,
1553 GDestroyNotify notify)
1555 g_return_if_fail (GST_IS_PAD (pad));
1557 if (pad->activatemodenotify)
1558 pad->activatemodenotify (pad->activatemodedata);
1559 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1560 pad->activatemodedata = user_data;
1561 pad->activatemodenotify = notify;
1563 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1564 GST_DEBUG_FUNCPTR_NAME (activatemode));
1568 * gst_pad_set_chain_function:
1569 * @p: a sink #GstPad.
1570 * @f: the #GstPadChainFunction to set.
1572 * Calls gst_pad_set_chain_function_full() with NULL for the user_data and
1576 * gst_pad_set_chain_function_full:
1577 * @pad: a sink #GstPad.
1578 * @chain: the #GstPadChainFunction to set.
1579 * @user_data: user_data passed to @notify
1580 * @notify: notify called when @chain will not be used anymore.
1582 * Sets the given chain function for the pad. The chain function is called to
1583 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1586 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1587 gpointer user_data, GDestroyNotify notify)
1589 g_return_if_fail (GST_IS_PAD (pad));
1590 g_return_if_fail (GST_PAD_IS_SINK (pad));
1592 if (pad->chainnotify)
1593 pad->chainnotify (pad->chaindata);
1594 GST_PAD_CHAINFUNC (pad) = chain;
1595 pad->chaindata = user_data;
1596 pad->chainnotify = notify;
1598 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1599 GST_DEBUG_FUNCPTR_NAME (chain));
1603 * gst_pad_set_chain_list_function:
1604 * @p: a sink #GstPad.
1605 * @f: the #GstPadChainListFunction to set.
1607 * Calls gst_pad_set_chain_list_function_full() with NULL for the user_data and
1611 * gst_pad_set_chain_list_function_full:
1612 * @pad: a sink #GstPad.
1613 * @chainlist: the #GstPadChainListFunction to set.
1614 * @user_data: user_data passed to @notify
1615 * @notify: notify called when @chainlist will not be used anymore.
1617 * Sets the given chain list function for the pad. The chainlist function is
1618 * called to process a #GstBufferList input buffer list. See
1619 * #GstPadChainListFunction for more details.
1622 gst_pad_set_chain_list_function_full (GstPad * pad,
1623 GstPadChainListFunction chainlist, gpointer user_data,
1624 GDestroyNotify notify)
1626 g_return_if_fail (GST_IS_PAD (pad));
1627 g_return_if_fail (GST_PAD_IS_SINK (pad));
1629 if (pad->chainlistnotify)
1630 pad->chainlistnotify (pad->chainlistdata);
1631 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1632 pad->chainlistdata = user_data;
1633 pad->chainlistnotify = notify;
1635 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1636 GST_DEBUG_FUNCPTR_NAME (chainlist));
1640 * gst_pad_set_getrange_function:
1641 * @p: a source #GstPad.
1642 * @f: the #GstPadGetRangeFunction to set.
1644 * Calls gst_pad_set_getrange_function_full() with NULL for the user_data and
1648 * gst_pad_set_getrange_function_full:
1649 * @pad: a source #GstPad.
1650 * @get: the #GstPadGetRangeFunction to set.
1651 * @user_data: user_data passed to @notify
1652 * @notify: notify called when @get will not be used anymore.
1654 * Sets the given getrange function for the pad. The getrange function is
1655 * called to produce a new #GstBuffer to start the processing pipeline. see
1656 * #GstPadGetRangeFunction for a description of the getrange function.
1659 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1660 gpointer user_data, GDestroyNotify notify)
1662 g_return_if_fail (GST_IS_PAD (pad));
1663 g_return_if_fail (GST_PAD_IS_SRC (pad));
1665 if (pad->getrangenotify)
1666 pad->getrangenotify (pad->getrangedata);
1667 GST_PAD_GETRANGEFUNC (pad) = get;
1668 pad->getrangedata = user_data;
1669 pad->getrangenotify = notify;
1671 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1672 GST_DEBUG_FUNCPTR_NAME (get));
1676 * gst_pad_set_event_function:
1677 * @p: a #GstPad of either direction.
1678 * @f: the #GstPadEventFunction to set.
1680 * Calls gst_pad_set_event_function_full() with NULL for the user_data and
1684 * gst_pad_set_event_function_full:
1685 * @pad: a #GstPad of either direction.
1686 * @event: the #GstPadEventFunction to set.
1687 * @user_data: user_data passed to @notify
1688 * @notify: notify called when @event will not be used anymore.
1690 * Sets the given event handler for the pad.
1693 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1694 gpointer user_data, GDestroyNotify notify)
1696 g_return_if_fail (GST_IS_PAD (pad));
1698 if (pad->eventnotify)
1699 pad->eventnotify (pad->eventdata);
1700 GST_PAD_EVENTFUNC (pad) = event;
1701 pad->eventdata = user_data;
1702 pad->eventnotify = notify;
1704 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1705 GST_DEBUG_FUNCPTR_NAME (event));
1709 * gst_pad_set_query_function:
1710 * @p: a #GstPad of either direction.
1711 * @f: the #GstPadQueryFunction to set.
1713 * Calls gst_pad_set_query_function_full() with NULL for the user_data and
1717 * gst_pad_set_query_function_full:
1718 * @pad: a #GstPad of either direction.
1719 * @query: the #GstPadQueryFunction to set.
1720 * @user_data: user_data passed to @notify
1721 * @notify: notify called when @query will not be used anymore.
1723 * Set the given query function for the pad.
1726 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1727 gpointer user_data, GDestroyNotify notify)
1729 g_return_if_fail (GST_IS_PAD (pad));
1731 if (pad->querynotify)
1732 pad->querynotify (pad->querydata);
1733 GST_PAD_QUERYFUNC (pad) = query;
1734 pad->querydata = user_data;
1735 pad->querynotify = notify;
1737 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1738 GST_DEBUG_FUNCPTR_NAME (query));
1742 * gst_pad_set_iterate_internal_links_function:
1743 * @p: a #GstPad of either direction.
1744 * @f: the #GstPadIterIntLinkFunction to set.
1746 * Calls gst_pad_set_iterate_internal_links_function_full() with NULL
1747 * for the user_data and notify.
1750 * gst_pad_set_iterate_internal_links_function_full:
1751 * @pad: a #GstPad of either direction.
1752 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1753 * @user_data: user_data passed to @notify
1754 * @notify: notify called when @iterintlink will not be used anymore.
1756 * Sets the given internal link iterator function for the pad.
1759 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1760 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1761 GDestroyNotify notify)
1763 g_return_if_fail (GST_IS_PAD (pad));
1765 if (pad->iterintlinknotify)
1766 pad->iterintlinknotify (pad->iterintlinkdata);
1767 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1768 pad->iterintlinkdata = user_data;
1769 pad->iterintlinknotify = notify;
1771 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1772 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1776 * gst_pad_set_link_function:
1778 * @f: the #GstPadLinkFunction to set.
1780 * Calls gst_pad_set_link_function_full() with NULL
1781 * for the user_data and notify.
1784 * gst_pad_set_link_function_full:
1786 * @link: the #GstPadLinkFunction to set.
1787 * @user_data: user_data passed to @notify
1788 * @notify: notify called when @link will not be used anymore.
1790 * Sets the given link function for the pad. It will be called when
1791 * the pad is linked with another pad.
1793 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1796 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1797 * cannot be made for some reason.
1799 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1800 * of the peer sink pad, if present.
1803 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1804 gpointer user_data, GDestroyNotify notify)
1806 g_return_if_fail (GST_IS_PAD (pad));
1808 if (pad->linknotify)
1809 pad->linknotify (pad->linkdata);
1810 GST_PAD_LINKFUNC (pad) = link;
1811 pad->linkdata = user_data;
1812 pad->linknotify = notify;
1814 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1815 GST_DEBUG_FUNCPTR_NAME (link));
1819 * gst_pad_set_unlink_function:
1821 * @f: the #GstPadUnlinkFunction to set.
1823 * Calls gst_pad_set_unlink_function_full() with NULL
1824 * for the user_data and notify.
1827 * gst_pad_set_unlink_function_full:
1829 * @unlink: the #GstPadUnlinkFunction to set.
1830 * @user_data: user_data passed to @notify
1831 * @notify: notify called when @unlink will not be used anymore.
1833 * Sets the given unlink function for the pad. It will be called
1834 * when the pad is unlinked.
1837 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1838 gpointer user_data, GDestroyNotify notify)
1840 g_return_if_fail (GST_IS_PAD (pad));
1842 if (pad->unlinknotify)
1843 pad->unlinknotify (pad->unlinkdata);
1844 GST_PAD_UNLINKFUNC (pad) = unlink;
1845 pad->unlinkdata = user_data;
1846 pad->unlinknotify = notify;
1848 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1849 GST_DEBUG_FUNCPTR_NAME (unlink));
1854 * @srcpad: the source #GstPad to unlink.
1855 * @sinkpad: the sink #GstPad to unlink.
1857 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1858 * signal on both pads.
1860 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1861 * the pads were not linked together.
1866 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1868 gboolean result = FALSE;
1869 GstElement *parent = NULL;
1871 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1872 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1873 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1874 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1876 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1877 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1878 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1880 /* We need to notify the parent before taking any pad locks as the bin in
1881 * question might be waiting for a lock on the pad while holding its lock
1882 * that our message will try to take. */
1883 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1884 if (GST_IS_ELEMENT (parent)) {
1885 gst_element_post_message (parent,
1886 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1887 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1889 gst_object_unref (parent);
1894 GST_OBJECT_LOCK (srcpad);
1895 GST_OBJECT_LOCK (sinkpad);
1897 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1898 goto not_linked_together;
1900 if (GST_PAD_UNLINKFUNC (srcpad)) {
1901 GstObject *tmpparent;
1903 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1905 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1906 RELEASE_PARENT (tmpparent);
1909 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1910 GstObject *tmpparent;
1912 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1914 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1915 RELEASE_PARENT (tmpparent);
1919 /* first clear peers */
1920 GST_PAD_PEER (srcpad) = NULL;
1921 GST_PAD_PEER (sinkpad) = NULL;
1923 GST_OBJECT_UNLOCK (sinkpad);
1924 GST_OBJECT_UNLOCK (srcpad);
1926 /* fire off a signal to each of the pads telling them
1927 * that they've been unlinked */
1928 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1929 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1931 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1932 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1937 if (parent != NULL) {
1938 gst_element_post_message (parent,
1939 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1940 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1941 gst_object_unref (parent);
1946 not_linked_together:
1948 /* we do not emit a warning in this case because unlinking cannot
1949 * be made MT safe.*/
1950 GST_OBJECT_UNLOCK (sinkpad);
1951 GST_OBJECT_UNLOCK (srcpad);
1957 * gst_pad_is_linked:
1958 * @pad: pad to check
1960 * Checks if a @pad is linked to another pad or not.
1962 * Returns: TRUE if the pad is linked, FALSE otherwise.
1967 gst_pad_is_linked (GstPad * pad)
1971 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1973 GST_OBJECT_LOCK (pad);
1974 result = (GST_PAD_PEER (pad) != NULL);
1975 GST_OBJECT_UNLOCK (pad);
1980 /* get the caps from both pads and see if the intersection
1983 * This function should be called with the pad LOCK on both
1987 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1988 GstPadLinkCheck flags)
1990 GstCaps *srccaps = NULL;
1991 GstCaps *sinkcaps = NULL;
1992 gboolean compatible = FALSE;
1994 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1997 /* Doing the expensive caps checking takes priority over only checking the template caps */
1998 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1999 GST_OBJECT_UNLOCK (sink);
2000 GST_OBJECT_UNLOCK (src);
2002 srccaps = gst_pad_query_caps (src, NULL);
2003 sinkcaps = gst_pad_query_caps (sink, NULL);
2005 GST_OBJECT_LOCK (src);
2006 GST_OBJECT_LOCK (sink);
2008 /* If one of the two pads doesn't have a template, consider the intersection
2010 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2011 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2015 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2017 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2020 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2022 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2025 /* if we have caps on both pads we can check the intersection. If one
2026 * of the caps is NULL, we return TRUE. */
2027 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2029 gst_caps_unref (srccaps);
2031 gst_caps_unref (sinkcaps);
2035 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2036 gst_caps_unref (srccaps);
2037 gst_caps_unref (sinkcaps);
2040 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2041 (compatible ? "" : "not"));
2046 /* check if the grandparents of both pads are the same.
2047 * This check is required so that we don't try to link
2048 * pads from elements in different bins without ghostpads.
2050 * The LOCK should be held on both pads
2053 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2055 GstObject *psrc, *psink;
2057 psrc = GST_OBJECT_PARENT (src);
2058 psink = GST_OBJECT_PARENT (sink);
2060 /* if one of the pads has no parent, we allow the link */
2061 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2064 /* only care about parents that are elements */
2065 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2066 goto no_element_parent;
2068 /* if the parents are the same, we have a loop */
2069 if (G_UNLIKELY (psrc == psink))
2072 /* if they both have a parent, we check the grandparents. We can not lock
2073 * the parent because we hold on the child (pad) and the locking order is
2074 * parent >> child. */
2075 psrc = GST_OBJECT_PARENT (psrc);
2076 psink = GST_OBJECT_PARENT (psink);
2078 /* if they have grandparents but they are not the same */
2079 if (G_UNLIKELY (psrc != psink))
2080 goto wrong_grandparents;
2087 GST_CAT_DEBUG (GST_CAT_CAPS,
2088 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2089 GST_PTR_FORMAT, psrc, psink);
2094 GST_CAT_DEBUG (GST_CAT_CAPS,
2095 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2096 GST_PTR_FORMAT, psrc, psink);
2101 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2107 GST_CAT_DEBUG (GST_CAT_CAPS,
2108 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2109 GST_PTR_FORMAT, psrc, psink);
2114 /* FIXME leftover from an attempt at refactoring... */
2115 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2116 * the two pads will be locked in the srcpad, sinkpad order. */
2117 static GstPadLinkReturn
2118 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2120 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2121 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2123 GST_OBJECT_LOCK (srcpad);
2125 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2126 goto src_was_linked;
2128 GST_OBJECT_LOCK (sinkpad);
2130 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2131 goto sink_was_linked;
2133 /* check hierarchy, pads can only be linked if the grandparents
2135 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2136 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2137 goto wrong_hierarchy;
2139 /* check pad caps for non-empty intersection */
2140 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2143 /* FIXME check pad scheduling for non-empty intersection */
2145 return GST_PAD_LINK_OK;
2149 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2150 GST_DEBUG_PAD_NAME (srcpad),
2151 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2152 /* we do not emit a warning in this case because unlinking cannot
2153 * be made MT safe.*/
2154 GST_OBJECT_UNLOCK (srcpad);
2155 return GST_PAD_LINK_WAS_LINKED;
2159 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2160 GST_DEBUG_PAD_NAME (sinkpad),
2161 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2162 /* we do not emit a warning in this case because unlinking cannot
2163 * be made MT safe.*/
2164 GST_OBJECT_UNLOCK (sinkpad);
2165 GST_OBJECT_UNLOCK (srcpad);
2166 return GST_PAD_LINK_WAS_LINKED;
2170 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2171 GST_OBJECT_UNLOCK (sinkpad);
2172 GST_OBJECT_UNLOCK (srcpad);
2173 return GST_PAD_LINK_WRONG_HIERARCHY;
2177 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2178 GST_OBJECT_UNLOCK (sinkpad);
2179 GST_OBJECT_UNLOCK (srcpad);
2180 return GST_PAD_LINK_NOFORMAT;
2186 * @srcpad: the source #GstPad.
2187 * @sinkpad: the sink #GstPad.
2189 * Checks if the source pad and the sink pad are compatible so they can be
2192 * Returns: TRUE if the pads can be linked.
2195 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2197 GstPadLinkReturn result;
2199 /* generic checks */
2200 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2201 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2203 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2204 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2206 /* gst_pad_link_prepare does everything for us, we only release the locks
2207 * on the pads that it gets us. If this function returns !OK the locks are not
2209 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2210 if (result != GST_PAD_LINK_OK)
2213 GST_OBJECT_UNLOCK (srcpad);
2214 GST_OBJECT_UNLOCK (sinkpad);
2217 return result == GST_PAD_LINK_OK;
2221 * gst_pad_link_full:
2222 * @srcpad: the source #GstPad to link.
2223 * @sinkpad: the sink #GstPad to link.
2224 * @flags: the checks to validate when linking
2226 * Links the source pad and the sink pad.
2228 * This variant of #gst_pad_link provides a more granular control on the
2229 * checks being done when linking. While providing some considerable speedups
2230 * the caller of this method must be aware that wrong usage of those flags
2231 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2232 * for more information.
2236 * Returns: A result code indicating if the connection worked or
2240 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2242 GstPadLinkReturn result;
2244 GstPadLinkFunction srcfunc, sinkfunc;
2246 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2247 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2248 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2249 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2250 GST_PAD_LINK_WRONG_DIRECTION);
2252 /* Notify the parent early. See gst_pad_unlink for details. */
2253 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2254 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2255 gst_element_post_message (parent,
2256 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2257 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2259 gst_object_unref (parent);
2264 /* prepare will also lock the two pads */
2265 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2267 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2270 /* must set peers before calling the link function */
2271 GST_PAD_PEER (srcpad) = sinkpad;
2272 GST_PAD_PEER (sinkpad) = srcpad;
2274 /* check events, when something is different, mark pending */
2275 schedule_events (srcpad, sinkpad);
2277 /* get the link functions */
2278 srcfunc = GST_PAD_LINKFUNC (srcpad);
2279 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2281 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2282 /* custom link functions, execute them */
2283 GST_OBJECT_UNLOCK (sinkpad);
2284 GST_OBJECT_UNLOCK (srcpad);
2287 GstObject *tmpparent;
2289 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2290 /* this one will call the peer link function */
2291 result = srcfunc (srcpad, tmpparent, sinkpad);
2292 RELEASE_PARENT (tmpparent);
2293 } else if (sinkfunc) {
2294 GstObject *tmpparent;
2296 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2297 /* if no source link function, we need to call the sink link
2298 * function ourselves. */
2299 result = sinkfunc (sinkpad, tmpparent, srcpad);
2300 RELEASE_PARENT (tmpparent);
2304 GST_OBJECT_LOCK (srcpad);
2305 GST_OBJECT_LOCK (sinkpad);
2307 /* we released the lock, check if the same pads are linked still */
2308 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2309 goto concurrent_link;
2311 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2314 GST_OBJECT_UNLOCK (sinkpad);
2315 GST_OBJECT_UNLOCK (srcpad);
2317 /* fire off a signal to each of the pads telling them
2318 * that they've been linked */
2319 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2320 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2322 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2323 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2325 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2328 if (G_LIKELY (parent)) {
2329 gst_element_post_message (parent,
2330 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2331 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2332 gst_object_unref (parent);
2340 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2341 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2342 GST_OBJECT_UNLOCK (sinkpad);
2343 GST_OBJECT_UNLOCK (srcpad);
2345 /* The other link operation succeeded first */
2346 result = GST_PAD_LINK_WAS_LINKED;
2351 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2352 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2354 GST_PAD_PEER (srcpad) = NULL;
2355 GST_PAD_PEER (sinkpad) = NULL;
2357 GST_OBJECT_UNLOCK (sinkpad);
2358 GST_OBJECT_UNLOCK (srcpad);
2366 * @srcpad: the source #GstPad to link.
2367 * @sinkpad: the sink #GstPad to link.
2369 * Links the source pad and the sink pad.
2371 * Returns: A result code indicating if the connection worked or
2377 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2379 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2383 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2385 GstPadTemplate **template_p;
2387 /* this function would need checks if it weren't static */
2389 GST_OBJECT_LOCK (pad);
2390 template_p = &pad->padtemplate;
2391 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2392 GST_OBJECT_UNLOCK (pad);
2395 gst_pad_template_pad_created (templ, pad);
2399 * gst_pad_get_pad_template:
2402 * Gets the template for @pad.
2404 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2405 * instantiated, or %NULL if this pad has no template. Unref after
2409 gst_pad_get_pad_template (GstPad * pad)
2411 GstPadTemplate *templ;
2413 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2415 templ = GST_PAD_PAD_TEMPLATE (pad);
2417 return (templ ? gst_object_ref (templ) : NULL);
2421 * gst_pad_has_current_caps:
2422 * @pad: a #GstPad to check
2424 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2426 * Returns: TRUE when @pad has caps associated with it.
2429 gst_pad_has_current_caps (GstPad * pad)
2434 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2436 GST_OBJECT_LOCK (pad);
2437 caps = get_pad_caps (pad);
2438 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2439 "check current pad caps %" GST_PTR_FORMAT, caps);
2440 result = (caps != NULL);
2441 GST_OBJECT_UNLOCK (pad);
2447 * gst_pad_get_current_caps:
2448 * @pad: a #GstPad to get the current capabilities of.
2450 * Gets the capabilities currently configured on @pad with the last
2451 * #GST_EVENT_CAPS event.
2453 * Returns: the current caps of the pad with incremented ref-count.
2456 gst_pad_get_current_caps (GstPad * pad)
2460 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2462 GST_OBJECT_LOCK (pad);
2463 if ((result = get_pad_caps (pad)))
2464 gst_caps_ref (result);
2465 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2466 "get current pad caps %" GST_PTR_FORMAT, result);
2467 GST_OBJECT_UNLOCK (pad);
2473 * gst_pad_get_pad_template_caps:
2474 * @pad: a #GstPad to get the template capabilities from.
2476 * Gets the capabilities for @pad's template.
2478 * Returns: (transfer full): the #GstCaps of this pad template.
2479 * Unref after usage.
2482 gst_pad_get_pad_template_caps (GstPad * pad)
2484 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2486 if (GST_PAD_PAD_TEMPLATE (pad))
2487 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2489 return gst_caps_ref (GST_CAPS_ANY);
2494 * @pad: a #GstPad to get the peer of.
2496 * Gets the peer of @pad. This function refs the peer pad so
2497 * you need to unref it after use.
2499 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2504 gst_pad_get_peer (GstPad * pad)
2508 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2510 GST_OBJECT_LOCK (pad);
2511 result = GST_PAD_PEER (pad);
2513 gst_object_ref (result);
2514 GST_OBJECT_UNLOCK (pad);
2520 * gst_pad_get_allowed_caps:
2523 * Gets the capabilities of the allowed media types that can flow through
2524 * @pad and its peer.
2526 * The allowed capabilities is calculated as the intersection of the results of
2527 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2528 * on the resulting caps.
2530 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2531 * caps when you no longer need it. This function returns NULL when @pad
2537 gst_pad_get_allowed_caps (GstPad * pad)
2543 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2545 GST_OBJECT_LOCK (pad);
2546 peer = GST_PAD_PEER (pad);
2547 if (G_UNLIKELY (peer == NULL))
2550 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2552 gst_object_ref (peer);
2553 GST_OBJECT_UNLOCK (pad);
2554 mycaps = gst_pad_query_caps (pad, NULL);
2556 caps = gst_pad_query_caps (peer, mycaps);
2557 gst_object_unref (peer);
2559 gst_caps_unref (mycaps);
2561 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2568 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2569 GST_OBJECT_UNLOCK (pad);
2576 * gst_pad_iterate_internal_links_default:
2577 * @pad: the #GstPad to get the internal links of.
2578 * @parent: (allow-none): the parent of @pad or NULL
2580 * Iterate the list of pads to which the given pad is linked to inside of
2581 * the parent element.
2582 * This is the default handler, and thus returns an iterator of all of the
2583 * pads inside the parent element with opposite direction.
2585 * The caller must free this iterator after use with gst_iterator_free().
2587 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2588 * returned pad with gst_object_unref().
2591 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2598 GstElement *eparent;
2600 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2602 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2603 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2605 GST_OBJECT_LOCK (pad);
2606 eparent = GST_PAD_PARENT (pad);
2607 if (!eparent || !GST_IS_ELEMENT (eparent))
2610 gst_object_ref (eparent);
2611 GST_OBJECT_UNLOCK (pad);
2614 if (pad->direction == GST_PAD_SRC)
2615 padlist = &eparent->sinkpads;
2617 padlist = &eparent->srcpads;
2619 GST_DEBUG_OBJECT (pad, "Making iterator");
2621 cookie = &eparent->pads_cookie;
2623 lock = GST_OBJECT_GET_LOCK (eparent);
2625 res = gst_iterator_new_list (GST_TYPE_PAD,
2626 lock, cookie, padlist, (GObject *) owner, NULL);
2628 gst_object_unref (owner);
2635 GST_OBJECT_UNLOCK (pad);
2636 GST_DEBUG_OBJECT (pad, "no parent element");
2642 * gst_pad_iterate_internal_links:
2643 * @pad: the GstPad to get the internal links of.
2645 * Gets an iterator for the pads to which the given pad is linked to inside
2646 * of the parent element.
2648 * Each #GstPad element yielded by the iterator will have its refcount increased,
2649 * so unref after use.
2651 * Free-function: gst_iterator_free
2653 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2654 * pad does not have an iterator function configured. Use
2655 * gst_iterator_free() after usage.
2658 gst_pad_iterate_internal_links (GstPad * pad)
2660 GstIterator *res = NULL;
2663 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2665 GST_OBJECT_LOCK (pad);
2666 ACQUIRE_PARENT (pad, parent, no_parent);
2667 GST_OBJECT_UNLOCK (pad);
2669 if (GST_PAD_ITERINTLINKFUNC (pad))
2670 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2672 RELEASE_PARENT (parent);
2679 GST_DEBUG_OBJECT (pad, "no parent");
2680 GST_OBJECT_UNLOCK (pad);
2688 * @forward: (scope call): a #GstPadForwardFunction
2689 * @user_data: user data passed to @forward
2691 * Calls @forward for all internally linked pads of @pad. This function deals with
2692 * dynamically changing internal pads and will make sure that the @forward
2693 * function is only called once for each pad.
2695 * When @forward returns TRUE, no further pads will be processed.
2697 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2700 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2703 gboolean result = FALSE;
2705 gboolean done = FALSE;
2706 GValue item = { 0, };
2707 GList *pushed_pads = NULL;
2709 iter = gst_pad_iterate_internal_links (pad);
2715 switch (gst_iterator_next (iter, &item)) {
2716 case GST_ITERATOR_OK:
2720 intpad = g_value_get_object (&item);
2722 /* if already pushed, skip. FIXME, find something faster to tag pads */
2723 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2724 g_value_reset (&item);
2728 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2729 GST_DEBUG_PAD_NAME (intpad));
2730 done = result = forward (intpad, user_data);
2732 pushed_pads = g_list_prepend (pushed_pads, intpad);
2734 g_value_reset (&item);
2737 case GST_ITERATOR_RESYNC:
2738 /* We don't reset the result here because we don't push the event
2739 * again on pads that got the event already and because we need
2740 * to consider the result of the previous pushes */
2741 gst_iterator_resync (iter);
2743 case GST_ITERATOR_ERROR:
2744 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2747 case GST_ITERATOR_DONE:
2752 g_value_unset (&item);
2753 gst_iterator_free (iter);
2755 g_list_free (pushed_pads);
2765 gboolean dispatched;
2769 event_forward_func (GstPad * pad, EventData * data)
2771 /* for each pad we send to, we should ref the event; it's up
2772 * to downstream to unref again when handled. */
2773 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2774 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2776 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2778 data->dispatched = TRUE;
2785 * gst_pad_event_default:
2786 * @pad: a #GstPad to call the default event handler on.
2787 * @parent: (allow-none): the parent of @pad or NULL
2788 * @event: (transfer full): the #GstEvent to handle.
2790 * Invokes the default event handler for the given pad.
2792 * The EOS event will pause the task associated with @pad before it is forwarded
2793 * to all internally linked pads,
2795 * The the event is sent to all pads internally linked to @pad. This function
2796 * takes ownership of @event.
2798 * Returns: TRUE if the event was sent successfully.
2801 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2803 gboolean result, forward = TRUE;
2805 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2806 g_return_val_if_fail (event != NULL, FALSE);
2808 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2811 switch (GST_EVENT_TYPE (event)) {
2812 case GST_EVENT_CAPS:
2813 forward = GST_PAD_IS_PROXY_CAPS (pad);
2824 data.dispatched = FALSE;
2825 data.result = FALSE;
2827 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2829 /* for sinkpads without a parent element or without internal links, nothing
2830 * will be dispatched but we still want to return TRUE. */
2831 if (data.dispatched)
2832 result = data.result;
2837 gst_event_unref (event);
2842 /* Default accept caps implementation just checks against
2843 * the allowed caps for the pad */
2845 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2847 /* get the caps and see if it intersects to something not empty */
2848 GstCaps *caps, *allowed;
2851 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2853 /* first forward the query to internally linked pads when we are dealing with
2855 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2856 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2861 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2862 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2864 gst_query_parse_accept_caps (query, &caps);
2865 allowed = gst_pad_query_caps (pad, caps);
2868 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
2869 GST_DEBUG_OBJECT (pad,
2870 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
2872 result = gst_caps_can_intersect (caps, allowed);
2874 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
2875 GST_PTR_FORMAT, allowed, caps);
2876 result = gst_caps_is_subset (caps, allowed);
2878 gst_caps_unref (allowed);
2880 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
2883 gst_query_set_accept_caps_result (query, result);
2889 /* Default caps implementation */
2891 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2893 GstCaps *result = NULL, *filter;
2894 GstPadTemplate *templ;
2895 gboolean fixed_caps;
2897 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2900 /* first try to proxy if we must */
2901 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2902 if ((gst_pad_proxy_query_caps (pad, query))) {
2907 gst_query_parse_caps (query, &filter);
2909 /* no proxy or it failed, do default handling */
2910 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2912 GST_OBJECT_LOCK (pad);
2914 /* fixed caps, try the negotiated caps first */
2915 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2916 if ((result = get_pad_caps (pad)))
2917 goto filter_done_unlock;
2920 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2921 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2922 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2923 goto filter_done_unlock;
2927 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2928 "non-fixed pad caps: trying pad caps");
2929 /* non fixed caps, try the negotiated caps */
2930 if ((result = get_pad_caps (pad)))
2931 goto filter_done_unlock;
2934 /* this almost never happens */
2935 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2936 result = GST_CAPS_ANY;
2939 GST_OBJECT_UNLOCK (pad);
2941 /* run the filter on the result */
2943 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2944 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2945 GST_PTR_FORMAT, result, result, filter, filter);
2946 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2947 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2950 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2951 "using caps %p %" GST_PTR_FORMAT, result, result);
2952 result = gst_caps_ref (result);
2954 gst_query_set_caps_result (query, result);
2955 gst_caps_unref (result);
2965 gboolean dispatched;
2969 query_forward_func (GstPad * pad, QueryData * data)
2971 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
2972 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
2974 data->result |= gst_pad_peer_query (pad, data->query);
2976 data->dispatched = TRUE;
2978 /* stop on first successful reply */
2979 return data->result;
2983 * gst_pad_query_default:
2984 * @pad: a #GstPad to call the default query handler on.
2985 * @parent: (allow-none): the parent of @pad or NULL
2986 * @query: (transfer none): the #GstQuery to handle.
2988 * Invokes the default query handler for the given pad.
2989 * The query is sent to all pads internally linked to @pad. Note that
2990 * if there are many possible sink pads that are internally linked to
2991 * @pad, only one will be sent the query.
2992 * Multi-sinkpad elements should implement custom query handlers.
2994 * Returns: TRUE if the query was performed successfully.
2997 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
2999 gboolean forward, ret = FALSE;
3001 switch (GST_QUERY_TYPE (query)) {
3002 case GST_QUERY_SCHEDULING:
3003 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3005 case GST_QUERY_ALLOCATION:
3006 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3008 case GST_QUERY_ACCEPT_CAPS:
3009 ret = gst_pad_query_accept_caps_default (pad, query);
3012 case GST_QUERY_CAPS:
3013 ret = gst_pad_query_caps_default (pad, query);
3016 case GST_QUERY_POSITION:
3017 case GST_QUERY_SEEKING:
3018 case GST_QUERY_FORMATS:
3019 case GST_QUERY_LATENCY:
3020 case GST_QUERY_JITTER:
3021 case GST_QUERY_RATE:
3022 case GST_QUERY_CONVERT:
3028 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3029 query, GST_QUERY_TYPE_NAME (query));
3035 data.dispatched = FALSE;
3036 data.result = FALSE;
3038 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3040 if (data.dispatched) {
3043 /* nothing dispatched, assume drained */
3044 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3054 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3056 GstPad *pad = data->pad;
3057 GstPadProbeInfo *info = data->info;
3058 GstPadProbeType type, flags;
3059 GstPadProbeCallback callback;
3060 GstPadProbeReturn ret;
3062 /* if we have called this callback, do nothing */
3063 if (PROBE_COOKIE (hook) == data->cookie) {
3064 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3065 "hook %lu, cookie %u already called", hook->hook_id,
3066 PROBE_COOKIE (hook));
3070 PROBE_COOKIE (hook) = data->cookie;
3072 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3075 /* one of the data types for non-idle probes */
3076 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3077 && (flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3079 /* one of the scheduling types */
3080 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3082 /* one of the blocking types must match */
3083 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3084 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3086 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3087 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3089 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3090 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3091 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3094 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3095 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3096 PROBE_COOKIE (hook), flags);
3098 data->marshalled = TRUE;
3100 callback = (GstPadProbeCallback) hook->func;
3101 if (callback == NULL)
3104 info->id = hook->hook_id;
3106 GST_OBJECT_UNLOCK (pad);
3108 ret = callback (pad, info, hook->data);
3110 GST_OBJECT_LOCK (pad);
3113 case GST_PAD_PROBE_REMOVE:
3114 /* remove the probe */
3115 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3116 cleanup_hook (pad, hook);
3118 case GST_PAD_PROBE_DROP:
3119 /* need to drop the data, make sure other probes don't get called
3121 GST_DEBUG_OBJECT (pad, "asked to drop item");
3122 info->type = GST_PAD_PROBE_TYPE_INVALID;
3123 data->dropped = TRUE;
3125 case GST_PAD_PROBE_PASS:
3126 /* inform the pad block to let things pass */
3127 GST_DEBUG_OBJECT (pad, "asked to pass item");
3130 case GST_PAD_PROBE_OK:
3131 GST_DEBUG_OBJECT (pad, "probe returned OK");
3134 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3141 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3142 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3143 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3148 /* a probe that does not take or return any data */
3149 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3151 if (G_UNLIKELY (pad->num_probes)) { \
3152 /* pass NULL as the data item */ \
3153 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3154 ret = do_probe_callbacks (pad, &info, defaultval); \
3155 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3160 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3162 if (G_UNLIKELY (pad->num_probes)) { \
3163 /* pass the data item */ \
3164 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3165 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3166 /* store the possibly updated data item */ \
3167 data = GST_PAD_PROBE_INFO_DATA (&info); \
3168 /* if something went wrong, exit */ \
3169 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3174 #define PROBE_PUSH(pad,mask,data,label) \
3175 PROBE_FULL(pad, mask, data, -1, -1, label);
3176 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3177 PROBE_FULL(pad, mask, data, offs, size, label);
3179 static GstFlowReturn
3180 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3181 GstFlowReturn defaultval)
3190 data.marshalled = FALSE;
3191 data.dropped = FALSE;
3192 data.cookie = ++pad->priv->probe_cookie;
3195 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3198 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3199 "do probes cookie %u", data.cookie);
3200 cookie = pad->priv->probe_list_cookie;
3202 g_hook_list_marshal (&pad->probes, TRUE,
3203 (GHookMarshaller) probe_hook_marshal, &data);
3205 /* if the list changed, call the new callbacks (they will not have their
3206 * cookie set to data.cookie */
3207 if (cookie != pad->priv->probe_list_cookie) {
3208 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3209 "probe list changed, restarting");
3213 /* the first item that dropped will stop the hooks and then we drop here */
3217 /* if no handler matched and we are blocking, let the item pass */
3218 if (!data.marshalled && is_block)
3221 /* At this point, all handlers returned either OK or PASS. If one handler
3222 * returned PASS, let the item pass */
3227 while (GST_PAD_IS_BLOCKED (pad)) {
3228 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3229 "we are blocked %d times", pad->num_blocked);
3231 /* we might have released the lock */
3232 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3235 /* now we block the streaming thread. It can be unlocked when we
3236 * deactivate the pad (which will also set the FLUSHING flag) or
3237 * when the pad is unblocked. A flushing event will also unblock
3238 * the pad after setting the FLUSHING flag. */
3239 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3240 "Waiting to be unblocked or set flushing");
3241 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3242 GST_PAD_BLOCK_WAIT (pad);
3243 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3244 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3246 /* if the list changed, call the new callbacks (they will not have their
3247 * cookie set to data.cookie */
3248 if (cookie != pad->priv->probe_list_cookie) {
3249 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3250 "probe list changed, restarting");
3254 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3264 GST_DEBUG_OBJECT (pad, "pad is flushing");
3265 return GST_FLOW_FLUSHING;
3269 GST_DEBUG_OBJECT (pad, "data is dropped");
3270 return GST_FLOW_CUSTOM_SUCCESS;
3274 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3275 GST_DEBUG_OBJECT (pad, "data is passed");
3283 * gst_pad_get_offset:
3286 * Get the offset applied to the running time of @pad. @pad has to be a source
3289 * Returns: the offset.
3292 gst_pad_get_offset (GstPad * pad)
3296 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3298 GST_OBJECT_LOCK (pad);
3299 result = pad->offset;
3300 GST_OBJECT_UNLOCK (pad);
3306 * gst_pad_set_offset:
3308 * @offset: the offset
3310 * Set the offset that will be applied to the running time of @pad.
3313 gst_pad_set_offset (GstPad * pad, gint64 offset)
3317 g_return_if_fail (GST_IS_PAD (pad));
3319 GST_OBJECT_LOCK (pad);
3320 /* if nothing changed, do nothing */
3321 if (pad->offset == offset)
3324 pad->offset = offset;
3325 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3327 /* sinkpads will apply their offset the next time a segment
3328 * event is received. */
3329 if (GST_PAD_IS_SINK (pad))
3332 /* resend the last segment event on next buffer push */
3333 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3334 ev->received = FALSE;
3335 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3339 GST_OBJECT_UNLOCK (pad);
3346 /* If TRUE and ret is not OK this means
3347 * that pushing the EOS event failed
3351 /* If called for an event this is
3352 * the event that would be pushed
3353 * next. Don't forward sticky events
3354 * that would come after that */
3358 /* should be called with pad LOCK */
3360 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3362 PushStickyData *data = user_data;
3363 GstEvent *event = ev->event;
3366 GST_DEBUG_OBJECT (pad, "event %s was already received",
3367 GST_EVENT_TYPE_NAME (event));
3371 /* If we're called because of an sticky event, only forward
3372 * events that would come before this new event and the
3374 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3375 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3376 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3377 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3379 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3380 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3383 switch (data->ret) {
3385 ev->received = TRUE;
3386 GST_DEBUG_OBJECT (pad, "event %s marked received",
3387 GST_EVENT_TYPE_NAME (event));
3389 case GST_FLOW_CUSTOM_SUCCESS:
3390 /* we can't assume the event is received when it was dropped */
3391 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3392 GST_EVENT_TYPE_NAME (event));
3393 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3394 data->ret = GST_FLOW_OK;
3396 case GST_FLOW_CUSTOM_SUCCESS_1:
3397 /* event was ignored and should be sent later */
3398 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3399 GST_EVENT_TYPE_NAME (event));
3400 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3401 data->ret = GST_FLOW_OK;
3403 case GST_FLOW_NOT_LINKED:
3404 /* not linked is not a problem, we are sticky so the event will be
3405 * sent later but only for non-EOS events */
3406 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3407 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3408 data->ret = GST_FLOW_OK;
3409 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3412 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3413 gst_flow_get_name (data->ret));
3414 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3418 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3419 data->was_eos = TRUE;
3421 return data->ret == GST_FLOW_OK;
3424 /* check sticky events and push them when needed. should be called
3426 static inline GstFlowReturn
3427 check_sticky (GstPad * pad, GstEvent * event)
3429 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3431 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3432 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3434 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3435 events_foreach (pad, push_sticky, &data);
3437 /* If there's an EOS event we must push it downstream
3438 * even if sending a previous sticky event failed.
3439 * Otherwise the pipeline might wait forever for EOS.
3441 * Only do this if pushing another event than the EOS
3444 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3445 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3447 if (ev && !ev->received) {
3448 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3449 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3450 /* the event could have been dropped. Because this can only
3451 * happen if the user asked for it, it's not an error */
3452 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3453 data.ret = GST_FLOW_OK;
3463 * @pad: a #GstPad to invoke the default query on.
3464 * @query: (transfer none): the #GstQuery to perform.
3466 * Dispatches a query to a pad. The query should have been allocated by the
3467 * caller via one of the type-specific allocation functions. The element that
3468 * the pad belongs to is responsible for filling the query with an appropriate
3469 * response, which should then be parsed with a type-specific query parsing
3472 * Again, the caller is responsible for both the allocation and deallocation of
3473 * the query structure.
3475 * Please also note that some queries might need a running pipeline to work.
3477 * Returns: TRUE if the query could be performed.
3480 gst_pad_query (GstPad * pad, GstQuery * query)
3483 gboolean res, serialized;
3484 GstPadQueryFunction func;
3485 GstPadProbeType type;
3488 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3489 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3491 if (GST_PAD_IS_SRC (pad)) {
3492 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3493 goto wrong_direction;
3494 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3495 } else if (GST_PAD_IS_SINK (pad)) {
3496 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3497 goto wrong_direction;
3498 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3500 goto unknown_direction;
3502 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3503 GST_QUERY_TYPE_NAME (query));
3505 serialized = GST_QUERY_IS_SERIALIZED (query);
3506 if (G_UNLIKELY (serialized))
3507 GST_PAD_STREAM_LOCK (pad);
3509 GST_OBJECT_LOCK (pad);
3510 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3511 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3512 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3514 ACQUIRE_PARENT (pad, parent, no_parent);
3515 GST_OBJECT_UNLOCK (pad);
3517 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3520 res = func (pad, parent, query);
3522 RELEASE_PARENT (parent);
3524 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3525 GST_QUERY_TYPE_NAME (query), res);
3530 GST_OBJECT_LOCK (pad);
3531 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3532 GST_OBJECT_UNLOCK (pad);
3534 if (G_UNLIKELY (serialized))
3535 GST_PAD_STREAM_UNLOCK (pad);
3542 g_warning ("pad %s:%s query %s in wrong direction",
3543 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3548 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3553 GST_DEBUG_OBJECT (pad, "had no parent");
3554 GST_OBJECT_UNLOCK (pad);
3555 if (G_UNLIKELY (serialized))
3556 GST_PAD_STREAM_UNLOCK (pad);
3561 GST_DEBUG_OBJECT (pad, "had no query function");
3562 RELEASE_PARENT (parent);
3563 if (G_UNLIKELY (serialized))
3564 GST_PAD_STREAM_UNLOCK (pad);
3569 GST_DEBUG_OBJECT (pad, "query failed");
3570 if (G_UNLIKELY (serialized))
3571 GST_PAD_STREAM_UNLOCK (pad);
3576 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3577 GST_OBJECT_UNLOCK (pad);
3578 if (G_UNLIKELY (serialized))
3579 GST_PAD_STREAM_UNLOCK (pad);
3581 /* if a probe dropped, we don't sent it further but assume that the probe
3582 * answered the query and return TRUE */
3583 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3593 * gst_pad_peer_query:
3594 * @pad: a #GstPad to invoke the peer query on.
3595 * @query: (transfer none): the #GstQuery to perform.
3597 * Performs gst_pad_query() on the peer of @pad.
3599 * The caller is responsible for both the allocation and deallocation of
3600 * the query structure.
3602 * Returns: TRUE if the query could be performed. This function returns %FALSE
3603 * if @pad has no peer.
3606 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3609 GstPadProbeType type;
3610 gboolean res, serialized;
3613 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3614 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3616 if (GST_PAD_IS_SRC (pad)) {
3617 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3618 goto wrong_direction;
3619 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3620 } else if (GST_PAD_IS_SINK (pad)) {
3621 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3622 goto wrong_direction;
3623 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3625 goto unknown_direction;
3627 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3628 GST_QUERY_TYPE_NAME (query));
3630 serialized = GST_QUERY_IS_SERIALIZED (query);
3632 GST_OBJECT_LOCK (pad);
3633 if (GST_PAD_IS_SRC (pad) && serialized) {
3634 /* all serialized queries on the srcpad trigger push of
3636 if (!check_sticky (pad, NULL) == GST_FLOW_OK)
3640 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3641 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3642 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3644 peerpad = GST_PAD_PEER (pad);
3645 if (G_UNLIKELY (peerpad == NULL))
3648 gst_object_ref (peerpad);
3649 GST_OBJECT_UNLOCK (pad);
3651 res = gst_pad_query (peerpad, query);
3653 gst_object_unref (peerpad);
3658 GST_OBJECT_LOCK (pad);
3659 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3660 GST_OBJECT_UNLOCK (pad);
3667 g_warning ("pad %s:%s query %s in wrong direction",
3668 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3673 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3678 GST_WARNING_OBJECT (pad, "could not send sticky events");
3679 GST_OBJECT_UNLOCK (pad);
3684 GST_INFO_OBJECT (pad, "pad has no peer");
3685 GST_OBJECT_UNLOCK (pad);
3690 GST_DEBUG_OBJECT (pad, "query failed");
3695 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3696 GST_OBJECT_UNLOCK (pad);
3698 /* if a probe dropped, we don't sent it further but assume that the probe
3699 * answered the query and return TRUE */
3700 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3709 /**********************************************************************
3710 * Data passing functions
3713 /* this is the chain function that does not perform the additional argument
3714 * checking for that little extra speed.
3716 static inline GstFlowReturn
3717 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3722 GST_PAD_STREAM_LOCK (pad);
3724 GST_OBJECT_LOCK (pad);
3725 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3728 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3731 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3734 #ifndef G_DISABLE_ASSERT
3735 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3736 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3738 ":%s:<%s:%s> Got data flow before stream-start event",
3739 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3741 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3743 ":%s:<%s:%s> Got data flow before segment event",
3744 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3746 pad->priv->last_cookie = pad->priv->events_cookie;
3750 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3752 PROBE_PUSH (pad, type, data, probe_stopped);
3754 parent = GST_OBJECT_PARENT (pad);
3755 GST_OBJECT_UNLOCK (pad);
3757 /* NOTE: we read the chainfunc unlocked.
3758 * we cannot hold the lock for the pad so we might send
3759 * the data to the wrong function. This is not really a
3760 * problem since functions are assigned at creation time
3761 * and don't change that often... */
3762 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3763 GstPadChainFunction chainfunc;
3765 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3768 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3769 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3770 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3772 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3774 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3775 "called chainfunction &%s with buffer %p, returned %s",
3776 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3778 GstPadChainListFunction chainlistfunc;
3780 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3783 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3784 "calling chainlistfunction &%s",
3785 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3787 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3789 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3790 "called chainlistfunction &%s, returned %s",
3791 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3794 GST_PAD_STREAM_UNLOCK (pad);
3801 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3802 "chaining, but pad was flushing");
3803 GST_OBJECT_UNLOCK (pad);
3804 GST_PAD_STREAM_UNLOCK (pad);
3805 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3806 return GST_FLOW_FLUSHING;
3810 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3811 GST_OBJECT_UNLOCK (pad);
3812 GST_PAD_STREAM_UNLOCK (pad);
3813 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3814 return GST_FLOW_EOS;
3818 g_critical ("chain on pad %s:%s but it was not in push mode",
3819 GST_DEBUG_PAD_NAME (pad));
3820 GST_OBJECT_UNLOCK (pad);
3821 GST_PAD_STREAM_UNLOCK (pad);
3822 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3823 return GST_FLOW_ERROR;
3827 GST_OBJECT_UNLOCK (pad);
3828 GST_PAD_STREAM_UNLOCK (pad);
3829 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3832 case GST_FLOW_CUSTOM_SUCCESS:
3833 GST_DEBUG_OBJECT (pad, "dropped buffer");
3837 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
3844 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3845 g_critical ("chain on pad %s:%s but it has no chainfunction",
3846 GST_DEBUG_PAD_NAME (pad));
3847 GST_PAD_STREAM_UNLOCK (pad);
3848 return GST_FLOW_NOT_SUPPORTED;
3854 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3855 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3858 * Chain a buffer to @pad.
3860 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3862 * If the buffer type is not acceptable for @pad (as negotiated with a
3863 * preceding GST_EVENT_CAPS event), this function returns
3864 * #GST_FLOW_NOT_NEGOTIATED.
3866 * The function proceeds calling the chain function installed on @pad (see
3867 * gst_pad_set_chain_function()) and the return value of that function is
3868 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3871 * In all cases, success or failure, the caller loses its reference to @buffer
3872 * after calling this function.
3874 * Returns: a #GstFlowReturn from the pad.
3879 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3881 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3882 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3883 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3885 return gst_pad_chain_data_unchecked (pad,
3886 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3889 static GstFlowReturn
3890 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3891 GstBufferList * list)
3897 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3899 len = gst_buffer_list_length (list);
3902 for (i = 0; i < len; i++) {
3903 buffer = gst_buffer_list_get (list, i);
3905 gst_pad_chain_data_unchecked (pad,
3906 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3907 gst_buffer_ref (buffer));
3908 if (ret != GST_FLOW_OK)
3911 gst_buffer_list_unref (list);
3917 * gst_pad_chain_list:
3918 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3919 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3922 * Chain a bufferlist to @pad.
3924 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3926 * If @pad was not negotiated properly with a CAPS event, this function
3927 * returns #GST_FLOW_NOT_NEGOTIATED.
3929 * The function proceeds calling the chainlist function installed on @pad (see
3930 * gst_pad_set_chain_list_function()) and the return value of that function is
3931 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3932 * chainlist function.
3934 * In all cases, success or failure, the caller loses its reference to @list
3935 * after calling this function.
3939 * Returns: a #GstFlowReturn from the pad.
3942 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3944 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3945 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3946 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3948 return gst_pad_chain_data_unchecked (pad,
3949 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3952 static GstFlowReturn
3953 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3958 GST_OBJECT_LOCK (pad);
3959 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3962 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3965 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3968 #ifndef G_DISABLE_ASSERT
3969 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3970 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3972 ":%s:<%s:%s> Got data flow before stream-start event",
3973 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3975 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3977 ":%s:<%s:%s> Got data flow before segment event",
3978 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3980 pad->priv->last_cookie = pad->priv->events_cookie;
3984 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3987 /* do block probes */
3988 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3990 /* recheck sticky events because the probe might have cause a relink */
3991 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3994 /* do post-blocking probes */
3995 PROBE_PUSH (pad, type, data, probe_stopped);
3997 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4000 /* take ref to peer pad before releasing the lock */
4001 gst_object_ref (peer);
4003 GST_OBJECT_UNLOCK (pad);
4005 ret = gst_pad_chain_data_unchecked (peer, type, data);
4007 gst_object_unref (peer);
4009 GST_OBJECT_LOCK (pad);
4011 if (pad->priv->using == 0) {
4012 /* pad is not active anymore, trigger idle callbacks */
4013 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4014 probe_stopped, ret);
4016 GST_OBJECT_UNLOCK (pad);
4020 /* ERROR recovery here */
4024 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4025 "pushing, but pad was flushing");
4026 GST_OBJECT_UNLOCK (pad);
4027 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4028 return GST_FLOW_FLUSHING;
4032 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4033 GST_OBJECT_UNLOCK (pad);
4034 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4035 return GST_FLOW_EOS;
4039 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4040 GST_DEBUG_PAD_NAME (pad));
4041 GST_OBJECT_UNLOCK (pad);
4042 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4043 return GST_FLOW_ERROR;
4047 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4048 "error pushing events, return %s", gst_flow_get_name (ret));
4049 GST_OBJECT_UNLOCK (pad);
4050 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4055 GST_OBJECT_UNLOCK (pad);
4056 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4059 case GST_FLOW_CUSTOM_SUCCESS:
4060 GST_DEBUG_OBJECT (pad, "dropped buffer");
4064 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4071 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4072 "pushing, but it was not linked");
4073 GST_OBJECT_UNLOCK (pad);
4074 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4075 return GST_FLOW_NOT_LINKED;
4081 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4082 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4085 * Pushes a buffer to the peer of @pad.
4087 * This function will call installed block probes before triggering any
4088 * installed data probes.
4090 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4091 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4094 * In all cases, success or failure, the caller loses its reference to @buffer
4095 * after calling this function.
4097 * Returns: a #GstFlowReturn from the peer pad.
4102 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4104 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4105 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4106 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4108 return gst_pad_push_data (pad,
4109 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4113 * gst_pad_push_list:
4114 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4115 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4118 * Pushes a buffer list to the peer of @pad.
4120 * This function will call installed block probes before triggering any
4121 * installed data probes.
4123 * The function proceeds calling the chain function on the peer pad and returns
4124 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4125 * be returned. If the peer pad does not have any installed chainlist function
4126 * every group buffer of the list will be merged into a normal #GstBuffer and
4127 * chained via gst_pad_chain().
4129 * In all cases, success or failure, the caller loses its reference to @list
4130 * after calling this function.
4132 * Returns: a #GstFlowReturn from the peer pad.
4137 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4139 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4140 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4141 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4143 return gst_pad_push_data (pad,
4144 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4147 static GstFlowReturn
4148 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4149 GstBuffer ** buffer)
4152 GstPadGetRangeFunction getrangefunc;
4156 GST_PAD_STREAM_LOCK (pad);
4158 GST_OBJECT_LOCK (pad);
4159 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4162 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4165 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4170 /* when one of the probes returns DROPPED, probe_stopped will be called
4171 * and we skip calling the getrange function, res_buf should then contain a
4172 * valid result buffer */
4173 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4174 res_buf, offset, size, probe_stopped);
4176 /* recheck sticky events because the probe might have cause a relink */
4177 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4180 ACQUIRE_PARENT (pad, parent, no_parent);
4181 GST_OBJECT_UNLOCK (pad);
4183 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4186 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4187 "calling getrangefunc %s, offset %"
4188 G_GUINT64_FORMAT ", size %u",
4189 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4191 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4193 RELEASE_PARENT (parent);
4195 if (G_UNLIKELY (ret != GST_FLOW_OK))
4196 goto get_range_failed;
4198 /* can only fire the signal if we have a valid buffer */
4199 GST_OBJECT_LOCK (pad);
4201 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4202 res_buf, offset, size, probe_stopped_unref);
4203 GST_OBJECT_UNLOCK (pad);
4205 GST_PAD_STREAM_UNLOCK (pad);
4214 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4215 "getrange, but pad was flushing");
4216 GST_OBJECT_UNLOCK (pad);
4217 GST_PAD_STREAM_UNLOCK (pad);
4218 return GST_FLOW_FLUSHING;
4222 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4223 GST_DEBUG_PAD_NAME (pad));
4224 GST_OBJECT_UNLOCK (pad);
4225 GST_PAD_STREAM_UNLOCK (pad);
4226 return GST_FLOW_ERROR;
4230 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4231 GST_OBJECT_UNLOCK (pad);
4232 GST_PAD_STREAM_UNLOCK (pad);
4237 GST_DEBUG_OBJECT (pad, "no parent");
4238 GST_OBJECT_UNLOCK (pad);
4239 GST_PAD_STREAM_UNLOCK (pad);
4240 return GST_FLOW_FLUSHING;
4244 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4245 GST_DEBUG_PAD_NAME (pad));
4246 RELEASE_PARENT (parent);
4247 GST_PAD_STREAM_UNLOCK (pad);
4248 return GST_FLOW_NOT_SUPPORTED;
4252 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4253 "probe returned %s", gst_flow_get_name (ret));
4254 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4256 /* the probe filled the buffer and asks us to not call the getrange
4257 * anymore, we continue with the post probes then. */
4258 GST_DEBUG_OBJECT (pad, "handled buffer");
4262 /* no buffer, we are EOS */
4263 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4267 GST_OBJECT_UNLOCK (pad);
4268 GST_PAD_STREAM_UNLOCK (pad);
4272 probe_stopped_unref:
4274 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4275 "probe returned %s", gst_flow_get_name (ret));
4276 /* if we drop here, it signals EOS */
4277 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4279 GST_OBJECT_UNLOCK (pad);
4280 GST_PAD_STREAM_UNLOCK (pad);
4281 if (*buffer == NULL)
4282 gst_buffer_unref (res_buf);
4287 GST_PAD_STREAM_UNLOCK (pad);
4288 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4289 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4290 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4296 * gst_pad_get_range:
4297 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4298 * @offset: The start offset of the buffer
4299 * @size: The length of the buffer
4300 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4301 * returns #GST_FLOW_ERROR if %NULL.
4303 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4304 * immediately and @buffer is %NULL.
4306 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4307 * description of a getrange function. If @pad has no getrange function
4308 * installed (see gst_pad_set_getrange_function()) this function returns
4309 * #GST_FLOW_NOT_SUPPORTED.
4311 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4312 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4313 * must be freed with gst_buffer_unref() after usage.
4315 * When @buffer points to a variable that points to a valid #GstBuffer, the
4316 * buffer will be filled with the result data when this function returns
4317 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4318 * @size bytes will be filled in the result buffer and its size will be updated
4321 * Note that less than @size bytes can be returned in @buffer when, for example,
4322 * an EOS condition is near or when @buffer is not large enough to hold @size
4323 * bytes. The caller should check the result buffer size to get the result size.
4325 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4326 * will be unchanged.
4328 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4330 * Returns: a #GstFlowReturn from the pad.
4335 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4336 GstBuffer ** buffer)
4338 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4339 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4340 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4341 g_return_val_if_fail (*buffer == NULL
4342 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4344 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4348 * gst_pad_pull_range:
4349 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4350 * @offset: The start offset of the buffer
4351 * @size: The length of the buffer
4352 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4353 * GST_FLOW_ERROR if %NULL.
4355 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4357 * This function will first trigger the pad block signal if it was
4360 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4361 * function returns the result of gst_pad_get_range() on the peer pad.
4362 * See gst_pad_get_range() for a list of return values and for the
4363 * semantics of the arguments of this function.
4365 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4366 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4367 * must be freed with gst_buffer_unref() after usage. When this function
4368 * returns any other result value, @buffer will still point to NULL.
4370 * When @buffer points to a variable that points to a valid #GstBuffer, the
4371 * buffer will be filled with the result data when this function returns
4372 * #GST_FLOW_OK. When this function returns any other result value,
4373 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4374 * @size bytes will be filled in the result buffer and its size will be updated
4377 * Note that less than @size bytes can be returned in @buffer when, for example,
4378 * an EOS condition is near or when @buffer is not large enough to hold @size
4379 * bytes. The caller should check the result buffer size to get the result size.
4381 * Returns: a #GstFlowReturn from the peer pad.
4386 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4387 GstBuffer ** buffer)
4393 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4394 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4395 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4396 g_return_val_if_fail (*buffer == NULL
4397 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4399 GST_OBJECT_LOCK (pad);
4400 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4403 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4408 /* when one of the probes returns DROPPED, probe_stopped will be
4409 * called and we skip calling the peer getrange function. *buffer should then
4410 * contain a valid buffer */
4411 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4412 res_buf, offset, size, probe_stopped);
4414 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4417 gst_object_ref (peer);
4419 GST_OBJECT_UNLOCK (pad);
4421 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4423 gst_object_unref (peer);
4425 GST_OBJECT_LOCK (pad);
4427 if (pad->priv->using == 0) {
4428 /* pad is not active anymore, trigger idle callbacks */
4429 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4430 probe_stopped_unref, ret);
4433 if (G_UNLIKELY (ret != GST_FLOW_OK))
4434 goto pull_range_failed;
4437 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4438 res_buf, offset, size, probe_stopped_unref);
4440 GST_OBJECT_UNLOCK (pad);
4446 /* ERROR recovery here */
4449 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4450 "pullrange, but pad was flushing");
4451 GST_OBJECT_UNLOCK (pad);
4452 return GST_FLOW_FLUSHING;
4456 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4457 GST_DEBUG_PAD_NAME (pad));
4458 GST_OBJECT_UNLOCK (pad);
4459 return GST_FLOW_ERROR;
4463 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4464 gst_flow_get_name (ret));
4465 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4467 /* the probe filled the buffer and asks us to not forward to the peer
4468 * anymore, we continue with the post probes then */
4469 GST_DEBUG_OBJECT (pad, "handled buffer");
4473 /* no buffer, we are EOS then */
4474 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4478 GST_OBJECT_UNLOCK (pad);
4483 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4484 "pulling range, but it was not linked");
4485 GST_OBJECT_UNLOCK (pad);
4486 return GST_FLOW_NOT_LINKED;
4490 GST_OBJECT_UNLOCK (pad);
4491 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4492 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4493 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4496 probe_stopped_unref:
4498 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4499 "post probe returned %s", gst_flow_get_name (ret));
4500 GST_OBJECT_UNLOCK (pad);
4501 /* if we drop here, it signals EOS */
4502 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4504 if (*buffer == NULL)
4505 gst_buffer_unref (res_buf);
4510 /* must be called with pad object lock */
4511 static GstFlowReturn
4512 store_sticky_event (GstPad * pad, GstEvent * event)
4517 gboolean res = FALSE;
4518 const gchar *name = NULL;
4519 gboolean insert = TRUE;
4521 type = GST_EVENT_TYPE (event);
4523 /* Store all sticky events except SEGMENT/SEGMENT when we're flushing,
4524 * otherwise they can be dropped and nothing would ever resend them.
4525 * Only do that for activated pads though, everything else is a bug!
4527 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4528 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4529 || type == GST_EVENT_EOS))))
4532 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4535 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4536 name = gst_structure_get_name (gst_event_get_structure (event));
4538 events = pad->priv->events;
4541 for (i = 0; i < len; i++) {
4542 PadEvent *ev = &g_array_index (events, PadEvent, i);
4544 if (ev->event == NULL)
4547 if (type == GST_EVENT_TYPE (ev->event)) {
4548 /* matching types, check matching name if needed */
4549 if (name && !gst_event_has_name (ev->event, name))
4553 if ((res = gst_event_replace (&ev->event, event)))
4554 ev->received = FALSE;
4560 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4561 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4562 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4563 * storing the sticky ordered we can check that this is respected. */
4564 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4565 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4567 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4568 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4569 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4570 gst_event_type_get_name (type));
4576 ev.event = gst_event_ref (event);
4577 ev.received = FALSE;
4578 g_array_insert_val (events, i, ev);
4583 pad->priv->events_cookie++;
4584 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4586 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4588 switch (GST_EVENT_TYPE (event)) {
4589 case GST_EVENT_CAPS:
4590 GST_OBJECT_UNLOCK (pad);
4592 GST_DEBUG_OBJECT (pad, "notify caps");
4593 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4595 GST_OBJECT_LOCK (pad);
4601 if (type == GST_EVENT_EOS)
4602 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4604 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4609 GST_DEBUG_OBJECT (pad, "pad is flushing");
4610 return GST_FLOW_FLUSHING;
4614 GST_DEBUG_OBJECT (pad, "pad is EOS");
4615 return GST_FLOW_EOS;
4620 * gst_pad_store_sticky_event:
4622 * @event: a #GstEvent
4624 * Store the sticky @event on @pad
4626 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4627 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4632 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4636 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4637 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4639 GST_OBJECT_LOCK (pad);
4640 ret = store_sticky_event (pad, event);
4641 GST_OBJECT_UNLOCK (pad);
4647 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
4649 PushStickyData *data = user_data;
4651 /* Forward all sticky events before our current one that are pending */
4652 if (ev->event != data->event
4653 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
4654 return push_sticky (pad, ev, data);
4659 /* should be called with pad LOCK */
4660 static GstFlowReturn
4661 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4662 GstPadProbeType type)
4666 GstEventType event_type;
4668 /* Two checks to be made:
4669 * . (un)set the FLUSHING flag for flushing events,
4670 * . handle pad blocking */
4671 event_type = GST_EVENT_TYPE (event);
4672 switch (event_type) {
4673 case GST_EVENT_FLUSH_START:
4674 GST_PAD_SET_FLUSHING (pad);
4676 GST_PAD_BLOCK_BROADCAST (pad);
4677 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4679 case GST_EVENT_FLUSH_STOP:
4680 GST_PAD_UNSET_FLUSHING (pad);
4682 /* Remove sticky EOS events */
4683 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4684 remove_event_by_type (pad, GST_EVENT_EOS);
4685 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4686 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4688 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4692 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4695 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4696 * checked already or this is called as part of pushing sticky events,
4697 * in which case we still want to forward the EOS event downstream.
4700 switch (GST_EVENT_TYPE (event)) {
4701 case GST_EVENT_SEGMENT:
4702 /* pass the adjusted segment event on. We need to do this even if
4703 * there is no peer pad because of the probes. */
4704 event = apply_pad_offset (pad, event);
4706 case GST_EVENT_RECONFIGURE:
4707 if (GST_PAD_IS_SINK (pad))
4708 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4713 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4714 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4719 /* send probes after modifying the events above */
4720 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4722 /* recheck sticky events because the probe might have cause a relink */
4723 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
4724 && (GST_EVENT_IS_SERIALIZED (event)
4725 || GST_EVENT_IS_STICKY (event))) {
4726 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4727 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4729 /* Push all sticky events before our current one
4730 * that have changed */
4731 events_foreach (pad, sticky_changed, &data);
4734 /* now check the peer pad */
4735 peerpad = GST_PAD_PEER (pad);
4736 if (peerpad == NULL)
4739 gst_object_ref (peerpad);
4741 GST_OBJECT_UNLOCK (pad);
4743 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4744 event, GST_EVENT_TYPE_NAME (event), peerpad);
4746 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4748 /* Note: we gave away ownership of the event at this point but we can still
4749 * print the old pointer */
4750 GST_LOG_OBJECT (pad, "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s",
4751 event, peerpad, gst_flow_get_name (ret));
4753 gst_object_unref (peerpad);
4755 GST_OBJECT_LOCK (pad);
4757 if (pad->priv->using == 0) {
4758 /* pad is not active anymore, trigger idle callbacks */
4759 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4760 idle_probe_stopped, ret);
4764 /* ERROR handling */
4767 GST_DEBUG_OBJECT (pad, "We're flushing");
4768 gst_event_unref (event);
4769 return GST_FLOW_FLUSHING;
4773 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4774 gst_event_unref (event);
4777 case GST_FLOW_CUSTOM_SUCCESS:
4778 GST_DEBUG_OBJECT (pad, "dropped event");
4781 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4788 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4789 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4790 gst_event_unref (event);
4792 /* unlinked pads should not influence latency configuration */
4793 if (event_type == GST_EVENT_LATENCY)
4796 return GST_FLOW_NOT_LINKED;
4800 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4806 * gst_pad_push_event:
4807 * @pad: a #GstPad to push the event to.
4808 * @event: (transfer full): the #GstEvent to send to the pad.
4810 * Sends the event to the peer of the given pad. This function is
4811 * mainly used by elements to send events to their peer
4814 * This function takes ownership of the provided event so you should
4815 * gst_event_ref() it if you want to reuse the event after this call.
4817 * Returns: TRUE if the event was handled.
4822 gst_pad_push_event (GstPad * pad, GstEvent * event)
4824 gboolean res = FALSE;
4825 GstPadProbeType type;
4826 gboolean sticky, serialized;
4828 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4829 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4831 if (GST_PAD_IS_SRC (pad)) {
4832 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4833 goto wrong_direction;
4834 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4835 } else if (GST_PAD_IS_SINK (pad)) {
4836 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4837 goto wrong_direction;
4838 /* events pushed on sinkpad never are sticky */
4839 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4841 goto unknown_direction;
4843 GST_OBJECT_LOCK (pad);
4844 sticky = GST_EVENT_IS_STICKY (event);
4845 serialized = GST_EVENT_IS_SERIALIZED (event);
4848 /* srcpad sticky events are stored immediately, the received flag is set
4849 * to FALSE and will be set to TRUE when we can successfully push the
4850 * event to the peer pad */
4851 switch (store_sticky_event (pad, event)) {
4852 case GST_FLOW_FLUSHING:
4860 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4861 /* all serialized or sticky events on the srcpad trigger push of
4863 res = (check_sticky (pad, event) == GST_FLOW_OK);
4868 /* other events are pushed right away */
4869 ret = gst_pad_push_event_unchecked (pad, event, type);
4870 /* dropped events by a probe are not an error */
4871 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4873 /* Errors in sticky event pushing are no problem and ignored here
4874 * as they will cause more meaningful errors during data flow.
4875 * For EOS events, that are not followed by data flow, we still
4876 * return FALSE here though.
4878 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4880 gst_event_unref (event);
4882 GST_OBJECT_UNLOCK (pad);
4886 /* ERROR handling */
4889 g_warning ("pad %s:%s pushing %s event in wrong direction",
4890 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4891 gst_event_unref (event);
4896 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4897 gst_event_unref (event);
4902 GST_DEBUG_OBJECT (pad, "We're flushing");
4903 GST_OBJECT_UNLOCK (pad);
4904 gst_event_unref (event);
4909 GST_DEBUG_OBJECT (pad, "We're EOS");
4910 GST_OBJECT_UNLOCK (pad);
4911 gst_event_unref (event);
4916 /* Check if we can call the event function with the given event */
4917 static GstFlowReturn
4918 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4922 switch (GST_EVENT_TYPE (event)) {
4923 case GST_EVENT_CAPS:
4925 /* backwards compatibility mode for caps */
4926 gst_event_parse_caps (event, &caps);
4928 if (!gst_pad_query_accept_caps (pad, caps))
4940 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4941 "caps %" GST_PTR_FORMAT " not accepted", caps);
4942 return GST_FLOW_NOT_NEGOTIATED;
4946 static GstFlowReturn
4947 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4948 GstPadProbeType type)
4951 GstEventType event_type;
4952 gboolean serialized, need_unlock = FALSE, sticky;
4953 GstPadEventFunction eventfunc;
4956 GST_OBJECT_LOCK (pad);
4957 if (GST_PAD_IS_SINK (pad))
4958 serialized = GST_EVENT_IS_SERIALIZED (event);
4961 sticky = GST_EVENT_IS_STICKY (event);
4962 event_type = GST_EVENT_TYPE (event);
4963 switch (event_type) {
4964 case GST_EVENT_FLUSH_START:
4965 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4966 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4968 /* can't even accept a flush begin event when flushing */
4969 if (GST_PAD_IS_FLUSHING (pad))
4972 GST_PAD_SET_FLUSHING (pad);
4973 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4975 case GST_EVENT_FLUSH_STOP:
4976 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4977 GST_PAD_UNSET_FLUSHING (pad);
4978 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4980 /* Remove pending EOS events */
4981 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
4982 remove_event_by_type (pad, GST_EVENT_EOS);
4983 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4984 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4986 GST_OBJECT_UNLOCK (pad);
4987 /* grab stream lock */
4988 GST_PAD_STREAM_LOCK (pad);
4990 GST_OBJECT_LOCK (pad);
4991 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4994 case GST_EVENT_RECONFIGURE:
4995 if (GST_PAD_IS_SRC (pad))
4996 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4998 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4999 "have event type %" GST_PTR_FORMAT, event);
5001 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5005 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5008 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5009 GST_OBJECT_UNLOCK (pad);
5010 GST_PAD_STREAM_LOCK (pad);
5012 GST_OBJECT_LOCK (pad);
5013 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5016 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5020 switch (GST_EVENT_TYPE (event)) {
5021 case GST_EVENT_SEGMENT:
5022 event = apply_pad_offset (pad, event);
5030 /* now do the probe */
5032 type | GST_PAD_PROBE_TYPE_PUSH |
5033 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5035 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5037 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5040 ACQUIRE_PARENT (pad, parent, no_parent);
5041 GST_OBJECT_UNLOCK (pad);
5043 ret = pre_eventfunc_check (pad, event);
5044 if (G_UNLIKELY (ret != GST_FLOW_OK))
5045 goto precheck_failed;
5048 gst_event_ref (event);
5050 if (eventfunc (pad, parent, event)) {
5053 /* something went wrong */
5054 switch (event_type) {
5055 case GST_EVENT_CAPS:
5056 ret = GST_FLOW_NOT_NEGOTIATED;
5059 ret = GST_FLOW_ERROR;
5063 RELEASE_PARENT (parent);
5065 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5068 if (ret == GST_FLOW_OK) {
5069 GST_OBJECT_LOCK (pad);
5070 /* after the event function accepted the event, we can store the sticky
5071 * event on the pad */
5072 switch (store_sticky_event (pad, event)) {
5073 case GST_FLOW_FLUSHING:
5080 GST_OBJECT_UNLOCK (pad);
5082 gst_event_unref (event);
5086 GST_PAD_STREAM_UNLOCK (pad);
5090 /* ERROR handling */
5093 GST_OBJECT_UNLOCK (pad);
5095 GST_PAD_STREAM_UNLOCK (pad);
5096 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5097 "Received event on flushing pad. Discarding");
5098 gst_event_unref (event);
5099 return GST_FLOW_FLUSHING;
5103 GST_OBJECT_UNLOCK (pad);
5105 GST_PAD_STREAM_UNLOCK (pad);
5106 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5107 "Received event on EOS pad. Discarding");
5108 gst_event_unref (event);
5109 return GST_FLOW_EOS;
5113 GST_OBJECT_UNLOCK (pad);
5115 GST_PAD_STREAM_UNLOCK (pad);
5116 gst_event_unref (event);
5119 case GST_FLOW_CUSTOM_SUCCESS:
5120 GST_DEBUG_OBJECT (pad, "dropped event");
5124 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5131 g_warning ("pad %s:%s has no event handler, file a bug.",
5132 GST_DEBUG_PAD_NAME (pad));
5133 GST_OBJECT_UNLOCK (pad);
5135 GST_PAD_STREAM_UNLOCK (pad);
5136 gst_event_unref (event);
5137 return GST_FLOW_NOT_SUPPORTED;
5141 GST_DEBUG_OBJECT (pad, "no parent");
5142 GST_OBJECT_UNLOCK (pad);
5144 GST_PAD_STREAM_UNLOCK (pad);
5145 gst_event_unref (event);
5146 return GST_FLOW_FLUSHING;
5150 GST_DEBUG_OBJECT (pad, "pre event check failed");
5151 RELEASE_PARENT (parent);
5153 GST_PAD_STREAM_UNLOCK (pad);
5154 gst_event_unref (event);
5160 * gst_pad_send_event:
5161 * @pad: a #GstPad to send the event to.
5162 * @event: (transfer full): the #GstEvent to send to the pad.
5164 * Sends the event to the pad. This function can be used
5165 * by applications to send events in the pipeline.
5167 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5168 * sink pad, @event should be a downstream event. For example, you would not
5169 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5170 * Furthermore, some downstream events have to be serialized with data flow,
5171 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5172 * the event needs to be serialized with data flow, this function will take the
5173 * pad's stream lock while calling its event function.
5175 * To find out whether an event type is upstream, downstream, or downstream and
5176 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5177 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5178 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5179 * plugin doesn't need to bother itself with this information; the core handles
5180 * all necessary locks and checks.
5182 * This function takes ownership of the provided event so you should
5183 * gst_event_ref() it if you want to reuse the event after this call.
5185 * Returns: TRUE if the event was handled.
5188 gst_pad_send_event (GstPad * pad, GstEvent * event)
5191 GstPadProbeType type;
5193 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5194 g_return_val_if_fail (event != NULL, FALSE);
5196 if (GST_PAD_IS_SINK (pad)) {
5197 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5198 goto wrong_direction;
5199 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5200 } else if (GST_PAD_IS_SRC (pad)) {
5201 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5202 goto wrong_direction;
5203 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5205 goto unknown_direction;
5207 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5214 /* ERROR handling */
5217 g_warning ("pad %s:%s sending %s event in wrong direction",
5218 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5219 gst_event_unref (event);
5224 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5225 gst_event_unref (event);
5231 * gst_pad_set_element_private:
5232 * @pad: the #GstPad to set the private data of.
5233 * @priv: The private data to attach to the pad.
5235 * Set the given private data gpointer on the pad.
5236 * This function can only be used by the element that owns the pad.
5237 * No locking is performed in this function.
5240 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5242 pad->element_private = priv;
5246 * gst_pad_get_element_private:
5247 * @pad: the #GstPad to get the private data of.
5249 * Gets the private data of a pad.
5250 * No locking is performed in this function.
5252 * Returns: (transfer none): a #gpointer to the private data.
5255 gst_pad_get_element_private (GstPad * pad)
5257 return pad->element_private;
5261 * gst_pad_get_sticky_event:
5262 * @pad: the #GstPad to get the event from.
5263 * @event_type: the #GstEventType that should be retrieved.
5264 * @idx: the index of the event
5266 * Returns a new reference of the sticky event of type @event_type
5269 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
5270 * event of @event_type was on @pad. Unref after usage.
5273 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5275 GstEvent *event = NULL;
5278 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5279 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5281 GST_OBJECT_LOCK (pad);
5282 ev = find_event_by_type (pad, event_type, idx);
5283 if (ev && (event = ev->event))
5284 gst_event_ref (event);
5285 GST_OBJECT_UNLOCK (pad);
5292 GstPadStickyEventsForeachFunction func;
5297 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5299 ForeachDispatch *data = user_data;
5300 gboolean ret = TRUE;
5303 GST_OBJECT_UNLOCK (pad);
5305 ret = data->func (pad, &ev->event, data->user_data);
5307 GST_OBJECT_LOCK (pad);
5314 * gst_pad_sticky_events_foreach:
5315 * @pad: the #GstPad that should be used for iteration.
5316 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5317 * should be called for every event.
5318 * @user_data: (closure): the optional user data.
5320 * Iterates all sticky events on @pad and calls @foreach_func for every
5321 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5324 gst_pad_sticky_events_foreach (GstPad * pad,
5325 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5327 ForeachDispatch data;
5329 g_return_if_fail (GST_IS_PAD (pad));
5330 g_return_if_fail (foreach_func != NULL);
5332 data.func = foreach_func;
5333 data.user_data = user_data;
5335 GST_OBJECT_LOCK (pad);
5336 events_foreach (pad, foreach_dispatch_function, &data);
5337 GST_OBJECT_UNLOCK (pad);
5341 do_stream_status (GstPad * pad, GstStreamStatusType type,
5342 GThread * thread, GstTask * task)
5346 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5348 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5349 if (GST_IS_ELEMENT (parent)) {
5350 GstMessage *message;
5351 GValue value = { 0 };
5353 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5354 gchar *tname, *ename, *pname;
5356 /* create a good task name */
5357 ename = gst_element_get_name (parent);
5358 pname = gst_pad_get_name (pad);
5359 tname = g_strdup_printf ("%s:%s", ename, pname);
5363 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5367 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5370 g_value_init (&value, GST_TYPE_TASK);
5371 g_value_set_object (&value, task);
5372 gst_message_set_stream_status_object (message, &value);
5373 g_value_unset (&value);
5375 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5376 gst_element_post_message (parent, message);
5378 gst_object_unref (parent);
5383 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5385 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5390 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5392 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5397 * gst_pad_start_task:
5398 * @pad: the #GstPad to start the task of
5399 * @func: the task function to call
5400 * @user_data: user data passed to the task function
5401 * @notify: called when @user_data is no longer referenced
5403 * Starts a task that repeatedly calls @func with @user_data. This function
5404 * is mostly used in pad activation functions to start the dataflow.
5405 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5406 * before @func is called.
5408 * Returns: a %TRUE if the task could be started.
5411 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5412 GDestroyNotify notify)
5417 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5418 g_return_val_if_fail (func != NULL, FALSE);
5420 GST_DEBUG_OBJECT (pad, "start task");
5422 GST_OBJECT_LOCK (pad);
5423 task = GST_PAD_TASK (pad);
5425 task = gst_task_new (func, user_data, notify);
5426 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5427 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5428 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5429 GST_INFO_OBJECT (pad, "created task %p", task);
5430 GST_PAD_TASK (pad) = task;
5431 gst_object_ref (task);
5432 /* release lock to post the message */
5433 GST_OBJECT_UNLOCK (pad);
5435 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5437 gst_object_unref (task);
5439 GST_OBJECT_LOCK (pad);
5440 /* nobody else is supposed to have changed the pad now */
5441 if (GST_PAD_TASK (pad) != task)
5442 goto concurrent_stop;
5444 res = gst_task_set_state (task, GST_TASK_STARTED);
5445 GST_OBJECT_UNLOCK (pad);
5452 GST_OBJECT_UNLOCK (pad);
5458 * gst_pad_pause_task:
5459 * @pad: the #GstPad to pause the task of
5461 * Pause the task of @pad. This function will also wait until the
5462 * function executed by the task is finished if this function is not
5463 * called from the task function.
5465 * Returns: a TRUE if the task could be paused or FALSE when the pad
5469 gst_pad_pause_task (GstPad * pad)
5474 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5476 GST_DEBUG_OBJECT (pad, "pause task");
5478 GST_OBJECT_LOCK (pad);
5479 task = GST_PAD_TASK (pad);
5482 res = gst_task_set_state (task, GST_TASK_PAUSED);
5483 GST_OBJECT_UNLOCK (pad);
5485 /* wait for task function to finish, this lock is recursive so it does nothing
5486 * when the pause is called from the task itself */
5487 GST_PAD_STREAM_LOCK (pad);
5488 GST_PAD_STREAM_UNLOCK (pad);
5494 GST_DEBUG_OBJECT (pad, "pad has no task");
5495 GST_OBJECT_UNLOCK (pad);
5501 * gst_pad_stop_task:
5502 * @pad: the #GstPad to stop the task of
5504 * Stop the task of @pad. This function will also make sure that the
5505 * function executed by the task will effectively stop if not called
5506 * from the GstTaskFunction.
5508 * This function will deadlock if called from the GstTaskFunction of
5509 * the task. Use gst_task_pause() instead.
5511 * Regardless of whether the pad has a task, the stream lock is acquired and
5512 * released so as to ensure that streaming through this pad has finished.
5514 * Returns: a TRUE if the task could be stopped or FALSE on error.
5517 gst_pad_stop_task (GstPad * pad)
5522 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5524 GST_DEBUG_OBJECT (pad, "stop task");
5526 GST_OBJECT_LOCK (pad);
5527 task = GST_PAD_TASK (pad);
5530 GST_PAD_TASK (pad) = NULL;
5531 res = gst_task_set_state (task, GST_TASK_STOPPED);
5532 GST_OBJECT_UNLOCK (pad);
5534 GST_PAD_STREAM_LOCK (pad);
5535 GST_PAD_STREAM_UNLOCK (pad);
5537 if (!gst_task_join (task))
5540 gst_object_unref (task);
5546 GST_DEBUG_OBJECT (pad, "no task");
5547 GST_OBJECT_UNLOCK (pad);
5549 GST_PAD_STREAM_LOCK (pad);
5550 GST_PAD_STREAM_UNLOCK (pad);
5552 /* this is not an error */
5557 /* this is bad, possibly the application tried to join the task from
5558 * the task's thread. We install the task again so that it will be stopped
5559 * again from the right thread next time hopefully. */
5560 GST_OBJECT_LOCK (pad);
5561 GST_DEBUG_OBJECT (pad, "join failed");
5562 /* we can only install this task if there was no other task */
5563 if (GST_PAD_TASK (pad) == NULL)
5564 GST_PAD_TASK (pad) = task;
5565 GST_OBJECT_UNLOCK (pad);
5572 * gst_pad_probe_info_get_event:
5573 * @info: a #GstPadProbeInfo
5575 * Returns: (transfer none): The #GstEvent from the probe
5579 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5581 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5582 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5584 return GST_PAD_PROBE_INFO_EVENT (info);
5589 * gst_pad_probe_info_get_query:
5590 * @info: a #GstPadProbeInfo
5592 * Returns: (transfer none): The #GstQuery from the probe
5596 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5598 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5599 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5601 return GST_PAD_PROBE_INFO_QUERY (info);
5605 * gst_pad_probe_info_get_buffer:
5606 * @info: a #GstPadProbeInfo
5608 * Returns: (transfer none): The #GstBuffer from the probe
5612 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5614 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5616 return GST_PAD_PROBE_INFO_BUFFER (info);
5620 * gst_pad_probe_info_get_bufferlist:
5621 * @info: a #GstPadProbeInfo
5623 * Returns: (transfer none): The #GstBufferlist from the probe
5627 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5629 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5631 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);