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)
606 /* check if we need to adjust the segment */
607 if (pad->offset != 0) {
610 /* copy segment values */
611 gst_event_copy_segment (event, &segment);
612 gst_event_unref (event);
614 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_TIME_FORMAT,
615 GST_TIME_ARGS (pad->offset));
616 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
617 event = gst_event_new_segment (&segment);
622 /* should be called with the OBJECT_LOCK */
624 get_pad_caps (GstPad * pad)
626 GstCaps *caps = NULL;
629 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
631 gst_event_parse_caps (ev->event, &caps);
637 gst_pad_dispose (GObject * object)
639 GstPad *pad = GST_PAD_CAST (object);
642 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
644 /* unlink the peer pad */
645 if ((peer = gst_pad_get_peer (pad))) {
646 /* window for MT unsafeness, someone else could unlink here
647 * and then we call unlink with wrong pads. The unlink
648 * function would catch this and safely return failed. */
649 if (GST_PAD_IS_SRC (pad))
650 gst_pad_unlink (pad, peer);
652 gst_pad_unlink (peer, pad);
654 gst_object_unref (peer);
657 gst_pad_set_pad_template (pad, NULL);
659 GST_OBJECT_LOCK (pad);
661 GST_OBJECT_UNLOCK (pad);
663 g_hook_list_clear (&pad->probes);
665 G_OBJECT_CLASS (parent_class)->dispose (object);
669 gst_pad_finalize (GObject * object)
671 GstPad *pad = GST_PAD_CAST (object);
674 /* in case the task is still around, clean it up */
675 if ((task = GST_PAD_TASK (pad))) {
676 gst_task_join (task);
677 GST_PAD_TASK (pad) = NULL;
678 gst_object_unref (task);
681 if (pad->activatenotify)
682 pad->activatenotify (pad->activatedata);
683 if (pad->activatemodenotify)
684 pad->activatemodenotify (pad->activatemodedata);
686 pad->linknotify (pad->linkdata);
687 if (pad->unlinknotify)
688 pad->unlinknotify (pad->unlinkdata);
689 if (pad->chainnotify)
690 pad->chainnotify (pad->chaindata);
691 if (pad->chainlistnotify)
692 pad->chainlistnotify (pad->chainlistdata);
693 if (pad->getrangenotify)
694 pad->getrangenotify (pad->getrangedata);
695 if (pad->eventnotify)
696 pad->eventnotify (pad->eventdata);
697 if (pad->querynotify)
698 pad->querynotify (pad->querydata);
699 if (pad->iterintlinknotify)
700 pad->iterintlinknotify (pad->iterintlinkdata);
702 g_rec_mutex_clear (&pad->stream_rec_lock);
703 g_cond_clear (&pad->block_cond);
704 g_array_free (pad->priv->events, TRUE);
706 G_OBJECT_CLASS (parent_class)->finalize (object);
710 gst_pad_set_property (GObject * object, guint prop_id,
711 const GValue * value, GParamSpec * pspec)
713 g_return_if_fail (GST_IS_PAD (object));
716 case PAD_PROP_DIRECTION:
717 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
719 case PAD_PROP_TEMPLATE:
720 gst_pad_set_pad_template (GST_PAD_CAST (object),
721 (GstPadTemplate *) g_value_get_object (value));
724 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
730 gst_pad_get_property (GObject * object, guint prop_id,
731 GValue * value, GParamSpec * pspec)
733 g_return_if_fail (GST_IS_PAD (object));
737 GST_OBJECT_LOCK (object);
738 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
739 GST_OBJECT_UNLOCK (object);
741 case PAD_PROP_DIRECTION:
742 g_value_set_enum (value, GST_PAD_DIRECTION (object));
744 case PAD_PROP_TEMPLATE:
745 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
748 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
755 * @name: the name of the new pad.
756 * @direction: the #GstPadDirection of the pad.
758 * Creates a new pad with the given name in the given direction.
759 * If name is NULL, a guaranteed unique name (across all pads)
761 * This function makes a copy of the name so you can safely free the name.
763 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
768 gst_pad_new (const gchar * name, GstPadDirection direction)
770 return g_object_new (GST_TYPE_PAD,
771 "name", name, "direction", direction, NULL);
775 * gst_pad_new_from_template:
776 * @templ: the pad template to use
777 * @name: the name of the element
779 * Creates a new pad with the given name from the given template.
780 * If name is NULL, a guaranteed unique name (across all pads)
782 * This function makes a copy of the name so you can safely free the name.
784 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
787 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
789 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
791 return g_object_new (GST_TYPE_PAD,
792 "name", name, "direction", templ->direction, "template", templ, NULL);
796 * gst_pad_new_from_static_template:
797 * @templ: the #GstStaticPadTemplate to use
798 * @name: the name of the element
800 * Creates a new pad with the given name from the given static template.
801 * If name is NULL, a guaranteed unique name (across all pads)
803 * This function makes a copy of the name so you can safely free the name.
805 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
808 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
812 GstPadTemplate *template;
814 template = gst_static_pad_template_get (templ);
815 pad = gst_pad_new_from_template (template, name);
816 gst_object_unref (template);
820 #define ACQUIRE_PARENT(pad, parent, label) \
822 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
823 gst_object_ref (parent); \
824 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
828 #define RELEASE_PARENT(parent) \
830 if (G_LIKELY (parent)) \
831 gst_object_unref (parent); \
835 * gst_pad_get_direction:
836 * @pad: a #GstPad to get the direction of.
838 * Gets the direction of the pad. The direction of the pad is
839 * decided at construction time so this function does not take
842 * Returns: the #GstPadDirection of the pad.
847 gst_pad_get_direction (GstPad * pad)
849 GstPadDirection result;
851 /* PAD_UNKNOWN is a little silly but we need some sort of
852 * error return value */
853 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
855 result = GST_PAD_DIRECTION (pad);
861 gst_pad_activate_default (GstPad * pad, GstObject * parent)
863 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
867 * gst_pad_mode_get_name:
868 * @mode: the pad mode
870 * Return the name of a pad mode, for use in debug messages mostly.
872 * Returns: short mnemonic for pad mode @mode
875 gst_pad_mode_get_name (GstPadMode mode)
878 case GST_PAD_MODE_NONE:
880 case GST_PAD_MODE_PUSH:
882 case GST_PAD_MODE_PULL:
891 pre_activate (GstPad * pad, GstPadMode new_mode)
894 case GST_PAD_MODE_NONE:
895 GST_OBJECT_LOCK (pad);
896 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
897 GST_PAD_SET_FLUSHING (pad);
898 GST_PAD_MODE (pad) = new_mode;
899 /* unlock blocked pads so element can resume and stop */
900 GST_PAD_BLOCK_BROADCAST (pad);
901 GST_OBJECT_UNLOCK (pad);
903 case GST_PAD_MODE_PUSH:
904 case GST_PAD_MODE_PULL:
905 GST_OBJECT_LOCK (pad);
906 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
907 gst_pad_mode_get_name (new_mode));
908 GST_PAD_UNSET_FLUSHING (pad);
909 GST_PAD_MODE (pad) = new_mode;
910 if (GST_PAD_IS_SINK (pad)) {
912 /* make sure the peer src pad sends us all events */
913 if ((peer = GST_PAD_PEER (pad))) {
914 gst_object_ref (peer);
915 GST_OBJECT_UNLOCK (pad);
917 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
918 GST_DEBUG_PAD_NAME (peer));
920 GST_OBJECT_LOCK (peer);
921 schedule_events (peer, NULL);
922 GST_OBJECT_UNLOCK (peer);
924 gst_object_unref (peer);
926 GST_OBJECT_UNLOCK (pad);
929 GST_OBJECT_UNLOCK (pad);
936 post_activate (GstPad * pad, GstPadMode new_mode)
939 case GST_PAD_MODE_NONE:
940 /* ensures that streaming stops */
941 GST_PAD_STREAM_LOCK (pad);
942 GST_DEBUG_OBJECT (pad, "stopped streaming");
943 GST_OBJECT_LOCK (pad);
945 GST_OBJECT_UNLOCK (pad);
946 GST_PAD_STREAM_UNLOCK (pad);
948 case GST_PAD_MODE_PUSH:
949 case GST_PAD_MODE_PULL:
956 * gst_pad_set_active:
957 * @pad: the #GstPad to activate or deactivate.
958 * @active: whether or not the pad should be active.
960 * Activates or deactivates the given pad.
961 * Normally called from within core state change functions.
963 * If @active, makes sure the pad is active. If it is already active, either in
964 * push or pull mode, just return. Otherwise dispatches to the pad's activate
965 * function to perform the actual activation.
967 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
968 * and a FALSE argument.
970 * Returns: #TRUE if the operation was successful.
975 gst_pad_set_active (GstPad * pad, gboolean active)
979 gboolean ret = FALSE;
981 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
983 GST_OBJECT_LOCK (pad);
984 old = GST_PAD_MODE (pad);
985 ACQUIRE_PARENT (pad, parent, no_parent);
986 GST_OBJECT_UNLOCK (pad);
989 if (old == GST_PAD_MODE_NONE) {
990 GST_DEBUG_OBJECT (pad, "activating pad from none");
991 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
993 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
994 gst_pad_mode_get_name (old));
998 if (old == GST_PAD_MODE_NONE) {
999 GST_DEBUG_OBJECT (pad, "pad was inactive");
1002 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1003 gst_pad_mode_get_name (old));
1004 ret = gst_pad_activate_mode (pad, old, FALSE);
1008 RELEASE_PARENT (parent);
1010 if (G_UNLIKELY (!ret))
1018 GST_DEBUG_OBJECT (pad, "no parent");
1019 GST_OBJECT_UNLOCK (pad);
1024 GST_OBJECT_LOCK (pad);
1026 g_critical ("Failed to deactivate pad %s:%s, very bad",
1027 GST_DEBUG_PAD_NAME (pad));
1029 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1031 GST_OBJECT_UNLOCK (pad);
1037 * gst_pad_activate_mode:
1038 * @pad: the #GstPad to activate or deactivate.
1039 * @mode: the requested activation mode
1040 * @active: whether or not the pad should be active.
1042 * Activates or deactivates the given pad in @mode via dispatching to the
1043 * pad's activatemodefunc. For use from within pad activation functions only.
1045 * If you don't know what this is, you probably don't want to call it.
1047 * Returns: TRUE if the operation was successful.
1052 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1054 gboolean res = FALSE;
1056 GstPadMode old, new;
1057 GstPadDirection dir;
1060 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1062 GST_OBJECT_LOCK (pad);
1063 old = GST_PAD_MODE (pad);
1064 dir = GST_PAD_DIRECTION (pad);
1065 ACQUIRE_PARENT (pad, parent, no_parent);
1066 GST_OBJECT_UNLOCK (pad);
1068 new = active ? mode : GST_PAD_MODE_NONE;
1073 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1074 /* pad was activate in the wrong direction, deactivate it
1075 * and reactivate it in the requested mode */
1076 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1077 gst_pad_mode_get_name (old));
1079 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1080 goto deactivate_failed;
1084 case GST_PAD_MODE_PULL:
1086 if (dir == GST_PAD_SINK) {
1087 if ((peer = gst_pad_get_peer (pad))) {
1088 GST_DEBUG_OBJECT (pad, "calling peer");
1089 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1091 gst_object_unref (peer);
1093 /* there is no peer, this is only fatal when we activate. When we
1094 * deactivate, we must assume the application has unlinked the peer and
1095 * will deactivate it eventually. */
1099 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1102 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1103 goto failure; /* Can't activate pull on a src without a
1104 getrange function */
1112 /* Mark pad as needing reconfiguration */
1114 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1115 pre_activate (pad, new);
1117 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1118 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1122 /* can happen for sinks of passthrough elements */
1125 post_activate (pad, new);
1127 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1128 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1133 /* Clear sticky flags on deactivation */
1135 GST_OBJECT_LOCK (pad);
1136 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1137 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1138 GST_OBJECT_UNLOCK (pad);
1142 RELEASE_PARENT (parent);
1148 GST_DEBUG_OBJECT (pad, "no parent");
1149 GST_OBJECT_UNLOCK (pad);
1154 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1155 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1160 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1161 "failed to %s in switch to %s mode from %s mode",
1162 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1163 gst_pad_mode_get_name (old));
1168 GST_OBJECT_LOCK (peer);
1169 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1170 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1171 GST_OBJECT_UNLOCK (peer);
1172 gst_object_unref (peer);
1177 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1178 "pad in pull mode");
1183 GST_OBJECT_LOCK (pad);
1184 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1185 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1186 GST_PAD_SET_FLUSHING (pad);
1187 GST_PAD_MODE (pad) = old;
1188 GST_OBJECT_UNLOCK (pad);
1194 * gst_pad_is_active:
1195 * @pad: the #GstPad to query
1197 * Query if a pad is active
1199 * Returns: TRUE if the pad is active.
1204 gst_pad_is_active (GstPad * pad)
1206 gboolean result = FALSE;
1208 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1210 GST_OBJECT_LOCK (pad);
1211 result = GST_PAD_IS_ACTIVE (pad);
1212 GST_OBJECT_UNLOCK (pad);
1218 cleanup_hook (GstPad * pad, GHook * hook)
1220 GstPadProbeType type;
1222 if (!G_HOOK_IS_VALID (hook))
1225 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1227 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1228 /* unblock when we remove the last blocking probe */
1230 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1233 /* Might have new probes now that want to be called */
1234 GST_PAD_BLOCK_BROADCAST (pad);
1236 if (pad->num_blocked == 0) {
1237 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1238 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1241 g_hook_destroy_link (&pad->probes, hook);
1246 * gst_pad_add_probe:
1247 * @pad: the #GstPad to add the probe to
1248 * @mask: the probe mask
1249 * @callback: #GstPadProbeCallback that will be called with notifications of
1251 * @user_data: (closure): user data passed to the callback
1252 * @destroy_data: #GDestroyNotify for user_data
1254 * Be notified of different states of pads. The provided callback is called for
1255 * every state that matches @mask.
1257 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1258 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1259 * happend that the probe can be run immediately and if the probe returns
1260 * GST_PAD_PROBE_REMOVE this functions returns 0.
1265 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1266 GstPadProbeCallback callback, gpointer user_data,
1267 GDestroyNotify destroy_data)
1272 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1273 g_return_val_if_fail (mask != 0, 0);
1275 GST_OBJECT_LOCK (pad);
1277 /* make a new probe */
1278 hook = g_hook_alloc (&pad->probes);
1280 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1283 /* when no contraints are given for the types, assume all types are
1285 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1286 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1287 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1288 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1290 /* store our flags and other fields */
1291 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1292 hook->func = callback;
1293 hook->data = user_data;
1294 hook->destroy = destroy_data;
1295 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1298 g_hook_prepend (&pad->probes, hook);
1300 /* incremenent cookie so that the new hook get's called */
1301 pad->priv->probe_list_cookie++;
1303 /* get the id of the hook, we return this and it can be used to remove the
1305 res = hook->hook_id;
1307 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1309 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1310 /* we have a block probe */
1312 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1313 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1314 "now %d blocking probes", pad->num_blocked);
1316 /* Might have new probes now that want to be called */
1317 GST_PAD_BLOCK_BROADCAST (pad);
1320 /* call the callback if we need to be called for idle callbacks */
1321 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1322 if (pad->priv->using > 0) {
1323 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1324 * flag above, the last thread to leave the push will do the callback. New
1325 * threads going into the push will block. */
1326 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1327 "pad is in use, delay idle callback");
1328 GST_OBJECT_UNLOCK (pad);
1330 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1331 GstPadProbeReturn ret;
1333 /* Keep another ref, the callback could destroy the pad */
1334 gst_object_ref (pad);
1336 /* the pad is idle now, we can signal the idle callback now */
1337 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1338 "pad is idle, trigger idle callback");
1339 GST_OBJECT_UNLOCK (pad);
1341 ret = callback (pad, &info, user_data);
1343 GST_OBJECT_LOCK (pad);
1345 case GST_PAD_PROBE_REMOVE:
1346 /* remove the probe */
1347 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1348 cleanup_hook (pad, hook);
1351 case GST_PAD_PROBE_DROP:
1352 GST_DEBUG_OBJECT (pad, "asked to drop item");
1354 case GST_PAD_PROBE_PASS:
1355 GST_DEBUG_OBJECT (pad, "asked to pass item");
1357 case GST_PAD_PROBE_OK:
1358 GST_DEBUG_OBJECT (pad, "probe returned OK");
1361 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1364 GST_OBJECT_UNLOCK (pad);
1366 gst_object_unref (pad);
1369 GST_OBJECT_UNLOCK (pad);
1375 * gst_pad_remove_probe:
1376 * @pad: the #GstPad with the probe
1377 * @id: the probe id to remove
1379 * Remove the probe with @id from @pad.
1384 gst_pad_remove_probe (GstPad * pad, gulong id)
1388 g_return_if_fail (GST_IS_PAD (pad));
1390 GST_OBJECT_LOCK (pad);
1392 hook = g_hook_get (&pad->probes, id);
1396 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1398 cleanup_hook (pad, hook);
1399 GST_OBJECT_UNLOCK (pad);
1405 GST_OBJECT_UNLOCK (pad);
1406 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1412 * gst_pad_is_blocked:
1413 * @pad: the #GstPad to query
1415 * Checks if the pad is blocked or not. This function returns the
1416 * last requested state of the pad. It is not certain that the pad
1417 * is actually blocking at this point (see gst_pad_is_blocking()).
1419 * Returns: TRUE if the pad is blocked.
1424 gst_pad_is_blocked (GstPad * pad)
1426 gboolean result = FALSE;
1428 g_return_val_if_fail (GST_IS_PAD (pad), result);
1430 GST_OBJECT_LOCK (pad);
1431 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1432 GST_OBJECT_UNLOCK (pad);
1438 * gst_pad_is_blocking:
1439 * @pad: the #GstPad to query
1441 * Checks if the pad is blocking or not. This is a guaranteed state
1442 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1444 * Returns: TRUE if the pad is blocking.
1449 gst_pad_is_blocking (GstPad * pad)
1451 gboolean result = FALSE;
1453 g_return_val_if_fail (GST_IS_PAD (pad), result);
1455 GST_OBJECT_LOCK (pad);
1456 /* the blocking flag is only valid if the pad is not flushing */
1457 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1458 GST_OBJECT_UNLOCK (pad);
1464 * gst_pad_needs_reconfigure:
1465 * @pad: the #GstPad to check
1467 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1468 * if the flag was set.
1470 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1473 gst_pad_needs_reconfigure (GstPad * pad)
1475 gboolean reconfigure;
1477 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1479 GST_OBJECT_LOCK (pad);
1480 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1481 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1482 GST_OBJECT_UNLOCK (pad);
1488 * gst_pad_check_reconfigure:
1489 * @pad: the #GstPad to check
1491 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1492 * if the flag was set.
1494 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1497 gst_pad_check_reconfigure (GstPad * pad)
1499 gboolean reconfigure;
1501 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1503 GST_OBJECT_LOCK (pad);
1504 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1506 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1507 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1509 GST_OBJECT_UNLOCK (pad);
1515 * gst_pad_mark_reconfigure:
1516 * @pad: the #GstPad to mark
1518 * Mark a pad for needing reconfiguration. The next call to
1519 * gst_pad_check_reconfigure() will return %TRUE after this call.
1522 gst_pad_mark_reconfigure (GstPad * pad)
1524 g_return_if_fail (GST_IS_PAD (pad));
1526 GST_OBJECT_LOCK (pad);
1527 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1528 GST_OBJECT_UNLOCK (pad);
1532 * gst_pad_set_activate_function:
1534 * @f: the #GstPadActivateFunction to set.
1536 * Calls gst_pad_set_activate_function_full() with NULL for the user_data and
1540 * gst_pad_set_activate_function_full:
1542 * @activate: the #GstPadActivateFunction to set.
1543 * @user_data: user_data passed to @notify
1544 * @notify: notify called when @activate will not be used anymore.
1546 * Sets the given activate function for @pad. The activate function will
1547 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1548 * Only makes sense to set on sink pads.
1550 * Call this function if your sink pad can start a pull-based task.
1553 gst_pad_set_activate_function_full (GstPad * pad,
1554 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1556 g_return_if_fail (GST_IS_PAD (pad));
1558 if (pad->activatenotify)
1559 pad->activatenotify (pad->activatedata);
1560 GST_PAD_ACTIVATEFUNC (pad) = activate;
1561 pad->activatedata = user_data;
1562 pad->activatenotify = notify;
1564 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1565 GST_DEBUG_FUNCPTR_NAME (activate));
1569 * gst_pad_set_activatemode_function:
1571 * @f: the #GstPadActivateModeFunction to set.
1573 * Calls gst_pad_set_activatemode_function_full() with NULL for the user_data and
1577 * gst_pad_set_activatemode_function_full:
1579 * @activatemode: the #GstPadActivateModeFunction to set.
1580 * @user_data: user_data passed to @notify
1581 * @notify: notify called when @activatemode will not be used anymore.
1583 * Sets the given activate_mode function for the pad. An activate_mode function
1584 * prepares the element for data passing.
1587 gst_pad_set_activatemode_function_full (GstPad * pad,
1588 GstPadActivateModeFunction activatemode, gpointer user_data,
1589 GDestroyNotify notify)
1591 g_return_if_fail (GST_IS_PAD (pad));
1593 if (pad->activatemodenotify)
1594 pad->activatemodenotify (pad->activatemodedata);
1595 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1596 pad->activatemodedata = user_data;
1597 pad->activatemodenotify = notify;
1599 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1600 GST_DEBUG_FUNCPTR_NAME (activatemode));
1604 * gst_pad_set_chain_function:
1605 * @p: a sink #GstPad.
1606 * @f: the #GstPadChainFunction to set.
1608 * Calls gst_pad_set_chain_function_full() with NULL for the user_data and
1612 * gst_pad_set_chain_function_full:
1613 * @pad: a sink #GstPad.
1614 * @chain: the #GstPadChainFunction to set.
1615 * @user_data: user_data passed to @notify
1616 * @notify: notify called when @chain will not be used anymore.
1618 * Sets the given chain function for the pad. The chain function is called to
1619 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1622 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1623 gpointer user_data, GDestroyNotify notify)
1625 g_return_if_fail (GST_IS_PAD (pad));
1626 g_return_if_fail (GST_PAD_IS_SINK (pad));
1628 if (pad->chainnotify)
1629 pad->chainnotify (pad->chaindata);
1630 GST_PAD_CHAINFUNC (pad) = chain;
1631 pad->chaindata = user_data;
1632 pad->chainnotify = notify;
1634 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1635 GST_DEBUG_FUNCPTR_NAME (chain));
1639 * gst_pad_set_chain_list_function:
1640 * @p: a sink #GstPad.
1641 * @f: the #GstPadChainListFunction to set.
1643 * Calls gst_pad_set_chain_list_function_full() with NULL for the user_data and
1647 * gst_pad_set_chain_list_function_full:
1648 * @pad: a sink #GstPad.
1649 * @chainlist: the #GstPadChainListFunction to set.
1650 * @user_data: user_data passed to @notify
1651 * @notify: notify called when @chainlist will not be used anymore.
1653 * Sets the given chain list function for the pad. The chainlist function is
1654 * called to process a #GstBufferList input buffer list. See
1655 * #GstPadChainListFunction for more details.
1658 gst_pad_set_chain_list_function_full (GstPad * pad,
1659 GstPadChainListFunction chainlist, gpointer user_data,
1660 GDestroyNotify notify)
1662 g_return_if_fail (GST_IS_PAD (pad));
1663 g_return_if_fail (GST_PAD_IS_SINK (pad));
1665 if (pad->chainlistnotify)
1666 pad->chainlistnotify (pad->chainlistdata);
1667 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1668 pad->chainlistdata = user_data;
1669 pad->chainlistnotify = notify;
1671 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1672 GST_DEBUG_FUNCPTR_NAME (chainlist));
1676 * gst_pad_set_getrange_function:
1677 * @p: a source #GstPad.
1678 * @f: the #GstPadGetRangeFunction to set.
1680 * Calls gst_pad_set_getrange_function_full() with NULL for the user_data and
1684 * gst_pad_set_getrange_function_full:
1685 * @pad: a source #GstPad.
1686 * @get: the #GstPadGetRangeFunction to set.
1687 * @user_data: user_data passed to @notify
1688 * @notify: notify called when @get will not be used anymore.
1690 * Sets the given getrange function for the pad. The getrange function is
1691 * called to produce a new #GstBuffer to start the processing pipeline. see
1692 * #GstPadGetRangeFunction for a description of the getrange function.
1695 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1696 gpointer user_data, GDestroyNotify notify)
1698 g_return_if_fail (GST_IS_PAD (pad));
1699 g_return_if_fail (GST_PAD_IS_SRC (pad));
1701 if (pad->getrangenotify)
1702 pad->getrangenotify (pad->getrangedata);
1703 GST_PAD_GETRANGEFUNC (pad) = get;
1704 pad->getrangedata = user_data;
1705 pad->getrangenotify = notify;
1707 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1708 GST_DEBUG_FUNCPTR_NAME (get));
1712 * gst_pad_set_event_function:
1713 * @p: a #GstPad of either direction.
1714 * @f: the #GstPadEventFunction to set.
1716 * Calls gst_pad_set_event_function_full() with NULL for the user_data and
1720 * gst_pad_set_event_function_full:
1721 * @pad: a #GstPad of either direction.
1722 * @event: the #GstPadEventFunction to set.
1723 * @user_data: user_data passed to @notify
1724 * @notify: notify called when @event will not be used anymore.
1726 * Sets the given event handler for the pad.
1729 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1730 gpointer user_data, GDestroyNotify notify)
1732 g_return_if_fail (GST_IS_PAD (pad));
1734 if (pad->eventnotify)
1735 pad->eventnotify (pad->eventdata);
1736 GST_PAD_EVENTFUNC (pad) = event;
1737 pad->eventdata = user_data;
1738 pad->eventnotify = notify;
1740 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1741 GST_DEBUG_FUNCPTR_NAME (event));
1745 * gst_pad_set_query_function:
1746 * @p: a #GstPad of either direction.
1747 * @f: the #GstPadQueryFunction to set.
1749 * Calls gst_pad_set_query_function_full() with NULL for the user_data and
1753 * gst_pad_set_query_function_full:
1754 * @pad: a #GstPad of either direction.
1755 * @query: the #GstPadQueryFunction to set.
1756 * @user_data: user_data passed to @notify
1757 * @notify: notify called when @query will not be used anymore.
1759 * Set the given query function for the pad.
1762 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1763 gpointer user_data, GDestroyNotify notify)
1765 g_return_if_fail (GST_IS_PAD (pad));
1767 if (pad->querynotify)
1768 pad->querynotify (pad->querydata);
1769 GST_PAD_QUERYFUNC (pad) = query;
1770 pad->querydata = user_data;
1771 pad->querynotify = notify;
1773 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1774 GST_DEBUG_FUNCPTR_NAME (query));
1778 * gst_pad_set_iterate_internal_links_function:
1779 * @p: a #GstPad of either direction.
1780 * @f: the #GstPadIterIntLinkFunction to set.
1782 * Calls gst_pad_set_iterate_internal_links_function_full() with NULL
1783 * for the user_data and notify.
1786 * gst_pad_set_iterate_internal_links_function_full:
1787 * @pad: a #GstPad of either direction.
1788 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1789 * @user_data: user_data passed to @notify
1790 * @notify: notify called when @iterintlink will not be used anymore.
1792 * Sets the given internal link iterator function for the pad.
1795 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1796 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1797 GDestroyNotify notify)
1799 g_return_if_fail (GST_IS_PAD (pad));
1801 if (pad->iterintlinknotify)
1802 pad->iterintlinknotify (pad->iterintlinkdata);
1803 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1804 pad->iterintlinkdata = user_data;
1805 pad->iterintlinknotify = notify;
1807 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1808 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1812 * gst_pad_set_link_function:
1814 * @f: the #GstPadLinkFunction to set.
1816 * Calls gst_pad_set_link_function_full() with NULL
1817 * for the user_data and notify.
1820 * gst_pad_set_link_function_full:
1822 * @link: the #GstPadLinkFunction to set.
1823 * @user_data: user_data passed to @notify
1824 * @notify: notify called when @link will not be used anymore.
1826 * Sets the given link function for the pad. It will be called when
1827 * the pad is linked with another pad.
1829 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1832 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1833 * cannot be made for some reason.
1835 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1836 * of the peer sink pad, if present.
1839 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1840 gpointer user_data, GDestroyNotify notify)
1842 g_return_if_fail (GST_IS_PAD (pad));
1844 if (pad->linknotify)
1845 pad->linknotify (pad->linkdata);
1846 GST_PAD_LINKFUNC (pad) = link;
1847 pad->linkdata = user_data;
1848 pad->linknotify = notify;
1850 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1851 GST_DEBUG_FUNCPTR_NAME (link));
1855 * gst_pad_set_unlink_function:
1857 * @f: the #GstPadUnlinkFunction to set.
1859 * Calls gst_pad_set_unlink_function_full() with NULL
1860 * for the user_data and notify.
1863 * gst_pad_set_unlink_function_full:
1865 * @unlink: the #GstPadUnlinkFunction to set.
1866 * @user_data: user_data passed to @notify
1867 * @notify: notify called when @unlink will not be used anymore.
1869 * Sets the given unlink function for the pad. It will be called
1870 * when the pad is unlinked.
1873 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1874 gpointer user_data, GDestroyNotify notify)
1876 g_return_if_fail (GST_IS_PAD (pad));
1878 if (pad->unlinknotify)
1879 pad->unlinknotify (pad->unlinkdata);
1880 GST_PAD_UNLINKFUNC (pad) = unlink;
1881 pad->unlinkdata = user_data;
1882 pad->unlinknotify = notify;
1884 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1885 GST_DEBUG_FUNCPTR_NAME (unlink));
1890 * @srcpad: the source #GstPad to unlink.
1891 * @sinkpad: the sink #GstPad to unlink.
1893 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1894 * signal on both pads.
1896 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1897 * the pads were not linked together.
1902 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1904 gboolean result = FALSE;
1905 GstElement *parent = NULL;
1907 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1908 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1909 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1910 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1912 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1913 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1914 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1916 /* We need to notify the parent before taking any pad locks as the bin in
1917 * question might be waiting for a lock on the pad while holding its lock
1918 * that our message will try to take. */
1919 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1920 if (GST_IS_ELEMENT (parent)) {
1921 gst_element_post_message (parent,
1922 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1923 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1925 gst_object_unref (parent);
1930 GST_OBJECT_LOCK (srcpad);
1931 GST_OBJECT_LOCK (sinkpad);
1933 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1934 goto not_linked_together;
1936 if (GST_PAD_UNLINKFUNC (srcpad)) {
1937 GstObject *tmpparent;
1939 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1941 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1942 RELEASE_PARENT (tmpparent);
1945 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1946 GstObject *tmpparent;
1948 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1950 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1951 RELEASE_PARENT (tmpparent);
1955 /* first clear peers */
1956 GST_PAD_PEER (srcpad) = NULL;
1957 GST_PAD_PEER (sinkpad) = NULL;
1959 GST_OBJECT_UNLOCK (sinkpad);
1960 GST_OBJECT_UNLOCK (srcpad);
1962 /* fire off a signal to each of the pads telling them
1963 * that they've been unlinked */
1964 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1965 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1967 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1968 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1973 if (parent != NULL) {
1974 gst_element_post_message (parent,
1975 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1976 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1977 gst_object_unref (parent);
1982 not_linked_together:
1984 /* we do not emit a warning in this case because unlinking cannot
1985 * be made MT safe.*/
1986 GST_OBJECT_UNLOCK (sinkpad);
1987 GST_OBJECT_UNLOCK (srcpad);
1993 * gst_pad_is_linked:
1994 * @pad: pad to check
1996 * Checks if a @pad is linked to another pad or not.
1998 * Returns: TRUE if the pad is linked, FALSE otherwise.
2003 gst_pad_is_linked (GstPad * pad)
2007 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2009 GST_OBJECT_LOCK (pad);
2010 result = (GST_PAD_PEER (pad) != NULL);
2011 GST_OBJECT_UNLOCK (pad);
2016 /* get the caps from both pads and see if the intersection
2019 * This function should be called with the pad LOCK on both
2023 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2024 GstPadLinkCheck flags)
2026 GstCaps *srccaps = NULL;
2027 GstCaps *sinkcaps = NULL;
2028 gboolean compatible = FALSE;
2030 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2033 /* Doing the expensive caps checking takes priority over only checking the template caps */
2034 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2035 GST_OBJECT_UNLOCK (sink);
2036 GST_OBJECT_UNLOCK (src);
2038 srccaps = gst_pad_query_caps (src, NULL);
2039 sinkcaps = gst_pad_query_caps (sink, NULL);
2041 GST_OBJECT_LOCK (src);
2042 GST_OBJECT_LOCK (sink);
2044 /* If one of the two pads doesn't have a template, consider the intersection
2046 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2047 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2051 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2053 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2056 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2058 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2061 /* if we have caps on both pads we can check the intersection. If one
2062 * of the caps is NULL, we return TRUE. */
2063 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2065 gst_caps_unref (srccaps);
2067 gst_caps_unref (sinkcaps);
2071 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2072 gst_caps_unref (srccaps);
2073 gst_caps_unref (sinkcaps);
2076 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2077 (compatible ? "" : "not"));
2082 /* check if the grandparents of both pads are the same.
2083 * This check is required so that we don't try to link
2084 * pads from elements in different bins without ghostpads.
2086 * The LOCK should be held on both pads
2089 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2091 GstObject *psrc, *psink;
2093 psrc = GST_OBJECT_PARENT (src);
2094 psink = GST_OBJECT_PARENT (sink);
2096 /* if one of the pads has no parent, we allow the link */
2097 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2100 /* only care about parents that are elements */
2101 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2102 goto no_element_parent;
2104 /* if the parents are the same, we have a loop */
2105 if (G_UNLIKELY (psrc == psink))
2108 /* if they both have a parent, we check the grandparents. We can not lock
2109 * the parent because we hold on the child (pad) and the locking order is
2110 * parent >> child. */
2111 psrc = GST_OBJECT_PARENT (psrc);
2112 psink = GST_OBJECT_PARENT (psink);
2114 /* if they have grandparents but they are not the same */
2115 if (G_UNLIKELY (psrc != psink))
2116 goto wrong_grandparents;
2123 GST_CAT_DEBUG (GST_CAT_CAPS,
2124 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2125 GST_PTR_FORMAT, psrc, psink);
2130 GST_CAT_DEBUG (GST_CAT_CAPS,
2131 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2132 GST_PTR_FORMAT, psrc, psink);
2137 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2143 GST_CAT_DEBUG (GST_CAT_CAPS,
2144 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2145 GST_PTR_FORMAT, psrc, psink);
2150 /* FIXME leftover from an attempt at refactoring... */
2151 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2152 * the two pads will be locked in the srcpad, sinkpad order. */
2153 static GstPadLinkReturn
2154 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2156 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2157 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2159 GST_OBJECT_LOCK (srcpad);
2161 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2162 goto src_was_linked;
2164 GST_OBJECT_LOCK (sinkpad);
2166 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2167 goto sink_was_linked;
2169 /* check hierarchy, pads can only be linked if the grandparents
2171 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2172 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2173 goto wrong_hierarchy;
2175 /* check pad caps for non-empty intersection */
2176 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2179 /* FIXME check pad scheduling for non-empty intersection */
2181 return GST_PAD_LINK_OK;
2185 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2186 GST_DEBUG_PAD_NAME (srcpad),
2187 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2188 /* we do not emit a warning in this case because unlinking cannot
2189 * be made MT safe.*/
2190 GST_OBJECT_UNLOCK (srcpad);
2191 return GST_PAD_LINK_WAS_LINKED;
2195 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2196 GST_DEBUG_PAD_NAME (sinkpad),
2197 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2198 /* we do not emit a warning in this case because unlinking cannot
2199 * be made MT safe.*/
2200 GST_OBJECT_UNLOCK (sinkpad);
2201 GST_OBJECT_UNLOCK (srcpad);
2202 return GST_PAD_LINK_WAS_LINKED;
2206 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2207 GST_OBJECT_UNLOCK (sinkpad);
2208 GST_OBJECT_UNLOCK (srcpad);
2209 return GST_PAD_LINK_WRONG_HIERARCHY;
2213 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2214 GST_OBJECT_UNLOCK (sinkpad);
2215 GST_OBJECT_UNLOCK (srcpad);
2216 return GST_PAD_LINK_NOFORMAT;
2222 * @srcpad: the source #GstPad.
2223 * @sinkpad: the sink #GstPad.
2225 * Checks if the source pad and the sink pad are compatible so they can be
2228 * Returns: TRUE if the pads can be linked.
2231 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2233 GstPadLinkReturn result;
2235 /* generic checks */
2236 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2237 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2239 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2240 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2242 /* gst_pad_link_prepare does everything for us, we only release the locks
2243 * on the pads that it gets us. If this function returns !OK the locks are not
2245 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2246 if (result != GST_PAD_LINK_OK)
2249 GST_OBJECT_UNLOCK (srcpad);
2250 GST_OBJECT_UNLOCK (sinkpad);
2253 return result == GST_PAD_LINK_OK;
2257 * gst_pad_link_full:
2258 * @srcpad: the source #GstPad to link.
2259 * @sinkpad: the sink #GstPad to link.
2260 * @flags: the checks to validate when linking
2262 * Links the source pad and the sink pad.
2264 * This variant of #gst_pad_link provides a more granular control on the
2265 * checks being done when linking. While providing some considerable speedups
2266 * the caller of this method must be aware that wrong usage of those flags
2267 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2268 * for more information.
2272 * Returns: A result code indicating if the connection worked or
2276 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2278 GstPadLinkReturn result;
2280 GstPadLinkFunction srcfunc, sinkfunc;
2282 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2283 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2284 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2285 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2286 GST_PAD_LINK_WRONG_DIRECTION);
2288 /* Notify the parent early. See gst_pad_unlink for details. */
2289 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2290 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2291 gst_element_post_message (parent,
2292 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2293 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2295 gst_object_unref (parent);
2300 /* prepare will also lock the two pads */
2301 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2303 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2306 /* must set peers before calling the link function */
2307 GST_PAD_PEER (srcpad) = sinkpad;
2308 GST_PAD_PEER (sinkpad) = srcpad;
2310 /* check events, when something is different, mark pending */
2311 schedule_events (srcpad, sinkpad);
2313 /* get the link functions */
2314 srcfunc = GST_PAD_LINKFUNC (srcpad);
2315 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2317 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2318 /* custom link functions, execute them */
2319 GST_OBJECT_UNLOCK (sinkpad);
2320 GST_OBJECT_UNLOCK (srcpad);
2323 GstObject *tmpparent;
2325 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2326 /* this one will call the peer link function */
2327 result = srcfunc (srcpad, tmpparent, sinkpad);
2328 RELEASE_PARENT (tmpparent);
2329 } else if (sinkfunc) {
2330 GstObject *tmpparent;
2332 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2333 /* if no source link function, we need to call the sink link
2334 * function ourselves. */
2335 result = sinkfunc (sinkpad, tmpparent, srcpad);
2336 RELEASE_PARENT (tmpparent);
2340 GST_OBJECT_LOCK (srcpad);
2341 GST_OBJECT_LOCK (sinkpad);
2343 /* we released the lock, check if the same pads are linked still */
2344 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2345 goto concurrent_link;
2347 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2350 GST_OBJECT_UNLOCK (sinkpad);
2351 GST_OBJECT_UNLOCK (srcpad);
2353 /* fire off a signal to each of the pads telling them
2354 * that they've been linked */
2355 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2356 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2358 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2359 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2361 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2364 if (G_LIKELY (parent)) {
2365 gst_element_post_message (parent,
2366 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2367 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2368 gst_object_unref (parent);
2376 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2377 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2378 GST_OBJECT_UNLOCK (sinkpad);
2379 GST_OBJECT_UNLOCK (srcpad);
2381 /* The other link operation succeeded first */
2382 result = GST_PAD_LINK_WAS_LINKED;
2387 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2388 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2389 gst_pad_link_get_name (result));
2391 GST_PAD_PEER (srcpad) = NULL;
2392 GST_PAD_PEER (sinkpad) = NULL;
2394 GST_OBJECT_UNLOCK (sinkpad);
2395 GST_OBJECT_UNLOCK (srcpad);
2403 * @srcpad: the source #GstPad to link.
2404 * @sinkpad: the sink #GstPad to link.
2406 * Links the source pad and the sink pad.
2408 * Returns: A result code indicating if the connection worked or
2414 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2416 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2420 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2422 GstPadTemplate **template_p;
2424 /* this function would need checks if it weren't static */
2426 GST_OBJECT_LOCK (pad);
2427 template_p = &pad->padtemplate;
2428 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2429 GST_OBJECT_UNLOCK (pad);
2432 gst_pad_template_pad_created (templ, pad);
2436 * gst_pad_get_pad_template:
2439 * Gets the template for @pad.
2441 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2442 * instantiated, or %NULL if this pad has no template. Unref after
2446 gst_pad_get_pad_template (GstPad * pad)
2448 GstPadTemplate *templ;
2450 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2452 templ = GST_PAD_PAD_TEMPLATE (pad);
2454 return (templ ? gst_object_ref (templ) : NULL);
2458 * gst_pad_has_current_caps:
2459 * @pad: a #GstPad to check
2461 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2463 * Returns: TRUE when @pad has caps associated with it.
2466 gst_pad_has_current_caps (GstPad * pad)
2471 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2473 GST_OBJECT_LOCK (pad);
2474 caps = get_pad_caps (pad);
2475 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2476 "check current pad caps %" GST_PTR_FORMAT, caps);
2477 result = (caps != NULL);
2478 GST_OBJECT_UNLOCK (pad);
2484 * gst_pad_get_current_caps:
2485 * @pad: a #GstPad to get the current capabilities of.
2487 * Gets the capabilities currently configured on @pad with the last
2488 * #GST_EVENT_CAPS event.
2490 * Returns: the current caps of the pad with incremented ref-count.
2493 gst_pad_get_current_caps (GstPad * pad)
2497 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2499 GST_OBJECT_LOCK (pad);
2500 if ((result = get_pad_caps (pad)))
2501 gst_caps_ref (result);
2502 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2503 "get current pad caps %" GST_PTR_FORMAT, result);
2504 GST_OBJECT_UNLOCK (pad);
2510 * gst_pad_get_pad_template_caps:
2511 * @pad: a #GstPad to get the template capabilities from.
2513 * Gets the capabilities for @pad's template.
2515 * Returns: (transfer full): the #GstCaps of this pad template.
2516 * Unref after usage.
2519 gst_pad_get_pad_template_caps (GstPad * pad)
2521 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2523 if (GST_PAD_PAD_TEMPLATE (pad))
2524 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2526 return gst_caps_ref (GST_CAPS_ANY);
2531 * @pad: a #GstPad to get the peer of.
2533 * Gets the peer of @pad. This function refs the peer pad so
2534 * you need to unref it after use.
2536 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2541 gst_pad_get_peer (GstPad * pad)
2545 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2547 GST_OBJECT_LOCK (pad);
2548 result = GST_PAD_PEER (pad);
2550 gst_object_ref (result);
2551 GST_OBJECT_UNLOCK (pad);
2557 * gst_pad_get_allowed_caps:
2560 * Gets the capabilities of the allowed media types that can flow through
2561 * @pad and its peer.
2563 * The allowed capabilities is calculated as the intersection of the results of
2564 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2565 * on the resulting caps.
2567 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2568 * caps when you no longer need it. This function returns NULL when @pad
2574 gst_pad_get_allowed_caps (GstPad * pad)
2580 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2582 GST_OBJECT_LOCK (pad);
2583 peer = GST_PAD_PEER (pad);
2584 if (G_UNLIKELY (peer == NULL))
2587 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2589 gst_object_ref (peer);
2590 GST_OBJECT_UNLOCK (pad);
2591 mycaps = gst_pad_query_caps (pad, NULL);
2593 caps = gst_pad_query_caps (peer, mycaps);
2594 gst_object_unref (peer);
2596 gst_caps_unref (mycaps);
2598 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2605 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2606 GST_OBJECT_UNLOCK (pad);
2613 * gst_pad_iterate_internal_links_default:
2614 * @pad: the #GstPad to get the internal links of.
2615 * @parent: (allow-none): the parent of @pad or NULL
2617 * Iterate the list of pads to which the given pad is linked to inside of
2618 * the parent element.
2619 * This is the default handler, and thus returns an iterator of all of the
2620 * pads inside the parent element with opposite direction.
2622 * The caller must free this iterator after use with gst_iterator_free().
2624 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2625 * returned pad with gst_object_unref().
2628 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2635 GstElement *eparent;
2637 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2639 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2640 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2642 GST_OBJECT_LOCK (pad);
2643 eparent = GST_PAD_PARENT (pad);
2644 if (!eparent || !GST_IS_ELEMENT (eparent))
2647 gst_object_ref (eparent);
2648 GST_OBJECT_UNLOCK (pad);
2651 if (pad->direction == GST_PAD_SRC)
2652 padlist = &eparent->sinkpads;
2654 padlist = &eparent->srcpads;
2656 GST_DEBUG_OBJECT (pad, "Making iterator");
2658 cookie = &eparent->pads_cookie;
2660 lock = GST_OBJECT_GET_LOCK (eparent);
2662 res = gst_iterator_new_list (GST_TYPE_PAD,
2663 lock, cookie, padlist, (GObject *) owner, NULL);
2665 gst_object_unref (owner);
2672 GST_OBJECT_UNLOCK (pad);
2673 GST_DEBUG_OBJECT (pad, "no parent element");
2679 * gst_pad_iterate_internal_links:
2680 * @pad: the GstPad to get the internal links of.
2682 * Gets an iterator for the pads to which the given pad is linked to inside
2683 * of the parent element.
2685 * Each #GstPad element yielded by the iterator will have its refcount increased,
2686 * so unref after use.
2688 * Free-function: gst_iterator_free
2690 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2691 * pad does not have an iterator function configured. Use
2692 * gst_iterator_free() after usage.
2695 gst_pad_iterate_internal_links (GstPad * pad)
2697 GstIterator *res = NULL;
2700 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2702 GST_OBJECT_LOCK (pad);
2703 ACQUIRE_PARENT (pad, parent, no_parent);
2704 GST_OBJECT_UNLOCK (pad);
2706 if (GST_PAD_ITERINTLINKFUNC (pad))
2707 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2709 RELEASE_PARENT (parent);
2716 GST_DEBUG_OBJECT (pad, "no parent");
2717 GST_OBJECT_UNLOCK (pad);
2725 * @forward: (scope call): a #GstPadForwardFunction
2726 * @user_data: user data passed to @forward
2728 * Calls @forward for all internally linked pads of @pad. This function deals with
2729 * dynamically changing internal pads and will make sure that the @forward
2730 * function is only called once for each pad.
2732 * When @forward returns TRUE, no further pads will be processed.
2734 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2737 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2740 gboolean result = FALSE;
2742 gboolean done = FALSE;
2743 GValue item = { 0, };
2744 GList *pushed_pads = NULL;
2746 iter = gst_pad_iterate_internal_links (pad);
2752 switch (gst_iterator_next (iter, &item)) {
2753 case GST_ITERATOR_OK:
2757 intpad = g_value_get_object (&item);
2759 /* if already pushed, skip. FIXME, find something faster to tag pads */
2760 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2761 g_value_reset (&item);
2765 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2766 GST_DEBUG_PAD_NAME (intpad));
2767 done = result = forward (intpad, user_data);
2769 pushed_pads = g_list_prepend (pushed_pads, intpad);
2771 g_value_reset (&item);
2774 case GST_ITERATOR_RESYNC:
2775 /* We don't reset the result here because we don't push the event
2776 * again on pads that got the event already and because we need
2777 * to consider the result of the previous pushes */
2778 gst_iterator_resync (iter);
2780 case GST_ITERATOR_ERROR:
2781 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2784 case GST_ITERATOR_DONE:
2789 g_value_unset (&item);
2790 gst_iterator_free (iter);
2792 g_list_free (pushed_pads);
2802 gboolean dispatched;
2806 event_forward_func (GstPad * pad, EventData * data)
2808 /* for each pad we send to, we should ref the event; it's up
2809 * to downstream to unref again when handled. */
2810 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2811 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2813 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2815 data->dispatched = TRUE;
2822 * gst_pad_event_default:
2823 * @pad: a #GstPad to call the default event handler on.
2824 * @parent: (allow-none): the parent of @pad or NULL
2825 * @event: (transfer full): the #GstEvent to handle.
2827 * Invokes the default event handler for the given pad.
2829 * The EOS event will pause the task associated with @pad before it is forwarded
2830 * to all internally linked pads,
2832 * The the event is sent to all pads internally linked to @pad. This function
2833 * takes ownership of @event.
2835 * Returns: TRUE if the event was sent successfully.
2838 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2840 gboolean result, forward = TRUE;
2842 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2843 g_return_val_if_fail (event != NULL, FALSE);
2845 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2848 switch (GST_EVENT_TYPE (event)) {
2849 case GST_EVENT_CAPS:
2850 forward = GST_PAD_IS_PROXY_CAPS (pad);
2861 data.dispatched = FALSE;
2862 data.result = FALSE;
2864 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2866 /* for sinkpads without a parent element or without internal links, nothing
2867 * will be dispatched but we still want to return TRUE. */
2868 if (data.dispatched)
2869 result = data.result;
2874 gst_event_unref (event);
2879 /* Default accept caps implementation just checks against
2880 * the allowed caps for the pad */
2882 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2884 /* get the caps and see if it intersects to something not empty */
2885 GstCaps *caps, *allowed;
2888 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2890 /* first forward the query to internally linked pads when we are dealing with
2892 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2893 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2898 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2899 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2901 gst_query_parse_accept_caps (query, &caps);
2902 allowed = gst_pad_query_caps (pad, caps);
2905 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
2906 GST_DEBUG_OBJECT (pad,
2907 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
2909 result = gst_caps_can_intersect (caps, allowed);
2911 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
2912 GST_PTR_FORMAT, allowed, caps);
2913 result = gst_caps_is_subset (caps, allowed);
2915 gst_caps_unref (allowed);
2917 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
2920 gst_query_set_accept_caps_result (query, result);
2926 /* Default caps implementation */
2928 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2930 GstCaps *result = NULL, *filter;
2931 GstPadTemplate *templ;
2932 gboolean fixed_caps;
2934 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2937 /* first try to proxy if we must */
2938 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2939 if ((gst_pad_proxy_query_caps (pad, query))) {
2944 gst_query_parse_caps (query, &filter);
2946 /* no proxy or it failed, do default handling */
2947 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2949 GST_OBJECT_LOCK (pad);
2951 /* fixed caps, try the negotiated caps first */
2952 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2953 if ((result = get_pad_caps (pad)))
2954 goto filter_done_unlock;
2957 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2958 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2959 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2960 goto filter_done_unlock;
2964 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2965 "non-fixed pad caps: trying pad caps");
2966 /* non fixed caps, try the negotiated caps */
2967 if ((result = get_pad_caps (pad)))
2968 goto filter_done_unlock;
2971 /* this almost never happens */
2972 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2973 result = GST_CAPS_ANY;
2976 GST_OBJECT_UNLOCK (pad);
2978 /* run the filter on the result */
2980 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2981 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2982 GST_PTR_FORMAT, result, result, filter, filter);
2983 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2984 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2987 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2988 "using caps %p %" GST_PTR_FORMAT, result, result);
2989 result = gst_caps_ref (result);
2991 gst_query_set_caps_result (query, result);
2992 gst_caps_unref (result);
3002 gboolean dispatched;
3006 query_forward_func (GstPad * pad, QueryData * data)
3008 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3009 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3011 data->result |= gst_pad_peer_query (pad, data->query);
3013 data->dispatched = TRUE;
3015 /* stop on first successful reply */
3016 return data->result;
3020 * gst_pad_query_default:
3021 * @pad: a #GstPad to call the default query handler on.
3022 * @parent: (allow-none): the parent of @pad or NULL
3023 * @query: (transfer none): the #GstQuery to handle.
3025 * Invokes the default query handler for the given pad.
3026 * The query is sent to all pads internally linked to @pad. Note that
3027 * if there are many possible sink pads that are internally linked to
3028 * @pad, only one will be sent the query.
3029 * Multi-sinkpad elements should implement custom query handlers.
3031 * Returns: TRUE if the query was performed successfully.
3034 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3036 gboolean forward, ret = FALSE;
3038 switch (GST_QUERY_TYPE (query)) {
3039 case GST_QUERY_SCHEDULING:
3040 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3042 case GST_QUERY_ALLOCATION:
3043 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3045 case GST_QUERY_ACCEPT_CAPS:
3046 ret = gst_pad_query_accept_caps_default (pad, query);
3049 case GST_QUERY_CAPS:
3050 ret = gst_pad_query_caps_default (pad, query);
3053 case GST_QUERY_POSITION:
3054 case GST_QUERY_SEEKING:
3055 case GST_QUERY_FORMATS:
3056 case GST_QUERY_LATENCY:
3057 case GST_QUERY_JITTER:
3058 case GST_QUERY_RATE:
3059 case GST_QUERY_CONVERT:
3065 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3066 query, GST_QUERY_TYPE_NAME (query));
3072 data.dispatched = FALSE;
3073 data.result = FALSE;
3075 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3077 if (data.dispatched) {
3080 /* nothing dispatched, assume drained */
3081 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3091 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3093 GstPad *pad = data->pad;
3094 GstPadProbeInfo *info = data->info;
3095 GstPadProbeType type, flags;
3096 GstPadProbeCallback callback;
3097 GstPadProbeReturn ret;
3099 /* if we have called this callback, do nothing */
3100 if (PROBE_COOKIE (hook) == data->cookie) {
3101 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3102 "hook %lu, cookie %u already called", hook->hook_id,
3103 PROBE_COOKIE (hook));
3107 PROBE_COOKIE (hook) = data->cookie;
3109 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3112 /* one of the data types for non-idle probes */
3113 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3114 && (flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3116 /* one of the scheduling types */
3117 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3119 /* one of the blocking types must match */
3120 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3121 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3123 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3124 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3126 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3127 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3128 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3131 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3132 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3133 PROBE_COOKIE (hook), flags);
3135 data->marshalled = TRUE;
3137 callback = (GstPadProbeCallback) hook->func;
3138 if (callback == NULL)
3141 info->id = hook->hook_id;
3143 GST_OBJECT_UNLOCK (pad);
3145 ret = callback (pad, info, hook->data);
3147 GST_OBJECT_LOCK (pad);
3150 case GST_PAD_PROBE_REMOVE:
3151 /* remove the probe */
3152 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3153 cleanup_hook (pad, hook);
3155 case GST_PAD_PROBE_DROP:
3156 /* need to drop the data, make sure other probes don't get called
3158 GST_DEBUG_OBJECT (pad, "asked to drop item");
3159 info->type = GST_PAD_PROBE_TYPE_INVALID;
3160 data->dropped = TRUE;
3162 case GST_PAD_PROBE_PASS:
3163 /* inform the pad block to let things pass */
3164 GST_DEBUG_OBJECT (pad, "asked to pass item");
3167 case GST_PAD_PROBE_OK:
3168 GST_DEBUG_OBJECT (pad, "probe returned OK");
3171 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3178 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3179 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3180 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3185 /* a probe that does not take or return any data */
3186 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3188 if (G_UNLIKELY (pad->num_probes)) { \
3189 /* pass NULL as the data item */ \
3190 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3191 ret = do_probe_callbacks (pad, &info, defaultval); \
3192 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3197 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3199 if (G_UNLIKELY (pad->num_probes)) { \
3200 /* pass the data item */ \
3201 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3202 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3203 /* store the possibly updated data item */ \
3204 data = GST_PAD_PROBE_INFO_DATA (&info); \
3205 /* if something went wrong, exit */ \
3206 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3211 #define PROBE_PUSH(pad,mask,data,label) \
3212 PROBE_FULL(pad, mask, data, -1, -1, label);
3213 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3214 PROBE_FULL(pad, mask, data, offs, size, label);
3216 static GstFlowReturn
3217 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3218 GstFlowReturn defaultval)
3227 data.marshalled = FALSE;
3228 data.dropped = FALSE;
3229 data.cookie = ++pad->priv->probe_cookie;
3232 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3235 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3236 "do probes cookie %u", data.cookie);
3237 cookie = pad->priv->probe_list_cookie;
3239 g_hook_list_marshal (&pad->probes, TRUE,
3240 (GHookMarshaller) probe_hook_marshal, &data);
3242 /* if the list changed, call the new callbacks (they will not have their
3243 * cookie set to data.cookie */
3244 if (cookie != pad->priv->probe_list_cookie) {
3245 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3246 "probe list changed, restarting");
3250 /* the first item that dropped will stop the hooks and then we drop here */
3254 /* if no handler matched and we are blocking, let the item pass */
3255 if (!data.marshalled && is_block)
3258 /* At this point, all handlers returned either OK or PASS. If one handler
3259 * returned PASS, let the item pass */
3264 while (GST_PAD_IS_BLOCKED (pad)) {
3265 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3266 "we are blocked %d times", pad->num_blocked);
3268 /* we might have released the lock */
3269 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3272 /* now we block the streaming thread. It can be unlocked when we
3273 * deactivate the pad (which will also set the FLUSHING flag) or
3274 * when the pad is unblocked. A flushing event will also unblock
3275 * the pad after setting the FLUSHING flag. */
3276 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3277 "Waiting to be unblocked or set flushing");
3278 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3279 GST_PAD_BLOCK_WAIT (pad);
3280 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3281 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3283 /* if the list changed, call the new callbacks (they will not have their
3284 * cookie set to data.cookie */
3285 if (cookie != pad->priv->probe_list_cookie) {
3286 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3287 "probe list changed, restarting");
3291 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3301 GST_DEBUG_OBJECT (pad, "pad is flushing");
3302 return GST_FLOW_FLUSHING;
3306 GST_DEBUG_OBJECT (pad, "data is dropped");
3307 return GST_FLOW_CUSTOM_SUCCESS;
3311 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3312 GST_DEBUG_OBJECT (pad, "data is passed");
3320 * gst_pad_get_offset:
3323 * Get the offset applied to the running time of @pad. @pad has to be a source
3326 * Returns: the offset.
3329 gst_pad_get_offset (GstPad * pad)
3333 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3335 GST_OBJECT_LOCK (pad);
3336 result = pad->offset;
3337 GST_OBJECT_UNLOCK (pad);
3343 * gst_pad_set_offset:
3345 * @offset: the offset
3347 * Set the offset that will be applied to the running time of @pad.
3350 gst_pad_set_offset (GstPad * pad, gint64 offset)
3354 g_return_if_fail (GST_IS_PAD (pad));
3356 GST_OBJECT_LOCK (pad);
3357 /* if nothing changed, do nothing */
3358 if (pad->offset == offset)
3361 pad->offset = offset;
3362 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3364 /* sinkpads will apply their offset the next time a segment
3365 * event is received. */
3366 if (GST_PAD_IS_SINK (pad))
3369 /* resend the last segment event on next buffer push */
3370 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3371 ev->received = FALSE;
3372 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3376 GST_OBJECT_UNLOCK (pad);
3383 /* If TRUE and ret is not OK this means
3384 * that pushing the EOS event failed
3388 /* If called for an event this is
3389 * the event that would be pushed
3390 * next. Don't forward sticky events
3391 * that would come after that */
3395 /* should be called with pad LOCK */
3397 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3399 PushStickyData *data = user_data;
3400 GstEvent *event = ev->event;
3403 GST_DEBUG_OBJECT (pad, "event %s was already received",
3404 GST_EVENT_TYPE_NAME (event));
3408 /* If we're called because of an sticky event, only forward
3409 * events that would come before this new event and the
3411 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3412 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3413 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3414 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3416 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3417 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3420 switch (data->ret) {
3422 ev->received = TRUE;
3423 GST_DEBUG_OBJECT (pad, "event %s marked received",
3424 GST_EVENT_TYPE_NAME (event));
3426 case GST_FLOW_CUSTOM_SUCCESS:
3427 /* we can't assume the event is received when it was dropped */
3428 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3429 GST_EVENT_TYPE_NAME (event));
3430 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3431 data->ret = GST_FLOW_OK;
3433 case GST_FLOW_CUSTOM_SUCCESS_1:
3434 /* event was ignored and should be sent later */
3435 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3436 GST_EVENT_TYPE_NAME (event));
3437 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3438 data->ret = GST_FLOW_OK;
3440 case GST_FLOW_NOT_LINKED:
3441 /* not linked is not a problem, we are sticky so the event will be
3442 * sent later but only for non-EOS events */
3443 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3444 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3445 data->ret = GST_FLOW_OK;
3446 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3449 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3450 gst_flow_get_name (data->ret));
3451 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3455 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3456 data->was_eos = TRUE;
3458 return data->ret == GST_FLOW_OK;
3461 /* check sticky events and push them when needed. should be called
3463 static inline GstFlowReturn
3464 check_sticky (GstPad * pad, GstEvent * event)
3466 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3468 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3469 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3471 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3472 events_foreach (pad, push_sticky, &data);
3474 /* If there's an EOS event we must push it downstream
3475 * even if sending a previous sticky event failed.
3476 * Otherwise the pipeline might wait forever for EOS.
3478 * Only do this if pushing another event than the EOS
3481 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3482 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3484 if (ev && !ev->received) {
3485 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3486 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3487 /* the event could have been dropped. Because this can only
3488 * happen if the user asked for it, it's not an error */
3489 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3490 data.ret = GST_FLOW_OK;
3500 * @pad: a #GstPad to invoke the default query on.
3501 * @query: (transfer none): the #GstQuery to perform.
3503 * Dispatches a query to a pad. The query should have been allocated by the
3504 * caller via one of the type-specific allocation functions. The element that
3505 * the pad belongs to is responsible for filling the query with an appropriate
3506 * response, which should then be parsed with a type-specific query parsing
3509 * Again, the caller is responsible for both the allocation and deallocation of
3510 * the query structure.
3512 * Please also note that some queries might need a running pipeline to work.
3514 * Returns: TRUE if the query could be performed.
3517 gst_pad_query (GstPad * pad, GstQuery * query)
3520 gboolean res, serialized;
3521 GstPadQueryFunction func;
3522 GstPadProbeType type;
3525 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3526 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3528 if (GST_PAD_IS_SRC (pad)) {
3529 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3530 goto wrong_direction;
3531 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3532 } else if (GST_PAD_IS_SINK (pad)) {
3533 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3534 goto wrong_direction;
3535 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3537 goto unknown_direction;
3539 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3540 GST_QUERY_TYPE_NAME (query));
3542 serialized = GST_QUERY_IS_SERIALIZED (query);
3543 if (G_UNLIKELY (serialized))
3544 GST_PAD_STREAM_LOCK (pad);
3546 GST_OBJECT_LOCK (pad);
3547 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3548 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3549 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3551 ACQUIRE_PARENT (pad, parent, no_parent);
3552 GST_OBJECT_UNLOCK (pad);
3554 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3557 res = func (pad, parent, query);
3559 RELEASE_PARENT (parent);
3561 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3562 GST_QUERY_TYPE_NAME (query), res);
3567 GST_OBJECT_LOCK (pad);
3568 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3569 GST_OBJECT_UNLOCK (pad);
3571 if (G_UNLIKELY (serialized))
3572 GST_PAD_STREAM_UNLOCK (pad);
3579 g_warning ("pad %s:%s query %s in wrong direction",
3580 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3585 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3590 GST_DEBUG_OBJECT (pad, "had no parent");
3591 GST_OBJECT_UNLOCK (pad);
3592 if (G_UNLIKELY (serialized))
3593 GST_PAD_STREAM_UNLOCK (pad);
3598 GST_DEBUG_OBJECT (pad, "had no query function");
3599 RELEASE_PARENT (parent);
3600 if (G_UNLIKELY (serialized))
3601 GST_PAD_STREAM_UNLOCK (pad);
3606 GST_DEBUG_OBJECT (pad, "query failed");
3607 if (G_UNLIKELY (serialized))
3608 GST_PAD_STREAM_UNLOCK (pad);
3613 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3614 GST_OBJECT_UNLOCK (pad);
3615 if (G_UNLIKELY (serialized))
3616 GST_PAD_STREAM_UNLOCK (pad);
3618 /* if a probe dropped, we don't sent it further but assume that the probe
3619 * answered the query and return TRUE */
3620 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3630 * gst_pad_peer_query:
3631 * @pad: a #GstPad to invoke the peer query on.
3632 * @query: (transfer none): the #GstQuery to perform.
3634 * Performs gst_pad_query() on the peer of @pad.
3636 * The caller is responsible for both the allocation and deallocation of
3637 * the query structure.
3639 * Returns: TRUE if the query could be performed. This function returns %FALSE
3640 * if @pad has no peer.
3643 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3646 GstPadProbeType type;
3647 gboolean res, serialized;
3650 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3651 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3653 if (GST_PAD_IS_SRC (pad)) {
3654 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3655 goto wrong_direction;
3656 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3657 } else if (GST_PAD_IS_SINK (pad)) {
3658 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3659 goto wrong_direction;
3660 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3662 goto unknown_direction;
3664 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3665 GST_QUERY_TYPE_NAME (query));
3667 serialized = GST_QUERY_IS_SERIALIZED (query);
3669 GST_OBJECT_LOCK (pad);
3670 if (GST_PAD_IS_SRC (pad) && serialized) {
3671 /* all serialized queries on the srcpad trigger push of
3673 if (check_sticky (pad, NULL) != GST_FLOW_OK)
3677 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3678 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3679 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3681 peerpad = GST_PAD_PEER (pad);
3682 if (G_UNLIKELY (peerpad == NULL))
3685 gst_object_ref (peerpad);
3686 GST_OBJECT_UNLOCK (pad);
3688 res = gst_pad_query (peerpad, query);
3690 gst_object_unref (peerpad);
3695 GST_OBJECT_LOCK (pad);
3696 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3697 GST_OBJECT_UNLOCK (pad);
3704 g_warning ("pad %s:%s query %s in wrong direction",
3705 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3710 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3715 GST_WARNING_OBJECT (pad, "could not send sticky events");
3716 GST_OBJECT_UNLOCK (pad);
3721 GST_INFO_OBJECT (pad, "pad has no peer");
3722 GST_OBJECT_UNLOCK (pad);
3727 GST_DEBUG_OBJECT (pad, "query failed");
3732 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3733 GST_OBJECT_UNLOCK (pad);
3735 /* if a probe dropped, we don't sent it further but assume that the probe
3736 * answered the query and return TRUE */
3737 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3746 /**********************************************************************
3747 * Data passing functions
3750 /* this is the chain function that does not perform the additional argument
3751 * checking for that little extra speed.
3753 static inline GstFlowReturn
3754 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3759 GST_PAD_STREAM_LOCK (pad);
3761 GST_OBJECT_LOCK (pad);
3762 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3765 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3768 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3771 #ifndef G_DISABLE_ASSERT
3772 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3773 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3775 ":%s:<%s:%s> Got data flow before stream-start event",
3776 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3778 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3780 ":%s:<%s:%s> Got data flow before segment event",
3781 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3783 pad->priv->last_cookie = pad->priv->events_cookie;
3787 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3789 PROBE_PUSH (pad, type, data, probe_stopped);
3791 parent = GST_OBJECT_PARENT (pad);
3792 GST_OBJECT_UNLOCK (pad);
3794 /* NOTE: we read the chainfunc unlocked.
3795 * we cannot hold the lock for the pad so we might send
3796 * the data to the wrong function. This is not really a
3797 * problem since functions are assigned at creation time
3798 * and don't change that often... */
3799 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3800 GstPadChainFunction chainfunc;
3802 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3805 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3806 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3807 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3809 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3811 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3812 "called chainfunction &%s with buffer %p, returned %s",
3813 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3815 GstPadChainListFunction chainlistfunc;
3817 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3820 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3821 "calling chainlistfunction &%s",
3822 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3824 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3826 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3827 "called chainlistfunction &%s, returned %s",
3828 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3831 GST_PAD_STREAM_UNLOCK (pad);
3838 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3839 "chaining, but pad was flushing");
3840 GST_OBJECT_UNLOCK (pad);
3841 GST_PAD_STREAM_UNLOCK (pad);
3842 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3843 return GST_FLOW_FLUSHING;
3847 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3848 GST_OBJECT_UNLOCK (pad);
3849 GST_PAD_STREAM_UNLOCK (pad);
3850 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3851 return GST_FLOW_EOS;
3855 g_critical ("chain on pad %s:%s but it was not in push mode",
3856 GST_DEBUG_PAD_NAME (pad));
3857 GST_OBJECT_UNLOCK (pad);
3858 GST_PAD_STREAM_UNLOCK (pad);
3859 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3860 return GST_FLOW_ERROR;
3864 GST_OBJECT_UNLOCK (pad);
3865 GST_PAD_STREAM_UNLOCK (pad);
3866 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3869 case GST_FLOW_CUSTOM_SUCCESS:
3870 GST_DEBUG_OBJECT (pad, "dropped buffer");
3874 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
3881 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3882 g_critical ("chain on pad %s:%s but it has no chainfunction",
3883 GST_DEBUG_PAD_NAME (pad));
3884 GST_PAD_STREAM_UNLOCK (pad);
3885 return GST_FLOW_NOT_SUPPORTED;
3891 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3892 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3895 * Chain a buffer to @pad.
3897 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3899 * If the buffer type is not acceptable for @pad (as negotiated with a
3900 * preceding GST_EVENT_CAPS event), this function returns
3901 * #GST_FLOW_NOT_NEGOTIATED.
3903 * The function proceeds calling the chain function installed on @pad (see
3904 * gst_pad_set_chain_function()) and the return value of that function is
3905 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3908 * In all cases, success or failure, the caller loses its reference to @buffer
3909 * after calling this function.
3911 * Returns: a #GstFlowReturn from the pad.
3916 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3918 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3919 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3920 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3922 return gst_pad_chain_data_unchecked (pad,
3923 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3926 static GstFlowReturn
3927 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3928 GstBufferList * list)
3934 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3936 len = gst_buffer_list_length (list);
3939 for (i = 0; i < len; i++) {
3940 buffer = gst_buffer_list_get (list, i);
3942 gst_pad_chain_data_unchecked (pad,
3943 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3944 gst_buffer_ref (buffer));
3945 if (ret != GST_FLOW_OK)
3948 gst_buffer_list_unref (list);
3954 * gst_pad_chain_list:
3955 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3956 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3959 * Chain a bufferlist to @pad.
3961 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3963 * If @pad was not negotiated properly with a CAPS event, this function
3964 * returns #GST_FLOW_NOT_NEGOTIATED.
3966 * The function proceeds calling the chainlist function installed on @pad (see
3967 * gst_pad_set_chain_list_function()) and the return value of that function is
3968 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3969 * chainlist function.
3971 * In all cases, success or failure, the caller loses its reference to @list
3972 * after calling this function.
3976 * Returns: a #GstFlowReturn from the pad.
3979 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3981 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3982 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3983 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3985 return gst_pad_chain_data_unchecked (pad,
3986 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3989 static GstFlowReturn
3990 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3995 GST_OBJECT_LOCK (pad);
3996 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3999 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4002 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4005 #ifndef G_DISABLE_ASSERT
4006 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4007 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4009 ":%s:<%s:%s> Got data flow before stream-start event",
4010 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4012 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4014 ":%s:<%s:%s> Got data flow before segment event",
4015 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4017 pad->priv->last_cookie = pad->priv->events_cookie;
4021 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4024 /* do block probes */
4025 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
4027 /* recheck sticky events because the probe might have cause a relink */
4028 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4031 /* do post-blocking probes */
4032 PROBE_PUSH (pad, type, data, probe_stopped);
4034 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4037 /* take ref to peer pad before releasing the lock */
4038 gst_object_ref (peer);
4040 GST_OBJECT_UNLOCK (pad);
4042 ret = gst_pad_chain_data_unchecked (peer, type, data);
4044 gst_object_unref (peer);
4046 GST_OBJECT_LOCK (pad);
4048 if (pad->priv->using == 0) {
4049 /* pad is not active anymore, trigger idle callbacks */
4050 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4051 probe_stopped, ret);
4053 GST_OBJECT_UNLOCK (pad);
4057 /* ERROR recovery here */
4061 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4062 "pushing, but pad was flushing");
4063 GST_OBJECT_UNLOCK (pad);
4064 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4065 return GST_FLOW_FLUSHING;
4069 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4070 GST_OBJECT_UNLOCK (pad);
4071 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4072 return GST_FLOW_EOS;
4076 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4077 GST_DEBUG_PAD_NAME (pad));
4078 GST_OBJECT_UNLOCK (pad);
4079 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4080 return GST_FLOW_ERROR;
4084 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4085 "error pushing events, return %s", gst_flow_get_name (ret));
4086 GST_OBJECT_UNLOCK (pad);
4087 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4092 GST_OBJECT_UNLOCK (pad);
4093 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4096 case GST_FLOW_CUSTOM_SUCCESS:
4097 GST_DEBUG_OBJECT (pad, "dropped buffer");
4101 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4108 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4109 "pushing, but it was not linked");
4110 GST_OBJECT_UNLOCK (pad);
4111 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4112 return GST_FLOW_NOT_LINKED;
4118 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4119 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4122 * Pushes a buffer to the peer of @pad.
4124 * This function will call installed block probes before triggering any
4125 * installed data probes.
4127 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4128 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4131 * In all cases, success or failure, the caller loses its reference to @buffer
4132 * after calling this function.
4134 * Returns: a #GstFlowReturn from the peer pad.
4139 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4141 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4142 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4143 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4145 return gst_pad_push_data (pad,
4146 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4150 * gst_pad_push_list:
4151 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4152 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4155 * Pushes a buffer list to the peer of @pad.
4157 * This function will call installed block probes before triggering any
4158 * installed data probes.
4160 * The function proceeds calling the chain function on the peer pad and returns
4161 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4162 * be returned. If the peer pad does not have any installed chainlist function
4163 * every group buffer of the list will be merged into a normal #GstBuffer and
4164 * chained via gst_pad_chain().
4166 * In all cases, success or failure, the caller loses its reference to @list
4167 * after calling this function.
4169 * Returns: a #GstFlowReturn from the peer pad.
4174 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4176 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4177 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4178 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4180 return gst_pad_push_data (pad,
4181 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4184 static GstFlowReturn
4185 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4186 GstBuffer ** buffer)
4189 GstPadGetRangeFunction getrangefunc;
4193 GST_PAD_STREAM_LOCK (pad);
4195 GST_OBJECT_LOCK (pad);
4196 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4199 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4202 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4207 /* when one of the probes returns DROPPED, probe_stopped will be called
4208 * and we skip calling the getrange function, res_buf should then contain a
4209 * valid result buffer */
4210 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4211 res_buf, offset, size, probe_stopped);
4213 /* recheck sticky events because the probe might have cause a relink */
4214 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4217 ACQUIRE_PARENT (pad, parent, no_parent);
4218 GST_OBJECT_UNLOCK (pad);
4220 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4223 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4224 "calling getrangefunc %s, offset %"
4225 G_GUINT64_FORMAT ", size %u",
4226 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4228 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4230 RELEASE_PARENT (parent);
4232 if (G_UNLIKELY (ret != GST_FLOW_OK))
4233 goto get_range_failed;
4235 /* can only fire the signal if we have a valid buffer */
4236 GST_OBJECT_LOCK (pad);
4238 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4239 res_buf, offset, size, probe_stopped_unref);
4240 GST_OBJECT_UNLOCK (pad);
4242 GST_PAD_STREAM_UNLOCK (pad);
4251 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4252 "getrange, but pad was flushing");
4253 GST_OBJECT_UNLOCK (pad);
4254 GST_PAD_STREAM_UNLOCK (pad);
4255 return GST_FLOW_FLUSHING;
4259 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4260 GST_DEBUG_PAD_NAME (pad));
4261 GST_OBJECT_UNLOCK (pad);
4262 GST_PAD_STREAM_UNLOCK (pad);
4263 return GST_FLOW_ERROR;
4267 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4268 GST_OBJECT_UNLOCK (pad);
4269 GST_PAD_STREAM_UNLOCK (pad);
4274 GST_DEBUG_OBJECT (pad, "no parent");
4275 GST_OBJECT_UNLOCK (pad);
4276 GST_PAD_STREAM_UNLOCK (pad);
4277 return GST_FLOW_FLUSHING;
4281 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4282 GST_DEBUG_PAD_NAME (pad));
4283 RELEASE_PARENT (parent);
4284 GST_PAD_STREAM_UNLOCK (pad);
4285 return GST_FLOW_NOT_SUPPORTED;
4289 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4290 "probe returned %s", gst_flow_get_name (ret));
4291 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4293 /* the probe filled the buffer and asks us to not call the getrange
4294 * anymore, we continue with the post probes then. */
4295 GST_DEBUG_OBJECT (pad, "handled buffer");
4299 /* no buffer, we are EOS */
4300 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4304 GST_OBJECT_UNLOCK (pad);
4305 GST_PAD_STREAM_UNLOCK (pad);
4309 probe_stopped_unref:
4311 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4312 "probe returned %s", gst_flow_get_name (ret));
4313 /* if we drop here, it signals EOS */
4314 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4316 GST_OBJECT_UNLOCK (pad);
4317 GST_PAD_STREAM_UNLOCK (pad);
4318 if (*buffer == NULL)
4319 gst_buffer_unref (res_buf);
4324 GST_PAD_STREAM_UNLOCK (pad);
4325 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4326 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4327 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4333 * gst_pad_get_range:
4334 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4335 * @offset: The start offset of the buffer
4336 * @size: The length of the buffer
4337 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4338 * returns #GST_FLOW_ERROR if %NULL.
4340 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4341 * immediately and @buffer is %NULL.
4343 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4344 * description of a getrange function. If @pad has no getrange function
4345 * installed (see gst_pad_set_getrange_function()) this function returns
4346 * #GST_FLOW_NOT_SUPPORTED.
4348 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4349 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4350 * must be freed with gst_buffer_unref() after usage.
4352 * When @buffer points to a variable that points to a valid #GstBuffer, the
4353 * buffer will be filled with the result data when this function returns
4354 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4355 * @size bytes will be filled in the result buffer and its size will be updated
4358 * Note that less than @size bytes can be returned in @buffer when, for example,
4359 * an EOS condition is near or when @buffer is not large enough to hold @size
4360 * bytes. The caller should check the result buffer size to get the result size.
4362 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4363 * will be unchanged.
4365 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4367 * Returns: a #GstFlowReturn from the pad.
4372 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4373 GstBuffer ** buffer)
4375 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4376 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4377 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4378 g_return_val_if_fail (*buffer == NULL
4379 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4381 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4385 * gst_pad_pull_range:
4386 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4387 * @offset: The start offset of the buffer
4388 * @size: The length of the buffer
4389 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4390 * GST_FLOW_ERROR if %NULL.
4392 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4394 * This function will first trigger the pad block signal if it was
4397 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4398 * function returns the result of gst_pad_get_range() on the peer pad.
4399 * See gst_pad_get_range() for a list of return values and for the
4400 * semantics of the arguments of this function.
4402 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4403 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4404 * must be freed with gst_buffer_unref() after usage. When this function
4405 * returns any other result value, @buffer will still point to NULL.
4407 * When @buffer points to a variable that points to a valid #GstBuffer, the
4408 * buffer will be filled with the result data when this function returns
4409 * #GST_FLOW_OK. When this function returns any other result value,
4410 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4411 * @size bytes will be filled in the result buffer and its size will be updated
4414 * Note that less than @size bytes can be returned in @buffer when, for example,
4415 * an EOS condition is near or when @buffer is not large enough to hold @size
4416 * bytes. The caller should check the result buffer size to get the result size.
4418 * Returns: a #GstFlowReturn from the peer pad.
4423 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4424 GstBuffer ** buffer)
4430 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4431 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4432 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4433 g_return_val_if_fail (*buffer == NULL
4434 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4436 GST_OBJECT_LOCK (pad);
4437 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4440 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4445 /* when one of the probes returns DROPPED, probe_stopped will be
4446 * called and we skip calling the peer getrange function. *buffer should then
4447 * contain a valid buffer */
4448 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4449 res_buf, offset, size, probe_stopped);
4451 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4454 gst_object_ref (peer);
4456 GST_OBJECT_UNLOCK (pad);
4458 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4460 gst_object_unref (peer);
4462 GST_OBJECT_LOCK (pad);
4464 if (pad->priv->using == 0) {
4465 /* pad is not active anymore, trigger idle callbacks */
4466 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4467 probe_stopped_unref, ret);
4470 if (G_UNLIKELY (ret != GST_FLOW_OK))
4471 goto pull_range_failed;
4474 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4475 res_buf, offset, size, probe_stopped_unref);
4477 GST_OBJECT_UNLOCK (pad);
4483 /* ERROR recovery here */
4486 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4487 "pullrange, but pad was flushing");
4488 GST_OBJECT_UNLOCK (pad);
4489 return GST_FLOW_FLUSHING;
4493 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4494 GST_DEBUG_PAD_NAME (pad));
4495 GST_OBJECT_UNLOCK (pad);
4496 return GST_FLOW_ERROR;
4500 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4501 gst_flow_get_name (ret));
4502 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4504 /* the probe filled the buffer and asks us to not forward to the peer
4505 * anymore, we continue with the post probes then */
4506 GST_DEBUG_OBJECT (pad, "handled buffer");
4510 /* no buffer, we are EOS then */
4511 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4515 GST_OBJECT_UNLOCK (pad);
4520 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4521 "pulling range, but it was not linked");
4522 GST_OBJECT_UNLOCK (pad);
4523 return GST_FLOW_NOT_LINKED;
4527 GST_OBJECT_UNLOCK (pad);
4528 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4529 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4530 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4533 probe_stopped_unref:
4535 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4536 "post probe returned %s", gst_flow_get_name (ret));
4537 GST_OBJECT_UNLOCK (pad);
4538 /* if we drop here, it signals EOS */
4539 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4541 if (*buffer == NULL)
4542 gst_buffer_unref (res_buf);
4547 /* must be called with pad object lock */
4548 static GstFlowReturn
4549 store_sticky_event (GstPad * pad, GstEvent * event)
4554 gboolean res = FALSE;
4555 const gchar *name = NULL;
4556 gboolean insert = TRUE;
4558 type = GST_EVENT_TYPE (event);
4560 /* Store all sticky events except SEGMENT/EOS when we're flushing,
4561 * otherwise they can be dropped and nothing would ever resend them.
4562 * Only do that for activated pads though, everything else is a bug!
4564 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4565 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4566 || type == GST_EVENT_EOS))))
4569 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4572 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4573 name = gst_structure_get_name (gst_event_get_structure (event));
4575 events = pad->priv->events;
4578 for (i = 0; i < len; i++) {
4579 PadEvent *ev = &g_array_index (events, PadEvent, i);
4581 if (ev->event == NULL)
4584 if (type == GST_EVENT_TYPE (ev->event)) {
4585 /* matching types, check matching name if needed */
4586 if (name && !gst_event_has_name (ev->event, name))
4590 if ((res = gst_event_replace (&ev->event, event)))
4591 ev->received = FALSE;
4597 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4598 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4599 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4600 * storing the sticky ordered we can check that this is respected. */
4601 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4602 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4604 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4605 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4606 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4607 gst_event_type_get_name (type));
4613 ev.event = gst_event_ref (event);
4614 ev.received = FALSE;
4615 g_array_insert_val (events, i, ev);
4620 pad->priv->events_cookie++;
4621 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4623 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4625 switch (GST_EVENT_TYPE (event)) {
4626 case GST_EVENT_CAPS:
4627 GST_OBJECT_UNLOCK (pad);
4629 GST_DEBUG_OBJECT (pad, "notify caps");
4630 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4632 GST_OBJECT_LOCK (pad);
4638 if (type == GST_EVENT_EOS)
4639 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4641 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4646 GST_DEBUG_OBJECT (pad, "pad is flushing");
4647 return GST_FLOW_FLUSHING;
4651 GST_DEBUG_OBJECT (pad, "pad is EOS");
4652 return GST_FLOW_EOS;
4657 * gst_pad_store_sticky_event:
4659 * @event: a #GstEvent
4661 * Store the sticky @event on @pad
4663 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4664 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4669 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4673 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4674 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4676 GST_OBJECT_LOCK (pad);
4677 ret = store_sticky_event (pad, event);
4678 GST_OBJECT_UNLOCK (pad);
4684 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
4686 PushStickyData *data = user_data;
4688 /* Forward all sticky events before our current one that are pending */
4689 if (ev->event != data->event
4690 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
4691 return push_sticky (pad, ev, data);
4696 /* should be called with pad LOCK */
4697 static GstFlowReturn
4698 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4699 GstPadProbeType type)
4703 GstEventType event_type;
4705 /* Two checks to be made:
4706 * . (un)set the FLUSHING flag for flushing events,
4707 * . handle pad blocking */
4708 event_type = GST_EVENT_TYPE (event);
4709 switch (event_type) {
4710 case GST_EVENT_FLUSH_START:
4711 GST_PAD_SET_FLUSHING (pad);
4713 GST_PAD_BLOCK_BROADCAST (pad);
4714 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4716 case GST_EVENT_FLUSH_STOP:
4717 GST_PAD_UNSET_FLUSHING (pad);
4719 /* Remove sticky EOS events */
4720 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4721 remove_event_by_type (pad, GST_EVENT_EOS);
4722 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4723 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4725 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4729 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4732 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4733 * checked already or this is called as part of pushing sticky events,
4734 * in which case we still want to forward the EOS event downstream.
4737 switch (GST_EVENT_TYPE (event)) {
4738 case GST_EVENT_SEGMENT:
4739 /* pass the adjusted segment event on. We need to do this even if
4740 * there is no peer pad because of the probes. */
4741 event = apply_pad_offset (pad, event);
4743 case GST_EVENT_RECONFIGURE:
4744 if (GST_PAD_IS_SINK (pad))
4745 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4750 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4751 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4756 /* send probes after modifying the events above */
4757 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4759 /* recheck sticky events because the probe might have cause a relink */
4760 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
4761 && (GST_EVENT_IS_SERIALIZED (event)
4762 || GST_EVENT_IS_STICKY (event))) {
4763 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4764 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4766 /* Push all sticky events before our current one
4767 * that have changed */
4768 events_foreach (pad, sticky_changed, &data);
4771 /* now check the peer pad */
4772 peerpad = GST_PAD_PEER (pad);
4773 if (peerpad == NULL)
4776 gst_object_ref (peerpad);
4778 GST_OBJECT_UNLOCK (pad);
4780 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4781 event, GST_EVENT_TYPE_NAME (event), peerpad);
4783 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4785 /* Note: we gave away ownership of the event at this point but we can still
4786 * print the old pointer */
4787 GST_LOG_OBJECT (pad,
4788 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
4789 GST_EVENT_TYPE_NAME (event), peerpad, gst_flow_get_name (ret));
4791 gst_object_unref (peerpad);
4793 GST_OBJECT_LOCK (pad);
4795 if (pad->priv->using == 0) {
4796 /* pad is not active anymore, trigger idle callbacks */
4797 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4798 idle_probe_stopped, ret);
4802 /* ERROR handling */
4805 GST_DEBUG_OBJECT (pad, "We're flushing");
4806 gst_event_unref (event);
4807 return GST_FLOW_FLUSHING;
4811 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4812 gst_event_unref (event);
4815 case GST_FLOW_CUSTOM_SUCCESS:
4816 GST_DEBUG_OBJECT (pad, "dropped event");
4819 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4826 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
4827 gst_event_type_get_name (GST_EVENT_TYPE (event)));
4828 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4829 gst_event_unref (event);
4831 /* unlinked pads should not influence latency configuration */
4832 if (event_type == GST_EVENT_LATENCY)
4835 return GST_FLOW_NOT_LINKED;
4839 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4845 * gst_pad_push_event:
4846 * @pad: a #GstPad to push the event to.
4847 * @event: (transfer full): the #GstEvent to send to the pad.
4849 * Sends the event to the peer of the given pad. This function is
4850 * mainly used by elements to send events to their peer
4853 * This function takes ownership of the provided event so you should
4854 * gst_event_ref() it if you want to reuse the event after this call.
4856 * Returns: TRUE if the event was handled.
4861 gst_pad_push_event (GstPad * pad, GstEvent * event)
4863 gboolean res = FALSE;
4864 GstPadProbeType type;
4865 gboolean sticky, serialized;
4867 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4868 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4870 if (GST_PAD_IS_SRC (pad)) {
4871 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4872 goto wrong_direction;
4873 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4874 } else if (GST_PAD_IS_SINK (pad)) {
4875 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4876 goto wrong_direction;
4877 /* events pushed on sinkpad never are sticky */
4878 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4880 goto unknown_direction;
4882 GST_OBJECT_LOCK (pad);
4883 sticky = GST_EVENT_IS_STICKY (event);
4884 serialized = GST_EVENT_IS_SERIALIZED (event);
4887 /* srcpad sticky events are stored immediately, the received flag is set
4888 * to FALSE and will be set to TRUE when we can successfully push the
4889 * event to the peer pad */
4890 switch (store_sticky_event (pad, event)) {
4891 case GST_FLOW_FLUSHING:
4899 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4900 /* all serialized or sticky events on the srcpad trigger push of
4902 res = (check_sticky (pad, event) == GST_FLOW_OK);
4907 /* other events are pushed right away */
4908 ret = gst_pad_push_event_unchecked (pad, event, type);
4909 /* dropped events by a probe are not an error */
4910 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4912 /* Errors in sticky event pushing are no problem and ignored here
4913 * as they will cause more meaningful errors during data flow.
4914 * For EOS events, that are not followed by data flow, we still
4915 * return FALSE here though.
4917 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4919 gst_event_unref (event);
4921 GST_OBJECT_UNLOCK (pad);
4925 /* ERROR handling */
4928 g_warning ("pad %s:%s pushing %s event in wrong direction",
4929 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4930 gst_event_unref (event);
4935 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4936 gst_event_unref (event);
4941 GST_DEBUG_OBJECT (pad, "We're flushing");
4942 GST_OBJECT_UNLOCK (pad);
4943 gst_event_unref (event);
4948 GST_DEBUG_OBJECT (pad, "We're EOS");
4949 GST_OBJECT_UNLOCK (pad);
4950 gst_event_unref (event);
4955 /* Check if we can call the event function with the given event */
4956 static GstFlowReturn
4957 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4961 switch (GST_EVENT_TYPE (event)) {
4962 case GST_EVENT_CAPS:
4964 /* backwards compatibility mode for caps */
4965 gst_event_parse_caps (event, &caps);
4967 if (!gst_pad_query_accept_caps (pad, caps))
4979 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4980 "caps %" GST_PTR_FORMAT " not accepted", caps);
4981 return GST_FLOW_NOT_NEGOTIATED;
4985 static GstFlowReturn
4986 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4987 GstPadProbeType type)
4990 GstEventType event_type;
4991 gboolean serialized, need_unlock = FALSE, sticky;
4992 GstPadEventFunction eventfunc;
4995 GST_OBJECT_LOCK (pad);
4996 if (GST_PAD_IS_SINK (pad))
4997 serialized = GST_EVENT_IS_SERIALIZED (event);
5000 sticky = GST_EVENT_IS_STICKY (event);
5001 event_type = GST_EVENT_TYPE (event);
5002 switch (event_type) {
5003 case GST_EVENT_FLUSH_START:
5004 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5005 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5007 /* can't even accept a flush begin event when flushing */
5008 if (GST_PAD_IS_FLUSHING (pad))
5011 GST_PAD_SET_FLUSHING (pad);
5012 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5014 case GST_EVENT_FLUSH_STOP:
5015 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
5016 GST_PAD_UNSET_FLUSHING (pad);
5017 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5019 /* Remove pending EOS events */
5020 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5021 remove_event_by_type (pad, GST_EVENT_EOS);
5022 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5023 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5025 GST_OBJECT_UNLOCK (pad);
5026 /* grab stream lock */
5027 GST_PAD_STREAM_LOCK (pad);
5029 GST_OBJECT_LOCK (pad);
5030 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5033 case GST_EVENT_RECONFIGURE:
5034 if (GST_PAD_IS_SRC (pad))
5035 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5037 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5038 "have event type %" GST_PTR_FORMAT, event);
5040 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5044 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5047 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5048 GST_OBJECT_UNLOCK (pad);
5049 GST_PAD_STREAM_LOCK (pad);
5051 GST_OBJECT_LOCK (pad);
5052 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5055 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5059 switch (GST_EVENT_TYPE (event)) {
5060 case GST_EVENT_SEGMENT:
5061 event = apply_pad_offset (pad, event);
5069 /* now do the probe */
5071 type | GST_PAD_PROBE_TYPE_PUSH |
5072 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5074 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5076 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5079 ACQUIRE_PARENT (pad, parent, no_parent);
5080 GST_OBJECT_UNLOCK (pad);
5082 ret = pre_eventfunc_check (pad, event);
5083 if (G_UNLIKELY (ret != GST_FLOW_OK))
5084 goto precheck_failed;
5087 gst_event_ref (event);
5089 if (eventfunc (pad, parent, event)) {
5092 /* something went wrong */
5093 switch (event_type) {
5094 case GST_EVENT_CAPS:
5095 ret = GST_FLOW_NOT_NEGOTIATED;
5098 ret = GST_FLOW_ERROR;
5102 RELEASE_PARENT (parent);
5104 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5107 if (ret == GST_FLOW_OK) {
5108 GST_OBJECT_LOCK (pad);
5109 /* after the event function accepted the event, we can store the sticky
5110 * event on the pad */
5111 switch (store_sticky_event (pad, event)) {
5112 case GST_FLOW_FLUSHING:
5119 GST_OBJECT_UNLOCK (pad);
5121 gst_event_unref (event);
5125 GST_PAD_STREAM_UNLOCK (pad);
5129 /* ERROR handling */
5132 GST_OBJECT_UNLOCK (pad);
5134 GST_PAD_STREAM_UNLOCK (pad);
5135 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5136 "Received event on flushing pad. Discarding");
5137 gst_event_unref (event);
5138 return GST_FLOW_FLUSHING;
5142 GST_OBJECT_UNLOCK (pad);
5144 GST_PAD_STREAM_UNLOCK (pad);
5145 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5146 "Received event on EOS pad. Discarding");
5147 gst_event_unref (event);
5148 return GST_FLOW_EOS;
5152 GST_OBJECT_UNLOCK (pad);
5154 GST_PAD_STREAM_UNLOCK (pad);
5155 gst_event_unref (event);
5158 case GST_FLOW_CUSTOM_SUCCESS:
5159 GST_DEBUG_OBJECT (pad, "dropped event");
5163 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5170 g_warning ("pad %s:%s has no event handler, file a bug.",
5171 GST_DEBUG_PAD_NAME (pad));
5172 GST_OBJECT_UNLOCK (pad);
5174 GST_PAD_STREAM_UNLOCK (pad);
5175 gst_event_unref (event);
5176 return GST_FLOW_NOT_SUPPORTED;
5180 GST_DEBUG_OBJECT (pad, "no parent");
5181 GST_OBJECT_UNLOCK (pad);
5183 GST_PAD_STREAM_UNLOCK (pad);
5184 gst_event_unref (event);
5185 return GST_FLOW_FLUSHING;
5189 GST_DEBUG_OBJECT (pad, "pre event check failed");
5190 RELEASE_PARENT (parent);
5192 GST_PAD_STREAM_UNLOCK (pad);
5193 gst_event_unref (event);
5199 * gst_pad_send_event:
5200 * @pad: a #GstPad to send the event to.
5201 * @event: (transfer full): the #GstEvent to send to the pad.
5203 * Sends the event to the pad. This function can be used
5204 * by applications to send events in the pipeline.
5206 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5207 * sink pad, @event should be a downstream event. For example, you would not
5208 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5209 * Furthermore, some downstream events have to be serialized with data flow,
5210 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5211 * the event needs to be serialized with data flow, this function will take the
5212 * pad's stream lock while calling its event function.
5214 * To find out whether an event type is upstream, downstream, or downstream and
5215 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5216 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5217 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5218 * plugin doesn't need to bother itself with this information; the core handles
5219 * all necessary locks and checks.
5221 * This function takes ownership of the provided event so you should
5222 * gst_event_ref() it if you want to reuse the event after this call.
5224 * Returns: TRUE if the event was handled.
5227 gst_pad_send_event (GstPad * pad, GstEvent * event)
5230 GstPadProbeType type;
5232 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5233 g_return_val_if_fail (event != NULL, FALSE);
5235 if (GST_PAD_IS_SINK (pad)) {
5236 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5237 goto wrong_direction;
5238 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5239 } else if (GST_PAD_IS_SRC (pad)) {
5240 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5241 goto wrong_direction;
5242 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5244 goto unknown_direction;
5246 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5253 /* ERROR handling */
5256 g_warning ("pad %s:%s sending %s event in wrong direction",
5257 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5258 gst_event_unref (event);
5263 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5264 gst_event_unref (event);
5270 * gst_pad_set_element_private:
5271 * @pad: the #GstPad to set the private data of.
5272 * @priv: The private data to attach to the pad.
5274 * Set the given private data gpointer on the pad.
5275 * This function can only be used by the element that owns the pad.
5276 * No locking is performed in this function.
5279 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5281 pad->element_private = priv;
5285 * gst_pad_get_element_private:
5286 * @pad: the #GstPad to get the private data of.
5288 * Gets the private data of a pad.
5289 * No locking is performed in this function.
5291 * Returns: (transfer none): a #gpointer to the private data.
5294 gst_pad_get_element_private (GstPad * pad)
5296 return pad->element_private;
5300 * gst_pad_get_sticky_event:
5301 * @pad: the #GstPad to get the event from.
5302 * @event_type: the #GstEventType that should be retrieved.
5303 * @idx: the index of the event
5305 * Returns a new reference of the sticky event of type @event_type
5308 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
5309 * event of @event_type was on @pad. Unref after usage.
5312 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5314 GstEvent *event = NULL;
5317 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5318 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5320 GST_OBJECT_LOCK (pad);
5321 ev = find_event_by_type (pad, event_type, idx);
5322 if (ev && (event = ev->event))
5323 gst_event_ref (event);
5324 GST_OBJECT_UNLOCK (pad);
5331 GstPadStickyEventsForeachFunction func;
5336 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5338 ForeachDispatch *data = user_data;
5339 gboolean ret = TRUE;
5342 GST_OBJECT_UNLOCK (pad);
5344 ret = data->func (pad, &ev->event, data->user_data);
5346 GST_OBJECT_LOCK (pad);
5353 * gst_pad_sticky_events_foreach:
5354 * @pad: the #GstPad that should be used for iteration.
5355 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5356 * should be called for every event.
5357 * @user_data: (closure): the optional user data.
5359 * Iterates all sticky events on @pad and calls @foreach_func for every
5360 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5363 gst_pad_sticky_events_foreach (GstPad * pad,
5364 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5366 ForeachDispatch data;
5368 g_return_if_fail (GST_IS_PAD (pad));
5369 g_return_if_fail (foreach_func != NULL);
5371 data.func = foreach_func;
5372 data.user_data = user_data;
5374 GST_OBJECT_LOCK (pad);
5375 events_foreach (pad, foreach_dispatch_function, &data);
5376 GST_OBJECT_UNLOCK (pad);
5380 do_stream_status (GstPad * pad, GstStreamStatusType type,
5381 GThread * thread, GstTask * task)
5385 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5387 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5388 if (GST_IS_ELEMENT (parent)) {
5389 GstMessage *message;
5390 GValue value = { 0 };
5392 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5393 gchar *tname, *ename, *pname;
5395 /* create a good task name */
5396 ename = gst_element_get_name (parent);
5397 pname = gst_pad_get_name (pad);
5398 tname = g_strdup_printf ("%s:%s", ename, pname);
5402 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5406 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5409 g_value_init (&value, GST_TYPE_TASK);
5410 g_value_set_object (&value, task);
5411 gst_message_set_stream_status_object (message, &value);
5412 g_value_unset (&value);
5414 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5415 gst_element_post_message (parent, message);
5417 gst_object_unref (parent);
5422 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5424 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5429 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5431 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5436 * gst_pad_start_task:
5437 * @pad: the #GstPad to start the task of
5438 * @func: the task function to call
5439 * @user_data: user data passed to the task function
5440 * @notify: called when @user_data is no longer referenced
5442 * Starts a task that repeatedly calls @func with @user_data. This function
5443 * is mostly used in pad activation functions to start the dataflow.
5444 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5445 * before @func is called.
5447 * Returns: a %TRUE if the task could be started.
5450 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5451 GDestroyNotify notify)
5456 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5457 g_return_val_if_fail (func != NULL, FALSE);
5459 GST_DEBUG_OBJECT (pad, "start task");
5461 GST_OBJECT_LOCK (pad);
5462 task = GST_PAD_TASK (pad);
5464 task = gst_task_new (func, user_data, notify);
5465 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5466 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5467 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5468 GST_INFO_OBJECT (pad, "created task %p", task);
5469 GST_PAD_TASK (pad) = task;
5470 gst_object_ref (task);
5471 /* release lock to post the message */
5472 GST_OBJECT_UNLOCK (pad);
5474 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5476 gst_object_unref (task);
5478 GST_OBJECT_LOCK (pad);
5479 /* nobody else is supposed to have changed the pad now */
5480 if (GST_PAD_TASK (pad) != task)
5481 goto concurrent_stop;
5483 res = gst_task_set_state (task, GST_TASK_STARTED);
5484 GST_OBJECT_UNLOCK (pad);
5491 GST_OBJECT_UNLOCK (pad);
5497 * gst_pad_pause_task:
5498 * @pad: the #GstPad to pause the task of
5500 * Pause the task of @pad. This function will also wait until the
5501 * function executed by the task is finished if this function is not
5502 * called from the task function.
5504 * Returns: a TRUE if the task could be paused or FALSE when the pad
5508 gst_pad_pause_task (GstPad * pad)
5513 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5515 GST_DEBUG_OBJECT (pad, "pause task");
5517 GST_OBJECT_LOCK (pad);
5518 task = GST_PAD_TASK (pad);
5521 res = gst_task_set_state (task, GST_TASK_PAUSED);
5522 GST_OBJECT_UNLOCK (pad);
5524 /* wait for task function to finish, this lock is recursive so it does nothing
5525 * when the pause is called from the task itself */
5526 GST_PAD_STREAM_LOCK (pad);
5527 GST_PAD_STREAM_UNLOCK (pad);
5533 GST_DEBUG_OBJECT (pad, "pad has no task");
5534 GST_OBJECT_UNLOCK (pad);
5540 * gst_pad_stop_task:
5541 * @pad: the #GstPad to stop the task of
5543 * Stop the task of @pad. This function will also make sure that the
5544 * function executed by the task will effectively stop if not called
5545 * from the GstTaskFunction.
5547 * This function will deadlock if called from the GstTaskFunction of
5548 * the task. Use gst_task_pause() instead.
5550 * Regardless of whether the pad has a task, the stream lock is acquired and
5551 * released so as to ensure that streaming through this pad has finished.
5553 * Returns: a TRUE if the task could be stopped or FALSE on error.
5556 gst_pad_stop_task (GstPad * pad)
5561 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5563 GST_DEBUG_OBJECT (pad, "stop task");
5565 GST_OBJECT_LOCK (pad);
5566 task = GST_PAD_TASK (pad);
5569 GST_PAD_TASK (pad) = NULL;
5570 res = gst_task_set_state (task, GST_TASK_STOPPED);
5571 GST_OBJECT_UNLOCK (pad);
5573 GST_PAD_STREAM_LOCK (pad);
5574 GST_PAD_STREAM_UNLOCK (pad);
5576 if (!gst_task_join (task))
5579 gst_object_unref (task);
5585 GST_DEBUG_OBJECT (pad, "no task");
5586 GST_OBJECT_UNLOCK (pad);
5588 GST_PAD_STREAM_LOCK (pad);
5589 GST_PAD_STREAM_UNLOCK (pad);
5591 /* this is not an error */
5596 /* this is bad, possibly the application tried to join the task from
5597 * the task's thread. We install the task again so that it will be stopped
5598 * again from the right thread next time hopefully. */
5599 GST_OBJECT_LOCK (pad);
5600 GST_DEBUG_OBJECT (pad, "join failed");
5601 /* we can only install this task if there was no other task */
5602 if (GST_PAD_TASK (pad) == NULL)
5603 GST_PAD_TASK (pad) = task;
5604 GST_OBJECT_UNLOCK (pad);
5611 * gst_pad_probe_info_get_event:
5612 * @info: a #GstPadProbeInfo
5614 * Returns: (transfer none): The #GstEvent from the probe
5618 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5620 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5621 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5623 return GST_PAD_PROBE_INFO_EVENT (info);
5628 * gst_pad_probe_info_get_query:
5629 * @info: a #GstPadProbeInfo
5631 * Returns: (transfer none): The #GstQuery from the probe
5635 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5637 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5638 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5640 return GST_PAD_PROBE_INFO_QUERY (info);
5644 * gst_pad_probe_info_get_buffer:
5645 * @info: a #GstPadProbeInfo
5647 * Returns: (transfer none): The #GstBuffer from the probe
5651 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5653 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5655 return GST_PAD_PROBE_INFO_BUFFER (info);
5659 * gst_pad_probe_info_get_bufferlist:
5660 * @info: a #GstPadProbeInfo
5662 * Returns: (transfer none): The #GstBufferlist from the probe
5666 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5668 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5670 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);