2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 * @short_description: Object contained by elements that allows links to
26 * @see_also: #GstPadTemplate, #GstElement, #GstEvent, #GstQuery, #GstBuffer
28 * A #GstElement is linked to other elements via "pads", which are extremely
29 * light-weight generic link points.
31 * Pads have a #GstPadDirection, source pads produce data, sink pads consume
34 * Pads are typically created from a #GstPadTemplate with
35 * gst_pad_new_from_template() and are then added to a #GstElement. This usually
36 * happens when the element is created but it can also happen dynamically based
37 * on the data that the element is processing or based on the pads that the
38 * application requests.
40 * Pads without pad templates can be created with gst_pad_new(),
41 * which takes a direction and a name as an argument. If the name is NULL,
42 * then a guaranteed unique name will be assigned to it.
44 * A #GstElement creating a pad will typically use the various
45 * gst_pad_set_*_function() calls to register callbacks for events, queries or
46 * dataflow on the pads.
48 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
50 * After two pads are retrieved from an element by gst_element_get_static_pad(),
51 * the pads can be linked with gst_pad_link(). (For quick links,
52 * you can also use gst_element_link(), which will make the obvious
53 * link for you if it's straightforward.). Pads can be unlinked again with
54 * gst_pad_unlink(). gst_pad_get_peer() can be used to check what the pad is
57 * Before dataflow is possible on the pads, they need to be activated with
58 * gst_pad_set_active().
60 * gst_pad_query() and gst_pad_peer_query() can be used to query various
61 * properties of the pad and the stream.
63 * To send a #GstEvent on a pad, use gst_pad_send_event() and
64 * gst_pad_push_event(). Some events will be sticky on the pad, meaning that
65 * after they pass on the pad they can be queried later with
66 * gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().
67 * gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience
68 * functions to query the current sticky CAPS event on a pad.
70 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
71 * or pull in a buffer.
73 * The dataflow, events and queries that happen on a pad can be monitored with
74 * probes that can be installed with gst_pad_add_probe(). gst_pad_is_blocked()
75 * can be used to check if a block probe is installed on the pad.
76 * gst_pad_is_blocking() checks if the blocking probe is currently blocking the
77 * pad. gst_pad_remove_probe() is used to remove a previously installed probe
78 * and unblock blocking probes if any.
80 * Pad have an offset that can be retrieved with gst_pad_get_offset(). This
81 * offset will be applied to the running_time of all data passing over the pad.
82 * gst_pad_set_offset() can be used to change the offset.
84 * Convenience functions exist to start, pause and stop the task on a pad with
85 * gst_pad_start_task(), gst_pad_pause_task() and gst_pad_stop_task()
88 * Last reviewed on 2012-03-29 (0.11.3)
91 #include "gst_private.h"
94 #include "gstpadtemplate.h"
95 #include "gstenumtypes.h"
100 #include "glib-compat-private.h"
102 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
103 #define GST_CAT_DEFAULT GST_CAT_PADS
105 /* Pad signals and args */
123 #define GST_PAD_GET_PRIVATE(obj) \
124 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
126 /* we have a pending and an active event on the pad. On source pads only the
127 * active event is used. On sinkpads, events are copied to the pending entry and
128 * moved to the active event when the eventfunc returned TRUE. */
135 struct _GstPadPrivate
142 guint probe_list_cookie;
152 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
157 GstPadProbeInfo *info;
164 static void gst_pad_dispose (GObject * object);
165 static void gst_pad_finalize (GObject * object);
166 static void gst_pad_set_property (GObject * object, guint prop_id,
167 const GValue * value, GParamSpec * pspec);
168 static void gst_pad_get_property (GObject * object, guint prop_id,
169 GValue * value, GParamSpec * pspec);
171 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
172 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
173 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
174 GstObject * parent, GstBufferList * list);
176 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
177 GstEvent * event, GstPadProbeType type);
178 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
179 GstEvent * event, GstPadProbeType type);
181 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
183 static GParamSpec *pspec_caps = NULL;
185 /* quarks for probe signals */
186 static GQuark buffer_quark;
187 static GQuark buffer_list_quark;
188 static GQuark event_quark;
197 static GstFlowQuarks flow_quarks[] = {
198 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
199 {GST_FLOW_OK, "ok", 0},
200 {GST_FLOW_NOT_LINKED, "not-linked", 0},
201 {GST_FLOW_FLUSHING, "flushing", 0},
202 {GST_FLOW_EOS, "eos", 0},
203 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
204 {GST_FLOW_ERROR, "error", 0},
205 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
206 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
211 * @ret: a #GstFlowReturn to get the name of.
213 * Gets a string representing the given flow return.
215 * Returns: a static string with the name of the flow return.
218 gst_flow_get_name (GstFlowReturn ret)
222 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
224 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
225 if (ret == flow_quarks[i].ret)
226 return flow_quarks[i].name;
233 * @ret: a #GstFlowReturn to get the quark of.
235 * Get the unique quark for the given GstFlowReturn.
237 * Returns: the quark associated with the flow return or 0 if an
238 * invalid return was specified.
241 gst_flow_to_quark (GstFlowReturn ret)
245 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
247 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
248 if (ret == flow_quarks[i].ret)
249 return flow_quarks[i].quark;
255 * gst_pad_link_get_name:
256 * @ret: a #GstPadLinkReturn to get the name of.
258 * Gets a string representing the given pad-link return.
260 * Returns: a static string with the name of the pad-link return.
265 gst_pad_link_get_name (GstPadLinkReturn ret)
268 case GST_PAD_LINK_OK:
270 case GST_PAD_LINK_WRONG_HIERARCHY:
271 return "wrong hierarchy";
272 case GST_PAD_LINK_WAS_LINKED:
274 case GST_PAD_LINK_WRONG_DIRECTION:
275 return "wrong direction";
276 case GST_PAD_LINK_NOFORMAT:
277 return "no common format";
278 case GST_PAD_LINK_NOSCHED:
279 return "incompatible scheduling";
280 case GST_PAD_LINK_REFUSED:
283 g_return_val_if_reached ("unknown");
290 buffer_quark = g_quark_from_static_string ("buffer"); \
291 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
292 event_quark = g_quark_from_static_string ("event"); \
294 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
295 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
298 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
299 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
302 #define gst_pad_parent_class parent_class
303 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
306 gst_pad_class_init (GstPadClass * klass)
308 GObjectClass *gobject_class;
309 GstObjectClass *gstobject_class;
311 gobject_class = G_OBJECT_CLASS (klass);
312 gstobject_class = GST_OBJECT_CLASS (klass);
314 g_type_class_add_private (klass, sizeof (GstPadPrivate));
316 gobject_class->dispose = gst_pad_dispose;
317 gobject_class->finalize = gst_pad_finalize;
318 gobject_class->set_property = gst_pad_set_property;
319 gobject_class->get_property = gst_pad_get_property;
323 * @pad: the pad that emitted the signal
324 * @peer: the peer pad that has been connected
326 * Signals that a pad has been linked to the peer pad.
328 gst_pad_signals[PAD_LINKED] =
329 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
330 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
331 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
334 * @pad: the pad that emitted the signal
335 * @peer: the peer pad that has been disconnected
337 * Signals that a pad has been unlinked from the peer pad.
339 gst_pad_signals[PAD_UNLINKED] =
340 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
341 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
342 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
344 pspec_caps = g_param_spec_boxed ("caps", "Caps",
345 "The capabilities of the pad", GST_TYPE_CAPS,
346 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
347 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
349 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
350 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
351 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
352 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
354 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
355 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
356 g_param_spec_object ("template", "Template",
357 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
358 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
360 gstobject_class->path_string_separator = ".";
362 /* Register common function pointer descriptions */
363 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
364 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
365 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
366 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
367 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
371 gst_pad_init (GstPad * pad)
373 pad->priv = GST_PAD_GET_PRIVATE (pad);
375 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
377 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
378 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
379 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
380 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
381 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
383 GST_PAD_SET_FLUSHING (pad);
385 g_rec_mutex_init (&pad->stream_rec_lock);
387 g_cond_init (&pad->block_cond);
389 g_hook_list_init (&pad->probes, sizeof (GstProbe));
391 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
392 pad->priv->events_cookie = 0;
393 pad->priv->last_cookie = -1;
396 /* called when setting the pad inactive. It removes all sticky events from
397 * the pad. must be called with object lock */
399 remove_events (GstPad * pad)
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) {
414 GST_OBJECT_UNLOCK (pad);
416 GST_DEBUG_OBJECT (pad, "notify caps");
417 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
419 GST_OBJECT_LOCK (pad);
421 gst_event_unref (event);
423 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
424 g_array_set_size (events, 0);
425 pad->priv->events_cookie++;
428 /* should be called with object lock */
430 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
436 events = pad->priv->events;
439 for (i = 0; i < len; i++) {
440 ev = &g_array_index (events, PadEvent, i);
441 if (ev->event == NULL)
444 if (GST_EVENT_TYPE (ev->event) == type) {
455 /* should be called with OBJECT lock */
457 find_event (GstPad * pad, GstEvent * event)
463 events = pad->priv->events;
466 for (i = 0; i < len; i++) {
467 ev = &g_array_index (events, PadEvent, i);
468 if (event == ev->event)
476 /* should be called with OBJECT lock */
478 remove_event_by_type (GstPad * pad, GstEventType type)
484 events = pad->priv->events;
489 ev = &g_array_index (events, PadEvent, i);
490 if (ev->event == NULL)
493 if (GST_EVENT_TYPE (ev->event) != type)
496 gst_event_unref (ev->event);
497 g_array_remove_index (events, i);
499 pad->priv->events_cookie++;
507 /* check all events on srcpad against those on sinkpad. All events that are not
508 * on sinkpad are marked as received=FALSE and the PENDING_EVENTS is set on the
509 * srcpad so that the events will be sent next time */
510 /* should be called with srcpad and sinkpad LOCKS */
512 schedule_events (GstPad * srcpad, GstPad * sinkpad)
517 gboolean pending = FALSE;
519 events = srcpad->priv->events;
522 for (i = 0; i < len; i++) {
523 ev = &g_array_index (events, PadEvent, i);
524 if (ev->event == NULL)
527 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
528 ev->received = FALSE;
533 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
536 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
539 /* should be called with pad LOCK */
541 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
548 events = pad->priv->events;
551 cookie = pad->priv->events_cookie;
555 PadEvent *ev, ev_ret;
557 ev = &g_array_index (events, PadEvent, i);
558 if (G_UNLIKELY (ev->event == NULL))
561 /* take aditional ref, func might release the lock */
562 ev_ret.event = gst_event_ref (ev->event);
563 ev_ret.received = ev->received;
565 ret = func (pad, &ev_ret, user_data);
567 /* recheck the cookie, lock might have been released and the list could have
569 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
570 if (G_LIKELY (ev_ret.event))
571 gst_event_unref (ev_ret.event);
575 /* store the received state */
576 ev->received = ev_ret.received;
578 /* if the event changed, we need to do something */
579 if (G_UNLIKELY (ev->event != ev_ret.event)) {
580 if (G_UNLIKELY (ev_ret.event == NULL)) {
581 /* function unreffed and set the event to NULL, remove it */
582 gst_event_unref (ev->event);
583 g_array_remove_index (events, i);
585 cookie = ++pad->priv->events_cookie;
588 /* function gave a new event for us */
589 gst_event_take (&ev->event, ev_ret.event);
592 /* just unref, nothing changed */
593 gst_event_unref (ev_ret.event);
602 /* should be called with LOCK */
604 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
606 /* check if we need to adjust the segment */
607 if (pad->offset != 0) {
610 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_TIME_FORMAT,
611 GST_TIME_ARGS (pad->offset));
613 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
616 g_assert (!upstream);
618 /* copy segment values */
619 gst_event_copy_segment (event, &segment);
620 gst_event_unref (event);
622 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
623 event = gst_event_new_segment (&segment);
626 event = gst_event_make_writable (event);
627 offset = gst_event_get_running_time_offset (event);
629 offset -= pad->offset;
631 offset += pad->offset;
632 gst_event_set_running_time_offset (event, offset);
637 /* should be called with the OBJECT_LOCK */
639 get_pad_caps (GstPad * pad)
641 GstCaps *caps = NULL;
644 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
646 gst_event_parse_caps (ev->event, &caps);
652 gst_pad_dispose (GObject * object)
654 GstPad *pad = GST_PAD_CAST (object);
657 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
659 /* unlink the peer pad */
660 if ((peer = gst_pad_get_peer (pad))) {
661 /* window for MT unsafeness, someone else could unlink here
662 * and then we call unlink with wrong pads. The unlink
663 * function would catch this and safely return failed. */
664 if (GST_PAD_IS_SRC (pad))
665 gst_pad_unlink (pad, peer);
667 gst_pad_unlink (peer, pad);
669 gst_object_unref (peer);
672 gst_pad_set_pad_template (pad, NULL);
674 GST_OBJECT_LOCK (pad);
676 GST_OBJECT_UNLOCK (pad);
678 g_hook_list_clear (&pad->probes);
680 G_OBJECT_CLASS (parent_class)->dispose (object);
684 gst_pad_finalize (GObject * object)
686 GstPad *pad = GST_PAD_CAST (object);
689 /* in case the task is still around, clean it up */
690 if ((task = GST_PAD_TASK (pad))) {
691 gst_task_join (task);
692 GST_PAD_TASK (pad) = NULL;
693 gst_object_unref (task);
696 if (pad->activatenotify)
697 pad->activatenotify (pad->activatedata);
698 if (pad->activatemodenotify)
699 pad->activatemodenotify (pad->activatemodedata);
701 pad->linknotify (pad->linkdata);
702 if (pad->unlinknotify)
703 pad->unlinknotify (pad->unlinkdata);
704 if (pad->chainnotify)
705 pad->chainnotify (pad->chaindata);
706 if (pad->chainlistnotify)
707 pad->chainlistnotify (pad->chainlistdata);
708 if (pad->getrangenotify)
709 pad->getrangenotify (pad->getrangedata);
710 if (pad->eventnotify)
711 pad->eventnotify (pad->eventdata);
712 if (pad->querynotify)
713 pad->querynotify (pad->querydata);
714 if (pad->iterintlinknotify)
715 pad->iterintlinknotify (pad->iterintlinkdata);
717 g_rec_mutex_clear (&pad->stream_rec_lock);
718 g_cond_clear (&pad->block_cond);
719 g_array_free (pad->priv->events, TRUE);
721 G_OBJECT_CLASS (parent_class)->finalize (object);
725 gst_pad_set_property (GObject * object, guint prop_id,
726 const GValue * value, GParamSpec * pspec)
728 g_return_if_fail (GST_IS_PAD (object));
731 case PAD_PROP_DIRECTION:
732 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
734 case PAD_PROP_TEMPLATE:
735 gst_pad_set_pad_template (GST_PAD_CAST (object),
736 (GstPadTemplate *) g_value_get_object (value));
739 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
745 gst_pad_get_property (GObject * object, guint prop_id,
746 GValue * value, GParamSpec * pspec)
748 g_return_if_fail (GST_IS_PAD (object));
752 GST_OBJECT_LOCK (object);
753 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
754 GST_OBJECT_UNLOCK (object);
756 case PAD_PROP_DIRECTION:
757 g_value_set_enum (value, GST_PAD_DIRECTION (object));
759 case PAD_PROP_TEMPLATE:
760 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
763 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
770 * @name: the name of the new pad.
771 * @direction: the #GstPadDirection of the pad.
773 * Creates a new pad with the given name in the given direction.
774 * If name is NULL, a guaranteed unique name (across all pads)
776 * This function makes a copy of the name so you can safely free the name.
778 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
783 gst_pad_new (const gchar * name, GstPadDirection direction)
785 return g_object_new (GST_TYPE_PAD,
786 "name", name, "direction", direction, NULL);
790 * gst_pad_new_from_template:
791 * @templ: the pad template to use
792 * @name: the name of the element
794 * Creates a new pad with the given name from the given template.
795 * If name is NULL, a guaranteed unique name (across all pads)
797 * This function makes a copy of the name so you can safely free the name.
799 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
802 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
804 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
806 return g_object_new (GST_TYPE_PAD,
807 "name", name, "direction", templ->direction, "template", templ, NULL);
811 * gst_pad_new_from_static_template:
812 * @templ: the #GstStaticPadTemplate to use
813 * @name: the name of the element
815 * Creates a new pad with the given name from the given static template.
816 * If name is NULL, a guaranteed unique name (across all pads)
818 * This function makes a copy of the name so you can safely free the name.
820 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
823 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
827 GstPadTemplate *template;
829 template = gst_static_pad_template_get (templ);
830 pad = gst_pad_new_from_template (template, name);
831 gst_object_unref (template);
835 #define ACQUIRE_PARENT(pad, parent, label) \
837 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
838 gst_object_ref (parent); \
839 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
843 #define RELEASE_PARENT(parent) \
845 if (G_LIKELY (parent)) \
846 gst_object_unref (parent); \
850 * gst_pad_get_direction:
851 * @pad: a #GstPad to get the direction of.
853 * Gets the direction of the pad. The direction of the pad is
854 * decided at construction time so this function does not take
857 * Returns: the #GstPadDirection of the pad.
862 gst_pad_get_direction (GstPad * pad)
864 GstPadDirection result;
866 /* PAD_UNKNOWN is a little silly but we need some sort of
867 * error return value */
868 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
870 result = GST_PAD_DIRECTION (pad);
876 gst_pad_activate_default (GstPad * pad, GstObject * parent)
878 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
882 * gst_pad_mode_get_name:
883 * @mode: the pad mode
885 * Return the name of a pad mode, for use in debug messages mostly.
887 * Returns: short mnemonic for pad mode @mode
890 gst_pad_mode_get_name (GstPadMode mode)
893 case GST_PAD_MODE_NONE:
895 case GST_PAD_MODE_PUSH:
897 case GST_PAD_MODE_PULL:
906 pre_activate (GstPad * pad, GstPadMode new_mode)
909 case GST_PAD_MODE_NONE:
910 GST_OBJECT_LOCK (pad);
911 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
912 GST_PAD_SET_FLUSHING (pad);
913 GST_PAD_MODE (pad) = new_mode;
914 /* unlock blocked pads so element can resume and stop */
915 GST_PAD_BLOCK_BROADCAST (pad);
916 GST_OBJECT_UNLOCK (pad);
918 case GST_PAD_MODE_PUSH:
919 case GST_PAD_MODE_PULL:
920 GST_OBJECT_LOCK (pad);
921 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
922 gst_pad_mode_get_name (new_mode));
923 GST_PAD_UNSET_FLUSHING (pad);
924 GST_PAD_MODE (pad) = new_mode;
925 if (GST_PAD_IS_SINK (pad)) {
927 /* make sure the peer src pad sends us all events */
928 if ((peer = GST_PAD_PEER (pad))) {
929 gst_object_ref (peer);
930 GST_OBJECT_UNLOCK (pad);
932 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
933 GST_DEBUG_PAD_NAME (peer));
935 GST_OBJECT_LOCK (peer);
936 schedule_events (peer, NULL);
937 GST_OBJECT_UNLOCK (peer);
939 gst_object_unref (peer);
941 GST_OBJECT_UNLOCK (pad);
944 GST_OBJECT_UNLOCK (pad);
951 post_activate (GstPad * pad, GstPadMode new_mode)
954 case GST_PAD_MODE_NONE:
955 /* ensures that streaming stops */
956 GST_PAD_STREAM_LOCK (pad);
957 GST_DEBUG_OBJECT (pad, "stopped streaming");
958 GST_OBJECT_LOCK (pad);
960 GST_OBJECT_UNLOCK (pad);
961 GST_PAD_STREAM_UNLOCK (pad);
963 case GST_PAD_MODE_PUSH:
964 case GST_PAD_MODE_PULL:
971 * gst_pad_set_active:
972 * @pad: the #GstPad to activate or deactivate.
973 * @active: whether or not the pad should be active.
975 * Activates or deactivates the given pad.
976 * Normally called from within core state change functions.
978 * If @active, makes sure the pad is active. If it is already active, either in
979 * push or pull mode, just return. Otherwise dispatches to the pad's activate
980 * function to perform the actual activation.
982 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
983 * and a FALSE argument.
985 * Returns: #TRUE if the operation was successful.
990 gst_pad_set_active (GstPad * pad, gboolean active)
994 gboolean ret = FALSE;
996 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
998 GST_OBJECT_LOCK (pad);
999 old = GST_PAD_MODE (pad);
1000 ACQUIRE_PARENT (pad, parent, no_parent);
1001 GST_OBJECT_UNLOCK (pad);
1004 if (old == GST_PAD_MODE_NONE) {
1005 GST_DEBUG_OBJECT (pad, "activating pad from none");
1006 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1008 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1009 gst_pad_mode_get_name (old));
1013 if (old == GST_PAD_MODE_NONE) {
1014 GST_DEBUG_OBJECT (pad, "pad was inactive");
1017 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1018 gst_pad_mode_get_name (old));
1019 ret = gst_pad_activate_mode (pad, old, FALSE);
1023 RELEASE_PARENT (parent);
1025 if (G_UNLIKELY (!ret))
1033 GST_DEBUG_OBJECT (pad, "no parent");
1034 GST_OBJECT_UNLOCK (pad);
1039 GST_OBJECT_LOCK (pad);
1041 g_critical ("Failed to deactivate pad %s:%s, very bad",
1042 GST_DEBUG_PAD_NAME (pad));
1044 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1046 GST_OBJECT_UNLOCK (pad);
1052 * gst_pad_activate_mode:
1053 * @pad: the #GstPad to activate or deactivate.
1054 * @mode: the requested activation mode
1055 * @active: whether or not the pad should be active.
1057 * Activates or deactivates the given pad in @mode via dispatching to the
1058 * pad's activatemodefunc. For use from within pad activation functions only.
1060 * If you don't know what this is, you probably don't want to call it.
1062 * Returns: TRUE if the operation was successful.
1067 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1069 gboolean res = FALSE;
1071 GstPadMode old, new;
1072 GstPadDirection dir;
1075 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1077 GST_OBJECT_LOCK (pad);
1078 old = GST_PAD_MODE (pad);
1079 dir = GST_PAD_DIRECTION (pad);
1080 ACQUIRE_PARENT (pad, parent, no_parent);
1081 GST_OBJECT_UNLOCK (pad);
1083 new = active ? mode : GST_PAD_MODE_NONE;
1088 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1089 /* pad was activate in the wrong direction, deactivate it
1090 * and reactivate it in the requested mode */
1091 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1092 gst_pad_mode_get_name (old));
1094 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1095 goto deactivate_failed;
1099 case GST_PAD_MODE_PULL:
1101 if (dir == GST_PAD_SINK) {
1102 if ((peer = gst_pad_get_peer (pad))) {
1103 GST_DEBUG_OBJECT (pad, "calling peer");
1104 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1106 gst_object_unref (peer);
1108 /* there is no peer, this is only fatal when we activate. When we
1109 * deactivate, we must assume the application has unlinked the peer and
1110 * will deactivate it eventually. */
1114 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1117 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1118 goto failure; /* Can't activate pull on a src without a
1119 getrange function */
1127 /* Mark pad as needing reconfiguration */
1129 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1130 pre_activate (pad, new);
1132 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1133 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1137 /* can happen for sinks of passthrough elements */
1140 post_activate (pad, new);
1142 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1143 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1148 /* Clear sticky flags on deactivation */
1150 GST_OBJECT_LOCK (pad);
1151 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1152 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1153 GST_OBJECT_UNLOCK (pad);
1157 RELEASE_PARENT (parent);
1163 GST_DEBUG_OBJECT (pad, "no parent");
1164 GST_OBJECT_UNLOCK (pad);
1169 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1170 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1175 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1176 "failed to %s in switch to %s mode from %s mode",
1177 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1178 gst_pad_mode_get_name (old));
1183 GST_OBJECT_LOCK (peer);
1184 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1185 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1186 GST_OBJECT_UNLOCK (peer);
1187 gst_object_unref (peer);
1192 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1193 "pad in pull mode");
1198 GST_OBJECT_LOCK (pad);
1199 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1200 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1201 GST_PAD_SET_FLUSHING (pad);
1202 GST_PAD_MODE (pad) = old;
1203 GST_OBJECT_UNLOCK (pad);
1209 * gst_pad_is_active:
1210 * @pad: the #GstPad to query
1212 * Query if a pad is active
1214 * Returns: TRUE if the pad is active.
1219 gst_pad_is_active (GstPad * pad)
1221 gboolean result = FALSE;
1223 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1225 GST_OBJECT_LOCK (pad);
1226 result = GST_PAD_IS_ACTIVE (pad);
1227 GST_OBJECT_UNLOCK (pad);
1233 cleanup_hook (GstPad * pad, GHook * hook)
1235 GstPadProbeType type;
1237 if (!G_HOOK_IS_VALID (hook))
1240 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1242 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1243 /* unblock when we remove the last blocking probe */
1245 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1248 /* Might have new probes now that want to be called */
1249 GST_PAD_BLOCK_BROADCAST (pad);
1251 if (pad->num_blocked == 0) {
1252 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1253 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1256 g_hook_destroy_link (&pad->probes, hook);
1261 * gst_pad_add_probe:
1262 * @pad: the #GstPad to add the probe to
1263 * @mask: the probe mask
1264 * @callback: #GstPadProbeCallback that will be called with notifications of
1266 * @user_data: (closure): user data passed to the callback
1267 * @destroy_data: #GDestroyNotify for user_data
1269 * Be notified of different states of pads. The provided callback is called for
1270 * every state that matches @mask.
1272 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1273 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1274 * happend that the probe can be run immediately and if the probe returns
1275 * GST_PAD_PROBE_REMOVE this functions returns 0.
1280 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1281 GstPadProbeCallback callback, gpointer user_data,
1282 GDestroyNotify destroy_data)
1287 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1288 g_return_val_if_fail (mask != 0, 0);
1290 GST_OBJECT_LOCK (pad);
1292 /* make a new probe */
1293 hook = g_hook_alloc (&pad->probes);
1295 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1298 /* when no contraints are given for the types, assume all types are
1300 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1301 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1302 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1303 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1305 /* store our flags and other fields */
1306 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1307 hook->func = callback;
1308 hook->data = user_data;
1309 hook->destroy = destroy_data;
1310 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1313 g_hook_prepend (&pad->probes, hook);
1315 /* incremenent cookie so that the new hook get's called */
1316 pad->priv->probe_list_cookie++;
1318 /* get the id of the hook, we return this and it can be used to remove the
1320 res = hook->hook_id;
1322 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1324 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1325 /* we have a block probe */
1327 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1328 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1329 "now %d blocking probes", pad->num_blocked);
1331 /* Might have new probes now that want to be called */
1332 GST_PAD_BLOCK_BROADCAST (pad);
1335 /* call the callback if we need to be called for idle callbacks */
1336 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1337 if (pad->priv->using > 0) {
1338 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1339 * flag above, the last thread to leave the push will do the callback. New
1340 * threads going into the push will block. */
1341 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1342 "pad is in use, delay idle callback");
1343 GST_OBJECT_UNLOCK (pad);
1345 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1346 GstPadProbeReturn ret;
1348 /* Keep another ref, the callback could destroy the pad */
1349 gst_object_ref (pad);
1351 /* the pad is idle now, we can signal the idle callback now */
1352 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1353 "pad is idle, trigger idle callback");
1354 GST_OBJECT_UNLOCK (pad);
1356 ret = callback (pad, &info, user_data);
1358 GST_OBJECT_LOCK (pad);
1360 case GST_PAD_PROBE_REMOVE:
1361 /* remove the probe */
1362 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1363 cleanup_hook (pad, hook);
1366 case GST_PAD_PROBE_DROP:
1367 GST_DEBUG_OBJECT (pad, "asked to drop item");
1369 case GST_PAD_PROBE_PASS:
1370 GST_DEBUG_OBJECT (pad, "asked to pass item");
1372 case GST_PAD_PROBE_OK:
1373 GST_DEBUG_OBJECT (pad, "probe returned OK");
1376 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1379 GST_OBJECT_UNLOCK (pad);
1381 gst_object_unref (pad);
1384 GST_OBJECT_UNLOCK (pad);
1390 * gst_pad_remove_probe:
1391 * @pad: the #GstPad with the probe
1392 * @id: the probe id to remove
1394 * Remove the probe with @id from @pad.
1399 gst_pad_remove_probe (GstPad * pad, gulong id)
1403 g_return_if_fail (GST_IS_PAD (pad));
1405 GST_OBJECT_LOCK (pad);
1407 hook = g_hook_get (&pad->probes, id);
1411 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1413 cleanup_hook (pad, hook);
1414 GST_OBJECT_UNLOCK (pad);
1420 GST_OBJECT_UNLOCK (pad);
1421 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1427 * gst_pad_is_blocked:
1428 * @pad: the #GstPad to query
1430 * Checks if the pad is blocked or not. This function returns the
1431 * last requested state of the pad. It is not certain that the pad
1432 * is actually blocking at this point (see gst_pad_is_blocking()).
1434 * Returns: TRUE if the pad is blocked.
1439 gst_pad_is_blocked (GstPad * pad)
1441 gboolean result = FALSE;
1443 g_return_val_if_fail (GST_IS_PAD (pad), result);
1445 GST_OBJECT_LOCK (pad);
1446 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1447 GST_OBJECT_UNLOCK (pad);
1453 * gst_pad_is_blocking:
1454 * @pad: the #GstPad to query
1456 * Checks if the pad is blocking or not. This is a guaranteed state
1457 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1459 * Returns: TRUE if the pad is blocking.
1464 gst_pad_is_blocking (GstPad * pad)
1466 gboolean result = FALSE;
1468 g_return_val_if_fail (GST_IS_PAD (pad), result);
1470 GST_OBJECT_LOCK (pad);
1471 /* the blocking flag is only valid if the pad is not flushing */
1472 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1473 GST_OBJECT_UNLOCK (pad);
1479 * gst_pad_needs_reconfigure:
1480 * @pad: the #GstPad to check
1482 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1483 * if the flag was set.
1485 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1488 gst_pad_needs_reconfigure (GstPad * pad)
1490 gboolean reconfigure;
1492 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1494 GST_OBJECT_LOCK (pad);
1495 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1496 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1497 GST_OBJECT_UNLOCK (pad);
1503 * gst_pad_check_reconfigure:
1504 * @pad: the #GstPad to check
1506 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1507 * if the flag was set.
1509 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1512 gst_pad_check_reconfigure (GstPad * pad)
1514 gboolean reconfigure;
1516 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1518 GST_OBJECT_LOCK (pad);
1519 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1521 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1522 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1524 GST_OBJECT_UNLOCK (pad);
1530 * gst_pad_mark_reconfigure:
1531 * @pad: the #GstPad to mark
1533 * Mark a pad for needing reconfiguration. The next call to
1534 * gst_pad_check_reconfigure() will return %TRUE after this call.
1537 gst_pad_mark_reconfigure (GstPad * pad)
1539 g_return_if_fail (GST_IS_PAD (pad));
1541 GST_OBJECT_LOCK (pad);
1542 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1543 GST_OBJECT_UNLOCK (pad);
1547 * gst_pad_set_activate_function:
1549 * @f: the #GstPadActivateFunction to set.
1551 * Calls gst_pad_set_activate_function_full() with NULL for the user_data and
1555 * gst_pad_set_activate_function_full:
1557 * @activate: the #GstPadActivateFunction to set.
1558 * @user_data: user_data passed to @notify
1559 * @notify: notify called when @activate will not be used anymore.
1561 * Sets the given activate function for @pad. The activate function will
1562 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1563 * Only makes sense to set on sink pads.
1565 * Call this function if your sink pad can start a pull-based task.
1568 gst_pad_set_activate_function_full (GstPad * pad,
1569 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1571 g_return_if_fail (GST_IS_PAD (pad));
1573 if (pad->activatenotify)
1574 pad->activatenotify (pad->activatedata);
1575 GST_PAD_ACTIVATEFUNC (pad) = activate;
1576 pad->activatedata = user_data;
1577 pad->activatenotify = notify;
1579 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1580 GST_DEBUG_FUNCPTR_NAME (activate));
1584 * gst_pad_set_activatemode_function:
1586 * @f: the #GstPadActivateModeFunction to set.
1588 * Calls gst_pad_set_activatemode_function_full() with NULL for the user_data and
1592 * gst_pad_set_activatemode_function_full:
1594 * @activatemode: the #GstPadActivateModeFunction to set.
1595 * @user_data: user_data passed to @notify
1596 * @notify: notify called when @activatemode will not be used anymore.
1598 * Sets the given activate_mode function for the pad. An activate_mode function
1599 * prepares the element for data passing.
1602 gst_pad_set_activatemode_function_full (GstPad * pad,
1603 GstPadActivateModeFunction activatemode, gpointer user_data,
1604 GDestroyNotify notify)
1606 g_return_if_fail (GST_IS_PAD (pad));
1608 if (pad->activatemodenotify)
1609 pad->activatemodenotify (pad->activatemodedata);
1610 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1611 pad->activatemodedata = user_data;
1612 pad->activatemodenotify = notify;
1614 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1615 GST_DEBUG_FUNCPTR_NAME (activatemode));
1619 * gst_pad_set_chain_function:
1620 * @p: a sink #GstPad.
1621 * @f: the #GstPadChainFunction to set.
1623 * Calls gst_pad_set_chain_function_full() with NULL for the user_data and
1627 * gst_pad_set_chain_function_full:
1628 * @pad: a sink #GstPad.
1629 * @chain: the #GstPadChainFunction to set.
1630 * @user_data: user_data passed to @notify
1631 * @notify: notify called when @chain will not be used anymore.
1633 * Sets the given chain function for the pad. The chain function is called to
1634 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1637 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1638 gpointer user_data, GDestroyNotify notify)
1640 g_return_if_fail (GST_IS_PAD (pad));
1641 g_return_if_fail (GST_PAD_IS_SINK (pad));
1643 if (pad->chainnotify)
1644 pad->chainnotify (pad->chaindata);
1645 GST_PAD_CHAINFUNC (pad) = chain;
1646 pad->chaindata = user_data;
1647 pad->chainnotify = notify;
1649 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1650 GST_DEBUG_FUNCPTR_NAME (chain));
1654 * gst_pad_set_chain_list_function:
1655 * @p: a sink #GstPad.
1656 * @f: the #GstPadChainListFunction to set.
1658 * Calls gst_pad_set_chain_list_function_full() with NULL for the user_data and
1662 * gst_pad_set_chain_list_function_full:
1663 * @pad: a sink #GstPad.
1664 * @chainlist: the #GstPadChainListFunction to set.
1665 * @user_data: user_data passed to @notify
1666 * @notify: notify called when @chainlist will not be used anymore.
1668 * Sets the given chain list function for the pad. The chainlist function is
1669 * called to process a #GstBufferList input buffer list. See
1670 * #GstPadChainListFunction for more details.
1673 gst_pad_set_chain_list_function_full (GstPad * pad,
1674 GstPadChainListFunction chainlist, gpointer user_data,
1675 GDestroyNotify notify)
1677 g_return_if_fail (GST_IS_PAD (pad));
1678 g_return_if_fail (GST_PAD_IS_SINK (pad));
1680 if (pad->chainlistnotify)
1681 pad->chainlistnotify (pad->chainlistdata);
1682 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1683 pad->chainlistdata = user_data;
1684 pad->chainlistnotify = notify;
1686 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1687 GST_DEBUG_FUNCPTR_NAME (chainlist));
1691 * gst_pad_set_getrange_function:
1692 * @p: a source #GstPad.
1693 * @f: the #GstPadGetRangeFunction to set.
1695 * Calls gst_pad_set_getrange_function_full() with NULL for the user_data and
1699 * gst_pad_set_getrange_function_full:
1700 * @pad: a source #GstPad.
1701 * @get: the #GstPadGetRangeFunction to set.
1702 * @user_data: user_data passed to @notify
1703 * @notify: notify called when @get will not be used anymore.
1705 * Sets the given getrange function for the pad. The getrange function is
1706 * called to produce a new #GstBuffer to start the processing pipeline. see
1707 * #GstPadGetRangeFunction for a description of the getrange function.
1710 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1711 gpointer user_data, GDestroyNotify notify)
1713 g_return_if_fail (GST_IS_PAD (pad));
1714 g_return_if_fail (GST_PAD_IS_SRC (pad));
1716 if (pad->getrangenotify)
1717 pad->getrangenotify (pad->getrangedata);
1718 GST_PAD_GETRANGEFUNC (pad) = get;
1719 pad->getrangedata = user_data;
1720 pad->getrangenotify = notify;
1722 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1723 GST_DEBUG_FUNCPTR_NAME (get));
1727 * gst_pad_set_event_function:
1728 * @p: a #GstPad of either direction.
1729 * @f: the #GstPadEventFunction to set.
1731 * Calls gst_pad_set_event_function_full() with NULL for the user_data and
1735 * gst_pad_set_event_function_full:
1736 * @pad: a #GstPad of either direction.
1737 * @event: the #GstPadEventFunction to set.
1738 * @user_data: user_data passed to @notify
1739 * @notify: notify called when @event will not be used anymore.
1741 * Sets the given event handler for the pad.
1744 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1745 gpointer user_data, GDestroyNotify notify)
1747 g_return_if_fail (GST_IS_PAD (pad));
1749 if (pad->eventnotify)
1750 pad->eventnotify (pad->eventdata);
1751 GST_PAD_EVENTFUNC (pad) = event;
1752 pad->eventdata = user_data;
1753 pad->eventnotify = notify;
1755 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1756 GST_DEBUG_FUNCPTR_NAME (event));
1760 * gst_pad_set_query_function:
1761 * @p: a #GstPad of either direction.
1762 * @f: the #GstPadQueryFunction to set.
1764 * Calls gst_pad_set_query_function_full() with NULL for the user_data and
1768 * gst_pad_set_query_function_full:
1769 * @pad: a #GstPad of either direction.
1770 * @query: the #GstPadQueryFunction to set.
1771 * @user_data: user_data passed to @notify
1772 * @notify: notify called when @query will not be used anymore.
1774 * Set the given query function for the pad.
1777 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1778 gpointer user_data, GDestroyNotify notify)
1780 g_return_if_fail (GST_IS_PAD (pad));
1782 if (pad->querynotify)
1783 pad->querynotify (pad->querydata);
1784 GST_PAD_QUERYFUNC (pad) = query;
1785 pad->querydata = user_data;
1786 pad->querynotify = notify;
1788 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1789 GST_DEBUG_FUNCPTR_NAME (query));
1793 * gst_pad_set_iterate_internal_links_function:
1794 * @p: a #GstPad of either direction.
1795 * @f: the #GstPadIterIntLinkFunction to set.
1797 * Calls gst_pad_set_iterate_internal_links_function_full() with NULL
1798 * for the user_data and notify.
1801 * gst_pad_set_iterate_internal_links_function_full:
1802 * @pad: a #GstPad of either direction.
1803 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1804 * @user_data: user_data passed to @notify
1805 * @notify: notify called when @iterintlink will not be used anymore.
1807 * Sets the given internal link iterator function for the pad.
1810 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1811 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1812 GDestroyNotify notify)
1814 g_return_if_fail (GST_IS_PAD (pad));
1816 if (pad->iterintlinknotify)
1817 pad->iterintlinknotify (pad->iterintlinkdata);
1818 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1819 pad->iterintlinkdata = user_data;
1820 pad->iterintlinknotify = notify;
1822 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1823 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1827 * gst_pad_set_link_function:
1829 * @f: the #GstPadLinkFunction to set.
1831 * Calls gst_pad_set_link_function_full() with NULL
1832 * for the user_data and notify.
1835 * gst_pad_set_link_function_full:
1837 * @link: the #GstPadLinkFunction to set.
1838 * @user_data: user_data passed to @notify
1839 * @notify: notify called when @link will not be used anymore.
1841 * Sets the given link function for the pad. It will be called when
1842 * the pad is linked with another pad.
1844 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1847 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1848 * cannot be made for some reason.
1850 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1851 * of the peer sink pad, if present.
1854 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1855 gpointer user_data, GDestroyNotify notify)
1857 g_return_if_fail (GST_IS_PAD (pad));
1859 if (pad->linknotify)
1860 pad->linknotify (pad->linkdata);
1861 GST_PAD_LINKFUNC (pad) = link;
1862 pad->linkdata = user_data;
1863 pad->linknotify = notify;
1865 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1866 GST_DEBUG_FUNCPTR_NAME (link));
1870 * gst_pad_set_unlink_function:
1872 * @f: the #GstPadUnlinkFunction to set.
1874 * Calls gst_pad_set_unlink_function_full() with NULL
1875 * for the user_data and notify.
1878 * gst_pad_set_unlink_function_full:
1880 * @unlink: the #GstPadUnlinkFunction to set.
1881 * @user_data: user_data passed to @notify
1882 * @notify: notify called when @unlink will not be used anymore.
1884 * Sets the given unlink function for the pad. It will be called
1885 * when the pad is unlinked.
1888 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1889 gpointer user_data, GDestroyNotify notify)
1891 g_return_if_fail (GST_IS_PAD (pad));
1893 if (pad->unlinknotify)
1894 pad->unlinknotify (pad->unlinkdata);
1895 GST_PAD_UNLINKFUNC (pad) = unlink;
1896 pad->unlinkdata = user_data;
1897 pad->unlinknotify = notify;
1899 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1900 GST_DEBUG_FUNCPTR_NAME (unlink));
1905 * @srcpad: the source #GstPad to unlink.
1906 * @sinkpad: the sink #GstPad to unlink.
1908 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1909 * signal on both pads.
1911 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1912 * the pads were not linked together.
1917 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1919 gboolean result = FALSE;
1920 GstElement *parent = NULL;
1922 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1923 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1924 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1925 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1927 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1928 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1929 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1931 /* We need to notify the parent before taking any pad locks as the bin in
1932 * question might be waiting for a lock on the pad while holding its lock
1933 * that our message will try to take. */
1934 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1935 if (GST_IS_ELEMENT (parent)) {
1936 gst_element_post_message (parent,
1937 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1938 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1940 gst_object_unref (parent);
1945 GST_OBJECT_LOCK (srcpad);
1946 GST_OBJECT_LOCK (sinkpad);
1948 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1949 goto not_linked_together;
1951 if (GST_PAD_UNLINKFUNC (srcpad)) {
1952 GstObject *tmpparent;
1954 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1956 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1957 RELEASE_PARENT (tmpparent);
1960 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1961 GstObject *tmpparent;
1963 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1965 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1966 RELEASE_PARENT (tmpparent);
1970 /* first clear peers */
1971 GST_PAD_PEER (srcpad) = NULL;
1972 GST_PAD_PEER (sinkpad) = NULL;
1974 GST_OBJECT_UNLOCK (sinkpad);
1975 GST_OBJECT_UNLOCK (srcpad);
1977 /* fire off a signal to each of the pads telling them
1978 * that they've been unlinked */
1979 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1980 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1982 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1983 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1988 if (parent != NULL) {
1989 gst_element_post_message (parent,
1990 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1991 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1992 gst_object_unref (parent);
1997 not_linked_together:
1999 /* we do not emit a warning in this case because unlinking cannot
2000 * be made MT safe.*/
2001 GST_OBJECT_UNLOCK (sinkpad);
2002 GST_OBJECT_UNLOCK (srcpad);
2008 * gst_pad_is_linked:
2009 * @pad: pad to check
2011 * Checks if a @pad is linked to another pad or not.
2013 * Returns: TRUE if the pad is linked, FALSE otherwise.
2018 gst_pad_is_linked (GstPad * pad)
2022 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2024 GST_OBJECT_LOCK (pad);
2025 result = (GST_PAD_PEER (pad) != NULL);
2026 GST_OBJECT_UNLOCK (pad);
2031 /* get the caps from both pads and see if the intersection
2034 * This function should be called with the pad LOCK on both
2038 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2039 GstPadLinkCheck flags)
2041 GstCaps *srccaps = NULL;
2042 GstCaps *sinkcaps = NULL;
2043 gboolean compatible = FALSE;
2045 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2048 /* Doing the expensive caps checking takes priority over only checking the template caps */
2049 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2050 GST_OBJECT_UNLOCK (sink);
2051 GST_OBJECT_UNLOCK (src);
2053 srccaps = gst_pad_query_caps (src, NULL);
2054 sinkcaps = gst_pad_query_caps (sink, NULL);
2056 GST_OBJECT_LOCK (src);
2057 GST_OBJECT_LOCK (sink);
2059 /* If one of the two pads doesn't have a template, consider the intersection
2061 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2062 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2066 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2068 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2071 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2073 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2076 /* if we have caps on both pads we can check the intersection. If one
2077 * of the caps is NULL, we return TRUE. */
2078 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2080 gst_caps_unref (srccaps);
2082 gst_caps_unref (sinkcaps);
2086 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2087 gst_caps_unref (srccaps);
2088 gst_caps_unref (sinkcaps);
2091 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2092 (compatible ? "" : "not"));
2097 /* check if the grandparents of both pads are the same.
2098 * This check is required so that we don't try to link
2099 * pads from elements in different bins without ghostpads.
2101 * The LOCK should be held on both pads
2104 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2106 GstObject *psrc, *psink;
2108 psrc = GST_OBJECT_PARENT (src);
2109 psink = GST_OBJECT_PARENT (sink);
2111 /* if one of the pads has no parent, we allow the link */
2112 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2115 /* only care about parents that are elements */
2116 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2117 goto no_element_parent;
2119 /* if the parents are the same, we have a loop */
2120 if (G_UNLIKELY (psrc == psink))
2123 /* if they both have a parent, we check the grandparents. We can not lock
2124 * the parent because we hold on the child (pad) and the locking order is
2125 * parent >> child. */
2126 psrc = GST_OBJECT_PARENT (psrc);
2127 psink = GST_OBJECT_PARENT (psink);
2129 /* if they have grandparents but they are not the same */
2130 if (G_UNLIKELY (psrc != psink))
2131 goto wrong_grandparents;
2138 GST_CAT_DEBUG (GST_CAT_CAPS,
2139 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2140 GST_PTR_FORMAT, psrc, psink);
2145 GST_CAT_DEBUG (GST_CAT_CAPS,
2146 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2147 GST_PTR_FORMAT, psrc, psink);
2152 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2158 GST_CAT_DEBUG (GST_CAT_CAPS,
2159 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2160 GST_PTR_FORMAT, psrc, psink);
2165 /* FIXME leftover from an attempt at refactoring... */
2166 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2167 * the two pads will be locked in the srcpad, sinkpad order. */
2168 static GstPadLinkReturn
2169 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2171 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2172 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2174 GST_OBJECT_LOCK (srcpad);
2176 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2177 goto src_was_linked;
2179 GST_OBJECT_LOCK (sinkpad);
2181 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2182 goto sink_was_linked;
2184 /* check hierarchy, pads can only be linked if the grandparents
2186 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2187 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2188 goto wrong_hierarchy;
2190 /* check pad caps for non-empty intersection */
2191 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2194 /* FIXME check pad scheduling for non-empty intersection */
2196 return GST_PAD_LINK_OK;
2200 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2201 GST_DEBUG_PAD_NAME (srcpad),
2202 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2203 /* we do not emit a warning in this case because unlinking cannot
2204 * be made MT safe.*/
2205 GST_OBJECT_UNLOCK (srcpad);
2206 return GST_PAD_LINK_WAS_LINKED;
2210 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2211 GST_DEBUG_PAD_NAME (sinkpad),
2212 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2213 /* we do not emit a warning in this case because unlinking cannot
2214 * be made MT safe.*/
2215 GST_OBJECT_UNLOCK (sinkpad);
2216 GST_OBJECT_UNLOCK (srcpad);
2217 return GST_PAD_LINK_WAS_LINKED;
2221 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2222 GST_OBJECT_UNLOCK (sinkpad);
2223 GST_OBJECT_UNLOCK (srcpad);
2224 return GST_PAD_LINK_WRONG_HIERARCHY;
2228 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2229 GST_OBJECT_UNLOCK (sinkpad);
2230 GST_OBJECT_UNLOCK (srcpad);
2231 return GST_PAD_LINK_NOFORMAT;
2237 * @srcpad: the source #GstPad.
2238 * @sinkpad: the sink #GstPad.
2240 * Checks if the source pad and the sink pad are compatible so they can be
2243 * Returns: TRUE if the pads can be linked.
2246 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2248 GstPadLinkReturn result;
2250 /* generic checks */
2251 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2252 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2254 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2255 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2257 /* gst_pad_link_prepare does everything for us, we only release the locks
2258 * on the pads that it gets us. If this function returns !OK the locks are not
2260 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2261 if (result != GST_PAD_LINK_OK)
2264 GST_OBJECT_UNLOCK (srcpad);
2265 GST_OBJECT_UNLOCK (sinkpad);
2268 return result == GST_PAD_LINK_OK;
2272 * gst_pad_link_full:
2273 * @srcpad: the source #GstPad to link.
2274 * @sinkpad: the sink #GstPad to link.
2275 * @flags: the checks to validate when linking
2277 * Links the source pad and the sink pad.
2279 * This variant of #gst_pad_link provides a more granular control on the
2280 * checks being done when linking. While providing some considerable speedups
2281 * the caller of this method must be aware that wrong usage of those flags
2282 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2283 * for more information.
2287 * Returns: A result code indicating if the connection worked or
2291 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2293 GstPadLinkReturn result;
2295 GstPadLinkFunction srcfunc, sinkfunc;
2297 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2298 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2299 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2300 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2301 GST_PAD_LINK_WRONG_DIRECTION);
2303 /* Notify the parent early. See gst_pad_unlink for details. */
2304 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2305 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2306 gst_element_post_message (parent,
2307 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2308 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2310 gst_object_unref (parent);
2315 /* prepare will also lock the two pads */
2316 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2318 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2321 /* must set peers before calling the link function */
2322 GST_PAD_PEER (srcpad) = sinkpad;
2323 GST_PAD_PEER (sinkpad) = srcpad;
2325 /* check events, when something is different, mark pending */
2326 schedule_events (srcpad, sinkpad);
2328 /* get the link functions */
2329 srcfunc = GST_PAD_LINKFUNC (srcpad);
2330 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2332 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2333 /* custom link functions, execute them */
2334 GST_OBJECT_UNLOCK (sinkpad);
2335 GST_OBJECT_UNLOCK (srcpad);
2338 GstObject *tmpparent;
2340 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2341 /* this one will call the peer link function */
2342 result = srcfunc (srcpad, tmpparent, sinkpad);
2343 RELEASE_PARENT (tmpparent);
2344 } else if (sinkfunc) {
2345 GstObject *tmpparent;
2347 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2348 /* if no source link function, we need to call the sink link
2349 * function ourselves. */
2350 result = sinkfunc (sinkpad, tmpparent, srcpad);
2351 RELEASE_PARENT (tmpparent);
2355 GST_OBJECT_LOCK (srcpad);
2356 GST_OBJECT_LOCK (sinkpad);
2358 /* we released the lock, check if the same pads are linked still */
2359 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2360 goto concurrent_link;
2362 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2365 GST_OBJECT_UNLOCK (sinkpad);
2366 GST_OBJECT_UNLOCK (srcpad);
2368 /* fire off a signal to each of the pads telling them
2369 * that they've been linked */
2370 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2371 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2373 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2374 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2376 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2379 if (G_LIKELY (parent)) {
2380 gst_element_post_message (parent,
2381 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2382 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2383 gst_object_unref (parent);
2391 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2392 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2393 GST_OBJECT_UNLOCK (sinkpad);
2394 GST_OBJECT_UNLOCK (srcpad);
2396 /* The other link operation succeeded first */
2397 result = GST_PAD_LINK_WAS_LINKED;
2402 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2403 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2404 gst_pad_link_get_name (result));
2406 GST_PAD_PEER (srcpad) = NULL;
2407 GST_PAD_PEER (sinkpad) = NULL;
2409 GST_OBJECT_UNLOCK (sinkpad);
2410 GST_OBJECT_UNLOCK (srcpad);
2418 * @srcpad: the source #GstPad to link.
2419 * @sinkpad: the sink #GstPad to link.
2421 * Links the source pad and the sink pad.
2423 * Returns: A result code indicating if the connection worked or
2429 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2431 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2435 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2437 GstPadTemplate **template_p;
2439 /* this function would need checks if it weren't static */
2441 GST_OBJECT_LOCK (pad);
2442 template_p = &pad->padtemplate;
2443 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2444 GST_OBJECT_UNLOCK (pad);
2447 gst_pad_template_pad_created (templ, pad);
2451 * gst_pad_get_pad_template:
2454 * Gets the template for @pad.
2456 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2457 * instantiated, or %NULL if this pad has no template. Unref after
2461 gst_pad_get_pad_template (GstPad * pad)
2463 GstPadTemplate *templ;
2465 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2467 templ = GST_PAD_PAD_TEMPLATE (pad);
2469 return (templ ? gst_object_ref (templ) : NULL);
2473 * gst_pad_has_current_caps:
2474 * @pad: a #GstPad to check
2476 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2478 * Returns: TRUE when @pad has caps associated with it.
2481 gst_pad_has_current_caps (GstPad * pad)
2486 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2488 GST_OBJECT_LOCK (pad);
2489 caps = get_pad_caps (pad);
2490 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2491 "check current pad caps %" GST_PTR_FORMAT, caps);
2492 result = (caps != NULL);
2493 GST_OBJECT_UNLOCK (pad);
2499 * gst_pad_get_current_caps:
2500 * @pad: a #GstPad to get the current capabilities of.
2502 * Gets the capabilities currently configured on @pad with the last
2503 * #GST_EVENT_CAPS event.
2505 * Returns: the current caps of the pad with incremented ref-count.
2508 gst_pad_get_current_caps (GstPad * pad)
2512 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2514 GST_OBJECT_LOCK (pad);
2515 if ((result = get_pad_caps (pad)))
2516 gst_caps_ref (result);
2517 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2518 "get current pad caps %" GST_PTR_FORMAT, result);
2519 GST_OBJECT_UNLOCK (pad);
2525 * gst_pad_get_pad_template_caps:
2526 * @pad: a #GstPad to get the template capabilities from.
2528 * Gets the capabilities for @pad's template.
2530 * Returns: (transfer full): the #GstCaps of this pad template.
2531 * Unref after usage.
2534 gst_pad_get_pad_template_caps (GstPad * pad)
2536 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2538 if (GST_PAD_PAD_TEMPLATE (pad))
2539 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2541 return gst_caps_ref (GST_CAPS_ANY);
2546 * @pad: a #GstPad to get the peer of.
2548 * Gets the peer of @pad. This function refs the peer pad so
2549 * you need to unref it after use.
2551 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2556 gst_pad_get_peer (GstPad * pad)
2560 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2562 GST_OBJECT_LOCK (pad);
2563 result = GST_PAD_PEER (pad);
2565 gst_object_ref (result);
2566 GST_OBJECT_UNLOCK (pad);
2572 * gst_pad_get_allowed_caps:
2575 * Gets the capabilities of the allowed media types that can flow through
2576 * @pad and its peer.
2578 * The allowed capabilities is calculated as the intersection of the results of
2579 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2580 * on the resulting caps.
2582 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2583 * caps when you no longer need it. This function returns NULL when @pad
2589 gst_pad_get_allowed_caps (GstPad * pad)
2595 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2597 GST_OBJECT_LOCK (pad);
2598 peer = GST_PAD_PEER (pad);
2599 if (G_UNLIKELY (peer == NULL))
2602 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2604 gst_object_ref (peer);
2605 GST_OBJECT_UNLOCK (pad);
2606 mycaps = gst_pad_query_caps (pad, NULL);
2608 caps = gst_pad_query_caps (peer, mycaps);
2609 gst_object_unref (peer);
2611 gst_caps_unref (mycaps);
2613 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2620 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2621 GST_OBJECT_UNLOCK (pad);
2628 * gst_pad_iterate_internal_links_default:
2629 * @pad: the #GstPad to get the internal links of.
2630 * @parent: (allow-none): the parent of @pad or NULL
2632 * Iterate the list of pads to which the given pad is linked to inside of
2633 * the parent element.
2634 * This is the default handler, and thus returns an iterator of all of the
2635 * pads inside the parent element with opposite direction.
2637 * The caller must free this iterator after use with gst_iterator_free().
2639 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2640 * returned pad with gst_object_unref().
2643 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2650 GstElement *eparent;
2652 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2654 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2655 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2657 GST_OBJECT_LOCK (pad);
2658 eparent = GST_PAD_PARENT (pad);
2659 if (!eparent || !GST_IS_ELEMENT (eparent))
2662 gst_object_ref (eparent);
2663 GST_OBJECT_UNLOCK (pad);
2666 if (pad->direction == GST_PAD_SRC)
2667 padlist = &eparent->sinkpads;
2669 padlist = &eparent->srcpads;
2671 GST_DEBUG_OBJECT (pad, "Making iterator");
2673 cookie = &eparent->pads_cookie;
2675 lock = GST_OBJECT_GET_LOCK (eparent);
2677 res = gst_iterator_new_list (GST_TYPE_PAD,
2678 lock, cookie, padlist, (GObject *) owner, NULL);
2680 gst_object_unref (owner);
2687 GST_OBJECT_UNLOCK (pad);
2688 GST_DEBUG_OBJECT (pad, "no parent element");
2694 * gst_pad_iterate_internal_links:
2695 * @pad: the GstPad to get the internal links of.
2697 * Gets an iterator for the pads to which the given pad is linked to inside
2698 * of the parent element.
2700 * Each #GstPad element yielded by the iterator will have its refcount increased,
2701 * so unref after use.
2703 * Free-function: gst_iterator_free
2705 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2706 * pad does not have an iterator function configured. Use
2707 * gst_iterator_free() after usage.
2710 gst_pad_iterate_internal_links (GstPad * pad)
2712 GstIterator *res = NULL;
2715 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2717 GST_OBJECT_LOCK (pad);
2718 ACQUIRE_PARENT (pad, parent, no_parent);
2719 GST_OBJECT_UNLOCK (pad);
2721 if (GST_PAD_ITERINTLINKFUNC (pad))
2722 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2724 RELEASE_PARENT (parent);
2731 GST_DEBUG_OBJECT (pad, "no parent");
2732 GST_OBJECT_UNLOCK (pad);
2740 * @forward: (scope call): a #GstPadForwardFunction
2741 * @user_data: user data passed to @forward
2743 * Calls @forward for all internally linked pads of @pad. This function deals with
2744 * dynamically changing internal pads and will make sure that the @forward
2745 * function is only called once for each pad.
2747 * When @forward returns TRUE, no further pads will be processed.
2749 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2752 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2755 gboolean result = FALSE;
2757 gboolean done = FALSE;
2758 GValue item = { 0, };
2759 GList *pushed_pads = NULL;
2761 iter = gst_pad_iterate_internal_links (pad);
2767 switch (gst_iterator_next (iter, &item)) {
2768 case GST_ITERATOR_OK:
2772 intpad = g_value_get_object (&item);
2774 /* if already pushed, skip. FIXME, find something faster to tag pads */
2775 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2776 g_value_reset (&item);
2780 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2781 GST_DEBUG_PAD_NAME (intpad));
2782 done = result = forward (intpad, user_data);
2784 pushed_pads = g_list_prepend (pushed_pads, intpad);
2786 g_value_reset (&item);
2789 case GST_ITERATOR_RESYNC:
2790 /* We don't reset the result here because we don't push the event
2791 * again on pads that got the event already and because we need
2792 * to consider the result of the previous pushes */
2793 gst_iterator_resync (iter);
2795 case GST_ITERATOR_ERROR:
2796 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2799 case GST_ITERATOR_DONE:
2804 g_value_unset (&item);
2805 gst_iterator_free (iter);
2807 g_list_free (pushed_pads);
2817 gboolean dispatched;
2821 event_forward_func (GstPad * pad, EventData * data)
2823 /* for each pad we send to, we should ref the event; it's up
2824 * to downstream to unref again when handled. */
2825 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2826 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2828 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2830 data->dispatched = TRUE;
2837 * gst_pad_event_default:
2838 * @pad: a #GstPad to call the default event handler on.
2839 * @parent: (allow-none): the parent of @pad or NULL
2840 * @event: (transfer full): the #GstEvent to handle.
2842 * Invokes the default event handler for the given pad.
2844 * The EOS event will pause the task associated with @pad before it is forwarded
2845 * to all internally linked pads,
2847 * The the event is sent to all pads internally linked to @pad. This function
2848 * takes ownership of @event.
2850 * Returns: TRUE if the event was sent successfully.
2853 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2855 gboolean result, forward = TRUE;
2857 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2858 g_return_val_if_fail (event != NULL, FALSE);
2860 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2863 switch (GST_EVENT_TYPE (event)) {
2864 case GST_EVENT_CAPS:
2865 forward = GST_PAD_IS_PROXY_CAPS (pad);
2876 data.dispatched = FALSE;
2877 data.result = FALSE;
2879 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2881 /* for sinkpads without a parent element or without internal links, nothing
2882 * will be dispatched but we still want to return TRUE. */
2883 if (data.dispatched)
2884 result = data.result;
2889 gst_event_unref (event);
2894 /* Default accept caps implementation just checks against
2895 * the allowed caps for the pad */
2897 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2899 /* get the caps and see if it intersects to something not empty */
2900 GstCaps *caps, *allowed;
2903 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2905 /* first forward the query to internally linked pads when we are dealing with
2907 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2908 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2913 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2914 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2916 gst_query_parse_accept_caps (query, &caps);
2917 allowed = gst_pad_query_caps (pad, caps);
2920 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
2921 GST_DEBUG_OBJECT (pad,
2922 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
2924 result = gst_caps_can_intersect (caps, allowed);
2926 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
2927 GST_PTR_FORMAT, allowed, caps);
2928 result = gst_caps_is_subset (caps, allowed);
2930 gst_caps_unref (allowed);
2932 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
2935 gst_query_set_accept_caps_result (query, result);
2941 /* Default caps implementation */
2943 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2945 GstCaps *result = NULL, *filter;
2946 GstPadTemplate *templ;
2947 gboolean fixed_caps;
2949 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2952 /* first try to proxy if we must */
2953 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2954 if ((gst_pad_proxy_query_caps (pad, query))) {
2959 gst_query_parse_caps (query, &filter);
2961 /* no proxy or it failed, do default handling */
2962 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2964 GST_OBJECT_LOCK (pad);
2966 /* fixed caps, try the negotiated caps first */
2967 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2968 if ((result = get_pad_caps (pad)))
2969 goto filter_done_unlock;
2972 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2973 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2974 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2975 goto filter_done_unlock;
2979 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2980 "non-fixed pad caps: trying pad caps");
2981 /* non fixed caps, try the negotiated caps */
2982 if ((result = get_pad_caps (pad)))
2983 goto filter_done_unlock;
2986 /* this almost never happens */
2987 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2988 result = GST_CAPS_ANY;
2991 GST_OBJECT_UNLOCK (pad);
2993 /* run the filter on the result */
2995 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2996 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2997 GST_PTR_FORMAT, result, result, filter, filter);
2998 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2999 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3002 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3003 "using caps %p %" GST_PTR_FORMAT, result, result);
3004 result = gst_caps_ref (result);
3006 gst_query_set_caps_result (query, result);
3007 gst_caps_unref (result);
3017 gboolean dispatched;
3021 query_forward_func (GstPad * pad, QueryData * data)
3023 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3024 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3026 data->result |= gst_pad_peer_query (pad, data->query);
3028 data->dispatched = TRUE;
3030 /* stop on first successful reply */
3031 return data->result;
3035 * gst_pad_query_default:
3036 * @pad: a #GstPad to call the default query handler on.
3037 * @parent: (allow-none): the parent of @pad or NULL
3038 * @query: (transfer none): the #GstQuery to handle.
3040 * Invokes the default query handler for the given pad.
3041 * The query is sent to all pads internally linked to @pad. Note that
3042 * if there are many possible sink pads that are internally linked to
3043 * @pad, only one will be sent the query.
3044 * Multi-sinkpad elements should implement custom query handlers.
3046 * Returns: TRUE if the query was performed successfully.
3049 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3051 gboolean forward, ret = FALSE;
3053 switch (GST_QUERY_TYPE (query)) {
3054 case GST_QUERY_SCHEDULING:
3055 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3057 case GST_QUERY_ALLOCATION:
3058 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3060 case GST_QUERY_ACCEPT_CAPS:
3061 ret = gst_pad_query_accept_caps_default (pad, query);
3064 case GST_QUERY_CAPS:
3065 ret = gst_pad_query_caps_default (pad, query);
3068 case GST_QUERY_POSITION:
3069 case GST_QUERY_SEEKING:
3070 case GST_QUERY_FORMATS:
3071 case GST_QUERY_LATENCY:
3072 case GST_QUERY_JITTER:
3073 case GST_QUERY_RATE:
3074 case GST_QUERY_CONVERT:
3080 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3081 query, GST_QUERY_TYPE_NAME (query));
3087 data.dispatched = FALSE;
3088 data.result = FALSE;
3090 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3092 if (data.dispatched) {
3095 /* nothing dispatched, assume drained */
3096 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3106 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3108 GstPad *pad = data->pad;
3109 GstPadProbeInfo *info = data->info;
3110 GstPadProbeType type, flags;
3111 GstPadProbeCallback callback;
3112 GstPadProbeReturn ret;
3114 /* if we have called this callback, do nothing */
3115 if (PROBE_COOKIE (hook) == data->cookie) {
3116 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3117 "hook %lu, cookie %u already called", hook->hook_id,
3118 PROBE_COOKIE (hook));
3122 PROBE_COOKIE (hook) = data->cookie;
3124 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3127 /* one of the data types for non-idle probes */
3128 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3129 && (flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3131 /* one of the scheduling types */
3132 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3134 /* one of the blocking types must match */
3135 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3136 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3138 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3139 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3141 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3142 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3143 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3146 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3147 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3148 PROBE_COOKIE (hook), flags);
3150 data->marshalled = TRUE;
3152 callback = (GstPadProbeCallback) hook->func;
3153 if (callback == NULL)
3156 info->id = hook->hook_id;
3158 GST_OBJECT_UNLOCK (pad);
3160 ret = callback (pad, info, hook->data);
3162 GST_OBJECT_LOCK (pad);
3165 case GST_PAD_PROBE_REMOVE:
3166 /* remove the probe */
3167 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3168 cleanup_hook (pad, hook);
3170 case GST_PAD_PROBE_DROP:
3171 /* need to drop the data, make sure other probes don't get called
3173 GST_DEBUG_OBJECT (pad, "asked to drop item");
3174 info->type = GST_PAD_PROBE_TYPE_INVALID;
3175 data->dropped = TRUE;
3177 case GST_PAD_PROBE_PASS:
3178 /* inform the pad block to let things pass */
3179 GST_DEBUG_OBJECT (pad, "asked to pass item");
3182 case GST_PAD_PROBE_OK:
3183 GST_DEBUG_OBJECT (pad, "probe returned OK");
3186 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3193 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3194 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3195 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3200 /* a probe that does not take or return any data */
3201 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3203 if (G_UNLIKELY (pad->num_probes)) { \
3204 /* pass NULL as the data item */ \
3205 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3206 ret = do_probe_callbacks (pad, &info, defaultval); \
3207 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3212 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3214 if (G_UNLIKELY (pad->num_probes)) { \
3215 /* pass the data item */ \
3216 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3217 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3218 /* store the possibly updated data item */ \
3219 data = GST_PAD_PROBE_INFO_DATA (&info); \
3220 /* if something went wrong, exit */ \
3221 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3226 #define PROBE_PUSH(pad,mask,data,label) \
3227 PROBE_FULL(pad, mask, data, -1, -1, label);
3228 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3229 PROBE_FULL(pad, mask, data, offs, size, label);
3231 static GstFlowReturn
3232 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3233 GstFlowReturn defaultval)
3242 data.marshalled = FALSE;
3243 data.dropped = FALSE;
3244 data.cookie = ++pad->priv->probe_cookie;
3247 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3250 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3251 "do probes cookie %u", data.cookie);
3252 cookie = pad->priv->probe_list_cookie;
3254 g_hook_list_marshal (&pad->probes, TRUE,
3255 (GHookMarshaller) probe_hook_marshal, &data);
3257 /* if the list changed, call the new callbacks (they will not have their
3258 * cookie set to data.cookie */
3259 if (cookie != pad->priv->probe_list_cookie) {
3260 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3261 "probe list changed, restarting");
3265 /* the first item that dropped will stop the hooks and then we drop here */
3269 /* if no handler matched and we are blocking, let the item pass */
3270 if (!data.marshalled && is_block)
3273 /* At this point, all handlers returned either OK or PASS. If one handler
3274 * returned PASS, let the item pass */
3279 while (GST_PAD_IS_BLOCKED (pad)) {
3280 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3281 "we are blocked %d times", pad->num_blocked);
3283 /* we might have released the lock */
3284 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3287 /* now we block the streaming thread. It can be unlocked when we
3288 * deactivate the pad (which will also set the FLUSHING flag) or
3289 * when the pad is unblocked. A flushing event will also unblock
3290 * the pad after setting the FLUSHING flag. */
3291 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3292 "Waiting to be unblocked or set flushing");
3293 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3294 GST_PAD_BLOCK_WAIT (pad);
3295 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3296 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3298 /* if the list changed, call the new callbacks (they will not have their
3299 * cookie set to data.cookie */
3300 if (cookie != pad->priv->probe_list_cookie) {
3301 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3302 "probe list changed, restarting");
3306 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3316 GST_DEBUG_OBJECT (pad, "pad is flushing");
3317 return GST_FLOW_FLUSHING;
3321 GST_DEBUG_OBJECT (pad, "data is dropped");
3322 return GST_FLOW_CUSTOM_SUCCESS;
3326 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3327 GST_DEBUG_OBJECT (pad, "data is passed");
3335 * gst_pad_get_offset:
3338 * Get the offset applied to the running time of @pad. @pad has to be a source
3341 * Returns: the offset.
3344 gst_pad_get_offset (GstPad * pad)
3348 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3350 GST_OBJECT_LOCK (pad);
3351 result = pad->offset;
3352 GST_OBJECT_UNLOCK (pad);
3358 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3360 ev->received = FALSE;
3365 * gst_pad_set_offset:
3367 * @offset: the offset
3369 * Set the offset that will be applied to the running time of @pad.
3372 gst_pad_set_offset (GstPad * pad, gint64 offset)
3374 g_return_if_fail (GST_IS_PAD (pad));
3376 GST_OBJECT_LOCK (pad);
3377 /* if nothing changed, do nothing */
3378 if (pad->offset == offset)
3381 pad->offset = offset;
3382 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3384 /* resend all sticky events with updated offset on next buffer push */
3385 events_foreach (pad, mark_event_not_received, NULL);
3386 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3389 GST_OBJECT_UNLOCK (pad);
3396 /* If TRUE and ret is not OK this means
3397 * that pushing the EOS event failed
3401 /* If called for an event this is
3402 * the event that would be pushed
3403 * next. Don't forward sticky events
3404 * that would come after that */
3408 /* should be called with pad LOCK */
3410 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3412 PushStickyData *data = user_data;
3413 GstEvent *event = ev->event;
3416 GST_DEBUG_OBJECT (pad, "event %s was already received",
3417 GST_EVENT_TYPE_NAME (event));
3421 /* If we're called because of an sticky event, only forward
3422 * events that would come before this new event and the
3424 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3425 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3426 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3427 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3429 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3430 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3433 switch (data->ret) {
3435 ev->received = TRUE;
3436 GST_DEBUG_OBJECT (pad, "event %s marked received",
3437 GST_EVENT_TYPE_NAME (event));
3439 case GST_FLOW_CUSTOM_SUCCESS:
3440 /* we can't assume the event is received when it was dropped */
3441 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3442 GST_EVENT_TYPE_NAME (event));
3443 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3444 data->ret = GST_FLOW_OK;
3446 case GST_FLOW_CUSTOM_SUCCESS_1:
3447 /* event was ignored and should be sent later */
3448 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3449 GST_EVENT_TYPE_NAME (event));
3450 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3451 data->ret = GST_FLOW_OK;
3453 case GST_FLOW_NOT_LINKED:
3454 /* not linked is not a problem, we are sticky so the event will be
3455 * sent later but only for non-EOS events */
3456 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3457 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3458 data->ret = GST_FLOW_OK;
3459 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3462 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3463 gst_flow_get_name (data->ret));
3464 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3468 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3469 data->was_eos = TRUE;
3471 return data->ret == GST_FLOW_OK;
3474 /* check sticky events and push them when needed. should be called
3476 static inline GstFlowReturn
3477 check_sticky (GstPad * pad, GstEvent * event)
3479 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3481 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3482 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3484 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3485 events_foreach (pad, push_sticky, &data);
3487 /* If there's an EOS event we must push it downstream
3488 * even if sending a previous sticky event failed.
3489 * Otherwise the pipeline might wait forever for EOS.
3491 * Only do this if pushing another event than the EOS
3494 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3495 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3497 if (ev && !ev->received) {
3498 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3499 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3500 /* the event could have been dropped. Because this can only
3501 * happen if the user asked for it, it's not an error */
3502 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3503 data.ret = GST_FLOW_OK;
3513 * @pad: a #GstPad to invoke the default query on.
3514 * @query: (transfer none): the #GstQuery to perform.
3516 * Dispatches a query to a pad. The query should have been allocated by the
3517 * caller via one of the type-specific allocation functions. The element that
3518 * the pad belongs to is responsible for filling the query with an appropriate
3519 * response, which should then be parsed with a type-specific query parsing
3522 * Again, the caller is responsible for both the allocation and deallocation of
3523 * the query structure.
3525 * Please also note that some queries might need a running pipeline to work.
3527 * Returns: TRUE if the query could be performed.
3530 gst_pad_query (GstPad * pad, GstQuery * query)
3533 gboolean res, serialized;
3534 GstPadQueryFunction func;
3535 GstPadProbeType type;
3538 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3539 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3541 if (GST_PAD_IS_SRC (pad)) {
3542 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3543 goto wrong_direction;
3544 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3545 } else if (GST_PAD_IS_SINK (pad)) {
3546 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3547 goto wrong_direction;
3548 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3550 goto unknown_direction;
3552 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3553 GST_QUERY_TYPE_NAME (query));
3555 serialized = GST_QUERY_IS_SERIALIZED (query);
3556 if (G_UNLIKELY (serialized))
3557 GST_PAD_STREAM_LOCK (pad);
3559 GST_OBJECT_LOCK (pad);
3560 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3561 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3562 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3564 ACQUIRE_PARENT (pad, parent, no_parent);
3565 GST_OBJECT_UNLOCK (pad);
3567 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3570 res = func (pad, parent, query);
3572 RELEASE_PARENT (parent);
3574 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3575 GST_QUERY_TYPE_NAME (query), res);
3580 GST_OBJECT_LOCK (pad);
3581 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3582 GST_OBJECT_UNLOCK (pad);
3584 if (G_UNLIKELY (serialized))
3585 GST_PAD_STREAM_UNLOCK (pad);
3592 g_warning ("pad %s:%s query %s in wrong direction",
3593 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3598 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3603 GST_DEBUG_OBJECT (pad, "had no parent");
3604 GST_OBJECT_UNLOCK (pad);
3605 if (G_UNLIKELY (serialized))
3606 GST_PAD_STREAM_UNLOCK (pad);
3611 GST_DEBUG_OBJECT (pad, "had no query function");
3612 RELEASE_PARENT (parent);
3613 if (G_UNLIKELY (serialized))
3614 GST_PAD_STREAM_UNLOCK (pad);
3619 GST_DEBUG_OBJECT (pad, "query failed");
3620 if (G_UNLIKELY (serialized))
3621 GST_PAD_STREAM_UNLOCK (pad);
3626 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3627 GST_OBJECT_UNLOCK (pad);
3628 if (G_UNLIKELY (serialized))
3629 GST_PAD_STREAM_UNLOCK (pad);
3631 /* if a probe dropped, we don't sent it further but assume that the probe
3632 * answered the query and return TRUE */
3633 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3643 * gst_pad_peer_query:
3644 * @pad: a #GstPad to invoke the peer query on.
3645 * @query: (transfer none): the #GstQuery to perform.
3647 * Performs gst_pad_query() on the peer of @pad.
3649 * The caller is responsible for both the allocation and deallocation of
3650 * the query structure.
3652 * Returns: TRUE if the query could be performed. This function returns %FALSE
3653 * if @pad has no peer.
3656 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3659 GstPadProbeType type;
3660 gboolean res, serialized;
3663 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3664 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3666 if (GST_PAD_IS_SRC (pad)) {
3667 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3668 goto wrong_direction;
3669 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3670 } else if (GST_PAD_IS_SINK (pad)) {
3671 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3672 goto wrong_direction;
3673 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3675 goto unknown_direction;
3677 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3678 GST_QUERY_TYPE_NAME (query));
3680 serialized = GST_QUERY_IS_SERIALIZED (query);
3682 GST_OBJECT_LOCK (pad);
3683 if (GST_PAD_IS_SRC (pad) && serialized) {
3684 /* all serialized queries on the srcpad trigger push of
3686 if (check_sticky (pad, NULL) != GST_FLOW_OK)
3690 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3691 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3692 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3694 peerpad = GST_PAD_PEER (pad);
3695 if (G_UNLIKELY (peerpad == NULL))
3698 gst_object_ref (peerpad);
3699 GST_OBJECT_UNLOCK (pad);
3701 res = gst_pad_query (peerpad, query);
3703 gst_object_unref (peerpad);
3708 GST_OBJECT_LOCK (pad);
3709 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3710 GST_OBJECT_UNLOCK (pad);
3717 g_warning ("pad %s:%s query %s in wrong direction",
3718 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3723 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3728 GST_WARNING_OBJECT (pad, "could not send sticky events");
3729 GST_OBJECT_UNLOCK (pad);
3734 GST_INFO_OBJECT (pad, "pad has no peer");
3735 GST_OBJECT_UNLOCK (pad);
3740 GST_DEBUG_OBJECT (pad, "query failed");
3745 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3746 GST_OBJECT_UNLOCK (pad);
3748 /* if a probe dropped, we don't sent it further but assume that the probe
3749 * answered the query and return TRUE */
3750 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3759 /**********************************************************************
3760 * Data passing functions
3763 /* this is the chain function that does not perform the additional argument
3764 * checking for that little extra speed.
3766 static inline GstFlowReturn
3767 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3772 GST_PAD_STREAM_LOCK (pad);
3774 GST_OBJECT_LOCK (pad);
3775 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3778 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3781 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3784 #ifndef G_DISABLE_ASSERT
3785 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3786 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3788 ":%s:<%s:%s> Got data flow before stream-start event",
3789 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3791 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3793 ":%s:<%s:%s> Got data flow before segment event",
3794 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3796 pad->priv->last_cookie = pad->priv->events_cookie;
3800 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3802 PROBE_PUSH (pad, type, data, probe_stopped);
3804 parent = GST_OBJECT_PARENT (pad);
3805 GST_OBJECT_UNLOCK (pad);
3807 /* NOTE: we read the chainfunc unlocked.
3808 * we cannot hold the lock for the pad so we might send
3809 * the data to the wrong function. This is not really a
3810 * problem since functions are assigned at creation time
3811 * and don't change that often... */
3812 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3813 GstPadChainFunction chainfunc;
3815 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3818 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3819 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3820 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3822 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3824 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3825 "called chainfunction &%s with buffer %p, returned %s",
3826 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3828 GstPadChainListFunction chainlistfunc;
3830 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3833 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3834 "calling chainlistfunction &%s",
3835 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3837 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3839 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3840 "called chainlistfunction &%s, returned %s",
3841 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3844 GST_PAD_STREAM_UNLOCK (pad);
3851 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3852 "chaining, but pad was flushing");
3853 GST_OBJECT_UNLOCK (pad);
3854 GST_PAD_STREAM_UNLOCK (pad);
3855 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3856 return GST_FLOW_FLUSHING;
3860 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3861 GST_OBJECT_UNLOCK (pad);
3862 GST_PAD_STREAM_UNLOCK (pad);
3863 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3864 return GST_FLOW_EOS;
3868 g_critical ("chain on pad %s:%s but it was not in push mode",
3869 GST_DEBUG_PAD_NAME (pad));
3870 GST_OBJECT_UNLOCK (pad);
3871 GST_PAD_STREAM_UNLOCK (pad);
3872 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3873 return GST_FLOW_ERROR;
3877 GST_OBJECT_UNLOCK (pad);
3878 GST_PAD_STREAM_UNLOCK (pad);
3879 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3882 case GST_FLOW_CUSTOM_SUCCESS:
3883 GST_DEBUG_OBJECT (pad, "dropped buffer");
3887 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
3894 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3895 g_critical ("chain on pad %s:%s but it has no chainfunction",
3896 GST_DEBUG_PAD_NAME (pad));
3897 GST_PAD_STREAM_UNLOCK (pad);
3898 return GST_FLOW_NOT_SUPPORTED;
3904 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3905 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3908 * Chain a buffer to @pad.
3910 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3912 * If the buffer type is not acceptable for @pad (as negotiated with a
3913 * preceding GST_EVENT_CAPS event), this function returns
3914 * #GST_FLOW_NOT_NEGOTIATED.
3916 * The function proceeds calling the chain function installed on @pad (see
3917 * gst_pad_set_chain_function()) and the return value of that function is
3918 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3921 * In all cases, success or failure, the caller loses its reference to @buffer
3922 * after calling this function.
3924 * Returns: a #GstFlowReturn from the pad.
3929 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3931 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3932 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3933 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3935 return gst_pad_chain_data_unchecked (pad,
3936 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3939 static GstFlowReturn
3940 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3941 GstBufferList * list)
3947 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3949 len = gst_buffer_list_length (list);
3952 for (i = 0; i < len; i++) {
3953 buffer = gst_buffer_list_get (list, i);
3955 gst_pad_chain_data_unchecked (pad,
3956 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3957 gst_buffer_ref (buffer));
3958 if (ret != GST_FLOW_OK)
3961 gst_buffer_list_unref (list);
3967 * gst_pad_chain_list:
3968 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3969 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3972 * Chain a bufferlist to @pad.
3974 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3976 * If @pad was not negotiated properly with a CAPS event, this function
3977 * returns #GST_FLOW_NOT_NEGOTIATED.
3979 * The function proceeds calling the chainlist function installed on @pad (see
3980 * gst_pad_set_chain_list_function()) and the return value of that function is
3981 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3982 * chainlist function.
3984 * In all cases, success or failure, the caller loses its reference to @list
3985 * after calling this function.
3989 * Returns: a #GstFlowReturn from the pad.
3992 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3994 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3995 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3996 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3998 return gst_pad_chain_data_unchecked (pad,
3999 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4002 static GstFlowReturn
4003 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4008 GST_OBJECT_LOCK (pad);
4009 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4012 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4015 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4018 #ifndef G_DISABLE_ASSERT
4019 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4020 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4022 ":%s:<%s:%s> Got data flow before stream-start event",
4023 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4025 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4027 ":%s:<%s:%s> Got data flow before segment event",
4028 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4030 pad->priv->last_cookie = pad->priv->events_cookie;
4034 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4037 /* do block probes */
4038 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
4040 /* recheck sticky events because the probe might have cause a relink */
4041 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4044 /* do post-blocking probes */
4045 PROBE_PUSH (pad, type, data, probe_stopped);
4047 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4050 /* take ref to peer pad before releasing the lock */
4051 gst_object_ref (peer);
4053 GST_OBJECT_UNLOCK (pad);
4055 ret = gst_pad_chain_data_unchecked (peer, type, data);
4057 gst_object_unref (peer);
4059 GST_OBJECT_LOCK (pad);
4061 if (pad->priv->using == 0) {
4062 /* pad is not active anymore, trigger idle callbacks */
4063 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4064 probe_stopped, ret);
4066 GST_OBJECT_UNLOCK (pad);
4070 /* ERROR recovery here */
4074 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4075 "pushing, but pad was flushing");
4076 GST_OBJECT_UNLOCK (pad);
4077 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4078 return GST_FLOW_FLUSHING;
4082 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4083 GST_OBJECT_UNLOCK (pad);
4084 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4085 return GST_FLOW_EOS;
4089 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4090 GST_DEBUG_PAD_NAME (pad));
4091 GST_OBJECT_UNLOCK (pad);
4092 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4093 return GST_FLOW_ERROR;
4097 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4098 "error pushing events, return %s", gst_flow_get_name (ret));
4099 GST_OBJECT_UNLOCK (pad);
4100 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4105 GST_OBJECT_UNLOCK (pad);
4106 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4109 case GST_FLOW_CUSTOM_SUCCESS:
4110 GST_DEBUG_OBJECT (pad, "dropped buffer");
4114 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4121 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4122 "pushing, but it was not linked");
4123 GST_OBJECT_UNLOCK (pad);
4124 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4125 return GST_FLOW_NOT_LINKED;
4131 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4132 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4135 * Pushes a buffer to the peer of @pad.
4137 * This function will call installed block probes before triggering any
4138 * installed data probes.
4140 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4141 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4144 * In all cases, success or failure, the caller loses its reference to @buffer
4145 * after calling this function.
4147 * Returns: a #GstFlowReturn from the peer pad.
4152 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4154 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4155 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4156 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4158 return gst_pad_push_data (pad,
4159 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4163 * gst_pad_push_list:
4164 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4165 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4168 * Pushes a buffer list to the peer of @pad.
4170 * This function will call installed block probes before triggering any
4171 * installed data probes.
4173 * The function proceeds calling the chain function on the peer pad and returns
4174 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4175 * be returned. If the peer pad does not have any installed chainlist function
4176 * every group buffer of the list will be merged into a normal #GstBuffer and
4177 * chained via gst_pad_chain().
4179 * In all cases, success or failure, the caller loses its reference to @list
4180 * after calling this function.
4182 * Returns: a #GstFlowReturn from the peer pad.
4187 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4189 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4190 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4191 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4193 return gst_pad_push_data (pad,
4194 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4197 static GstFlowReturn
4198 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4199 GstBuffer ** buffer)
4202 GstPadGetRangeFunction getrangefunc;
4206 GST_PAD_STREAM_LOCK (pad);
4208 GST_OBJECT_LOCK (pad);
4209 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4212 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4215 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4220 /* when one of the probes returns DROPPED, probe_stopped will be called
4221 * and we skip calling the getrange function, res_buf should then contain a
4222 * valid result buffer */
4223 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4224 res_buf, offset, size, probe_stopped);
4226 /* recheck sticky events because the probe might have cause a relink */
4227 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4230 ACQUIRE_PARENT (pad, parent, no_parent);
4231 GST_OBJECT_UNLOCK (pad);
4233 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4236 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4237 "calling getrangefunc %s, offset %"
4238 G_GUINT64_FORMAT ", size %u",
4239 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4241 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4243 RELEASE_PARENT (parent);
4245 if (G_UNLIKELY (ret != GST_FLOW_OK))
4246 goto get_range_failed;
4248 /* can only fire the signal if we have a valid buffer */
4249 GST_OBJECT_LOCK (pad);
4251 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4252 res_buf, offset, size, probe_stopped_unref);
4253 GST_OBJECT_UNLOCK (pad);
4255 GST_PAD_STREAM_UNLOCK (pad);
4264 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4265 "getrange, but pad was flushing");
4266 GST_OBJECT_UNLOCK (pad);
4267 GST_PAD_STREAM_UNLOCK (pad);
4268 return GST_FLOW_FLUSHING;
4272 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4273 GST_DEBUG_PAD_NAME (pad));
4274 GST_OBJECT_UNLOCK (pad);
4275 GST_PAD_STREAM_UNLOCK (pad);
4276 return GST_FLOW_ERROR;
4280 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4281 GST_OBJECT_UNLOCK (pad);
4282 GST_PAD_STREAM_UNLOCK (pad);
4287 GST_DEBUG_OBJECT (pad, "no parent");
4288 GST_OBJECT_UNLOCK (pad);
4289 GST_PAD_STREAM_UNLOCK (pad);
4290 return GST_FLOW_FLUSHING;
4294 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4295 GST_DEBUG_PAD_NAME (pad));
4296 RELEASE_PARENT (parent);
4297 GST_PAD_STREAM_UNLOCK (pad);
4298 return GST_FLOW_NOT_SUPPORTED;
4302 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4303 "probe returned %s", gst_flow_get_name (ret));
4304 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4306 /* the probe filled the buffer and asks us to not call the getrange
4307 * anymore, we continue with the post probes then. */
4308 GST_DEBUG_OBJECT (pad, "handled buffer");
4312 /* no buffer, we are EOS */
4313 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4317 GST_OBJECT_UNLOCK (pad);
4318 GST_PAD_STREAM_UNLOCK (pad);
4322 probe_stopped_unref:
4324 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4325 "probe returned %s", gst_flow_get_name (ret));
4326 /* if we drop here, it signals EOS */
4327 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4329 GST_OBJECT_UNLOCK (pad);
4330 GST_PAD_STREAM_UNLOCK (pad);
4331 if (*buffer == NULL)
4332 gst_buffer_unref (res_buf);
4337 GST_PAD_STREAM_UNLOCK (pad);
4338 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4339 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4340 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4346 * gst_pad_get_range:
4347 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4348 * @offset: The start offset of the buffer
4349 * @size: The length of the buffer
4350 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4351 * returns #GST_FLOW_ERROR if %NULL.
4353 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4354 * immediately and @buffer is %NULL.
4356 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4357 * description of a getrange function. If @pad has no getrange function
4358 * installed (see gst_pad_set_getrange_function()) this function returns
4359 * #GST_FLOW_NOT_SUPPORTED.
4361 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4362 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4363 * must be freed with gst_buffer_unref() after usage.
4365 * When @buffer points to a variable that points to a valid #GstBuffer, the
4366 * buffer will be filled with the result data when this function returns
4367 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4368 * @size bytes will be filled in the result buffer and its size will be updated
4371 * Note that less than @size bytes can be returned in @buffer when, for example,
4372 * an EOS condition is near or when @buffer is not large enough to hold @size
4373 * bytes. The caller should check the result buffer size to get the result size.
4375 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4376 * will be unchanged.
4378 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4380 * Returns: a #GstFlowReturn from the pad.
4385 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4386 GstBuffer ** buffer)
4388 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4389 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4390 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4391 g_return_val_if_fail (*buffer == NULL
4392 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4394 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4398 * gst_pad_pull_range:
4399 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4400 * @offset: The start offset of the buffer
4401 * @size: The length of the buffer
4402 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4403 * GST_FLOW_ERROR if %NULL.
4405 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4407 * This function will first trigger the pad block signal if it was
4410 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4411 * function returns the result of gst_pad_get_range() on the peer pad.
4412 * See gst_pad_get_range() for a list of return values and for the
4413 * semantics of the arguments of this function.
4415 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4416 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4417 * must be freed with gst_buffer_unref() after usage. When this function
4418 * returns any other result value, @buffer will still point to NULL.
4420 * When @buffer points to a variable that points to a valid #GstBuffer, the
4421 * buffer will be filled with the result data when this function returns
4422 * #GST_FLOW_OK. When this function returns any other result value,
4423 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4424 * @size bytes will be filled in the result buffer and its size will be updated
4427 * Note that less than @size bytes can be returned in @buffer when, for example,
4428 * an EOS condition is near or when @buffer is not large enough to hold @size
4429 * bytes. The caller should check the result buffer size to get the result size.
4431 * Returns: a #GstFlowReturn from the peer pad.
4436 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4437 GstBuffer ** buffer)
4443 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4444 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4445 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4446 g_return_val_if_fail (*buffer == NULL
4447 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4449 GST_OBJECT_LOCK (pad);
4450 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4453 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4458 /* when one of the probes returns DROPPED, probe_stopped will be
4459 * called and we skip calling the peer getrange function. *buffer should then
4460 * contain a valid buffer */
4461 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4462 res_buf, offset, size, probe_stopped);
4464 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4467 gst_object_ref (peer);
4469 GST_OBJECT_UNLOCK (pad);
4471 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4473 gst_object_unref (peer);
4475 GST_OBJECT_LOCK (pad);
4477 if (pad->priv->using == 0) {
4478 /* pad is not active anymore, trigger idle callbacks */
4479 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4480 probe_stopped_unref, ret);
4483 if (G_UNLIKELY (ret != GST_FLOW_OK))
4484 goto pull_range_failed;
4487 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4488 res_buf, offset, size, probe_stopped_unref);
4490 GST_OBJECT_UNLOCK (pad);
4496 /* ERROR recovery here */
4499 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4500 "pullrange, but pad was flushing");
4501 GST_OBJECT_UNLOCK (pad);
4502 return GST_FLOW_FLUSHING;
4506 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4507 GST_DEBUG_PAD_NAME (pad));
4508 GST_OBJECT_UNLOCK (pad);
4509 return GST_FLOW_ERROR;
4513 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4514 gst_flow_get_name (ret));
4515 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4517 /* the probe filled the buffer and asks us to not forward to the peer
4518 * anymore, we continue with the post probes then */
4519 GST_DEBUG_OBJECT (pad, "handled buffer");
4523 /* no buffer, we are EOS then */
4524 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4528 GST_OBJECT_UNLOCK (pad);
4533 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4534 "pulling range, but it was not linked");
4535 GST_OBJECT_UNLOCK (pad);
4536 return GST_FLOW_NOT_LINKED;
4540 GST_OBJECT_UNLOCK (pad);
4541 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4542 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4543 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4546 probe_stopped_unref:
4548 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4549 "post probe returned %s", gst_flow_get_name (ret));
4550 GST_OBJECT_UNLOCK (pad);
4551 /* if we drop here, it signals EOS */
4552 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4554 if (*buffer == NULL)
4555 gst_buffer_unref (res_buf);
4560 /* must be called with pad object lock */
4561 static GstFlowReturn
4562 store_sticky_event (GstPad * pad, GstEvent * event)
4567 gboolean res = FALSE;
4568 const gchar *name = NULL;
4569 gboolean insert = TRUE;
4571 type = GST_EVENT_TYPE (event);
4573 /* Store all sticky events except SEGMENT/EOS when we're flushing,
4574 * otherwise they can be dropped and nothing would ever resend them.
4575 * Only do that for activated pads though, everything else is a bug!
4577 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4578 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4579 || type == GST_EVENT_EOS))))
4582 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4585 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4586 name = gst_structure_get_name (gst_event_get_structure (event));
4588 events = pad->priv->events;
4591 for (i = 0; i < len; i++) {
4592 PadEvent *ev = &g_array_index (events, PadEvent, i);
4594 if (ev->event == NULL)
4597 if (type == GST_EVENT_TYPE (ev->event)) {
4598 /* matching types, check matching name if needed */
4599 if (name && !gst_event_has_name (ev->event, name))
4603 if ((res = gst_event_replace (&ev->event, event)))
4604 ev->received = FALSE;
4610 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4611 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4612 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4613 * storing the sticky ordered we can check that this is respected. */
4614 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4615 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4617 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4618 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4619 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4620 gst_event_type_get_name (type));
4626 ev.event = gst_event_ref (event);
4627 ev.received = FALSE;
4628 g_array_insert_val (events, i, ev);
4633 pad->priv->events_cookie++;
4634 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4636 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4638 switch (GST_EVENT_TYPE (event)) {
4639 case GST_EVENT_CAPS:
4640 GST_OBJECT_UNLOCK (pad);
4642 GST_DEBUG_OBJECT (pad, "notify caps");
4643 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4645 GST_OBJECT_LOCK (pad);
4651 if (type == GST_EVENT_EOS)
4652 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4654 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4659 GST_DEBUG_OBJECT (pad, "pad is flushing");
4660 return GST_FLOW_FLUSHING;
4664 GST_DEBUG_OBJECT (pad, "pad is EOS");
4665 return GST_FLOW_EOS;
4670 * gst_pad_store_sticky_event:
4672 * @event: a #GstEvent
4674 * Store the sticky @event on @pad
4676 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4677 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4682 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4686 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4687 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4689 GST_OBJECT_LOCK (pad);
4690 ret = store_sticky_event (pad, event);
4691 GST_OBJECT_UNLOCK (pad);
4697 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
4699 PushStickyData *data = user_data;
4701 /* Forward all sticky events before our current one that are pending */
4702 if (ev->event != data->event
4703 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
4704 return push_sticky (pad, ev, data);
4709 /* should be called with pad LOCK */
4710 static GstFlowReturn
4711 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4712 GstPadProbeType type)
4716 GstEventType event_type;
4718 /* pass the adjusted event on. We need to do this even if
4719 * there is no peer pad because of the probes. */
4720 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
4722 /* Two checks to be made:
4723 * . (un)set the FLUSHING flag for flushing events,
4724 * . handle pad blocking */
4725 event_type = GST_EVENT_TYPE (event);
4726 switch (event_type) {
4727 case GST_EVENT_FLUSH_START:
4728 GST_PAD_SET_FLUSHING (pad);
4730 GST_PAD_BLOCK_BROADCAST (pad);
4731 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4733 case GST_EVENT_FLUSH_STOP:
4734 GST_PAD_UNSET_FLUSHING (pad);
4736 /* Remove sticky EOS events */
4737 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4738 remove_event_by_type (pad, GST_EVENT_EOS);
4739 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4740 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4742 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4746 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4749 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4750 * checked already or this is called as part of pushing sticky events,
4751 * in which case we still want to forward the EOS event downstream.
4754 switch (GST_EVENT_TYPE (event)) {
4755 case GST_EVENT_RECONFIGURE:
4756 if (GST_PAD_IS_SINK (pad))
4757 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4762 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4763 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4768 /* send probes after modifying the events above */
4769 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4771 /* recheck sticky events because the probe might have cause a relink */
4772 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
4773 && (GST_EVENT_IS_SERIALIZED (event)
4774 || GST_EVENT_IS_STICKY (event))) {
4775 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4776 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4778 /* Push all sticky events before our current one
4779 * that have changed */
4780 events_foreach (pad, sticky_changed, &data);
4783 /* now check the peer pad */
4784 peerpad = GST_PAD_PEER (pad);
4785 if (peerpad == NULL)
4788 gst_object_ref (peerpad);
4790 GST_OBJECT_UNLOCK (pad);
4792 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4793 event, gst_event_type_get_name (event_type), peerpad);
4795 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4797 /* Note: we gave away ownership of the event at this point but we can still
4798 * print the old pointer */
4799 GST_LOG_OBJECT (pad,
4800 "sent event %p to (%s) peerpad %" GST_PTR_FORMAT ", ret %s", event,
4801 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
4803 gst_object_unref (peerpad);
4805 GST_OBJECT_LOCK (pad);
4807 if (pad->priv->using == 0) {
4808 /* pad is not active anymore, trigger idle callbacks */
4809 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4810 idle_probe_stopped, ret);
4814 /* ERROR handling */
4817 GST_DEBUG_OBJECT (pad, "We're flushing");
4818 gst_event_unref (event);
4819 return GST_FLOW_FLUSHING;
4823 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4824 gst_event_unref (event);
4827 case GST_FLOW_CUSTOM_SUCCESS:
4828 GST_DEBUG_OBJECT (pad, "dropped event");
4831 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4838 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
4839 gst_event_type_get_name (GST_EVENT_TYPE (event)));
4840 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4841 gst_event_unref (event);
4843 /* unlinked pads should not influence latency configuration */
4844 if (event_type == GST_EVENT_LATENCY)
4847 return GST_FLOW_NOT_LINKED;
4851 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4857 * gst_pad_push_event:
4858 * @pad: a #GstPad to push the event to.
4859 * @event: (transfer full): the #GstEvent to send to the pad.
4861 * Sends the event to the peer of the given pad. This function is
4862 * mainly used by elements to send events to their peer
4865 * This function takes ownership of the provided event so you should
4866 * gst_event_ref() it if you want to reuse the event after this call.
4868 * Returns: TRUE if the event was handled.
4873 gst_pad_push_event (GstPad * pad, GstEvent * event)
4875 gboolean res = FALSE;
4876 GstPadProbeType type;
4877 gboolean sticky, serialized;
4879 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4880 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4882 if (GST_PAD_IS_SRC (pad)) {
4883 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4884 goto wrong_direction;
4885 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4886 } else if (GST_PAD_IS_SINK (pad)) {
4887 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4888 goto wrong_direction;
4889 /* events pushed on sinkpad never are sticky */
4890 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4892 goto unknown_direction;
4894 GST_OBJECT_LOCK (pad);
4895 sticky = GST_EVENT_IS_STICKY (event);
4896 serialized = GST_EVENT_IS_SERIALIZED (event);
4899 /* srcpad sticky events are stored immediately, the received flag is set
4900 * to FALSE and will be set to TRUE when we can successfully push the
4901 * event to the peer pad */
4902 switch (store_sticky_event (pad, event)) {
4903 case GST_FLOW_FLUSHING:
4911 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4912 /* all serialized or sticky events on the srcpad trigger push of
4914 res = (check_sticky (pad, event) == GST_FLOW_OK);
4919 /* other events are pushed right away */
4920 ret = gst_pad_push_event_unchecked (pad, event, type);
4921 /* dropped events by a probe are not an error */
4922 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4924 /* Errors in sticky event pushing are no problem and ignored here
4925 * as they will cause more meaningful errors during data flow.
4926 * For EOS events, that are not followed by data flow, we still
4927 * return FALSE here though.
4929 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4931 gst_event_unref (event);
4933 GST_OBJECT_UNLOCK (pad);
4937 /* ERROR handling */
4940 g_warning ("pad %s:%s pushing %s event in wrong direction",
4941 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4942 gst_event_unref (event);
4947 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4948 gst_event_unref (event);
4953 GST_DEBUG_OBJECT (pad, "We're flushing");
4954 GST_OBJECT_UNLOCK (pad);
4955 gst_event_unref (event);
4960 GST_DEBUG_OBJECT (pad, "We're EOS");
4961 GST_OBJECT_UNLOCK (pad);
4962 gst_event_unref (event);
4967 /* Check if we can call the event function with the given event */
4968 static GstFlowReturn
4969 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4973 switch (GST_EVENT_TYPE (event)) {
4974 case GST_EVENT_CAPS:
4976 /* backwards compatibility mode for caps */
4977 gst_event_parse_caps (event, &caps);
4979 if (!gst_pad_query_accept_caps (pad, caps))
4991 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4992 "caps %" GST_PTR_FORMAT " not accepted", caps);
4993 return GST_FLOW_NOT_NEGOTIATED;
4997 static GstFlowReturn
4998 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4999 GstPadProbeType type)
5002 GstEventType event_type;
5003 gboolean serialized, need_unlock = FALSE, sticky;
5004 GstPadEventFunction eventfunc;
5007 GST_OBJECT_LOCK (pad);
5009 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5011 if (GST_PAD_IS_SINK (pad))
5012 serialized = GST_EVENT_IS_SERIALIZED (event);
5015 sticky = GST_EVENT_IS_STICKY (event);
5016 event_type = GST_EVENT_TYPE (event);
5017 switch (event_type) {
5018 case GST_EVENT_FLUSH_START:
5019 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5020 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5022 /* can't even accept a flush begin event when flushing */
5023 if (GST_PAD_IS_FLUSHING (pad))
5026 GST_PAD_SET_FLUSHING (pad);
5027 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5029 case GST_EVENT_FLUSH_STOP:
5030 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
5031 GST_PAD_UNSET_FLUSHING (pad);
5032 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5034 /* Remove pending EOS events */
5035 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5036 remove_event_by_type (pad, GST_EVENT_EOS);
5037 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5038 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5040 GST_OBJECT_UNLOCK (pad);
5041 /* grab stream lock */
5042 GST_PAD_STREAM_LOCK (pad);
5044 GST_OBJECT_LOCK (pad);
5045 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5048 case GST_EVENT_RECONFIGURE:
5049 if (GST_PAD_IS_SRC (pad))
5050 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5052 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5053 "have event type %" GST_PTR_FORMAT, event);
5055 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5059 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5062 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5063 GST_OBJECT_UNLOCK (pad);
5064 GST_PAD_STREAM_LOCK (pad);
5066 GST_OBJECT_LOCK (pad);
5067 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5070 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5076 /* now do the probe */
5078 type | GST_PAD_PROBE_TYPE_PUSH |
5079 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5081 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5083 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5086 ACQUIRE_PARENT (pad, parent, no_parent);
5087 GST_OBJECT_UNLOCK (pad);
5089 ret = pre_eventfunc_check (pad, event);
5090 if (G_UNLIKELY (ret != GST_FLOW_OK))
5091 goto precheck_failed;
5094 gst_event_ref (event);
5096 if (eventfunc (pad, parent, event)) {
5099 /* something went wrong */
5100 switch (event_type) {
5101 case GST_EVENT_CAPS:
5102 ret = GST_FLOW_NOT_NEGOTIATED;
5105 ret = GST_FLOW_ERROR;
5109 RELEASE_PARENT (parent);
5111 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5114 if (ret == GST_FLOW_OK) {
5115 GST_OBJECT_LOCK (pad);
5116 /* after the event function accepted the event, we can store the sticky
5117 * event on the pad */
5118 switch (store_sticky_event (pad, event)) {
5119 case GST_FLOW_FLUSHING:
5126 GST_OBJECT_UNLOCK (pad);
5128 gst_event_unref (event);
5132 GST_PAD_STREAM_UNLOCK (pad);
5136 /* ERROR handling */
5139 GST_OBJECT_UNLOCK (pad);
5141 GST_PAD_STREAM_UNLOCK (pad);
5142 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5143 "Received event on flushing pad. Discarding");
5144 gst_event_unref (event);
5145 return GST_FLOW_FLUSHING;
5149 GST_OBJECT_UNLOCK (pad);
5151 GST_PAD_STREAM_UNLOCK (pad);
5152 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5153 "Received event on EOS pad. Discarding");
5154 gst_event_unref (event);
5155 return GST_FLOW_EOS;
5159 GST_OBJECT_UNLOCK (pad);
5161 GST_PAD_STREAM_UNLOCK (pad);
5162 gst_event_unref (event);
5165 case GST_FLOW_CUSTOM_SUCCESS:
5166 GST_DEBUG_OBJECT (pad, "dropped event");
5170 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5177 g_warning ("pad %s:%s has no event handler, file a bug.",
5178 GST_DEBUG_PAD_NAME (pad));
5179 GST_OBJECT_UNLOCK (pad);
5181 GST_PAD_STREAM_UNLOCK (pad);
5182 gst_event_unref (event);
5183 return GST_FLOW_NOT_SUPPORTED;
5187 GST_DEBUG_OBJECT (pad, "no parent");
5188 GST_OBJECT_UNLOCK (pad);
5190 GST_PAD_STREAM_UNLOCK (pad);
5191 gst_event_unref (event);
5192 return GST_FLOW_FLUSHING;
5196 GST_DEBUG_OBJECT (pad, "pre event check failed");
5197 RELEASE_PARENT (parent);
5199 GST_PAD_STREAM_UNLOCK (pad);
5200 gst_event_unref (event);
5206 * gst_pad_send_event:
5207 * @pad: a #GstPad to send the event to.
5208 * @event: (transfer full): the #GstEvent to send to the pad.
5210 * Sends the event to the pad. This function can be used
5211 * by applications to send events in the pipeline.
5213 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5214 * sink pad, @event should be a downstream event. For example, you would not
5215 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5216 * Furthermore, some downstream events have to be serialized with data flow,
5217 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5218 * the event needs to be serialized with data flow, this function will take the
5219 * pad's stream lock while calling its event function.
5221 * To find out whether an event type is upstream, downstream, or downstream and
5222 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5223 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5224 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5225 * plugin doesn't need to bother itself with this information; the core handles
5226 * all necessary locks and checks.
5228 * This function takes ownership of the provided event so you should
5229 * gst_event_ref() it if you want to reuse the event after this call.
5231 * Returns: TRUE if the event was handled.
5234 gst_pad_send_event (GstPad * pad, GstEvent * event)
5237 GstPadProbeType type;
5239 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5240 g_return_val_if_fail (event != NULL, FALSE);
5242 if (GST_PAD_IS_SINK (pad)) {
5243 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5244 goto wrong_direction;
5245 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5246 } else if (GST_PAD_IS_SRC (pad)) {
5247 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5248 goto wrong_direction;
5249 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5251 goto unknown_direction;
5253 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5260 /* ERROR handling */
5263 g_warning ("pad %s:%s sending %s event in wrong direction",
5264 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5265 gst_event_unref (event);
5270 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5271 gst_event_unref (event);
5277 * gst_pad_set_element_private:
5278 * @pad: the #GstPad to set the private data of.
5279 * @priv: The private data to attach to the pad.
5281 * Set the given private data gpointer on the pad.
5282 * This function can only be used by the element that owns the pad.
5283 * No locking is performed in this function.
5286 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5288 pad->element_private = priv;
5292 * gst_pad_get_element_private:
5293 * @pad: the #GstPad to get the private data of.
5295 * Gets the private data of a pad.
5296 * No locking is performed in this function.
5298 * Returns: (transfer none): a #gpointer to the private data.
5301 gst_pad_get_element_private (GstPad * pad)
5303 return pad->element_private;
5307 * gst_pad_get_sticky_event:
5308 * @pad: the #GstPad to get the event from.
5309 * @event_type: the #GstEventType that should be retrieved.
5310 * @idx: the index of the event
5312 * Returns a new reference of the sticky event of type @event_type
5315 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
5316 * event of @event_type was on @pad. Unref after usage.
5319 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5321 GstEvent *event = NULL;
5324 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5325 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5327 GST_OBJECT_LOCK (pad);
5328 ev = find_event_by_type (pad, event_type, idx);
5329 if (ev && (event = ev->event))
5330 gst_event_ref (event);
5331 GST_OBJECT_UNLOCK (pad);
5338 GstPadStickyEventsForeachFunction func;
5343 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5345 ForeachDispatch *data = user_data;
5346 gboolean ret = TRUE;
5349 GST_OBJECT_UNLOCK (pad);
5351 ret = data->func (pad, &ev->event, data->user_data);
5353 GST_OBJECT_LOCK (pad);
5360 * gst_pad_sticky_events_foreach:
5361 * @pad: the #GstPad that should be used for iteration.
5362 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5363 * should be called for every event.
5364 * @user_data: (closure): the optional user data.
5366 * Iterates all sticky events on @pad and calls @foreach_func for every
5367 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5370 gst_pad_sticky_events_foreach (GstPad * pad,
5371 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5373 ForeachDispatch data;
5375 g_return_if_fail (GST_IS_PAD (pad));
5376 g_return_if_fail (foreach_func != NULL);
5378 data.func = foreach_func;
5379 data.user_data = user_data;
5381 GST_OBJECT_LOCK (pad);
5382 events_foreach (pad, foreach_dispatch_function, &data);
5383 GST_OBJECT_UNLOCK (pad);
5387 do_stream_status (GstPad * pad, GstStreamStatusType type,
5388 GThread * thread, GstTask * task)
5392 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5394 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5395 if (GST_IS_ELEMENT (parent)) {
5396 GstMessage *message;
5397 GValue value = { 0 };
5399 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5400 gchar *tname, *ename, *pname;
5402 /* create a good task name */
5403 ename = gst_element_get_name (parent);
5404 pname = gst_pad_get_name (pad);
5405 tname = g_strdup_printf ("%s:%s", ename, pname);
5409 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5413 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5416 g_value_init (&value, GST_TYPE_TASK);
5417 g_value_set_object (&value, task);
5418 gst_message_set_stream_status_object (message, &value);
5419 g_value_unset (&value);
5421 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5422 gst_element_post_message (parent, message);
5424 gst_object_unref (parent);
5429 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5431 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5436 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5438 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5443 * gst_pad_start_task:
5444 * @pad: the #GstPad to start the task of
5445 * @func: the task function to call
5446 * @user_data: user data passed to the task function
5447 * @notify: called when @user_data is no longer referenced
5449 * Starts a task that repeatedly calls @func with @user_data. This function
5450 * is mostly used in pad activation functions to start the dataflow.
5451 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5452 * before @func is called.
5454 * Returns: a %TRUE if the task could be started.
5457 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5458 GDestroyNotify notify)
5463 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5464 g_return_val_if_fail (func != NULL, FALSE);
5466 GST_DEBUG_OBJECT (pad, "start task");
5468 GST_OBJECT_LOCK (pad);
5469 task = GST_PAD_TASK (pad);
5471 task = gst_task_new (func, user_data, notify);
5472 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5473 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5474 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5475 GST_INFO_OBJECT (pad, "created task %p", task);
5476 GST_PAD_TASK (pad) = task;
5477 gst_object_ref (task);
5478 /* release lock to post the message */
5479 GST_OBJECT_UNLOCK (pad);
5481 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5483 gst_object_unref (task);
5485 GST_OBJECT_LOCK (pad);
5486 /* nobody else is supposed to have changed the pad now */
5487 if (GST_PAD_TASK (pad) != task)
5488 goto concurrent_stop;
5490 res = gst_task_set_state (task, GST_TASK_STARTED);
5491 GST_OBJECT_UNLOCK (pad);
5498 GST_OBJECT_UNLOCK (pad);
5504 * gst_pad_pause_task:
5505 * @pad: the #GstPad to pause the task of
5507 * Pause the task of @pad. This function will also wait until the
5508 * function executed by the task is finished if this function is not
5509 * called from the task function.
5511 * Returns: a TRUE if the task could be paused or FALSE when the pad
5515 gst_pad_pause_task (GstPad * pad)
5520 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5522 GST_DEBUG_OBJECT (pad, "pause task");
5524 GST_OBJECT_LOCK (pad);
5525 task = GST_PAD_TASK (pad);
5528 res = gst_task_set_state (task, GST_TASK_PAUSED);
5529 GST_OBJECT_UNLOCK (pad);
5531 /* wait for task function to finish, this lock is recursive so it does nothing
5532 * when the pause is called from the task itself */
5533 GST_PAD_STREAM_LOCK (pad);
5534 GST_PAD_STREAM_UNLOCK (pad);
5540 GST_DEBUG_OBJECT (pad, "pad has no task");
5541 GST_OBJECT_UNLOCK (pad);
5547 * gst_pad_stop_task:
5548 * @pad: the #GstPad to stop the task of
5550 * Stop the task of @pad. This function will also make sure that the
5551 * function executed by the task will effectively stop if not called
5552 * from the GstTaskFunction.
5554 * This function will deadlock if called from the GstTaskFunction of
5555 * the task. Use gst_task_pause() instead.
5557 * Regardless of whether the pad has a task, the stream lock is acquired and
5558 * released so as to ensure that streaming through this pad has finished.
5560 * Returns: a TRUE if the task could be stopped or FALSE on error.
5563 gst_pad_stop_task (GstPad * pad)
5568 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5570 GST_DEBUG_OBJECT (pad, "stop task");
5572 GST_OBJECT_LOCK (pad);
5573 task = GST_PAD_TASK (pad);
5576 GST_PAD_TASK (pad) = NULL;
5577 res = gst_task_set_state (task, GST_TASK_STOPPED);
5578 GST_OBJECT_UNLOCK (pad);
5580 GST_PAD_STREAM_LOCK (pad);
5581 GST_PAD_STREAM_UNLOCK (pad);
5583 if (!gst_task_join (task))
5586 gst_object_unref (task);
5592 GST_DEBUG_OBJECT (pad, "no task");
5593 GST_OBJECT_UNLOCK (pad);
5595 GST_PAD_STREAM_LOCK (pad);
5596 GST_PAD_STREAM_UNLOCK (pad);
5598 /* this is not an error */
5603 /* this is bad, possibly the application tried to join the task from
5604 * the task's thread. We install the task again so that it will be stopped
5605 * again from the right thread next time hopefully. */
5606 GST_OBJECT_LOCK (pad);
5607 GST_DEBUG_OBJECT (pad, "join failed");
5608 /* we can only install this task if there was no other task */
5609 if (GST_PAD_TASK (pad) == NULL)
5610 GST_PAD_TASK (pad) = task;
5611 GST_OBJECT_UNLOCK (pad);
5618 * gst_pad_probe_info_get_event:
5619 * @info: a #GstPadProbeInfo
5621 * Returns: (transfer none): The #GstEvent from the probe
5625 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5627 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5628 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5630 return GST_PAD_PROBE_INFO_EVENT (info);
5635 * gst_pad_probe_info_get_query:
5636 * @info: a #GstPadProbeInfo
5638 * Returns: (transfer none): The #GstQuery from the probe
5642 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5644 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5645 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5647 return GST_PAD_PROBE_INFO_QUERY (info);
5651 * gst_pad_probe_info_get_buffer:
5652 * @info: a #GstPadProbeInfo
5654 * Returns: (transfer none): The #GstBuffer from the probe
5658 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5660 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5662 return GST_PAD_PROBE_INFO_BUFFER (info);
5666 * gst_pad_probe_info_get_bufferlist:
5667 * @info: a #GstPadProbeInfo
5669 * Returns: (transfer none): The #GstBufferlist from the probe
5673 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5675 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5677 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);