2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 * @short_description: Object contained by elements that allows links to
26 * @see_also: #GstPadTemplate, #GstElement, #GstEvent, #GstQuery, #GstBuffer
28 * A #GstElement is linked to other elements via "pads", which are extremely
29 * light-weight generic link points.
31 * Pads have a #GstPadDirection, source pads produce data, sink pads consume
34 * Pads are typically created from a #GstPadTemplate with
35 * gst_pad_new_from_template() and are then added to a #GstElement. This usually
36 * happens when the element is created but it can also happen dynamically based
37 * on the data that the element is processing or based on the pads that the
38 * application requests.
40 * Pads without pad templates can be created with gst_pad_new(),
41 * which takes a direction and a name as an argument. If the name is NULL,
42 * then a guaranteed unique name will be assigned to it.
44 * A #GstElement creating a pad will typically use the various
45 * gst_pad_set_*_function() calls to register callbacks for events, queries or
46 * dataflow on the pads.
48 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
50 * After two pads are retrieved from an element by gst_element_get_static_pad(),
51 * the pads can be linked with gst_pad_link(). (For quick links,
52 * you can also use gst_element_link(), which will make the obvious
53 * link for you if it's straightforward.). Pads can be unlinked again with
54 * gst_pad_unlink(). gst_pad_get_peer() can be used to check what the pad is
57 * Before dataflow is possible on the pads, they need to be activated with
58 * gst_pad_set_active().
60 * gst_pad_query() and gst_pad_peer_query() can be used to query various
61 * properties of the pad and the stream.
63 * To send a #GstEvent on a pad, use gst_pad_send_event() and
64 * gst_pad_push_event(). Some events will be sticky on the pad, meaning that
65 * after they pass on the pad they can be queried later with
66 * gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().
67 * gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience
68 * functions to query the current sticky CAPS event on a pad.
70 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
71 * or pull in a buffer.
73 * The dataflow, events and queries that happen on a pad can be monitored with
74 * probes that can be installed with gst_pad_add_probe(). gst_pad_is_blocked()
75 * can be used to check if a block probe is installed on the pad.
76 * gst_pad_is_blocking() checks if the blocking probe is currently blocking the
77 * pad. gst_pad_remove_probe() is used to remove a previously installed probe
78 * and unblock blocking probes if any.
80 * Pad have an offset that can be retrieved with gst_pad_get_offset(). This
81 * offset will be applied to the running_time of all data passing over the pad.
82 * gst_pad_set_offset() can be used to change the offset.
84 * Convenience functions exist to start, pause and stop the task on a pad with
85 * gst_pad_start_task(), gst_pad_pause_task() and gst_pad_stop_task()
88 * Last reviewed on 2012-03-29 (0.11.3)
91 #include "gst_private.h"
94 #include "gstpadtemplate.h"
95 #include "gstenumtypes.h"
100 #include "glib-compat-private.h"
102 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
103 #define GST_CAT_DEFAULT GST_CAT_PADS
105 /* Pad signals and args */
123 #define GST_PAD_GET_PRIVATE(obj) \
124 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
126 /* we have a pending and an active event on the pad. On source pads only the
127 * active event is used. On sinkpads, events are copied to the pending entry and
128 * moved to the active event when the eventfunc returned TRUE. */
135 struct _GstPadPrivate
142 guint probe_list_cookie;
152 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
157 GstPadProbeInfo *info;
164 static void gst_pad_dispose (GObject * object);
165 static void gst_pad_finalize (GObject * object);
166 static void gst_pad_set_property (GObject * object, guint prop_id,
167 const GValue * value, GParamSpec * pspec);
168 static void gst_pad_get_property (GObject * object, guint prop_id,
169 GValue * value, GParamSpec * pspec);
171 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
172 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
173 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
174 GstObject * parent, GstBufferList * list);
176 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
177 GstEvent * event, GstPadProbeType type);
178 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
179 GstEvent * event, GstPadProbeType type);
181 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
183 static GParamSpec *pspec_caps = NULL;
185 /* quarks for probe signals */
186 static GQuark buffer_quark;
187 static GQuark buffer_list_quark;
188 static GQuark event_quark;
197 static GstFlowQuarks flow_quarks[] = {
198 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
199 {GST_FLOW_OK, "ok", 0},
200 {GST_FLOW_NOT_LINKED, "not-linked", 0},
201 {GST_FLOW_FLUSHING, "flushing", 0},
202 {GST_FLOW_EOS, "eos", 0},
203 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
204 {GST_FLOW_ERROR, "error", 0},
205 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
206 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
211 * @ret: a #GstFlowReturn to get the name of.
213 * Gets a string representing the given flow return.
215 * Returns: a static string with the name of the flow return.
218 gst_flow_get_name (GstFlowReturn ret)
222 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
224 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
225 if (ret == flow_quarks[i].ret)
226 return flow_quarks[i].name;
233 * @ret: a #GstFlowReturn to get the quark of.
235 * Get the unique quark for the given GstFlowReturn.
237 * Returns: the quark associated with the flow return or 0 if an
238 * invalid return was specified.
241 gst_flow_to_quark (GstFlowReturn ret)
245 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
247 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
248 if (ret == flow_quarks[i].ret)
249 return flow_quarks[i].quark;
258 buffer_quark = g_quark_from_static_string ("buffer"); \
259 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
260 event_quark = g_quark_from_static_string ("event"); \
262 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
263 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
266 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
267 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
270 #define gst_pad_parent_class parent_class
271 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
274 gst_pad_class_init (GstPadClass * klass)
276 GObjectClass *gobject_class;
277 GstObjectClass *gstobject_class;
279 gobject_class = G_OBJECT_CLASS (klass);
280 gstobject_class = GST_OBJECT_CLASS (klass);
282 g_type_class_add_private (klass, sizeof (GstPadPrivate));
284 gobject_class->dispose = gst_pad_dispose;
285 gobject_class->finalize = gst_pad_finalize;
286 gobject_class->set_property = gst_pad_set_property;
287 gobject_class->get_property = gst_pad_get_property;
291 * @pad: the pad that emitted the signal
292 * @peer: the peer pad that has been connected
294 * Signals that a pad has been linked to the peer pad.
296 gst_pad_signals[PAD_LINKED] =
297 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
298 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
299 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
302 * @pad: the pad that emitted the signal
303 * @peer: the peer pad that has been disconnected
305 * Signals that a pad has been unlinked from the peer pad.
307 gst_pad_signals[PAD_UNLINKED] =
308 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
309 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
310 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
312 pspec_caps = g_param_spec_boxed ("caps", "Caps",
313 "The capabilities of the pad", GST_TYPE_CAPS,
314 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
315 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
317 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
318 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
319 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
320 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
322 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
323 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
324 g_param_spec_object ("template", "Template",
325 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
326 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
328 gstobject_class->path_string_separator = ".";
330 /* Register common function pointer descriptions */
331 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
332 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
333 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
334 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
335 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
339 gst_pad_init (GstPad * pad)
341 pad->priv = GST_PAD_GET_PRIVATE (pad);
343 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
345 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
346 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
347 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
348 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
349 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
351 GST_PAD_SET_FLUSHING (pad);
353 g_rec_mutex_init (&pad->stream_rec_lock);
355 g_cond_init (&pad->block_cond);
357 g_hook_list_init (&pad->probes, sizeof (GstProbe));
359 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
360 pad->priv->events_cookie = 0;
361 pad->priv->last_cookie = -1;
364 /* called when setting the pad inactive. It removes all sticky events from
365 * the pad. must be called with object lock */
367 remove_events (GstPad * pad)
372 events = pad->priv->events;
375 for (i = 0; i < len; i++) {
376 PadEvent *ev = &g_array_index (events, PadEvent, i);
377 GstEvent *event = ev->event;
381 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS) {
382 GST_OBJECT_UNLOCK (pad);
384 GST_DEBUG_OBJECT (pad, "notify caps");
385 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
387 GST_OBJECT_LOCK (pad);
389 gst_event_unref (event);
391 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
392 g_array_set_size (events, 0);
393 pad->priv->events_cookie++;
396 /* should be called with object lock */
398 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
404 events = pad->priv->events;
407 for (i = 0; i < len; i++) {
408 ev = &g_array_index (events, PadEvent, i);
409 if (ev->event == NULL)
412 if (GST_EVENT_TYPE (ev->event) == type) {
423 /* should be called with OBJECT lock */
425 find_event (GstPad * pad, GstEvent * event)
431 events = pad->priv->events;
434 for (i = 0; i < len; i++) {
435 ev = &g_array_index (events, PadEvent, i);
436 if (event == ev->event)
444 /* should be called with OBJECT lock */
446 remove_event_by_type (GstPad * pad, GstEventType type)
452 events = pad->priv->events;
457 ev = &g_array_index (events, PadEvent, i);
458 if (ev->event == NULL)
461 if (GST_EVENT_TYPE (ev->event) != type)
464 gst_event_unref (ev->event);
465 g_array_remove_index (events, i);
467 pad->priv->events_cookie++;
475 /* check all events on srcpad against those on sinkpad. All events that are not
476 * on sinkpad are marked as received=FALSE and the PENDING_EVENTS is set on the
477 * srcpad so that the events will be sent next time */
478 /* should be called with srcpad and sinkpad LOCKS */
480 schedule_events (GstPad * srcpad, GstPad * sinkpad)
485 gboolean pending = FALSE;
487 events = srcpad->priv->events;
490 for (i = 0; i < len; i++) {
491 ev = &g_array_index (events, PadEvent, i);
492 if (ev->event == NULL)
495 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
496 ev->received = FALSE;
501 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
504 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
507 /* should be called with pad LOCK */
509 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
516 events = pad->priv->events;
519 cookie = pad->priv->events_cookie;
523 PadEvent *ev, ev_ret;
525 ev = &g_array_index (events, PadEvent, i);
526 if (G_UNLIKELY (ev->event == NULL))
529 /* take aditional ref, func might release the lock */
530 ev_ret.event = gst_event_ref (ev->event);
531 ev_ret.received = ev->received;
533 ret = func (pad, &ev_ret, user_data);
535 /* recheck the cookie, lock might have been released and the list could have
537 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
538 if (G_LIKELY (ev_ret.event))
539 gst_event_unref (ev_ret.event);
543 /* store the received state */
544 ev->received = ev_ret.received;
546 /* if the event changed, we need to do something */
547 if (G_UNLIKELY (ev->event != ev_ret.event)) {
548 if (G_UNLIKELY (ev_ret.event == NULL)) {
549 /* function unreffed and set the event to NULL, remove it */
550 g_array_remove_index (events, i);
552 cookie = ++pad->priv->events_cookie;
555 /* function gave a new event for us */
556 gst_event_take (&ev->event, ev_ret.event);
559 /* just unref, nothing changed */
560 gst_event_unref (ev_ret.event);
569 /* should be called with LOCK */
571 apply_pad_offset (GstPad * pad, GstEvent * event)
573 /* check if we need to adjust the segment */
574 if (pad->offset != 0) {
577 /* copy segment values */
578 gst_event_copy_segment (event, &segment);
579 gst_event_unref (event);
581 /* adjust and make a new event with the offset applied */
582 segment.base += pad->offset;
583 event = gst_event_new_segment (&segment);
588 /* should be called with the OBJECT_LOCK */
590 get_pad_caps (GstPad * pad)
592 GstCaps *caps = NULL;
595 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
597 gst_event_parse_caps (ev->event, &caps);
603 gst_pad_dispose (GObject * object)
605 GstPad *pad = GST_PAD_CAST (object);
608 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
610 /* unlink the peer pad */
611 if ((peer = gst_pad_get_peer (pad))) {
612 /* window for MT unsafeness, someone else could unlink here
613 * and then we call unlink with wrong pads. The unlink
614 * function would catch this and safely return failed. */
615 if (GST_PAD_IS_SRC (pad))
616 gst_pad_unlink (pad, peer);
618 gst_pad_unlink (peer, pad);
620 gst_object_unref (peer);
623 gst_pad_set_pad_template (pad, NULL);
625 GST_OBJECT_LOCK (pad);
627 GST_OBJECT_UNLOCK (pad);
629 g_hook_list_clear (&pad->probes);
631 G_OBJECT_CLASS (parent_class)->dispose (object);
635 gst_pad_finalize (GObject * object)
637 GstPad *pad = GST_PAD_CAST (object);
640 /* in case the task is still around, clean it up */
641 if ((task = GST_PAD_TASK (pad))) {
642 gst_task_join (task);
643 GST_PAD_TASK (pad) = NULL;
644 gst_object_unref (task);
647 if (pad->activatenotify)
648 pad->activatenotify (pad->activatedata);
649 if (pad->activatemodenotify)
650 pad->activatemodenotify (pad->activatemodedata);
652 pad->linknotify (pad->linkdata);
653 if (pad->unlinknotify)
654 pad->unlinknotify (pad->unlinkdata);
655 if (pad->chainnotify)
656 pad->chainnotify (pad->chaindata);
657 if (pad->chainlistnotify)
658 pad->chainlistnotify (pad->chainlistdata);
659 if (pad->getrangenotify)
660 pad->getrangenotify (pad->getrangedata);
661 if (pad->eventnotify)
662 pad->eventnotify (pad->eventdata);
663 if (pad->querynotify)
664 pad->querynotify (pad->querydata);
665 if (pad->iterintlinknotify)
666 pad->iterintlinknotify (pad->iterintlinkdata);
668 g_rec_mutex_clear (&pad->stream_rec_lock);
669 g_cond_clear (&pad->block_cond);
670 g_array_free (pad->priv->events, TRUE);
672 G_OBJECT_CLASS (parent_class)->finalize (object);
676 gst_pad_set_property (GObject * object, guint prop_id,
677 const GValue * value, GParamSpec * pspec)
679 g_return_if_fail (GST_IS_PAD (object));
682 case PAD_PROP_DIRECTION:
683 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
685 case PAD_PROP_TEMPLATE:
686 gst_pad_set_pad_template (GST_PAD_CAST (object),
687 (GstPadTemplate *) g_value_get_object (value));
690 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
696 gst_pad_get_property (GObject * object, guint prop_id,
697 GValue * value, GParamSpec * pspec)
699 g_return_if_fail (GST_IS_PAD (object));
703 GST_OBJECT_LOCK (object);
704 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
705 GST_OBJECT_UNLOCK (object);
707 case PAD_PROP_DIRECTION:
708 g_value_set_enum (value, GST_PAD_DIRECTION (object));
710 case PAD_PROP_TEMPLATE:
711 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
714 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
721 * @name: the name of the new pad.
722 * @direction: the #GstPadDirection of the pad.
724 * Creates a new pad with the given name in the given direction.
725 * If name is NULL, a guaranteed unique name (across all pads)
727 * This function makes a copy of the name so you can safely free the name.
729 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
734 gst_pad_new (const gchar * name, GstPadDirection direction)
736 return g_object_new (GST_TYPE_PAD,
737 "name", name, "direction", direction, NULL);
741 * gst_pad_new_from_template:
742 * @templ: the pad template to use
743 * @name: the name of the element
745 * Creates a new pad with the given name from the given template.
746 * If name is NULL, a guaranteed unique name (across all pads)
748 * This function makes a copy of the name so you can safely free the name.
750 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
753 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
755 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
757 return g_object_new (GST_TYPE_PAD,
758 "name", name, "direction", templ->direction, "template", templ, NULL);
762 * gst_pad_new_from_static_template:
763 * @templ: the #GstStaticPadTemplate to use
764 * @name: the name of the element
766 * Creates a new pad with the given name from the given static template.
767 * If name is NULL, a guaranteed unique name (across all pads)
769 * This function makes a copy of the name so you can safely free the name.
771 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
774 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
778 GstPadTemplate *template;
780 template = gst_static_pad_template_get (templ);
781 pad = gst_pad_new_from_template (template, name);
782 gst_object_unref (template);
786 #define ACQUIRE_PARENT(pad, parent, label) \
788 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
789 gst_object_ref (parent); \
790 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
794 #define RELEASE_PARENT(parent) \
796 if (G_LIKELY (parent)) \
797 gst_object_unref (parent); \
801 * gst_pad_get_direction:
802 * @pad: a #GstPad to get the direction of.
804 * Gets the direction of the pad. The direction of the pad is
805 * decided at construction time so this function does not take
808 * Returns: the #GstPadDirection of the pad.
813 gst_pad_get_direction (GstPad * pad)
815 GstPadDirection result;
817 /* PAD_UNKNOWN is a little silly but we need some sort of
818 * error return value */
819 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
821 result = GST_PAD_DIRECTION (pad);
827 gst_pad_activate_default (GstPad * pad, GstObject * parent)
829 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
833 * gst_pad_mode_get_name:
834 * @mode: the pad mode
836 * Return the name of a pad mode, for use in debug messages mostly.
838 * Returns: short mnemonic for pad mode @mode
841 gst_pad_mode_get_name (GstPadMode mode)
844 case GST_PAD_MODE_NONE:
846 case GST_PAD_MODE_PUSH:
848 case GST_PAD_MODE_PULL:
857 pre_activate (GstPad * pad, GstPadMode new_mode)
860 case GST_PAD_MODE_NONE:
861 GST_OBJECT_LOCK (pad);
862 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
863 GST_PAD_SET_FLUSHING (pad);
864 GST_PAD_MODE (pad) = new_mode;
865 /* unlock blocked pads so element can resume and stop */
866 GST_PAD_BLOCK_BROADCAST (pad);
867 GST_OBJECT_UNLOCK (pad);
869 case GST_PAD_MODE_PUSH:
870 case GST_PAD_MODE_PULL:
871 GST_OBJECT_LOCK (pad);
872 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
873 gst_pad_mode_get_name (new_mode));
874 GST_PAD_UNSET_FLUSHING (pad);
875 GST_PAD_MODE (pad) = new_mode;
876 if (GST_PAD_IS_SINK (pad)) {
878 /* make sure the peer src pad sends us all events */
879 if ((peer = GST_PAD_PEER (pad))) {
880 gst_object_ref (peer);
881 GST_OBJECT_UNLOCK (pad);
883 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
884 GST_DEBUG_PAD_NAME (peer));
886 GST_OBJECT_LOCK (peer);
887 schedule_events (peer, NULL);
888 GST_OBJECT_UNLOCK (peer);
890 gst_object_unref (peer);
892 GST_OBJECT_UNLOCK (pad);
895 GST_OBJECT_UNLOCK (pad);
902 post_activate (GstPad * pad, GstPadMode new_mode)
905 case GST_PAD_MODE_NONE:
906 /* ensures that streaming stops */
907 GST_PAD_STREAM_LOCK (pad);
908 GST_DEBUG_OBJECT (pad, "stopped streaming");
909 GST_OBJECT_LOCK (pad);
911 GST_OBJECT_UNLOCK (pad);
912 GST_PAD_STREAM_UNLOCK (pad);
914 case GST_PAD_MODE_PUSH:
915 case GST_PAD_MODE_PULL:
922 * gst_pad_set_active:
923 * @pad: the #GstPad to activate or deactivate.
924 * @active: whether or not the pad should be active.
926 * Activates or deactivates the given pad.
927 * Normally called from within core state change functions.
929 * If @active, makes sure the pad is active. If it is already active, either in
930 * push or pull mode, just return. Otherwise dispatches to the pad's activate
931 * function to perform the actual activation.
933 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
934 * and a FALSE argument.
936 * Returns: #TRUE if the operation was successful.
941 gst_pad_set_active (GstPad * pad, gboolean active)
945 gboolean ret = FALSE;
947 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
949 GST_OBJECT_LOCK (pad);
950 old = GST_PAD_MODE (pad);
951 ACQUIRE_PARENT (pad, parent, no_parent);
952 GST_OBJECT_UNLOCK (pad);
955 if (old == GST_PAD_MODE_NONE) {
956 GST_DEBUG_OBJECT (pad, "activating pad from none");
957 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
959 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
960 gst_pad_mode_get_name (old));
964 if (old == GST_PAD_MODE_NONE) {
965 GST_DEBUG_OBJECT (pad, "pad was inactive");
968 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
969 gst_pad_mode_get_name (old));
970 ret = gst_pad_activate_mode (pad, old, FALSE);
974 RELEASE_PARENT (parent);
976 if (G_UNLIKELY (!ret))
984 GST_DEBUG_OBJECT (pad, "no parent");
985 GST_OBJECT_UNLOCK (pad);
990 GST_OBJECT_LOCK (pad);
992 g_critical ("Failed to deactivate pad %s:%s, very bad",
993 GST_DEBUG_PAD_NAME (pad));
995 GST_WARNING_OBJECT (pad, "Failed to activate pad");
997 GST_OBJECT_UNLOCK (pad);
1003 * gst_pad_activate_mode:
1004 * @pad: the #GstPad to activate or deactivate.
1005 * @mode: the requested activation mode
1006 * @active: whether or not the pad should be active.
1008 * Activates or deactivates the given pad in @mode via dispatching to the
1009 * pad's activatemodefunc. For use from within pad activation functions only.
1011 * If you don't know what this is, you probably don't want to call it.
1013 * Returns: TRUE if the operation was successful.
1018 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1020 gboolean res = FALSE;
1022 GstPadMode old, new;
1023 GstPadDirection dir;
1026 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1028 GST_OBJECT_LOCK (pad);
1029 old = GST_PAD_MODE (pad);
1030 dir = GST_PAD_DIRECTION (pad);
1031 ACQUIRE_PARENT (pad, parent, no_parent);
1032 GST_OBJECT_UNLOCK (pad);
1034 new = active ? mode : GST_PAD_MODE_NONE;
1039 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1040 /* pad was activate in the wrong direction, deactivate it
1041 * and reactivate it in the requested mode */
1042 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1043 gst_pad_mode_get_name (old));
1045 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1046 goto deactivate_failed;
1050 case GST_PAD_MODE_PULL:
1052 if (dir == GST_PAD_SINK) {
1053 if ((peer = gst_pad_get_peer (pad))) {
1054 GST_DEBUG_OBJECT (pad, "calling peer");
1055 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1057 gst_object_unref (peer);
1059 /* there is no peer, this is only fatal when we activate. When we
1060 * deactivate, we must assume the application has unlinked the peer and
1061 * will deactivate it eventually. */
1065 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1068 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1069 goto failure; /* Can't activate pull on a src without a
1070 getrange function */
1078 /* Mark pad as needing reconfiguration */
1080 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1081 pre_activate (pad, new);
1083 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1084 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1088 /* can happen for sinks of passthrough elements */
1091 post_activate (pad, new);
1093 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1094 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1099 /* Clear sticky flags on deactivation */
1101 GST_OBJECT_LOCK (pad);
1102 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1103 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1104 GST_OBJECT_UNLOCK (pad);
1108 RELEASE_PARENT (parent);
1114 GST_DEBUG_OBJECT (pad, "no parent");
1115 GST_OBJECT_UNLOCK (pad);
1120 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1121 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1126 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1127 "failed to %s in switch to %s mode from %s mode",
1128 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1129 gst_pad_mode_get_name (old));
1134 GST_OBJECT_LOCK (peer);
1135 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1136 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1137 GST_OBJECT_UNLOCK (peer);
1138 gst_object_unref (peer);
1143 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1144 "pad in pull mode");
1149 GST_OBJECT_LOCK (pad);
1150 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1151 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1152 GST_PAD_SET_FLUSHING (pad);
1153 GST_PAD_MODE (pad) = old;
1154 GST_OBJECT_UNLOCK (pad);
1160 * gst_pad_is_active:
1161 * @pad: the #GstPad to query
1163 * Query if a pad is active
1165 * Returns: TRUE if the pad is active.
1170 gst_pad_is_active (GstPad * pad)
1172 gboolean result = FALSE;
1174 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1176 GST_OBJECT_LOCK (pad);
1177 result = GST_PAD_IS_ACTIVE (pad);
1178 GST_OBJECT_UNLOCK (pad);
1184 cleanup_hook (GstPad * pad, GHook * hook)
1186 GstPadProbeType type;
1188 if (!G_HOOK_IS_VALID (hook))
1191 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1193 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1194 /* unblock when we remove the last blocking probe */
1196 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1198 if (pad->num_blocked == 0) {
1199 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1200 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1201 GST_PAD_BLOCK_BROADCAST (pad);
1204 g_hook_destroy_link (&pad->probes, hook);
1209 * gst_pad_add_probe:
1210 * @pad: the #GstPad to add the probe to
1211 * @mask: the probe mask
1212 * @callback: #GstPadProbeCallback that will be called with notifications of
1214 * @user_data: (closure): user data passed to the callback
1215 * @destroy_data: #GDestroyNotify for user_data
1217 * Be notified of different states of pads. The provided callback is called for
1218 * every state that matches @mask.
1220 * Returns: an id or 0 on error. The id can be used to remove the probe with
1221 * gst_pad_remove_probe().
1226 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1227 GstPadProbeCallback callback, gpointer user_data,
1228 GDestroyNotify destroy_data)
1233 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1234 g_return_val_if_fail (mask != 0, 0);
1236 GST_OBJECT_LOCK (pad);
1238 /* make a new probe */
1239 hook = g_hook_alloc (&pad->probes);
1241 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1244 /* when no contraints are given for the types, assume all types are
1246 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1247 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1248 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1249 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1251 /* store our flags and other fields */
1252 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1253 hook->func = callback;
1254 hook->data = user_data;
1255 hook->destroy = destroy_data;
1256 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1259 g_hook_prepend (&pad->probes, hook);
1261 /* incremenent cookie so that the new hook get's called */
1262 pad->priv->probe_list_cookie++;
1264 /* get the id of the hook, we return this and it can be used to remove the
1266 res = hook->hook_id;
1268 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1270 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1271 /* we have a block probe */
1273 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1274 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1275 "now %d blocking probes", pad->num_blocked);
1278 /* call the callback if we need to be called for idle callbacks */
1279 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1280 if (pad->priv->using > 0) {
1281 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1282 * flag above, the last thread to leave the push will do the callback. New
1283 * threads going into the push will block. */
1284 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1285 "pad is in use, delay idle callback");
1286 GST_OBJECT_UNLOCK (pad);
1288 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1289 GstPadProbeReturn ret;
1291 /* the pad is idle now, we can signal the idle callback now */
1292 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1293 "pad is idle, trigger idle callback");
1294 GST_OBJECT_UNLOCK (pad);
1296 ret = callback (pad, &info, user_data);
1298 GST_OBJECT_LOCK (pad);
1300 case GST_PAD_PROBE_REMOVE:
1301 /* remove the probe */
1302 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1303 cleanup_hook (pad, hook);
1306 case GST_PAD_PROBE_DROP:
1307 GST_DEBUG_OBJECT (pad, "asked to drop item");
1309 case GST_PAD_PROBE_PASS:
1310 GST_DEBUG_OBJECT (pad, "asked to pass item");
1312 case GST_PAD_PROBE_OK:
1313 GST_DEBUG_OBJECT (pad, "probe returned OK");
1316 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1319 GST_OBJECT_UNLOCK (pad);
1322 GST_OBJECT_UNLOCK (pad);
1328 * gst_pad_remove_probe:
1329 * @pad: the #GstPad with the probe
1330 * @id: the probe id to remove
1332 * Remove the probe with @id from @pad.
1337 gst_pad_remove_probe (GstPad * pad, gulong id)
1341 g_return_if_fail (GST_IS_PAD (pad));
1343 GST_OBJECT_LOCK (pad);
1345 hook = g_hook_get (&pad->probes, id);
1349 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1351 cleanup_hook (pad, hook);
1352 GST_OBJECT_UNLOCK (pad);
1358 GST_OBJECT_UNLOCK (pad);
1359 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1365 * gst_pad_is_blocked:
1366 * @pad: the #GstPad to query
1368 * Checks if the pad is blocked or not. This function returns the
1369 * last requested state of the pad. It is not certain that the pad
1370 * is actually blocking at this point (see gst_pad_is_blocking()).
1372 * Returns: TRUE if the pad is blocked.
1377 gst_pad_is_blocked (GstPad * pad)
1379 gboolean result = FALSE;
1381 g_return_val_if_fail (GST_IS_PAD (pad), result);
1383 GST_OBJECT_LOCK (pad);
1384 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1385 GST_OBJECT_UNLOCK (pad);
1391 * gst_pad_is_blocking:
1392 * @pad: the #GstPad to query
1394 * Checks if the pad is blocking or not. This is a guaranteed state
1395 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1397 * Returns: TRUE if the pad is blocking.
1402 gst_pad_is_blocking (GstPad * pad)
1404 gboolean result = FALSE;
1406 g_return_val_if_fail (GST_IS_PAD (pad), result);
1408 GST_OBJECT_LOCK (pad);
1409 /* the blocking flag is only valid if the pad is not flushing */
1410 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1411 GST_OBJECT_UNLOCK (pad);
1417 * gst_pad_needs_reconfigure:
1418 * @pad: the #GstPad to check
1420 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1421 * if the flag was set.
1423 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1426 gst_pad_needs_reconfigure (GstPad * pad)
1428 gboolean reconfigure;
1430 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1432 GST_OBJECT_LOCK (pad);
1433 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1434 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1435 GST_OBJECT_UNLOCK (pad);
1441 * gst_pad_check_reconfigure:
1442 * @pad: the #GstPad to check
1444 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1445 * if the flag was set.
1447 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1450 gst_pad_check_reconfigure (GstPad * pad)
1452 gboolean reconfigure;
1454 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1456 GST_OBJECT_LOCK (pad);
1457 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1459 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1460 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1462 GST_OBJECT_UNLOCK (pad);
1468 * gst_pad_mark_reconfigure:
1469 * @pad: the #GstPad to mark
1471 * Mark a pad for needing reconfiguration. The next call to
1472 * gst_pad_check_reconfigure() will return %TRUE after this call.
1475 gst_pad_mark_reconfigure (GstPad * pad)
1477 g_return_if_fail (GST_IS_PAD (pad));
1479 GST_OBJECT_LOCK (pad);
1480 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1481 GST_OBJECT_UNLOCK (pad);
1485 * gst_pad_set_activate_function:
1487 * @f: the #GstPadActivateFunction to set.
1489 * Calls gst_pad_set_activate_function_full() with NULL for the user_data and
1493 * gst_pad_set_activate_function_full:
1495 * @activate: the #GstPadActivateFunction to set.
1496 * @user_data: user_data passed to @notify
1497 * @notify: notify called when @activate will not be used anymore.
1499 * Sets the given activate function for @pad. The activate function will
1500 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1501 * Only makes sense to set on sink pads.
1503 * Call this function if your sink pad can start a pull-based task.
1506 gst_pad_set_activate_function_full (GstPad * pad,
1507 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1509 g_return_if_fail (GST_IS_PAD (pad));
1511 if (pad->activatenotify)
1512 pad->activatenotify (pad->activatedata);
1513 GST_PAD_ACTIVATEFUNC (pad) = activate;
1514 pad->activatedata = user_data;
1515 pad->activatenotify = notify;
1517 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1518 GST_DEBUG_FUNCPTR_NAME (activate));
1522 * gst_pad_set_activatemode_function:
1524 * @f: the #GstPadActivateModeFunction to set.
1526 * Calls gst_pad_set_activatemode_function_full() with NULL for the user_data and
1530 * gst_pad_set_activatemode_function_full:
1532 * @activatemode: the #GstPadActivateModeFunction to set.
1533 * @user_data: user_data passed to @notify
1534 * @notify: notify called when @activatemode will not be used anymore.
1536 * Sets the given activate_mode function for the pad. An activate_mode function
1537 * prepares the element for data passing.
1540 gst_pad_set_activatemode_function_full (GstPad * pad,
1541 GstPadActivateModeFunction activatemode, gpointer user_data,
1542 GDestroyNotify notify)
1544 g_return_if_fail (GST_IS_PAD (pad));
1546 if (pad->activatemodenotify)
1547 pad->activatemodenotify (pad->activatemodedata);
1548 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1549 pad->activatemodedata = user_data;
1550 pad->activatemodenotify = notify;
1552 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1553 GST_DEBUG_FUNCPTR_NAME (activatemode));
1557 * gst_pad_set_chain_function:
1558 * @p: a sink #GstPad.
1559 * @f: the #GstPadChainFunction to set.
1561 * Calls gst_pad_set_chain_function_full() with NULL for the user_data and
1565 * gst_pad_set_chain_function_full:
1566 * @pad: a sink #GstPad.
1567 * @chain: the #GstPadChainFunction to set.
1568 * @user_data: user_data passed to @notify
1569 * @notify: notify called when @chain will not be used anymore.
1571 * Sets the given chain function for the pad. The chain function is called to
1572 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1575 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1576 gpointer user_data, GDestroyNotify notify)
1578 g_return_if_fail (GST_IS_PAD (pad));
1579 g_return_if_fail (GST_PAD_IS_SINK (pad));
1581 if (pad->chainnotify)
1582 pad->chainnotify (pad->chaindata);
1583 GST_PAD_CHAINFUNC (pad) = chain;
1584 pad->chaindata = user_data;
1585 pad->chainnotify = notify;
1587 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1588 GST_DEBUG_FUNCPTR_NAME (chain));
1592 * gst_pad_set_chain_list_function:
1593 * @p: a sink #GstPad.
1594 * @f: the #GstPadChainListFunction to set.
1596 * Calls gst_pad_set_chain_list_function_full() with NULL for the user_data and
1600 * gst_pad_set_chain_list_function_full:
1601 * @pad: a sink #GstPad.
1602 * @chainlist: the #GstPadChainListFunction to set.
1603 * @user_data: user_data passed to @notify
1604 * @notify: notify called when @chainlist will not be used anymore.
1606 * Sets the given chain list function for the pad. The chainlist function is
1607 * called to process a #GstBufferList input buffer list. See
1608 * #GstPadChainListFunction for more details.
1611 gst_pad_set_chain_list_function_full (GstPad * pad,
1612 GstPadChainListFunction chainlist, gpointer user_data,
1613 GDestroyNotify notify)
1615 g_return_if_fail (GST_IS_PAD (pad));
1616 g_return_if_fail (GST_PAD_IS_SINK (pad));
1618 if (pad->chainlistnotify)
1619 pad->chainlistnotify (pad->chainlistdata);
1620 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1621 pad->chainlistdata = user_data;
1622 pad->chainlistnotify = notify;
1624 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1625 GST_DEBUG_FUNCPTR_NAME (chainlist));
1629 * gst_pad_set_getrange_function:
1630 * @p: a source #GstPad.
1631 * @f: the #GstPadGetRangeFunction to set.
1633 * Calls gst_pad_set_getrange_function_full() with NULL for the user_data and
1637 * gst_pad_set_getrange_function_full:
1638 * @pad: a source #GstPad.
1639 * @get: the #GstPadGetRangeFunction to set.
1640 * @user_data: user_data passed to @notify
1641 * @notify: notify called when @get will not be used anymore.
1643 * Sets the given getrange function for the pad. The getrange function is
1644 * called to produce a new #GstBuffer to start the processing pipeline. see
1645 * #GstPadGetRangeFunction for a description of the getrange function.
1648 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1649 gpointer user_data, GDestroyNotify notify)
1651 g_return_if_fail (GST_IS_PAD (pad));
1652 g_return_if_fail (GST_PAD_IS_SRC (pad));
1654 if (pad->getrangenotify)
1655 pad->getrangenotify (pad->getrangedata);
1656 GST_PAD_GETRANGEFUNC (pad) = get;
1657 pad->getrangedata = user_data;
1658 pad->getrangenotify = notify;
1660 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1661 GST_DEBUG_FUNCPTR_NAME (get));
1665 * gst_pad_set_event_function:
1666 * @p: a #GstPad of either direction.
1667 * @f: the #GstPadEventFunction to set.
1669 * Calls gst_pad_set_event_function_full() with NULL for the user_data and
1673 * gst_pad_set_event_function_full:
1674 * @pad: a #GstPad of either direction.
1675 * @event: the #GstPadEventFunction to set.
1676 * @user_data: user_data passed to @notify
1677 * @notify: notify called when @event will not be used anymore.
1679 * Sets the given event handler for the pad.
1682 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1683 gpointer user_data, GDestroyNotify notify)
1685 g_return_if_fail (GST_IS_PAD (pad));
1687 if (pad->eventnotify)
1688 pad->eventnotify (pad->eventdata);
1689 GST_PAD_EVENTFUNC (pad) = event;
1690 pad->eventdata = user_data;
1691 pad->eventnotify = notify;
1693 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1694 GST_DEBUG_FUNCPTR_NAME (event));
1698 * gst_pad_set_query_function:
1699 * @p: a #GstPad of either direction.
1700 * @f: the #GstPadQueryFunction to set.
1702 * Calls gst_pad_set_query_function_full() with NULL for the user_data and
1706 * gst_pad_set_query_function_full:
1707 * @pad: a #GstPad of either direction.
1708 * @query: the #GstPadQueryFunction to set.
1709 * @user_data: user_data passed to @notify
1710 * @notify: notify called when @query will not be used anymore.
1712 * Set the given query function for the pad.
1715 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1716 gpointer user_data, GDestroyNotify notify)
1718 g_return_if_fail (GST_IS_PAD (pad));
1720 if (pad->querynotify)
1721 pad->querynotify (pad->querydata);
1722 GST_PAD_QUERYFUNC (pad) = query;
1723 pad->querydata = user_data;
1724 pad->querynotify = notify;
1726 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1727 GST_DEBUG_FUNCPTR_NAME (query));
1731 * gst_pad_set_iterate_internal_links_function:
1732 * @p: a #GstPad of either direction.
1733 * @f: the #GstPadIterIntLinkFunction to set.
1735 * Calls gst_pad_set_iterate_internal_links_function_full() with NULL
1736 * for the user_data and notify.
1739 * gst_pad_set_iterate_internal_links_function_full:
1740 * @pad: a #GstPad of either direction.
1741 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1742 * @user_data: user_data passed to @notify
1743 * @notify: notify called when @iterintlink will not be used anymore.
1745 * Sets the given internal link iterator function for the pad.
1748 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1749 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1750 GDestroyNotify notify)
1752 g_return_if_fail (GST_IS_PAD (pad));
1754 if (pad->iterintlinknotify)
1755 pad->iterintlinknotify (pad->iterintlinkdata);
1756 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1757 pad->iterintlinkdata = user_data;
1758 pad->iterintlinknotify = notify;
1760 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1761 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1765 * gst_pad_set_link_function:
1767 * @f: the #GstPadLinkFunction to set.
1769 * Calls gst_pad_set_link_function_full() with NULL
1770 * for the user_data and notify.
1773 * gst_pad_set_link_function_full:
1775 * @link: the #GstPadLinkFunction to set.
1776 * @user_data: user_data passed to @notify
1777 * @notify: notify called when @link will not be used anymore.
1779 * Sets the given link function for the pad. It will be called when
1780 * the pad is linked with another pad.
1782 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1785 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1786 * cannot be made for some reason.
1788 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1789 * of the peer sink pad, if present.
1792 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1793 gpointer user_data, GDestroyNotify notify)
1795 g_return_if_fail (GST_IS_PAD (pad));
1797 if (pad->linknotify)
1798 pad->linknotify (pad->linkdata);
1799 GST_PAD_LINKFUNC (pad) = link;
1800 pad->linkdata = user_data;
1801 pad->linknotify = notify;
1803 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1804 GST_DEBUG_FUNCPTR_NAME (link));
1808 * gst_pad_set_unlink_function:
1810 * @f: the #GstPadUnlinkFunction to set.
1812 * Calls gst_pad_set_unlink_function_full() with NULL
1813 * for the user_data and notify.
1816 * gst_pad_set_unlink_function_full:
1818 * @unlink: the #GstPadUnlinkFunction to set.
1819 * @user_data: user_data passed to @notify
1820 * @notify: notify called when @unlink will not be used anymore.
1822 * Sets the given unlink function for the pad. It will be called
1823 * when the pad is unlinked.
1826 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1827 gpointer user_data, GDestroyNotify notify)
1829 g_return_if_fail (GST_IS_PAD (pad));
1831 if (pad->unlinknotify)
1832 pad->unlinknotify (pad->unlinkdata);
1833 GST_PAD_UNLINKFUNC (pad) = unlink;
1834 pad->unlinkdata = user_data;
1835 pad->unlinknotify = notify;
1837 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1838 GST_DEBUG_FUNCPTR_NAME (unlink));
1843 * @srcpad: the source #GstPad to unlink.
1844 * @sinkpad: the sink #GstPad to unlink.
1846 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1847 * signal on both pads.
1849 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1850 * the pads were not linked together.
1855 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1857 gboolean result = FALSE;
1858 GstElement *parent = NULL;
1860 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1861 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1862 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1863 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1865 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1866 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1867 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1869 /* We need to notify the parent before taking any pad locks as the bin in
1870 * question might be waiting for a lock on the pad while holding its lock
1871 * that our message will try to take. */
1872 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1873 if (GST_IS_ELEMENT (parent)) {
1874 gst_element_post_message (parent,
1875 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1876 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1878 gst_object_unref (parent);
1883 GST_OBJECT_LOCK (srcpad);
1884 GST_OBJECT_LOCK (sinkpad);
1886 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1887 goto not_linked_together;
1889 if (GST_PAD_UNLINKFUNC (srcpad)) {
1890 GstObject *tmpparent;
1892 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1894 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1895 RELEASE_PARENT (tmpparent);
1898 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1899 GstObject *tmpparent;
1901 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1903 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1904 RELEASE_PARENT (tmpparent);
1908 /* first clear peers */
1909 GST_PAD_PEER (srcpad) = NULL;
1910 GST_PAD_PEER (sinkpad) = NULL;
1912 GST_OBJECT_UNLOCK (sinkpad);
1913 GST_OBJECT_UNLOCK (srcpad);
1915 /* fire off a signal to each of the pads telling them
1916 * that they've been unlinked */
1917 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1918 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1920 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1921 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1926 if (parent != NULL) {
1927 gst_element_post_message (parent,
1928 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1929 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1930 gst_object_unref (parent);
1935 not_linked_together:
1937 /* we do not emit a warning in this case because unlinking cannot
1938 * be made MT safe.*/
1939 GST_OBJECT_UNLOCK (sinkpad);
1940 GST_OBJECT_UNLOCK (srcpad);
1946 * gst_pad_is_linked:
1947 * @pad: pad to check
1949 * Checks if a @pad is linked to another pad or not.
1951 * Returns: TRUE if the pad is linked, FALSE otherwise.
1956 gst_pad_is_linked (GstPad * pad)
1960 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1962 GST_OBJECT_LOCK (pad);
1963 result = (GST_PAD_PEER (pad) != NULL);
1964 GST_OBJECT_UNLOCK (pad);
1969 /* get the caps from both pads and see if the intersection
1972 * This function should be called with the pad LOCK on both
1976 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1977 GstPadLinkCheck flags)
1979 GstCaps *srccaps = NULL;
1980 GstCaps *sinkcaps = NULL;
1981 gboolean compatible = FALSE;
1983 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1986 /* Doing the expensive caps checking takes priority over only checking the template caps */
1987 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1988 GST_OBJECT_UNLOCK (sink);
1989 GST_OBJECT_UNLOCK (src);
1991 srccaps = gst_pad_query_caps (src, NULL);
1992 sinkcaps = gst_pad_query_caps (sink, NULL);
1994 GST_OBJECT_LOCK (src);
1995 GST_OBJECT_LOCK (sink);
1997 /* If one of the two pads doesn't have a template, consider the intersection
1999 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2000 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2004 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2006 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2009 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2011 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2014 /* if we have caps on both pads we can check the intersection. If one
2015 * of the caps is NULL, we return TRUE. */
2016 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2018 gst_caps_unref (srccaps);
2020 gst_caps_unref (sinkcaps);
2024 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2025 gst_caps_unref (srccaps);
2026 gst_caps_unref (sinkcaps);
2029 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2030 (compatible ? "" : "not"));
2035 /* check if the grandparents of both pads are the same.
2036 * This check is required so that we don't try to link
2037 * pads from elements in different bins without ghostpads.
2039 * The LOCK should be held on both pads
2042 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2044 GstObject *psrc, *psink;
2046 psrc = GST_OBJECT_PARENT (src);
2047 psink = GST_OBJECT_PARENT (sink);
2049 /* if one of the pads has no parent, we allow the link */
2050 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2053 /* only care about parents that are elements */
2054 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2055 goto no_element_parent;
2057 /* if the parents are the same, we have a loop */
2058 if (G_UNLIKELY (psrc == psink))
2061 /* if they both have a parent, we check the grandparents. We can not lock
2062 * the parent because we hold on the child (pad) and the locking order is
2063 * parent >> child. */
2064 psrc = GST_OBJECT_PARENT (psrc);
2065 psink = GST_OBJECT_PARENT (psink);
2067 /* if they have grandparents but they are not the same */
2068 if (G_UNLIKELY (psrc != psink))
2069 goto wrong_grandparents;
2076 GST_CAT_DEBUG (GST_CAT_CAPS,
2077 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2078 GST_PTR_FORMAT, psrc, psink);
2083 GST_CAT_DEBUG (GST_CAT_CAPS,
2084 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2085 GST_PTR_FORMAT, psrc, psink);
2090 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2096 GST_CAT_DEBUG (GST_CAT_CAPS,
2097 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2098 GST_PTR_FORMAT, psrc, psink);
2103 /* FIXME leftover from an attempt at refactoring... */
2104 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2105 * the two pads will be locked in the srcpad, sinkpad order. */
2106 static GstPadLinkReturn
2107 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2109 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2110 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2112 GST_OBJECT_LOCK (srcpad);
2114 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2115 goto src_was_linked;
2117 GST_OBJECT_LOCK (sinkpad);
2119 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2120 goto sink_was_linked;
2122 /* check hierarchy, pads can only be linked if the grandparents
2124 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2125 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2126 goto wrong_hierarchy;
2128 /* check pad caps for non-empty intersection */
2129 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2132 /* FIXME check pad scheduling for non-empty intersection */
2134 return GST_PAD_LINK_OK;
2138 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2139 GST_DEBUG_PAD_NAME (srcpad),
2140 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2141 /* we do not emit a warning in this case because unlinking cannot
2142 * be made MT safe.*/
2143 GST_OBJECT_UNLOCK (srcpad);
2144 return GST_PAD_LINK_WAS_LINKED;
2148 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2149 GST_DEBUG_PAD_NAME (sinkpad),
2150 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2151 /* we do not emit a warning in this case because unlinking cannot
2152 * be made MT safe.*/
2153 GST_OBJECT_UNLOCK (sinkpad);
2154 GST_OBJECT_UNLOCK (srcpad);
2155 return GST_PAD_LINK_WAS_LINKED;
2159 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2160 GST_OBJECT_UNLOCK (sinkpad);
2161 GST_OBJECT_UNLOCK (srcpad);
2162 return GST_PAD_LINK_WRONG_HIERARCHY;
2166 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2167 GST_OBJECT_UNLOCK (sinkpad);
2168 GST_OBJECT_UNLOCK (srcpad);
2169 return GST_PAD_LINK_NOFORMAT;
2175 * @srcpad: the source #GstPad.
2176 * @sinkpad: the sink #GstPad.
2178 * Checks if the source pad and the sink pad are compatible so they can be
2181 * Returns: TRUE if the pads can be linked.
2184 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2186 GstPadLinkReturn result;
2188 /* generic checks */
2189 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2190 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2192 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2193 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2195 /* gst_pad_link_prepare does everything for us, we only release the locks
2196 * on the pads that it gets us. If this function returns !OK the locks are not
2198 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2199 if (result != GST_PAD_LINK_OK)
2202 GST_OBJECT_UNLOCK (srcpad);
2203 GST_OBJECT_UNLOCK (sinkpad);
2206 return result == GST_PAD_LINK_OK;
2210 * gst_pad_link_full:
2211 * @srcpad: the source #GstPad to link.
2212 * @sinkpad: the sink #GstPad to link.
2213 * @flags: the checks to validate when linking
2215 * Links the source pad and the sink pad.
2217 * This variant of #gst_pad_link provides a more granular control on the
2218 * checks being done when linking. While providing some considerable speedups
2219 * the caller of this method must be aware that wrong usage of those flags
2220 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2221 * for more information.
2225 * Returns: A result code indicating if the connection worked or
2229 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2231 GstPadLinkReturn result;
2233 GstPadLinkFunction srcfunc, sinkfunc;
2235 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2236 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2237 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2238 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2239 GST_PAD_LINK_WRONG_DIRECTION);
2241 /* Notify the parent early. See gst_pad_unlink for details. */
2242 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2243 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2244 gst_element_post_message (parent,
2245 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2246 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2248 gst_object_unref (parent);
2253 /* prepare will also lock the two pads */
2254 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2256 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2259 /* must set peers before calling the link function */
2260 GST_PAD_PEER (srcpad) = sinkpad;
2261 GST_PAD_PEER (sinkpad) = srcpad;
2263 /* check events, when something is different, mark pending */
2264 schedule_events (srcpad, sinkpad);
2266 /* get the link functions */
2267 srcfunc = GST_PAD_LINKFUNC (srcpad);
2268 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2270 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2271 /* custom link functions, execute them */
2272 GST_OBJECT_UNLOCK (sinkpad);
2273 GST_OBJECT_UNLOCK (srcpad);
2276 GstObject *tmpparent;
2278 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2279 /* this one will call the peer link function */
2280 result = srcfunc (srcpad, tmpparent, sinkpad);
2281 RELEASE_PARENT (tmpparent);
2282 } else if (sinkfunc) {
2283 GstObject *tmpparent;
2285 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2286 /* if no source link function, we need to call the sink link
2287 * function ourselves. */
2288 result = sinkfunc (sinkpad, tmpparent, srcpad);
2289 RELEASE_PARENT (tmpparent);
2293 GST_OBJECT_LOCK (srcpad);
2294 GST_OBJECT_LOCK (sinkpad);
2296 /* we released the lock, check if the same pads are linked still */
2297 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2298 goto concurrent_link;
2300 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2303 GST_OBJECT_UNLOCK (sinkpad);
2304 GST_OBJECT_UNLOCK (srcpad);
2306 /* fire off a signal to each of the pads telling them
2307 * that they've been linked */
2308 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2309 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2311 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2312 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2314 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2317 if (G_LIKELY (parent)) {
2318 gst_element_post_message (parent,
2319 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2320 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2321 gst_object_unref (parent);
2329 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2330 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2331 GST_OBJECT_UNLOCK (sinkpad);
2332 GST_OBJECT_UNLOCK (srcpad);
2334 /* The other link operation succeeded first */
2335 result = GST_PAD_LINK_WAS_LINKED;
2340 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2341 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2343 GST_PAD_PEER (srcpad) = NULL;
2344 GST_PAD_PEER (sinkpad) = NULL;
2346 GST_OBJECT_UNLOCK (sinkpad);
2347 GST_OBJECT_UNLOCK (srcpad);
2355 * @srcpad: the source #GstPad to link.
2356 * @sinkpad: the sink #GstPad to link.
2358 * Links the source pad and the sink pad.
2360 * Returns: A result code indicating if the connection worked or
2366 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2368 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2372 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2374 GstPadTemplate **template_p;
2376 /* this function would need checks if it weren't static */
2378 GST_OBJECT_LOCK (pad);
2379 template_p = &pad->padtemplate;
2380 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2381 GST_OBJECT_UNLOCK (pad);
2384 gst_pad_template_pad_created (templ, pad);
2388 * gst_pad_get_pad_template:
2391 * Gets the template for @pad.
2393 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2394 * instantiated, or %NULL if this pad has no template. Unref after
2398 gst_pad_get_pad_template (GstPad * pad)
2400 GstPadTemplate *templ;
2402 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2404 templ = GST_PAD_PAD_TEMPLATE (pad);
2406 return (templ ? gst_object_ref (templ) : NULL);
2410 * gst_pad_has_current_caps:
2411 * @pad: a #GstPad to check
2413 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2415 * Returns: TRUE when @pad has caps associated with it.
2418 gst_pad_has_current_caps (GstPad * pad)
2423 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2425 GST_OBJECT_LOCK (pad);
2426 caps = get_pad_caps (pad);
2427 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2428 "check current pad caps %" GST_PTR_FORMAT, caps);
2429 result = (caps != NULL);
2430 GST_OBJECT_UNLOCK (pad);
2436 * gst_pad_get_current_caps:
2437 * @pad: a #GstPad to get the current capabilities of.
2439 * Gets the capabilities currently configured on @pad with the last
2440 * #GST_EVENT_CAPS event.
2442 * Returns: the current caps of the pad with incremented ref-count.
2445 gst_pad_get_current_caps (GstPad * pad)
2449 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2451 GST_OBJECT_LOCK (pad);
2452 if ((result = get_pad_caps (pad)))
2453 gst_caps_ref (result);
2454 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2455 "get current pad caps %" GST_PTR_FORMAT, result);
2456 GST_OBJECT_UNLOCK (pad);
2462 * gst_pad_get_pad_template_caps:
2463 * @pad: a #GstPad to get the template capabilities from.
2465 * Gets the capabilities for @pad's template.
2467 * Returns: (transfer full): the #GstCaps of this pad template.
2468 * Unref after usage.
2471 gst_pad_get_pad_template_caps (GstPad * pad)
2473 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2475 if (GST_PAD_PAD_TEMPLATE (pad))
2476 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2478 return gst_caps_ref (GST_CAPS_ANY);
2483 * @pad: a #GstPad to get the peer of.
2485 * Gets the peer of @pad. This function refs the peer pad so
2486 * you need to unref it after use.
2488 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2493 gst_pad_get_peer (GstPad * pad)
2497 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2499 GST_OBJECT_LOCK (pad);
2500 result = GST_PAD_PEER (pad);
2502 gst_object_ref (result);
2503 GST_OBJECT_UNLOCK (pad);
2509 * gst_pad_get_allowed_caps:
2512 * Gets the capabilities of the allowed media types that can flow through
2513 * @pad and its peer.
2515 * The allowed capabilities is calculated as the intersection of the results of
2516 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2517 * on the resulting caps.
2519 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2520 * caps when you no longer need it. This function returns NULL when @pad
2526 gst_pad_get_allowed_caps (GstPad * pad)
2532 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2534 GST_OBJECT_LOCK (pad);
2535 peer = GST_PAD_PEER (pad);
2536 if (G_UNLIKELY (peer == NULL))
2539 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2541 gst_object_ref (peer);
2542 GST_OBJECT_UNLOCK (pad);
2543 mycaps = gst_pad_query_caps (pad, NULL);
2545 caps = gst_pad_query_caps (peer, mycaps);
2546 gst_object_unref (peer);
2548 gst_caps_unref (mycaps);
2550 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2557 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2558 GST_OBJECT_UNLOCK (pad);
2565 * gst_pad_iterate_internal_links_default:
2566 * @pad: the #GstPad to get the internal links of.
2567 * @parent: (allow-none): the parent of @pad or NULL
2569 * Iterate the list of pads to which the given pad is linked to inside of
2570 * the parent element.
2571 * This is the default handler, and thus returns an iterator of all of the
2572 * pads inside the parent element with opposite direction.
2574 * The caller must free this iterator after use with gst_iterator_free().
2576 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2577 * returned pad with gst_object_unref().
2580 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2587 GstElement *eparent;
2589 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2591 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2592 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2594 GST_OBJECT_LOCK (pad);
2595 eparent = GST_PAD_PARENT (pad);
2596 if (!eparent || !GST_IS_ELEMENT (eparent))
2599 gst_object_ref (eparent);
2600 GST_OBJECT_UNLOCK (pad);
2603 if (pad->direction == GST_PAD_SRC)
2604 padlist = &eparent->sinkpads;
2606 padlist = &eparent->srcpads;
2608 GST_DEBUG_OBJECT (pad, "Making iterator");
2610 cookie = &eparent->pads_cookie;
2612 lock = GST_OBJECT_GET_LOCK (eparent);
2614 res = gst_iterator_new_list (GST_TYPE_PAD,
2615 lock, cookie, padlist, (GObject *) owner, NULL);
2617 gst_object_unref (owner);
2624 GST_OBJECT_UNLOCK (pad);
2625 GST_DEBUG_OBJECT (pad, "no parent element");
2631 * gst_pad_iterate_internal_links:
2632 * @pad: the GstPad to get the internal links of.
2634 * Gets an iterator for the pads to which the given pad is linked to inside
2635 * of the parent element.
2637 * Each #GstPad element yielded by the iterator will have its refcount increased,
2638 * so unref after use.
2640 * Free-function: gst_iterator_free
2642 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2643 * pad does not have an iterator function configured. Use
2644 * gst_iterator_free() after usage.
2647 gst_pad_iterate_internal_links (GstPad * pad)
2649 GstIterator *res = NULL;
2652 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2654 GST_OBJECT_LOCK (pad);
2655 ACQUIRE_PARENT (pad, parent, no_parent);
2656 GST_OBJECT_UNLOCK (pad);
2658 if (GST_PAD_ITERINTLINKFUNC (pad))
2659 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2661 RELEASE_PARENT (parent);
2668 GST_DEBUG_OBJECT (pad, "no parent");
2669 GST_OBJECT_UNLOCK (pad);
2677 * @forward: (scope call): a #GstPadForwardFunction
2678 * @user_data: user data passed to @forward
2680 * Calls @forward for all internally linked pads of @pad. This function deals with
2681 * dynamically changing internal pads and will make sure that the @forward
2682 * function is only called once for each pad.
2684 * When @forward returns TRUE, no further pads will be processed.
2686 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2689 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2692 gboolean result = FALSE;
2694 gboolean done = FALSE;
2695 GValue item = { 0, };
2696 GList *pushed_pads = NULL;
2698 iter = gst_pad_iterate_internal_links (pad);
2704 switch (gst_iterator_next (iter, &item)) {
2705 case GST_ITERATOR_OK:
2709 intpad = g_value_get_object (&item);
2711 /* if already pushed, skip. FIXME, find something faster to tag pads */
2712 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2713 g_value_reset (&item);
2717 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2718 GST_DEBUG_PAD_NAME (intpad));
2719 done = result = forward (intpad, user_data);
2721 pushed_pads = g_list_prepend (pushed_pads, intpad);
2723 g_value_reset (&item);
2726 case GST_ITERATOR_RESYNC:
2727 /* We don't reset the result here because we don't push the event
2728 * again on pads that got the event already and because we need
2729 * to consider the result of the previous pushes */
2730 gst_iterator_resync (iter);
2732 case GST_ITERATOR_ERROR:
2733 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2736 case GST_ITERATOR_DONE:
2741 g_value_unset (&item);
2742 gst_iterator_free (iter);
2744 g_list_free (pushed_pads);
2754 gboolean dispatched;
2758 event_forward_func (GstPad * pad, EventData * data)
2760 /* for each pad we send to, we should ref the event; it's up
2761 * to downstream to unref again when handled. */
2762 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2763 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2765 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2767 data->dispatched = TRUE;
2774 * gst_pad_event_default:
2775 * @pad: a #GstPad to call the default event handler on.
2776 * @parent: (allow-none): the parent of @pad or NULL
2777 * @event: (transfer full): the #GstEvent to handle.
2779 * Invokes the default event handler for the given pad.
2781 * The EOS event will pause the task associated with @pad before it is forwarded
2782 * to all internally linked pads,
2784 * The the event is sent to all pads internally linked to @pad. This function
2785 * takes ownership of @event.
2787 * Returns: TRUE if the event was sent successfully.
2790 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2792 gboolean result, forward = TRUE;
2794 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2795 g_return_val_if_fail (event != NULL, FALSE);
2797 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2800 switch (GST_EVENT_TYPE (event)) {
2801 case GST_EVENT_CAPS:
2802 forward = GST_PAD_IS_PROXY_CAPS (pad);
2813 data.dispatched = FALSE;
2814 data.result = FALSE;
2816 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2818 /* for sinkpads without a parent element or without internal links, nothing
2819 * will be dispatched but we still want to return TRUE. */
2820 if (data.dispatched)
2821 result = data.result;
2826 gst_event_unref (event);
2831 /* Default accept caps implementation just checks against
2832 * the allowed caps for the pad */
2834 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2836 /* get the caps and see if it intersects to something not empty */
2837 GstCaps *caps, *allowed;
2840 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2842 /* first forward the query to internally linked pads when we are dealing with
2844 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2845 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2850 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2851 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2853 gst_query_parse_accept_caps (query, &caps);
2854 allowed = gst_pad_query_caps (pad, caps);
2857 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
2858 GST_DEBUG_OBJECT (pad,
2859 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
2861 result = gst_caps_can_intersect (caps, allowed);
2863 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
2864 GST_PTR_FORMAT, allowed, caps);
2865 result = gst_caps_is_subset (caps, allowed);
2867 gst_caps_unref (allowed);
2869 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
2872 gst_query_set_accept_caps_result (query, result);
2878 /* Default caps implementation */
2880 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2882 GstCaps *result = NULL, *filter;
2883 GstPadTemplate *templ;
2884 gboolean fixed_caps;
2886 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2889 /* first try to proxy if we must */
2890 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2891 if ((gst_pad_proxy_query_caps (pad, query))) {
2896 gst_query_parse_caps (query, &filter);
2898 /* no proxy or it failed, do default handling */
2899 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2901 GST_OBJECT_LOCK (pad);
2903 /* fixed caps, try the negotiated caps first */
2904 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2905 if ((result = get_pad_caps (pad)))
2906 goto filter_done_unlock;
2909 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2910 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2911 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2912 goto filter_done_unlock;
2916 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2917 "non-fixed pad caps: trying pad caps");
2918 /* non fixed caps, try the negotiated caps */
2919 if ((result = get_pad_caps (pad)))
2920 goto filter_done_unlock;
2923 /* this almost never happens */
2924 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2925 result = GST_CAPS_ANY;
2928 GST_OBJECT_UNLOCK (pad);
2930 /* run the filter on the result */
2932 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2933 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2934 GST_PTR_FORMAT, result, result, filter, filter);
2935 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2936 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2939 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2940 "using caps %p %" GST_PTR_FORMAT, result, result);
2941 result = gst_caps_ref (result);
2943 gst_query_set_caps_result (query, result);
2944 gst_caps_unref (result);
2954 gboolean dispatched;
2958 query_forward_func (GstPad * pad, QueryData * data)
2960 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
2961 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
2963 data->result |= gst_pad_peer_query (pad, data->query);
2965 data->dispatched = TRUE;
2967 /* stop on first successful reply */
2968 return data->result;
2972 * gst_pad_query_default:
2973 * @pad: a #GstPad to call the default query handler on.
2974 * @parent: (allow-none): the parent of @pad or NULL
2975 * @query: (transfer none): the #GstQuery to handle.
2977 * Invokes the default query handler for the given pad.
2978 * The query is sent to all pads internally linked to @pad. Note that
2979 * if there are many possible sink pads that are internally linked to
2980 * @pad, only one will be sent the query.
2981 * Multi-sinkpad elements should implement custom query handlers.
2983 * Returns: TRUE if the query was performed successfully.
2986 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
2988 gboolean forward, ret = FALSE;
2990 switch (GST_QUERY_TYPE (query)) {
2991 case GST_QUERY_SCHEDULING:
2992 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
2994 case GST_QUERY_ALLOCATION:
2995 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
2997 case GST_QUERY_ACCEPT_CAPS:
2998 ret = gst_pad_query_accept_caps_default (pad, query);
3001 case GST_QUERY_CAPS:
3002 ret = gst_pad_query_caps_default (pad, query);
3005 case GST_QUERY_POSITION:
3006 case GST_QUERY_SEEKING:
3007 case GST_QUERY_FORMATS:
3008 case GST_QUERY_LATENCY:
3009 case GST_QUERY_JITTER:
3010 case GST_QUERY_RATE:
3011 case GST_QUERY_CONVERT:
3017 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3018 query, GST_QUERY_TYPE_NAME (query));
3024 data.dispatched = FALSE;
3025 data.result = FALSE;
3027 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3029 if (data.dispatched) {
3032 /* nothing dispatched, assume drained */
3033 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3043 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3045 GstPad *pad = data->pad;
3046 GstPadProbeInfo *info = data->info;
3047 GstPadProbeType type, flags;
3048 GstPadProbeCallback callback;
3049 GstPadProbeReturn ret;
3051 /* if we have called this callback, do nothing */
3052 if (PROBE_COOKIE (hook) == data->cookie) {
3053 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3054 "hook %lu, cookie %u already called", hook->hook_id,
3055 PROBE_COOKIE (hook));
3059 PROBE_COOKIE (hook) = data->cookie;
3061 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3064 /* one of the data types */
3065 if ((flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3067 /* one of the scheduling types */
3068 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3070 /* one of the blocking types must match */
3071 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3072 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3074 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3075 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3076 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3079 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3080 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3081 PROBE_COOKIE (hook), flags);
3083 data->marshalled = TRUE;
3085 callback = (GstPadProbeCallback) hook->func;
3086 if (callback == NULL)
3089 info->id = hook->hook_id;
3091 GST_OBJECT_UNLOCK (pad);
3093 ret = callback (pad, info, hook->data);
3095 GST_OBJECT_LOCK (pad);
3098 case GST_PAD_PROBE_REMOVE:
3099 /* remove the probe */
3100 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3101 cleanup_hook (pad, hook);
3103 case GST_PAD_PROBE_DROP:
3104 /* need to drop the data, make sure other probes don't get called
3106 GST_DEBUG_OBJECT (pad, "asked to drop item");
3107 info->type = GST_PAD_PROBE_TYPE_INVALID;
3108 data->dropped = TRUE;
3110 case GST_PAD_PROBE_PASS:
3111 /* inform the pad block to let things pass */
3112 GST_DEBUG_OBJECT (pad, "asked to pass item");
3115 case GST_PAD_PROBE_OK:
3116 GST_DEBUG_OBJECT (pad, "probe returned OK");
3119 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3126 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3127 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3128 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3133 /* a probe that does not take or return any data */
3134 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3136 if (G_UNLIKELY (pad->num_probes)) { \
3137 /* pass NULL as the data item */ \
3138 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3139 ret = do_probe_callbacks (pad, &info, defaultval); \
3140 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3145 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3147 if (G_UNLIKELY (pad->num_probes)) { \
3148 /* pass the data item */ \
3149 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3150 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3151 /* store the possibly updated data item */ \
3152 data = GST_PAD_PROBE_INFO_DATA (&info); \
3153 /* if something went wrong, exit */ \
3154 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3159 #define PROBE_PUSH(pad,mask,data,label) \
3160 PROBE_FULL(pad, mask, data, -1, -1, label);
3161 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3162 PROBE_FULL(pad, mask, data, offs, size, label);
3164 static GstFlowReturn
3165 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3166 GstFlowReturn defaultval)
3175 data.marshalled = FALSE;
3176 data.dropped = FALSE;
3177 data.cookie = ++pad->priv->probe_cookie;
3180 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3183 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3184 "do probes cookie %u", data.cookie);
3185 cookie = pad->priv->probe_list_cookie;
3187 g_hook_list_marshal (&pad->probes, TRUE,
3188 (GHookMarshaller) probe_hook_marshal, &data);
3190 /* if the list changed, call the new callbacks (they will not have their
3191 * cookie set to data.cookie */
3192 if (cookie != pad->priv->probe_list_cookie) {
3193 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3194 "probe list changed, restarting");
3198 /* the first item that dropped will stop the hooks and then we drop here */
3202 /* if no handler matched and we are blocking, let the item pass */
3203 if (!data.marshalled && is_block)
3206 /* At this point, all handlers returned either OK or PASS. If one handler
3207 * returned PASS, let the item pass */
3212 while (GST_PAD_IS_BLOCKED (pad)) {
3213 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3214 "we are blocked %d times", pad->num_blocked);
3216 /* we might have released the lock */
3217 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3220 /* now we block the streaming thread. It can be unlocked when we
3221 * deactivate the pad (which will also set the FLUSHING flag) or
3222 * when the pad is unblocked. A flushing event will also unblock
3223 * the pad after setting the FLUSHING flag. */
3224 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3225 "Waiting to be unblocked or set flushing");
3226 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3227 GST_PAD_BLOCK_WAIT (pad);
3228 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3229 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3231 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3241 GST_DEBUG_OBJECT (pad, "pad is flushing");
3242 return GST_FLOW_FLUSHING;
3246 GST_DEBUG_OBJECT (pad, "data is dropped");
3247 return GST_FLOW_CUSTOM_SUCCESS;
3251 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3252 GST_DEBUG_OBJECT (pad, "data is passed");
3260 * gst_pad_get_offset:
3263 * Get the offset applied to the running time of @pad. @pad has to be a source
3266 * Returns: the offset.
3269 gst_pad_get_offset (GstPad * pad)
3273 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3275 GST_OBJECT_LOCK (pad);
3276 result = pad->offset;
3277 GST_OBJECT_UNLOCK (pad);
3283 * gst_pad_set_offset:
3285 * @offset: the offset
3287 * Set the offset that will be applied to the running time of @pad.
3290 gst_pad_set_offset (GstPad * pad, gint64 offset)
3294 g_return_if_fail (GST_IS_PAD (pad));
3296 GST_OBJECT_LOCK (pad);
3297 /* if nothing changed, do nothing */
3298 if (pad->offset == offset)
3301 pad->offset = offset;
3302 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3304 /* sinkpads will apply their offset the next time a segment
3305 * event is received. */
3306 if (GST_PAD_IS_SINK (pad))
3309 /* resend the last segment event on next buffer push */
3310 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3311 ev->received = FALSE;
3312 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3316 GST_OBJECT_UNLOCK (pad);
3323 /* If TRUE and ret is not OK this means
3324 * that pushing the EOS event failed
3328 /* If called for an event this is
3329 * the event that would be pushed
3330 * next. Don't forward sticky events
3331 * that would come after that */
3335 /* should be called with pad LOCK */
3337 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3339 PushStickyData *data = user_data;
3340 GstEvent *event = ev->event;
3343 GST_DEBUG_OBJECT (pad, "event %s was already received",
3344 GST_EVENT_TYPE_NAME (event));
3348 /* If we're called because of an sticky event, only forward
3349 * events that would come before this new event and the
3351 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3352 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3353 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3354 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3356 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3357 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3360 switch (data->ret) {
3362 ev->received = TRUE;
3363 GST_DEBUG_OBJECT (pad, "event %s marked received",
3364 GST_EVENT_TYPE_NAME (event));
3366 case GST_FLOW_CUSTOM_SUCCESS:
3367 /* we can't assume the event is received when it was dropped */
3368 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3369 GST_EVENT_TYPE_NAME (event));
3370 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3371 data->ret = GST_FLOW_OK;
3373 case GST_FLOW_CUSTOM_SUCCESS_1:
3374 /* event was ignored and should be sent later */
3375 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3376 GST_EVENT_TYPE_NAME (event));
3377 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3378 data->ret = GST_FLOW_OK;
3380 case GST_FLOW_NOT_LINKED:
3381 /* not linked is not a problem, we are sticky so the event will be
3382 * sent later but only for non-EOS events */
3383 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3384 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3385 data->ret = GST_FLOW_OK;
3386 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3389 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3390 gst_flow_get_name (data->ret));
3391 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3395 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3396 data->was_eos = TRUE;
3398 return data->ret == GST_FLOW_OK;
3401 /* check sticky events and push them when needed. should be called
3403 static inline GstFlowReturn
3404 check_sticky (GstPad * pad, GstEvent * event)
3406 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3408 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3409 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3411 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3412 events_foreach (pad, push_sticky, &data);
3414 /* If there's an EOS event we must push it downstream
3415 * even if sending a previous sticky event failed.
3416 * Otherwise the pipeline might wait forever for EOS.
3418 * Only do this if pushing another event than the EOS
3421 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3422 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3424 if (ev && !ev->received) {
3425 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3426 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3427 /* the event could have been dropped. Because this can only
3428 * happen if the user asked for it, it's not an error */
3429 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3430 data.ret = GST_FLOW_OK;
3440 * @pad: a #GstPad to invoke the default query on.
3441 * @query: (transfer none): the #GstQuery to perform.
3443 * Dispatches a query to a pad. The query should have been allocated by the
3444 * caller via one of the type-specific allocation functions. The element that
3445 * the pad belongs to is responsible for filling the query with an appropriate
3446 * response, which should then be parsed with a type-specific query parsing
3449 * Again, the caller is responsible for both the allocation and deallocation of
3450 * the query structure.
3452 * Please also note that some queries might need a running pipeline to work.
3454 * Returns: TRUE if the query could be performed.
3457 gst_pad_query (GstPad * pad, GstQuery * query)
3460 gboolean res, serialized;
3461 GstPadQueryFunction func;
3462 GstPadProbeType type;
3465 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3466 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3468 if (GST_PAD_IS_SRC (pad)) {
3469 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3470 goto wrong_direction;
3471 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3472 } else if (GST_PAD_IS_SINK (pad)) {
3473 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3474 goto wrong_direction;
3475 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3477 goto unknown_direction;
3479 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3480 GST_QUERY_TYPE_NAME (query));
3482 serialized = GST_QUERY_IS_SERIALIZED (query);
3483 if (G_UNLIKELY (serialized))
3484 GST_PAD_STREAM_LOCK (pad);
3486 GST_OBJECT_LOCK (pad);
3487 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3488 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3489 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3491 ACQUIRE_PARENT (pad, parent, no_parent);
3492 GST_OBJECT_UNLOCK (pad);
3494 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3497 res = func (pad, parent, query);
3499 RELEASE_PARENT (parent);
3501 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3502 GST_QUERY_TYPE_NAME (query), res);
3507 GST_OBJECT_LOCK (pad);
3508 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3509 GST_OBJECT_UNLOCK (pad);
3511 if (G_UNLIKELY (serialized))
3512 GST_PAD_STREAM_UNLOCK (pad);
3519 g_warning ("pad %s:%s query %s in wrong direction",
3520 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3525 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3530 GST_DEBUG_OBJECT (pad, "had no parent");
3531 GST_OBJECT_UNLOCK (pad);
3532 if (G_UNLIKELY (serialized))
3533 GST_PAD_STREAM_UNLOCK (pad);
3538 GST_DEBUG_OBJECT (pad, "had no query function");
3539 RELEASE_PARENT (parent);
3540 if (G_UNLIKELY (serialized))
3541 GST_PAD_STREAM_UNLOCK (pad);
3546 GST_DEBUG_OBJECT (pad, "query failed");
3547 if (G_UNLIKELY (serialized))
3548 GST_PAD_STREAM_UNLOCK (pad);
3553 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3554 GST_OBJECT_UNLOCK (pad);
3555 if (G_UNLIKELY (serialized))
3556 GST_PAD_STREAM_UNLOCK (pad);
3558 /* if a probe dropped, we don't sent it further but assume that the probe
3559 * answered the query and return TRUE */
3560 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3570 * gst_pad_peer_query:
3571 * @pad: a #GstPad to invoke the peer query on.
3572 * @query: (transfer none): the #GstQuery to perform.
3574 * Performs gst_pad_query() on the peer of @pad.
3576 * The caller is responsible for both the allocation and deallocation of
3577 * the query structure.
3579 * Returns: TRUE if the query could be performed. This function returns %FALSE
3580 * if @pad has no peer.
3583 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3586 GstPadProbeType type;
3587 gboolean res, serialized;
3590 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3591 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3593 if (GST_PAD_IS_SRC (pad)) {
3594 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3595 goto wrong_direction;
3596 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3597 } else if (GST_PAD_IS_SINK (pad)) {
3598 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3599 goto wrong_direction;
3600 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3602 goto unknown_direction;
3604 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3605 GST_QUERY_TYPE_NAME (query));
3607 serialized = GST_QUERY_IS_SERIALIZED (query);
3609 GST_OBJECT_LOCK (pad);
3610 if (GST_PAD_IS_SRC (pad) && serialized) {
3611 /* all serialized queries on the srcpad trigger push of
3613 if (!check_sticky (pad, NULL) == GST_FLOW_OK)
3617 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3618 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3619 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3621 peerpad = GST_PAD_PEER (pad);
3622 if (G_UNLIKELY (peerpad == NULL))
3625 gst_object_ref (peerpad);
3626 GST_OBJECT_UNLOCK (pad);
3628 res = gst_pad_query (peerpad, query);
3630 gst_object_unref (peerpad);
3635 GST_OBJECT_LOCK (pad);
3636 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3637 GST_OBJECT_UNLOCK (pad);
3644 g_warning ("pad %s:%s query %s in wrong direction",
3645 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3650 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3655 GST_WARNING_OBJECT (pad, "could not send sticky events");
3656 GST_OBJECT_UNLOCK (pad);
3661 GST_INFO_OBJECT (pad, "pad has no peer");
3662 GST_OBJECT_UNLOCK (pad);
3667 GST_DEBUG_OBJECT (pad, "query failed");
3672 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3673 GST_OBJECT_UNLOCK (pad);
3675 /* if a probe dropped, we don't sent it further but assume that the probe
3676 * answered the query and return TRUE */
3677 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3686 /**********************************************************************
3687 * Data passing functions
3690 /* this is the chain function that does not perform the additional argument
3691 * checking for that little extra speed.
3693 static inline GstFlowReturn
3694 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3699 GST_PAD_STREAM_LOCK (pad);
3701 GST_OBJECT_LOCK (pad);
3702 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3705 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3708 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3711 #ifndef G_DISABLE_ASSERT
3712 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3713 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3715 ":%s:<%s:%s> Got data flow before stream-start event",
3716 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3718 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3720 ":%s:<%s:%s> Got data flow before segment event",
3721 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3723 pad->priv->last_cookie = pad->priv->events_cookie;
3727 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3729 PROBE_PUSH (pad, type, data, probe_stopped);
3731 parent = GST_OBJECT_PARENT (pad);
3732 GST_OBJECT_UNLOCK (pad);
3734 /* NOTE: we read the chainfunc unlocked.
3735 * we cannot hold the lock for the pad so we might send
3736 * the data to the wrong function. This is not really a
3737 * problem since functions are assigned at creation time
3738 * and don't change that often... */
3739 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3740 GstPadChainFunction chainfunc;
3742 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3745 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3746 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3747 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3749 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3751 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3752 "called chainfunction &%s with buffer %p, returned %s",
3753 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3755 GstPadChainListFunction chainlistfunc;
3757 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3760 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3761 "calling chainlistfunction &%s",
3762 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3764 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3766 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3767 "called chainlistfunction &%s, returned %s",
3768 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3771 GST_PAD_STREAM_UNLOCK (pad);
3778 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3779 "chaining, but pad was flushing");
3780 GST_OBJECT_UNLOCK (pad);
3781 GST_PAD_STREAM_UNLOCK (pad);
3782 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3783 return GST_FLOW_FLUSHING;
3787 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3788 GST_OBJECT_UNLOCK (pad);
3789 GST_PAD_STREAM_UNLOCK (pad);
3790 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3791 return GST_FLOW_EOS;
3795 g_critical ("chain on pad %s:%s but it was not in push mode",
3796 GST_DEBUG_PAD_NAME (pad));
3797 GST_OBJECT_UNLOCK (pad);
3798 GST_PAD_STREAM_UNLOCK (pad);
3799 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3800 return GST_FLOW_ERROR;
3804 GST_OBJECT_UNLOCK (pad);
3805 GST_PAD_STREAM_UNLOCK (pad);
3806 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3809 case GST_FLOW_CUSTOM_SUCCESS:
3810 GST_DEBUG_OBJECT (pad, "dropped buffer");
3814 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
3821 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3822 g_critical ("chain on pad %s:%s but it has no chainfunction",
3823 GST_DEBUG_PAD_NAME (pad));
3824 GST_PAD_STREAM_UNLOCK (pad);
3825 return GST_FLOW_NOT_SUPPORTED;
3831 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3832 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3835 * Chain a buffer to @pad.
3837 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3839 * If the buffer type is not acceptable for @pad (as negotiated with a
3840 * preceding GST_EVENT_CAPS event), this function returns
3841 * #GST_FLOW_NOT_NEGOTIATED.
3843 * The function proceeds calling the chain function installed on @pad (see
3844 * gst_pad_set_chain_function()) and the return value of that function is
3845 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3848 * In all cases, success or failure, the caller loses its reference to @buffer
3849 * after calling this function.
3851 * Returns: a #GstFlowReturn from the pad.
3856 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3858 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3859 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3860 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3862 return gst_pad_chain_data_unchecked (pad,
3863 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3866 static GstFlowReturn
3867 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3868 GstBufferList * list)
3874 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3876 len = gst_buffer_list_length (list);
3879 for (i = 0; i < len; i++) {
3880 buffer = gst_buffer_list_get (list, i);
3882 gst_pad_chain_data_unchecked (pad,
3883 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3884 gst_buffer_ref (buffer));
3885 if (ret != GST_FLOW_OK)
3888 gst_buffer_list_unref (list);
3894 * gst_pad_chain_list:
3895 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3896 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3899 * Chain a bufferlist to @pad.
3901 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3903 * If @pad was not negotiated properly with a CAPS event, this function
3904 * returns #GST_FLOW_NOT_NEGOTIATED.
3906 * The function proceeds calling the chainlist function installed on @pad (see
3907 * gst_pad_set_chain_list_function()) and the return value of that function is
3908 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3909 * chainlist function.
3911 * In all cases, success or failure, the caller loses its reference to @list
3912 * after calling this function.
3916 * Returns: a #GstFlowReturn from the pad.
3919 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3921 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3922 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3923 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3925 return gst_pad_chain_data_unchecked (pad,
3926 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3929 static GstFlowReturn
3930 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3935 GST_OBJECT_LOCK (pad);
3936 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3939 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3942 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3945 #ifndef G_DISABLE_ASSERT
3946 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3947 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3949 ":%s:<%s:%s> Got data flow before stream-start event",
3950 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3952 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3954 ":%s:<%s:%s> Got data flow before segment event",
3955 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3957 pad->priv->last_cookie = pad->priv->events_cookie;
3961 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3964 /* do block probes */
3965 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3967 /* recheck sticky events because the probe might have cause a relink */
3968 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
3971 /* do post-blocking probes */
3972 PROBE_PUSH (pad, type, data, probe_stopped);
3974 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3977 /* take ref to peer pad before releasing the lock */
3978 gst_object_ref (peer);
3980 GST_OBJECT_UNLOCK (pad);
3982 ret = gst_pad_chain_data_unchecked (peer, type, data);
3984 gst_object_unref (peer);
3986 GST_OBJECT_LOCK (pad);
3988 if (pad->priv->using == 0) {
3989 /* pad is not active anymore, trigger idle callbacks */
3990 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3991 probe_stopped, ret);
3993 GST_OBJECT_UNLOCK (pad);
3997 /* ERROR recovery here */
4001 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4002 "pushing, but pad was flushing");
4003 GST_OBJECT_UNLOCK (pad);
4004 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4005 return GST_FLOW_FLUSHING;
4009 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4010 GST_OBJECT_UNLOCK (pad);
4011 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4012 return GST_FLOW_EOS;
4016 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4017 GST_DEBUG_PAD_NAME (pad));
4018 GST_OBJECT_UNLOCK (pad);
4019 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4020 return GST_FLOW_ERROR;
4024 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4025 "error pushing events, return %s", gst_flow_get_name (ret));
4026 GST_OBJECT_UNLOCK (pad);
4027 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4032 GST_OBJECT_UNLOCK (pad);
4033 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4036 case GST_FLOW_CUSTOM_SUCCESS:
4037 GST_DEBUG_OBJECT (pad, "dropped buffer");
4041 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4048 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4049 "pushing, but it was not linked");
4050 GST_OBJECT_UNLOCK (pad);
4051 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4052 return GST_FLOW_NOT_LINKED;
4058 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4059 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4062 * Pushes a buffer to the peer of @pad.
4064 * This function will call installed block probes before triggering any
4065 * installed data probes.
4067 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4068 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4071 * In all cases, success or failure, the caller loses its reference to @buffer
4072 * after calling this function.
4074 * Returns: a #GstFlowReturn from the peer pad.
4079 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4081 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4082 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4083 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4085 return gst_pad_push_data (pad,
4086 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4090 * gst_pad_push_list:
4091 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4092 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4095 * Pushes a buffer list to the peer of @pad.
4097 * This function will call installed block probes before triggering any
4098 * installed data probes.
4100 * The function proceeds calling the chain function on the peer pad and returns
4101 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4102 * be returned. If the peer pad does not have any installed chainlist function
4103 * every group buffer of the list will be merged into a normal #GstBuffer and
4104 * chained via gst_pad_chain().
4106 * In all cases, success or failure, the caller loses its reference to @list
4107 * after calling this function.
4109 * Returns: a #GstFlowReturn from the peer pad.
4114 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4116 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4117 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4118 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4120 return gst_pad_push_data (pad,
4121 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4124 static GstFlowReturn
4125 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4126 GstBuffer ** buffer)
4129 GstPadGetRangeFunction getrangefunc;
4133 GST_PAD_STREAM_LOCK (pad);
4135 GST_OBJECT_LOCK (pad);
4136 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4139 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4142 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4147 /* when one of the probes returns DROPPED, probe_stopped will be called
4148 * and we skip calling the getrange function, res_buf should then contain a
4149 * valid result buffer */
4150 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4151 res_buf, offset, size, probe_stopped);
4153 /* recheck sticky events because the probe might have cause a relink */
4154 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4157 ACQUIRE_PARENT (pad, parent, no_parent);
4158 GST_OBJECT_UNLOCK (pad);
4160 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4163 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4164 "calling getrangefunc %s, offset %"
4165 G_GUINT64_FORMAT ", size %u",
4166 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4168 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4170 RELEASE_PARENT (parent);
4172 if (G_UNLIKELY (ret != GST_FLOW_OK))
4173 goto get_range_failed;
4175 /* can only fire the signal if we have a valid buffer */
4176 GST_OBJECT_LOCK (pad);
4178 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4179 res_buf, offset, size, probe_stopped_unref);
4180 GST_OBJECT_UNLOCK (pad);
4182 GST_PAD_STREAM_UNLOCK (pad);
4191 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4192 "getrange, but pad was flushing");
4193 GST_OBJECT_UNLOCK (pad);
4194 GST_PAD_STREAM_UNLOCK (pad);
4195 return GST_FLOW_FLUSHING;
4199 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4200 GST_DEBUG_PAD_NAME (pad));
4201 GST_OBJECT_UNLOCK (pad);
4202 GST_PAD_STREAM_UNLOCK (pad);
4203 return GST_FLOW_ERROR;
4207 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4208 GST_OBJECT_UNLOCK (pad);
4209 GST_PAD_STREAM_UNLOCK (pad);
4214 GST_DEBUG_OBJECT (pad, "no parent");
4215 GST_OBJECT_UNLOCK (pad);
4216 GST_PAD_STREAM_UNLOCK (pad);
4217 return GST_FLOW_FLUSHING;
4221 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4222 GST_DEBUG_PAD_NAME (pad));
4223 RELEASE_PARENT (parent);
4224 GST_PAD_STREAM_UNLOCK (pad);
4225 return GST_FLOW_NOT_SUPPORTED;
4229 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4230 "probe returned %s", gst_flow_get_name (ret));
4231 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4233 /* the probe filled the buffer and asks us to not call the getrange
4234 * anymore, we continue with the post probes then. */
4235 GST_DEBUG_OBJECT (pad, "handled buffer");
4239 /* no buffer, we are EOS */
4240 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4244 GST_OBJECT_UNLOCK (pad);
4245 GST_PAD_STREAM_UNLOCK (pad);
4249 probe_stopped_unref:
4251 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4252 "probe returned %s", gst_flow_get_name (ret));
4253 /* if we drop here, it signals EOS */
4254 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4256 GST_OBJECT_UNLOCK (pad);
4257 GST_PAD_STREAM_UNLOCK (pad);
4258 if (*buffer == NULL)
4259 gst_buffer_unref (res_buf);
4264 GST_PAD_STREAM_UNLOCK (pad);
4265 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4266 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4267 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4273 * gst_pad_get_range:
4274 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4275 * @offset: The start offset of the buffer
4276 * @size: The length of the buffer
4277 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4278 * returns #GST_FLOW_ERROR if %NULL.
4280 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4281 * immediately and @buffer is %NULL.
4283 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4284 * description of a getrange function. If @pad has no getrange function
4285 * installed (see gst_pad_set_getrange_function()) this function returns
4286 * #GST_FLOW_NOT_SUPPORTED.
4288 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4289 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4290 * must be freed with gst_buffer_unref() after usage.
4292 * When @buffer points to a variable that points to a valid #GstBuffer, the
4293 * buffer will be filled with the result data when this function returns
4294 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4295 * @size bytes will be filled in the result buffer and its size will be updated
4298 * Note that less than @size bytes can be returned in @buffer when, for example,
4299 * an EOS condition is near or when @buffer is not large enough to hold @size
4300 * bytes. The caller should check the result buffer size to get the result size.
4302 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4303 * will be unchanged.
4305 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4307 * Returns: a #GstFlowReturn from the pad.
4312 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4313 GstBuffer ** buffer)
4315 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4316 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4317 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4318 g_return_val_if_fail (*buffer == NULL
4319 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4321 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4325 * gst_pad_pull_range:
4326 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4327 * @offset: The start offset of the buffer
4328 * @size: The length of the buffer
4329 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4330 * GST_FLOW_ERROR if %NULL.
4332 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4334 * This function will first trigger the pad block signal if it was
4337 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4338 * function returns the result of gst_pad_get_range() on the peer pad.
4339 * See gst_pad_get_range() for a list of return values and for the
4340 * semantics of the arguments of this function.
4342 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4343 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4344 * must be freed with gst_buffer_unref() after usage. When this function
4345 * returns any other result value, @buffer will still point to NULL.
4347 * When @buffer points to a variable that points to a valid #GstBuffer, the
4348 * buffer will be filled with the result data when this function returns
4349 * #GST_FLOW_OK. When this function returns any other result value,
4350 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4351 * @size bytes will be filled in the result buffer and its size will be updated
4354 * Note that less than @size bytes can be returned in @buffer when, for example,
4355 * an EOS condition is near or when @buffer is not large enough to hold @size
4356 * bytes. The caller should check the result buffer size to get the result size.
4358 * Returns: a #GstFlowReturn from the peer pad.
4363 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4364 GstBuffer ** buffer)
4370 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4371 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4372 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4373 g_return_val_if_fail (*buffer == NULL
4374 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4376 GST_OBJECT_LOCK (pad);
4377 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4380 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4385 /* when one of the probes returns DROPPED, probe_stopped will be
4386 * called and we skip calling the peer getrange function. *buffer should then
4387 * contain a valid buffer */
4388 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4389 res_buf, offset, size, probe_stopped);
4391 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4394 gst_object_ref (peer);
4396 GST_OBJECT_UNLOCK (pad);
4398 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4400 gst_object_unref (peer);
4402 GST_OBJECT_LOCK (pad);
4404 if (pad->priv->using == 0) {
4405 /* pad is not active anymore, trigger idle callbacks */
4406 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4407 probe_stopped_unref, ret);
4410 if (G_UNLIKELY (ret != GST_FLOW_OK))
4411 goto pull_range_failed;
4414 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4415 res_buf, offset, size, probe_stopped_unref);
4417 GST_OBJECT_UNLOCK (pad);
4423 /* ERROR recovery here */
4426 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4427 "pullrange, but pad was flushing");
4428 GST_OBJECT_UNLOCK (pad);
4429 return GST_FLOW_FLUSHING;
4433 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4434 GST_DEBUG_PAD_NAME (pad));
4435 GST_OBJECT_UNLOCK (pad);
4436 return GST_FLOW_ERROR;
4440 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4441 gst_flow_get_name (ret));
4442 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4444 /* the probe filled the buffer and asks us to not forward to the peer
4445 * anymore, we continue with the post probes then */
4446 GST_DEBUG_OBJECT (pad, "handled buffer");
4450 /* no buffer, we are EOS then */
4451 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4455 GST_OBJECT_UNLOCK (pad);
4460 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4461 "pulling range, but it was not linked");
4462 GST_OBJECT_UNLOCK (pad);
4463 return GST_FLOW_NOT_LINKED;
4467 GST_OBJECT_UNLOCK (pad);
4468 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4469 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4470 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4473 probe_stopped_unref:
4475 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4476 "post probe returned %s", gst_flow_get_name (ret));
4477 GST_OBJECT_UNLOCK (pad);
4478 /* if we drop here, it signals EOS */
4479 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4481 if (*buffer == NULL)
4482 gst_buffer_unref (res_buf);
4487 /* must be called with pad object lock */
4488 static GstFlowReturn
4489 store_sticky_event (GstPad * pad, GstEvent * event)
4494 gboolean res = FALSE;
4495 const gchar *name = NULL;
4496 gboolean insert = TRUE;
4498 type = GST_EVENT_TYPE (event);
4500 /* Store all sticky events except SEGMENT/SEGMENT when we're flushing,
4501 * otherwise they can be dropped and nothing would ever resend them.
4502 * Only do that for activated pads though, everything else is a bug!
4504 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4505 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4506 || type == GST_EVENT_EOS))))
4509 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4512 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4513 name = gst_structure_get_name (gst_event_get_structure (event));
4515 events = pad->priv->events;
4518 for (i = 0; i < len; i++) {
4519 PadEvent *ev = &g_array_index (events, PadEvent, i);
4521 if (ev->event == NULL)
4524 if (type == GST_EVENT_TYPE (ev->event)) {
4525 /* matching types, check matching name if needed */
4526 if (name && !gst_event_has_name (ev->event, name))
4530 if ((res = gst_event_replace (&ev->event, event)))
4531 ev->received = FALSE;
4537 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4538 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4539 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4540 * storing the sticky ordered we can check that this is respected. */
4541 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4542 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4544 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4545 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4546 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4547 gst_event_type_get_name (type));
4553 ev.event = gst_event_ref (event);
4554 ev.received = FALSE;
4555 g_array_insert_val (events, i, ev);
4560 pad->priv->events_cookie++;
4561 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4563 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4565 switch (GST_EVENT_TYPE (event)) {
4566 case GST_EVENT_CAPS:
4567 GST_OBJECT_UNLOCK (pad);
4569 GST_DEBUG_OBJECT (pad, "notify caps");
4570 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4572 GST_OBJECT_LOCK (pad);
4578 if (type == GST_EVENT_EOS)
4579 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4581 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4586 GST_DEBUG_OBJECT (pad, "pad is flushing");
4587 return GST_FLOW_FLUSHING;
4591 GST_DEBUG_OBJECT (pad, "pad is EOS");
4592 return GST_FLOW_EOS;
4597 * gst_pad_store_sticky_event:
4599 * @event: a #GstEvent
4601 * Store the sticky @event on @pad
4603 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4604 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4609 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4613 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4614 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4616 GST_OBJECT_LOCK (pad);
4617 ret = store_sticky_event (pad, event);
4618 GST_OBJECT_UNLOCK (pad);
4624 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
4626 PushStickyData *data = user_data;
4628 /* Forward all sticky events before our current one that are pending */
4629 if (ev->event != data->event
4630 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
4631 return push_sticky (pad, ev, data);
4636 /* should be called with pad LOCK */
4637 static GstFlowReturn
4638 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4639 GstPadProbeType type)
4643 GstEventType event_type;
4645 /* Two checks to be made:
4646 * . (un)set the FLUSHING flag for flushing events,
4647 * . handle pad blocking */
4648 event_type = GST_EVENT_TYPE (event);
4649 switch (event_type) {
4650 case GST_EVENT_FLUSH_START:
4651 GST_PAD_SET_FLUSHING (pad);
4653 GST_PAD_BLOCK_BROADCAST (pad);
4654 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4656 case GST_EVENT_FLUSH_STOP:
4657 GST_PAD_UNSET_FLUSHING (pad);
4659 /* Remove sticky EOS events */
4660 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4661 remove_event_by_type (pad, GST_EVENT_EOS);
4662 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4663 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4665 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4669 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4672 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4673 * checked already or this is called as part of pushing sticky events,
4674 * in which case we still want to forward the EOS event downstream.
4677 switch (GST_EVENT_TYPE (event)) {
4678 case GST_EVENT_SEGMENT:
4679 /* pass the adjusted segment event on. We need to do this even if
4680 * there is no peer pad because of the probes. */
4681 event = apply_pad_offset (pad, event);
4683 case GST_EVENT_RECONFIGURE:
4684 if (GST_PAD_IS_SINK (pad))
4685 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4690 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4691 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4696 /* send probes after modifying the events above */
4697 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4699 /* recheck sticky events because the probe might have cause a relink */
4700 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
4701 && (GST_EVENT_IS_SERIALIZED (event)
4702 || GST_EVENT_IS_STICKY (event))) {
4703 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4704 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4706 /* Push all sticky events before our current one
4707 * that have changed */
4708 events_foreach (pad, sticky_changed, &data);
4711 /* now check the peer pad */
4712 peerpad = GST_PAD_PEER (pad);
4713 if (peerpad == NULL)
4716 gst_object_ref (peerpad);
4718 GST_OBJECT_UNLOCK (pad);
4720 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4721 event, GST_EVENT_TYPE_NAME (event), peerpad);
4723 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4725 /* Note: we gave away ownership of the event at this point but we can still
4726 * print the old pointer */
4727 GST_LOG_OBJECT (pad, "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s",
4728 event, peerpad, gst_flow_get_name (ret));
4730 gst_object_unref (peerpad);
4732 GST_OBJECT_LOCK (pad);
4734 if (pad->priv->using == 0) {
4735 /* pad is not active anymore, trigger idle callbacks */
4736 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4737 idle_probe_stopped, ret);
4741 /* ERROR handling */
4744 GST_DEBUG_OBJECT (pad, "We're flushing");
4745 gst_event_unref (event);
4746 return GST_FLOW_FLUSHING;
4750 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4751 gst_event_unref (event);
4754 case GST_FLOW_CUSTOM_SUCCESS:
4755 GST_DEBUG_OBJECT (pad, "dropped event");
4758 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4765 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4766 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4767 gst_event_unref (event);
4769 /* unlinked pads should not influence latency configuration */
4770 if (event_type == GST_EVENT_LATENCY)
4773 return GST_FLOW_NOT_LINKED;
4777 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4783 * gst_pad_push_event:
4784 * @pad: a #GstPad to push the event to.
4785 * @event: (transfer full): the #GstEvent to send to the pad.
4787 * Sends the event to the peer of the given pad. This function is
4788 * mainly used by elements to send events to their peer
4791 * This function takes ownership of the provided event so you should
4792 * gst_event_ref() it if you want to reuse the event after this call.
4794 * Returns: TRUE if the event was handled.
4799 gst_pad_push_event (GstPad * pad, GstEvent * event)
4801 gboolean res = FALSE;
4802 GstPadProbeType type;
4803 gboolean sticky, serialized;
4805 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4806 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4808 if (GST_PAD_IS_SRC (pad)) {
4809 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4810 goto wrong_direction;
4811 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4812 } else if (GST_PAD_IS_SINK (pad)) {
4813 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4814 goto wrong_direction;
4815 /* events pushed on sinkpad never are sticky */
4816 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4818 goto unknown_direction;
4820 GST_OBJECT_LOCK (pad);
4821 sticky = GST_EVENT_IS_STICKY (event);
4822 serialized = GST_EVENT_IS_SERIALIZED (event);
4825 /* srcpad sticky events are stored immediately, the received flag is set
4826 * to FALSE and will be set to TRUE when we can successfully push the
4827 * event to the peer pad */
4828 switch (store_sticky_event (pad, event)) {
4829 case GST_FLOW_FLUSHING:
4837 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4838 /* all serialized or sticky events on the srcpad trigger push of
4840 res = (check_sticky (pad, event) == GST_FLOW_OK);
4845 /* other events are pushed right away */
4846 ret = gst_pad_push_event_unchecked (pad, event, type);
4847 /* dropped events by a probe are not an error */
4848 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4850 /* Errors in sticky event pushing are no problem and ignored here
4851 * as they will cause more meaningful errors during data flow.
4852 * For EOS events, that are not followed by data flow, we still
4853 * return FALSE here though.
4855 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4857 gst_event_unref (event);
4859 GST_OBJECT_UNLOCK (pad);
4863 /* ERROR handling */
4866 g_warning ("pad %s:%s pushing %s event in wrong direction",
4867 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4868 gst_event_unref (event);
4873 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4874 gst_event_unref (event);
4879 GST_DEBUG_OBJECT (pad, "We're flushing");
4880 GST_OBJECT_UNLOCK (pad);
4881 gst_event_unref (event);
4886 GST_DEBUG_OBJECT (pad, "We're EOS");
4887 GST_OBJECT_UNLOCK (pad);
4888 gst_event_unref (event);
4893 /* Check if we can call the event function with the given event */
4894 static GstFlowReturn
4895 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4899 switch (GST_EVENT_TYPE (event)) {
4900 case GST_EVENT_CAPS:
4902 /* backwards compatibility mode for caps */
4903 gst_event_parse_caps (event, &caps);
4905 if (!gst_pad_query_accept_caps (pad, caps))
4917 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4918 "caps %" GST_PTR_FORMAT " not accepted", caps);
4919 return GST_FLOW_NOT_NEGOTIATED;
4923 static GstFlowReturn
4924 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4925 GstPadProbeType type)
4928 GstEventType event_type;
4929 gboolean serialized, need_unlock = FALSE, sticky;
4930 GstPadEventFunction eventfunc;
4933 GST_OBJECT_LOCK (pad);
4934 if (GST_PAD_IS_SINK (pad))
4935 serialized = GST_EVENT_IS_SERIALIZED (event);
4938 sticky = GST_EVENT_IS_STICKY (event);
4939 event_type = GST_EVENT_TYPE (event);
4940 switch (event_type) {
4941 case GST_EVENT_FLUSH_START:
4942 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4943 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4945 /* can't even accept a flush begin event when flushing */
4946 if (GST_PAD_IS_FLUSHING (pad))
4949 GST_PAD_SET_FLUSHING (pad);
4950 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4952 case GST_EVENT_FLUSH_STOP:
4953 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4954 GST_PAD_UNSET_FLUSHING (pad);
4955 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4957 /* Remove pending EOS events */
4958 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
4959 remove_event_by_type (pad, GST_EVENT_EOS);
4960 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4961 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4963 GST_OBJECT_UNLOCK (pad);
4964 /* grab stream lock */
4965 GST_PAD_STREAM_LOCK (pad);
4967 GST_OBJECT_LOCK (pad);
4968 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4971 case GST_EVENT_RECONFIGURE:
4972 if (GST_PAD_IS_SRC (pad))
4973 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4975 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4976 "have event type %" GST_PTR_FORMAT, event);
4978 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4982 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4985 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4986 GST_OBJECT_UNLOCK (pad);
4987 GST_PAD_STREAM_LOCK (pad);
4989 GST_OBJECT_LOCK (pad);
4990 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4993 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4997 switch (GST_EVENT_TYPE (event)) {
4998 case GST_EVENT_SEGMENT:
4999 event = apply_pad_offset (pad, event);
5007 /* now do the probe */
5009 type | GST_PAD_PROBE_TYPE_PUSH |
5010 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5012 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5014 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5017 ACQUIRE_PARENT (pad, parent, no_parent);
5018 GST_OBJECT_UNLOCK (pad);
5020 ret = pre_eventfunc_check (pad, event);
5021 if (G_UNLIKELY (ret != GST_FLOW_OK))
5022 goto precheck_failed;
5025 gst_event_ref (event);
5027 if (eventfunc (pad, parent, event)) {
5030 /* something went wrong */
5031 switch (event_type) {
5032 case GST_EVENT_CAPS:
5033 ret = GST_FLOW_NOT_NEGOTIATED;
5036 ret = GST_FLOW_ERROR;
5040 RELEASE_PARENT (parent);
5042 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5045 if (ret == GST_FLOW_OK) {
5046 GST_OBJECT_LOCK (pad);
5047 /* after the event function accepted the event, we can store the sticky
5048 * event on the pad */
5049 switch (store_sticky_event (pad, event)) {
5050 case GST_FLOW_FLUSHING:
5057 GST_OBJECT_UNLOCK (pad);
5059 gst_event_unref (event);
5063 GST_PAD_STREAM_UNLOCK (pad);
5067 /* ERROR handling */
5070 GST_OBJECT_UNLOCK (pad);
5072 GST_PAD_STREAM_UNLOCK (pad);
5073 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5074 "Received event on flushing pad. Discarding");
5075 gst_event_unref (event);
5076 return GST_FLOW_FLUSHING;
5080 GST_OBJECT_UNLOCK (pad);
5082 GST_PAD_STREAM_UNLOCK (pad);
5083 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5084 "Received event on EOS pad. Discarding");
5085 gst_event_unref (event);
5086 return GST_FLOW_EOS;
5090 GST_OBJECT_UNLOCK (pad);
5092 GST_PAD_STREAM_UNLOCK (pad);
5093 gst_event_unref (event);
5096 case GST_FLOW_CUSTOM_SUCCESS:
5097 GST_DEBUG_OBJECT (pad, "dropped event");
5101 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5108 g_warning ("pad %s:%s has no event handler, file a bug.",
5109 GST_DEBUG_PAD_NAME (pad));
5110 GST_OBJECT_UNLOCK (pad);
5112 GST_PAD_STREAM_UNLOCK (pad);
5113 gst_event_unref (event);
5114 return GST_FLOW_NOT_SUPPORTED;
5118 GST_DEBUG_OBJECT (pad, "no parent");
5119 GST_OBJECT_UNLOCK (pad);
5121 GST_PAD_STREAM_UNLOCK (pad);
5122 gst_event_unref (event);
5123 return GST_FLOW_FLUSHING;
5127 GST_DEBUG_OBJECT (pad, "pre event check failed");
5128 RELEASE_PARENT (parent);
5130 GST_PAD_STREAM_UNLOCK (pad);
5131 gst_event_unref (event);
5137 * gst_pad_send_event:
5138 * @pad: a #GstPad to send the event to.
5139 * @event: (transfer full): the #GstEvent to send to the pad.
5141 * Sends the event to the pad. This function can be used
5142 * by applications to send events in the pipeline.
5144 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5145 * sink pad, @event should be a downstream event. For example, you would not
5146 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5147 * Furthermore, some downstream events have to be serialized with data flow,
5148 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5149 * the event needs to be serialized with data flow, this function will take the
5150 * pad's stream lock while calling its event function.
5152 * To find out whether an event type is upstream, downstream, or downstream and
5153 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5154 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5155 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5156 * plugin doesn't need to bother itself with this information; the core handles
5157 * all necessary locks and checks.
5159 * This function takes ownership of the provided event so you should
5160 * gst_event_ref() it if you want to reuse the event after this call.
5162 * Returns: TRUE if the event was handled.
5165 gst_pad_send_event (GstPad * pad, GstEvent * event)
5168 GstPadProbeType type;
5170 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5171 g_return_val_if_fail (event != NULL, FALSE);
5173 if (GST_PAD_IS_SINK (pad)) {
5174 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5175 goto wrong_direction;
5176 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5177 } else if (GST_PAD_IS_SRC (pad)) {
5178 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5179 goto wrong_direction;
5180 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5182 goto unknown_direction;
5184 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5191 /* ERROR handling */
5194 g_warning ("pad %s:%s sending %s event in wrong direction",
5195 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5196 gst_event_unref (event);
5201 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5202 gst_event_unref (event);
5208 * gst_pad_set_element_private:
5209 * @pad: the #GstPad to set the private data of.
5210 * @priv: The private data to attach to the pad.
5212 * Set the given private data gpointer on the pad.
5213 * This function can only be used by the element that owns the pad.
5214 * No locking is performed in this function.
5217 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5219 pad->element_private = priv;
5223 * gst_pad_get_element_private:
5224 * @pad: the #GstPad to get the private data of.
5226 * Gets the private data of a pad.
5227 * No locking is performed in this function.
5229 * Returns: (transfer none): a #gpointer to the private data.
5232 gst_pad_get_element_private (GstPad * pad)
5234 return pad->element_private;
5238 * gst_pad_get_sticky_event:
5239 * @pad: the #GstPad to get the event from.
5240 * @event_type: the #GstEventType that should be retrieved.
5241 * @idx: the index of the event
5243 * Returns a new reference of the sticky event of type @event_type
5246 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
5247 * event of @event_type was on @pad. Unref after usage.
5250 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5252 GstEvent *event = NULL;
5255 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5256 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5258 GST_OBJECT_LOCK (pad);
5259 ev = find_event_by_type (pad, event_type, idx);
5260 if (ev && (event = ev->event))
5261 gst_event_ref (event);
5262 GST_OBJECT_UNLOCK (pad);
5269 GstPadStickyEventsForeachFunction func;
5274 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5276 ForeachDispatch *data = user_data;
5277 gboolean ret = TRUE;
5280 GST_OBJECT_UNLOCK (pad);
5282 ret = data->func (pad, &ev->event, data->user_data);
5284 GST_OBJECT_LOCK (pad);
5291 * gst_pad_sticky_events_foreach:
5292 * @pad: the #GstPad that should be used for iteration.
5293 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5294 * should be called for every event.
5295 * @user_data: (closure): the optional user data.
5297 * Iterates all sticky events on @pad and calls @foreach_func for every
5298 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5301 gst_pad_sticky_events_foreach (GstPad * pad,
5302 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5304 ForeachDispatch data;
5306 g_return_if_fail (GST_IS_PAD (pad));
5307 g_return_if_fail (foreach_func != NULL);
5309 data.func = foreach_func;
5310 data.user_data = user_data;
5312 GST_OBJECT_LOCK (pad);
5313 events_foreach (pad, foreach_dispatch_function, &data);
5314 GST_OBJECT_UNLOCK (pad);
5318 do_stream_status (GstPad * pad, GstStreamStatusType type,
5319 GThread * thread, GstTask * task)
5323 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5325 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5326 if (GST_IS_ELEMENT (parent)) {
5327 GstMessage *message;
5328 GValue value = { 0 };
5330 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5331 gchar *tname, *ename, *pname;
5333 /* create a good task name */
5334 ename = gst_element_get_name (parent);
5335 pname = gst_pad_get_name (pad);
5336 tname = g_strdup_printf ("%s:%s", ename, pname);
5340 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5344 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5347 g_value_init (&value, GST_TYPE_TASK);
5348 g_value_set_object (&value, task);
5349 gst_message_set_stream_status_object (message, &value);
5350 g_value_unset (&value);
5352 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5353 gst_element_post_message (parent, message);
5355 gst_object_unref (parent);
5360 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5362 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5367 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5369 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5374 * gst_pad_start_task:
5375 * @pad: the #GstPad to start the task of
5376 * @func: the task function to call
5377 * @user_data: user data passed to the task function
5378 * @notify: called when @user_data is no longer referenced
5380 * Starts a task that repeatedly calls @func with @user_data. This function
5381 * is mostly used in pad activation functions to start the dataflow.
5382 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5383 * before @func is called.
5385 * Returns: a %TRUE if the task could be started.
5388 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5389 GDestroyNotify notify)
5394 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5395 g_return_val_if_fail (func != NULL, FALSE);
5397 GST_DEBUG_OBJECT (pad, "start task");
5399 GST_OBJECT_LOCK (pad);
5400 task = GST_PAD_TASK (pad);
5402 task = gst_task_new (func, user_data, notify);
5403 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5404 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5405 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5406 GST_INFO_OBJECT (pad, "created task %p", task);
5407 GST_PAD_TASK (pad) = task;
5408 gst_object_ref (task);
5409 /* release lock to post the message */
5410 GST_OBJECT_UNLOCK (pad);
5412 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5414 gst_object_unref (task);
5416 GST_OBJECT_LOCK (pad);
5417 /* nobody else is supposed to have changed the pad now */
5418 if (GST_PAD_TASK (pad) != task)
5419 goto concurrent_stop;
5421 res = gst_task_set_state (task, GST_TASK_STARTED);
5422 GST_OBJECT_UNLOCK (pad);
5429 GST_OBJECT_UNLOCK (pad);
5435 * gst_pad_pause_task:
5436 * @pad: the #GstPad to pause the task of
5438 * Pause the task of @pad. This function will also wait until the
5439 * function executed by the task is finished if this function is not
5440 * called from the task function.
5442 * Returns: a TRUE if the task could be paused or FALSE when the pad
5446 gst_pad_pause_task (GstPad * pad)
5451 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5453 GST_DEBUG_OBJECT (pad, "pause task");
5455 GST_OBJECT_LOCK (pad);
5456 task = GST_PAD_TASK (pad);
5459 res = gst_task_set_state (task, GST_TASK_PAUSED);
5460 GST_OBJECT_UNLOCK (pad);
5462 /* wait for task function to finish, this lock is recursive so it does nothing
5463 * when the pause is called from the task itself */
5464 GST_PAD_STREAM_LOCK (pad);
5465 GST_PAD_STREAM_UNLOCK (pad);
5471 GST_DEBUG_OBJECT (pad, "pad has no task");
5472 GST_OBJECT_UNLOCK (pad);
5478 * gst_pad_stop_task:
5479 * @pad: the #GstPad to stop the task of
5481 * Stop the task of @pad. This function will also make sure that the
5482 * function executed by the task will effectively stop if not called
5483 * from the GstTaskFunction.
5485 * This function will deadlock if called from the GstTaskFunction of
5486 * the task. Use gst_task_pause() instead.
5488 * Regardless of whether the pad has a task, the stream lock is acquired and
5489 * released so as to ensure that streaming through this pad has finished.
5491 * Returns: a TRUE if the task could be stopped or FALSE on error.
5494 gst_pad_stop_task (GstPad * pad)
5499 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5501 GST_DEBUG_OBJECT (pad, "stop task");
5503 GST_OBJECT_LOCK (pad);
5504 task = GST_PAD_TASK (pad);
5507 GST_PAD_TASK (pad) = NULL;
5508 res = gst_task_set_state (task, GST_TASK_STOPPED);
5509 GST_OBJECT_UNLOCK (pad);
5511 GST_PAD_STREAM_LOCK (pad);
5512 GST_PAD_STREAM_UNLOCK (pad);
5514 if (!gst_task_join (task))
5517 gst_object_unref (task);
5523 GST_DEBUG_OBJECT (pad, "no task");
5524 GST_OBJECT_UNLOCK (pad);
5526 GST_PAD_STREAM_LOCK (pad);
5527 GST_PAD_STREAM_UNLOCK (pad);
5529 /* this is not an error */
5534 /* this is bad, possibly the application tried to join the task from
5535 * the task's thread. We install the task again so that it will be stopped
5536 * again from the right thread next time hopefully. */
5537 GST_OBJECT_LOCK (pad);
5538 GST_DEBUG_OBJECT (pad, "join failed");
5539 /* we can only install this task if there was no other task */
5540 if (GST_PAD_TASK (pad) == NULL)
5541 GST_PAD_TASK (pad) = task;
5542 GST_OBJECT_UNLOCK (pad);
5549 * gst_pad_probe_info_get_event:
5550 * @info: a #GstPadProbeInfo
5552 * Returns: (transfer none): The #GstEvent from the probe
5556 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5558 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5559 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5561 return GST_PAD_PROBE_INFO_EVENT (info);
5566 * gst_pad_probe_info_get_query:
5567 * @info: a #GstPadProbeInfo
5569 * Returns: (transfer none): The #GstQuery from the probe
5573 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5575 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5576 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5578 return GST_PAD_PROBE_INFO_QUERY (info);
5582 * gst_pad_probe_info_get_buffer:
5583 * @info: a #GstPadProbeInfo
5585 * Returns: (transfer none): The #GstBuffer from the probe
5589 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5591 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5593 return GST_PAD_PROBE_INFO_BUFFER (info);
5597 * gst_pad_probe_info_get_bufferlist:
5598 * @info: a #GstPadProbeInfo
5600 * Returns: (transfer none): The #GstBufferlist from the probe
5604 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5606 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5608 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);