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., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, 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 with gst_element_get_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
141 guint probe_list_cookie;
151 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
156 GstPadProbeInfo *info;
163 static void gst_pad_dispose (GObject * object);
164 static void gst_pad_finalize (GObject * object);
165 static void gst_pad_set_property (GObject * object, guint prop_id,
166 const GValue * value, GParamSpec * pspec);
167 static void gst_pad_get_property (GObject * object, guint prop_id,
168 GValue * value, GParamSpec * pspec);
170 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
171 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
172 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
173 GstObject * parent, GstBufferList * list);
175 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
176 GstEvent * event, GstPadProbeType type);
177 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
178 GstEvent * event, GstPadProbeType type);
180 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
182 static GParamSpec *pspec_caps = NULL;
184 /* quarks for probe signals */
185 static GQuark buffer_quark;
186 static GQuark buffer_list_quark;
187 static GQuark event_quark;
196 static GstFlowQuarks flow_quarks[] = {
197 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
198 {GST_FLOW_OK, "ok", 0},
199 {GST_FLOW_NOT_LINKED, "not-linked", 0},
200 {GST_FLOW_FLUSHING, "flushing", 0},
201 {GST_FLOW_EOS, "eos", 0},
202 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
203 {GST_FLOW_ERROR, "error", 0},
204 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
205 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
210 * @ret: a #GstFlowReturn to get the name of.
212 * Gets a string representing the given flow return.
214 * Returns: a static string with the name of the flow return.
217 gst_flow_get_name (GstFlowReturn ret)
221 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
223 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
224 if (ret == flow_quarks[i].ret)
225 return flow_quarks[i].name;
232 * @ret: a #GstFlowReturn to get the quark of.
234 * Get the unique quark for the given GstFlowReturn.
236 * Returns: the quark associated with the flow return or 0 if an
237 * invalid return was specified.
240 gst_flow_to_quark (GstFlowReturn ret)
244 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
246 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
247 if (ret == flow_quarks[i].ret)
248 return flow_quarks[i].quark;
257 buffer_quark = g_quark_from_static_string ("buffer"); \
258 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
259 event_quark = g_quark_from_static_string ("event"); \
261 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
262 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
265 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
266 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
269 #define gst_pad_parent_class parent_class
270 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
273 gst_pad_class_init (GstPadClass * klass)
275 GObjectClass *gobject_class;
276 GstObjectClass *gstobject_class;
278 gobject_class = G_OBJECT_CLASS (klass);
279 gstobject_class = GST_OBJECT_CLASS (klass);
281 g_type_class_add_private (klass, sizeof (GstPadPrivate));
283 gobject_class->dispose = gst_pad_dispose;
284 gobject_class->finalize = gst_pad_finalize;
285 gobject_class->set_property = gst_pad_set_property;
286 gobject_class->get_property = gst_pad_get_property;
290 * @pad: the pad that emitted the signal
291 * @peer: the peer pad that has been connected
293 * Signals that a pad has been linked to the peer pad.
295 gst_pad_signals[PAD_LINKED] =
296 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
297 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
298 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
301 * @pad: the pad that emitted the signal
302 * @peer: the peer pad that has been disconnected
304 * Signals that a pad has been unlinked from the peer pad.
306 gst_pad_signals[PAD_UNLINKED] =
307 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
308 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
309 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
311 pspec_caps = g_param_spec_boxed ("caps", "Caps",
312 "The capabilities of the pad", GST_TYPE_CAPS,
313 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
314 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
316 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
317 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
318 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
319 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
321 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
322 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
323 g_param_spec_object ("template", "Template",
324 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
325 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
327 gstobject_class->path_string_separator = ".";
329 /* Register common function pointer descriptions */
330 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
331 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
332 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
333 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
334 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
338 gst_pad_init (GstPad * pad)
340 pad->priv = GST_PAD_GET_PRIVATE (pad);
342 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
344 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
345 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
346 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
347 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
348 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
350 GST_PAD_SET_FLUSHING (pad);
352 g_rec_mutex_init (&pad->stream_rec_lock);
354 g_cond_init (&pad->block_cond);
356 g_hook_list_init (&pad->probes, sizeof (GstProbe));
358 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
361 /* called when setting the pad inactive. It removes all sticky events from
364 remove_events (GstPad * pad)
369 events = pad->priv->events;
372 for (i = 0; i < len; i++) {
373 PadEvent *ev = &g_array_index (events, PadEvent, i);
374 gst_event_unref (ev->event);
376 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
377 g_array_set_size (events, 0);
378 pad->priv->events_cookie++;
382 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
388 events = pad->priv->events;
391 for (i = 0; i < len; i++) {
392 ev = &g_array_index (events, PadEvent, i);
393 if (ev->event == NULL)
396 if (GST_EVENT_TYPE (ev->event) == type) {
408 find_event (GstPad * pad, GstEvent * event)
414 events = pad->priv->events;
417 for (i = 0; i < len; i++) {
418 ev = &g_array_index (events, PadEvent, i);
419 if (event == ev->event)
428 remove_event_by_type (GstPad * pad, GstEventType type)
434 events = pad->priv->events;
439 ev = &g_array_index (events, PadEvent, i);
440 if (ev->event == NULL)
443 if (GST_EVENT_TYPE (ev->event) != type)
446 gst_event_unref (ev->event);
447 g_array_remove_index (events, i);
449 pad->priv->events_cookie++;
457 /* check all events on srcpad against those on sinkpad. All events that are not
458 * on sinkpad are marked as received=FALSE and the PENDING_EVENTS is set on the
459 * srcpad so that the events will be sent next time */
461 schedule_events (GstPad * srcpad, GstPad * sinkpad)
466 gboolean pending = FALSE;
468 events = srcpad->priv->events;
471 for (i = 0; i < len; i++) {
472 ev = &g_array_index (events, PadEvent, i);
473 if (ev->event == NULL)
476 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
477 ev->received = FALSE;
482 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
485 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
488 /* should be called with pad LOCK */
490 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
497 events = pad->priv->events;
500 cookie = pad->priv->events_cookie;
504 PadEvent *ev, ev_ret;
506 ev = &g_array_index (events, PadEvent, i);
507 if (G_UNLIKELY (ev->event == NULL))
510 /* take aditional ref, func might release the lock */
511 ev_ret.event = gst_event_ref (ev->event);
512 ev_ret.received = ev->received;
514 ret = func (pad, &ev_ret, user_data);
516 /* recheck the cookie, lock might have been released and the list could have
518 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
519 if (G_LIKELY (ev_ret.event))
520 gst_event_unref (ev_ret.event);
524 /* store the received state */
525 ev->received = ev_ret.received;
527 /* if the event changed, we need to do something */
528 if (G_UNLIKELY (ev->event != ev_ret.event)) {
529 if (G_UNLIKELY (ev_ret.event == NULL)) {
530 /* function unreffed and set the event to NULL, remove it */
531 g_array_remove_index (events, i);
533 cookie = ++pad->priv->events_cookie;
536 /* function gave a new event for us */
537 gst_event_take (&ev->event, ev_ret.event);
540 /* just unref, nothing changed */
541 gst_event_unref (ev_ret.event);
550 /* should be called with LOCK */
552 apply_pad_offset (GstPad * pad, GstEvent * event)
554 /* check if we need to adjust the segment */
555 if (pad->offset != 0) {
558 /* copy segment values */
559 gst_event_copy_segment (event, &segment);
560 gst_event_unref (event);
562 /* adjust and make a new event with the offset applied */
563 segment.base += pad->offset;
564 event = gst_event_new_segment (&segment);
569 /* should be called with the OBJECT_LOCK */
571 get_pad_caps (GstPad * pad)
573 GstCaps *caps = NULL;
576 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
578 gst_event_parse_caps (ev->event, &caps);
584 gst_pad_dispose (GObject * object)
586 GstPad *pad = GST_PAD_CAST (object);
589 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
591 /* unlink the peer pad */
592 if ((peer = gst_pad_get_peer (pad))) {
593 /* window for MT unsafeness, someone else could unlink here
594 * and then we call unlink with wrong pads. The unlink
595 * function would catch this and safely return failed. */
596 if (GST_PAD_IS_SRC (pad))
597 gst_pad_unlink (pad, peer);
599 gst_pad_unlink (peer, pad);
601 gst_object_unref (peer);
604 gst_pad_set_pad_template (pad, NULL);
608 g_hook_list_clear (&pad->probes);
610 G_OBJECT_CLASS (parent_class)->dispose (object);
614 gst_pad_finalize (GObject * object)
616 GstPad *pad = GST_PAD_CAST (object);
619 /* in case the task is still around, clean it up */
620 if ((task = GST_PAD_TASK (pad))) {
621 gst_task_join (task);
622 GST_PAD_TASK (pad) = NULL;
623 gst_object_unref (task);
626 if (pad->activatenotify)
627 pad->activatenotify (pad->activatedata);
628 if (pad->activatemodenotify)
629 pad->activatemodenotify (pad->activatemodedata);
631 pad->linknotify (pad->linkdata);
632 if (pad->unlinknotify)
633 pad->unlinknotify (pad->unlinkdata);
634 if (pad->chainnotify)
635 pad->chainnotify (pad->chaindata);
636 if (pad->chainlistnotify)
637 pad->chainlistnotify (pad->chainlistdata);
638 if (pad->getrangenotify)
639 pad->getrangenotify (pad->getrangedata);
640 if (pad->eventnotify)
641 pad->eventnotify (pad->eventdata);
642 if (pad->querynotify)
643 pad->querynotify (pad->querydata);
644 if (pad->iterintlinknotify)
645 pad->iterintlinknotify (pad->iterintlinkdata);
647 g_rec_mutex_clear (&pad->stream_rec_lock);
648 g_cond_clear (&pad->block_cond);
649 g_array_free (pad->priv->events, TRUE);
651 G_OBJECT_CLASS (parent_class)->finalize (object);
655 gst_pad_set_property (GObject * object, guint prop_id,
656 const GValue * value, GParamSpec * pspec)
658 g_return_if_fail (GST_IS_PAD (object));
661 case PAD_PROP_DIRECTION:
662 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
664 case PAD_PROP_TEMPLATE:
665 gst_pad_set_pad_template (GST_PAD_CAST (object),
666 (GstPadTemplate *) g_value_get_object (value));
669 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
675 gst_pad_get_property (GObject * object, guint prop_id,
676 GValue * value, GParamSpec * pspec)
678 g_return_if_fail (GST_IS_PAD (object));
682 GST_OBJECT_LOCK (object);
683 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
684 GST_OBJECT_UNLOCK (object);
686 case PAD_PROP_DIRECTION:
687 g_value_set_enum (value, GST_PAD_DIRECTION (object));
689 case PAD_PROP_TEMPLATE:
690 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
693 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
700 * @name: the name of the new pad.
701 * @direction: the #GstPadDirection of the pad.
703 * Creates a new pad with the given name in the given direction.
704 * If name is NULL, a guaranteed unique name (across all pads)
706 * This function makes a copy of the name so you can safely free the name.
708 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
713 gst_pad_new (const gchar * name, GstPadDirection direction)
715 return g_object_new (GST_TYPE_PAD,
716 "name", name, "direction", direction, NULL);
720 * gst_pad_new_from_template:
721 * @templ: the pad template to use
722 * @name: the name of the element
724 * Creates a new pad with the given name from the given template.
725 * If name is NULL, a guaranteed unique name (across all pads)
727 * This function makes a copy of the name so you can safely free the name.
729 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
732 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
734 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
736 return g_object_new (GST_TYPE_PAD,
737 "name", name, "direction", templ->direction, "template", templ, NULL);
741 * gst_pad_new_from_static_template:
742 * @templ: the #GstStaticPadTemplate to use
743 * @name: the name of the element
745 * Creates a new pad with the given name from the given static template.
746 * If name is NULL, a guaranteed unique name (across all pads)
748 * This function makes a copy of the name so you can safely free the name.
750 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
753 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
757 GstPadTemplate *template;
759 template = gst_static_pad_template_get (templ);
760 pad = gst_pad_new_from_template (template, name);
761 gst_object_unref (template);
765 #define ACQUIRE_PARENT(pad, parent, label) \
767 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
768 gst_object_ref (parent); \
769 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
773 #define RELEASE_PARENT(parent) \
775 if (G_LIKELY (parent)) \
776 gst_object_unref (parent); \
780 * gst_pad_get_direction:
781 * @pad: a #GstPad to get the direction of.
783 * Gets the direction of the pad. The direction of the pad is
784 * decided at construction time so this function does not take
787 * Returns: the #GstPadDirection of the pad.
792 gst_pad_get_direction (GstPad * pad)
794 GstPadDirection result;
796 /* PAD_UNKNOWN is a little silly but we need some sort of
797 * error return value */
798 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
800 result = GST_PAD_DIRECTION (pad);
806 gst_pad_activate_default (GstPad * pad, GstObject * parent)
808 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
812 pre_activate (GstPad * pad, GstPadMode new_mode)
815 case GST_PAD_MODE_NONE:
816 GST_OBJECT_LOCK (pad);
817 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
818 GST_PAD_SET_FLUSHING (pad);
819 GST_PAD_MODE (pad) = new_mode;
820 /* unlock blocked pads so element can resume and stop */
821 GST_PAD_BLOCK_BROADCAST (pad);
822 GST_OBJECT_UNLOCK (pad);
824 case GST_PAD_MODE_PUSH:
825 case GST_PAD_MODE_PULL:
826 GST_OBJECT_LOCK (pad);
827 GST_DEBUG_OBJECT (pad, "setting PAD_MODE %d, unset flushing", new_mode);
828 GST_PAD_UNSET_FLUSHING (pad);
829 GST_PAD_MODE (pad) = new_mode;
830 if (GST_PAD_IS_SINK (pad)) {
832 /* make sure the peer src pad sends us all events */
833 if ((peer = GST_PAD_PEER (pad))) {
834 gst_object_ref (peer);
835 GST_OBJECT_UNLOCK (pad);
837 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
838 GST_DEBUG_PAD_NAME (peer));
840 GST_OBJECT_LOCK (peer);
841 schedule_events (peer, NULL);
842 GST_OBJECT_UNLOCK (peer);
844 gst_object_unref (peer);
846 GST_OBJECT_UNLOCK (pad);
849 GST_OBJECT_UNLOCK (pad);
856 post_activate (GstPad * pad, GstPadMode new_mode)
859 case GST_PAD_MODE_NONE:
860 /* ensures that streaming stops */
861 GST_PAD_STREAM_LOCK (pad);
862 GST_DEBUG_OBJECT (pad, "stopped streaming");
863 GST_OBJECT_LOCK (pad);
865 GST_OBJECT_UNLOCK (pad);
866 GST_PAD_STREAM_UNLOCK (pad);
868 case GST_PAD_MODE_PUSH:
869 case GST_PAD_MODE_PULL:
876 * gst_pad_set_active:
877 * @pad: the #GstPad to activate or deactivate.
878 * @active: whether or not the pad should be active.
880 * Activates or deactivates the given pad.
881 * Normally called from within core state change functions.
883 * If @active, makes sure the pad is active. If it is already active, either in
884 * push or pull mode, just return. Otherwise dispatches to the pad's activate
885 * function to perform the actual activation.
887 * If not @active, checks the pad's current mode and calls
888 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
891 * Returns: #TRUE if the operation was successful.
896 gst_pad_set_active (GstPad * pad, gboolean active)
900 gboolean ret = FALSE;
902 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
904 GST_OBJECT_LOCK (pad);
905 old = GST_PAD_MODE (pad);
906 ACQUIRE_PARENT (pad, parent, no_parent);
907 GST_OBJECT_UNLOCK (pad);
910 if (old == GST_PAD_MODE_NONE) {
911 GST_DEBUG_OBJECT (pad, "activating pad from none");
912 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
914 GST_DEBUG_OBJECT (pad, "pad was active in mode %d", old);
918 if (old == GST_PAD_MODE_NONE) {
919 GST_DEBUG_OBJECT (pad, "pad was inactive");
922 GST_DEBUG_OBJECT (pad, "deactivating pad from mode %d", old);
923 ret = gst_pad_activate_mode (pad, old, FALSE);
927 RELEASE_PARENT (parent);
929 if (G_UNLIKELY (!ret))
933 GST_OBJECT_LOCK (pad);
934 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
935 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
936 GST_OBJECT_UNLOCK (pad);
943 GST_DEBUG_OBJECT (pad, "no parent");
944 GST_OBJECT_UNLOCK (pad);
949 GST_OBJECT_LOCK (pad);
951 g_critical ("Failed to deactivate pad %s:%s, very bad",
952 GST_DEBUG_PAD_NAME (pad));
954 GST_WARNING_OBJECT (pad, "Failed to activate pad");
956 GST_OBJECT_UNLOCK (pad);
962 * gst_pad_activate_mode:
963 * @pad: the #GstPad to activate or deactivate.
964 * @mode: the requested activation mode
965 * @active: whether or not the pad should be active.
967 * Activates or deactivates the given pad in @mode via dispatching to the
968 * pad's activatemodefunc. For use from within pad activation functions only.
970 * If you don't know what this is, you probably don't want to call it.
972 * Returns: TRUE if the operation was successful.
977 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
979 gboolean res = FALSE;
985 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
987 GST_OBJECT_LOCK (pad);
988 old = GST_PAD_MODE (pad);
989 dir = GST_PAD_DIRECTION (pad);
990 ACQUIRE_PARENT (pad, parent, no_parent);
991 GST_OBJECT_UNLOCK (pad);
993 new = active ? mode : GST_PAD_MODE_NONE;
998 if (active && old != mode) {
999 /* pad was activate in the wrong direction, deactivate it
1000 * and reactivate it in the requested mode */
1001 GST_DEBUG_OBJECT (pad, "deactivating pad from mode %d", old);
1002 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1003 goto deactivate_failed;
1007 case GST_PAD_MODE_PULL:
1009 if (dir == GST_PAD_SINK) {
1010 if ((peer = gst_pad_get_peer (pad))) {
1011 GST_DEBUG_OBJECT (pad, "calling peer");
1012 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1014 gst_object_unref (peer);
1016 /* there is no peer, this is only fatal when we activate. When we
1017 * deactivate, we must assume the application has unlinked the peer and
1018 * will deactivate it eventually. */
1022 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1025 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1026 goto failure; /* Can't activate pull on a src without a
1027 getrange function */
1035 pre_activate (pad, new);
1037 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1038 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1042 /* can happen for sinks of passthrough elements */
1045 post_activate (pad, new);
1047 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in mode %d",
1048 active ? "activated" : "deactivated", mode);
1053 RELEASE_PARENT (parent);
1059 GST_DEBUG_OBJECT (pad, "no parent");
1060 GST_OBJECT_UNLOCK (pad);
1065 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in mode %d",
1066 active ? "activated" : "deactivated", mode);
1071 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1072 "failed to %s in switch to mode %d from mode %d",
1073 (active ? "activate" : "deactivate"), mode, old);
1078 GST_OBJECT_LOCK (peer);
1079 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1080 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1081 GST_OBJECT_UNLOCK (peer);
1082 gst_object_unref (peer);
1087 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1088 "pad in pull mode");
1093 GST_OBJECT_LOCK (pad);
1094 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in mode %d",
1095 active ? "activate" : "deactivate", mode);
1096 GST_PAD_SET_FLUSHING (pad);
1097 GST_PAD_MODE (pad) = old;
1098 GST_OBJECT_UNLOCK (pad);
1104 * gst_pad_is_active:
1105 * @pad: the #GstPad to query
1107 * Query if a pad is active
1109 * Returns: TRUE if the pad is active.
1114 gst_pad_is_active (GstPad * pad)
1116 gboolean result = FALSE;
1118 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1120 GST_OBJECT_LOCK (pad);
1121 result = GST_PAD_IS_ACTIVE (pad);
1122 GST_OBJECT_UNLOCK (pad);
1128 * gst_pad_add_probe:
1129 * @pad: the #GstPad to add the probe to
1130 * @mask: the probe mask
1131 * @callback: #GstPadProbeCallback that will be called with notifications of
1133 * @user_data: (closure): user data passed to the callback
1134 * @destroy_data: #GDestroyNotify for user_data
1136 * Be notified of different states of pads. The provided callback is called for
1137 * every state that matches @mask.
1139 * Returns: an id or 0 on error. The id can be used to remove the probe with
1140 * gst_pad_remove_probe().
1145 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1146 GstPadProbeCallback callback, gpointer user_data,
1147 GDestroyNotify destroy_data)
1152 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1153 g_return_val_if_fail (mask != 0, 0);
1155 GST_OBJECT_LOCK (pad);
1157 /* make a new probe */
1158 hook = g_hook_alloc (&pad->probes);
1160 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1163 /* when no contraints are given for the types, assume all types are
1165 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1166 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1167 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1168 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1170 /* store our flags and other fields */
1171 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1172 hook->func = callback;
1173 hook->data = user_data;
1174 hook->destroy = destroy_data;
1175 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1178 g_hook_prepend (&pad->probes, hook);
1180 /* incremenent cookie so that the new hook get's called */
1181 pad->priv->probe_list_cookie++;
1183 /* get the id of the hook, we return this and it can be used to remove the
1185 res = hook->hook_id;
1187 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1189 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1190 /* we have a block probe */
1192 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1193 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1194 "now %d blocking probes", pad->num_blocked);
1197 /* call the callback if we need to be called for idle callbacks */
1198 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1199 if (pad->priv->using > 0) {
1200 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1201 * flag above, the last thread to leave the push will do the callback. New
1202 * threads going into the push will block. */
1203 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1204 "pad is in use, delay idle callback");
1205 GST_OBJECT_UNLOCK (pad);
1207 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1209 /* the pad is idle now, we can signal the idle callback now */
1210 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1211 "pad is idle, trigger idle callback");
1212 GST_OBJECT_UNLOCK (pad);
1214 callback (pad, &info, user_data);
1217 GST_OBJECT_UNLOCK (pad);
1223 cleanup_hook (GstPad * pad, GHook * hook)
1225 GstPadProbeType type;
1227 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1229 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1230 /* unblock when we remove the last blocking probe */
1232 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1234 if (pad->num_blocked == 0) {
1235 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1236 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1237 GST_PAD_BLOCK_BROADCAST (pad);
1240 g_hook_destroy_link (&pad->probes, hook);
1245 * gst_pad_remove_probe:
1246 * @pad: the #GstPad with the probe
1247 * @id: the probe id to remove
1249 * Remove the probe with @id from @pad.
1254 gst_pad_remove_probe (GstPad * pad, gulong id)
1258 g_return_if_fail (GST_IS_PAD (pad));
1260 GST_OBJECT_LOCK (pad);
1262 hook = g_hook_get (&pad->probes, id);
1266 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1268 cleanup_hook (pad, hook);
1269 GST_OBJECT_UNLOCK (pad);
1275 GST_OBJECT_UNLOCK (pad);
1276 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1282 * gst_pad_is_blocked:
1283 * @pad: the #GstPad to query
1285 * Checks if the pad is blocked or not. This function returns the
1286 * last requested state of the pad. It is not certain that the pad
1287 * is actually blocking at this point (see gst_pad_is_blocking()).
1289 * Returns: TRUE if the pad is blocked.
1294 gst_pad_is_blocked (GstPad * pad)
1296 gboolean result = FALSE;
1298 g_return_val_if_fail (GST_IS_PAD (pad), result);
1300 GST_OBJECT_LOCK (pad);
1301 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1302 GST_OBJECT_UNLOCK (pad);
1308 * gst_pad_is_blocking:
1309 * @pad: the #GstPad to query
1311 * Checks if the pad is blocking or not. This is a guaranteed state
1312 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1314 * Returns: TRUE if the pad is blocking.
1321 gst_pad_is_blocking (GstPad * pad)
1323 gboolean result = FALSE;
1325 g_return_val_if_fail (GST_IS_PAD (pad), result);
1327 GST_OBJECT_LOCK (pad);
1328 /* the blocking flag is only valid if the pad is not flushing */
1329 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1330 GST_OBJECT_UNLOCK (pad);
1336 * gst_pad_check_reconfigure:
1337 * @pad: the #GstPad to check
1339 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1340 * if the flag was set.
1342 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1345 gst_pad_check_reconfigure (GstPad * pad)
1347 gboolean reconfigure;
1349 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1351 GST_OBJECT_LOCK (pad);
1352 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1354 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1355 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1356 GST_OBJECT_UNLOCK (pad);
1362 * gst_pad_mark_reconfigure:
1363 * @pad: the #GstPad to mark
1365 * Mark a pad for needing reconfiguration. The next call to
1366 * gst_pad_check_reconfigure() will return %TRUE after this call.
1369 gst_pad_mark_reconfigure (GstPad * pad)
1371 g_return_if_fail (GST_IS_PAD (pad));
1373 GST_OBJECT_LOCK (pad);
1374 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1375 GST_OBJECT_UNLOCK (pad);
1379 * gst_pad_set_activate_function:
1381 * @f: the #GstPadActivateFunction to set.
1383 * Calls gst_pad_set_activate_function_full() with NULL for the user_data and
1387 * gst_pad_set_activate_function_full:
1389 * @activate: the #GstPadActivateFunction to set.
1390 * @user_data: user_data passed to @notify
1391 * @notify: notify called when @activate will not be used anymore.
1393 * Sets the given activate function for @pad. The activate function will
1394 * dispatch to gst_pad_activate_push() or gst_pad_activate_pull() to perform
1395 * the actual activation. Only makes sense to set on sink pads.
1397 * Call this function if your sink pad can start a pull-based task.
1400 gst_pad_set_activate_function_full (GstPad * pad,
1401 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1403 g_return_if_fail (GST_IS_PAD (pad));
1405 if (pad->activatenotify)
1406 pad->activatenotify (pad->activatedata);
1407 GST_PAD_ACTIVATEFUNC (pad) = activate;
1408 pad->activatedata = user_data;
1409 pad->activatenotify = notify;
1411 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1412 GST_DEBUG_FUNCPTR_NAME (activate));
1416 * gst_pad_set_activatemode_function:
1418 * @f: the #GstPadActivateModeFunction to set.
1420 * Calls gst_pad_set_activatemode_function_full() with NULL for the user_data and
1424 * gst_pad_set_activatemode_function_full:
1426 * @activatemode: the #GstPadActivateModeFunction to set.
1427 * @user_data: user_data passed to @notify
1428 * @notify: notify called when @activatemode will not be used anymore.
1430 * Sets the given activate_mode function for the pad. An activate_mode function
1431 * prepares the element for data passing.
1434 gst_pad_set_activatemode_function_full (GstPad * pad,
1435 GstPadActivateModeFunction activatemode, gpointer user_data,
1436 GDestroyNotify notify)
1438 g_return_if_fail (GST_IS_PAD (pad));
1440 if (pad->activatemodenotify)
1441 pad->activatemodenotify (pad->activatemodedata);
1442 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1443 pad->activatemodedata = user_data;
1444 pad->activatemodenotify = notify;
1446 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1447 GST_DEBUG_FUNCPTR_NAME (activatemode));
1451 * gst_pad_set_chain_function:
1452 * @p: a sink #GstPad.
1453 * @f: the #GstPadChainFunction to set.
1455 * Calls gst_pad_set_chain_function_full() with NULL for the user_data and
1459 * gst_pad_set_chain_function_full:
1460 * @pad: a sink #GstPad.
1461 * @chain: the #GstPadChainFunction to set.
1462 * @user_data: user_data passed to @notify
1463 * @notify: notify called when @chain will not be used anymore.
1465 * Sets the given chain function for the pad. The chain function is called to
1466 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1469 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1470 gpointer user_data, GDestroyNotify notify)
1472 g_return_if_fail (GST_IS_PAD (pad));
1473 g_return_if_fail (GST_PAD_IS_SINK (pad));
1475 if (pad->chainnotify)
1476 pad->chainnotify (pad->chaindata);
1477 GST_PAD_CHAINFUNC (pad) = chain;
1478 pad->chaindata = user_data;
1479 pad->chainnotify = notify;
1481 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1482 GST_DEBUG_FUNCPTR_NAME (chain));
1486 * gst_pad_set_chain_list_function:
1487 * @p: a sink #GstPad.
1488 * @f: the #GstPadChainListFunction to set.
1490 * Calls gst_pad_set_chain_list_function_full() with NULL for the user_data and
1494 * gst_pad_set_chain_list_function_full:
1495 * @pad: a sink #GstPad.
1496 * @chainlist: the #GstPadChainListFunction to set.
1497 * @user_data: user_data passed to @notify
1498 * @notify: notify called when @chainlist will not be used anymore.
1500 * Sets the given chain list function for the pad. The chainlist function is
1501 * called to process a #GstBufferList input buffer list. See
1502 * #GstPadChainListFunction for more details.
1507 gst_pad_set_chain_list_function_full (GstPad * pad,
1508 GstPadChainListFunction chainlist, gpointer user_data,
1509 GDestroyNotify notify)
1511 g_return_if_fail (GST_IS_PAD (pad));
1512 g_return_if_fail (GST_PAD_IS_SINK (pad));
1514 if (pad->chainlistnotify)
1515 pad->chainlistnotify (pad->chainlistdata);
1516 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1517 pad->chainlistdata = user_data;
1518 pad->chainlistnotify = notify;
1520 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1521 GST_DEBUG_FUNCPTR_NAME (chainlist));
1525 * gst_pad_set_getrange_function:
1526 * @p: a source #GstPad.
1527 * @f: the #GstPadGetRangeFunction to set.
1529 * Calls gst_pad_set_getrange_function_full() with NULL for the user_data and
1533 * gst_pad_set_getrange_function_full:
1534 * @pad: a source #GstPad.
1535 * @get: the #GstPadGetRangeFunction to set.
1536 * @user_data: user_data passed to @notify
1537 * @notify: notify called when @get will not be used anymore.
1539 * Sets the given getrange function for the pad. The getrange function is
1540 * called to produce a new #GstBuffer to start the processing pipeline. see
1541 * #GstPadGetRangeFunction for a description of the getrange function.
1544 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1545 gpointer user_data, GDestroyNotify notify)
1547 g_return_if_fail (GST_IS_PAD (pad));
1548 g_return_if_fail (GST_PAD_IS_SRC (pad));
1550 if (pad->getrangenotify)
1551 pad->getrangenotify (pad->getrangedata);
1552 GST_PAD_GETRANGEFUNC (pad) = get;
1553 pad->getrangedata = user_data;
1554 pad->getrangenotify = notify;
1556 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1557 GST_DEBUG_FUNCPTR_NAME (get));
1561 * gst_pad_set_event_function:
1562 * @p: a #GstPad of either direction.
1563 * @f: the #GstPadEventFunction to set.
1565 * Calls gst_pad_set_event_function_full() with NULL for the user_data and
1569 * gst_pad_set_event_function_full:
1570 * @pad: a #GstPad of either direction.
1571 * @event: the #GstPadEventFunction to set.
1572 * @user_data: user_data passed to @notify
1573 * @notify: notify called when @event will not be used anymore.
1575 * Sets the given event handler for the pad.
1578 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1579 gpointer user_data, GDestroyNotify notify)
1581 g_return_if_fail (GST_IS_PAD (pad));
1583 if (pad->eventnotify)
1584 pad->eventnotify (pad->eventdata);
1585 GST_PAD_EVENTFUNC (pad) = event;
1586 pad->eventdata = user_data;
1587 pad->eventnotify = notify;
1589 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1590 GST_DEBUG_FUNCPTR_NAME (event));
1594 * gst_pad_set_query_function:
1595 * @p: a #GstPad of either direction.
1596 * @f: the #GstPadQueryFunction to set.
1598 * Calls gst_pad_set_query_function_full() with NULL for the user_data and
1602 * gst_pad_set_query_function_full:
1603 * @pad: a #GstPad of either direction.
1604 * @query: the #GstPadQueryFunction to set.
1605 * @user_data: user_data passed to @notify
1606 * @notify: notify called when @query will not be used anymore.
1608 * Set the given query function for the pad.
1611 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1612 gpointer user_data, GDestroyNotify notify)
1614 g_return_if_fail (GST_IS_PAD (pad));
1616 if (pad->querynotify)
1617 pad->querynotify (pad->querydata);
1618 GST_PAD_QUERYFUNC (pad) = query;
1619 pad->querydata = user_data;
1620 pad->querynotify = notify;
1622 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1623 GST_DEBUG_FUNCPTR_NAME (query));
1627 * gst_pad_set_iterate_internal_links_function:
1628 * @p: a #GstPad of either direction.
1629 * @f: the #GstPadIterIntLinkFunction to set.
1631 * Calls gst_pad_set_iterate_internal_links_function_full() with NULL
1632 * for the user_data and notify.
1635 * gst_pad_set_iterate_internal_links_function_full:
1636 * @pad: a #GstPad of either direction.
1637 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1638 * @user_data: user_data passed to @notify
1639 * @notify: notify called when @iterintlink will not be used anymore.
1641 * Sets the given internal link iterator function for the pad.
1646 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1647 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1648 GDestroyNotify notify)
1650 g_return_if_fail (GST_IS_PAD (pad));
1652 if (pad->iterintlinknotify)
1653 pad->iterintlinknotify (pad->iterintlinkdata);
1654 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1655 pad->iterintlinkdata = user_data;
1656 pad->iterintlinknotify = notify;
1658 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1659 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1663 * gst_pad_set_link_function:
1665 * @f: the #GstPadLinkFunction to set.
1667 * Calls gst_pad_set_link_function_full() with NULL
1668 * for the user_data and notify.
1671 * gst_pad_set_link_function_full:
1673 * @link: the #GstPadLinkFunction to set.
1674 * @user_data: user_data passed to @notify
1675 * @notify: notify called when @link will not be used anymore.
1677 * Sets the given link function for the pad. It will be called when
1678 * the pad is linked with another pad.
1680 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1683 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1684 * cannot be made for some reason.
1686 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1687 * of the peer sink pad, if present.
1690 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1691 gpointer user_data, GDestroyNotify notify)
1693 g_return_if_fail (GST_IS_PAD (pad));
1695 if (pad->linknotify)
1696 pad->linknotify (pad->linkdata);
1697 GST_PAD_LINKFUNC (pad) = link;
1698 pad->linkdata = user_data;
1699 pad->linknotify = notify;
1701 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1702 GST_DEBUG_FUNCPTR_NAME (link));
1706 * gst_pad_set_unlink_function:
1708 * @f: the #GstPadUnlinkFunction to set.
1710 * Calls gst_pad_set_unlink_function_full() with NULL
1711 * for the user_data and notify.
1714 * gst_pad_set_unlink_function_full:
1716 * @unlink: the #GstPadUnlinkFunction to set.
1717 * @user_data: user_data passed to @notify
1718 * @notify: notify called when @unlink will not be used anymore.
1720 * Sets the given unlink function for the pad. It will be called
1721 * when the pad is unlinked.
1724 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1725 gpointer user_data, GDestroyNotify notify)
1727 g_return_if_fail (GST_IS_PAD (pad));
1729 if (pad->unlinknotify)
1730 pad->unlinknotify (pad->unlinkdata);
1731 GST_PAD_UNLINKFUNC (pad) = unlink;
1732 pad->unlinkdata = user_data;
1733 pad->unlinknotify = notify;
1735 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1736 GST_DEBUG_FUNCPTR_NAME (unlink));
1741 * @srcpad: the source #GstPad to unlink.
1742 * @sinkpad: the sink #GstPad to unlink.
1744 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1745 * signal on both pads.
1747 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1748 * the pads were not linked together.
1753 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1755 gboolean result = FALSE;
1756 GstElement *parent = NULL;
1758 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1759 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1760 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1761 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1763 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1764 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1765 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1767 /* We need to notify the parent before taking any pad locks as the bin in
1768 * question might be waiting for a lock on the pad while holding its lock
1769 * that our message will try to take. */
1770 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1771 if (GST_IS_ELEMENT (parent)) {
1772 gst_element_post_message (parent,
1773 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1774 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1776 gst_object_unref (parent);
1781 GST_OBJECT_LOCK (srcpad);
1782 GST_OBJECT_LOCK (sinkpad);
1784 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1785 goto not_linked_together;
1787 if (GST_PAD_UNLINKFUNC (srcpad)) {
1788 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1790 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1791 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1794 /* first clear peers */
1795 GST_PAD_PEER (srcpad) = NULL;
1796 GST_PAD_PEER (sinkpad) = NULL;
1798 GST_OBJECT_UNLOCK (sinkpad);
1799 GST_OBJECT_UNLOCK (srcpad);
1801 /* fire off a signal to each of the pads telling them
1802 * that they've been unlinked */
1803 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1804 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1806 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1807 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1812 if (parent != NULL) {
1813 gst_element_post_message (parent,
1814 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1815 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1816 gst_object_unref (parent);
1821 not_linked_together:
1823 /* we do not emit a warning in this case because unlinking cannot
1824 * be made MT safe.*/
1825 GST_OBJECT_UNLOCK (sinkpad);
1826 GST_OBJECT_UNLOCK (srcpad);
1832 * gst_pad_is_linked:
1833 * @pad: pad to check
1835 * Checks if a @pad is linked to another pad or not.
1837 * Returns: TRUE if the pad is linked, FALSE otherwise.
1842 gst_pad_is_linked (GstPad * pad)
1846 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1848 GST_OBJECT_LOCK (pad);
1849 result = (GST_PAD_PEER (pad) != NULL);
1850 GST_OBJECT_UNLOCK (pad);
1855 /* get the caps from both pads and see if the intersection
1858 * This function should be called with the pad LOCK on both
1862 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1863 GstPadLinkCheck flags)
1865 GstCaps *srccaps = NULL;
1866 GstCaps *sinkcaps = NULL;
1867 gboolean compatible = FALSE;
1869 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1872 /* Doing the expensive caps checking takes priority over only checking the template caps */
1873 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1874 GST_OBJECT_UNLOCK (sink);
1875 GST_OBJECT_UNLOCK (src);
1877 srccaps = gst_pad_query_caps (src, NULL);
1878 sinkcaps = gst_pad_query_caps (sink, NULL);
1880 GST_OBJECT_LOCK (src);
1881 GST_OBJECT_LOCK (sink);
1883 /* If one of the two pads doesn't have a template, consider the intersection
1885 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
1886 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
1890 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
1892 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
1895 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
1897 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
1900 /* if we have caps on both pads we can check the intersection. If one
1901 * of the caps is NULL, we return TRUE. */
1902 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1904 gst_caps_unref (srccaps);
1906 gst_caps_unref (sinkcaps);
1910 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
1911 gst_caps_unref (srccaps);
1912 gst_caps_unref (sinkcaps);
1915 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
1916 (compatible ? "" : "not"));
1921 /* check if the grandparents of both pads are the same.
1922 * This check is required so that we don't try to link
1923 * pads from elements in different bins without ghostpads.
1925 * The LOCK should be held on both pads
1928 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1930 GstObject *psrc, *psink;
1932 psrc = GST_OBJECT_PARENT (src);
1933 psink = GST_OBJECT_PARENT (sink);
1935 /* if one of the pads has no parent, we allow the link */
1936 if (G_UNLIKELY (psrc == NULL || psink == NULL))
1939 /* only care about parents that are elements */
1940 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
1941 goto no_element_parent;
1943 /* if the parents are the same, we have a loop */
1944 if (G_UNLIKELY (psrc == psink))
1947 /* if they both have a parent, we check the grandparents. We can not lock
1948 * the parent because we hold on the child (pad) and the locking order is
1949 * parent >> child. */
1950 psrc = GST_OBJECT_PARENT (psrc);
1951 psink = GST_OBJECT_PARENT (psink);
1953 /* if they have grandparents but they are not the same */
1954 if (G_UNLIKELY (psrc != psink))
1955 goto wrong_grandparents;
1962 GST_CAT_DEBUG (GST_CAT_CAPS,
1963 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
1964 GST_PTR_FORMAT, psrc, psink);
1969 GST_CAT_DEBUG (GST_CAT_CAPS,
1970 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
1971 GST_PTR_FORMAT, psrc, psink);
1976 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1982 GST_CAT_DEBUG (GST_CAT_CAPS,
1983 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1984 GST_PTR_FORMAT, psrc, psink);
1989 /* FIXME leftover from an attempt at refactoring... */
1990 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
1991 * the two pads will be locked in the srcpad, sinkpad order. */
1992 static GstPadLinkReturn
1993 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
1995 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1996 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1998 GST_OBJECT_LOCK (srcpad);
2000 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2001 goto src_was_linked;
2003 GST_OBJECT_LOCK (sinkpad);
2005 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2006 goto sink_was_linked;
2008 /* check hierarchy, pads can only be linked if the grandparents
2010 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2011 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2012 goto wrong_hierarchy;
2014 /* check pad caps for non-empty intersection */
2015 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2018 /* FIXME check pad scheduling for non-empty intersection */
2020 return GST_PAD_LINK_OK;
2024 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2025 GST_DEBUG_PAD_NAME (srcpad),
2026 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2027 /* we do not emit a warning in this case because unlinking cannot
2028 * be made MT safe.*/
2029 GST_OBJECT_UNLOCK (srcpad);
2030 return GST_PAD_LINK_WAS_LINKED;
2034 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2035 GST_DEBUG_PAD_NAME (sinkpad),
2036 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2037 /* we do not emit a warning in this case because unlinking cannot
2038 * be made MT safe.*/
2039 GST_OBJECT_UNLOCK (sinkpad);
2040 GST_OBJECT_UNLOCK (srcpad);
2041 return GST_PAD_LINK_WAS_LINKED;
2045 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2046 GST_OBJECT_UNLOCK (sinkpad);
2047 GST_OBJECT_UNLOCK (srcpad);
2048 return GST_PAD_LINK_WRONG_HIERARCHY;
2052 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2053 GST_OBJECT_UNLOCK (sinkpad);
2054 GST_OBJECT_UNLOCK (srcpad);
2055 return GST_PAD_LINK_NOFORMAT;
2061 * @srcpad: the source #GstPad.
2062 * @sinkpad: the sink #GstPad.
2064 * Checks if the source pad and the sink pad are compatible so they can be
2067 * Returns: TRUE if the pads can be linked.
2070 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2072 GstPadLinkReturn result;
2074 /* generic checks */
2075 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2076 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2078 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2079 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2081 /* gst_pad_link_prepare does everything for us, we only release the locks
2082 * on the pads that it gets us. If this function returns !OK the locks are not
2084 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2085 if (result != GST_PAD_LINK_OK)
2088 GST_OBJECT_UNLOCK (srcpad);
2089 GST_OBJECT_UNLOCK (sinkpad);
2092 return result == GST_PAD_LINK_OK;
2096 * gst_pad_link_full:
2097 * @srcpad: the source #GstPad to link.
2098 * @sinkpad: the sink #GstPad to link.
2099 * @flags: the checks to validate when linking
2101 * Links the source pad and the sink pad.
2103 * This variant of #gst_pad_link provides a more granular control on the
2104 * checks being done when linking. While providing some considerable speedups
2105 * the caller of this method must be aware that wrong usage of those flags
2106 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2107 * for more information.
2111 * Returns: A result code indicating if the connection worked or
2117 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2119 GstPadLinkReturn result;
2121 GstPadLinkFunction srcfunc, sinkfunc;
2123 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2124 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2125 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2126 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2127 GST_PAD_LINK_WRONG_DIRECTION);
2129 /* Notify the parent early. See gst_pad_unlink for details. */
2130 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2131 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2132 gst_element_post_message (parent,
2133 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2134 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2136 gst_object_unref (parent);
2141 /* prepare will also lock the two pads */
2142 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2144 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2147 /* must set peers before calling the link function */
2148 GST_PAD_PEER (srcpad) = sinkpad;
2149 GST_PAD_PEER (sinkpad) = srcpad;
2151 /* check events, when something is different, mark pending */
2152 schedule_events (srcpad, sinkpad);
2154 /* get the link functions */
2155 srcfunc = GST_PAD_LINKFUNC (srcpad);
2156 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2158 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2159 /* custom link functions, execute them */
2160 GST_OBJECT_UNLOCK (sinkpad);
2161 GST_OBJECT_UNLOCK (srcpad);
2164 /* this one will call the peer link function */
2165 result = srcfunc (srcpad, sinkpad);
2166 } else if (sinkfunc) {
2167 /* if no source link function, we need to call the sink link
2168 * function ourselves. */
2169 result = sinkfunc (sinkpad, srcpad);
2172 GST_OBJECT_LOCK (srcpad);
2173 GST_OBJECT_LOCK (sinkpad);
2175 /* we released the lock, check if the same pads are linked still */
2176 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2177 goto concurrent_link;
2179 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2182 GST_OBJECT_UNLOCK (sinkpad);
2183 GST_OBJECT_UNLOCK (srcpad);
2185 /* fire off a signal to each of the pads telling them
2186 * that they've been linked */
2187 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2188 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2190 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2191 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2193 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2196 if (G_LIKELY (parent)) {
2197 gst_element_post_message (parent,
2198 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2199 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2200 gst_object_unref (parent);
2208 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2209 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2210 GST_OBJECT_UNLOCK (sinkpad);
2211 GST_OBJECT_UNLOCK (srcpad);
2213 /* The other link operation succeeded first */
2214 result = GST_PAD_LINK_WAS_LINKED;
2219 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2220 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2222 GST_PAD_PEER (srcpad) = NULL;
2223 GST_PAD_PEER (sinkpad) = NULL;
2225 GST_OBJECT_UNLOCK (sinkpad);
2226 GST_OBJECT_UNLOCK (srcpad);
2234 * @srcpad: the source #GstPad to link.
2235 * @sinkpad: the sink #GstPad to link.
2237 * Links the source pad and the sink pad.
2239 * Returns: A result code indicating if the connection worked or
2245 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2247 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2251 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2253 GstPadTemplate **template_p;
2255 /* this function would need checks if it weren't static */
2257 GST_OBJECT_LOCK (pad);
2258 template_p = &pad->padtemplate;
2259 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2260 GST_OBJECT_UNLOCK (pad);
2263 gst_pad_template_pad_created (templ, pad);
2267 * gst_pad_get_pad_template:
2270 * Gets the template for @pad.
2272 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2273 * instantiated, or %NULL if this pad has no template. Unref after
2277 gst_pad_get_pad_template (GstPad * pad)
2279 GstPadTemplate *templ;
2281 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2283 templ = GST_PAD_PAD_TEMPLATE (pad);
2285 return (templ ? gst_object_ref (templ) : NULL);
2289 * gst_pad_has_current_caps:
2290 * @pad: a #GstPad to check
2292 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2294 * Returns: TRUE when @pad has caps associated with it.
2297 gst_pad_has_current_caps (GstPad * pad)
2302 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2304 GST_OBJECT_LOCK (pad);
2305 caps = get_pad_caps (pad);
2306 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2307 "check current pad caps %" GST_PTR_FORMAT, caps);
2308 result = (caps != NULL);
2309 GST_OBJECT_UNLOCK (pad);
2315 * gst_pad_get_current_caps:
2316 * @pad: a #GstPad to get the current capabilities of.
2318 * Gets the capabilities currently configured on @pad with the last
2319 * #GST_EVENT_CAPS event.
2321 * Returns: the current caps of the pad with incremented ref-count.
2324 gst_pad_get_current_caps (GstPad * pad)
2328 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2330 GST_OBJECT_LOCK (pad);
2331 if ((result = get_pad_caps (pad)))
2332 gst_caps_ref (result);
2333 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2334 "get current pad caps %" GST_PTR_FORMAT, result);
2335 GST_OBJECT_UNLOCK (pad);
2341 * gst_pad_get_pad_template_caps:
2342 * @pad: a #GstPad to get the template capabilities from.
2344 * Gets the capabilities for @pad's template.
2346 * Returns: (transfer full): the #GstCaps of this pad template.
2347 * Unref after usage.
2350 gst_pad_get_pad_template_caps (GstPad * pad)
2352 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2354 if (GST_PAD_PAD_TEMPLATE (pad))
2355 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2357 return gst_caps_ref (GST_CAPS_ANY);
2362 * @pad: a #GstPad to get the peer of.
2364 * Gets the peer of @pad. This function refs the peer pad so
2365 * you need to unref it after use.
2367 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2372 gst_pad_get_peer (GstPad * pad)
2376 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2378 GST_OBJECT_LOCK (pad);
2379 result = GST_PAD_PEER (pad);
2381 gst_object_ref (result);
2382 GST_OBJECT_UNLOCK (pad);
2388 * gst_pad_get_allowed_caps:
2391 * Gets the capabilities of the allowed media types that can flow through
2392 * @pad and its peer.
2394 * The allowed capabilities is calculated as the intersection of the results of
2395 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2396 * on the resulting caps.
2398 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2399 * caps when you no longer need it. This function returns NULL when @pad
2405 gst_pad_get_allowed_caps (GstPad * pad)
2412 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2414 GST_OBJECT_LOCK (pad);
2415 peer = GST_PAD_PEER (pad);
2416 if (G_UNLIKELY (peer == NULL))
2419 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2421 gst_object_ref (peer);
2422 GST_OBJECT_UNLOCK (pad);
2423 mycaps = gst_pad_query_caps (pad, NULL);
2425 peercaps = gst_pad_query_caps (peer, NULL);
2426 gst_object_unref (peer);
2428 caps = gst_caps_intersect (mycaps, peercaps);
2429 gst_caps_unref (peercaps);
2430 gst_caps_unref (mycaps);
2432 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2439 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2440 GST_OBJECT_UNLOCK (pad);
2447 * gst_pad_iterate_internal_links_default:
2448 * @pad: the #GstPad to get the internal links of.
2449 * @parent: the parent of @pad or NULL
2451 * Iterate the list of pads to which the given pad is linked to inside of
2452 * the parent element.
2453 * This is the default handler, and thus returns an iterator of all of the
2454 * pads inside the parent element with opposite direction.
2456 * The caller must free this iterator after use with gst_iterator_free().
2458 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2459 * returned pad with gst_object_unref().
2464 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2471 GstElement *eparent;
2473 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2475 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2476 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2478 GST_OBJECT_LOCK (pad);
2479 eparent = GST_PAD_PARENT (pad);
2480 if (!eparent || !GST_IS_ELEMENT (eparent))
2483 gst_object_ref (eparent);
2484 GST_OBJECT_UNLOCK (pad);
2487 if (pad->direction == GST_PAD_SRC)
2488 padlist = &eparent->sinkpads;
2490 padlist = &eparent->srcpads;
2492 GST_DEBUG_OBJECT (pad, "Making iterator");
2494 cookie = &eparent->pads_cookie;
2496 lock = GST_OBJECT_GET_LOCK (eparent);
2498 res = gst_iterator_new_list (GST_TYPE_PAD,
2499 lock, cookie, padlist, (GObject *) owner, NULL);
2501 gst_object_unref (owner);
2508 GST_OBJECT_UNLOCK (pad);
2509 GST_DEBUG_OBJECT (pad, "no parent element");
2515 * gst_pad_iterate_internal_links:
2516 * @pad: the GstPad to get the internal links of.
2518 * Gets an iterator for the pads to which the given pad is linked to inside
2519 * of the parent element.
2521 * Each #GstPad element yielded by the iterator will have its refcount increased,
2522 * so unref after use.
2524 * Free-function: gst_iterator_free
2526 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2527 * pad does not have an iterator function configured. Use
2528 * gst_iterator_free() after usage.
2533 gst_pad_iterate_internal_links (GstPad * pad)
2535 GstIterator *res = NULL;
2538 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2540 GST_OBJECT_LOCK (pad);
2541 ACQUIRE_PARENT (pad, parent, no_parent);
2542 GST_OBJECT_UNLOCK (pad);
2544 if (GST_PAD_ITERINTLINKFUNC (pad))
2545 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2547 RELEASE_PARENT (parent);
2554 GST_DEBUG_OBJECT (pad, "no parent");
2555 GST_OBJECT_UNLOCK (pad);
2563 * @forward: (scope call): a #GstPadForwardFunction
2564 * @user_data: user data passed to @forward
2566 * Calls @forward for all internally linked pads of @pad. This function deals with
2567 * dynamically changing internal pads and will make sure that the @forward
2568 * function is only called once for each pad.
2570 * When @forward returns TRUE, no further pads will be processed.
2572 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2575 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2578 gboolean result = FALSE;
2580 gboolean done = FALSE;
2581 GValue item = { 0, };
2582 GList *pushed_pads = NULL;
2584 iter = gst_pad_iterate_internal_links (pad);
2590 switch (gst_iterator_next (iter, &item)) {
2591 case GST_ITERATOR_OK:
2595 intpad = g_value_get_object (&item);
2597 /* if already pushed, skip. FIXME, find something faster to tag pads */
2598 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2599 g_value_reset (&item);
2603 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2604 GST_DEBUG_PAD_NAME (intpad));
2605 done = result = forward (intpad, user_data);
2607 pushed_pads = g_list_prepend (pushed_pads, intpad);
2609 g_value_reset (&item);
2612 case GST_ITERATOR_RESYNC:
2613 /* We don't reset the result here because we don't push the event
2614 * again on pads that got the event already and because we need
2615 * to consider the result of the previous pushes */
2616 gst_iterator_resync (iter);
2618 case GST_ITERATOR_ERROR:
2619 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2622 case GST_ITERATOR_DONE:
2627 g_value_unset (&item);
2628 gst_iterator_free (iter);
2630 g_list_free (pushed_pads);
2640 gboolean dispatched;
2644 event_forward_func (GstPad * pad, EventData * data)
2646 /* for each pad we send to, we should ref the event; it's up
2647 * to downstream to unref again when handled. */
2648 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2649 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2651 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2653 data->dispatched = TRUE;
2660 * gst_pad_event_default:
2661 * @pad: a #GstPad to call the default event handler on.
2662 * @parent: the parent of @pad or NULL
2663 * @event: (transfer full): the #GstEvent to handle.
2665 * Invokes the default event handler for the given pad.
2667 * The EOS event will pause the task associated with @pad before it is forwarded
2668 * to all internally linked pads,
2670 * The the event is sent to all pads internally linked to @pad. This function
2671 * takes ownership of @event.
2673 * Returns: TRUE if the event was sent successfully.
2676 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2678 gboolean result, forward = TRUE;
2680 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2681 g_return_val_if_fail (event != NULL, FALSE);
2683 GST_LOG_OBJECT (pad, "default event handler");
2685 switch (GST_EVENT_TYPE (event)) {
2686 case GST_EVENT_CAPS:
2687 forward = GST_PAD_IS_PROXY_CAPS (pad);
2698 data.dispatched = FALSE;
2699 data.result = FALSE;
2701 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2703 /* for sinkpads without a parent element or without internal links, nothing
2704 * will be dispatched but we still want to return TRUE. */
2705 if (data.dispatched)
2706 result = data.result;
2711 gst_event_unref (event);
2716 /* Default accept caps implementation just checks against
2717 * the allowed caps for the pad */
2719 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2721 /* get the caps and see if it intersects to something not empty */
2722 GstCaps *caps, *allowed;
2725 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2727 /* first forward the query to internally linked pads when we are dealing with
2729 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2730 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2735 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2736 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2738 allowed = gst_pad_query_caps (pad, NULL);
2739 gst_query_parse_accept_caps (query, &caps);
2742 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
2743 result = gst_caps_is_subset (caps, allowed);
2744 gst_caps_unref (allowed);
2746 GST_DEBUG_OBJECT (pad, "no caps allowed on the pad");
2749 gst_query_set_accept_caps_result (query, result);
2755 /* Default caps implementation */
2757 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2759 GstCaps *result = NULL, *filter;
2760 GstPadTemplate *templ;
2761 gboolean fixed_caps;
2763 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2765 gst_query_parse_caps (query, &filter);
2767 /* first try to proxy if we must */
2768 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2769 if ((gst_pad_proxy_query_caps (pad, query))) {
2770 gst_query_parse_caps_result (query, &result);
2775 /* no proxy or it failed, do default handling */
2776 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2778 GST_OBJECT_LOCK (pad);
2780 /* fixed caps, try the negotiated caps first */
2781 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2782 if ((result = get_pad_caps (pad)))
2783 goto filter_done_unlock;
2786 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2787 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2788 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2789 goto filter_done_unlock;
2793 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2794 "non-fixed pad caps: trying pad caps");
2795 /* non fixed caps, try the negotiated caps */
2796 if ((result = get_pad_caps (pad)))
2797 goto filter_done_unlock;
2800 /* this almost never happens */
2801 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2802 result = GST_CAPS_ANY;
2805 GST_OBJECT_UNLOCK (pad);
2808 /* run the filter on the result */
2810 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2811 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2812 GST_PTR_FORMAT, result, result, filter, filter);
2813 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2814 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2817 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2818 "using caps %p %" GST_PTR_FORMAT, result, result);
2819 result = gst_caps_ref (result);
2822 gst_query_set_caps_result (query, result);
2823 gst_caps_unref (result);
2832 gboolean dispatched;
2836 query_forward_func (GstPad * pad, QueryData * data)
2838 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
2839 data->query, GST_EVENT_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
2841 data->result |= gst_pad_peer_query (pad, data->query);
2843 data->dispatched = TRUE;
2845 /* stop on first successful reply */
2846 return data->result;
2850 * gst_pad_query_default:
2851 * @pad: a #GstPad to call the default query handler on.
2852 * @parent: the parent of @pad or NULL
2853 * @query: (transfer none): the #GstQuery to handle.
2855 * Invokes the default query handler for the given pad.
2856 * The query is sent to all pads internally linked to @pad. Note that
2857 * if there are many possible sink pads that are internally linked to
2858 * @pad, only one will be sent the query.
2859 * Multi-sinkpad elements should implement custom query handlers.
2861 * Returns: TRUE if the query was performed successfully.
2864 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
2866 gboolean forward, ret = FALSE;
2868 switch (GST_QUERY_TYPE (query)) {
2869 case GST_QUERY_SCHEDULING:
2872 case GST_QUERY_ALLOCATION:
2873 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
2875 case GST_QUERY_ACCEPT_CAPS:
2876 ret = gst_pad_query_accept_caps_default (pad, query);
2879 case GST_QUERY_CAPS:
2880 ret = gst_pad_query_caps_default (pad, query);
2883 case GST_QUERY_POSITION:
2884 case GST_QUERY_SEEKING:
2885 case GST_QUERY_FORMATS:
2886 case GST_QUERY_LATENCY:
2887 case GST_QUERY_JITTER:
2888 case GST_QUERY_RATE:
2889 case GST_QUERY_CONVERT:
2895 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
2896 query, GST_QUERY_TYPE_NAME (query));
2902 data.dispatched = FALSE;
2903 data.result = FALSE;
2905 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
2907 if (data.dispatched) {
2910 /* nothing dispatched, assume drained */
2911 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
2921 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
2923 GstPad *pad = data->pad;
2924 GstPadProbeInfo *info = data->info;
2925 GstPadProbeType type, flags;
2926 GstPadProbeCallback callback;
2927 GstPadProbeReturn ret;
2929 /* if we have called this callback, do nothing */
2930 if (PROBE_COOKIE (hook) == data->cookie) {
2931 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2932 "hook %lu, cookie %u already called", hook->hook_id,
2933 PROBE_COOKIE (hook));
2937 PROBE_COOKIE (hook) = data->cookie;
2939 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
2942 /* one of the data types */
2943 if ((flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
2945 /* one of the scheduling types */
2946 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
2948 /* one of the blocking types must match */
2949 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
2950 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
2952 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
2953 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
2954 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
2957 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2958 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
2959 PROBE_COOKIE (hook), flags);
2961 data->marshalled = TRUE;
2963 callback = (GstPadProbeCallback) hook->func;
2964 if (callback == NULL)
2967 info->id = hook->hook_id;
2969 GST_OBJECT_UNLOCK (pad);
2971 ret = callback (pad, info, hook->data);
2973 GST_OBJECT_LOCK (pad);
2976 case GST_PAD_PROBE_REMOVE:
2977 /* remove the probe */
2978 GST_DEBUG_OBJECT (pad, "asked to remove hook");
2979 cleanup_hook (pad, hook);
2981 case GST_PAD_PROBE_DROP:
2982 /* need to drop the data, make sure other probes don't get called
2984 GST_DEBUG_OBJECT (pad, "asked to drop item");
2985 info->type = GST_PAD_PROBE_TYPE_INVALID;
2986 data->dropped = TRUE;
2988 case GST_PAD_PROBE_PASS:
2989 /* inform the pad block to let things pass */
2990 GST_DEBUG_OBJECT (pad, "asked to pass item");
2994 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3001 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3002 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3003 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3008 /* a probe that does not take or return any data */
3009 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3011 if (G_UNLIKELY (pad->num_probes)) { \
3012 /* pass NULL as the data item */ \
3013 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3014 ret = do_probe_callbacks (pad, &info, defaultval); \
3015 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3020 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3022 if (G_UNLIKELY (pad->num_probes)) { \
3023 /* pass the data item */ \
3024 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3025 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3026 /* store the possibly updated data item */ \
3027 data = GST_PAD_PROBE_INFO_DATA (&info); \
3028 /* if something went wrong, exit */ \
3029 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3034 #define PROBE_PUSH(pad,mask,data,label) \
3035 PROBE_FULL(pad, mask, data, -1, -1, label);
3036 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3037 PROBE_FULL(pad, mask, data, offs, size, label);
3039 static GstFlowReturn
3040 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3041 GstFlowReturn defaultval)
3050 data.marshalled = FALSE;
3051 data.dropped = FALSE;
3052 data.cookie = ++pad->priv->probe_cookie;
3055 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3058 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3059 "do probes cookie %u", data.cookie);
3060 cookie = pad->priv->probe_list_cookie;
3062 g_hook_list_marshal (&pad->probes, TRUE,
3063 (GHookMarshaller) probe_hook_marshal, &data);
3065 /* if the list changed, call the new callbacks (they will not have their
3066 * cookie set to data.cookie */
3067 if (cookie != pad->priv->probe_list_cookie) {
3068 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3069 "probe list changed, restarting");
3073 /* the first item that dropped will stop the hooks and then we drop here */
3077 /* if no handler matched and we are blocking, let the item pass */
3078 if (!data.marshalled && is_block)
3081 /* At this point, all handlers returned either OK or PASS. If one handler
3082 * returned PASS, let the item pass */
3087 while (GST_PAD_IS_BLOCKED (pad)) {
3088 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3089 "we are blocked %d times", pad->num_blocked);
3091 /* we might have released the lock */
3092 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3095 /* now we block the streaming thread. It can be unlocked when we
3096 * deactivate the pad (which will also set the FLUSHING flag) or
3097 * when the pad is unblocked. A flushing event will also unblock
3098 * the pad after setting the FLUSHING flag. */
3099 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3100 "Waiting to be unblocked or set flushing");
3101 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3102 GST_PAD_BLOCK_WAIT (pad);
3103 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3104 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3106 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3116 GST_DEBUG_OBJECT (pad, "pad is flushing");
3117 return GST_FLOW_FLUSHING;
3121 GST_DEBUG_OBJECT (pad, "data is dropped");
3122 return GST_FLOW_CUSTOM_SUCCESS;
3126 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3127 GST_DEBUG_OBJECT (pad, "data is passed");
3135 * gst_pad_get_offset:
3138 * Get the offset applied to the running time of @pad. @pad has to be a source
3141 * Returns: the offset.
3144 gst_pad_get_offset (GstPad * pad)
3148 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3150 GST_OBJECT_LOCK (pad);
3151 result = pad->offset;
3152 GST_OBJECT_UNLOCK (pad);
3158 * gst_pad_set_offset:
3160 * @offset: the offset
3162 * Set the offset that will be applied to the running time of @pad.
3165 gst_pad_set_offset (GstPad * pad, gint64 offset)
3169 g_return_if_fail (GST_IS_PAD (pad));
3171 GST_OBJECT_LOCK (pad);
3172 /* if nothing changed, do nothing */
3173 if (pad->offset == offset)
3176 pad->offset = offset;
3177 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3179 /* sinkpads will apply their offset the next time a segment
3180 * event is received. */
3181 if (GST_PAD_IS_SINK (pad))
3184 /* resend the last segment event on next buffer push */
3185 if ((ev = find_event_by_type (pad, GST_EVENT_SEGMENT, 0))) {
3186 ev->received = FALSE;
3187 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3191 GST_OBJECT_UNLOCK (pad);
3198 /* If TRUE and ret is not OK this means
3199 * that pushing the EOS event failed
3204 /* should be called with pad LOCK */
3206 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3208 PushStickyData *data = user_data;
3209 GstEvent *event = ev->event;
3212 GST_DEBUG_OBJECT (pad, "event %s was already received",
3213 GST_EVENT_TYPE_NAME (event));
3217 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3218 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3220 switch (data->ret) {
3222 ev->received = TRUE;
3223 GST_DEBUG_OBJECT (pad, "event %s marked received",
3224 GST_EVENT_TYPE_NAME (event));
3226 case GST_FLOW_NOT_LINKED:
3227 /* not linked is not a problem, we are sticky so the event will be
3228 * sent later but only for non-EOS events */
3229 GST_DEBUG_OBJECT (pad, "pad was not linked");
3230 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3231 data->ret = GST_FLOW_OK;
3234 GST_DEBUG_OBJECT (pad, "mark pending events");
3235 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3239 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3240 data->was_eos = TRUE;
3242 return data->ret == GST_FLOW_OK;
3245 /* check sticky events and push them when needed. should be called
3247 static inline GstFlowReturn
3248 check_sticky (GstPad * pad)
3250 PushStickyData data = { GST_FLOW_OK, FALSE };
3252 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3253 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3255 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3256 events_foreach (pad, push_sticky, &data);
3258 /* If there's an EOS event we must push it downstream
3259 * even if sending a previous sticky event failed.
3260 * Otherwise the pipeline might wait forever for EOS.
3262 * Only do this if pushing another event than the EOS
3265 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3266 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3268 if (ev && !ev->received) {
3269 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3270 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3280 * @pad: a #GstPad to invoke the default query on.
3281 * @query: (transfer none): the #GstQuery to perform.
3283 * Dispatches a query to a pad. The query should have been allocated by the
3284 * caller via one of the type-specific allocation functions. The element that
3285 * the pad belongs to is responsible for filling the query with an appropriate
3286 * response, which should then be parsed with a type-specific query parsing
3289 * Again, the caller is responsible for both the allocation and deallocation of
3290 * the query structure.
3292 * Please also note that some queries might need a running pipeline to work.
3294 * Returns: TRUE if the query could be performed.
3297 gst_pad_query (GstPad * pad, GstQuery * query)
3300 gboolean res, serialized;
3301 GstPadQueryFunction func;
3302 GstPadProbeType type;
3305 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3306 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3308 if (GST_PAD_IS_SRC (pad)) {
3309 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3310 goto wrong_direction;
3311 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3312 } else if (GST_PAD_IS_SINK (pad)) {
3313 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3314 goto wrong_direction;
3315 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3317 goto unknown_direction;
3319 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3320 GST_QUERY_TYPE_NAME (query));
3322 serialized = GST_QUERY_IS_SERIALIZED (query);
3323 if (G_UNLIKELY (serialized))
3324 GST_PAD_STREAM_LOCK (pad);
3326 GST_OBJECT_LOCK (pad);
3327 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3328 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3329 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3331 ACQUIRE_PARENT (pad, parent, no_parent);
3332 GST_OBJECT_UNLOCK (pad);
3334 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3337 res = func (pad, parent, query);
3339 RELEASE_PARENT (parent);
3341 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3342 GST_QUERY_TYPE_NAME (query), res);
3347 GST_OBJECT_LOCK (pad);
3348 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3349 GST_OBJECT_UNLOCK (pad);
3351 if (G_UNLIKELY (serialized))
3352 GST_PAD_STREAM_UNLOCK (pad);
3359 g_warning ("pad %s:%s query %s in wrong direction",
3360 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3365 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3370 GST_DEBUG_OBJECT (pad, "had no parent");
3371 GST_OBJECT_UNLOCK (pad);
3372 if (G_UNLIKELY (serialized))
3373 GST_PAD_STREAM_UNLOCK (pad);
3378 GST_DEBUG_OBJECT (pad, "had no query function");
3379 RELEASE_PARENT (parent);
3380 if (G_UNLIKELY (serialized))
3381 GST_PAD_STREAM_UNLOCK (pad);
3386 GST_DEBUG_OBJECT (pad, "query failed");
3387 if (G_UNLIKELY (serialized))
3388 GST_PAD_STREAM_UNLOCK (pad);
3393 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3394 GST_OBJECT_UNLOCK (pad);
3395 if (G_UNLIKELY (serialized))
3396 GST_PAD_STREAM_UNLOCK (pad);
3398 /* if a probe dropped, we don't sent it further but assume that the probe
3399 * answered the query and return TRUE */
3400 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3410 * gst_pad_peer_query:
3411 * @pad: a #GstPad to invoke the peer query on.
3412 * @query: (transfer none): the #GstQuery to perform.
3414 * Performs gst_pad_query() on the peer of @pad.
3416 * The caller is responsible for both the allocation and deallocation of
3417 * the query structure.
3419 * Returns: TRUE if the query could be performed. This function returns %FALSE
3420 * if @pad has no peer.
3425 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3428 GstPadProbeType type;
3429 gboolean res, serialized;
3432 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3433 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3435 if (GST_PAD_IS_SRC (pad)) {
3436 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3437 goto wrong_direction;
3438 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3439 } else if (GST_PAD_IS_SINK (pad)) {
3440 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3441 goto wrong_direction;
3442 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3444 goto unknown_direction;
3446 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3447 GST_QUERY_TYPE_NAME (query));
3449 serialized = GST_QUERY_IS_SERIALIZED (query);
3451 GST_OBJECT_LOCK (pad);
3452 if (GST_PAD_IS_SRC (pad) && serialized) {
3453 /* all serialized queries on the srcpad trigger push of
3455 if (!check_sticky (pad) == GST_FLOW_OK)
3459 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3460 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3461 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3463 peerpad = GST_PAD_PEER (pad);
3464 if (G_UNLIKELY (peerpad == NULL))
3467 gst_object_ref (peerpad);
3468 GST_OBJECT_UNLOCK (pad);
3470 res = gst_pad_query (peerpad, query);
3472 gst_object_unref (peerpad);
3477 GST_OBJECT_LOCK (pad);
3478 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3479 GST_OBJECT_UNLOCK (pad);
3486 g_warning ("pad %s:%s query %s in wrong direction",
3487 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3492 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3497 GST_WARNING_OBJECT (pad, "could not send sticky events");
3498 GST_OBJECT_UNLOCK (pad);
3503 GST_WARNING_OBJECT (pad, "pad has no peer");
3504 GST_OBJECT_UNLOCK (pad);
3509 GST_DEBUG_OBJECT (pad, "query failed");
3514 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3515 GST_OBJECT_UNLOCK (pad);
3517 /* if a probe dropped, we don't sent it further but assume that the probe
3518 * answered the query and return TRUE */
3519 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3528 /**********************************************************************
3529 * Data passing functions
3532 /* this is the chain function that does not perform the additional argument
3533 * checking for that little extra speed.
3535 static inline GstFlowReturn
3536 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3541 GST_PAD_STREAM_LOCK (pad);
3543 GST_OBJECT_LOCK (pad);
3544 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3547 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3550 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3553 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3555 PROBE_PUSH (pad, type, data, probe_stopped);
3557 parent = GST_OBJECT_PARENT (pad);
3558 GST_OBJECT_UNLOCK (pad);
3560 /* NOTE: we read the chainfunc unlocked.
3561 * we cannot hold the lock for the pad so we might send
3562 * the data to the wrong function. This is not really a
3563 * problem since functions are assigned at creation time
3564 * and don't change that often... */
3565 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3566 GstPadChainFunction chainfunc;
3568 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3571 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3572 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3573 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3575 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3577 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3578 "called chainfunction &%s with buffer %p, returned %s",
3579 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3581 GstPadChainListFunction chainlistfunc;
3583 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3586 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3587 "calling chainlistfunction &%s",
3588 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3590 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3592 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3593 "called chainlistfunction &%s, returned %s",
3594 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3597 GST_PAD_STREAM_UNLOCK (pad);
3604 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3605 "chaining, but pad was flushing");
3606 GST_OBJECT_UNLOCK (pad);
3607 GST_PAD_STREAM_UNLOCK (pad);
3608 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3609 return GST_FLOW_FLUSHING;
3613 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3614 GST_OBJECT_UNLOCK (pad);
3615 GST_PAD_STREAM_UNLOCK (pad);
3616 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3617 return GST_FLOW_EOS;
3621 g_critical ("chain on pad %s:%s but it was not in push mode",
3622 GST_DEBUG_PAD_NAME (pad));
3623 GST_OBJECT_UNLOCK (pad);
3624 GST_PAD_STREAM_UNLOCK (pad);
3625 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3626 return GST_FLOW_ERROR;
3630 GST_OBJECT_UNLOCK (pad);
3631 GST_PAD_STREAM_UNLOCK (pad);
3632 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3635 case GST_FLOW_CUSTOM_SUCCESS:
3636 GST_DEBUG_OBJECT (pad, "dropped buffer");
3640 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
3647 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3648 g_critical ("chain on pad %s:%s but it has no chainfunction",
3649 GST_DEBUG_PAD_NAME (pad));
3650 GST_PAD_STREAM_UNLOCK (pad);
3651 return GST_FLOW_NOT_SUPPORTED;
3657 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3658 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3661 * Chain a buffer to @pad.
3663 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3665 * If the buffer type is not acceptable for @pad (as negotiated with a
3666 * preceeding GST_EVENT_CAPS event), this function returns
3667 * #GST_FLOW_NOT_NEGOTIATED.
3669 * The function proceeds calling the chain function installed on @pad (see
3670 * gst_pad_set_chain_function()) and the return value of that function is
3671 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3674 * In all cases, success or failure, the caller loses its reference to @buffer
3675 * after calling this function.
3677 * Returns: a #GstFlowReturn from the pad.
3682 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3684 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3685 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3686 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3688 return gst_pad_chain_data_unchecked (pad,
3689 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3692 static GstFlowReturn
3693 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3694 GstBufferList * list)
3700 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3702 len = gst_buffer_list_length (list);
3705 for (i = 0; i < len; i++) {
3706 buffer = gst_buffer_list_get (list, i);
3708 gst_pad_chain_data_unchecked (pad,
3709 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3710 gst_buffer_ref (buffer));
3711 if (ret != GST_FLOW_OK)
3714 gst_buffer_list_unref (list);
3720 * gst_pad_chain_list:
3721 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3722 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3725 * Chain a bufferlist to @pad.
3727 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3729 * If @pad was not negotiated properly with a CAPS event, this function
3730 * returns #GST_FLOW_NOT_NEGOTIATED.
3732 * The function proceeds calling the chainlist function installed on @pad (see
3733 * gst_pad_set_chain_list_function()) and the return value of that function is
3734 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3735 * chainlist function.
3737 * In all cases, success or failure, the caller loses its reference to @list
3738 * after calling this function.
3742 * Returns: a #GstFlowReturn from the pad.
3747 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3749 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3750 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3751 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3753 return gst_pad_chain_data_unchecked (pad,
3754 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3757 static GstFlowReturn
3758 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3763 GST_OBJECT_LOCK (pad);
3764 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3767 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3770 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3773 if (G_UNLIKELY ((ret = check_sticky (pad))) != GST_FLOW_OK)
3776 /* do block probes */
3777 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3779 /* do post-blocking probes */
3780 PROBE_PUSH (pad, type, data, probe_stopped);
3782 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3785 /* take ref to peer pad before releasing the lock */
3786 gst_object_ref (peer);
3788 GST_OBJECT_UNLOCK (pad);
3790 ret = gst_pad_chain_data_unchecked (peer, type, data);
3792 gst_object_unref (peer);
3794 GST_OBJECT_LOCK (pad);
3796 if (pad->priv->using == 0) {
3797 /* pad is not active anymore, trigger idle callbacks */
3798 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3799 probe_stopped, ret);
3801 GST_OBJECT_UNLOCK (pad);
3805 /* ERROR recovery here */
3809 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3810 "pushing, but pad was flushing");
3811 GST_OBJECT_UNLOCK (pad);
3812 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3813 return GST_FLOW_FLUSHING;
3817 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
3818 GST_OBJECT_UNLOCK (pad);
3819 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3820 return GST_FLOW_EOS;
3824 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
3825 GST_DEBUG_PAD_NAME (pad));
3826 GST_OBJECT_UNLOCK (pad);
3827 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3828 return GST_FLOW_ERROR;
3832 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3833 "error pushing events, return %s", gst_flow_get_name (ret));
3834 GST_OBJECT_UNLOCK (pad);
3835 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3840 GST_OBJECT_UNLOCK (pad);
3841 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3844 case GST_FLOW_CUSTOM_SUCCESS:
3845 GST_DEBUG_OBJECT (pad, "dropped buffer");
3849 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
3856 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3857 "pushing, but it was not linked");
3858 GST_OBJECT_UNLOCK (pad);
3859 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3860 return GST_FLOW_NOT_LINKED;
3866 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3867 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
3870 * Pushes a buffer to the peer of @pad.
3872 * This function will call installed block probes before triggering any
3873 * installed data probes.
3875 * The function proceeds calling gst_pad_chain() on the peer pad and returns
3876 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3879 * In all cases, success or failure, the caller loses its reference to @buffer
3880 * after calling this function.
3882 * Returns: a #GstFlowReturn from the peer pad.
3887 gst_pad_push (GstPad * pad, GstBuffer * buffer)
3889 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3890 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3891 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3893 return gst_pad_push_data (pad,
3894 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3898 * gst_pad_push_list:
3899 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3900 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
3903 * Pushes a buffer list to the peer of @pad.
3905 * This function will call installed block probes before triggering any
3906 * installed data probes.
3908 * The function proceeds calling the chain function on the peer pad and returns
3909 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3910 * be returned. If the peer pad does not have any installed chainlist function
3911 * every group buffer of the list will be merged into a normal #GstBuffer and
3912 * chained via gst_pad_chain().
3914 * In all cases, success or failure, the caller loses its reference to @list
3915 * after calling this function.
3917 * Returns: a #GstFlowReturn from the peer pad.
3924 gst_pad_push_list (GstPad * pad, GstBufferList * list)
3926 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3927 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3928 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3930 return gst_pad_push_data (pad,
3931 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3934 static GstFlowReturn
3935 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
3936 GstBuffer ** buffer)
3939 GstPadGetRangeFunction getrangefunc;
3943 GST_PAD_STREAM_LOCK (pad);
3945 GST_OBJECT_LOCK (pad);
3946 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3949 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
3952 if (G_UNLIKELY ((ret = check_sticky (pad))) != GST_FLOW_OK)
3957 /* when one of the probes returns DROPPED, probe_stopped will be called
3958 * and we skip calling the getrange function, res_buf should then contain a
3959 * valid result buffer */
3960 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
3961 res_buf, offset, size, probe_stopped);
3963 ACQUIRE_PARENT (pad, parent, no_parent);
3964 GST_OBJECT_UNLOCK (pad);
3966 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
3969 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3970 "calling getrangefunc %s, offset %"
3971 G_GUINT64_FORMAT ", size %u",
3972 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
3974 ret = getrangefunc (pad, parent, offset, size, &res_buf);
3976 RELEASE_PARENT (parent);
3978 if (G_UNLIKELY (ret != GST_FLOW_OK))
3979 goto get_range_failed;
3981 /* can only fire the signal if we have a valid buffer */
3982 GST_OBJECT_LOCK (pad);
3984 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
3985 res_buf, offset, size, probe_stopped_unref);
3986 GST_OBJECT_UNLOCK (pad);
3988 GST_PAD_STREAM_UNLOCK (pad);
3997 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3998 "getrange, but pad was flushing");
3999 GST_OBJECT_UNLOCK (pad);
4000 GST_PAD_STREAM_UNLOCK (pad);
4001 return GST_FLOW_FLUSHING;
4005 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4006 GST_DEBUG_PAD_NAME (pad));
4007 GST_OBJECT_UNLOCK (pad);
4008 GST_PAD_STREAM_UNLOCK (pad);
4009 return GST_FLOW_ERROR;
4013 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4014 GST_OBJECT_UNLOCK (pad);
4015 GST_PAD_STREAM_UNLOCK (pad);
4020 GST_DEBUG_OBJECT (pad, "no parent");
4021 GST_OBJECT_UNLOCK (pad);
4022 GST_PAD_STREAM_UNLOCK (pad);
4023 return GST_FLOW_FLUSHING;
4027 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4028 GST_DEBUG_PAD_NAME (pad));
4029 RELEASE_PARENT (parent);
4030 GST_PAD_STREAM_UNLOCK (pad);
4031 return GST_FLOW_NOT_SUPPORTED;
4035 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4036 "probe returned %s", gst_flow_get_name (ret));
4037 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4039 /* the probe filled the buffer and asks us to not call the getrange
4040 * anymore, we continue with the post probes then. */
4041 GST_DEBUG_OBJECT (pad, "handled buffer");
4045 /* no buffer, we are EOS */
4046 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4050 GST_OBJECT_UNLOCK (pad);
4051 GST_PAD_STREAM_UNLOCK (pad);
4055 probe_stopped_unref:
4057 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4058 "probe returned %s", gst_flow_get_name (ret));
4059 /* if we drop here, it signals EOS */
4060 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4062 GST_OBJECT_UNLOCK (pad);
4063 GST_PAD_STREAM_UNLOCK (pad);
4064 if (*buffer == NULL)
4065 gst_buffer_unref (res_buf);
4070 GST_PAD_STREAM_UNLOCK (pad);
4071 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4072 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4073 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4079 * gst_pad_get_range:
4080 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4081 * @offset: The start offset of the buffer
4082 * @size: The length of the buffer
4083 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4084 * returns #GST_FLOW_ERROR if %NULL.
4086 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4087 * immediately and @buffer is %NULL.
4089 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4090 * description of a getrange function. If @pad has no getrange function
4091 * installed (see gst_pad_set_getrange_function()) this function returns
4092 * #GST_FLOW_NOT_SUPPORTED.
4094 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4095 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4096 * must be freed with gst_buffer_unref() after usage.
4098 * When @buffer points to a variable that points to a valid #GstBuffer, the
4099 * buffer will be filled with the result data when this function returns
4100 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4101 * @size bytes will be filled in the result buffer and its size will be updated
4104 * Note that less than @size bytes can be returned in @buffer when, for example,
4105 * an EOS condition is near or when @buffer is not large enough to hold @size
4106 * bytes. The caller should check the result buffer size to get the result size.
4108 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4109 * will be unchanged.
4111 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
4113 * Returns: a #GstFlowReturn from the pad.
4118 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4119 GstBuffer ** buffer)
4121 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4122 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4123 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4124 g_return_val_if_fail (*buffer == NULL
4125 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4127 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4131 * gst_pad_pull_range:
4132 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4133 * @offset: The start offset of the buffer
4134 * @size: The length of the buffer
4135 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4136 * GST_FLOW_ERROR if %NULL.
4138 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4140 * This function will first trigger the pad block signal if it was
4143 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4144 * function returns the result of gst_pad_get_range() on the peer pad.
4145 * See gst_pad_get_range() for a list of return values and for the
4146 * semantics of the arguments of this function.
4148 * If @buffer points to a variable holding NULL, a valid new #GstBuffer will be
4149 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4150 * must be freed with gst_buffer_unref() after usage. When this function
4151 * returns any other result value, @buffer will still point to NULL.
4153 * When @buffer points to a variable that points to a valid #GstBuffer, the
4154 * buffer will be filled with the result data when this function returns
4155 * #GST_FLOW_OK. When this function returns any other result value,
4156 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4157 * @size bytes will be filled in the result buffer and its size will be updated
4160 * Note that less than @size bytes can be returned in @buffer when, for example,
4161 * an EOS condition is near or when @buffer is not large enough to hold @size
4162 * bytes. The caller should check the result buffer size to get the result size.
4164 * Returns: a #GstFlowReturn from the peer pad.
4169 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4170 GstBuffer ** buffer)
4176 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4177 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4178 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4179 g_return_val_if_fail (*buffer == NULL
4180 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4182 GST_OBJECT_LOCK (pad);
4183 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4186 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4191 /* when one of the probes returns DROPPED, probe_stopped will be
4192 * called and we skip calling the peer getrange function. *buffer should then
4193 * contain a valid buffer */
4194 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4195 res_buf, offset, size, probe_stopped);
4197 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4200 gst_object_ref (peer);
4202 GST_OBJECT_UNLOCK (pad);
4204 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4206 gst_object_unref (peer);
4208 GST_OBJECT_LOCK (pad);
4210 if (pad->priv->using == 0) {
4211 /* pad is not active anymore, trigger idle callbacks */
4212 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4213 probe_stopped_unref, ret);
4216 if (G_UNLIKELY (ret != GST_FLOW_OK))
4217 goto pull_range_failed;
4220 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4221 res_buf, offset, size, probe_stopped_unref);
4223 GST_OBJECT_UNLOCK (pad);
4229 /* ERROR recovery here */
4232 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4233 "pullrange, but pad was flushing");
4234 GST_OBJECT_UNLOCK (pad);
4235 return GST_FLOW_FLUSHING;
4239 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4240 GST_DEBUG_PAD_NAME (pad));
4241 GST_OBJECT_UNLOCK (pad);
4242 return GST_FLOW_ERROR;
4246 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4247 gst_flow_get_name (ret));
4248 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4250 /* the probe filled the buffer and asks us to not forward to the peer
4251 * anymore, we continue with the post probes then */
4252 GST_DEBUG_OBJECT (pad, "handled buffer");
4256 /* no buffer, we are EOS then */
4257 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4261 GST_OBJECT_UNLOCK (pad);
4266 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4267 "pulling range, but it was not linked");
4268 GST_OBJECT_UNLOCK (pad);
4269 return GST_FLOW_NOT_LINKED;
4273 GST_OBJECT_UNLOCK (pad);
4274 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4275 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4276 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4279 probe_stopped_unref:
4281 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4282 "post probe returned %s", gst_flow_get_name (ret));
4283 GST_OBJECT_UNLOCK (pad);
4284 /* if we drop here, it signals EOS */
4285 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4287 if (*buffer == NULL)
4288 gst_buffer_unref (res_buf);
4294 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event, gboolean locked)
4299 gboolean res = FALSE;
4300 const gchar *name = NULL;
4302 type = GST_EVENT_TYPE (event);
4303 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4304 name = gst_structure_get_name (gst_event_get_structure (event));
4306 events = pad->priv->events;
4309 for (i = 0; i < len; i++) {
4310 PadEvent *ev = &g_array_index (events, PadEvent, i);
4312 if (ev->event == NULL)
4315 if (type == GST_EVENT_TYPE (ev->event)) {
4316 /* matching types, check matching name if needed */
4317 if (name && !gst_event_has_name (ev->event, name))
4321 if ((res = gst_event_replace (&ev->event, event)))
4322 ev->received = FALSE;
4328 ev.event = gst_event_ref (event);
4329 ev.received = FALSE;
4330 g_array_append_val (events, ev);
4335 pad->priv->events_cookie++;
4336 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4338 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4340 switch (GST_EVENT_TYPE (event)) {
4341 case GST_EVENT_CAPS:
4343 GST_OBJECT_UNLOCK (pad);
4345 GST_DEBUG_OBJECT (pad, "notify caps");
4346 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4349 GST_OBJECT_LOCK (pad);
4358 /* should be called with pad LOCK */
4359 static GstFlowReturn
4360 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4361 GstPadProbeType type)
4365 GstEventType event_type;
4367 /* Two checks to be made:
4368 * . (un)set the FLUSHING flag for flushing events,
4369 * . handle pad blocking */
4370 event_type = GST_EVENT_TYPE (event);
4371 switch (event_type) {
4372 case GST_EVENT_FLUSH_START:
4373 GST_PAD_SET_FLUSHING (pad);
4375 GST_PAD_BLOCK_BROADCAST (pad);
4376 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4378 case GST_EVENT_FLUSH_STOP:
4379 GST_PAD_UNSET_FLUSHING (pad);
4381 /* Remove sticky EOS events */
4382 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4383 remove_event_by_type (pad, GST_EVENT_EOS);
4384 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4386 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4390 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4393 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4394 * checked already or this is called as part of pushing sticky events,
4395 * in which case we still want to forward the EOS event downstream.
4398 switch (GST_EVENT_TYPE (event)) {
4399 case GST_EVENT_SEGMENT:
4400 /* pass the adjusted segment event on. We need to do this even if
4401 * there is no peer pad because of the probes. */
4402 event = apply_pad_offset (pad, event);
4404 case GST_EVENT_RECONFIGURE:
4405 if (GST_PAD_IS_SINK (pad))
4406 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4411 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4412 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4417 /* send probes after modifying the events above */
4418 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4420 /* now check the peer pad */
4421 peerpad = GST_PAD_PEER (pad);
4422 if (peerpad == NULL)
4425 gst_object_ref (peerpad);
4427 GST_OBJECT_UNLOCK (pad);
4429 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4430 event, GST_EVENT_TYPE_NAME (event), peerpad);
4432 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4434 /* Note: we gave away ownership of the event at this point but we can still
4435 * print the old pointer */
4436 GST_LOG_OBJECT (pad,
4437 "sent event %p to peerpad %" GST_PTR_FORMAT ", ret %s", event, peerpad,
4438 gst_flow_get_name (ret));
4440 gst_object_unref (peerpad);
4442 GST_OBJECT_LOCK (pad);
4444 if (pad->priv->using == 0) {
4445 /* pad is not active anymore, trigger idle callbacks */
4446 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4447 idle_probe_stopped, ret);
4451 /* ERROR handling */
4454 GST_DEBUG_OBJECT (pad, "We're flushing");
4455 gst_event_unref (event);
4456 return GST_FLOW_FLUSHING;
4460 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4461 gst_event_unref (event);
4464 case GST_FLOW_CUSTOM_SUCCESS:
4465 GST_DEBUG_OBJECT (pad, "dropped event");
4469 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4476 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4477 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4478 gst_event_unref (event);
4480 /* unlinked pads should not influence latency configuration */
4481 if (event_type == GST_EVENT_LATENCY)
4484 return GST_FLOW_NOT_LINKED;
4488 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4494 * gst_pad_push_event:
4495 * @pad: a #GstPad to push the event to.
4496 * @event: (transfer full): the #GstEvent to send to the pad.
4498 * Sends the event to the peer of the given pad. This function is
4499 * mainly used by elements to send events to their peer
4502 * This function takes owership of the provided event so you should
4503 * gst_event_ref() it if you want to reuse the event after this call.
4505 * Returns: TRUE if the event was handled.
4510 gst_pad_push_event (GstPad * pad, GstEvent * event)
4512 gboolean res = FALSE;
4513 GstPadProbeType type;
4514 gboolean sticky, serialized;
4516 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4517 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4519 if (GST_PAD_IS_SRC (pad)) {
4520 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4521 goto wrong_direction;
4522 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4523 } else if (GST_PAD_IS_SINK (pad)) {
4524 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4525 goto wrong_direction;
4526 /* events pushed on sinkpad never are sticky */
4527 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4529 goto unknown_direction;
4531 GST_OBJECT_LOCK (pad);
4532 sticky = GST_EVENT_IS_STICKY (event);
4533 serialized = GST_EVENT_IS_SERIALIZED (event);
4536 /* can't store on flushing pads */
4537 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4540 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4543 /* srcpad sticky events are store immediately, the received flag is set
4544 * to FALSE and will be set to TRUE when we can successfully push the
4545 * event to the peer pad */
4546 if (gst_pad_store_sticky_event (pad, event, TRUE)) {
4547 GST_DEBUG_OBJECT (pad, "event %s updated", GST_EVENT_TYPE_NAME (event));
4549 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS)
4550 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4552 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4553 /* all serialized or sticky events on the srcpad trigger push of
4555 res = (check_sticky (pad) == GST_FLOW_OK);
4558 /* other events are pushed right away */
4559 res = (gst_pad_push_event_unchecked (pad, event, type) == GST_FLOW_OK);
4561 /* Errors in sticky event pushing are no problem and ignored here
4562 * as they will cause more meaningful errors during data flow.
4563 * For EOS events, that are not followed by data flow, we still
4564 * return FALSE here though.
4566 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4568 gst_event_unref (event);
4570 GST_OBJECT_UNLOCK (pad);
4574 /* ERROR handling */
4577 g_warning ("pad %s:%s pushing %s event in wrong direction",
4578 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4579 gst_event_unref (event);
4584 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4585 gst_event_unref (event);
4590 GST_DEBUG_OBJECT (pad, "We're flushing");
4591 GST_OBJECT_UNLOCK (pad);
4592 gst_event_unref (event);
4597 GST_DEBUG_OBJECT (pad, "We're EOS");
4598 GST_OBJECT_UNLOCK (pad);
4599 gst_event_unref (event);
4604 /* Check if we can call the event function with the given event */
4605 static GstFlowReturn
4606 pre_eventfunc_check (GstPad * pad, GstEvent * event)
4610 switch (GST_EVENT_TYPE (event)) {
4611 case GST_EVENT_CAPS:
4613 /* backwards compatibility mode for caps */
4614 gst_event_parse_caps (event, &caps);
4616 if (!gst_pad_query_accept_caps (pad, caps))
4628 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
4629 "caps %" GST_PTR_FORMAT " not accepted", caps);
4630 return GST_FLOW_NOT_NEGOTIATED;
4634 static GstFlowReturn
4635 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
4636 GstPadProbeType type)
4639 GstEventType event_type;
4640 gboolean serialized, need_unlock = FALSE, sticky;
4641 GstPadEventFunction eventfunc;
4644 GST_OBJECT_LOCK (pad);
4645 if (GST_PAD_IS_SINK (pad))
4646 serialized = GST_EVENT_IS_SERIALIZED (event);
4649 sticky = GST_EVENT_IS_STICKY (event);
4650 event_type = GST_EVENT_TYPE (event);
4651 switch (event_type) {
4652 case GST_EVENT_FLUSH_START:
4653 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4654 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4656 /* can't even accept a flush begin event when flushing */
4657 if (GST_PAD_IS_FLUSHING (pad))
4660 GST_PAD_SET_FLUSHING (pad);
4661 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4663 case GST_EVENT_FLUSH_STOP:
4664 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
4665 GST_PAD_UNSET_FLUSHING (pad);
4666 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4668 /* Remove pending EOS events */
4669 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4670 remove_event_by_type (pad, GST_EVENT_EOS);
4671 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4673 GST_OBJECT_UNLOCK (pad);
4674 /* grab stream lock */
4675 GST_PAD_STREAM_LOCK (pad);
4677 GST_OBJECT_LOCK (pad);
4678 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4681 case GST_EVENT_RECONFIGURE:
4682 if (GST_PAD_IS_SRC (pad))
4683 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4685 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4686 "have event type %" GST_PTR_FORMAT, event);
4688 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4692 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4695 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4696 GST_OBJECT_UNLOCK (pad);
4697 GST_PAD_STREAM_LOCK (pad);
4699 GST_OBJECT_LOCK (pad);
4700 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4703 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4707 switch (GST_EVENT_TYPE (event)) {
4708 case GST_EVENT_SEGMENT:
4709 event = apply_pad_offset (pad, event);
4715 /* now do the probe */
4717 type | GST_PAD_PROBE_TYPE_PUSH |
4718 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4720 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4724 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4727 ACQUIRE_PARENT (pad, parent, no_parent);
4728 GST_OBJECT_UNLOCK (pad);
4730 ret = pre_eventfunc_check (pad, event);
4731 if (G_UNLIKELY (ret != GST_FLOW_OK))
4732 goto precheck_failed;
4735 gst_event_ref (event);
4737 if (eventfunc (pad, parent, event)) {
4740 /* something went wrong */
4741 switch (event_type) {
4742 case GST_EVENT_CAPS:
4743 ret = GST_FLOW_NOT_NEGOTIATED;
4746 ret = GST_FLOW_ERROR;
4750 RELEASE_PARENT (parent);
4752 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
4755 if (ret == GST_FLOW_OK) {
4756 /* after the event function accepted the event, we can store the sticky
4757 * event on the pad */
4758 gst_pad_store_sticky_event (pad, event, FALSE);
4759 if (event_type == GST_EVENT_EOS)
4760 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4762 gst_event_unref (event);
4766 GST_PAD_STREAM_UNLOCK (pad);
4770 /* ERROR handling */
4773 GST_OBJECT_UNLOCK (pad);
4775 GST_PAD_STREAM_UNLOCK (pad);
4776 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
4777 "Received event on flushing pad. Discarding");
4778 gst_event_unref (event);
4779 return GST_FLOW_FLUSHING;
4783 GST_OBJECT_UNLOCK (pad);
4785 GST_PAD_STREAM_UNLOCK (pad);
4786 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
4787 "Received event on EOS pad. Discarding");
4788 gst_event_unref (event);
4789 return GST_FLOW_EOS;
4793 GST_OBJECT_UNLOCK (pad);
4795 GST_PAD_STREAM_UNLOCK (pad);
4796 gst_event_unref (event);
4799 case GST_FLOW_CUSTOM_SUCCESS:
4800 GST_DEBUG_OBJECT (pad, "dropped event");
4804 GST_DEBUG_OBJECT (pad, "an error occured %s", gst_flow_get_name (ret));
4811 g_warning ("pad %s:%s has no event handler, file a bug.",
4812 GST_DEBUG_PAD_NAME (pad));
4813 GST_OBJECT_UNLOCK (pad);
4815 GST_PAD_STREAM_UNLOCK (pad);
4816 gst_event_unref (event);
4817 return GST_FLOW_NOT_SUPPORTED;
4821 GST_DEBUG_OBJECT (pad, "no parent");
4822 GST_OBJECT_UNLOCK (pad);
4824 GST_PAD_STREAM_UNLOCK (pad);
4825 gst_event_unref (event);
4826 return GST_FLOW_FLUSHING;
4830 GST_DEBUG_OBJECT (pad, "pre event check failed");
4831 RELEASE_PARENT (parent);
4833 GST_PAD_STREAM_UNLOCK (pad);
4834 gst_event_unref (event);
4840 * gst_pad_send_event:
4841 * @pad: a #GstPad to send the event to.
4842 * @event: (transfer full): the #GstEvent to send to the pad.
4844 * Sends the event to the pad. This function can be used
4845 * by applications to send events in the pipeline.
4847 * If @pad is a source pad, @event should be an upstream event. If @pad is a
4848 * sink pad, @event should be a downstream event. For example, you would not
4849 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
4850 * Furthermore, some downstream events have to be serialized with data flow,
4851 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
4852 * the event needs to be serialized with data flow, this function will take the
4853 * pad's stream lock while calling its event function.
4855 * To find out whether an event type is upstream, downstream, or downstream and
4856 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
4857 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
4858 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
4859 * plugin doesn't need to bother itself with this information; the core handles
4860 * all necessary locks and checks.
4862 * This function takes owership of the provided event so you should
4863 * gst_event_ref() it if you want to reuse the event after this call.
4865 * Returns: TRUE if the event was handled.
4868 gst_pad_send_event (GstPad * pad, GstEvent * event)
4871 GstPadProbeType type;
4873 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4874 g_return_val_if_fail (event != NULL, FALSE);
4876 if (GST_PAD_IS_SINK (pad)) {
4877 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4878 goto wrong_direction;
4879 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4880 } else if (GST_PAD_IS_SRC (pad)) {
4881 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4882 goto wrong_direction;
4883 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4885 goto unknown_direction;
4887 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
4894 /* ERROR handling */
4897 g_warning ("pad %s:%s sending %s event in wrong direction",
4898 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4899 gst_event_unref (event);
4904 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4905 gst_event_unref (event);
4911 * gst_pad_set_element_private:
4912 * @pad: the #GstPad to set the private data of.
4913 * @priv: The private data to attach to the pad.
4915 * Set the given private data gpointer on the pad.
4916 * This function can only be used by the element that owns the pad.
4917 * No locking is performed in this function.
4920 gst_pad_set_element_private (GstPad * pad, gpointer priv)
4922 pad->element_private = priv;
4926 * gst_pad_get_element_private:
4927 * @pad: the #GstPad to get the private data of.
4929 * Gets the private data of a pad.
4930 * No locking is performed in this function.
4932 * Returns: (transfer none): a #gpointer to the private data.
4935 gst_pad_get_element_private (GstPad * pad)
4937 return pad->element_private;
4941 * gst_pad_get_sticky_event:
4942 * @pad: the #GstPad to get the event from.
4943 * @event_type: the #GstEventType that should be retrieved.
4944 * @idx: the index of the event
4946 * Returns a new reference of the sticky event of type @event_type
4949 * Returns: (transfer full): a #GstEvent of type @event_type or NULL when no
4950 * event of @event_type was on @pad. Unref after usage.
4953 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
4955 GstEvent *event = NULL;
4958 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4959 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
4961 GST_OBJECT_LOCK (pad);
4962 ev = find_event_by_type (pad, event_type, idx);
4963 if (ev && (event = ev->event))
4964 gst_event_ref (event);
4965 GST_OBJECT_UNLOCK (pad);
4972 GstPadStickyEventsForeachFunction func;
4977 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
4979 ForeachDispatch *data = user_data;
4982 GST_OBJECT_UNLOCK (pad);
4984 ret = data->func (pad, &ev->event, data->user_data);
4986 GST_OBJECT_LOCK (pad);
4992 * gst_pad_sticky_events_foreach:
4993 * @pad: the #GstPad that should be used for iteration.
4994 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
4995 * should be called for every event.
4996 * @user_data: (closure): the optional user data.
4998 * Iterates all sticky events on @pad and calls @foreach_func for every
4999 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5002 gst_pad_sticky_events_foreach (GstPad * pad,
5003 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5005 ForeachDispatch data;
5007 g_return_if_fail (GST_IS_PAD (pad));
5008 g_return_if_fail (foreach_func != NULL);
5010 data.func = foreach_func;
5011 data.user_data = user_data;
5013 GST_OBJECT_LOCK (pad);
5014 events_foreach (pad, foreach_dispatch_function, &data);
5015 GST_OBJECT_UNLOCK (pad);
5019 do_stream_status (GstPad * pad, GstStreamStatusType type,
5020 GThread * thread, GstTask * task)
5024 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5026 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5027 if (GST_IS_ELEMENT (parent)) {
5028 GstMessage *message;
5029 GValue value = { 0 };
5031 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5032 gchar *tname, *ename, *pname;
5034 /* create a good task name */
5035 ename = gst_element_get_name (parent);
5036 pname = gst_pad_get_name (pad);
5037 tname = g_strdup_printf ("%s:%s", ename, pname);
5041 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5045 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5048 g_value_init (&value, GST_TYPE_TASK);
5049 g_value_set_object (&value, task);
5050 gst_message_set_stream_status_object (message, &value);
5051 g_value_unset (&value);
5053 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5054 gst_element_post_message (parent, message);
5056 gst_object_unref (parent);
5061 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5063 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5068 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5070 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5075 * gst_pad_start_task:
5076 * @pad: the #GstPad to start the task of
5077 * @func: the task function to call
5078 * @user_data: user data passed to the task function
5079 * @notify: called when @user_data is no longer referenced
5081 * Starts a task that repeatedly calls @func with @user_data. This function
5082 * is mostly used in pad activation functions to start the dataflow.
5083 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5084 * before @func is called.
5086 * Returns: a %TRUE if the task could be started.
5089 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5090 GDestroyNotify notify)
5095 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5096 g_return_val_if_fail (func != NULL, FALSE);
5098 GST_DEBUG_OBJECT (pad, "start task");
5100 GST_OBJECT_LOCK (pad);
5101 task = GST_PAD_TASK (pad);
5103 task = gst_task_new (func, user_data, notify);
5104 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5105 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5106 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5107 GST_INFO_OBJECT (pad, "created task %p", task);
5108 GST_PAD_TASK (pad) = task;
5109 gst_object_ref (task);
5110 /* release lock to post the message */
5111 GST_OBJECT_UNLOCK (pad);
5113 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5115 gst_object_unref (task);
5117 GST_OBJECT_LOCK (pad);
5118 /* nobody else is supposed to have changed the pad now */
5119 if (GST_PAD_TASK (pad) != task)
5120 goto concurrent_stop;
5122 res = gst_task_set_state (task, GST_TASK_STARTED);
5123 GST_OBJECT_UNLOCK (pad);
5130 GST_OBJECT_UNLOCK (pad);
5136 * gst_pad_pause_task:
5137 * @pad: the #GstPad to pause the task of
5139 * Pause the task of @pad. This function will also wait until the
5140 * function executed by the task is finished if this function is not
5141 * called from the task function.
5143 * Returns: a TRUE if the task could be paused or FALSE when the pad
5147 gst_pad_pause_task (GstPad * pad)
5152 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5154 GST_DEBUG_OBJECT (pad, "pause task");
5156 GST_OBJECT_LOCK (pad);
5157 task = GST_PAD_TASK (pad);
5160 res = gst_task_set_state (task, GST_TASK_PAUSED);
5161 GST_OBJECT_UNLOCK (pad);
5163 /* wait for task function to finish, this lock is recursive so it does nothing
5164 * when the pause is called from the task itself */
5165 GST_PAD_STREAM_LOCK (pad);
5166 GST_PAD_STREAM_UNLOCK (pad);
5172 GST_DEBUG_OBJECT (pad, "pad has no task");
5173 GST_OBJECT_UNLOCK (pad);
5179 * gst_pad_stop_task:
5180 * @pad: the #GstPad to stop the task of
5182 * Stop the task of @pad. This function will also make sure that the
5183 * function executed by the task will effectively stop if not called
5184 * from the GstTaskFunction.
5186 * This function will deadlock if called from the GstTaskFunction of
5187 * the task. Use gst_task_pause() instead.
5189 * Regardless of whether the pad has a task, the stream lock is acquired and
5190 * released so as to ensure that streaming through this pad has finished.
5192 * Returns: a TRUE if the task could be stopped or FALSE on error.
5195 gst_pad_stop_task (GstPad * pad)
5200 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5202 GST_DEBUG_OBJECT (pad, "stop task");
5204 GST_OBJECT_LOCK (pad);
5205 task = GST_PAD_TASK (pad);
5208 GST_PAD_TASK (pad) = NULL;
5209 res = gst_task_set_state (task, GST_TASK_STOPPED);
5210 GST_OBJECT_UNLOCK (pad);
5212 GST_PAD_STREAM_LOCK (pad);
5213 GST_PAD_STREAM_UNLOCK (pad);
5215 if (!gst_task_join (task))
5218 gst_object_unref (task);
5224 GST_DEBUG_OBJECT (pad, "no task");
5225 GST_OBJECT_UNLOCK (pad);
5227 GST_PAD_STREAM_LOCK (pad);
5228 GST_PAD_STREAM_UNLOCK (pad);
5230 /* this is not an error */
5235 /* this is bad, possibly the application tried to join the task from
5236 * the task's thread. We install the task again so that it will be stopped
5237 * again from the right thread next time hopefully. */
5238 GST_OBJECT_LOCK (pad);
5239 GST_DEBUG_OBJECT (pad, "join failed");
5240 /* we can only install this task if there was no other task */
5241 if (GST_PAD_TASK (pad) == NULL)
5242 GST_PAD_TASK (pad) = task;
5243 GST_OBJECT_UNLOCK (pad);