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()
89 #include "gst_private.h"
92 #include "gstpadtemplate.h"
93 #include "gstenumtypes.h"
98 #include "glib-compat-private.h"
100 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
101 #define GST_CAT_DEFAULT GST_CAT_PADS
103 /* Pad signals and args */
121 #define GST_PAD_GET_PRIVATE(obj) \
122 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
124 /* we have a pending and an active event on the pad. On source pads only the
125 * active event is used. On sinkpads, events are copied to the pending entry and
126 * moved to the active event when the eventfunc returned %TRUE. */
133 struct _GstPadPrivate
140 guint probe_list_cookie;
150 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
155 GstPadProbeInfo *info;
162 static void gst_pad_dispose (GObject * object);
163 static void gst_pad_finalize (GObject * object);
164 static void gst_pad_set_property (GObject * object, guint prop_id,
165 const GValue * value, GParamSpec * pspec);
166 static void gst_pad_get_property (GObject * object, guint prop_id,
167 GValue * value, GParamSpec * pspec);
169 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
170 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
171 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
172 GstObject * parent, GstBufferList * list);
174 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
175 GstEvent * event, GstPadProbeType type);
176 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
177 GstEvent * event, GstPadProbeType type);
179 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
181 static GParamSpec *pspec_caps = NULL;
183 /* quarks for probe signals */
184 static GQuark buffer_quark;
185 static GQuark buffer_list_quark;
186 static GQuark event_quark;
195 static GstFlowQuarks flow_quarks[] = {
196 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
197 {GST_FLOW_OK, "ok", 0},
198 {GST_FLOW_NOT_LINKED, "not-linked", 0},
199 {GST_FLOW_FLUSHING, "flushing", 0},
200 {GST_FLOW_EOS, "eos", 0},
201 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
202 {GST_FLOW_ERROR, "error", 0},
203 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
204 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
209 * @ret: a #GstFlowReturn to get the name of.
211 * Gets a string representing the given flow return.
213 * Returns: a static string with the name of the flow return.
216 gst_flow_get_name (GstFlowReturn ret)
220 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
222 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
223 if (ret == flow_quarks[i].ret)
224 return flow_quarks[i].name;
231 * @ret: a #GstFlowReturn to get the quark of.
233 * Get the unique quark for the given GstFlowReturn.
235 * Returns: the quark associated with the flow return or 0 if an
236 * invalid return was specified.
239 gst_flow_to_quark (GstFlowReturn ret)
243 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
245 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
246 if (ret == flow_quarks[i].ret)
247 return flow_quarks[i].quark;
253 * gst_pad_link_get_name:
254 * @ret: a #GstPadLinkReturn to get the name of.
256 * Gets a string representing the given pad-link return.
258 * Returns: a static string with the name of the pad-link return.
263 gst_pad_link_get_name (GstPadLinkReturn ret)
266 case GST_PAD_LINK_OK:
268 case GST_PAD_LINK_WRONG_HIERARCHY:
269 return "wrong hierarchy";
270 case GST_PAD_LINK_WAS_LINKED:
272 case GST_PAD_LINK_WRONG_DIRECTION:
273 return "wrong direction";
274 case GST_PAD_LINK_NOFORMAT:
275 return "no common format";
276 case GST_PAD_LINK_NOSCHED:
277 return "incompatible scheduling";
278 case GST_PAD_LINK_REFUSED:
281 g_return_val_if_reached ("unknown");
288 buffer_quark = g_quark_from_static_string ("buffer"); \
289 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
290 event_quark = g_quark_from_static_string ("event"); \
292 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
293 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
296 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
297 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
300 #define gst_pad_parent_class parent_class
301 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
304 gst_pad_class_init (GstPadClass * klass)
306 GObjectClass *gobject_class;
307 GstObjectClass *gstobject_class;
309 gobject_class = G_OBJECT_CLASS (klass);
310 gstobject_class = GST_OBJECT_CLASS (klass);
312 g_type_class_add_private (klass, sizeof (GstPadPrivate));
314 gobject_class->dispose = gst_pad_dispose;
315 gobject_class->finalize = gst_pad_finalize;
316 gobject_class->set_property = gst_pad_set_property;
317 gobject_class->get_property = gst_pad_get_property;
321 * @pad: the pad that emitted the signal
322 * @peer: the peer pad that has been connected
324 * Signals that a pad has been linked to the peer pad.
326 gst_pad_signals[PAD_LINKED] =
327 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
328 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
329 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
332 * @pad: the pad that emitted the signal
333 * @peer: the peer pad that has been disconnected
335 * Signals that a pad has been unlinked from the peer pad.
337 gst_pad_signals[PAD_UNLINKED] =
338 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
339 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
340 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
342 pspec_caps = g_param_spec_boxed ("caps", "Caps",
343 "The capabilities of the pad", GST_TYPE_CAPS,
344 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
345 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
347 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
348 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
349 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
350 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
352 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
353 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
354 g_param_spec_object ("template", "Template",
355 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
356 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
358 gstobject_class->path_string_separator = ".";
360 /* Register common function pointer descriptions */
361 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
362 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
363 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
364 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
365 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
369 gst_pad_init (GstPad * pad)
371 pad->priv = GST_PAD_GET_PRIVATE (pad);
373 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
375 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
376 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
377 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
378 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
379 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
381 GST_PAD_SET_FLUSHING (pad);
383 g_rec_mutex_init (&pad->stream_rec_lock);
385 g_cond_init (&pad->block_cond);
387 g_hook_list_init (&pad->probes, sizeof (GstProbe));
389 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
390 pad->priv->events_cookie = 0;
391 pad->priv->last_cookie = -1;
392 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
395 /* called when setting the pad inactive. It removes all sticky events from
396 * the pad. must be called with object lock */
398 remove_events (GstPad * pad)
402 gboolean notify = FALSE;
404 events = pad->priv->events;
407 for (i = 0; i < len; i++) {
408 PadEvent *ev = &g_array_index (events, PadEvent, i);
409 GstEvent *event = ev->event;
413 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
416 gst_event_unref (event);
419 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
420 g_array_set_size (events, 0);
421 pad->priv->events_cookie++;
424 GST_OBJECT_UNLOCK (pad);
426 GST_DEBUG_OBJECT (pad, "notify caps");
427 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
429 GST_OBJECT_LOCK (pad);
433 /* should be called with object lock */
435 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
441 events = pad->priv->events;
444 for (i = 0; i < len; i++) {
445 ev = &g_array_index (events, PadEvent, i);
446 if (ev->event == NULL)
449 if (GST_EVENT_TYPE (ev->event) == type) {
460 /* should be called with OBJECT lock */
462 find_event (GstPad * pad, GstEvent * event)
468 events = pad->priv->events;
471 for (i = 0; i < len; i++) {
472 ev = &g_array_index (events, PadEvent, i);
473 if (event == ev->event)
481 /* should be called with OBJECT lock */
483 remove_event_by_type (GstPad * pad, GstEventType type)
489 events = pad->priv->events;
494 ev = &g_array_index (events, PadEvent, i);
495 if (ev->event == NULL)
498 if (GST_EVENT_TYPE (ev->event) != type)
501 gst_event_unref (ev->event);
502 g_array_remove_index (events, i);
504 pad->priv->events_cookie++;
512 /* check all events on srcpad against those on sinkpad. All events that are not
513 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
514 * srcpad so that the events will be sent next time */
515 /* should be called with srcpad and sinkpad LOCKS */
517 schedule_events (GstPad * srcpad, GstPad * sinkpad)
522 gboolean pending = FALSE;
524 events = srcpad->priv->events;
527 for (i = 0; i < len; i++) {
528 ev = &g_array_index (events, PadEvent, i);
529 if (ev->event == NULL)
532 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
533 ev->received = FALSE;
538 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
541 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
544 /* should be called with pad LOCK */
546 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
553 events = pad->priv->events;
556 cookie = pad->priv->events_cookie;
560 PadEvent *ev, ev_ret;
562 ev = &g_array_index (events, PadEvent, i);
563 if (G_UNLIKELY (ev->event == NULL))
566 /* take aditional ref, func might release the lock */
567 ev_ret.event = gst_event_ref (ev->event);
568 ev_ret.received = ev->received;
570 ret = func (pad, &ev_ret, user_data);
572 /* recheck the cookie, lock might have been released and the list could have
574 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
575 if (G_LIKELY (ev_ret.event))
576 gst_event_unref (ev_ret.event);
580 /* store the received state */
581 ev->received = ev_ret.received;
583 /* if the event changed, we need to do something */
584 if (G_UNLIKELY (ev->event != ev_ret.event)) {
585 if (G_UNLIKELY (ev_ret.event == NULL)) {
586 /* function unreffed and set the event to NULL, remove it */
587 gst_event_unref (ev->event);
588 g_array_remove_index (events, i);
590 cookie = ++pad->priv->events_cookie;
593 /* function gave a new event for us */
594 gst_event_take (&ev->event, ev_ret.event);
597 /* just unref, nothing changed */
598 gst_event_unref (ev_ret.event);
607 /* should be called with LOCK */
609 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
611 /* check if we need to adjust the segment */
612 if (pad->offset != 0) {
615 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_TIME_FORMAT,
616 GST_TIME_ARGS (pad->offset));
618 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
621 g_assert (!upstream);
623 /* copy segment values */
624 gst_event_copy_segment (event, &segment);
625 gst_event_unref (event);
627 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
628 event = gst_event_new_segment (&segment);
631 event = gst_event_make_writable (event);
632 offset = gst_event_get_running_time_offset (event);
634 offset -= pad->offset;
636 offset += pad->offset;
637 gst_event_set_running_time_offset (event, offset);
642 /* should be called with the OBJECT_LOCK */
644 get_pad_caps (GstPad * pad)
646 GstCaps *caps = NULL;
649 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
651 gst_event_parse_caps (ev->event, &caps);
657 gst_pad_dispose (GObject * object)
659 GstPad *pad = GST_PAD_CAST (object);
662 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
664 /* unlink the peer pad */
665 if ((peer = gst_pad_get_peer (pad))) {
666 /* window for MT unsafeness, someone else could unlink here
667 * and then we call unlink with wrong pads. The unlink
668 * function would catch this and safely return failed. */
669 if (GST_PAD_IS_SRC (pad))
670 gst_pad_unlink (pad, peer);
672 gst_pad_unlink (peer, pad);
674 gst_object_unref (peer);
677 gst_pad_set_pad_template (pad, NULL);
679 GST_OBJECT_LOCK (pad);
681 GST_OBJECT_UNLOCK (pad);
683 g_hook_list_clear (&pad->probes);
685 G_OBJECT_CLASS (parent_class)->dispose (object);
689 gst_pad_finalize (GObject * object)
691 GstPad *pad = GST_PAD_CAST (object);
694 /* in case the task is still around, clean it up */
695 if ((task = GST_PAD_TASK (pad))) {
696 gst_task_join (task);
697 GST_PAD_TASK (pad) = NULL;
698 gst_object_unref (task);
701 if (pad->activatenotify)
702 pad->activatenotify (pad->activatedata);
703 if (pad->activatemodenotify)
704 pad->activatemodenotify (pad->activatemodedata);
706 pad->linknotify (pad->linkdata);
707 if (pad->unlinknotify)
708 pad->unlinknotify (pad->unlinkdata);
709 if (pad->chainnotify)
710 pad->chainnotify (pad->chaindata);
711 if (pad->chainlistnotify)
712 pad->chainlistnotify (pad->chainlistdata);
713 if (pad->getrangenotify)
714 pad->getrangenotify (pad->getrangedata);
715 if (pad->eventnotify)
716 pad->eventnotify (pad->eventdata);
717 if (pad->querynotify)
718 pad->querynotify (pad->querydata);
719 if (pad->iterintlinknotify)
720 pad->iterintlinknotify (pad->iterintlinkdata);
722 g_rec_mutex_clear (&pad->stream_rec_lock);
723 g_cond_clear (&pad->block_cond);
724 g_array_free (pad->priv->events, TRUE);
726 G_OBJECT_CLASS (parent_class)->finalize (object);
730 gst_pad_set_property (GObject * object, guint prop_id,
731 const GValue * value, GParamSpec * pspec)
733 g_return_if_fail (GST_IS_PAD (object));
736 case PAD_PROP_DIRECTION:
737 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
739 case PAD_PROP_TEMPLATE:
740 gst_pad_set_pad_template (GST_PAD_CAST (object),
741 (GstPadTemplate *) g_value_get_object (value));
744 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
750 gst_pad_get_property (GObject * object, guint prop_id,
751 GValue * value, GParamSpec * pspec)
753 g_return_if_fail (GST_IS_PAD (object));
757 GST_OBJECT_LOCK (object);
758 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
759 GST_OBJECT_UNLOCK (object);
761 case PAD_PROP_DIRECTION:
762 g_value_set_enum (value, GST_PAD_DIRECTION (object));
764 case PAD_PROP_TEMPLATE:
765 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
768 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
775 * @name: (allow-none): the name of the new pad.
776 * @direction: the #GstPadDirection of the pad.
778 * Creates a new pad with the given name in the given direction.
779 * If name is %NULL, a guaranteed unique name (across all pads)
781 * This function makes a copy of the name so you can safely free the name.
783 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
789 gst_pad_new (const gchar * name, GstPadDirection direction)
791 return g_object_new (GST_TYPE_PAD,
792 "name", name, "direction", direction, NULL);
796 * gst_pad_new_from_template:
797 * @templ: the pad template to use
798 * @name: (allow-none): the name of the pad
800 * Creates a new pad with the given name from the given template.
801 * If name is %NULL, a guaranteed unique name (across all pads)
803 * This function makes a copy of the name so you can safely free the name.
805 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
809 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
811 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
813 return g_object_new (GST_TYPE_PAD,
814 "name", name, "direction", templ->direction, "template", templ, NULL);
818 * gst_pad_new_from_static_template:
819 * @templ: the #GstStaticPadTemplate to use
820 * @name: the name of the pad
822 * Creates a new pad with the given name from the given static template.
823 * If name is %NULL, a guaranteed unique name (across all pads)
825 * This function makes a copy of the name so you can safely free the name.
827 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
831 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
835 GstPadTemplate *template;
837 template = gst_static_pad_template_get (templ);
838 pad = gst_pad_new_from_template (template, name);
839 gst_object_unref (template);
843 #define ACQUIRE_PARENT(pad, parent, label) \
845 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
846 gst_object_ref (parent); \
847 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
851 #define RELEASE_PARENT(parent) \
853 if (G_LIKELY (parent)) \
854 gst_object_unref (parent); \
858 * gst_pad_get_direction:
859 * @pad: a #GstPad to get the direction of.
861 * Gets the direction of the pad. The direction of the pad is
862 * decided at construction time so this function does not take
865 * Returns: the #GstPadDirection of the pad.
870 gst_pad_get_direction (GstPad * pad)
872 GstPadDirection result;
874 /* PAD_UNKNOWN is a little silly but we need some sort of
875 * error return value */
876 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
878 result = GST_PAD_DIRECTION (pad);
884 gst_pad_activate_default (GstPad * pad, GstObject * parent)
886 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
890 * gst_pad_mode_get_name:
891 * @mode: the pad mode
893 * Return the name of a pad mode, for use in debug messages mostly.
895 * Returns: short mnemonic for pad mode @mode
898 gst_pad_mode_get_name (GstPadMode mode)
901 case GST_PAD_MODE_NONE:
903 case GST_PAD_MODE_PUSH:
905 case GST_PAD_MODE_PULL:
914 pre_activate (GstPad * pad, GstPadMode new_mode)
917 case GST_PAD_MODE_NONE:
918 GST_OBJECT_LOCK (pad);
919 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
920 GST_PAD_SET_FLUSHING (pad);
921 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
922 GST_PAD_MODE (pad) = new_mode;
923 /* unlock blocked pads so element can resume and stop */
924 GST_PAD_BLOCK_BROADCAST (pad);
925 GST_OBJECT_UNLOCK (pad);
927 case GST_PAD_MODE_PUSH:
928 case GST_PAD_MODE_PULL:
929 GST_OBJECT_LOCK (pad);
930 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
931 gst_pad_mode_get_name (new_mode));
932 GST_PAD_UNSET_FLUSHING (pad);
933 pad->ABI.abi.last_flowret = GST_FLOW_OK;
934 GST_PAD_MODE (pad) = new_mode;
935 if (GST_PAD_IS_SINK (pad)) {
937 /* make sure the peer src pad sends us all events */
938 if ((peer = GST_PAD_PEER (pad))) {
939 gst_object_ref (peer);
940 GST_OBJECT_UNLOCK (pad);
942 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
943 GST_DEBUG_PAD_NAME (peer));
945 GST_OBJECT_LOCK (peer);
946 schedule_events (peer, NULL);
947 GST_OBJECT_UNLOCK (peer);
949 gst_object_unref (peer);
951 GST_OBJECT_UNLOCK (pad);
954 GST_OBJECT_UNLOCK (pad);
961 post_activate (GstPad * pad, GstPadMode new_mode)
964 case GST_PAD_MODE_NONE:
965 /* ensures that streaming stops */
966 GST_PAD_STREAM_LOCK (pad);
967 GST_DEBUG_OBJECT (pad, "stopped streaming");
968 GST_OBJECT_LOCK (pad);
970 GST_OBJECT_UNLOCK (pad);
971 GST_PAD_STREAM_UNLOCK (pad);
973 case GST_PAD_MODE_PUSH:
974 case GST_PAD_MODE_PULL:
981 * gst_pad_set_active:
982 * @pad: the #GstPad to activate or deactivate.
983 * @active: whether or not the pad should be active.
985 * Activates or deactivates the given pad.
986 * Normally called from within core state change functions.
988 * If @active, makes sure the pad is active. If it is already active, either in
989 * push or pull mode, just return. Otherwise dispatches to the pad's activate
990 * function to perform the actual activation.
992 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
993 * and a %FALSE argument.
995 * Returns: %TRUE if the operation was successful.
1000 gst_pad_set_active (GstPad * pad, gboolean active)
1004 gboolean ret = FALSE;
1006 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1008 GST_OBJECT_LOCK (pad);
1009 old = GST_PAD_MODE (pad);
1010 ACQUIRE_PARENT (pad, parent, no_parent);
1011 GST_OBJECT_UNLOCK (pad);
1014 if (old == GST_PAD_MODE_NONE) {
1015 GST_DEBUG_OBJECT (pad, "activating pad from none");
1016 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1018 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1020 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1021 gst_pad_mode_get_name (old));
1025 if (old == GST_PAD_MODE_NONE) {
1026 GST_DEBUG_OBJECT (pad, "pad was inactive");
1029 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1030 gst_pad_mode_get_name (old));
1031 ret = gst_pad_activate_mode (pad, old, FALSE);
1033 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1037 RELEASE_PARENT (parent);
1039 if (G_UNLIKELY (!ret))
1047 GST_DEBUG_OBJECT (pad, "no parent");
1048 GST_OBJECT_UNLOCK (pad);
1053 GST_OBJECT_LOCK (pad);
1055 g_critical ("Failed to deactivate pad %s:%s, very bad",
1056 GST_DEBUG_PAD_NAME (pad));
1058 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1060 GST_OBJECT_UNLOCK (pad);
1066 * gst_pad_activate_mode:
1067 * @pad: the #GstPad to activate or deactivate.
1068 * @mode: the requested activation mode
1069 * @active: whether or not the pad should be active.
1071 * Activates or deactivates the given pad in @mode via dispatching to the
1072 * pad's activatemodefunc. For use from within pad activation functions only.
1074 * If you don't know what this is, you probably don't want to call it.
1076 * Returns: %TRUE if the operation was successful.
1081 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1083 gboolean res = FALSE;
1085 GstPadMode old, new;
1086 GstPadDirection dir;
1089 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1091 GST_OBJECT_LOCK (pad);
1092 old = GST_PAD_MODE (pad);
1093 dir = GST_PAD_DIRECTION (pad);
1094 ACQUIRE_PARENT (pad, parent, no_parent);
1095 GST_OBJECT_UNLOCK (pad);
1097 new = active ? mode : GST_PAD_MODE_NONE;
1102 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1103 /* pad was activate in the wrong direction, deactivate it
1104 * and reactivate it in the requested mode */
1105 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1106 gst_pad_mode_get_name (old));
1108 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1109 goto deactivate_failed;
1113 case GST_PAD_MODE_PULL:
1115 if (dir == GST_PAD_SINK) {
1116 if ((peer = gst_pad_get_peer (pad))) {
1117 GST_DEBUG_OBJECT (pad, "calling peer");
1118 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1120 gst_object_unref (peer);
1122 /* there is no peer, this is only fatal when we activate. When we
1123 * deactivate, we must assume the application has unlinked the peer and
1124 * will deactivate it eventually. */
1128 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1131 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1132 goto failure; /* Can't activate pull on a src without a
1133 getrange function */
1141 /* Mark pad as needing reconfiguration */
1143 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1144 pre_activate (pad, new);
1146 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1147 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1151 /* can happen for sinks of passthrough elements */
1154 post_activate (pad, new);
1156 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1157 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1162 /* Clear sticky flags on deactivation */
1164 GST_OBJECT_LOCK (pad);
1165 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1166 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1167 GST_OBJECT_UNLOCK (pad);
1171 RELEASE_PARENT (parent);
1177 GST_DEBUG_OBJECT (pad, "no parent");
1178 GST_OBJECT_UNLOCK (pad);
1183 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1184 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1189 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1190 "failed to %s in switch to %s mode from %s mode",
1191 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1192 gst_pad_mode_get_name (old));
1197 GST_OBJECT_LOCK (peer);
1198 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1199 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1200 GST_OBJECT_UNLOCK (peer);
1201 gst_object_unref (peer);
1206 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1207 "pad in pull mode");
1212 GST_OBJECT_LOCK (pad);
1213 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1214 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1215 GST_PAD_SET_FLUSHING (pad);
1216 GST_PAD_MODE (pad) = old;
1217 GST_OBJECT_UNLOCK (pad);
1223 * gst_pad_is_active:
1224 * @pad: the #GstPad to query
1226 * Query if a pad is active
1228 * Returns: %TRUE if the pad is active.
1233 gst_pad_is_active (GstPad * pad)
1235 gboolean result = FALSE;
1237 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1239 GST_OBJECT_LOCK (pad);
1240 result = GST_PAD_IS_ACTIVE (pad);
1241 GST_OBJECT_UNLOCK (pad);
1247 cleanup_hook (GstPad * pad, GHook * hook)
1249 GstPadProbeType type;
1251 if (!G_HOOK_IS_VALID (hook))
1254 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1256 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1257 /* unblock when we remove the last blocking probe */
1259 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1262 /* Might have new probes now that want to be called */
1263 GST_PAD_BLOCK_BROADCAST (pad);
1265 if (pad->num_blocked == 0) {
1266 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1267 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1270 g_hook_destroy_link (&pad->probes, hook);
1275 * gst_pad_add_probe:
1276 * @pad: the #GstPad to add the probe to
1277 * @mask: the probe mask
1278 * @callback: #GstPadProbeCallback that will be called with notifications of
1280 * @user_data: (closure): user data passed to the callback
1281 * @destroy_data: #GDestroyNotify for user_data
1283 * Be notified of different states of pads. The provided callback is called for
1284 * every state that matches @mask.
1286 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1287 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1288 * happend that the probe can be run immediately and if the probe returns
1289 * GST_PAD_PROBE_REMOVE this functions returns 0.
1294 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1295 GstPadProbeCallback callback, gpointer user_data,
1296 GDestroyNotify destroy_data)
1301 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1302 g_return_val_if_fail (mask != 0, 0);
1304 GST_OBJECT_LOCK (pad);
1306 /* make a new probe */
1307 hook = g_hook_alloc (&pad->probes);
1309 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1312 /* when no contraints are given for the types, assume all types are
1314 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1315 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1316 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1317 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1319 /* store our flags and other fields */
1320 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1321 hook->func = callback;
1322 hook->data = user_data;
1323 hook->destroy = destroy_data;
1324 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1327 g_hook_prepend (&pad->probes, hook);
1329 /* incremenent cookie so that the new hook get's called */
1330 pad->priv->probe_list_cookie++;
1332 /* get the id of the hook, we return this and it can be used to remove the
1334 res = hook->hook_id;
1336 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1338 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1339 /* we have a block probe */
1341 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1342 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1343 "now %d blocking probes", pad->num_blocked);
1345 /* Might have new probes now that want to be called */
1346 GST_PAD_BLOCK_BROADCAST (pad);
1349 /* call the callback if we need to be called for idle callbacks */
1350 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1351 if (pad->priv->using > 0) {
1352 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1353 * flag above, the last thread to leave the push will do the callback. New
1354 * threads going into the push will block. */
1355 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1356 "pad is in use, delay idle callback");
1357 GST_OBJECT_UNLOCK (pad);
1359 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1360 GstPadProbeReturn ret;
1362 /* Keep another ref, the callback could destroy the pad */
1363 gst_object_ref (pad);
1365 /* the pad is idle now, we can signal the idle callback now */
1366 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1367 "pad is idle, trigger idle callback");
1368 GST_OBJECT_UNLOCK (pad);
1370 ret = callback (pad, &info, user_data);
1372 GST_OBJECT_LOCK (pad);
1374 case GST_PAD_PROBE_REMOVE:
1375 /* remove the probe */
1376 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1377 cleanup_hook (pad, hook);
1380 case GST_PAD_PROBE_DROP:
1381 GST_DEBUG_OBJECT (pad, "asked to drop item");
1383 case GST_PAD_PROBE_PASS:
1384 GST_DEBUG_OBJECT (pad, "asked to pass item");
1386 case GST_PAD_PROBE_OK:
1387 GST_DEBUG_OBJECT (pad, "probe returned OK");
1390 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1393 GST_OBJECT_UNLOCK (pad);
1395 gst_object_unref (pad);
1398 GST_OBJECT_UNLOCK (pad);
1404 * gst_pad_remove_probe:
1405 * @pad: the #GstPad with the probe
1406 * @id: the probe id to remove
1408 * Remove the probe with @id from @pad.
1413 gst_pad_remove_probe (GstPad * pad, gulong id)
1417 g_return_if_fail (GST_IS_PAD (pad));
1419 GST_OBJECT_LOCK (pad);
1421 hook = g_hook_get (&pad->probes, id);
1425 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1427 cleanup_hook (pad, hook);
1428 GST_OBJECT_UNLOCK (pad);
1434 GST_OBJECT_UNLOCK (pad);
1435 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1441 * gst_pad_is_blocked:
1442 * @pad: the #GstPad to query
1444 * Checks if the pad is blocked or not. This function returns the
1445 * last requested state of the pad. It is not certain that the pad
1446 * is actually blocking at this point (see gst_pad_is_blocking()).
1448 * Returns: %TRUE if the pad is blocked.
1453 gst_pad_is_blocked (GstPad * pad)
1455 gboolean result = FALSE;
1457 g_return_val_if_fail (GST_IS_PAD (pad), result);
1459 GST_OBJECT_LOCK (pad);
1460 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1461 GST_OBJECT_UNLOCK (pad);
1467 * gst_pad_is_blocking:
1468 * @pad: the #GstPad to query
1470 * Checks if the pad is blocking or not. This is a guaranteed state
1471 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1473 * Returns: %TRUE if the pad is blocking.
1478 gst_pad_is_blocking (GstPad * pad)
1480 gboolean result = FALSE;
1482 g_return_val_if_fail (GST_IS_PAD (pad), result);
1484 GST_OBJECT_LOCK (pad);
1485 /* the blocking flag is only valid if the pad is not flushing */
1486 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1487 GST_OBJECT_UNLOCK (pad);
1493 * gst_pad_needs_reconfigure:
1494 * @pad: the #GstPad to check
1496 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1497 * if the flag was set.
1499 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1502 gst_pad_needs_reconfigure (GstPad * pad)
1504 gboolean reconfigure;
1506 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1508 GST_OBJECT_LOCK (pad);
1509 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1510 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1511 GST_OBJECT_UNLOCK (pad);
1517 * gst_pad_check_reconfigure:
1518 * @pad: the #GstPad to check
1520 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1521 * if the flag was set.
1523 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1526 gst_pad_check_reconfigure (GstPad * pad)
1528 gboolean reconfigure;
1530 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1532 GST_OBJECT_LOCK (pad);
1533 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1535 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1536 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1538 GST_OBJECT_UNLOCK (pad);
1544 * gst_pad_mark_reconfigure:
1545 * @pad: the #GstPad to mark
1547 * Mark a pad for needing reconfiguration. The next call to
1548 * gst_pad_check_reconfigure() will return %TRUE after this call.
1551 gst_pad_mark_reconfigure (GstPad * pad)
1553 g_return_if_fail (GST_IS_PAD (pad));
1555 GST_OBJECT_LOCK (pad);
1556 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1557 GST_OBJECT_UNLOCK (pad);
1561 * gst_pad_set_activate_function:
1563 * @f: the #GstPadActivateFunction to set.
1565 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1569 * gst_pad_set_activate_function_full:
1571 * @activate: the #GstPadActivateFunction to set.
1572 * @user_data: user_data passed to @notify
1573 * @notify: notify called when @activate will not be used anymore.
1575 * Sets the given activate function for @pad. The activate function will
1576 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1577 * Only makes sense to set on sink pads.
1579 * Call this function if your sink pad can start a pull-based task.
1582 gst_pad_set_activate_function_full (GstPad * pad,
1583 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1585 g_return_if_fail (GST_IS_PAD (pad));
1587 if (pad->activatenotify)
1588 pad->activatenotify (pad->activatedata);
1589 GST_PAD_ACTIVATEFUNC (pad) = activate;
1590 pad->activatedata = user_data;
1591 pad->activatenotify = notify;
1593 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1594 GST_DEBUG_FUNCPTR_NAME (activate));
1598 * gst_pad_set_activatemode_function:
1600 * @f: the #GstPadActivateModeFunction to set.
1602 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1606 * gst_pad_set_activatemode_function_full:
1608 * @activatemode: the #GstPadActivateModeFunction to set.
1609 * @user_data: user_data passed to @notify
1610 * @notify: notify called when @activatemode will not be used anymore.
1612 * Sets the given activate_mode function for the pad. An activate_mode function
1613 * prepares the element for data passing.
1616 gst_pad_set_activatemode_function_full (GstPad * pad,
1617 GstPadActivateModeFunction activatemode, gpointer user_data,
1618 GDestroyNotify notify)
1620 g_return_if_fail (GST_IS_PAD (pad));
1622 if (pad->activatemodenotify)
1623 pad->activatemodenotify (pad->activatemodedata);
1624 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1625 pad->activatemodedata = user_data;
1626 pad->activatemodenotify = notify;
1628 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1629 GST_DEBUG_FUNCPTR_NAME (activatemode));
1633 * gst_pad_set_chain_function:
1634 * @p: a sink #GstPad.
1635 * @f: the #GstPadChainFunction to set.
1637 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1641 * gst_pad_set_chain_function_full:
1642 * @pad: a sink #GstPad.
1643 * @chain: the #GstPadChainFunction to set.
1644 * @user_data: user_data passed to @notify
1645 * @notify: notify called when @chain will not be used anymore.
1647 * Sets the given chain function for the pad. The chain function is called to
1648 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1651 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1652 gpointer user_data, GDestroyNotify notify)
1654 g_return_if_fail (GST_IS_PAD (pad));
1655 g_return_if_fail (GST_PAD_IS_SINK (pad));
1657 if (pad->chainnotify)
1658 pad->chainnotify (pad->chaindata);
1659 GST_PAD_CHAINFUNC (pad) = chain;
1660 pad->chaindata = user_data;
1661 pad->chainnotify = notify;
1663 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1664 GST_DEBUG_FUNCPTR_NAME (chain));
1668 * gst_pad_set_chain_list_function:
1669 * @p: a sink #GstPad.
1670 * @f: the #GstPadChainListFunction to set.
1672 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1676 * gst_pad_set_chain_list_function_full:
1677 * @pad: a sink #GstPad.
1678 * @chainlist: the #GstPadChainListFunction to set.
1679 * @user_data: user_data passed to @notify
1680 * @notify: notify called when @chainlist will not be used anymore.
1682 * Sets the given chain list function for the pad. The chainlist function is
1683 * called to process a #GstBufferList input buffer list. See
1684 * #GstPadChainListFunction for more details.
1687 gst_pad_set_chain_list_function_full (GstPad * pad,
1688 GstPadChainListFunction chainlist, gpointer user_data,
1689 GDestroyNotify notify)
1691 g_return_if_fail (GST_IS_PAD (pad));
1692 g_return_if_fail (GST_PAD_IS_SINK (pad));
1694 if (pad->chainlistnotify)
1695 pad->chainlistnotify (pad->chainlistdata);
1696 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1697 pad->chainlistdata = user_data;
1698 pad->chainlistnotify = notify;
1700 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1701 GST_DEBUG_FUNCPTR_NAME (chainlist));
1705 * gst_pad_set_getrange_function:
1706 * @p: a source #GstPad.
1707 * @f: the #GstPadGetRangeFunction to set.
1709 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1713 * gst_pad_set_getrange_function_full:
1714 * @pad: a source #GstPad.
1715 * @get: the #GstPadGetRangeFunction to set.
1716 * @user_data: user_data passed to @notify
1717 * @notify: notify called when @get will not be used anymore.
1719 * Sets the given getrange function for the pad. The getrange function is
1720 * called to produce a new #GstBuffer to start the processing pipeline. see
1721 * #GstPadGetRangeFunction for a description of the getrange function.
1724 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1725 gpointer user_data, GDestroyNotify notify)
1727 g_return_if_fail (GST_IS_PAD (pad));
1728 g_return_if_fail (GST_PAD_IS_SRC (pad));
1730 if (pad->getrangenotify)
1731 pad->getrangenotify (pad->getrangedata);
1732 GST_PAD_GETRANGEFUNC (pad) = get;
1733 pad->getrangedata = user_data;
1734 pad->getrangenotify = notify;
1736 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1737 GST_DEBUG_FUNCPTR_NAME (get));
1741 * gst_pad_set_event_function:
1742 * @p: a #GstPad of either direction.
1743 * @f: the #GstPadEventFunction to set.
1745 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1749 * gst_pad_set_event_function_full:
1750 * @pad: a #GstPad of either direction.
1751 * @event: the #GstPadEventFunction to set.
1752 * @user_data: user_data passed to @notify
1753 * @notify: notify called when @event will not be used anymore.
1755 * Sets the given event handler for the pad.
1758 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1759 gpointer user_data, GDestroyNotify notify)
1761 g_return_if_fail (GST_IS_PAD (pad));
1763 if (pad->eventnotify)
1764 pad->eventnotify (pad->eventdata);
1765 GST_PAD_EVENTFUNC (pad) = event;
1766 pad->eventdata = user_data;
1767 pad->eventnotify = notify;
1769 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1770 GST_DEBUG_FUNCPTR_NAME (event));
1774 * gst_pad_set_query_function:
1775 * @p: a #GstPad of either direction.
1776 * @f: the #GstPadQueryFunction to set.
1778 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1782 * gst_pad_set_query_function_full:
1783 * @pad: a #GstPad of either direction.
1784 * @query: the #GstPadQueryFunction to set.
1785 * @user_data: user_data passed to @notify
1786 * @notify: notify called when @query will not be used anymore.
1788 * Set the given query function for the pad.
1791 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1792 gpointer user_data, GDestroyNotify notify)
1794 g_return_if_fail (GST_IS_PAD (pad));
1796 if (pad->querynotify)
1797 pad->querynotify (pad->querydata);
1798 GST_PAD_QUERYFUNC (pad) = query;
1799 pad->querydata = user_data;
1800 pad->querynotify = notify;
1802 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1803 GST_DEBUG_FUNCPTR_NAME (query));
1807 * gst_pad_set_iterate_internal_links_function:
1808 * @p: a #GstPad of either direction.
1809 * @f: the #GstPadIterIntLinkFunction to set.
1811 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1812 * for the user_data and notify.
1815 * gst_pad_set_iterate_internal_links_function_full:
1816 * @pad: a #GstPad of either direction.
1817 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1818 * @user_data: user_data passed to @notify
1819 * @notify: notify called when @iterintlink will not be used anymore.
1821 * Sets the given internal link iterator function for the pad.
1824 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1825 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1826 GDestroyNotify notify)
1828 g_return_if_fail (GST_IS_PAD (pad));
1830 if (pad->iterintlinknotify)
1831 pad->iterintlinknotify (pad->iterintlinkdata);
1832 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1833 pad->iterintlinkdata = user_data;
1834 pad->iterintlinknotify = notify;
1836 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1837 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1841 * gst_pad_set_link_function:
1843 * @f: the #GstPadLinkFunction to set.
1845 * Calls gst_pad_set_link_function_full() with %NULL
1846 * for the user_data and notify.
1849 * gst_pad_set_link_function_full:
1851 * @link: the #GstPadLinkFunction to set.
1852 * @user_data: user_data passed to @notify
1853 * @notify: notify called when @link will not be used anymore.
1855 * Sets the given link function for the pad. It will be called when
1856 * the pad is linked with another pad.
1858 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1861 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1862 * cannot be made for some reason.
1864 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1865 * of the peer sink pad, if present.
1868 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1869 gpointer user_data, GDestroyNotify notify)
1871 g_return_if_fail (GST_IS_PAD (pad));
1873 if (pad->linknotify)
1874 pad->linknotify (pad->linkdata);
1875 GST_PAD_LINKFUNC (pad) = link;
1876 pad->linkdata = user_data;
1877 pad->linknotify = notify;
1879 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1880 GST_DEBUG_FUNCPTR_NAME (link));
1884 * gst_pad_set_unlink_function:
1886 * @f: the #GstPadUnlinkFunction to set.
1888 * Calls gst_pad_set_unlink_function_full() with %NULL
1889 * for the user_data and notify.
1892 * gst_pad_set_unlink_function_full:
1894 * @unlink: the #GstPadUnlinkFunction to set.
1895 * @user_data: user_data passed to @notify
1896 * @notify: notify called when @unlink will not be used anymore.
1898 * Sets the given unlink function for the pad. It will be called
1899 * when the pad is unlinked.
1902 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1903 gpointer user_data, GDestroyNotify notify)
1905 g_return_if_fail (GST_IS_PAD (pad));
1907 if (pad->unlinknotify)
1908 pad->unlinknotify (pad->unlinkdata);
1909 GST_PAD_UNLINKFUNC (pad) = unlink;
1910 pad->unlinkdata = user_data;
1911 pad->unlinknotify = notify;
1913 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1914 GST_DEBUG_FUNCPTR_NAME (unlink));
1919 * @srcpad: the source #GstPad to unlink.
1920 * @sinkpad: the sink #GstPad to unlink.
1922 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1923 * signal on both pads.
1925 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
1926 * the pads were not linked together.
1931 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1933 gboolean result = FALSE;
1934 GstElement *parent = NULL;
1936 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1937 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1938 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1939 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1941 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1942 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1943 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1945 /* We need to notify the parent before taking any pad locks as the bin in
1946 * question might be waiting for a lock on the pad while holding its lock
1947 * that our message will try to take. */
1948 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1949 if (GST_IS_ELEMENT (parent)) {
1950 gst_element_post_message (parent,
1951 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1952 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1954 gst_object_unref (parent);
1959 GST_OBJECT_LOCK (srcpad);
1960 GST_OBJECT_LOCK (sinkpad);
1962 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1963 goto not_linked_together;
1965 if (GST_PAD_UNLINKFUNC (srcpad)) {
1966 GstObject *tmpparent;
1968 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1970 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1971 RELEASE_PARENT (tmpparent);
1974 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1975 GstObject *tmpparent;
1977 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1979 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1980 RELEASE_PARENT (tmpparent);
1984 /* first clear peers */
1985 GST_PAD_PEER (srcpad) = NULL;
1986 GST_PAD_PEER (sinkpad) = NULL;
1988 GST_OBJECT_UNLOCK (sinkpad);
1989 GST_OBJECT_UNLOCK (srcpad);
1991 /* fire off a signal to each of the pads telling them
1992 * that they've been unlinked */
1993 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1994 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1996 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1997 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2002 if (parent != NULL) {
2003 gst_element_post_message (parent,
2004 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2005 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2006 gst_object_unref (parent);
2011 not_linked_together:
2013 /* we do not emit a warning in this case because unlinking cannot
2014 * be made MT safe.*/
2015 GST_OBJECT_UNLOCK (sinkpad);
2016 GST_OBJECT_UNLOCK (srcpad);
2022 * gst_pad_is_linked:
2023 * @pad: pad to check
2025 * Checks if a @pad is linked to another pad or not.
2027 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2032 gst_pad_is_linked (GstPad * pad)
2036 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2038 GST_OBJECT_LOCK (pad);
2039 result = (GST_PAD_PEER (pad) != NULL);
2040 GST_OBJECT_UNLOCK (pad);
2045 /* get the caps from both pads and see if the intersection
2048 * This function should be called with the pad LOCK on both
2052 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2053 GstPadLinkCheck flags)
2055 GstCaps *srccaps = NULL;
2056 GstCaps *sinkcaps = NULL;
2057 gboolean compatible = FALSE;
2059 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2062 /* Doing the expensive caps checking takes priority over only checking the template caps */
2063 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2064 GST_OBJECT_UNLOCK (sink);
2065 GST_OBJECT_UNLOCK (src);
2067 srccaps = gst_pad_query_caps (src, NULL);
2068 sinkcaps = gst_pad_query_caps (sink, NULL);
2070 GST_OBJECT_LOCK (src);
2071 GST_OBJECT_LOCK (sink);
2073 /* If one of the two pads doesn't have a template, consider the intersection
2075 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2076 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2080 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2082 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2085 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2087 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2090 /* if we have caps on both pads we can check the intersection. If one
2091 * of the caps is %NULL, we return %TRUE. */
2092 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2094 gst_caps_unref (srccaps);
2096 gst_caps_unref (sinkcaps);
2100 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2101 gst_caps_unref (srccaps);
2102 gst_caps_unref (sinkcaps);
2105 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2106 (compatible ? "" : "not "));
2111 /* check if the grandparents of both pads are the same.
2112 * This check is required so that we don't try to link
2113 * pads from elements in different bins without ghostpads.
2115 * The LOCK should be held on both pads
2118 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2120 GstObject *psrc, *psink;
2122 psrc = GST_OBJECT_PARENT (src);
2123 psink = GST_OBJECT_PARENT (sink);
2125 /* if one of the pads has no parent, we allow the link */
2126 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2129 /* only care about parents that are elements */
2130 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2131 goto no_element_parent;
2133 /* if the parents are the same, we have a loop */
2134 if (G_UNLIKELY (psrc == psink))
2137 /* if they both have a parent, we check the grandparents. We can not lock
2138 * the parent because we hold on the child (pad) and the locking order is
2139 * parent >> child. */
2140 psrc = GST_OBJECT_PARENT (psrc);
2141 psink = GST_OBJECT_PARENT (psink);
2143 /* if they have grandparents but they are not the same */
2144 if (G_UNLIKELY (psrc != psink))
2145 goto wrong_grandparents;
2152 GST_CAT_DEBUG (GST_CAT_CAPS,
2153 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2154 GST_PTR_FORMAT, psrc, psink);
2159 GST_CAT_DEBUG (GST_CAT_CAPS,
2160 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2161 GST_PTR_FORMAT, psrc, psink);
2166 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2172 GST_CAT_DEBUG (GST_CAT_CAPS,
2173 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2174 GST_PTR_FORMAT, psrc, psink);
2179 /* FIXME leftover from an attempt at refactoring... */
2180 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2181 * the two pads will be locked in the srcpad, sinkpad order. */
2182 static GstPadLinkReturn
2183 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2185 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2186 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2188 GST_OBJECT_LOCK (srcpad);
2190 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2191 goto src_was_linked;
2193 GST_OBJECT_LOCK (sinkpad);
2195 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2196 goto sink_was_linked;
2198 /* check hierarchy, pads can only be linked if the grandparents
2200 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2201 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2202 goto wrong_hierarchy;
2204 /* check pad caps for non-empty intersection */
2205 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2208 /* FIXME check pad scheduling for non-empty intersection */
2210 return GST_PAD_LINK_OK;
2214 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2215 GST_DEBUG_PAD_NAME (srcpad),
2216 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2217 /* we do not emit a warning in this case because unlinking cannot
2218 * be made MT safe.*/
2219 GST_OBJECT_UNLOCK (srcpad);
2220 return GST_PAD_LINK_WAS_LINKED;
2224 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2225 GST_DEBUG_PAD_NAME (sinkpad),
2226 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2227 /* we do not emit a warning in this case because unlinking cannot
2228 * be made MT safe.*/
2229 GST_OBJECT_UNLOCK (sinkpad);
2230 GST_OBJECT_UNLOCK (srcpad);
2231 return GST_PAD_LINK_WAS_LINKED;
2235 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2236 GST_OBJECT_UNLOCK (sinkpad);
2237 GST_OBJECT_UNLOCK (srcpad);
2238 return GST_PAD_LINK_WRONG_HIERARCHY;
2242 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2243 GST_OBJECT_UNLOCK (sinkpad);
2244 GST_OBJECT_UNLOCK (srcpad);
2245 return GST_PAD_LINK_NOFORMAT;
2251 * @srcpad: the source #GstPad.
2252 * @sinkpad: the sink #GstPad.
2254 * Checks if the source pad and the sink pad are compatible so they can be
2257 * Returns: %TRUE if the pads can be linked.
2260 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2262 GstPadLinkReturn result;
2264 /* generic checks */
2265 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2266 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2268 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2269 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2271 /* gst_pad_link_prepare does everything for us, we only release the locks
2272 * on the pads that it gets us. If this function returns !OK the locks are not
2274 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2275 if (result != GST_PAD_LINK_OK)
2278 GST_OBJECT_UNLOCK (srcpad);
2279 GST_OBJECT_UNLOCK (sinkpad);
2282 return result == GST_PAD_LINK_OK;
2286 * gst_pad_link_full:
2287 * @srcpad: the source #GstPad to link.
2288 * @sinkpad: the sink #GstPad to link.
2289 * @flags: the checks to validate when linking
2291 * Links the source pad and the sink pad.
2293 * This variant of #gst_pad_link provides a more granular control on the
2294 * checks being done when linking. While providing some considerable speedups
2295 * the caller of this method must be aware that wrong usage of those flags
2296 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2297 * for more information.
2301 * Returns: A result code indicating if the connection worked or
2305 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2307 GstPadLinkReturn result;
2309 GstPadLinkFunction srcfunc, sinkfunc;
2311 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2312 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2313 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2314 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2315 GST_PAD_LINK_WRONG_DIRECTION);
2317 /* Notify the parent early. See gst_pad_unlink for details. */
2318 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2319 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2320 gst_element_post_message (parent,
2321 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2322 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2324 gst_object_unref (parent);
2329 /* prepare will also lock the two pads */
2330 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2332 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2335 /* must set peers before calling the link function */
2336 GST_PAD_PEER (srcpad) = sinkpad;
2337 GST_PAD_PEER (sinkpad) = srcpad;
2339 /* check events, when something is different, mark pending */
2340 schedule_events (srcpad, sinkpad);
2342 /* get the link functions */
2343 srcfunc = GST_PAD_LINKFUNC (srcpad);
2344 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2346 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2347 /* custom link functions, execute them */
2348 GST_OBJECT_UNLOCK (sinkpad);
2349 GST_OBJECT_UNLOCK (srcpad);
2352 GstObject *tmpparent;
2354 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2355 /* this one will call the peer link function */
2356 result = srcfunc (srcpad, tmpparent, sinkpad);
2357 RELEASE_PARENT (tmpparent);
2358 } else if (sinkfunc) {
2359 GstObject *tmpparent;
2361 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2362 /* if no source link function, we need to call the sink link
2363 * function ourselves. */
2364 result = sinkfunc (sinkpad, tmpparent, srcpad);
2365 RELEASE_PARENT (tmpparent);
2369 GST_OBJECT_LOCK (srcpad);
2370 GST_OBJECT_LOCK (sinkpad);
2372 /* we released the lock, check if the same pads are linked still */
2373 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2374 goto concurrent_link;
2376 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2379 GST_OBJECT_UNLOCK (sinkpad);
2380 GST_OBJECT_UNLOCK (srcpad);
2382 /* fire off a signal to each of the pads telling them
2383 * that they've been linked */
2384 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2385 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2387 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2388 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2390 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2393 if (G_LIKELY (parent)) {
2394 gst_element_post_message (parent,
2395 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2396 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2397 gst_object_unref (parent);
2405 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2406 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2407 GST_OBJECT_UNLOCK (sinkpad);
2408 GST_OBJECT_UNLOCK (srcpad);
2410 /* The other link operation succeeded first */
2411 result = GST_PAD_LINK_WAS_LINKED;
2416 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2417 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2418 gst_pad_link_get_name (result));
2420 GST_PAD_PEER (srcpad) = NULL;
2421 GST_PAD_PEER (sinkpad) = NULL;
2423 GST_OBJECT_UNLOCK (sinkpad);
2424 GST_OBJECT_UNLOCK (srcpad);
2432 * @srcpad: the source #GstPad to link.
2433 * @sinkpad: the sink #GstPad to link.
2435 * Links the source pad and the sink pad.
2437 * Returns: A result code indicating if the connection worked or
2443 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2445 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2449 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2451 GstPadTemplate **template_p;
2453 /* this function would need checks if it weren't static */
2455 GST_OBJECT_LOCK (pad);
2456 template_p = &pad->padtemplate;
2457 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2458 GST_OBJECT_UNLOCK (pad);
2461 gst_pad_template_pad_created (templ, pad);
2465 * gst_pad_get_pad_template:
2468 * Gets the template for @pad.
2470 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2471 * this pad was instantiated, or %NULL if this pad has no
2472 * template. Unref after usage.
2475 gst_pad_get_pad_template (GstPad * pad)
2477 GstPadTemplate *templ;
2479 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2481 templ = GST_PAD_PAD_TEMPLATE (pad);
2483 return (templ ? gst_object_ref (templ) : NULL);
2487 * gst_pad_has_current_caps:
2488 * @pad: a #GstPad to check
2490 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2492 * Returns: %TRUE when @pad has caps associated with it.
2495 gst_pad_has_current_caps (GstPad * pad)
2500 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2502 GST_OBJECT_LOCK (pad);
2503 caps = get_pad_caps (pad);
2504 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2505 "check current pad caps %" GST_PTR_FORMAT, caps);
2506 result = (caps != NULL);
2507 GST_OBJECT_UNLOCK (pad);
2513 * gst_pad_get_current_caps:
2514 * @pad: a #GstPad to get the current capabilities of.
2516 * Gets the capabilities currently configured on @pad with the last
2517 * #GST_EVENT_CAPS event.
2519 * Returns: the current caps of the pad with incremented ref-count.
2522 gst_pad_get_current_caps (GstPad * pad)
2526 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2528 GST_OBJECT_LOCK (pad);
2529 if ((result = get_pad_caps (pad)))
2530 gst_caps_ref (result);
2531 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2532 "get current pad caps %" GST_PTR_FORMAT, result);
2533 GST_OBJECT_UNLOCK (pad);
2539 * gst_pad_get_pad_template_caps:
2540 * @pad: a #GstPad to get the template capabilities from.
2542 * Gets the capabilities for @pad's template.
2544 * Returns: (transfer full): the #GstCaps of this pad template.
2545 * Unref after usage.
2548 gst_pad_get_pad_template_caps (GstPad * pad)
2550 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2552 if (GST_PAD_PAD_TEMPLATE (pad))
2553 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2555 return gst_caps_ref (GST_CAPS_ANY);
2560 * @pad: a #GstPad to get the peer of.
2562 * Gets the peer of @pad. This function refs the peer pad so
2563 * you need to unref it after use.
2565 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2570 gst_pad_get_peer (GstPad * pad)
2574 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2576 GST_OBJECT_LOCK (pad);
2577 result = GST_PAD_PEER (pad);
2579 gst_object_ref (result);
2580 GST_OBJECT_UNLOCK (pad);
2586 * gst_pad_get_allowed_caps:
2589 * Gets the capabilities of the allowed media types that can flow through
2590 * @pad and its peer.
2592 * The allowed capabilities is calculated as the intersection of the results of
2593 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2594 * on the resulting caps.
2596 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2597 * pad link. Unref the caps when you no longer need it. This
2598 * function returns %NULL when @pad has no peer.
2603 gst_pad_get_allowed_caps (GstPad * pad)
2609 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2611 GST_OBJECT_LOCK (pad);
2612 peer = GST_PAD_PEER (pad);
2613 if (G_UNLIKELY (peer == NULL))
2616 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2618 gst_object_ref (peer);
2619 GST_OBJECT_UNLOCK (pad);
2620 mycaps = gst_pad_query_caps (pad, NULL);
2622 caps = gst_pad_query_caps (peer, mycaps);
2623 gst_object_unref (peer);
2625 gst_caps_unref (mycaps);
2627 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2634 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2635 GST_OBJECT_UNLOCK (pad);
2642 * gst_pad_iterate_internal_links_default:
2643 * @pad: the #GstPad to get the internal links of.
2644 * @parent: (allow-none): the parent of @pad or %NULL
2646 * Iterate the list of pads to which the given pad is linked to inside of
2647 * the parent element.
2648 * This is the default handler, and thus returns an iterator of all of the
2649 * pads inside the parent element with opposite direction.
2651 * The caller must free this iterator after use with gst_iterator_free().
2653 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2654 * has no parent. Unref each returned pad with gst_object_unref().
2657 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2664 GstElement *eparent;
2666 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2668 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2669 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2671 GST_OBJECT_LOCK (pad);
2672 eparent = GST_PAD_PARENT (pad);
2673 if (!eparent || !GST_IS_ELEMENT (eparent))
2676 gst_object_ref (eparent);
2677 GST_OBJECT_UNLOCK (pad);
2680 if (pad->direction == GST_PAD_SRC)
2681 padlist = &eparent->sinkpads;
2683 padlist = &eparent->srcpads;
2685 GST_DEBUG_OBJECT (pad, "Making iterator");
2687 cookie = &eparent->pads_cookie;
2689 lock = GST_OBJECT_GET_LOCK (eparent);
2691 res = gst_iterator_new_list (GST_TYPE_PAD,
2692 lock, cookie, padlist, (GObject *) owner, NULL);
2694 gst_object_unref (owner);
2701 GST_OBJECT_UNLOCK (pad);
2702 GST_DEBUG_OBJECT (pad, "no parent element");
2708 * gst_pad_iterate_internal_links:
2709 * @pad: the GstPad to get the internal links of.
2711 * Gets an iterator for the pads to which the given pad is linked to inside
2712 * of the parent element.
2714 * Each #GstPad element yielded by the iterator will have its refcount increased,
2715 * so unref after use.
2717 * Free-function: gst_iterator_free
2719 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2720 * or %NULL when the pad does not have an iterator function
2721 * configured. Use gst_iterator_free() after usage.
2724 gst_pad_iterate_internal_links (GstPad * pad)
2726 GstIterator *res = NULL;
2729 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2731 GST_OBJECT_LOCK (pad);
2732 ACQUIRE_PARENT (pad, parent, no_parent);
2733 GST_OBJECT_UNLOCK (pad);
2735 if (GST_PAD_ITERINTLINKFUNC (pad))
2736 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2738 RELEASE_PARENT (parent);
2745 GST_DEBUG_OBJECT (pad, "no parent");
2746 GST_OBJECT_UNLOCK (pad);
2754 * @forward: (scope call): a #GstPadForwardFunction
2755 * @user_data: user data passed to @forward
2757 * Calls @forward for all internally linked pads of @pad. This function deals with
2758 * dynamically changing internal pads and will make sure that the @forward
2759 * function is only called once for each pad.
2761 * When @forward returns %TRUE, no further pads will be processed.
2763 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2766 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2769 gboolean result = FALSE;
2771 gboolean done = FALSE;
2772 GValue item = { 0, };
2773 GList *pushed_pads = NULL;
2775 iter = gst_pad_iterate_internal_links (pad);
2781 switch (gst_iterator_next (iter, &item)) {
2782 case GST_ITERATOR_OK:
2786 intpad = g_value_get_object (&item);
2788 /* if already pushed, skip. FIXME, find something faster to tag pads */
2789 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2790 g_value_reset (&item);
2794 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2795 GST_DEBUG_PAD_NAME (intpad));
2796 done = result = forward (intpad, user_data);
2798 pushed_pads = g_list_prepend (pushed_pads, intpad);
2800 g_value_reset (&item);
2803 case GST_ITERATOR_RESYNC:
2804 /* We don't reset the result here because we don't push the event
2805 * again on pads that got the event already and because we need
2806 * to consider the result of the previous pushes */
2807 gst_iterator_resync (iter);
2809 case GST_ITERATOR_ERROR:
2810 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2813 case GST_ITERATOR_DONE:
2818 g_value_unset (&item);
2819 gst_iterator_free (iter);
2821 g_list_free (pushed_pads);
2831 gboolean dispatched;
2835 event_forward_func (GstPad * pad, EventData * data)
2837 /* for each pad we send to, we should ref the event; it's up
2838 * to downstream to unref again when handled. */
2839 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2840 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2842 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2844 data->dispatched = TRUE;
2851 * gst_pad_event_default:
2852 * @pad: a #GstPad to call the default event handler on.
2853 * @parent: (allow-none): the parent of @pad or %NULL
2854 * @event: (transfer full): the #GstEvent to handle.
2856 * Invokes the default event handler for the given pad.
2858 * The EOS event will pause the task associated with @pad before it is forwarded
2859 * to all internally linked pads,
2861 * The the event is sent to all pads internally linked to @pad. This function
2862 * takes ownership of @event.
2864 * Returns: %TRUE if the event was sent successfully.
2867 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2869 gboolean result, forward = TRUE;
2871 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2872 g_return_val_if_fail (event != NULL, FALSE);
2874 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2877 switch (GST_EVENT_TYPE (event)) {
2878 case GST_EVENT_CAPS:
2879 forward = GST_PAD_IS_PROXY_CAPS (pad);
2890 data.dispatched = FALSE;
2891 data.result = FALSE;
2893 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2895 /* for sinkpads without a parent element or without internal links, nothing
2896 * will be dispatched but we still want to return TRUE. */
2897 if (data.dispatched)
2898 result = data.result;
2903 gst_event_unref (event);
2908 /* Default accept caps implementation just checks against
2909 * the allowed caps for the pad */
2911 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2913 /* get the caps and see if it intersects to something not empty */
2914 GstCaps *caps, *allowed;
2917 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2919 /* first forward the query to internally linked pads when we are dealing with
2921 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2922 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2927 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2928 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2930 gst_query_parse_accept_caps (query, &caps);
2931 allowed = gst_pad_query_caps (pad, caps);
2934 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
2935 GST_DEBUG_OBJECT (pad,
2936 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
2938 result = gst_caps_can_intersect (caps, allowed);
2940 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
2941 GST_PTR_FORMAT, allowed, caps);
2942 result = gst_caps_is_subset (caps, allowed);
2944 gst_caps_unref (allowed);
2946 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
2949 gst_query_set_accept_caps_result (query, result);
2955 /* Default caps implementation */
2957 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2959 GstCaps *result = NULL, *filter;
2960 GstPadTemplate *templ;
2961 gboolean fixed_caps;
2963 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2966 /* first try to proxy if we must */
2967 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2968 if ((gst_pad_proxy_query_caps (pad, query))) {
2973 gst_query_parse_caps (query, &filter);
2975 /* no proxy or it failed, do default handling */
2976 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2978 GST_OBJECT_LOCK (pad);
2980 /* fixed caps, try the negotiated caps first */
2981 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2982 if ((result = get_pad_caps (pad)))
2983 goto filter_done_unlock;
2986 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2987 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2988 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2989 goto filter_done_unlock;
2993 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2994 "non-fixed pad caps: trying pad caps");
2995 /* non fixed caps, try the negotiated caps */
2996 if ((result = get_pad_caps (pad)))
2997 goto filter_done_unlock;
3000 /* this almost never happens */
3001 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3002 result = GST_CAPS_ANY;
3005 GST_OBJECT_UNLOCK (pad);
3007 /* run the filter on the result */
3009 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3010 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3011 GST_PTR_FORMAT, result, result, filter, filter);
3012 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3013 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3016 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3017 "using caps %p %" GST_PTR_FORMAT, result, result);
3018 result = gst_caps_ref (result);
3020 gst_query_set_caps_result (query, result);
3021 gst_caps_unref (result);
3031 gboolean dispatched;
3035 query_forward_func (GstPad * pad, QueryData * data)
3037 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3038 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3040 data->result |= gst_pad_peer_query (pad, data->query);
3042 data->dispatched = TRUE;
3044 /* stop on first successful reply */
3045 return data->result;
3049 * gst_pad_query_default:
3050 * @pad: a #GstPad to call the default query handler on.
3051 * @parent: (allow-none): the parent of @pad or %NULL
3052 * @query: (transfer none): the #GstQuery to handle.
3054 * Invokes the default query handler for the given pad.
3055 * The query is sent to all pads internally linked to @pad. Note that
3056 * if there are many possible sink pads that are internally linked to
3057 * @pad, only one will be sent the query.
3058 * Multi-sinkpad elements should implement custom query handlers.
3060 * Returns: %TRUE if the query was performed successfully.
3063 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3065 gboolean forward, ret = FALSE;
3067 switch (GST_QUERY_TYPE (query)) {
3068 case GST_QUERY_SCHEDULING:
3069 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3071 case GST_QUERY_ALLOCATION:
3072 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3074 case GST_QUERY_ACCEPT_CAPS:
3075 ret = gst_pad_query_accept_caps_default (pad, query);
3078 case GST_QUERY_CAPS:
3079 ret = gst_pad_query_caps_default (pad, query);
3082 case GST_QUERY_POSITION:
3083 case GST_QUERY_SEEKING:
3084 case GST_QUERY_FORMATS:
3085 case GST_QUERY_LATENCY:
3086 case GST_QUERY_JITTER:
3087 case GST_QUERY_RATE:
3088 case GST_QUERY_CONVERT:
3094 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3095 query, GST_QUERY_TYPE_NAME (query));
3101 data.dispatched = FALSE;
3102 data.result = FALSE;
3104 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3106 if (data.dispatched) {
3109 /* nothing dispatched, assume drained */
3110 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3120 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3122 GstPad *pad = data->pad;
3123 GstPadProbeInfo *info = data->info;
3124 GstPadProbeType type, flags;
3125 GstPadProbeCallback callback;
3126 GstPadProbeReturn ret;
3128 /* if we have called this callback, do nothing */
3129 if (PROBE_COOKIE (hook) == data->cookie) {
3130 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3131 "hook %lu, cookie %u already called", hook->hook_id,
3132 PROBE_COOKIE (hook));
3136 PROBE_COOKIE (hook) = data->cookie;
3138 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3141 /* one of the data types for non-idle probes */
3142 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3143 && (flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3145 /* one of the scheduling types */
3146 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3148 /* one of the blocking types must match */
3149 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3150 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3152 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3153 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3155 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3156 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3157 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3160 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3161 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3162 PROBE_COOKIE (hook), flags);
3164 data->marshalled = TRUE;
3166 callback = (GstPadProbeCallback) hook->func;
3167 if (callback == NULL)
3170 info->id = hook->hook_id;
3172 GST_OBJECT_UNLOCK (pad);
3174 ret = callback (pad, info, hook->data);
3176 GST_OBJECT_LOCK (pad);
3179 case GST_PAD_PROBE_REMOVE:
3180 /* remove the probe */
3181 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3182 cleanup_hook (pad, hook);
3184 case GST_PAD_PROBE_DROP:
3185 /* need to drop the data, make sure other probes don't get called
3187 GST_DEBUG_OBJECT (pad, "asked to drop item");
3188 info->type = GST_PAD_PROBE_TYPE_INVALID;
3189 data->dropped = TRUE;
3191 case GST_PAD_PROBE_PASS:
3192 /* inform the pad block to let things pass */
3193 GST_DEBUG_OBJECT (pad, "asked to pass item");
3196 case GST_PAD_PROBE_OK:
3197 GST_DEBUG_OBJECT (pad, "probe returned OK");
3200 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3207 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3208 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3209 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3214 /* a probe that does not take or return any data */
3215 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3217 if (G_UNLIKELY (pad->num_probes)) { \
3218 /* pass NULL as the data item */ \
3219 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3220 ret = do_probe_callbacks (pad, &info, defaultval); \
3221 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3226 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3228 if (G_UNLIKELY (pad->num_probes)) { \
3229 /* pass the data item */ \
3230 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3231 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3232 /* store the possibly updated data item */ \
3233 data = GST_PAD_PROBE_INFO_DATA (&info); \
3234 /* if something went wrong, exit */ \
3235 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3240 #define PROBE_PUSH(pad,mask,data,label) \
3241 PROBE_FULL(pad, mask, data, -1, -1, label);
3242 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3243 PROBE_FULL(pad, mask, data, offs, size, label);
3245 static GstFlowReturn
3246 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3247 GstFlowReturn defaultval)
3256 data.marshalled = FALSE;
3257 data.dropped = FALSE;
3258 data.cookie = ++pad->priv->probe_cookie;
3261 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3264 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3265 "do probes cookie %u", data.cookie);
3266 cookie = pad->priv->probe_list_cookie;
3268 g_hook_list_marshal (&pad->probes, TRUE,
3269 (GHookMarshaller) probe_hook_marshal, &data);
3271 /* if the list changed, call the new callbacks (they will not have their
3272 * cookie set to data.cookie */
3273 if (cookie != pad->priv->probe_list_cookie) {
3274 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3275 "probe list changed, restarting");
3279 /* the first item that dropped will stop the hooks and then we drop here */
3283 /* if no handler matched and we are blocking, let the item pass */
3284 if (!data.marshalled && is_block)
3287 /* At this point, all handlers returned either OK or PASS. If one handler
3288 * returned PASS, let the item pass */
3293 while (GST_PAD_IS_BLOCKED (pad)) {
3294 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3295 "we are blocked %d times", pad->num_blocked);
3297 /* we might have released the lock */
3298 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3301 /* now we block the streaming thread. It can be unlocked when we
3302 * deactivate the pad (which will also set the FLUSHING flag) or
3303 * when the pad is unblocked. A flushing event will also unblock
3304 * the pad after setting the FLUSHING flag. */
3305 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3306 "Waiting to be unblocked or set flushing");
3307 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3308 GST_PAD_BLOCK_WAIT (pad);
3309 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3310 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3312 /* if the list changed, call the new callbacks (they will not have their
3313 * cookie set to data.cookie */
3314 if (cookie != pad->priv->probe_list_cookie) {
3315 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3316 "probe list changed, restarting");
3320 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3330 GST_DEBUG_OBJECT (pad, "pad is flushing");
3331 return GST_FLOW_FLUSHING;
3335 GST_DEBUG_OBJECT (pad, "data is dropped");
3336 return GST_FLOW_CUSTOM_SUCCESS;
3340 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3341 GST_DEBUG_OBJECT (pad, "data is passed");
3349 * gst_pad_get_offset:
3352 * Get the offset applied to the running time of @pad. @pad has to be a source
3355 * Returns: the offset.
3358 gst_pad_get_offset (GstPad * pad)
3362 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3364 GST_OBJECT_LOCK (pad);
3365 result = pad->offset;
3366 GST_OBJECT_UNLOCK (pad);
3372 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3374 ev->received = FALSE;
3379 * gst_pad_set_offset:
3381 * @offset: the offset
3383 * Set the offset that will be applied to the running time of @pad.
3386 gst_pad_set_offset (GstPad * pad, gint64 offset)
3388 g_return_if_fail (GST_IS_PAD (pad));
3390 GST_OBJECT_LOCK (pad);
3391 /* if nothing changed, do nothing */
3392 if (pad->offset == offset)
3395 pad->offset = offset;
3396 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3398 /* resend all sticky events with updated offset on next buffer push */
3399 events_foreach (pad, mark_event_not_received, NULL);
3400 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3403 GST_OBJECT_UNLOCK (pad);
3410 /* If TRUE and ret is not OK this means
3411 * that pushing the EOS event failed
3415 /* If called for an event this is
3416 * the event that would be pushed
3417 * next. Don't forward sticky events
3418 * that would come after that */
3422 /* should be called with pad LOCK */
3424 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3426 PushStickyData *data = user_data;
3427 GstEvent *event = ev->event;
3430 GST_DEBUG_OBJECT (pad, "event %s was already received",
3431 GST_EVENT_TYPE_NAME (event));
3435 /* If we're called because of an sticky event, only forward
3436 * events that would come before this new event and the
3438 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3439 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3440 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3441 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3443 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3444 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3447 switch (data->ret) {
3449 ev->received = TRUE;
3450 GST_DEBUG_OBJECT (pad, "event %s marked received",
3451 GST_EVENT_TYPE_NAME (event));
3453 case GST_FLOW_CUSTOM_SUCCESS:
3454 /* we can't assume the event is received when it was dropped */
3455 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3456 GST_EVENT_TYPE_NAME (event));
3457 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3458 data->ret = GST_FLOW_OK;
3460 case GST_FLOW_CUSTOM_SUCCESS_1:
3461 /* event was ignored and should be sent later */
3462 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3463 GST_EVENT_TYPE_NAME (event));
3464 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3465 data->ret = GST_FLOW_OK;
3467 case GST_FLOW_NOT_LINKED:
3468 /* not linked is not a problem, we are sticky so the event will be
3469 * sent later but only for non-EOS events */
3470 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3471 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3472 data->ret = GST_FLOW_OK;
3473 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3476 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3477 gst_flow_get_name (data->ret));
3478 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3482 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3483 data->was_eos = TRUE;
3485 return data->ret == GST_FLOW_OK;
3488 /* check sticky events and push them when needed. should be called
3490 static inline GstFlowReturn
3491 check_sticky (GstPad * pad, GstEvent * event)
3493 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3495 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3496 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3498 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3499 events_foreach (pad, push_sticky, &data);
3501 /* If there's an EOS event we must push it downstream
3502 * even if sending a previous sticky event failed.
3503 * Otherwise the pipeline might wait forever for EOS.
3505 * Only do this if pushing another event than the EOS
3508 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3509 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3511 if (ev && !ev->received) {
3512 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3513 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3514 /* the event could have been dropped. Because this can only
3515 * happen if the user asked for it, it's not an error */
3516 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3517 data.ret = GST_FLOW_OK;
3527 * @pad: a #GstPad to invoke the default query on.
3528 * @query: (transfer none): the #GstQuery to perform.
3530 * Dispatches a query to a pad. The query should have been allocated by the
3531 * caller via one of the type-specific allocation functions. The element that
3532 * the pad belongs to is responsible for filling the query with an appropriate
3533 * response, which should then be parsed with a type-specific query parsing
3536 * Again, the caller is responsible for both the allocation and deallocation of
3537 * the query structure.
3539 * Please also note that some queries might need a running pipeline to work.
3541 * Returns: %TRUE if the query could be performed.
3544 gst_pad_query (GstPad * pad, GstQuery * query)
3547 gboolean res, serialized;
3548 GstPadQueryFunction func;
3549 GstPadProbeType type;
3552 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3553 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3555 if (GST_PAD_IS_SRC (pad)) {
3556 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3557 goto wrong_direction;
3558 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3559 } else if (GST_PAD_IS_SINK (pad)) {
3560 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3561 goto wrong_direction;
3562 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3564 goto unknown_direction;
3566 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3567 GST_QUERY_TYPE_NAME (query));
3569 serialized = GST_QUERY_IS_SERIALIZED (query);
3570 if (G_UNLIKELY (serialized))
3571 GST_PAD_STREAM_LOCK (pad);
3573 GST_OBJECT_LOCK (pad);
3574 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3575 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3576 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3578 ACQUIRE_PARENT (pad, parent, no_parent);
3579 GST_OBJECT_UNLOCK (pad);
3581 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3584 res = func (pad, parent, query);
3586 RELEASE_PARENT (parent);
3588 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3589 GST_QUERY_TYPE_NAME (query), res);
3594 GST_OBJECT_LOCK (pad);
3595 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3596 GST_OBJECT_UNLOCK (pad);
3598 if (G_UNLIKELY (serialized))
3599 GST_PAD_STREAM_UNLOCK (pad);
3606 g_warning ("pad %s:%s query %s in wrong direction",
3607 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3612 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3617 GST_DEBUG_OBJECT (pad, "had no parent");
3618 GST_OBJECT_UNLOCK (pad);
3619 if (G_UNLIKELY (serialized))
3620 GST_PAD_STREAM_UNLOCK (pad);
3625 GST_DEBUG_OBJECT (pad, "had no query function");
3626 RELEASE_PARENT (parent);
3627 if (G_UNLIKELY (serialized))
3628 GST_PAD_STREAM_UNLOCK (pad);
3633 GST_DEBUG_OBJECT (pad, "query failed");
3634 if (G_UNLIKELY (serialized))
3635 GST_PAD_STREAM_UNLOCK (pad);
3640 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3641 GST_OBJECT_UNLOCK (pad);
3642 if (G_UNLIKELY (serialized))
3643 GST_PAD_STREAM_UNLOCK (pad);
3645 /* if a probe dropped, we don't sent it further but assume that the probe
3646 * answered the query and return TRUE */
3647 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3657 * gst_pad_peer_query:
3658 * @pad: a #GstPad to invoke the peer query on.
3659 * @query: (transfer none): the #GstQuery to perform.
3661 * Performs gst_pad_query() on the peer of @pad.
3663 * The caller is responsible for both the allocation and deallocation of
3664 * the query structure.
3666 * Returns: %TRUE if the query could be performed. This function returns %FALSE
3667 * if @pad has no peer.
3670 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3673 GstPadProbeType type;
3674 gboolean res, serialized;
3677 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3678 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3680 if (GST_PAD_IS_SRC (pad)) {
3681 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3682 goto wrong_direction;
3683 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3684 } else if (GST_PAD_IS_SINK (pad)) {
3685 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3686 goto wrong_direction;
3687 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3689 goto unknown_direction;
3691 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3692 GST_QUERY_TYPE_NAME (query));
3694 serialized = GST_QUERY_IS_SERIALIZED (query);
3696 GST_OBJECT_LOCK (pad);
3697 if (GST_PAD_IS_SRC (pad) && serialized) {
3698 /* all serialized queries on the srcpad trigger push of
3700 if (check_sticky (pad, NULL) != GST_FLOW_OK)
3704 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3705 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3706 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3708 peerpad = GST_PAD_PEER (pad);
3709 if (G_UNLIKELY (peerpad == NULL))
3712 gst_object_ref (peerpad);
3713 GST_OBJECT_UNLOCK (pad);
3715 res = gst_pad_query (peerpad, query);
3717 gst_object_unref (peerpad);
3722 GST_OBJECT_LOCK (pad);
3723 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3724 GST_OBJECT_UNLOCK (pad);
3731 g_warning ("pad %s:%s query %s in wrong direction",
3732 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3737 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3742 GST_WARNING_OBJECT (pad, "could not send sticky events");
3743 GST_OBJECT_UNLOCK (pad);
3748 GST_INFO_OBJECT (pad, "pad has no peer");
3749 GST_OBJECT_UNLOCK (pad);
3754 GST_DEBUG_OBJECT (pad, "query failed");
3759 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3760 GST_OBJECT_UNLOCK (pad);
3762 /* if a probe dropped, we don't sent it further but assume that the probe
3763 * answered the query and return TRUE */
3764 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3773 /**********************************************************************
3774 * Data passing functions
3777 /* this is the chain function that does not perform the additional argument
3778 * checking for that little extra speed.
3780 static inline GstFlowReturn
3781 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3786 GST_PAD_STREAM_LOCK (pad);
3788 GST_OBJECT_LOCK (pad);
3789 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3792 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3795 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3798 #ifndef G_DISABLE_ASSERT
3799 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3800 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3802 ":%s:<%s:%s> Got data flow before stream-start event",
3803 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3805 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3807 ":%s:<%s:%s> Got data flow before segment event",
3808 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3810 pad->priv->last_cookie = pad->priv->events_cookie;
3814 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3816 PROBE_PUSH (pad, type, data, probe_stopped);
3818 parent = GST_OBJECT_PARENT (pad);
3819 GST_OBJECT_UNLOCK (pad);
3821 /* NOTE: we read the chainfunc unlocked.
3822 * we cannot hold the lock for the pad so we might send
3823 * the data to the wrong function. This is not really a
3824 * problem since functions are assigned at creation time
3825 * and don't change that often... */
3826 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3827 GstPadChainFunction chainfunc;
3829 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3832 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3833 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3834 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3836 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3838 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3839 "called chainfunction &%s with buffer %p, returned %s",
3840 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3842 GstPadChainListFunction chainlistfunc;
3844 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3847 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3848 "calling chainlistfunction &%s",
3849 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3851 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3853 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3854 "called chainlistfunction &%s, returned %s",
3855 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3858 GST_PAD_STREAM_UNLOCK (pad);
3865 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3866 "chaining, but pad was flushing");
3867 GST_OBJECT_UNLOCK (pad);
3868 GST_PAD_STREAM_UNLOCK (pad);
3869 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3870 return GST_FLOW_FLUSHING;
3874 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3875 GST_OBJECT_UNLOCK (pad);
3876 GST_PAD_STREAM_UNLOCK (pad);
3877 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3878 return GST_FLOW_EOS;
3882 g_critical ("chain on pad %s:%s but it was not in push mode",
3883 GST_DEBUG_PAD_NAME (pad));
3884 GST_OBJECT_UNLOCK (pad);
3885 GST_PAD_STREAM_UNLOCK (pad);
3886 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3887 return GST_FLOW_ERROR;
3891 GST_OBJECT_UNLOCK (pad);
3892 GST_PAD_STREAM_UNLOCK (pad);
3893 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3896 case GST_FLOW_CUSTOM_SUCCESS:
3897 GST_DEBUG_OBJECT (pad, "dropped buffer");
3901 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
3908 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3909 g_critical ("chain on pad %s:%s but it has no chainfunction",
3910 GST_DEBUG_PAD_NAME (pad));
3911 GST_PAD_STREAM_UNLOCK (pad);
3912 return GST_FLOW_NOT_SUPPORTED;
3918 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3919 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3922 * Chain a buffer to @pad.
3924 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3926 * If the buffer type is not acceptable for @pad (as negotiated with a
3927 * preceding GST_EVENT_CAPS event), this function returns
3928 * #GST_FLOW_NOT_NEGOTIATED.
3930 * The function proceeds calling the chain function installed on @pad (see
3931 * gst_pad_set_chain_function()) and the return value of that function is
3932 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3935 * In all cases, success or failure, the caller loses its reference to @buffer
3936 * after calling this function.
3938 * Returns: a #GstFlowReturn from the pad.
3943 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3945 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3946 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3947 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3949 return gst_pad_chain_data_unchecked (pad,
3950 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3953 static GstFlowReturn
3954 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3955 GstBufferList * list)
3961 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3963 len = gst_buffer_list_length (list);
3966 for (i = 0; i < len; i++) {
3967 buffer = gst_buffer_list_get (list, i);
3969 gst_pad_chain_data_unchecked (pad,
3970 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3971 gst_buffer_ref (buffer));
3972 if (ret != GST_FLOW_OK)
3975 gst_buffer_list_unref (list);
3981 * gst_pad_chain_list:
3982 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3983 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3986 * Chain a bufferlist to @pad.
3988 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3990 * If @pad was not negotiated properly with a CAPS event, this function
3991 * returns #GST_FLOW_NOT_NEGOTIATED.
3993 * The function proceeds calling the chainlist function installed on @pad (see
3994 * gst_pad_set_chain_list_function()) and the return value of that function is
3995 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3996 * chainlist function.
3998 * In all cases, success or failure, the caller loses its reference to @list
3999 * after calling this function.
4003 * Returns: a #GstFlowReturn from the pad.
4006 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4008 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4009 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4010 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4012 return gst_pad_chain_data_unchecked (pad,
4013 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4016 static GstFlowReturn
4017 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4022 GST_OBJECT_LOCK (pad);
4023 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4026 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4029 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4032 #ifndef G_DISABLE_ASSERT
4033 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4034 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4036 ":%s:<%s:%s> Got data flow before stream-start event",
4037 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4039 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4041 ":%s:<%s:%s> Got data flow before segment event",
4042 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4044 pad->priv->last_cookie = pad->priv->events_cookie;
4048 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4051 /* do block probes */
4052 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
4054 /* recheck sticky events because the probe might have cause a relink */
4055 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4058 /* do post-blocking probes */
4059 PROBE_PUSH (pad, type, data, probe_stopped);
4061 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4064 /* take ref to peer pad before releasing the lock */
4065 gst_object_ref (peer);
4067 GST_OBJECT_UNLOCK (pad);
4069 ret = gst_pad_chain_data_unchecked (peer, type, data);
4071 gst_object_unref (peer);
4073 GST_OBJECT_LOCK (pad);
4074 pad->ABI.abi.last_flowret = ret;
4076 if (pad->priv->using == 0) {
4077 /* pad is not active anymore, trigger idle callbacks */
4078 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4079 probe_stopped, ret);
4081 GST_OBJECT_UNLOCK (pad);
4085 /* ERROR recovery here */
4089 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4090 "pushing, but pad was flushing");
4091 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4092 GST_OBJECT_UNLOCK (pad);
4093 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4094 return GST_FLOW_FLUSHING;
4098 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4099 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4100 GST_OBJECT_UNLOCK (pad);
4101 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4102 return GST_FLOW_EOS;
4106 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4107 GST_DEBUG_PAD_NAME (pad));
4108 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4109 GST_OBJECT_UNLOCK (pad);
4110 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4111 return GST_FLOW_ERROR;
4115 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4116 "error pushing events, return %s", gst_flow_get_name (ret));
4117 pad->ABI.abi.last_flowret = ret;
4118 GST_OBJECT_UNLOCK (pad);
4119 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4124 GST_OBJECT_UNLOCK (pad);
4125 pad->ABI.abi.last_flowret =
4126 ret == GST_FLOW_CUSTOM_SUCCESS ? GST_FLOW_OK : ret;
4127 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4130 case GST_FLOW_CUSTOM_SUCCESS:
4131 GST_DEBUG_OBJECT (pad, "dropped buffer");
4135 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4142 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4143 "pushing, but it was not linked");
4144 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4145 GST_OBJECT_UNLOCK (pad);
4146 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4147 return GST_FLOW_NOT_LINKED;
4153 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4154 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4157 * Pushes a buffer to the peer of @pad.
4159 * This function will call installed block probes before triggering any
4160 * installed data probes.
4162 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4163 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4166 * In all cases, success or failure, the caller loses its reference to @buffer
4167 * after calling this function.
4169 * Returns: a #GstFlowReturn from the peer pad.
4174 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4176 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4177 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4178 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4180 return gst_pad_push_data (pad,
4181 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4185 * gst_pad_push_list:
4186 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4187 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4190 * Pushes a buffer list to the peer of @pad.
4192 * This function will call installed block probes before triggering any
4193 * installed data probes.
4195 * The function proceeds calling the chain function on the peer pad and returns
4196 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4197 * be returned. If the peer pad does not have any installed chainlist function
4198 * every group buffer of the list will be merged into a normal #GstBuffer and
4199 * chained via gst_pad_chain().
4201 * In all cases, success or failure, the caller loses its reference to @list
4202 * after calling this function.
4204 * Returns: a #GstFlowReturn from the peer pad.
4209 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4211 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4212 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4213 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4215 return gst_pad_push_data (pad,
4216 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4219 static GstFlowReturn
4220 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4221 GstBuffer ** buffer)
4224 GstPadGetRangeFunction getrangefunc;
4228 GST_PAD_STREAM_LOCK (pad);
4230 GST_OBJECT_LOCK (pad);
4231 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4234 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4237 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4242 /* when one of the probes returns DROPPED, probe_stopped will be called
4243 * and we skip calling the getrange function, res_buf should then contain a
4244 * valid result buffer */
4245 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4246 res_buf, offset, size, probe_stopped);
4248 /* recheck sticky events because the probe might have cause a relink */
4249 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4252 ACQUIRE_PARENT (pad, parent, no_parent);
4253 GST_OBJECT_UNLOCK (pad);
4255 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4258 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4259 "calling getrangefunc %s, offset %"
4260 G_GUINT64_FORMAT ", size %u",
4261 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4263 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4265 RELEASE_PARENT (parent);
4267 GST_OBJECT_LOCK (pad);
4268 if (G_UNLIKELY (ret != GST_FLOW_OK))
4269 goto get_range_failed;
4271 /* can only fire the signal if we have a valid buffer */
4273 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4274 res_buf, offset, size, probe_stopped_unref);
4275 pad->ABI.abi.last_flowret = ret;
4276 GST_OBJECT_UNLOCK (pad);
4278 GST_PAD_STREAM_UNLOCK (pad);
4287 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4288 "getrange, but pad was flushing");
4289 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4290 GST_OBJECT_UNLOCK (pad);
4291 GST_PAD_STREAM_UNLOCK (pad);
4292 return GST_FLOW_FLUSHING;
4296 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4297 GST_DEBUG_PAD_NAME (pad));
4298 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4299 GST_OBJECT_UNLOCK (pad);
4300 GST_PAD_STREAM_UNLOCK (pad);
4301 return GST_FLOW_ERROR;
4305 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4306 pad->ABI.abi.last_flowret = ret;
4307 GST_OBJECT_UNLOCK (pad);
4308 GST_PAD_STREAM_UNLOCK (pad);
4313 GST_DEBUG_OBJECT (pad, "no parent");
4314 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4315 GST_OBJECT_UNLOCK (pad);
4316 GST_PAD_STREAM_UNLOCK (pad);
4317 return GST_FLOW_FLUSHING;
4321 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4322 GST_DEBUG_PAD_NAME (pad));
4323 RELEASE_PARENT (parent);
4324 GST_PAD_STREAM_UNLOCK (pad);
4325 return GST_FLOW_NOT_SUPPORTED;
4329 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4330 "probe returned %s", gst_flow_get_name (ret));
4331 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4333 /* the probe filled the buffer and asks us to not call the getrange
4334 * anymore, we continue with the post probes then. */
4335 GST_DEBUG_OBJECT (pad, "handled buffer");
4339 /* no buffer, we are EOS */
4340 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4344 pad->ABI.abi.last_flowret = ret;
4345 GST_OBJECT_UNLOCK (pad);
4346 GST_PAD_STREAM_UNLOCK (pad);
4350 probe_stopped_unref:
4352 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4353 "probe returned %s", gst_flow_get_name (ret));
4354 /* if we drop here, it signals EOS */
4355 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4357 pad->ABI.abi.last_flowret = ret;
4358 GST_OBJECT_UNLOCK (pad);
4359 GST_PAD_STREAM_UNLOCK (pad);
4360 if (*buffer == NULL)
4361 gst_buffer_unref (res_buf);
4366 pad->ABI.abi.last_flowret = ret;
4367 GST_OBJECT_UNLOCK (pad);
4368 GST_PAD_STREAM_UNLOCK (pad);
4369 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4370 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4371 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4377 * gst_pad_get_range:
4378 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4379 * @offset: The start offset of the buffer
4380 * @size: The length of the buffer
4381 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4382 * returns #GST_FLOW_ERROR if %NULL.
4384 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4385 * immediately and @buffer is %NULL.
4387 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4388 * description of a getrange function. If @pad has no getrange function
4389 * installed (see gst_pad_set_getrange_function()) this function returns
4390 * #GST_FLOW_NOT_SUPPORTED.
4392 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4393 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4394 * must be freed with gst_buffer_unref() after usage.
4396 * When @buffer points to a variable that points to a valid #GstBuffer, the
4397 * buffer will be filled with the result data when this function returns
4398 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4399 * @size bytes will be filled in the result buffer and its size will be updated
4402 * Note that less than @size bytes can be returned in @buffer when, for example,
4403 * an EOS condition is near or when @buffer is not large enough to hold @size
4404 * bytes. The caller should check the result buffer size to get the result size.
4406 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4407 * will be unchanged.
4409 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4411 * Returns: a #GstFlowReturn from the pad.
4416 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4417 GstBuffer ** buffer)
4419 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4420 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4421 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4422 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4423 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4425 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4429 * gst_pad_pull_range:
4430 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4431 * @offset: The start offset of the buffer
4432 * @size: The length of the buffer
4433 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4434 * GST_FLOW_ERROR if %NULL.
4436 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4438 * This function will first trigger the pad block signal if it was
4441 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4442 * function returns the result of gst_pad_get_range() on the peer pad.
4443 * See gst_pad_get_range() for a list of return values and for the
4444 * semantics of the arguments of this function.
4446 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4447 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4448 * must be freed with gst_buffer_unref() after usage. When this function
4449 * returns any other result value, @buffer will still point to %NULL.
4451 * When @buffer points to a variable that points to a valid #GstBuffer, the
4452 * buffer will be filled with the result data when this function returns
4453 * #GST_FLOW_OK. When this function returns any other result value,
4454 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4455 * @size bytes will be filled in the result buffer and its size will be updated
4458 * Note that less than @size bytes can be returned in @buffer when, for example,
4459 * an EOS condition is near or when @buffer is not large enough to hold @size
4460 * bytes. The caller should check the result buffer size to get the result size.
4462 * Returns: a #GstFlowReturn from the peer pad.
4467 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4468 GstBuffer ** buffer)
4474 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4475 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4476 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4477 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4478 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4480 GST_OBJECT_LOCK (pad);
4481 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4484 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4489 /* when one of the probes returns DROPPED, probe_stopped will be
4490 * called and we skip calling the peer getrange function. *buffer should then
4491 * contain a valid buffer */
4492 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4493 res_buf, offset, size, probe_stopped);
4495 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4498 gst_object_ref (peer);
4500 GST_OBJECT_UNLOCK (pad);
4502 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4504 gst_object_unref (peer);
4506 GST_OBJECT_LOCK (pad);
4508 pad->ABI.abi.last_flowret = ret;
4509 if (pad->priv->using == 0) {
4510 /* pad is not active anymore, trigger idle callbacks */
4511 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4512 probe_stopped_unref, ret);
4515 if (G_UNLIKELY (ret != GST_FLOW_OK))
4516 goto pull_range_failed;
4519 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4520 res_buf, offset, size, probe_stopped_unref);
4522 GST_OBJECT_UNLOCK (pad);
4528 /* ERROR recovery here */
4531 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4532 "pullrange, but pad was flushing");
4533 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4534 GST_OBJECT_UNLOCK (pad);
4535 return GST_FLOW_FLUSHING;
4539 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4540 GST_DEBUG_PAD_NAME (pad));
4541 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4542 GST_OBJECT_UNLOCK (pad);
4543 return GST_FLOW_ERROR;
4547 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4548 gst_flow_get_name (ret));
4549 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4551 /* the probe filled the buffer and asks us to not forward to the peer
4552 * anymore, we continue with the post probes then */
4553 GST_DEBUG_OBJECT (pad, "handled buffer");
4557 /* no buffer, we are EOS then */
4558 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4562 pad->ABI.abi.last_flowret = ret;
4563 GST_OBJECT_UNLOCK (pad);
4568 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4569 "pulling range, but it was not linked");
4570 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4571 GST_OBJECT_UNLOCK (pad);
4572 return GST_FLOW_NOT_LINKED;
4576 pad->ABI.abi.last_flowret = ret;
4577 GST_OBJECT_UNLOCK (pad);
4578 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4579 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4580 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4583 probe_stopped_unref:
4585 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4586 "post probe returned %s", gst_flow_get_name (ret));
4588 /* if we drop here, it signals EOS */
4589 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4592 pad->ABI.abi.last_flowret = ret;
4593 GST_OBJECT_UNLOCK (pad);
4595 if (*buffer == NULL)
4596 gst_buffer_unref (res_buf);
4601 /* must be called with pad object lock */
4602 static GstFlowReturn
4603 store_sticky_event (GstPad * pad, GstEvent * event)
4608 gboolean res = FALSE;
4609 const gchar *name = NULL;
4610 gboolean insert = TRUE;
4612 type = GST_EVENT_TYPE (event);
4614 /* Store all sticky events except SEGMENT/EOS when we're flushing,
4615 * otherwise they can be dropped and nothing would ever resend them.
4616 * Only do that for activated pads though, everything else is a bug!
4618 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4619 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4620 || type == GST_EVENT_EOS))))
4623 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4626 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4627 name = gst_structure_get_name (gst_event_get_structure (event));
4629 events = pad->priv->events;
4632 for (i = 0; i < len; i++) {
4633 PadEvent *ev = &g_array_index (events, PadEvent, i);
4635 if (ev->event == NULL)
4638 if (type == GST_EVENT_TYPE (ev->event)) {
4639 /* matching types, check matching name if needed */
4640 if (name && !gst_event_has_name (ev->event, name))
4644 if ((res = gst_event_replace (&ev->event, event)))
4645 ev->received = FALSE;
4651 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4652 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4653 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4654 * storing the sticky ordered we can check that this is respected. */
4655 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4656 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4658 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4659 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4660 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4661 gst_event_type_get_name (type));
4667 ev.event = gst_event_ref (event);
4668 ev.received = FALSE;
4669 g_array_insert_val (events, i, ev);
4674 pad->priv->events_cookie++;
4675 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4677 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4679 switch (GST_EVENT_TYPE (event)) {
4680 case GST_EVENT_CAPS:
4681 GST_OBJECT_UNLOCK (pad);
4683 GST_DEBUG_OBJECT (pad, "notify caps");
4684 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4686 GST_OBJECT_LOCK (pad);
4692 if (type == GST_EVENT_EOS) {
4693 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4694 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4697 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4702 GST_DEBUG_OBJECT (pad, "pad is flushing");
4703 return GST_FLOW_FLUSHING;
4707 GST_DEBUG_OBJECT (pad, "pad is EOS");
4708 return GST_FLOW_EOS;
4713 * gst_pad_store_sticky_event:
4715 * @event: a #GstEvent
4717 * Store the sticky @event on @pad
4719 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4720 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4725 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4729 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4730 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4732 GST_OBJECT_LOCK (pad);
4733 ret = store_sticky_event (pad, event);
4734 GST_OBJECT_UNLOCK (pad);
4740 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
4742 PushStickyData *data = user_data;
4744 /* Forward all sticky events before our current one that are pending */
4745 if (ev->event != data->event
4746 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
4747 return push_sticky (pad, ev, data);
4752 /* should be called with pad LOCK */
4753 static GstFlowReturn
4754 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4755 GstPadProbeType type)
4759 GstEventType event_type;
4761 /* pass the adjusted event on. We need to do this even if
4762 * there is no peer pad because of the probes. */
4763 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
4765 /* Two checks to be made:
4766 * . (un)set the FLUSHING flag for flushing events,
4767 * . handle pad blocking */
4768 event_type = GST_EVENT_TYPE (event);
4769 switch (event_type) {
4770 case GST_EVENT_FLUSH_START:
4771 GST_PAD_SET_FLUSHING (pad);
4773 GST_PAD_BLOCK_BROADCAST (pad);
4774 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4776 case GST_EVENT_FLUSH_STOP:
4777 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
4780 GST_PAD_UNSET_FLUSHING (pad);
4782 /* Remove sticky EOS events */
4783 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4784 remove_event_by_type (pad, GST_EVENT_EOS);
4785 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4786 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4787 pad->ABI.abi.last_flowret = GST_FLOW_OK;
4789 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4793 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4796 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4797 * checked already or this is called as part of pushing sticky events,
4798 * in which case we still want to forward the EOS event downstream.
4801 switch (GST_EVENT_TYPE (event)) {
4802 case GST_EVENT_RECONFIGURE:
4803 if (GST_PAD_IS_SINK (pad))
4804 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4809 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4810 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4815 /* send probes after modifying the events above */
4816 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4818 /* recheck sticky events because the probe might have cause a relink */
4819 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
4820 && (GST_EVENT_IS_SERIALIZED (event)
4821 || GST_EVENT_IS_STICKY (event))) {
4822 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4823 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4825 /* Push all sticky events before our current one
4826 * that have changed */
4827 events_foreach (pad, sticky_changed, &data);
4830 /* now check the peer pad */
4831 peerpad = GST_PAD_PEER (pad);
4832 if (peerpad == NULL)
4835 gst_object_ref (peerpad);
4837 GST_OBJECT_UNLOCK (pad);
4839 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4840 event, gst_event_type_get_name (event_type), peerpad);
4842 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4844 /* Note: we gave away ownership of the event at this point but we can still
4845 * print the old pointer */
4846 GST_LOG_OBJECT (pad,
4847 "sent event %p to (%s) peerpad %" GST_PTR_FORMAT ", ret %s", event,
4848 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
4850 gst_object_unref (peerpad);
4852 GST_OBJECT_LOCK (pad);
4854 if (pad->priv->using == 0) {
4855 /* pad is not active anymore, trigger idle callbacks */
4856 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4857 idle_probe_stopped, ret);
4861 /* ERROR handling */
4864 GST_DEBUG_OBJECT (pad, "We're flushing");
4865 gst_event_unref (event);
4866 return GST_FLOW_FLUSHING;
4870 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
4871 gst_event_unref (event);
4872 return GST_FLOW_FLUSHING;
4876 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4877 gst_event_unref (event);
4880 case GST_FLOW_CUSTOM_SUCCESS:
4881 GST_DEBUG_OBJECT (pad, "dropped event");
4884 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4891 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
4892 gst_event_type_get_name (GST_EVENT_TYPE (event)));
4893 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4894 gst_event_unref (event);
4896 /* unlinked pads should not influence latency configuration */
4897 if (event_type == GST_EVENT_LATENCY)
4900 return GST_FLOW_NOT_LINKED;
4904 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4910 * gst_pad_push_event:
4911 * @pad: a #GstPad to push the event to.
4912 * @event: (transfer full): the #GstEvent to send to the pad.
4914 * Sends the event to the peer of the given pad. This function is
4915 * mainly used by elements to send events to their peer
4918 * This function takes ownership of the provided event so you should
4919 * gst_event_ref() it if you want to reuse the event after this call.
4921 * Returns: %TRUE if the event was handled.
4926 gst_pad_push_event (GstPad * pad, GstEvent * event)
4928 gboolean res = FALSE;
4929 GstPadProbeType type;
4930 gboolean sticky, serialized;
4932 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4933 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4935 if (GST_PAD_IS_SRC (pad)) {
4936 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4937 goto wrong_direction;
4938 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4939 } else if (GST_PAD_IS_SINK (pad)) {
4940 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4941 goto wrong_direction;
4942 /* events pushed on sinkpad never are sticky */
4943 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4945 goto unknown_direction;
4947 GST_OBJECT_LOCK (pad);
4948 sticky = GST_EVENT_IS_STICKY (event);
4949 serialized = GST_EVENT_IS_SERIALIZED (event);
4952 /* srcpad sticky events are stored immediately, the received flag is set
4953 * to FALSE and will be set to TRUE when we can successfully push the
4954 * event to the peer pad */
4955 switch (store_sticky_event (pad, event)) {
4956 case GST_FLOW_FLUSHING:
4964 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4965 /* all serialized or sticky events on the srcpad trigger push of
4967 res = (check_sticky (pad, event) == GST_FLOW_OK);
4972 /* other events are pushed right away */
4973 ret = gst_pad_push_event_unchecked (pad, event, type);
4974 /* dropped events by a probe are not an error */
4975 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4977 /* Errors in sticky event pushing are no problem and ignored here
4978 * as they will cause more meaningful errors during data flow.
4979 * For EOS events, that are not followed by data flow, we still
4980 * return FALSE here though.
4982 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4984 gst_event_unref (event);
4986 GST_OBJECT_UNLOCK (pad);
4990 /* ERROR handling */
4993 g_warning ("pad %s:%s pushing %s event in wrong direction",
4994 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4995 gst_event_unref (event);
5000 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5001 gst_event_unref (event);
5006 GST_DEBUG_OBJECT (pad, "We're flushing");
5007 GST_OBJECT_UNLOCK (pad);
5008 gst_event_unref (event);
5013 GST_DEBUG_OBJECT (pad, "We're EOS");
5014 GST_OBJECT_UNLOCK (pad);
5015 gst_event_unref (event);
5020 /* Check if we can call the event function with the given event */
5021 static GstFlowReturn
5022 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5026 switch (GST_EVENT_TYPE (event)) {
5027 case GST_EVENT_CAPS:
5029 /* backwards compatibility mode for caps */
5030 gst_event_parse_caps (event, &caps);
5032 if (!gst_pad_query_accept_caps (pad, caps))
5044 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5045 "caps %" GST_PTR_FORMAT " not accepted", caps);
5046 return GST_FLOW_NOT_NEGOTIATED;
5050 static GstFlowReturn
5051 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5052 GstPadProbeType type)
5055 GstEventType event_type;
5056 gboolean serialized, need_unlock = FALSE, sticky;
5057 GstPadEventFunction eventfunc;
5060 GST_OBJECT_LOCK (pad);
5062 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5064 if (GST_PAD_IS_SINK (pad))
5065 serialized = GST_EVENT_IS_SERIALIZED (event);
5068 sticky = GST_EVENT_IS_STICKY (event);
5069 event_type = GST_EVENT_TYPE (event);
5070 switch (event_type) {
5071 case GST_EVENT_FLUSH_START:
5072 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5073 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5075 /* can't even accept a flush begin event when flushing */
5076 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5079 GST_PAD_SET_FLUSHING (pad);
5080 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5082 case GST_EVENT_FLUSH_STOP:
5083 /* we can't accept flush-stop on inactive pads else the flushing flag
5084 * would be cleared and it would look like the pad can accept data.
5085 * Also, some elements restart a streaming thread in flush-stop which we
5086 * can't allow on inactive pads */
5087 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5090 GST_PAD_UNSET_FLUSHING (pad);
5091 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5092 /* Remove pending EOS events */
5093 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5094 remove_event_by_type (pad, GST_EVENT_EOS);
5095 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5096 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5097 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5099 GST_OBJECT_UNLOCK (pad);
5100 /* grab stream lock */
5101 GST_PAD_STREAM_LOCK (pad);
5103 GST_OBJECT_LOCK (pad);
5104 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5107 case GST_EVENT_RECONFIGURE:
5108 if (GST_PAD_IS_SRC (pad))
5109 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5111 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5112 "have event type %" GST_PTR_FORMAT, event);
5114 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5118 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5121 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5122 GST_OBJECT_UNLOCK (pad);
5123 GST_PAD_STREAM_LOCK (pad);
5125 GST_OBJECT_LOCK (pad);
5126 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5129 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5135 /* now do the probe */
5137 type | GST_PAD_PROBE_TYPE_PUSH |
5138 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5140 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5142 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5145 ACQUIRE_PARENT (pad, parent, no_parent);
5146 GST_OBJECT_UNLOCK (pad);
5148 ret = pre_eventfunc_check (pad, event);
5149 if (G_UNLIKELY (ret != GST_FLOW_OK))
5150 goto precheck_failed;
5153 gst_event_ref (event);
5155 if (eventfunc (pad, parent, event)) {
5158 /* something went wrong */
5159 switch (event_type) {
5160 case GST_EVENT_CAPS:
5161 ret = GST_FLOW_NOT_NEGOTIATED;
5164 ret = GST_FLOW_ERROR;
5168 RELEASE_PARENT (parent);
5170 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5173 if (ret == GST_FLOW_OK) {
5174 GST_OBJECT_LOCK (pad);
5175 /* after the event function accepted the event, we can store the sticky
5176 * event on the pad */
5177 switch (store_sticky_event (pad, event)) {
5178 case GST_FLOW_FLUSHING:
5185 GST_OBJECT_UNLOCK (pad);
5187 gst_event_unref (event);
5191 GST_PAD_STREAM_UNLOCK (pad);
5195 /* ERROR handling */
5198 GST_OBJECT_UNLOCK (pad);
5200 GST_PAD_STREAM_UNLOCK (pad);
5201 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5202 "Received event on flushing pad. Discarding");
5203 gst_event_unref (event);
5204 return GST_FLOW_FLUSHING;
5208 GST_OBJECT_UNLOCK (pad);
5210 GST_PAD_STREAM_UNLOCK (pad);
5211 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5212 "Received flush-stop on inactive pad. Discarding");
5213 gst_event_unref (event);
5214 return GST_FLOW_FLUSHING;
5218 GST_OBJECT_UNLOCK (pad);
5220 GST_PAD_STREAM_UNLOCK (pad);
5221 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5222 "Received event on EOS pad. Discarding");
5223 gst_event_unref (event);
5224 return GST_FLOW_EOS;
5228 GST_OBJECT_UNLOCK (pad);
5230 GST_PAD_STREAM_UNLOCK (pad);
5231 gst_event_unref (event);
5234 case GST_FLOW_CUSTOM_SUCCESS:
5235 GST_DEBUG_OBJECT (pad, "dropped event");
5239 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5246 g_warning ("pad %s:%s has no event handler, file a bug.",
5247 GST_DEBUG_PAD_NAME (pad));
5248 GST_OBJECT_UNLOCK (pad);
5250 GST_PAD_STREAM_UNLOCK (pad);
5251 gst_event_unref (event);
5252 return GST_FLOW_NOT_SUPPORTED;
5256 GST_DEBUG_OBJECT (pad, "no parent");
5257 GST_OBJECT_UNLOCK (pad);
5259 GST_PAD_STREAM_UNLOCK (pad);
5260 gst_event_unref (event);
5261 return GST_FLOW_FLUSHING;
5265 GST_DEBUG_OBJECT (pad, "pre event check failed");
5266 RELEASE_PARENT (parent);
5268 GST_PAD_STREAM_UNLOCK (pad);
5269 gst_event_unref (event);
5275 * gst_pad_send_event:
5276 * @pad: a #GstPad to send the event to.
5277 * @event: (transfer full): the #GstEvent to send to the pad.
5279 * Sends the event to the pad. This function can be used
5280 * by applications to send events in the pipeline.
5282 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5283 * sink pad, @event should be a downstream event. For example, you would not
5284 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5285 * Furthermore, some downstream events have to be serialized with data flow,
5286 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5287 * the event needs to be serialized with data flow, this function will take the
5288 * pad's stream lock while calling its event function.
5290 * To find out whether an event type is upstream, downstream, or downstream and
5291 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5292 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5293 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5294 * plugin doesn't need to bother itself with this information; the core handles
5295 * all necessary locks and checks.
5297 * This function takes ownership of the provided event so you should
5298 * gst_event_ref() it if you want to reuse the event after this call.
5300 * Returns: %TRUE if the event was handled.
5303 gst_pad_send_event (GstPad * pad, GstEvent * event)
5306 GstPadProbeType type;
5308 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5309 g_return_val_if_fail (event != NULL, FALSE);
5311 if (GST_PAD_IS_SINK (pad)) {
5312 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5313 goto wrong_direction;
5314 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5315 } else if (GST_PAD_IS_SRC (pad)) {
5316 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5317 goto wrong_direction;
5318 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5320 goto unknown_direction;
5322 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5329 /* ERROR handling */
5332 g_warning ("pad %s:%s sending %s event in wrong direction",
5333 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5334 gst_event_unref (event);
5339 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5340 gst_event_unref (event);
5346 * gst_pad_set_element_private:
5347 * @pad: the #GstPad to set the private data of.
5348 * @priv: The private data to attach to the pad.
5350 * Set the given private data gpointer on the pad.
5351 * This function can only be used by the element that owns the pad.
5352 * No locking is performed in this function.
5355 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5357 pad->element_private = priv;
5361 * gst_pad_get_element_private:
5362 * @pad: the #GstPad to get the private data of.
5364 * Gets the private data of a pad.
5365 * No locking is performed in this function.
5367 * Returns: (transfer none): a #gpointer to the private data.
5370 gst_pad_get_element_private (GstPad * pad)
5372 return pad->element_private;
5376 * gst_pad_get_sticky_event:
5377 * @pad: the #GstPad to get the event from.
5378 * @event_type: the #GstEventType that should be retrieved.
5379 * @idx: the index of the event
5381 * Returns a new reference of the sticky event of type @event_type
5384 * Returns: (transfer full) (nullable): a #GstEvent of type
5385 * @event_type or %NULL when no event of @event_type was on
5386 * @pad. Unref after usage.
5389 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5391 GstEvent *event = NULL;
5394 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5395 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5397 GST_OBJECT_LOCK (pad);
5398 ev = find_event_by_type (pad, event_type, idx);
5399 if (ev && (event = ev->event))
5400 gst_event_ref (event);
5401 GST_OBJECT_UNLOCK (pad);
5408 GstPadStickyEventsForeachFunction func;
5413 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5415 ForeachDispatch *data = user_data;
5416 gboolean ret = TRUE;
5419 GST_OBJECT_UNLOCK (pad);
5421 ret = data->func (pad, &ev->event, data->user_data);
5423 GST_OBJECT_LOCK (pad);
5430 * gst_pad_sticky_events_foreach:
5431 * @pad: the #GstPad that should be used for iteration.
5432 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5433 * should be called for every event.
5434 * @user_data: (closure): the optional user data.
5436 * Iterates all sticky events on @pad and calls @foreach_func for every
5437 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5440 gst_pad_sticky_events_foreach (GstPad * pad,
5441 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5443 ForeachDispatch data;
5445 g_return_if_fail (GST_IS_PAD (pad));
5446 g_return_if_fail (foreach_func != NULL);
5448 data.func = foreach_func;
5449 data.user_data = user_data;
5451 GST_OBJECT_LOCK (pad);
5452 events_foreach (pad, foreach_dispatch_function, &data);
5453 GST_OBJECT_UNLOCK (pad);
5457 do_stream_status (GstPad * pad, GstStreamStatusType type,
5458 GThread * thread, GstTask * task)
5462 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5464 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5465 if (GST_IS_ELEMENT (parent)) {
5466 GstMessage *message;
5467 GValue value = { 0 };
5469 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5470 gchar *tname, *ename, *pname;
5472 /* create a good task name */
5473 ename = gst_element_get_name (parent);
5474 pname = gst_pad_get_name (pad);
5475 tname = g_strdup_printf ("%s:%s", ename, pname);
5479 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5483 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5486 g_value_init (&value, GST_TYPE_TASK);
5487 g_value_set_object (&value, task);
5488 gst_message_set_stream_status_object (message, &value);
5489 g_value_unset (&value);
5491 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5492 gst_element_post_message (parent, message);
5494 gst_object_unref (parent);
5499 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5501 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5506 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5508 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5513 * gst_pad_start_task:
5514 * @pad: the #GstPad to start the task of
5515 * @func: the task function to call
5516 * @user_data: user data passed to the task function
5517 * @notify: called when @user_data is no longer referenced
5519 * Starts a task that repeatedly calls @func with @user_data. This function
5520 * is mostly used in pad activation functions to start the dataflow.
5521 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5522 * before @func is called.
5524 * Returns: a %TRUE if the task could be started.
5527 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5528 GDestroyNotify notify)
5533 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5534 g_return_val_if_fail (func != NULL, FALSE);
5536 GST_DEBUG_OBJECT (pad, "start task");
5538 GST_OBJECT_LOCK (pad);
5539 task = GST_PAD_TASK (pad);
5541 task = gst_task_new (func, user_data, notify);
5542 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5543 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5544 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5545 GST_INFO_OBJECT (pad, "created task %p", task);
5546 GST_PAD_TASK (pad) = task;
5547 gst_object_ref (task);
5548 /* release lock to post the message */
5549 GST_OBJECT_UNLOCK (pad);
5551 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5553 gst_object_unref (task);
5555 GST_OBJECT_LOCK (pad);
5556 /* nobody else is supposed to have changed the pad now */
5557 if (GST_PAD_TASK (pad) != task)
5558 goto concurrent_stop;
5560 res = gst_task_set_state (task, GST_TASK_STARTED);
5561 GST_OBJECT_UNLOCK (pad);
5568 GST_OBJECT_UNLOCK (pad);
5574 * gst_pad_pause_task:
5575 * @pad: the #GstPad to pause the task of
5577 * Pause the task of @pad. This function will also wait until the
5578 * function executed by the task is finished if this function is not
5579 * called from the task function.
5581 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
5585 gst_pad_pause_task (GstPad * pad)
5590 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5592 GST_DEBUG_OBJECT (pad, "pause task");
5594 GST_OBJECT_LOCK (pad);
5595 task = GST_PAD_TASK (pad);
5598 res = gst_task_set_state (task, GST_TASK_PAUSED);
5599 GST_OBJECT_UNLOCK (pad);
5601 /* wait for task function to finish, this lock is recursive so it does nothing
5602 * when the pause is called from the task itself */
5603 GST_PAD_STREAM_LOCK (pad);
5604 GST_PAD_STREAM_UNLOCK (pad);
5610 GST_DEBUG_OBJECT (pad, "pad has no task");
5611 GST_OBJECT_UNLOCK (pad);
5617 * gst_pad_stop_task:
5618 * @pad: the #GstPad to stop the task of
5620 * Stop the task of @pad. This function will also make sure that the
5621 * function executed by the task will effectively stop if not called
5622 * from the GstTaskFunction.
5624 * This function will deadlock if called from the GstTaskFunction of
5625 * the task. Use gst_task_pause() instead.
5627 * Regardless of whether the pad has a task, the stream lock is acquired and
5628 * released so as to ensure that streaming through this pad has finished.
5630 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
5633 gst_pad_stop_task (GstPad * pad)
5638 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5640 GST_DEBUG_OBJECT (pad, "stop task");
5642 GST_OBJECT_LOCK (pad);
5643 task = GST_PAD_TASK (pad);
5646 GST_PAD_TASK (pad) = NULL;
5647 res = gst_task_set_state (task, GST_TASK_STOPPED);
5648 GST_OBJECT_UNLOCK (pad);
5650 GST_PAD_STREAM_LOCK (pad);
5651 GST_PAD_STREAM_UNLOCK (pad);
5653 if (!gst_task_join (task))
5656 gst_object_unref (task);
5662 GST_DEBUG_OBJECT (pad, "no task");
5663 GST_OBJECT_UNLOCK (pad);
5665 GST_PAD_STREAM_LOCK (pad);
5666 GST_PAD_STREAM_UNLOCK (pad);
5668 /* this is not an error */
5673 /* this is bad, possibly the application tried to join the task from
5674 * the task's thread. We install the task again so that it will be stopped
5675 * again from the right thread next time hopefully. */
5676 GST_OBJECT_LOCK (pad);
5677 GST_DEBUG_OBJECT (pad, "join failed");
5678 /* we can only install this task if there was no other task */
5679 if (GST_PAD_TASK (pad) == NULL)
5680 GST_PAD_TASK (pad) = task;
5681 GST_OBJECT_UNLOCK (pad);
5688 * gst_pad_probe_info_get_event:
5689 * @info: a #GstPadProbeInfo
5691 * Returns: (transfer none): The #GstEvent from the probe
5695 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5697 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5698 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5700 return GST_PAD_PROBE_INFO_EVENT (info);
5705 * gst_pad_probe_info_get_query:
5706 * @info: a #GstPadProbeInfo
5708 * Returns: (transfer none): The #GstQuery from the probe
5712 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5714 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5715 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5717 return GST_PAD_PROBE_INFO_QUERY (info);
5721 * gst_pad_probe_info_get_buffer:
5722 * @info: a #GstPadProbeInfo
5724 * Returns: (transfer none): The #GstBuffer from the probe
5728 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5730 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5732 return GST_PAD_PROBE_INFO_BUFFER (info);
5736 * gst_pad_probe_info_get_bufferlist:
5737 * @info: a #GstPadProbeInfo
5739 * Returns: (transfer none): The #GstBufferlist from the probe
5743 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5745 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5747 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
5751 * gst_pad_get_last_flow_return:
5754 * Gets the #GstFlowReturn return from the last data passed by this pad.
5759 gst_pad_get_last_flow_return (GstPad * pad)
5763 GST_OBJECT_LOCK (pad);
5764 ret = GST_PAD_LAST_FLOW_RETURN (pad);
5765 GST_OBJECT_UNLOCK (pad);