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)
613 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_TIME_FORMAT,
614 GST_TIME_ARGS (pad->offset));
616 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
619 g_assert (!upstream);
621 /* copy segment values */
622 gst_event_copy_segment (event, &segment);
623 gst_event_unref (event);
625 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
626 event = gst_event_new_segment (&segment);
629 event = gst_event_make_writable (event);
630 offset = gst_event_get_running_time_offset (event);
632 offset -= pad->offset;
634 offset += pad->offset;
635 gst_event_set_running_time_offset (event, offset);
640 static inline GstEvent *
641 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
643 if (G_UNLIKELY (pad->offset != 0))
644 return _apply_pad_offset (pad, event, upstream);
649 /* should be called with the OBJECT_LOCK */
651 get_pad_caps (GstPad * pad)
653 GstCaps *caps = NULL;
656 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
658 gst_event_parse_caps (ev->event, &caps);
664 gst_pad_dispose (GObject * object)
666 GstPad *pad = GST_PAD_CAST (object);
669 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
671 /* unlink the peer pad */
672 if ((peer = gst_pad_get_peer (pad))) {
673 /* window for MT unsafeness, someone else could unlink here
674 * and then we call unlink with wrong pads. The unlink
675 * function would catch this and safely return failed. */
676 if (GST_PAD_IS_SRC (pad))
677 gst_pad_unlink (pad, peer);
679 gst_pad_unlink (peer, pad);
681 gst_object_unref (peer);
684 gst_pad_set_pad_template (pad, NULL);
686 GST_OBJECT_LOCK (pad);
688 GST_OBJECT_UNLOCK (pad);
690 g_hook_list_clear (&pad->probes);
692 G_OBJECT_CLASS (parent_class)->dispose (object);
696 gst_pad_finalize (GObject * object)
698 GstPad *pad = GST_PAD_CAST (object);
701 /* in case the task is still around, clean it up */
702 if ((task = GST_PAD_TASK (pad))) {
703 gst_task_join (task);
704 GST_PAD_TASK (pad) = NULL;
705 gst_object_unref (task);
708 if (pad->activatenotify)
709 pad->activatenotify (pad->activatedata);
710 if (pad->activatemodenotify)
711 pad->activatemodenotify (pad->activatemodedata);
713 pad->linknotify (pad->linkdata);
714 if (pad->unlinknotify)
715 pad->unlinknotify (pad->unlinkdata);
716 if (pad->chainnotify)
717 pad->chainnotify (pad->chaindata);
718 if (pad->chainlistnotify)
719 pad->chainlistnotify (pad->chainlistdata);
720 if (pad->getrangenotify)
721 pad->getrangenotify (pad->getrangedata);
722 if (pad->eventnotify)
723 pad->eventnotify (pad->eventdata);
724 if (pad->querynotify)
725 pad->querynotify (pad->querydata);
726 if (pad->iterintlinknotify)
727 pad->iterintlinknotify (pad->iterintlinkdata);
729 g_rec_mutex_clear (&pad->stream_rec_lock);
730 g_cond_clear (&pad->block_cond);
731 g_array_free (pad->priv->events, TRUE);
733 G_OBJECT_CLASS (parent_class)->finalize (object);
737 gst_pad_set_property (GObject * object, guint prop_id,
738 const GValue * value, GParamSpec * pspec)
740 g_return_if_fail (GST_IS_PAD (object));
743 case PAD_PROP_DIRECTION:
744 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
746 case PAD_PROP_TEMPLATE:
747 gst_pad_set_pad_template (GST_PAD_CAST (object),
748 (GstPadTemplate *) g_value_get_object (value));
751 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
757 gst_pad_get_property (GObject * object, guint prop_id,
758 GValue * value, GParamSpec * pspec)
760 g_return_if_fail (GST_IS_PAD (object));
764 GST_OBJECT_LOCK (object);
765 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
766 GST_OBJECT_UNLOCK (object);
768 case PAD_PROP_DIRECTION:
769 g_value_set_enum (value, GST_PAD_DIRECTION (object));
771 case PAD_PROP_TEMPLATE:
772 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
775 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
782 * @name: (allow-none): the name of the new pad.
783 * @direction: the #GstPadDirection of the pad.
785 * Creates a new pad with the given name in the given direction.
786 * If name is %NULL, a guaranteed unique name (across all pads)
788 * This function makes a copy of the name so you can safely free the name.
790 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
796 gst_pad_new (const gchar * name, GstPadDirection direction)
798 return g_object_new (GST_TYPE_PAD,
799 "name", name, "direction", direction, NULL);
803 * gst_pad_new_from_template:
804 * @templ: the pad template to use
805 * @name: (allow-none): the name of the pad
807 * Creates a new pad with the given name from the given template.
808 * If name is %NULL, a guaranteed unique name (across all pads)
810 * This function makes a copy of the name so you can safely free the name.
812 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
816 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
818 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
820 return g_object_new (GST_TYPE_PAD,
821 "name", name, "direction", templ->direction, "template", templ, NULL);
825 * gst_pad_new_from_static_template:
826 * @templ: the #GstStaticPadTemplate to use
827 * @name: the name of the pad
829 * Creates a new pad with the given name from the given static template.
830 * If name is %NULL, a guaranteed unique name (across all pads)
832 * This function makes a copy of the name so you can safely free the name.
834 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
838 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
842 GstPadTemplate *template;
844 template = gst_static_pad_template_get (templ);
845 pad = gst_pad_new_from_template (template, name);
846 gst_object_unref (template);
850 #define ACQUIRE_PARENT(pad, parent, label) \
852 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
853 gst_object_ref (parent); \
854 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
858 #define RELEASE_PARENT(parent) \
860 if (G_LIKELY (parent)) \
861 gst_object_unref (parent); \
865 * gst_pad_get_direction:
866 * @pad: a #GstPad to get the direction of.
868 * Gets the direction of the pad. The direction of the pad is
869 * decided at construction time so this function does not take
872 * Returns: the #GstPadDirection of the pad.
877 gst_pad_get_direction (GstPad * pad)
879 GstPadDirection result;
881 /* PAD_UNKNOWN is a little silly but we need some sort of
882 * error return value */
883 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
885 result = GST_PAD_DIRECTION (pad);
891 gst_pad_activate_default (GstPad * pad, GstObject * parent)
893 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
897 * gst_pad_mode_get_name:
898 * @mode: the pad mode
900 * Return the name of a pad mode, for use in debug messages mostly.
902 * Returns: short mnemonic for pad mode @mode
905 gst_pad_mode_get_name (GstPadMode mode)
908 case GST_PAD_MODE_NONE:
910 case GST_PAD_MODE_PUSH:
912 case GST_PAD_MODE_PULL:
921 pre_activate (GstPad * pad, GstPadMode new_mode)
924 case GST_PAD_MODE_NONE:
925 GST_OBJECT_LOCK (pad);
926 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
927 GST_PAD_SET_FLUSHING (pad);
928 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
929 GST_PAD_MODE (pad) = new_mode;
930 /* unlock blocked pads so element can resume and stop */
931 GST_PAD_BLOCK_BROADCAST (pad);
932 GST_OBJECT_UNLOCK (pad);
934 case GST_PAD_MODE_PUSH:
935 case GST_PAD_MODE_PULL:
936 GST_OBJECT_LOCK (pad);
937 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
938 gst_pad_mode_get_name (new_mode));
939 GST_PAD_UNSET_FLUSHING (pad);
940 pad->ABI.abi.last_flowret = GST_FLOW_OK;
941 GST_PAD_MODE (pad) = new_mode;
942 if (GST_PAD_IS_SINK (pad)) {
944 /* make sure the peer src pad sends us all events */
945 if ((peer = GST_PAD_PEER (pad))) {
946 gst_object_ref (peer);
947 GST_OBJECT_UNLOCK (pad);
949 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
950 GST_DEBUG_PAD_NAME (peer));
952 GST_OBJECT_LOCK (peer);
953 schedule_events (peer, NULL);
954 GST_OBJECT_UNLOCK (peer);
956 gst_object_unref (peer);
958 GST_OBJECT_UNLOCK (pad);
961 GST_OBJECT_UNLOCK (pad);
968 post_activate (GstPad * pad, GstPadMode new_mode)
971 case GST_PAD_MODE_NONE:
972 /* ensures that streaming stops */
973 GST_PAD_STREAM_LOCK (pad);
974 GST_DEBUG_OBJECT (pad, "stopped streaming");
975 GST_OBJECT_LOCK (pad);
977 GST_OBJECT_UNLOCK (pad);
978 GST_PAD_STREAM_UNLOCK (pad);
980 case GST_PAD_MODE_PUSH:
981 case GST_PAD_MODE_PULL:
988 * gst_pad_set_active:
989 * @pad: the #GstPad to activate or deactivate.
990 * @active: whether or not the pad should be active.
992 * Activates or deactivates the given pad.
993 * Normally called from within core state change functions.
995 * If @active, makes sure the pad is active. If it is already active, either in
996 * push or pull mode, just return. Otherwise dispatches to the pad's activate
997 * function to perform the actual activation.
999 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1000 * and a %FALSE argument.
1002 * Returns: %TRUE if the operation was successful.
1007 gst_pad_set_active (GstPad * pad, gboolean active)
1011 gboolean ret = FALSE;
1013 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1015 GST_OBJECT_LOCK (pad);
1016 old = GST_PAD_MODE (pad);
1017 ACQUIRE_PARENT (pad, parent, no_parent);
1018 GST_OBJECT_UNLOCK (pad);
1021 if (old == GST_PAD_MODE_NONE) {
1022 GST_DEBUG_OBJECT (pad, "activating pad from none");
1023 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1025 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1027 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1028 gst_pad_mode_get_name (old));
1032 if (old == GST_PAD_MODE_NONE) {
1033 GST_DEBUG_OBJECT (pad, "pad was inactive");
1036 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1037 gst_pad_mode_get_name (old));
1038 ret = gst_pad_activate_mode (pad, old, FALSE);
1040 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1044 RELEASE_PARENT (parent);
1046 if (G_UNLIKELY (!ret))
1054 GST_DEBUG_OBJECT (pad, "no parent");
1055 GST_OBJECT_UNLOCK (pad);
1060 GST_OBJECT_LOCK (pad);
1062 g_critical ("Failed to deactivate pad %s:%s, very bad",
1063 GST_DEBUG_PAD_NAME (pad));
1065 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1067 GST_OBJECT_UNLOCK (pad);
1073 * gst_pad_activate_mode:
1074 * @pad: the #GstPad to activate or deactivate.
1075 * @mode: the requested activation mode
1076 * @active: whether or not the pad should be active.
1078 * Activates or deactivates the given pad in @mode via dispatching to the
1079 * pad's activatemodefunc. For use from within pad activation functions only.
1081 * If you don't know what this is, you probably don't want to call it.
1083 * Returns: %TRUE if the operation was successful.
1088 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1090 gboolean res = FALSE;
1092 GstPadMode old, new;
1093 GstPadDirection dir;
1096 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1098 GST_OBJECT_LOCK (pad);
1099 old = GST_PAD_MODE (pad);
1100 dir = GST_PAD_DIRECTION (pad);
1101 ACQUIRE_PARENT (pad, parent, no_parent);
1102 GST_OBJECT_UNLOCK (pad);
1104 new = active ? mode : GST_PAD_MODE_NONE;
1109 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1110 /* pad was activate in the wrong direction, deactivate it
1111 * and reactivate it in the requested mode */
1112 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1113 gst_pad_mode_get_name (old));
1115 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1116 goto deactivate_failed;
1120 case GST_PAD_MODE_PULL:
1122 if (dir == GST_PAD_SINK) {
1123 if ((peer = gst_pad_get_peer (pad))) {
1124 GST_DEBUG_OBJECT (pad, "calling peer");
1125 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1127 gst_object_unref (peer);
1129 /* there is no peer, this is only fatal when we activate. When we
1130 * deactivate, we must assume the application has unlinked the peer and
1131 * will deactivate it eventually. */
1135 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1138 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1139 goto failure; /* Can't activate pull on a src without a
1140 getrange function */
1148 /* Mark pad as needing reconfiguration */
1150 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1151 pre_activate (pad, new);
1153 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1154 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1158 /* can happen for sinks of passthrough elements */
1161 post_activate (pad, new);
1163 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1164 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1169 /* Clear sticky flags on deactivation */
1171 GST_OBJECT_LOCK (pad);
1172 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1173 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1174 GST_OBJECT_UNLOCK (pad);
1178 RELEASE_PARENT (parent);
1184 GST_DEBUG_OBJECT (pad, "no parent");
1185 GST_OBJECT_UNLOCK (pad);
1190 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1191 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1196 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1197 "failed to %s in switch to %s mode from %s mode",
1198 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1199 gst_pad_mode_get_name (old));
1204 GST_OBJECT_LOCK (peer);
1205 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1206 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1207 GST_OBJECT_UNLOCK (peer);
1208 gst_object_unref (peer);
1213 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1214 "pad in pull mode");
1219 GST_OBJECT_LOCK (pad);
1220 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1221 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1222 GST_PAD_SET_FLUSHING (pad);
1223 GST_PAD_MODE (pad) = old;
1224 GST_OBJECT_UNLOCK (pad);
1230 * gst_pad_is_active:
1231 * @pad: the #GstPad to query
1233 * Query if a pad is active
1235 * Returns: %TRUE if the pad is active.
1240 gst_pad_is_active (GstPad * pad)
1242 gboolean result = FALSE;
1244 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1246 GST_OBJECT_LOCK (pad);
1247 result = GST_PAD_IS_ACTIVE (pad);
1248 GST_OBJECT_UNLOCK (pad);
1254 cleanup_hook (GstPad * pad, GHook * hook)
1256 GstPadProbeType type;
1258 if (!G_HOOK_IS_VALID (hook))
1261 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1263 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1264 /* unblock when we remove the last blocking probe */
1266 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1269 /* Might have new probes now that want to be called */
1270 GST_PAD_BLOCK_BROADCAST (pad);
1272 if (pad->num_blocked == 0) {
1273 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1274 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1277 g_hook_destroy_link (&pad->probes, hook);
1282 * gst_pad_add_probe:
1283 * @pad: the #GstPad to add the probe to
1284 * @mask: the probe mask
1285 * @callback: #GstPadProbeCallback that will be called with notifications of
1287 * @user_data: (closure): user data passed to the callback
1288 * @destroy_data: #GDestroyNotify for user_data
1290 * Be notified of different states of pads. The provided callback is called for
1291 * every state that matches @mask.
1293 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1294 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1295 * happend that the probe can be run immediately and if the probe returns
1296 * GST_PAD_PROBE_REMOVE this functions returns 0.
1301 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1302 GstPadProbeCallback callback, gpointer user_data,
1303 GDestroyNotify destroy_data)
1308 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1309 g_return_val_if_fail (mask != 0, 0);
1311 GST_OBJECT_LOCK (pad);
1313 /* make a new probe */
1314 hook = g_hook_alloc (&pad->probes);
1316 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1319 /* when no contraints are given for the types, assume all types are
1321 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1322 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1323 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1324 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1326 /* store our flags and other fields */
1327 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1328 hook->func = callback;
1329 hook->data = user_data;
1330 hook->destroy = destroy_data;
1331 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1334 g_hook_prepend (&pad->probes, hook);
1336 /* incremenent cookie so that the new hook get's called */
1337 pad->priv->probe_list_cookie++;
1339 /* get the id of the hook, we return this and it can be used to remove the
1341 res = hook->hook_id;
1343 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1345 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1346 /* we have a block probe */
1348 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1349 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1350 "now %d blocking probes", pad->num_blocked);
1352 /* Might have new probes now that want to be called */
1353 GST_PAD_BLOCK_BROADCAST (pad);
1356 /* call the callback if we need to be called for idle callbacks */
1357 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1358 if (pad->priv->using > 0) {
1359 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1360 * flag above, the last thread to leave the push will do the callback. New
1361 * threads going into the push will block. */
1362 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1363 "pad is in use, delay idle callback");
1364 GST_OBJECT_UNLOCK (pad);
1366 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1367 GstPadProbeReturn ret;
1369 /* Keep another ref, the callback could destroy the pad */
1370 gst_object_ref (pad);
1372 /* the pad is idle now, we can signal the idle callback now */
1373 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1374 "pad is idle, trigger idle callback");
1375 GST_OBJECT_UNLOCK (pad);
1377 ret = callback (pad, &info, user_data);
1379 GST_OBJECT_LOCK (pad);
1381 case GST_PAD_PROBE_REMOVE:
1382 /* remove the probe */
1383 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1384 cleanup_hook (pad, hook);
1387 case GST_PAD_PROBE_DROP:
1388 GST_DEBUG_OBJECT (pad, "asked to drop item");
1390 case GST_PAD_PROBE_PASS:
1391 GST_DEBUG_OBJECT (pad, "asked to pass item");
1393 case GST_PAD_PROBE_OK:
1394 GST_DEBUG_OBJECT (pad, "probe returned OK");
1397 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1400 GST_OBJECT_UNLOCK (pad);
1402 gst_object_unref (pad);
1405 GST_OBJECT_UNLOCK (pad);
1411 * gst_pad_remove_probe:
1412 * @pad: the #GstPad with the probe
1413 * @id: the probe id to remove
1415 * Remove the probe with @id from @pad.
1420 gst_pad_remove_probe (GstPad * pad, gulong id)
1424 g_return_if_fail (GST_IS_PAD (pad));
1426 GST_OBJECT_LOCK (pad);
1428 hook = g_hook_get (&pad->probes, id);
1432 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1434 cleanup_hook (pad, hook);
1435 GST_OBJECT_UNLOCK (pad);
1441 GST_OBJECT_UNLOCK (pad);
1442 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1448 * gst_pad_is_blocked:
1449 * @pad: the #GstPad to query
1451 * Checks if the pad is blocked or not. This function returns the
1452 * last requested state of the pad. It is not certain that the pad
1453 * is actually blocking at this point (see gst_pad_is_blocking()).
1455 * Returns: %TRUE if the pad is blocked.
1460 gst_pad_is_blocked (GstPad * pad)
1462 gboolean result = FALSE;
1464 g_return_val_if_fail (GST_IS_PAD (pad), result);
1466 GST_OBJECT_LOCK (pad);
1467 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1468 GST_OBJECT_UNLOCK (pad);
1474 * gst_pad_is_blocking:
1475 * @pad: the #GstPad to query
1477 * Checks if the pad is blocking or not. This is a guaranteed state
1478 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1480 * Returns: %TRUE if the pad is blocking.
1485 gst_pad_is_blocking (GstPad * pad)
1487 gboolean result = FALSE;
1489 g_return_val_if_fail (GST_IS_PAD (pad), result);
1491 GST_OBJECT_LOCK (pad);
1492 /* the blocking flag is only valid if the pad is not flushing */
1493 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1494 GST_OBJECT_UNLOCK (pad);
1500 * gst_pad_needs_reconfigure:
1501 * @pad: the #GstPad to check
1503 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1504 * if the flag was set.
1506 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1509 gst_pad_needs_reconfigure (GstPad * pad)
1511 gboolean reconfigure;
1513 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1515 GST_OBJECT_LOCK (pad);
1516 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1517 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1518 GST_OBJECT_UNLOCK (pad);
1524 * gst_pad_check_reconfigure:
1525 * @pad: the #GstPad to check
1527 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1528 * if the flag was set.
1530 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1533 gst_pad_check_reconfigure (GstPad * pad)
1535 gboolean reconfigure;
1537 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1539 GST_OBJECT_LOCK (pad);
1540 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1542 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1543 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1545 GST_OBJECT_UNLOCK (pad);
1551 * gst_pad_mark_reconfigure:
1552 * @pad: the #GstPad to mark
1554 * Mark a pad for needing reconfiguration. The next call to
1555 * gst_pad_check_reconfigure() will return %TRUE after this call.
1558 gst_pad_mark_reconfigure (GstPad * pad)
1560 g_return_if_fail (GST_IS_PAD (pad));
1562 GST_OBJECT_LOCK (pad);
1563 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1564 GST_OBJECT_UNLOCK (pad);
1568 * gst_pad_set_activate_function:
1570 * @f: the #GstPadActivateFunction to set.
1572 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1576 * gst_pad_set_activate_function_full:
1578 * @activate: the #GstPadActivateFunction to set.
1579 * @user_data: user_data passed to @notify
1580 * @notify: notify called when @activate will not be used anymore.
1582 * Sets the given activate function for @pad. The activate function will
1583 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1584 * Only makes sense to set on sink pads.
1586 * Call this function if your sink pad can start a pull-based task.
1589 gst_pad_set_activate_function_full (GstPad * pad,
1590 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1592 g_return_if_fail (GST_IS_PAD (pad));
1594 if (pad->activatenotify)
1595 pad->activatenotify (pad->activatedata);
1596 GST_PAD_ACTIVATEFUNC (pad) = activate;
1597 pad->activatedata = user_data;
1598 pad->activatenotify = notify;
1600 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1601 GST_DEBUG_FUNCPTR_NAME (activate));
1605 * gst_pad_set_activatemode_function:
1607 * @f: the #GstPadActivateModeFunction to set.
1609 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1613 * gst_pad_set_activatemode_function_full:
1615 * @activatemode: the #GstPadActivateModeFunction to set.
1616 * @user_data: user_data passed to @notify
1617 * @notify: notify called when @activatemode will not be used anymore.
1619 * Sets the given activate_mode function for the pad. An activate_mode function
1620 * prepares the element for data passing.
1623 gst_pad_set_activatemode_function_full (GstPad * pad,
1624 GstPadActivateModeFunction activatemode, gpointer user_data,
1625 GDestroyNotify notify)
1627 g_return_if_fail (GST_IS_PAD (pad));
1629 if (pad->activatemodenotify)
1630 pad->activatemodenotify (pad->activatemodedata);
1631 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1632 pad->activatemodedata = user_data;
1633 pad->activatemodenotify = notify;
1635 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1636 GST_DEBUG_FUNCPTR_NAME (activatemode));
1640 * gst_pad_set_chain_function:
1641 * @p: a sink #GstPad.
1642 * @f: the #GstPadChainFunction to set.
1644 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1648 * gst_pad_set_chain_function_full:
1649 * @pad: a sink #GstPad.
1650 * @chain: the #GstPadChainFunction to set.
1651 * @user_data: user_data passed to @notify
1652 * @notify: notify called when @chain will not be used anymore.
1654 * Sets the given chain function for the pad. The chain function is called to
1655 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1658 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1659 gpointer user_data, GDestroyNotify notify)
1661 g_return_if_fail (GST_IS_PAD (pad));
1662 g_return_if_fail (GST_PAD_IS_SINK (pad));
1664 if (pad->chainnotify)
1665 pad->chainnotify (pad->chaindata);
1666 GST_PAD_CHAINFUNC (pad) = chain;
1667 pad->chaindata = user_data;
1668 pad->chainnotify = notify;
1670 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1671 GST_DEBUG_FUNCPTR_NAME (chain));
1675 * gst_pad_set_chain_list_function:
1676 * @p: a sink #GstPad.
1677 * @f: the #GstPadChainListFunction to set.
1679 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1683 * gst_pad_set_chain_list_function_full:
1684 * @pad: a sink #GstPad.
1685 * @chainlist: the #GstPadChainListFunction to set.
1686 * @user_data: user_data passed to @notify
1687 * @notify: notify called when @chainlist will not be used anymore.
1689 * Sets the given chain list function for the pad. The chainlist function is
1690 * called to process a #GstBufferList input buffer list. See
1691 * #GstPadChainListFunction for more details.
1694 gst_pad_set_chain_list_function_full (GstPad * pad,
1695 GstPadChainListFunction chainlist, gpointer user_data,
1696 GDestroyNotify notify)
1698 g_return_if_fail (GST_IS_PAD (pad));
1699 g_return_if_fail (GST_PAD_IS_SINK (pad));
1701 if (pad->chainlistnotify)
1702 pad->chainlistnotify (pad->chainlistdata);
1703 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1704 pad->chainlistdata = user_data;
1705 pad->chainlistnotify = notify;
1707 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1708 GST_DEBUG_FUNCPTR_NAME (chainlist));
1712 * gst_pad_set_getrange_function:
1713 * @p: a source #GstPad.
1714 * @f: the #GstPadGetRangeFunction to set.
1716 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1720 * gst_pad_set_getrange_function_full:
1721 * @pad: a source #GstPad.
1722 * @get: the #GstPadGetRangeFunction to set.
1723 * @user_data: user_data passed to @notify
1724 * @notify: notify called when @get will not be used anymore.
1726 * Sets the given getrange function for the pad. The getrange function is
1727 * called to produce a new #GstBuffer to start the processing pipeline. see
1728 * #GstPadGetRangeFunction for a description of the getrange function.
1731 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1732 gpointer user_data, GDestroyNotify notify)
1734 g_return_if_fail (GST_IS_PAD (pad));
1735 g_return_if_fail (GST_PAD_IS_SRC (pad));
1737 if (pad->getrangenotify)
1738 pad->getrangenotify (pad->getrangedata);
1739 GST_PAD_GETRANGEFUNC (pad) = get;
1740 pad->getrangedata = user_data;
1741 pad->getrangenotify = notify;
1743 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1744 GST_DEBUG_FUNCPTR_NAME (get));
1748 * gst_pad_set_event_function:
1749 * @p: a #GstPad of either direction.
1750 * @f: the #GstPadEventFunction to set.
1752 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1756 * gst_pad_set_event_function_full:
1757 * @pad: a #GstPad of either direction.
1758 * @event: the #GstPadEventFunction to set.
1759 * @user_data: user_data passed to @notify
1760 * @notify: notify called when @event will not be used anymore.
1762 * Sets the given event handler for the pad.
1765 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1766 gpointer user_data, GDestroyNotify notify)
1768 g_return_if_fail (GST_IS_PAD (pad));
1770 if (pad->eventnotify)
1771 pad->eventnotify (pad->eventdata);
1772 GST_PAD_EVENTFUNC (pad) = event;
1773 pad->eventdata = user_data;
1774 pad->eventnotify = notify;
1776 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1777 GST_DEBUG_FUNCPTR_NAME (event));
1781 * gst_pad_set_query_function:
1782 * @p: a #GstPad of either direction.
1783 * @f: the #GstPadQueryFunction to set.
1785 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1789 * gst_pad_set_query_function_full:
1790 * @pad: a #GstPad of either direction.
1791 * @query: the #GstPadQueryFunction to set.
1792 * @user_data: user_data passed to @notify
1793 * @notify: notify called when @query will not be used anymore.
1795 * Set the given query function for the pad.
1798 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1799 gpointer user_data, GDestroyNotify notify)
1801 g_return_if_fail (GST_IS_PAD (pad));
1803 if (pad->querynotify)
1804 pad->querynotify (pad->querydata);
1805 GST_PAD_QUERYFUNC (pad) = query;
1806 pad->querydata = user_data;
1807 pad->querynotify = notify;
1809 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1810 GST_DEBUG_FUNCPTR_NAME (query));
1814 * gst_pad_set_iterate_internal_links_function:
1815 * @p: a #GstPad of either direction.
1816 * @f: the #GstPadIterIntLinkFunction to set.
1818 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1819 * for the user_data and notify.
1822 * gst_pad_set_iterate_internal_links_function_full:
1823 * @pad: a #GstPad of either direction.
1824 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1825 * @user_data: user_data passed to @notify
1826 * @notify: notify called when @iterintlink will not be used anymore.
1828 * Sets the given internal link iterator function for the pad.
1831 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1832 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1833 GDestroyNotify notify)
1835 g_return_if_fail (GST_IS_PAD (pad));
1837 if (pad->iterintlinknotify)
1838 pad->iterintlinknotify (pad->iterintlinkdata);
1839 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1840 pad->iterintlinkdata = user_data;
1841 pad->iterintlinknotify = notify;
1843 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1844 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1848 * gst_pad_set_link_function:
1850 * @f: the #GstPadLinkFunction to set.
1852 * Calls gst_pad_set_link_function_full() with %NULL
1853 * for the user_data and notify.
1856 * gst_pad_set_link_function_full:
1858 * @link: the #GstPadLinkFunction to set.
1859 * @user_data: user_data passed to @notify
1860 * @notify: notify called when @link will not be used anymore.
1862 * Sets the given link function for the pad. It will be called when
1863 * the pad is linked with another pad.
1865 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1868 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1869 * cannot be made for some reason.
1871 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1872 * of the peer sink pad, if present.
1875 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1876 gpointer user_data, GDestroyNotify notify)
1878 g_return_if_fail (GST_IS_PAD (pad));
1880 if (pad->linknotify)
1881 pad->linknotify (pad->linkdata);
1882 GST_PAD_LINKFUNC (pad) = link;
1883 pad->linkdata = user_data;
1884 pad->linknotify = notify;
1886 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1887 GST_DEBUG_FUNCPTR_NAME (link));
1891 * gst_pad_set_unlink_function:
1893 * @f: the #GstPadUnlinkFunction to set.
1895 * Calls gst_pad_set_unlink_function_full() with %NULL
1896 * for the user_data and notify.
1899 * gst_pad_set_unlink_function_full:
1901 * @unlink: the #GstPadUnlinkFunction to set.
1902 * @user_data: user_data passed to @notify
1903 * @notify: notify called when @unlink will not be used anymore.
1905 * Sets the given unlink function for the pad. It will be called
1906 * when the pad is unlinked.
1909 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1910 gpointer user_data, GDestroyNotify notify)
1912 g_return_if_fail (GST_IS_PAD (pad));
1914 if (pad->unlinknotify)
1915 pad->unlinknotify (pad->unlinkdata);
1916 GST_PAD_UNLINKFUNC (pad) = unlink;
1917 pad->unlinkdata = user_data;
1918 pad->unlinknotify = notify;
1920 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1921 GST_DEBUG_FUNCPTR_NAME (unlink));
1926 * @srcpad: the source #GstPad to unlink.
1927 * @sinkpad: the sink #GstPad to unlink.
1929 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1930 * signal on both pads.
1932 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
1933 * the pads were not linked together.
1938 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1940 gboolean result = FALSE;
1941 GstElement *parent = NULL;
1943 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1944 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1945 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1946 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1948 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1949 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1950 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1952 /* We need to notify the parent before taking any pad locks as the bin in
1953 * question might be waiting for a lock on the pad while holding its lock
1954 * that our message will try to take. */
1955 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1956 if (GST_IS_ELEMENT (parent)) {
1957 gst_element_post_message (parent,
1958 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1959 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1961 gst_object_unref (parent);
1966 GST_OBJECT_LOCK (srcpad);
1967 GST_OBJECT_LOCK (sinkpad);
1969 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1970 goto not_linked_together;
1972 if (GST_PAD_UNLINKFUNC (srcpad)) {
1973 GstObject *tmpparent;
1975 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1977 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1978 RELEASE_PARENT (tmpparent);
1981 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1982 GstObject *tmpparent;
1984 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1986 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1987 RELEASE_PARENT (tmpparent);
1991 /* first clear peers */
1992 GST_PAD_PEER (srcpad) = NULL;
1993 GST_PAD_PEER (sinkpad) = NULL;
1995 GST_OBJECT_UNLOCK (sinkpad);
1996 GST_OBJECT_UNLOCK (srcpad);
1998 /* fire off a signal to each of the pads telling them
1999 * that they've been unlinked */
2000 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2001 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2003 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2004 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2009 if (parent != NULL) {
2010 gst_element_post_message (parent,
2011 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2012 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2013 gst_object_unref (parent);
2018 not_linked_together:
2020 /* we do not emit a warning in this case because unlinking cannot
2021 * be made MT safe.*/
2022 GST_OBJECT_UNLOCK (sinkpad);
2023 GST_OBJECT_UNLOCK (srcpad);
2029 * gst_pad_is_linked:
2030 * @pad: pad to check
2032 * Checks if a @pad is linked to another pad or not.
2034 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2039 gst_pad_is_linked (GstPad * pad)
2043 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2045 GST_OBJECT_LOCK (pad);
2046 result = (GST_PAD_PEER (pad) != NULL);
2047 GST_OBJECT_UNLOCK (pad);
2052 /* get the caps from both pads and see if the intersection
2055 * This function should be called with the pad LOCK on both
2059 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2060 GstPadLinkCheck flags)
2062 GstCaps *srccaps = NULL;
2063 GstCaps *sinkcaps = NULL;
2064 gboolean compatible = FALSE;
2066 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2069 /* Doing the expensive caps checking takes priority over only checking the template caps */
2070 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2071 GST_OBJECT_UNLOCK (sink);
2072 GST_OBJECT_UNLOCK (src);
2074 srccaps = gst_pad_query_caps (src, NULL);
2075 sinkcaps = gst_pad_query_caps (sink, NULL);
2077 GST_OBJECT_LOCK (src);
2078 GST_OBJECT_LOCK (sink);
2080 /* If one of the two pads doesn't have a template, consider the intersection
2082 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2083 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2087 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2089 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2092 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2094 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2097 /* if we have caps on both pads we can check the intersection. If one
2098 * of the caps is %NULL, we return %TRUE. */
2099 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2101 gst_caps_unref (srccaps);
2103 gst_caps_unref (sinkcaps);
2107 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2108 gst_caps_unref (srccaps);
2109 gst_caps_unref (sinkcaps);
2112 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2113 (compatible ? "" : "not "));
2118 /* check if the grandparents of both pads are the same.
2119 * This check is required so that we don't try to link
2120 * pads from elements in different bins without ghostpads.
2122 * The LOCK should be held on both pads
2125 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2127 GstObject *psrc, *psink;
2129 psrc = GST_OBJECT_PARENT (src);
2130 psink = GST_OBJECT_PARENT (sink);
2132 /* if one of the pads has no parent, we allow the link */
2133 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2136 /* only care about parents that are elements */
2137 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2138 goto no_element_parent;
2140 /* if the parents are the same, we have a loop */
2141 if (G_UNLIKELY (psrc == psink))
2144 /* if they both have a parent, we check the grandparents. We can not lock
2145 * the parent because we hold on the child (pad) and the locking order is
2146 * parent >> child. */
2147 psrc = GST_OBJECT_PARENT (psrc);
2148 psink = GST_OBJECT_PARENT (psink);
2150 /* if they have grandparents but they are not the same */
2151 if (G_UNLIKELY (psrc != psink))
2152 goto wrong_grandparents;
2159 GST_CAT_DEBUG (GST_CAT_CAPS,
2160 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2161 GST_PTR_FORMAT, psrc, psink);
2166 GST_CAT_DEBUG (GST_CAT_CAPS,
2167 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2168 GST_PTR_FORMAT, psrc, psink);
2173 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2179 GST_CAT_DEBUG (GST_CAT_CAPS,
2180 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2181 GST_PTR_FORMAT, psrc, psink);
2186 /* FIXME leftover from an attempt at refactoring... */
2187 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2188 * the two pads will be locked in the srcpad, sinkpad order. */
2189 static GstPadLinkReturn
2190 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2192 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2193 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2195 GST_OBJECT_LOCK (srcpad);
2197 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2198 goto src_was_linked;
2200 GST_OBJECT_LOCK (sinkpad);
2202 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2203 goto sink_was_linked;
2205 /* check hierarchy, pads can only be linked if the grandparents
2207 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2208 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2209 goto wrong_hierarchy;
2211 /* check pad caps for non-empty intersection */
2212 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2215 /* FIXME check pad scheduling for non-empty intersection */
2217 return GST_PAD_LINK_OK;
2221 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2222 GST_DEBUG_PAD_NAME (srcpad),
2223 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2224 /* we do not emit a warning in this case because unlinking cannot
2225 * be made MT safe.*/
2226 GST_OBJECT_UNLOCK (srcpad);
2227 return GST_PAD_LINK_WAS_LINKED;
2231 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2232 GST_DEBUG_PAD_NAME (sinkpad),
2233 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2234 /* we do not emit a warning in this case because unlinking cannot
2235 * be made MT safe.*/
2236 GST_OBJECT_UNLOCK (sinkpad);
2237 GST_OBJECT_UNLOCK (srcpad);
2238 return GST_PAD_LINK_WAS_LINKED;
2242 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2243 GST_OBJECT_UNLOCK (sinkpad);
2244 GST_OBJECT_UNLOCK (srcpad);
2245 return GST_PAD_LINK_WRONG_HIERARCHY;
2249 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2250 GST_OBJECT_UNLOCK (sinkpad);
2251 GST_OBJECT_UNLOCK (srcpad);
2252 return GST_PAD_LINK_NOFORMAT;
2258 * @srcpad: the source #GstPad.
2259 * @sinkpad: the sink #GstPad.
2261 * Checks if the source pad and the sink pad are compatible so they can be
2264 * Returns: %TRUE if the pads can be linked.
2267 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2269 GstPadLinkReturn result;
2271 /* generic checks */
2272 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2273 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2275 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2276 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2278 /* gst_pad_link_prepare does everything for us, we only release the locks
2279 * on the pads that it gets us. If this function returns !OK the locks are not
2281 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2282 if (result != GST_PAD_LINK_OK)
2285 GST_OBJECT_UNLOCK (srcpad);
2286 GST_OBJECT_UNLOCK (sinkpad);
2289 return result == GST_PAD_LINK_OK;
2293 * gst_pad_link_full:
2294 * @srcpad: the source #GstPad to link.
2295 * @sinkpad: the sink #GstPad to link.
2296 * @flags: the checks to validate when linking
2298 * Links the source pad and the sink pad.
2300 * This variant of #gst_pad_link provides a more granular control on the
2301 * checks being done when linking. While providing some considerable speedups
2302 * the caller of this method must be aware that wrong usage of those flags
2303 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2304 * for more information.
2308 * Returns: A result code indicating if the connection worked or
2312 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2314 GstPadLinkReturn result;
2316 GstPadLinkFunction srcfunc, sinkfunc;
2318 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2319 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2320 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2321 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2322 GST_PAD_LINK_WRONG_DIRECTION);
2324 /* Notify the parent early. See gst_pad_unlink for details. */
2325 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2326 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2327 gst_element_post_message (parent,
2328 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2329 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2331 gst_object_unref (parent);
2336 /* prepare will also lock the two pads */
2337 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2339 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2342 /* must set peers before calling the link function */
2343 GST_PAD_PEER (srcpad) = sinkpad;
2344 GST_PAD_PEER (sinkpad) = srcpad;
2346 /* check events, when something is different, mark pending */
2347 schedule_events (srcpad, sinkpad);
2349 /* get the link functions */
2350 srcfunc = GST_PAD_LINKFUNC (srcpad);
2351 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2353 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2354 /* custom link functions, execute them */
2355 GST_OBJECT_UNLOCK (sinkpad);
2356 GST_OBJECT_UNLOCK (srcpad);
2359 GstObject *tmpparent;
2361 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2362 /* this one will call the peer link function */
2363 result = srcfunc (srcpad, tmpparent, sinkpad);
2364 RELEASE_PARENT (tmpparent);
2365 } else if (sinkfunc) {
2366 GstObject *tmpparent;
2368 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2369 /* if no source link function, we need to call the sink link
2370 * function ourselves. */
2371 result = sinkfunc (sinkpad, tmpparent, srcpad);
2372 RELEASE_PARENT (tmpparent);
2376 GST_OBJECT_LOCK (srcpad);
2377 GST_OBJECT_LOCK (sinkpad);
2379 /* we released the lock, check if the same pads are linked still */
2380 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2381 goto concurrent_link;
2383 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2386 GST_OBJECT_UNLOCK (sinkpad);
2387 GST_OBJECT_UNLOCK (srcpad);
2389 /* fire off a signal to each of the pads telling them
2390 * that they've been linked */
2391 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2392 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2394 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2395 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2397 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2400 if (G_LIKELY (parent)) {
2401 gst_element_post_message (parent,
2402 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2403 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2404 gst_object_unref (parent);
2412 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2413 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2414 GST_OBJECT_UNLOCK (sinkpad);
2415 GST_OBJECT_UNLOCK (srcpad);
2417 /* The other link operation succeeded first */
2418 result = GST_PAD_LINK_WAS_LINKED;
2423 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2424 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2425 gst_pad_link_get_name (result));
2427 GST_PAD_PEER (srcpad) = NULL;
2428 GST_PAD_PEER (sinkpad) = NULL;
2430 GST_OBJECT_UNLOCK (sinkpad);
2431 GST_OBJECT_UNLOCK (srcpad);
2439 * @srcpad: the source #GstPad to link.
2440 * @sinkpad: the sink #GstPad to link.
2442 * Links the source pad and the sink pad.
2444 * Returns: A result code indicating if the connection worked or
2450 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2452 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2456 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2458 GstPadTemplate **template_p;
2460 /* this function would need checks if it weren't static */
2462 GST_OBJECT_LOCK (pad);
2463 template_p = &pad->padtemplate;
2464 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2465 GST_OBJECT_UNLOCK (pad);
2468 gst_pad_template_pad_created (templ, pad);
2472 * gst_pad_get_pad_template:
2475 * Gets the template for @pad.
2477 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2478 * this pad was instantiated, or %NULL if this pad has no
2479 * template. Unref after usage.
2482 gst_pad_get_pad_template (GstPad * pad)
2484 GstPadTemplate *templ;
2486 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2488 templ = GST_PAD_PAD_TEMPLATE (pad);
2490 return (templ ? gst_object_ref (templ) : NULL);
2494 * gst_pad_has_current_caps:
2495 * @pad: a #GstPad to check
2497 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2499 * Returns: %TRUE when @pad has caps associated with it.
2502 gst_pad_has_current_caps (GstPad * pad)
2507 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2509 GST_OBJECT_LOCK (pad);
2510 caps = get_pad_caps (pad);
2511 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2512 "check current pad caps %" GST_PTR_FORMAT, caps);
2513 result = (caps != NULL);
2514 GST_OBJECT_UNLOCK (pad);
2520 * gst_pad_get_current_caps:
2521 * @pad: a #GstPad to get the current capabilities of.
2523 * Gets the capabilities currently configured on @pad with the last
2524 * #GST_EVENT_CAPS event.
2526 * Returns: the current caps of the pad with incremented ref-count.
2529 gst_pad_get_current_caps (GstPad * pad)
2533 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2535 GST_OBJECT_LOCK (pad);
2536 if ((result = get_pad_caps (pad)))
2537 gst_caps_ref (result);
2538 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2539 "get current pad caps %" GST_PTR_FORMAT, result);
2540 GST_OBJECT_UNLOCK (pad);
2546 * gst_pad_get_pad_template_caps:
2547 * @pad: a #GstPad to get the template capabilities from.
2549 * Gets the capabilities for @pad's template.
2551 * Returns: (transfer full): the #GstCaps of this pad template.
2552 * Unref after usage.
2555 gst_pad_get_pad_template_caps (GstPad * pad)
2557 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2559 if (GST_PAD_PAD_TEMPLATE (pad))
2560 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2562 return gst_caps_ref (GST_CAPS_ANY);
2567 * @pad: a #GstPad to get the peer of.
2569 * Gets the peer of @pad. This function refs the peer pad so
2570 * you need to unref it after use.
2572 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2577 gst_pad_get_peer (GstPad * pad)
2581 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2583 GST_OBJECT_LOCK (pad);
2584 result = GST_PAD_PEER (pad);
2586 gst_object_ref (result);
2587 GST_OBJECT_UNLOCK (pad);
2593 * gst_pad_get_allowed_caps:
2596 * Gets the capabilities of the allowed media types that can flow through
2597 * @pad and its peer.
2599 * The allowed capabilities is calculated as the intersection of the results of
2600 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2601 * on the resulting caps.
2603 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2604 * pad link. Unref the caps when you no longer need it. This
2605 * function returns %NULL when @pad has no peer.
2610 gst_pad_get_allowed_caps (GstPad * pad)
2616 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2618 GST_OBJECT_LOCK (pad);
2619 peer = GST_PAD_PEER (pad);
2620 if (G_UNLIKELY (peer == NULL))
2623 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2625 gst_object_ref (peer);
2626 GST_OBJECT_UNLOCK (pad);
2627 mycaps = gst_pad_query_caps (pad, NULL);
2629 caps = gst_pad_query_caps (peer, mycaps);
2630 gst_object_unref (peer);
2632 gst_caps_unref (mycaps);
2634 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2641 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2642 GST_OBJECT_UNLOCK (pad);
2649 * gst_pad_iterate_internal_links_default:
2650 * @pad: the #GstPad to get the internal links of.
2651 * @parent: (allow-none): the parent of @pad or %NULL
2653 * Iterate the list of pads to which the given pad is linked to inside of
2654 * the parent element.
2655 * This is the default handler, and thus returns an iterator of all of the
2656 * pads inside the parent element with opposite direction.
2658 * The caller must free this iterator after use with gst_iterator_free().
2660 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2661 * has no parent. Unref each returned pad with gst_object_unref().
2664 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2671 GstElement *eparent;
2673 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2675 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2676 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2678 GST_OBJECT_LOCK (pad);
2679 eparent = GST_PAD_PARENT (pad);
2680 if (!eparent || !GST_IS_ELEMENT (eparent))
2683 gst_object_ref (eparent);
2684 GST_OBJECT_UNLOCK (pad);
2687 if (pad->direction == GST_PAD_SRC)
2688 padlist = &eparent->sinkpads;
2690 padlist = &eparent->srcpads;
2692 GST_DEBUG_OBJECT (pad, "Making iterator");
2694 cookie = &eparent->pads_cookie;
2696 lock = GST_OBJECT_GET_LOCK (eparent);
2698 res = gst_iterator_new_list (GST_TYPE_PAD,
2699 lock, cookie, padlist, (GObject *) owner, NULL);
2701 gst_object_unref (owner);
2708 GST_OBJECT_UNLOCK (pad);
2709 GST_DEBUG_OBJECT (pad, "no parent element");
2715 * gst_pad_iterate_internal_links:
2716 * @pad: the GstPad to get the internal links of.
2718 * Gets an iterator for the pads to which the given pad is linked to inside
2719 * of the parent element.
2721 * Each #GstPad element yielded by the iterator will have its refcount increased,
2722 * so unref after use.
2724 * Free-function: gst_iterator_free
2726 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2727 * or %NULL when the pad does not have an iterator function
2728 * configured. Use gst_iterator_free() after usage.
2731 gst_pad_iterate_internal_links (GstPad * pad)
2733 GstIterator *res = NULL;
2736 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2738 GST_OBJECT_LOCK (pad);
2739 ACQUIRE_PARENT (pad, parent, no_parent);
2740 GST_OBJECT_UNLOCK (pad);
2742 if (GST_PAD_ITERINTLINKFUNC (pad))
2743 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2745 RELEASE_PARENT (parent);
2752 GST_DEBUG_OBJECT (pad, "no parent");
2753 GST_OBJECT_UNLOCK (pad);
2761 * @forward: (scope call): a #GstPadForwardFunction
2762 * @user_data: user data passed to @forward
2764 * Calls @forward for all internally linked pads of @pad. This function deals with
2765 * dynamically changing internal pads and will make sure that the @forward
2766 * function is only called once for each pad.
2768 * When @forward returns %TRUE, no further pads will be processed.
2770 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2773 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2776 gboolean result = FALSE;
2778 gboolean done = FALSE;
2779 GValue item = { 0, };
2780 GList *pushed_pads = NULL;
2782 iter = gst_pad_iterate_internal_links (pad);
2788 switch (gst_iterator_next (iter, &item)) {
2789 case GST_ITERATOR_OK:
2793 intpad = g_value_get_object (&item);
2795 /* if already pushed, skip. FIXME, find something faster to tag pads */
2796 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2797 g_value_reset (&item);
2801 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2802 GST_DEBUG_PAD_NAME (intpad));
2803 done = result = forward (intpad, user_data);
2805 pushed_pads = g_list_prepend (pushed_pads, intpad);
2807 g_value_reset (&item);
2810 case GST_ITERATOR_RESYNC:
2811 /* We don't reset the result here because we don't push the event
2812 * again on pads that got the event already and because we need
2813 * to consider the result of the previous pushes */
2814 gst_iterator_resync (iter);
2816 case GST_ITERATOR_ERROR:
2817 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2820 case GST_ITERATOR_DONE:
2825 g_value_unset (&item);
2826 gst_iterator_free (iter);
2828 g_list_free (pushed_pads);
2838 gboolean dispatched;
2842 event_forward_func (GstPad * pad, EventData * data)
2844 /* for each pad we send to, we should ref the event; it's up
2845 * to downstream to unref again when handled. */
2846 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2847 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2849 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2851 data->dispatched = TRUE;
2858 * gst_pad_event_default:
2859 * @pad: a #GstPad to call the default event handler on.
2860 * @parent: (allow-none): the parent of @pad or %NULL
2861 * @event: (transfer full): the #GstEvent to handle.
2863 * Invokes the default event handler for the given pad.
2865 * The EOS event will pause the task associated with @pad before it is forwarded
2866 * to all internally linked pads,
2868 * The the event is sent to all pads internally linked to @pad. This function
2869 * takes ownership of @event.
2871 * Returns: %TRUE if the event was sent successfully.
2874 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2876 gboolean result, forward = TRUE;
2878 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2879 g_return_val_if_fail (event != NULL, FALSE);
2881 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2884 switch (GST_EVENT_TYPE (event)) {
2885 case GST_EVENT_CAPS:
2886 forward = GST_PAD_IS_PROXY_CAPS (pad);
2897 data.dispatched = FALSE;
2898 data.result = FALSE;
2900 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2902 /* for sinkpads without a parent element or without internal links, nothing
2903 * will be dispatched but we still want to return TRUE. */
2904 if (data.dispatched)
2905 result = data.result;
2910 gst_event_unref (event);
2915 /* Default accept caps implementation just checks against
2916 * the allowed caps for the pad */
2918 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2920 /* get the caps and see if it intersects to something not empty */
2921 GstCaps *caps, *allowed;
2924 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2926 /* first forward the query to internally linked pads when we are dealing with
2928 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2929 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2934 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2935 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2937 gst_query_parse_accept_caps (query, &caps);
2938 allowed = gst_pad_query_caps (pad, caps);
2941 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
2942 GST_DEBUG_OBJECT (pad,
2943 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
2945 result = gst_caps_can_intersect (caps, allowed);
2947 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
2948 GST_PTR_FORMAT, allowed, caps);
2949 result = gst_caps_is_subset (caps, allowed);
2951 gst_caps_unref (allowed);
2953 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
2956 gst_query_set_accept_caps_result (query, result);
2962 /* Default caps implementation */
2964 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2966 GstCaps *result = NULL, *filter;
2967 GstPadTemplate *templ;
2968 gboolean fixed_caps;
2970 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2973 /* first try to proxy if we must */
2974 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2975 if ((gst_pad_proxy_query_caps (pad, query))) {
2980 gst_query_parse_caps (query, &filter);
2982 /* no proxy or it failed, do default handling */
2983 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2985 GST_OBJECT_LOCK (pad);
2987 /* fixed caps, try the negotiated caps first */
2988 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2989 if ((result = get_pad_caps (pad)))
2990 goto filter_done_unlock;
2993 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2994 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2995 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2996 goto filter_done_unlock;
3000 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3001 "non-fixed pad caps: trying pad caps");
3002 /* non fixed caps, try the negotiated caps */
3003 if ((result = get_pad_caps (pad)))
3004 goto filter_done_unlock;
3007 /* this almost never happens */
3008 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3009 result = GST_CAPS_ANY;
3012 GST_OBJECT_UNLOCK (pad);
3014 /* run the filter on the result */
3016 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3017 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3018 GST_PTR_FORMAT, result, result, filter, filter);
3019 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3020 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3023 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3024 "using caps %p %" GST_PTR_FORMAT, result, result);
3025 result = gst_caps_ref (result);
3027 gst_query_set_caps_result (query, result);
3028 gst_caps_unref (result);
3038 gboolean dispatched;
3042 query_forward_func (GstPad * pad, QueryData * data)
3044 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3045 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3047 data->result |= gst_pad_peer_query (pad, data->query);
3049 data->dispatched = TRUE;
3051 /* stop on first successful reply */
3052 return data->result;
3056 * gst_pad_query_default:
3057 * @pad: a #GstPad to call the default query handler on.
3058 * @parent: (allow-none): the parent of @pad or %NULL
3059 * @query: (transfer none): the #GstQuery to handle.
3061 * Invokes the default query handler for the given pad.
3062 * The query is sent to all pads internally linked to @pad. Note that
3063 * if there are many possible sink pads that are internally linked to
3064 * @pad, only one will be sent the query.
3065 * Multi-sinkpad elements should implement custom query handlers.
3067 * Returns: %TRUE if the query was performed successfully.
3070 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3072 gboolean forward, ret = FALSE;
3074 switch (GST_QUERY_TYPE (query)) {
3075 case GST_QUERY_SCHEDULING:
3076 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3078 case GST_QUERY_ALLOCATION:
3079 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3081 case GST_QUERY_ACCEPT_CAPS:
3082 ret = gst_pad_query_accept_caps_default (pad, query);
3085 case GST_QUERY_CAPS:
3086 ret = gst_pad_query_caps_default (pad, query);
3089 case GST_QUERY_POSITION:
3090 case GST_QUERY_SEEKING:
3091 case GST_QUERY_FORMATS:
3092 case GST_QUERY_LATENCY:
3093 case GST_QUERY_JITTER:
3094 case GST_QUERY_RATE:
3095 case GST_QUERY_CONVERT:
3101 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3102 query, GST_QUERY_TYPE_NAME (query));
3108 data.dispatched = FALSE;
3109 data.result = FALSE;
3111 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3113 if (data.dispatched) {
3116 /* nothing dispatched, assume drained */
3117 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3127 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3129 GstPad *pad = data->pad;
3130 GstPadProbeInfo *info = data->info;
3131 GstPadProbeType type, flags;
3132 GstPadProbeCallback callback;
3133 GstPadProbeReturn ret;
3135 /* if we have called this callback, do nothing */
3136 if (PROBE_COOKIE (hook) == data->cookie) {
3137 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3138 "hook %lu, cookie %u already called", hook->hook_id,
3139 PROBE_COOKIE (hook));
3143 PROBE_COOKIE (hook) = data->cookie;
3145 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3148 /* one of the data types for non-idle probes */
3149 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3150 && (flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3152 /* one of the scheduling types */
3153 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3155 /* one of the blocking types must match */
3156 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3157 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3159 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3160 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3162 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3163 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3164 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3167 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3168 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3169 PROBE_COOKIE (hook), flags);
3171 data->marshalled = TRUE;
3173 callback = (GstPadProbeCallback) hook->func;
3174 if (callback == NULL)
3177 info->id = hook->hook_id;
3179 GST_OBJECT_UNLOCK (pad);
3181 ret = callback (pad, info, hook->data);
3183 GST_OBJECT_LOCK (pad);
3186 case GST_PAD_PROBE_REMOVE:
3187 /* remove the probe */
3188 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3189 cleanup_hook (pad, hook);
3191 case GST_PAD_PROBE_DROP:
3192 /* need to drop the data, make sure other probes don't get called
3194 GST_DEBUG_OBJECT (pad, "asked to drop item");
3195 info->type = GST_PAD_PROBE_TYPE_INVALID;
3196 data->dropped = TRUE;
3198 case GST_PAD_PROBE_PASS:
3199 /* inform the pad block to let things pass */
3200 GST_DEBUG_OBJECT (pad, "asked to pass item");
3203 case GST_PAD_PROBE_OK:
3204 GST_DEBUG_OBJECT (pad, "probe returned OK");
3207 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3214 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3215 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3216 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3221 /* a probe that does not take or return any data */
3222 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3224 if (G_UNLIKELY (pad->num_probes)) { \
3225 GstFlowReturn pval = defaultval; \
3226 /* pass NULL as the data item */ \
3227 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3228 ret = do_probe_callbacks (pad, &info, defaultval); \
3229 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3234 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3236 if (G_UNLIKELY (pad->num_probes)) { \
3237 /* pass the data item */ \
3238 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3239 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3240 /* store the possibly updated data item */ \
3241 data = GST_PAD_PROBE_INFO_DATA (&info); \
3242 /* if something went wrong, exit */ \
3243 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3248 #define PROBE_PUSH(pad,mask,data,label) \
3249 PROBE_FULL(pad, mask, data, -1, -1, label);
3250 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3251 PROBE_FULL(pad, mask, data, offs, size, label);
3253 static GstFlowReturn
3254 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3255 GstFlowReturn defaultval)
3264 data.marshalled = FALSE;
3265 data.dropped = FALSE;
3266 data.cookie = ++pad->priv->probe_cookie;
3269 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3272 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3273 "do probes cookie %u", data.cookie);
3274 cookie = pad->priv->probe_list_cookie;
3276 g_hook_list_marshal (&pad->probes, TRUE,
3277 (GHookMarshaller) probe_hook_marshal, &data);
3279 /* if the list changed, call the new callbacks (they will not have their
3280 * cookie set to data.cookie */
3281 if (cookie != pad->priv->probe_list_cookie) {
3282 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3283 "probe list changed, restarting");
3287 /* the first item that dropped will stop the hooks and then we drop here */
3291 /* if no handler matched and we are blocking, let the item pass */
3292 if (!data.marshalled && is_block)
3295 /* At this point, all handlers returned either OK or PASS. If one handler
3296 * returned PASS, let the item pass */
3301 while (GST_PAD_IS_BLOCKED (pad)) {
3302 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3303 "we are blocked %d times", pad->num_blocked);
3305 /* we might have released the lock */
3306 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3309 /* now we block the streaming thread. It can be unlocked when we
3310 * deactivate the pad (which will also set the FLUSHING flag) or
3311 * when the pad is unblocked. A flushing event will also unblock
3312 * the pad after setting the FLUSHING flag. */
3313 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3314 "Waiting to be unblocked or set flushing");
3315 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3316 GST_PAD_BLOCK_WAIT (pad);
3317 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3318 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3320 /* if the list changed, call the new callbacks (they will not have their
3321 * cookie set to data.cookie */
3322 if (cookie != pad->priv->probe_list_cookie) {
3323 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3324 "probe list changed, restarting");
3328 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3338 GST_DEBUG_OBJECT (pad, "pad is flushing");
3339 return GST_FLOW_FLUSHING;
3343 GST_DEBUG_OBJECT (pad, "data is dropped");
3344 return GST_FLOW_CUSTOM_SUCCESS;
3348 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3349 GST_DEBUG_OBJECT (pad, "data is passed");
3357 * gst_pad_get_offset:
3360 * Get the offset applied to the running time of @pad. @pad has to be a source
3363 * Returns: the offset.
3366 gst_pad_get_offset (GstPad * pad)
3370 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3372 GST_OBJECT_LOCK (pad);
3373 result = pad->offset;
3374 GST_OBJECT_UNLOCK (pad);
3380 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3382 ev->received = FALSE;
3387 * gst_pad_set_offset:
3389 * @offset: the offset
3391 * Set the offset that will be applied to the running time of @pad.
3394 gst_pad_set_offset (GstPad * pad, gint64 offset)
3396 g_return_if_fail (GST_IS_PAD (pad));
3398 GST_OBJECT_LOCK (pad);
3399 /* if nothing changed, do nothing */
3400 if (pad->offset == offset)
3403 pad->offset = offset;
3404 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3406 /* resend all sticky events with updated offset on next buffer push */
3407 events_foreach (pad, mark_event_not_received, NULL);
3408 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3411 GST_OBJECT_UNLOCK (pad);
3418 /* If TRUE and ret is not OK this means
3419 * that pushing the EOS event failed
3423 /* If called for an event this is
3424 * the event that would be pushed
3425 * next. Don't forward sticky events
3426 * that would come after that */
3430 /* should be called with pad LOCK */
3432 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3434 PushStickyData *data = user_data;
3435 GstEvent *event = ev->event;
3438 GST_DEBUG_OBJECT (pad, "event %s was already received",
3439 GST_EVENT_TYPE_NAME (event));
3443 /* If we're called because of an sticky event, only forward
3444 * events that would come before this new event and the
3446 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3447 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3448 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3449 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3451 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3452 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3455 switch (data->ret) {
3457 ev->received = TRUE;
3458 GST_DEBUG_OBJECT (pad, "event %s marked received",
3459 GST_EVENT_TYPE_NAME (event));
3461 case GST_FLOW_CUSTOM_SUCCESS:
3462 /* we can't assume the event is received when it was dropped */
3463 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3464 GST_EVENT_TYPE_NAME (event));
3465 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3466 data->ret = GST_FLOW_OK;
3468 case GST_FLOW_CUSTOM_SUCCESS_1:
3469 /* event was ignored and should be sent later */
3470 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3471 GST_EVENT_TYPE_NAME (event));
3472 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3473 data->ret = GST_FLOW_OK;
3475 case GST_FLOW_NOT_LINKED:
3476 /* not linked is not a problem, we are sticky so the event will be
3477 * sent later but only for non-EOS events */
3478 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3479 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3480 data->ret = GST_FLOW_OK;
3481 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3484 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3485 gst_flow_get_name (data->ret));
3486 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3490 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3491 data->was_eos = TRUE;
3493 return data->ret == GST_FLOW_OK;
3496 /* check sticky events and push them when needed. should be called
3498 static inline GstFlowReturn
3499 check_sticky (GstPad * pad, GstEvent * event)
3501 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3503 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3504 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3506 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3507 events_foreach (pad, push_sticky, &data);
3509 /* If there's an EOS event we must push it downstream
3510 * even if sending a previous sticky event failed.
3511 * Otherwise the pipeline might wait forever for EOS.
3513 * Only do this if pushing another event than the EOS
3516 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3517 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3519 if (ev && !ev->received) {
3520 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3521 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3522 /* the event could have been dropped. Because this can only
3523 * happen if the user asked for it, it's not an error */
3524 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3525 data.ret = GST_FLOW_OK;
3535 * @pad: a #GstPad to invoke the default query on.
3536 * @query: (transfer none): the #GstQuery to perform.
3538 * Dispatches a query to a pad. The query should have been allocated by the
3539 * caller via one of the type-specific allocation functions. The element that
3540 * the pad belongs to is responsible for filling the query with an appropriate
3541 * response, which should then be parsed with a type-specific query parsing
3544 * Again, the caller is responsible for both the allocation and deallocation of
3545 * the query structure.
3547 * Please also note that some queries might need a running pipeline to work.
3549 * Returns: %TRUE if the query could be performed.
3552 gst_pad_query (GstPad * pad, GstQuery * query)
3555 gboolean res, serialized;
3556 GstPadQueryFunction func;
3557 GstPadProbeType type;
3560 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3561 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3563 if (GST_PAD_IS_SRC (pad)) {
3564 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3565 goto wrong_direction;
3566 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3567 } else if (GST_PAD_IS_SINK (pad)) {
3568 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3569 goto wrong_direction;
3570 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3572 goto unknown_direction;
3574 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3575 GST_QUERY_TYPE_NAME (query));
3577 serialized = GST_QUERY_IS_SERIALIZED (query);
3578 if (G_UNLIKELY (serialized))
3579 GST_PAD_STREAM_LOCK (pad);
3581 GST_OBJECT_LOCK (pad);
3582 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3583 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3584 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3586 ACQUIRE_PARENT (pad, parent, no_parent);
3587 GST_OBJECT_UNLOCK (pad);
3589 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3592 res = func (pad, parent, query);
3594 RELEASE_PARENT (parent);
3596 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3597 GST_QUERY_TYPE_NAME (query), res);
3602 GST_OBJECT_LOCK (pad);
3603 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3604 GST_OBJECT_UNLOCK (pad);
3606 if (G_UNLIKELY (serialized))
3607 GST_PAD_STREAM_UNLOCK (pad);
3614 g_warning ("pad %s:%s query %s in wrong direction",
3615 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3620 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3625 GST_DEBUG_OBJECT (pad, "had no parent");
3626 GST_OBJECT_UNLOCK (pad);
3627 if (G_UNLIKELY (serialized))
3628 GST_PAD_STREAM_UNLOCK (pad);
3633 GST_DEBUG_OBJECT (pad, "had no query function");
3634 RELEASE_PARENT (parent);
3635 if (G_UNLIKELY (serialized))
3636 GST_PAD_STREAM_UNLOCK (pad);
3641 GST_DEBUG_OBJECT (pad, "query failed");
3642 if (G_UNLIKELY (serialized))
3643 GST_PAD_STREAM_UNLOCK (pad);
3648 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3649 GST_OBJECT_UNLOCK (pad);
3650 if (G_UNLIKELY (serialized))
3651 GST_PAD_STREAM_UNLOCK (pad);
3653 /* if a probe dropped, we don't sent it further but assume that the probe
3654 * did not answer the query and return FALSE */
3662 * gst_pad_peer_query:
3663 * @pad: a #GstPad to invoke the peer query on.
3664 * @query: (transfer none): the #GstQuery to perform.
3666 * Performs gst_pad_query() on the peer of @pad.
3668 * The caller is responsible for both the allocation and deallocation of
3669 * the query structure.
3671 * Returns: %TRUE if the query could be performed. This function returns %FALSE
3672 * if @pad has no peer.
3675 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3678 GstPadProbeType type;
3679 gboolean res, serialized;
3682 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3683 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3685 if (GST_PAD_IS_SRC (pad)) {
3686 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3687 goto wrong_direction;
3688 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3689 } else if (GST_PAD_IS_SINK (pad)) {
3690 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3691 goto wrong_direction;
3692 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3694 goto unknown_direction;
3696 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3697 GST_QUERY_TYPE_NAME (query));
3699 serialized = GST_QUERY_IS_SERIALIZED (query);
3701 GST_OBJECT_LOCK (pad);
3702 if (GST_PAD_IS_SRC (pad) && serialized) {
3703 /* all serialized queries on the srcpad trigger push of
3705 if (check_sticky (pad, NULL) != GST_FLOW_OK)
3709 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3710 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3711 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3713 peerpad = GST_PAD_PEER (pad);
3714 if (G_UNLIKELY (peerpad == NULL))
3717 gst_object_ref (peerpad);
3718 GST_OBJECT_UNLOCK (pad);
3720 res = gst_pad_query (peerpad, query);
3722 gst_object_unref (peerpad);
3727 GST_OBJECT_LOCK (pad);
3728 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3729 GST_OBJECT_UNLOCK (pad);
3736 g_warning ("pad %s:%s query %s in wrong direction",
3737 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3742 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3747 GST_WARNING_OBJECT (pad, "could not send sticky events");
3748 GST_OBJECT_UNLOCK (pad);
3753 GST_INFO_OBJECT (pad, "pad has no peer");
3754 GST_OBJECT_UNLOCK (pad);
3759 GST_DEBUG_OBJECT (pad, "query failed");
3764 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3765 GST_OBJECT_UNLOCK (pad);
3767 /* if a probe dropped, we don't sent it further but assume that the probe
3768 * did not answer the query and return FALSE */
3775 /**********************************************************************
3776 * Data passing functions
3779 /* this is the chain function that does not perform the additional argument
3780 * checking for that little extra speed.
3782 static inline GstFlowReturn
3783 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3788 GST_PAD_STREAM_LOCK (pad);
3790 GST_OBJECT_LOCK (pad);
3791 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3794 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3797 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3800 #ifndef G_DISABLE_ASSERT
3801 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3802 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3804 ":%s:<%s:%s> Got data flow before stream-start event",
3805 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3807 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3809 ":%s:<%s:%s> Got data flow before segment event",
3810 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3812 pad->priv->last_cookie = pad->priv->events_cookie;
3816 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3818 PROBE_PUSH (pad, type, data, probe_stopped);
3820 parent = GST_OBJECT_PARENT (pad);
3821 GST_OBJECT_UNLOCK (pad);
3823 /* NOTE: we read the chainfunc unlocked.
3824 * we cannot hold the lock for the pad so we might send
3825 * the data to the wrong function. This is not really a
3826 * problem since functions are assigned at creation time
3827 * and don't change that often... */
3828 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3829 GstPadChainFunction chainfunc;
3831 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3834 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3835 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3836 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3838 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3840 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3841 "called chainfunction &%s with buffer %p, returned %s",
3842 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3844 GstPadChainListFunction chainlistfunc;
3846 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3849 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3850 "calling chainlistfunction &%s",
3851 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3853 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3855 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3856 "called chainlistfunction &%s, returned %s",
3857 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3860 GST_PAD_STREAM_UNLOCK (pad);
3867 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3868 "chaining, but pad was flushing");
3869 GST_OBJECT_UNLOCK (pad);
3870 GST_PAD_STREAM_UNLOCK (pad);
3871 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3872 return GST_FLOW_FLUSHING;
3876 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3877 GST_OBJECT_UNLOCK (pad);
3878 GST_PAD_STREAM_UNLOCK (pad);
3879 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3880 return GST_FLOW_EOS;
3884 g_critical ("chain on pad %s:%s but it was not in push mode",
3885 GST_DEBUG_PAD_NAME (pad));
3886 GST_OBJECT_UNLOCK (pad);
3887 GST_PAD_STREAM_UNLOCK (pad);
3888 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3889 return GST_FLOW_ERROR;
3893 GST_OBJECT_UNLOCK (pad);
3894 GST_PAD_STREAM_UNLOCK (pad);
3895 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3898 case GST_FLOW_CUSTOM_SUCCESS:
3899 GST_DEBUG_OBJECT (pad, "dropped buffer");
3903 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
3910 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3911 g_critical ("chain on pad %s:%s but it has no chainfunction",
3912 GST_DEBUG_PAD_NAME (pad));
3913 GST_PAD_STREAM_UNLOCK (pad);
3914 return GST_FLOW_NOT_SUPPORTED;
3920 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3921 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3924 * Chain a buffer to @pad.
3926 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3928 * If the buffer type is not acceptable for @pad (as negotiated with a
3929 * preceding GST_EVENT_CAPS event), this function returns
3930 * #GST_FLOW_NOT_NEGOTIATED.
3932 * The function proceeds calling the chain function installed on @pad (see
3933 * gst_pad_set_chain_function()) and the return value of that function is
3934 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3937 * In all cases, success or failure, the caller loses its reference to @buffer
3938 * after calling this function.
3940 * Returns: a #GstFlowReturn from the pad.
3945 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3947 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3948 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3949 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3951 return gst_pad_chain_data_unchecked (pad,
3952 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3955 static GstFlowReturn
3956 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3957 GstBufferList * list)
3963 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3965 len = gst_buffer_list_length (list);
3968 for (i = 0; i < len; i++) {
3969 buffer = gst_buffer_list_get (list, i);
3971 gst_pad_chain_data_unchecked (pad,
3972 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3973 gst_buffer_ref (buffer));
3974 if (ret != GST_FLOW_OK)
3977 gst_buffer_list_unref (list);
3983 * gst_pad_chain_list:
3984 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3985 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3988 * Chain a bufferlist to @pad.
3990 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3992 * If @pad was not negotiated properly with a CAPS event, this function
3993 * returns #GST_FLOW_NOT_NEGOTIATED.
3995 * The function proceeds calling the chainlist function installed on @pad (see
3996 * gst_pad_set_chain_list_function()) and the return value of that function is
3997 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3998 * chainlist function.
4000 * In all cases, success or failure, the caller loses its reference to @list
4001 * after calling this function.
4005 * Returns: a #GstFlowReturn from the pad.
4008 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4010 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4011 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4012 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4014 return gst_pad_chain_data_unchecked (pad,
4015 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4018 static GstFlowReturn
4019 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4024 GST_OBJECT_LOCK (pad);
4025 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4028 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4031 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4034 #ifndef G_DISABLE_ASSERT
4035 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4036 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4038 ":%s:<%s:%s> Got data flow before stream-start event",
4039 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4041 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4043 ":%s:<%s:%s> Got data flow before segment event",
4044 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4046 pad->priv->last_cookie = pad->priv->events_cookie;
4050 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4053 /* do block probes */
4054 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
4056 /* recheck sticky events because the probe might have cause a relink */
4057 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4060 /* do post-blocking probes */
4061 PROBE_PUSH (pad, type, data, probe_stopped);
4063 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4066 /* take ref to peer pad before releasing the lock */
4067 gst_object_ref (peer);
4069 GST_OBJECT_UNLOCK (pad);
4071 ret = gst_pad_chain_data_unchecked (peer, type, data);
4073 gst_object_unref (peer);
4075 GST_OBJECT_LOCK (pad);
4076 pad->ABI.abi.last_flowret = ret;
4078 if (pad->priv->using == 0) {
4079 /* pad is not active anymore, trigger idle callbacks */
4080 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4081 probe_stopped, ret);
4083 GST_OBJECT_UNLOCK (pad);
4087 /* ERROR recovery here */
4091 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4092 "pushing, but pad was flushing");
4093 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4094 GST_OBJECT_UNLOCK (pad);
4095 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4096 return GST_FLOW_FLUSHING;
4100 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4101 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4102 GST_OBJECT_UNLOCK (pad);
4103 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4104 return GST_FLOW_EOS;
4108 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4109 GST_DEBUG_PAD_NAME (pad));
4110 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4111 GST_OBJECT_UNLOCK (pad);
4112 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4113 return GST_FLOW_ERROR;
4117 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4118 "error pushing events, return %s", gst_flow_get_name (ret));
4119 pad->ABI.abi.last_flowret = ret;
4120 GST_OBJECT_UNLOCK (pad);
4121 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4126 GST_OBJECT_UNLOCK (pad);
4127 pad->ABI.abi.last_flowret =
4128 ret == GST_FLOW_CUSTOM_SUCCESS ? GST_FLOW_OK : ret;
4129 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4132 case GST_FLOW_CUSTOM_SUCCESS:
4133 GST_DEBUG_OBJECT (pad, "dropped buffer");
4137 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4144 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4145 "pushing, but it was not linked");
4146 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4147 GST_OBJECT_UNLOCK (pad);
4148 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4149 return GST_FLOW_NOT_LINKED;
4155 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4156 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4159 * Pushes a buffer to the peer of @pad.
4161 * This function will call installed block probes before triggering any
4162 * installed data probes.
4164 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4165 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4168 * In all cases, success or failure, the caller loses its reference to @buffer
4169 * after calling this function.
4171 * Returns: a #GstFlowReturn from the peer pad.
4176 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4178 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4179 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4180 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4182 return gst_pad_push_data (pad,
4183 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4187 * gst_pad_push_list:
4188 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4189 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4192 * Pushes a buffer list to the peer of @pad.
4194 * This function will call installed block probes before triggering any
4195 * installed data probes.
4197 * The function proceeds calling the chain function on the peer pad and returns
4198 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4199 * be returned. If the peer pad does not have any installed chainlist function
4200 * every group buffer of the list will be merged into a normal #GstBuffer and
4201 * chained via gst_pad_chain().
4203 * In all cases, success or failure, the caller loses its reference to @list
4204 * after calling this function.
4206 * Returns: a #GstFlowReturn from the peer pad.
4211 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4213 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4214 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4215 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4217 return gst_pad_push_data (pad,
4218 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4221 static GstFlowReturn
4222 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4223 GstBuffer ** buffer)
4226 GstPadGetRangeFunction getrangefunc;
4230 GST_PAD_STREAM_LOCK (pad);
4232 GST_OBJECT_LOCK (pad);
4233 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4236 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4239 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4244 /* when one of the probes returns DROPPED, probe_stopped will be called
4245 * and we skip calling the getrange function, res_buf should then contain a
4246 * valid result buffer */
4247 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4248 res_buf, offset, size, probe_stopped);
4250 /* recheck sticky events because the probe might have cause a relink */
4251 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4254 ACQUIRE_PARENT (pad, parent, no_parent);
4255 GST_OBJECT_UNLOCK (pad);
4257 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4260 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4261 "calling getrangefunc %s, offset %"
4262 G_GUINT64_FORMAT ", size %u",
4263 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4265 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4267 RELEASE_PARENT (parent);
4269 GST_OBJECT_LOCK (pad);
4270 if (G_UNLIKELY (ret != GST_FLOW_OK))
4271 goto get_range_failed;
4273 /* can only fire the signal if we have a valid buffer */
4275 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4276 res_buf, offset, size, probe_stopped_unref);
4277 pad->ABI.abi.last_flowret = ret;
4278 GST_OBJECT_UNLOCK (pad);
4280 GST_PAD_STREAM_UNLOCK (pad);
4289 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4290 "getrange, but pad was flushing");
4291 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4292 GST_OBJECT_UNLOCK (pad);
4293 GST_PAD_STREAM_UNLOCK (pad);
4294 return GST_FLOW_FLUSHING;
4298 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4299 GST_DEBUG_PAD_NAME (pad));
4300 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4301 GST_OBJECT_UNLOCK (pad);
4302 GST_PAD_STREAM_UNLOCK (pad);
4303 return GST_FLOW_ERROR;
4307 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4308 pad->ABI.abi.last_flowret = ret;
4309 GST_OBJECT_UNLOCK (pad);
4310 GST_PAD_STREAM_UNLOCK (pad);
4315 GST_DEBUG_OBJECT (pad, "no parent");
4316 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4317 GST_OBJECT_UNLOCK (pad);
4318 GST_PAD_STREAM_UNLOCK (pad);
4319 return GST_FLOW_FLUSHING;
4323 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4324 GST_DEBUG_PAD_NAME (pad));
4325 RELEASE_PARENT (parent);
4326 GST_PAD_STREAM_UNLOCK (pad);
4327 return GST_FLOW_NOT_SUPPORTED;
4331 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4332 "probe returned %s", gst_flow_get_name (ret));
4333 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4335 /* the probe filled the buffer and asks us to not call the getrange
4336 * anymore, we continue with the post probes then. */
4337 GST_DEBUG_OBJECT (pad, "handled buffer");
4341 /* no buffer, we are EOS */
4342 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4346 pad->ABI.abi.last_flowret = ret;
4347 GST_OBJECT_UNLOCK (pad);
4348 GST_PAD_STREAM_UNLOCK (pad);
4352 probe_stopped_unref:
4354 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4355 "probe returned %s", gst_flow_get_name (ret));
4356 /* if we drop here, it signals EOS */
4357 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4359 pad->ABI.abi.last_flowret = ret;
4360 GST_OBJECT_UNLOCK (pad);
4361 GST_PAD_STREAM_UNLOCK (pad);
4362 if (*buffer == NULL)
4363 gst_buffer_unref (res_buf);
4368 pad->ABI.abi.last_flowret = ret;
4369 GST_OBJECT_UNLOCK (pad);
4370 GST_PAD_STREAM_UNLOCK (pad);
4371 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4372 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4373 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4379 * gst_pad_get_range:
4380 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4381 * @offset: The start offset of the buffer
4382 * @size: The length of the buffer
4383 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4384 * returns #GST_FLOW_ERROR if %NULL.
4386 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4387 * immediately and @buffer is %NULL.
4389 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4390 * description of a getrange function. If @pad has no getrange function
4391 * installed (see gst_pad_set_getrange_function()) this function returns
4392 * #GST_FLOW_NOT_SUPPORTED.
4394 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4395 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4396 * must be freed with gst_buffer_unref() after usage.
4398 * When @buffer points to a variable that points to a valid #GstBuffer, the
4399 * buffer will be filled with the result data when this function returns
4400 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4401 * @size bytes will be filled in the result buffer and its size will be updated
4404 * Note that less than @size bytes can be returned in @buffer when, for example,
4405 * an EOS condition is near or when @buffer is not large enough to hold @size
4406 * bytes. The caller should check the result buffer size to get the result size.
4408 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4409 * will be unchanged.
4411 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4413 * Returns: a #GstFlowReturn from the pad.
4418 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4419 GstBuffer ** buffer)
4421 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4422 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4423 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4424 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4425 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4427 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4431 * gst_pad_pull_range:
4432 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4433 * @offset: The start offset of the buffer
4434 * @size: The length of the buffer
4435 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4436 * GST_FLOW_ERROR if %NULL.
4438 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4440 * This function will first trigger the pad block signal if it was
4443 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4444 * function returns the result of gst_pad_get_range() on the peer pad.
4445 * See gst_pad_get_range() for a list of return values and for the
4446 * semantics of the arguments of this function.
4448 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4449 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4450 * must be freed with gst_buffer_unref() after usage. When this function
4451 * returns any other result value, @buffer will still point to %NULL.
4453 * When @buffer points to a variable that points to a valid #GstBuffer, the
4454 * buffer will be filled with the result data when this function returns
4455 * #GST_FLOW_OK. When this function returns any other result value,
4456 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4457 * @size bytes will be filled in the result buffer and its size will be updated
4460 * Note that less than @size bytes can be returned in @buffer when, for example,
4461 * an EOS condition is near or when @buffer is not large enough to hold @size
4462 * bytes. The caller should check the result buffer size to get the result size.
4464 * Returns: a #GstFlowReturn from the peer pad.
4469 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4470 GstBuffer ** buffer)
4476 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4477 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4478 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4479 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4480 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4482 GST_OBJECT_LOCK (pad);
4483 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4486 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4491 /* when one of the probes returns DROPPED, probe_stopped will be
4492 * called and we skip calling the peer getrange function. *buffer should then
4493 * contain a valid buffer */
4494 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4495 res_buf, offset, size, probe_stopped);
4497 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4500 gst_object_ref (peer);
4502 GST_OBJECT_UNLOCK (pad);
4504 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4506 gst_object_unref (peer);
4508 GST_OBJECT_LOCK (pad);
4510 pad->ABI.abi.last_flowret = ret;
4511 if (pad->priv->using == 0) {
4512 /* pad is not active anymore, trigger idle callbacks */
4513 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4514 probe_stopped_unref, ret);
4517 if (G_UNLIKELY (ret != GST_FLOW_OK))
4518 goto pull_range_failed;
4521 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4522 res_buf, offset, size, probe_stopped_unref);
4524 GST_OBJECT_UNLOCK (pad);
4530 /* ERROR recovery here */
4533 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4534 "pullrange, but pad was flushing");
4535 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4536 GST_OBJECT_UNLOCK (pad);
4537 return GST_FLOW_FLUSHING;
4541 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4542 GST_DEBUG_PAD_NAME (pad));
4543 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4544 GST_OBJECT_UNLOCK (pad);
4545 return GST_FLOW_ERROR;
4549 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4550 gst_flow_get_name (ret));
4551 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4553 /* the probe filled the buffer and asks us to not forward to the peer
4554 * anymore, we continue with the post probes then */
4555 GST_DEBUG_OBJECT (pad, "handled buffer");
4559 /* no buffer, we are EOS then */
4560 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4564 pad->ABI.abi.last_flowret = ret;
4565 GST_OBJECT_UNLOCK (pad);
4570 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4571 "pulling range, but it was not linked");
4572 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4573 GST_OBJECT_UNLOCK (pad);
4574 return GST_FLOW_NOT_LINKED;
4578 pad->ABI.abi.last_flowret = ret;
4579 GST_OBJECT_UNLOCK (pad);
4580 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4581 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4582 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4585 probe_stopped_unref:
4587 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4588 "post probe returned %s", gst_flow_get_name (ret));
4590 /* if we drop here, it signals EOS */
4591 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4594 pad->ABI.abi.last_flowret = ret;
4595 GST_OBJECT_UNLOCK (pad);
4597 if (*buffer == NULL)
4598 gst_buffer_unref (res_buf);
4603 /* must be called with pad object lock */
4604 static GstFlowReturn
4605 store_sticky_event (GstPad * pad, GstEvent * event)
4610 gboolean res = FALSE;
4611 const gchar *name = NULL;
4612 gboolean insert = TRUE;
4614 type = GST_EVENT_TYPE (event);
4616 /* Store all sticky events except SEGMENT/EOS when we're flushing,
4617 * otherwise they can be dropped and nothing would ever resend them.
4618 * Only do that for activated pads though, everything else is a bug!
4620 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4621 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4622 || type == GST_EVENT_EOS))))
4625 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4628 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4629 name = gst_structure_get_name (gst_event_get_structure (event));
4631 events = pad->priv->events;
4634 for (i = 0; i < len; i++) {
4635 PadEvent *ev = &g_array_index (events, PadEvent, i);
4637 if (ev->event == NULL)
4640 if (type == GST_EVENT_TYPE (ev->event)) {
4641 /* matching types, check matching name if needed */
4642 if (name && !gst_event_has_name (ev->event, name))
4646 if ((res = gst_event_replace (&ev->event, event)))
4647 ev->received = FALSE;
4653 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4654 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4655 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4656 * storing the sticky ordered we can check that this is respected. */
4657 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4658 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4660 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4661 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4662 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4663 gst_event_type_get_name (type));
4669 ev.event = gst_event_ref (event);
4670 ev.received = FALSE;
4671 g_array_insert_val (events, i, ev);
4676 pad->priv->events_cookie++;
4677 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4679 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4681 switch (GST_EVENT_TYPE (event)) {
4682 case GST_EVENT_CAPS:
4683 GST_OBJECT_UNLOCK (pad);
4685 GST_DEBUG_OBJECT (pad, "notify caps");
4686 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4688 GST_OBJECT_LOCK (pad);
4694 if (type == GST_EVENT_EOS) {
4695 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4696 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4699 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4704 GST_DEBUG_OBJECT (pad, "pad is flushing");
4705 return GST_FLOW_FLUSHING;
4709 GST_DEBUG_OBJECT (pad, "pad is EOS");
4710 return GST_FLOW_EOS;
4715 * gst_pad_store_sticky_event:
4717 * @event: a #GstEvent
4719 * Store the sticky @event on @pad
4721 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4722 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4727 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4731 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4732 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4734 GST_OBJECT_LOCK (pad);
4735 ret = store_sticky_event (pad, event);
4736 GST_OBJECT_UNLOCK (pad);
4742 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
4744 PushStickyData *data = user_data;
4746 /* Forward all sticky events before our current one that are pending */
4747 if (ev->event != data->event
4748 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
4749 return push_sticky (pad, ev, data);
4754 /* should be called with pad LOCK */
4755 static GstFlowReturn
4756 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4757 GstPadProbeType type)
4761 GstEventType event_type;
4763 /* pass the adjusted event on. We need to do this even if
4764 * there is no peer pad because of the probes. */
4765 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
4767 /* Two checks to be made:
4768 * . (un)set the FLUSHING flag for flushing events,
4769 * . handle pad blocking */
4770 event_type = GST_EVENT_TYPE (event);
4771 switch (event_type) {
4772 case GST_EVENT_FLUSH_START:
4773 GST_PAD_SET_FLUSHING (pad);
4775 GST_PAD_BLOCK_BROADCAST (pad);
4776 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4778 case GST_EVENT_FLUSH_STOP:
4779 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
4782 GST_PAD_UNSET_FLUSHING (pad);
4784 /* Remove sticky EOS events */
4785 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4786 remove_event_by_type (pad, GST_EVENT_EOS);
4787 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4788 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4789 pad->ABI.abi.last_flowret = GST_FLOW_OK;
4791 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4795 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4798 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4799 * checked already or this is called as part of pushing sticky events,
4800 * in which case we still want to forward the EOS event downstream.
4803 switch (GST_EVENT_TYPE (event)) {
4804 case GST_EVENT_RECONFIGURE:
4805 if (GST_PAD_IS_SINK (pad))
4806 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4811 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4812 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4817 /* send probes after modifying the events above */
4818 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4820 /* recheck sticky events because the probe might have cause a relink */
4821 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
4822 && (GST_EVENT_IS_SERIALIZED (event)
4823 || GST_EVENT_IS_STICKY (event))) {
4824 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4825 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4827 /* Push all sticky events before our current one
4828 * that have changed */
4829 events_foreach (pad, sticky_changed, &data);
4832 /* now check the peer pad */
4833 peerpad = GST_PAD_PEER (pad);
4834 if (peerpad == NULL)
4837 gst_object_ref (peerpad);
4839 GST_OBJECT_UNLOCK (pad);
4841 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4842 event, gst_event_type_get_name (event_type), peerpad);
4844 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4846 /* Note: we gave away ownership of the event at this point but we can still
4847 * print the old pointer */
4848 GST_LOG_OBJECT (pad,
4849 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
4850 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
4852 gst_object_unref (peerpad);
4854 GST_OBJECT_LOCK (pad);
4856 if (pad->priv->using == 0) {
4857 /* pad is not active anymore, trigger idle callbacks */
4858 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4859 idle_probe_stopped, ret);
4863 /* ERROR handling */
4866 GST_DEBUG_OBJECT (pad, "We're flushing");
4867 gst_event_unref (event);
4868 return GST_FLOW_FLUSHING;
4872 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
4873 gst_event_unref (event);
4874 return GST_FLOW_FLUSHING;
4878 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4879 gst_event_unref (event);
4882 case GST_FLOW_CUSTOM_SUCCESS:
4883 GST_DEBUG_OBJECT (pad, "dropped event");
4886 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4893 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
4894 gst_event_type_get_name (GST_EVENT_TYPE (event)));
4895 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4896 gst_event_unref (event);
4898 /* unlinked pads should not influence latency configuration */
4899 if (event_type == GST_EVENT_LATENCY)
4902 return GST_FLOW_NOT_LINKED;
4906 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4912 * gst_pad_push_event:
4913 * @pad: a #GstPad to push the event to.
4914 * @event: (transfer full): the #GstEvent to send to the pad.
4916 * Sends the event to the peer of the given pad. This function is
4917 * mainly used by elements to send events to their peer
4920 * This function takes ownership of the provided event so you should
4921 * gst_event_ref() it if you want to reuse the event after this call.
4923 * Returns: %TRUE if the event was handled.
4928 gst_pad_push_event (GstPad * pad, GstEvent * event)
4930 gboolean res = FALSE;
4931 GstPadProbeType type;
4932 gboolean sticky, serialized;
4934 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4935 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4937 if (GST_PAD_IS_SRC (pad)) {
4938 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4939 goto wrong_direction;
4940 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4941 } else if (GST_PAD_IS_SINK (pad)) {
4942 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4943 goto wrong_direction;
4944 /* events pushed on sinkpad never are sticky */
4945 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4947 goto unknown_direction;
4949 GST_OBJECT_LOCK (pad);
4950 sticky = GST_EVENT_IS_STICKY (event);
4951 serialized = GST_EVENT_IS_SERIALIZED (event);
4954 /* srcpad sticky events are stored immediately, the received flag is set
4955 * to FALSE and will be set to TRUE when we can successfully push the
4956 * event to the peer pad */
4957 switch (store_sticky_event (pad, event)) {
4958 case GST_FLOW_FLUSHING:
4966 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4967 /* all serialized or sticky events on the srcpad trigger push of
4969 res = (check_sticky (pad, event) == GST_FLOW_OK);
4974 /* other events are pushed right away */
4975 ret = gst_pad_push_event_unchecked (pad, event, type);
4976 /* dropped events by a probe are not an error */
4977 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4979 /* Errors in sticky event pushing are no problem and ignored here
4980 * as they will cause more meaningful errors during data flow.
4981 * For EOS events, that are not followed by data flow, we still
4982 * return FALSE here though.
4984 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4986 gst_event_unref (event);
4988 GST_OBJECT_UNLOCK (pad);
4992 /* ERROR handling */
4995 g_warning ("pad %s:%s pushing %s event in wrong direction",
4996 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4997 gst_event_unref (event);
5002 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5003 gst_event_unref (event);
5008 GST_DEBUG_OBJECT (pad, "We're flushing");
5009 GST_OBJECT_UNLOCK (pad);
5010 gst_event_unref (event);
5015 GST_DEBUG_OBJECT (pad, "We're EOS");
5016 GST_OBJECT_UNLOCK (pad);
5017 gst_event_unref (event);
5022 /* Check if we can call the event function with the given event */
5023 static GstFlowReturn
5024 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5028 switch (GST_EVENT_TYPE (event)) {
5029 case GST_EVENT_CAPS:
5031 /* backwards compatibility mode for caps */
5032 gst_event_parse_caps (event, &caps);
5034 if (!gst_pad_query_accept_caps (pad, caps))
5046 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5047 "caps %" GST_PTR_FORMAT " not accepted", caps);
5048 return GST_FLOW_NOT_NEGOTIATED;
5052 static GstFlowReturn
5053 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5054 GstPadProbeType type)
5057 GstEventType event_type;
5058 gboolean serialized, need_unlock = FALSE, sticky;
5059 GstPadEventFunction eventfunc;
5062 GST_OBJECT_LOCK (pad);
5064 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5066 if (GST_PAD_IS_SINK (pad))
5067 serialized = GST_EVENT_IS_SERIALIZED (event);
5070 sticky = GST_EVENT_IS_STICKY (event);
5071 event_type = GST_EVENT_TYPE (event);
5072 switch (event_type) {
5073 case GST_EVENT_FLUSH_START:
5074 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5075 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5077 /* can't even accept a flush begin event when flushing */
5078 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5081 GST_PAD_SET_FLUSHING (pad);
5082 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5084 case GST_EVENT_FLUSH_STOP:
5085 /* we can't accept flush-stop on inactive pads else the flushing flag
5086 * would be cleared and it would look like the pad can accept data.
5087 * Also, some elements restart a streaming thread in flush-stop which we
5088 * can't allow on inactive pads */
5089 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5092 GST_PAD_UNSET_FLUSHING (pad);
5093 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5094 /* Remove pending EOS events */
5095 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5096 remove_event_by_type (pad, GST_EVENT_EOS);
5097 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5098 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5099 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5101 GST_OBJECT_UNLOCK (pad);
5102 /* grab stream lock */
5103 GST_PAD_STREAM_LOCK (pad);
5105 GST_OBJECT_LOCK (pad);
5106 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5109 case GST_EVENT_RECONFIGURE:
5110 if (GST_PAD_IS_SRC (pad))
5111 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5113 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5114 "have event type %" GST_PTR_FORMAT, event);
5116 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5120 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5123 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5124 GST_OBJECT_UNLOCK (pad);
5125 GST_PAD_STREAM_LOCK (pad);
5127 GST_OBJECT_LOCK (pad);
5128 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5131 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5137 /* now do the probe */
5139 type | GST_PAD_PROBE_TYPE_PUSH |
5140 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5142 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5144 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5147 ACQUIRE_PARENT (pad, parent, no_parent);
5148 GST_OBJECT_UNLOCK (pad);
5150 ret = pre_eventfunc_check (pad, event);
5151 if (G_UNLIKELY (ret != GST_FLOW_OK))
5152 goto precheck_failed;
5155 gst_event_ref (event);
5157 if (eventfunc (pad, parent, event)) {
5160 /* something went wrong */
5161 switch (event_type) {
5162 case GST_EVENT_CAPS:
5163 ret = GST_FLOW_NOT_NEGOTIATED;
5166 ret = GST_FLOW_ERROR;
5170 RELEASE_PARENT (parent);
5172 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5175 if (ret == GST_FLOW_OK) {
5176 GST_OBJECT_LOCK (pad);
5177 /* after the event function accepted the event, we can store the sticky
5178 * event on the pad */
5179 switch (store_sticky_event (pad, event)) {
5180 case GST_FLOW_FLUSHING:
5187 GST_OBJECT_UNLOCK (pad);
5189 gst_event_unref (event);
5193 GST_PAD_STREAM_UNLOCK (pad);
5197 /* ERROR handling */
5200 GST_OBJECT_UNLOCK (pad);
5202 GST_PAD_STREAM_UNLOCK (pad);
5203 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5204 "Received event on flushing pad. Discarding");
5205 gst_event_unref (event);
5206 return GST_FLOW_FLUSHING;
5210 GST_OBJECT_UNLOCK (pad);
5212 GST_PAD_STREAM_UNLOCK (pad);
5213 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5214 "Received flush-stop on inactive pad. Discarding");
5215 gst_event_unref (event);
5216 return GST_FLOW_FLUSHING;
5220 GST_OBJECT_UNLOCK (pad);
5222 GST_PAD_STREAM_UNLOCK (pad);
5223 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5224 "Received event on EOS pad. Discarding");
5225 gst_event_unref (event);
5226 return GST_FLOW_EOS;
5230 GST_OBJECT_UNLOCK (pad);
5232 GST_PAD_STREAM_UNLOCK (pad);
5233 gst_event_unref (event);
5236 case GST_FLOW_CUSTOM_SUCCESS:
5237 GST_DEBUG_OBJECT (pad, "dropped event");
5241 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5248 g_warning ("pad %s:%s has no event handler, file a bug.",
5249 GST_DEBUG_PAD_NAME (pad));
5250 GST_OBJECT_UNLOCK (pad);
5252 GST_PAD_STREAM_UNLOCK (pad);
5253 gst_event_unref (event);
5254 return GST_FLOW_NOT_SUPPORTED;
5258 GST_DEBUG_OBJECT (pad, "no parent");
5259 GST_OBJECT_UNLOCK (pad);
5261 GST_PAD_STREAM_UNLOCK (pad);
5262 gst_event_unref (event);
5263 return GST_FLOW_FLUSHING;
5267 GST_DEBUG_OBJECT (pad, "pre event check failed");
5268 RELEASE_PARENT (parent);
5270 GST_PAD_STREAM_UNLOCK (pad);
5271 gst_event_unref (event);
5277 * gst_pad_send_event:
5278 * @pad: a #GstPad to send the event to.
5279 * @event: (transfer full): the #GstEvent to send to the pad.
5281 * Sends the event to the pad. This function can be used
5282 * by applications to send events in the pipeline.
5284 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5285 * sink pad, @event should be a downstream event. For example, you would not
5286 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5287 * Furthermore, some downstream events have to be serialized with data flow,
5288 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5289 * the event needs to be serialized with data flow, this function will take the
5290 * pad's stream lock while calling its event function.
5292 * To find out whether an event type is upstream, downstream, or downstream and
5293 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5294 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5295 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5296 * plugin doesn't need to bother itself with this information; the core handles
5297 * all necessary locks and checks.
5299 * This function takes ownership of the provided event so you should
5300 * gst_event_ref() it if you want to reuse the event after this call.
5302 * Returns: %TRUE if the event was handled.
5305 gst_pad_send_event (GstPad * pad, GstEvent * event)
5308 GstPadProbeType type;
5310 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5311 g_return_val_if_fail (event != NULL, FALSE);
5313 if (GST_PAD_IS_SINK (pad)) {
5314 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5315 goto wrong_direction;
5316 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5317 } else if (GST_PAD_IS_SRC (pad)) {
5318 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5319 goto wrong_direction;
5320 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5322 goto unknown_direction;
5324 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5331 /* ERROR handling */
5334 g_warning ("pad %s:%s sending %s event in wrong direction",
5335 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5336 gst_event_unref (event);
5341 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5342 gst_event_unref (event);
5348 * gst_pad_set_element_private:
5349 * @pad: the #GstPad to set the private data of.
5350 * @priv: The private data to attach to the pad.
5352 * Set the given private data gpointer on the pad.
5353 * This function can only be used by the element that owns the pad.
5354 * No locking is performed in this function.
5357 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5359 pad->element_private = priv;
5363 * gst_pad_get_element_private:
5364 * @pad: the #GstPad to get the private data of.
5366 * Gets the private data of a pad.
5367 * No locking is performed in this function.
5369 * Returns: (transfer none): a #gpointer to the private data.
5372 gst_pad_get_element_private (GstPad * pad)
5374 return pad->element_private;
5378 * gst_pad_get_sticky_event:
5379 * @pad: the #GstPad to get the event from.
5380 * @event_type: the #GstEventType that should be retrieved.
5381 * @idx: the index of the event
5383 * Returns a new reference of the sticky event of type @event_type
5386 * Returns: (transfer full) (nullable): a #GstEvent of type
5387 * @event_type or %NULL when no event of @event_type was on
5388 * @pad. Unref after usage.
5391 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5393 GstEvent *event = NULL;
5396 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5397 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5399 GST_OBJECT_LOCK (pad);
5400 ev = find_event_by_type (pad, event_type, idx);
5401 if (ev && (event = ev->event))
5402 gst_event_ref (event);
5403 GST_OBJECT_UNLOCK (pad);
5410 GstPadStickyEventsForeachFunction func;
5415 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5417 ForeachDispatch *data = user_data;
5418 gboolean ret = TRUE;
5421 GST_OBJECT_UNLOCK (pad);
5423 ret = data->func (pad, &ev->event, data->user_data);
5425 GST_OBJECT_LOCK (pad);
5432 * gst_pad_sticky_events_foreach:
5433 * @pad: the #GstPad that should be used for iteration.
5434 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5435 * should be called for every event.
5436 * @user_data: (closure): the optional user data.
5438 * Iterates all sticky events on @pad and calls @foreach_func for every
5439 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5442 gst_pad_sticky_events_foreach (GstPad * pad,
5443 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5445 ForeachDispatch data;
5447 g_return_if_fail (GST_IS_PAD (pad));
5448 g_return_if_fail (foreach_func != NULL);
5450 data.func = foreach_func;
5451 data.user_data = user_data;
5453 GST_OBJECT_LOCK (pad);
5454 events_foreach (pad, foreach_dispatch_function, &data);
5455 GST_OBJECT_UNLOCK (pad);
5459 do_stream_status (GstPad * pad, GstStreamStatusType type,
5460 GThread * thread, GstTask * task)
5464 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5466 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5467 if (GST_IS_ELEMENT (parent)) {
5468 GstMessage *message;
5469 GValue value = { 0 };
5471 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5472 gchar *tname, *ename, *pname;
5474 /* create a good task name */
5475 ename = gst_element_get_name (parent);
5476 pname = gst_pad_get_name (pad);
5477 tname = g_strdup_printf ("%s:%s", ename, pname);
5481 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5485 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5488 g_value_init (&value, GST_TYPE_TASK);
5489 g_value_set_object (&value, task);
5490 gst_message_set_stream_status_object (message, &value);
5491 g_value_unset (&value);
5493 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5494 gst_element_post_message (parent, message);
5496 gst_object_unref (parent);
5501 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5503 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5508 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5510 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5515 * gst_pad_start_task:
5516 * @pad: the #GstPad to start the task of
5517 * @func: the task function to call
5518 * @user_data: user data passed to the task function
5519 * @notify: called when @user_data is no longer referenced
5521 * Starts a task that repeatedly calls @func with @user_data. This function
5522 * is mostly used in pad activation functions to start the dataflow.
5523 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5524 * before @func is called.
5526 * Returns: a %TRUE if the task could be started.
5529 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5530 GDestroyNotify notify)
5535 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5536 g_return_val_if_fail (func != NULL, FALSE);
5538 GST_DEBUG_OBJECT (pad, "start task");
5540 GST_OBJECT_LOCK (pad);
5541 task = GST_PAD_TASK (pad);
5543 task = gst_task_new (func, user_data, notify);
5544 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5545 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5546 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5547 GST_INFO_OBJECT (pad, "created task %p", task);
5548 GST_PAD_TASK (pad) = task;
5549 gst_object_ref (task);
5550 /* release lock to post the message */
5551 GST_OBJECT_UNLOCK (pad);
5553 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5555 gst_object_unref (task);
5557 GST_OBJECT_LOCK (pad);
5558 /* nobody else is supposed to have changed the pad now */
5559 if (GST_PAD_TASK (pad) != task)
5560 goto concurrent_stop;
5562 res = gst_task_set_state (task, GST_TASK_STARTED);
5563 GST_OBJECT_UNLOCK (pad);
5570 GST_OBJECT_UNLOCK (pad);
5576 * gst_pad_pause_task:
5577 * @pad: the #GstPad to pause the task of
5579 * Pause the task of @pad. This function will also wait until the
5580 * function executed by the task is finished if this function is not
5581 * called from the task function.
5583 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
5587 gst_pad_pause_task (GstPad * pad)
5592 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5594 GST_DEBUG_OBJECT (pad, "pause task");
5596 GST_OBJECT_LOCK (pad);
5597 task = GST_PAD_TASK (pad);
5600 res = gst_task_set_state (task, GST_TASK_PAUSED);
5601 GST_OBJECT_UNLOCK (pad);
5603 /* wait for task function to finish, this lock is recursive so it does nothing
5604 * when the pause is called from the task itself */
5605 GST_PAD_STREAM_LOCK (pad);
5606 GST_PAD_STREAM_UNLOCK (pad);
5612 GST_DEBUG_OBJECT (pad, "pad has no task");
5613 GST_OBJECT_UNLOCK (pad);
5619 * gst_pad_stop_task:
5620 * @pad: the #GstPad to stop the task of
5622 * Stop the task of @pad. This function will also make sure that the
5623 * function executed by the task will effectively stop if not called
5624 * from the GstTaskFunction.
5626 * This function will deadlock if called from the GstTaskFunction of
5627 * the task. Use gst_task_pause() instead.
5629 * Regardless of whether the pad has a task, the stream lock is acquired and
5630 * released so as to ensure that streaming through this pad has finished.
5632 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
5635 gst_pad_stop_task (GstPad * pad)
5640 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5642 GST_DEBUG_OBJECT (pad, "stop task");
5644 GST_OBJECT_LOCK (pad);
5645 task = GST_PAD_TASK (pad);
5648 GST_PAD_TASK (pad) = NULL;
5649 res = gst_task_set_state (task, GST_TASK_STOPPED);
5650 GST_OBJECT_UNLOCK (pad);
5652 GST_PAD_STREAM_LOCK (pad);
5653 GST_PAD_STREAM_UNLOCK (pad);
5655 if (!gst_task_join (task))
5658 gst_object_unref (task);
5664 GST_DEBUG_OBJECT (pad, "no task");
5665 GST_OBJECT_UNLOCK (pad);
5667 GST_PAD_STREAM_LOCK (pad);
5668 GST_PAD_STREAM_UNLOCK (pad);
5670 /* this is not an error */
5675 /* this is bad, possibly the application tried to join the task from
5676 * the task's thread. We install the task again so that it will be stopped
5677 * again from the right thread next time hopefully. */
5678 GST_OBJECT_LOCK (pad);
5679 GST_DEBUG_OBJECT (pad, "join failed");
5680 /* we can only install this task if there was no other task */
5681 if (GST_PAD_TASK (pad) == NULL)
5682 GST_PAD_TASK (pad) = task;
5683 GST_OBJECT_UNLOCK (pad);
5690 * gst_pad_probe_info_get_event:
5691 * @info: a #GstPadProbeInfo
5693 * Returns: (transfer none): The #GstEvent from the probe
5697 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5699 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5700 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5702 return GST_PAD_PROBE_INFO_EVENT (info);
5707 * gst_pad_probe_info_get_query:
5708 * @info: a #GstPadProbeInfo
5710 * Returns: (transfer none): The #GstQuery from the probe
5714 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5716 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5717 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5719 return GST_PAD_PROBE_INFO_QUERY (info);
5723 * gst_pad_probe_info_get_buffer:
5724 * @info: a #GstPadProbeInfo
5726 * Returns: (transfer none): The #GstBuffer from the probe
5730 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5732 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5734 return GST_PAD_PROBE_INFO_BUFFER (info);
5738 * gst_pad_probe_info_get_bufferlist:
5739 * @info: a #GstPadProbeInfo
5741 * Returns: (transfer none): The #GstBufferlist from the probe
5745 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5747 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5749 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
5753 * gst_pad_get_last_flow_return:
5756 * Gets the #GstFlowReturn return from the last data passed by this pad.
5761 gst_pad_get_last_flow_return (GstPad * pad)
5765 GST_OBJECT_LOCK (pad);
5766 ret = GST_PAD_LAST_FLOW_RETURN (pad);
5767 GST_OBJECT_UNLOCK (pad);