2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 * @short_description: Object contained by elements that allows links to
26 * @see_also: #GstPadTemplate, #GstElement, #GstEvent, #GstQuery, #GstBuffer
28 * A #GstElement is linked to other elements via "pads", which are extremely
29 * light-weight generic link points.
31 * Pads have a #GstPadDirection, source pads produce data, sink pads consume
34 * Pads are typically created from a #GstPadTemplate with
35 * gst_pad_new_from_template() and are then added to a #GstElement. This usually
36 * happens when the element is created but it can also happen dynamically based
37 * on the data that the element is processing or based on the pads that the
38 * application requests.
40 * Pads without pad templates can be created with gst_pad_new(),
41 * which takes a direction and a name as an argument. If the name is %NULL,
42 * then a guaranteed unique name will be assigned to it.
44 * A #GstElement creating a pad will typically use the various
45 * gst_pad_set_*_function() calls to register callbacks for events, queries or
46 * dataflow on the pads.
48 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
50 * After two pads are retrieved from an element by gst_element_get_static_pad(),
51 * the pads can be linked with gst_pad_link(). (For quick links,
52 * you can also use gst_element_link(), which will make the obvious
53 * link for you if it's straightforward.). Pads can be unlinked again with
54 * gst_pad_unlink(). gst_pad_get_peer() can be used to check what the pad is
57 * Before dataflow is possible on the pads, they need to be activated with
58 * gst_pad_set_active().
60 * gst_pad_query() and gst_pad_peer_query() can be used to query various
61 * properties of the pad and the stream.
63 * To send a #GstEvent on a pad, use gst_pad_send_event() and
64 * gst_pad_push_event(). Some events will be sticky on the pad, meaning that
65 * after they pass on the pad they can be queried later with
66 * gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().
67 * gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience
68 * functions to query the current sticky CAPS event on a pad.
70 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
71 * or pull in a buffer.
73 * The dataflow, events and queries that happen on a pad can be monitored with
74 * probes that can be installed with gst_pad_add_probe(). gst_pad_is_blocked()
75 * can be used to check if a block probe is installed on the pad.
76 * gst_pad_is_blocking() checks if the blocking probe is currently blocking the
77 * pad. gst_pad_remove_probe() is used to remove a previously installed probe
78 * and unblock blocking probes if any.
80 * Pad have an offset that can be retrieved with gst_pad_get_offset(). This
81 * offset will be applied to the running_time of all data passing over the pad.
82 * gst_pad_set_offset() can be used to change the offset.
84 * Convenience functions exist to start, pause and stop the task on a pad with
85 * gst_pad_start_task(), gst_pad_pause_task() and gst_pad_stop_task()
89 #include "gst_private.h"
92 #include "gstpadtemplate.h"
93 #include "gstenumtypes.h"
98 #include "glib-compat-private.h"
100 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
101 #define GST_CAT_DEFAULT GST_CAT_PADS
103 /* Pad signals and args */
122 #define GST_PAD_GET_PRIVATE(obj) \
123 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
125 /* we have a pending and an active event on the pad. On source pads only the
126 * active event is used. On sinkpads, events are copied to the pending entry and
127 * moved to the active event when the eventfunc returned %TRUE. */
134 struct _GstPadPrivate
141 guint probe_list_cookie;
144 /* counter of how many idle probes are running directly from the add_probe
145 * call. Used to block any data flowing in the pad while the idle callback
146 * Doesn't finish its work */
156 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
157 #define GST_PAD_IS_RUNNING_IDLE_PROBE(p) \
158 (((GstPad *)(p))->priv->idle_running > 0)
163 GstPadProbeInfo *info;
171 static void gst_pad_dispose (GObject * object);
172 static void gst_pad_finalize (GObject * object);
173 static void gst_pad_set_property (GObject * object, guint prop_id,
174 const GValue * value, GParamSpec * pspec);
175 static void gst_pad_get_property (GObject * object, guint prop_id,
176 GValue * value, GParamSpec * pspec);
178 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
179 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
180 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
181 GstObject * parent, GstBufferList * list);
183 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
184 GstEvent * event, GstPadProbeType type);
185 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
186 GstEvent * event, GstPadProbeType type);
188 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
190 static GParamSpec *pspec_caps = NULL;
192 /* quarks for probe signals */
193 static GQuark buffer_quark;
194 static GQuark buffer_list_quark;
195 static GQuark event_quark;
204 static GstFlowQuarks flow_quarks[] = {
205 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
206 {GST_FLOW_OK, "ok", 0},
207 {GST_FLOW_NOT_LINKED, "not-linked", 0},
208 {GST_FLOW_FLUSHING, "flushing", 0},
209 {GST_FLOW_EOS, "eos", 0},
210 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
211 {GST_FLOW_ERROR, "error", 0},
212 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
213 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
218 * @ret: a #GstFlowReturn to get the name of.
220 * Gets a string representing the given flow return.
222 * Returns: a static string with the name of the flow return.
225 gst_flow_get_name (GstFlowReturn ret)
229 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
231 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
232 if (ret == flow_quarks[i].ret)
233 return flow_quarks[i].name;
240 * @ret: a #GstFlowReturn to get the quark of.
242 * Get the unique quark for the given GstFlowReturn.
244 * Returns: the quark associated with the flow return or 0 if an
245 * invalid return was specified.
248 gst_flow_to_quark (GstFlowReturn ret)
252 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
254 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
255 if (ret == flow_quarks[i].ret)
256 return flow_quarks[i].quark;
262 * gst_pad_link_get_name:
263 * @ret: a #GstPadLinkReturn to get the name of.
265 * Gets a string representing the given pad-link return.
267 * Returns: a static string with the name of the pad-link return.
272 gst_pad_link_get_name (GstPadLinkReturn ret)
275 case GST_PAD_LINK_OK:
277 case GST_PAD_LINK_WRONG_HIERARCHY:
278 return "wrong hierarchy";
279 case GST_PAD_LINK_WAS_LINKED:
281 case GST_PAD_LINK_WRONG_DIRECTION:
282 return "wrong direction";
283 case GST_PAD_LINK_NOFORMAT:
284 return "no common format";
285 case GST_PAD_LINK_NOSCHED:
286 return "incompatible scheduling";
287 case GST_PAD_LINK_REFUSED:
290 g_return_val_if_reached ("unknown");
297 buffer_quark = g_quark_from_static_string ("buffer"); \
298 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
299 event_quark = g_quark_from_static_string ("event"); \
301 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
302 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
305 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
306 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
309 #define gst_pad_parent_class parent_class
310 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
313 gst_pad_class_init (GstPadClass * klass)
315 GObjectClass *gobject_class;
316 GstObjectClass *gstobject_class;
318 gobject_class = G_OBJECT_CLASS (klass);
319 gstobject_class = GST_OBJECT_CLASS (klass);
321 g_type_class_add_private (klass, sizeof (GstPadPrivate));
323 gobject_class->dispose = gst_pad_dispose;
324 gobject_class->finalize = gst_pad_finalize;
325 gobject_class->set_property = gst_pad_set_property;
326 gobject_class->get_property = gst_pad_get_property;
330 * @pad: the pad that emitted the signal
331 * @peer: the peer pad that has been connected
333 * Signals that a pad has been linked to the peer pad.
335 gst_pad_signals[PAD_LINKED] =
336 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
337 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
338 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
341 * @pad: the pad that emitted the signal
342 * @peer: the peer pad that has been disconnected
344 * Signals that a pad has been unlinked from the peer pad.
346 gst_pad_signals[PAD_UNLINKED] =
347 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
348 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
349 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
351 pspec_caps = g_param_spec_boxed ("caps", "Caps",
352 "The capabilities of the pad", GST_TYPE_CAPS,
353 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
354 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
356 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
357 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
358 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
359 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
361 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
362 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
363 g_param_spec_object ("template", "Template",
364 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
365 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
370 * The offset that will be applied to the running time of the pad.
374 g_object_class_install_property (gobject_class, PAD_PROP_OFFSET,
375 g_param_spec_int64 ("offset", "Offset",
376 "The running time offset of the pad", 0, G_MAXINT64, 0,
377 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
379 gstobject_class->path_string_separator = ".";
381 /* Register common function pointer descriptions */
382 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
383 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
384 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
385 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
386 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
390 gst_pad_init (GstPad * pad)
392 pad->priv = GST_PAD_GET_PRIVATE (pad);
394 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
396 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
397 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
398 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
399 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
400 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
402 GST_PAD_SET_FLUSHING (pad);
404 g_rec_mutex_init (&pad->stream_rec_lock);
406 g_cond_init (&pad->block_cond);
408 g_hook_list_init (&pad->probes, sizeof (GstProbe));
410 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
411 pad->priv->events_cookie = 0;
412 pad->priv->last_cookie = -1;
413 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
416 /* called when setting the pad inactive. It removes all sticky events from
417 * the pad. must be called with object lock */
419 remove_events (GstPad * pad)
423 gboolean notify = FALSE;
425 events = pad->priv->events;
428 for (i = 0; i < len; i++) {
429 PadEvent *ev = &g_array_index (events, PadEvent, i);
430 GstEvent *event = ev->event;
434 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS)
437 gst_event_unref (event);
440 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
441 g_array_set_size (events, 0);
442 pad->priv->events_cookie++;
445 GST_OBJECT_UNLOCK (pad);
447 GST_DEBUG_OBJECT (pad, "notify caps");
448 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
450 GST_OBJECT_LOCK (pad);
454 /* should be called with object lock */
456 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
462 events = pad->priv->events;
465 for (i = 0; i < len; i++) {
466 ev = &g_array_index (events, PadEvent, i);
467 if (ev->event == NULL)
470 if (GST_EVENT_TYPE (ev->event) == type) {
481 /* should be called with OBJECT lock */
483 find_event (GstPad * pad, GstEvent * event)
489 events = pad->priv->events;
492 for (i = 0; i < len; i++) {
493 ev = &g_array_index (events, PadEvent, i);
494 if (event == ev->event)
502 /* should be called with OBJECT lock */
504 remove_event_by_type (GstPad * pad, GstEventType type)
510 events = pad->priv->events;
515 ev = &g_array_index (events, PadEvent, i);
516 if (ev->event == NULL)
519 if (GST_EVENT_TYPE (ev->event) != type)
522 gst_event_unref (ev->event);
523 g_array_remove_index (events, i);
525 pad->priv->events_cookie++;
533 /* check all events on srcpad against those on sinkpad. All events that are not
534 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
535 * srcpad so that the events will be sent next time */
536 /* should be called with srcpad and sinkpad LOCKS */
538 schedule_events (GstPad * srcpad, GstPad * sinkpad)
543 gboolean pending = FALSE;
545 events = srcpad->priv->events;
548 for (i = 0; i < len; i++) {
549 ev = &g_array_index (events, PadEvent, i);
550 if (ev->event == NULL)
553 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
554 ev->received = FALSE;
559 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
562 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
565 /* should be called with pad LOCK */
567 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
574 events = pad->priv->events;
577 cookie = pad->priv->events_cookie;
581 PadEvent *ev, ev_ret;
583 ev = &g_array_index (events, PadEvent, i);
584 if (G_UNLIKELY (ev->event == NULL))
587 /* take aditional ref, func might release the lock */
588 ev_ret.event = gst_event_ref (ev->event);
589 ev_ret.received = ev->received;
591 ret = func (pad, &ev_ret, user_data);
593 /* recheck the cookie, lock might have been released and the list could have
595 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
596 if (G_LIKELY (ev_ret.event))
597 gst_event_unref (ev_ret.event);
601 /* store the received state */
602 ev->received = ev_ret.received;
604 /* if the event changed, we need to do something */
605 if (G_UNLIKELY (ev->event != ev_ret.event)) {
606 if (G_UNLIKELY (ev_ret.event == NULL)) {
607 /* function unreffed and set the event to NULL, remove it */
608 gst_event_unref (ev->event);
609 g_array_remove_index (events, i);
611 cookie = ++pad->priv->events_cookie;
614 /* function gave a new event for us */
615 gst_event_take (&ev->event, ev_ret.event);
618 /* just unref, nothing changed */
619 gst_event_unref (ev_ret.event);
628 /* should be called with LOCK */
630 _apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
634 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_TIME_FORMAT,
635 GST_TIME_ARGS (pad->offset));
637 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
640 g_assert (!upstream);
642 /* copy segment values */
643 gst_event_copy_segment (event, &segment);
644 gst_event_unref (event);
646 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
647 event = gst_event_new_segment (&segment);
650 event = gst_event_make_writable (event);
651 offset = gst_event_get_running_time_offset (event);
653 offset -= pad->offset;
655 offset += pad->offset;
656 gst_event_set_running_time_offset (event, offset);
661 static inline GstEvent *
662 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
664 if (G_UNLIKELY (pad->offset != 0))
665 return _apply_pad_offset (pad, event, upstream);
670 /* should be called with the OBJECT_LOCK */
672 get_pad_caps (GstPad * pad)
674 GstCaps *caps = NULL;
677 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
679 gst_event_parse_caps (ev->event, &caps);
685 gst_pad_dispose (GObject * object)
687 GstPad *pad = GST_PAD_CAST (object);
690 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
692 /* unlink the peer pad */
693 if ((peer = gst_pad_get_peer (pad))) {
694 /* window for MT unsafeness, someone else could unlink here
695 * and then we call unlink with wrong pads. The unlink
696 * function would catch this and safely return failed. */
697 if (GST_PAD_IS_SRC (pad))
698 gst_pad_unlink (pad, peer);
700 gst_pad_unlink (peer, pad);
702 gst_object_unref (peer);
705 gst_pad_set_pad_template (pad, NULL);
707 GST_OBJECT_LOCK (pad);
709 GST_OBJECT_UNLOCK (pad);
711 g_hook_list_clear (&pad->probes);
713 G_OBJECT_CLASS (parent_class)->dispose (object);
717 gst_pad_finalize (GObject * object)
719 GstPad *pad = GST_PAD_CAST (object);
722 /* in case the task is still around, clean it up */
723 if ((task = GST_PAD_TASK (pad))) {
724 gst_task_join (task);
725 GST_PAD_TASK (pad) = NULL;
726 gst_object_unref (task);
729 if (pad->activatenotify)
730 pad->activatenotify (pad->activatedata);
731 if (pad->activatemodenotify)
732 pad->activatemodenotify (pad->activatemodedata);
734 pad->linknotify (pad->linkdata);
735 if (pad->unlinknotify)
736 pad->unlinknotify (pad->unlinkdata);
737 if (pad->chainnotify)
738 pad->chainnotify (pad->chaindata);
739 if (pad->chainlistnotify)
740 pad->chainlistnotify (pad->chainlistdata);
741 if (pad->getrangenotify)
742 pad->getrangenotify (pad->getrangedata);
743 if (pad->eventnotify)
744 pad->eventnotify (pad->eventdata);
745 if (pad->querynotify)
746 pad->querynotify (pad->querydata);
747 if (pad->iterintlinknotify)
748 pad->iterintlinknotify (pad->iterintlinkdata);
750 g_rec_mutex_clear (&pad->stream_rec_lock);
751 g_cond_clear (&pad->block_cond);
752 g_array_free (pad->priv->events, TRUE);
754 G_OBJECT_CLASS (parent_class)->finalize (object);
758 gst_pad_set_property (GObject * object, guint prop_id,
759 const GValue * value, GParamSpec * pspec)
761 g_return_if_fail (GST_IS_PAD (object));
764 case PAD_PROP_DIRECTION:
765 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
767 case PAD_PROP_TEMPLATE:
768 gst_pad_set_pad_template (GST_PAD_CAST (object),
769 (GstPadTemplate *) g_value_get_object (value));
771 case PAD_PROP_OFFSET:
772 gst_pad_set_offset (GST_PAD_CAST (object), g_value_get_int64 (value));
775 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
781 gst_pad_get_property (GObject * object, guint prop_id,
782 GValue * value, GParamSpec * pspec)
784 g_return_if_fail (GST_IS_PAD (object));
788 GST_OBJECT_LOCK (object);
789 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
790 GST_OBJECT_UNLOCK (object);
792 case PAD_PROP_DIRECTION:
793 g_value_set_enum (value, GST_PAD_DIRECTION (object));
795 case PAD_PROP_TEMPLATE:
796 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
798 case PAD_PROP_OFFSET:
799 g_value_set_int64 (value, gst_pad_get_offset (GST_PAD_CAST (object)));
802 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
809 * @name: (allow-none): the name of the new pad.
810 * @direction: the #GstPadDirection of the pad.
812 * Creates a new pad with the given name in the given direction.
813 * If name is %NULL, a guaranteed unique name (across all pads)
815 * This function makes a copy of the name so you can safely free the name.
817 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
823 gst_pad_new (const gchar * name, GstPadDirection direction)
825 return g_object_new (GST_TYPE_PAD,
826 "name", name, "direction", direction, NULL);
830 * gst_pad_new_from_template:
831 * @templ: the pad template to use
832 * @name: (allow-none): the name of the pad
834 * Creates a new pad with the given name from the given template.
835 * If name is %NULL, a guaranteed unique name (across all pads)
837 * This function makes a copy of the name so you can safely free the name.
839 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
843 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
845 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
847 return g_object_new (GST_TYPE_PAD,
848 "name", name, "direction", templ->direction, "template", templ, NULL);
852 * gst_pad_new_from_static_template:
853 * @templ: the #GstStaticPadTemplate to use
854 * @name: the name of the pad
856 * Creates a new pad with the given name from the given static template.
857 * If name is %NULL, a guaranteed unique name (across all pads)
859 * This function makes a copy of the name so you can safely free the name.
861 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
865 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
869 GstPadTemplate *template;
871 template = gst_static_pad_template_get (templ);
872 pad = gst_pad_new_from_template (template, name);
873 gst_object_unref (template);
877 #define ACQUIRE_PARENT(pad, parent, label) \
879 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
880 gst_object_ref (parent); \
881 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
885 #define RELEASE_PARENT(parent) \
887 if (G_LIKELY (parent)) \
888 gst_object_unref (parent); \
892 * gst_pad_get_direction:
893 * @pad: a #GstPad to get the direction of.
895 * Gets the direction of the pad. The direction of the pad is
896 * decided at construction time so this function does not take
899 * Returns: the #GstPadDirection of the pad.
904 gst_pad_get_direction (GstPad * pad)
906 GstPadDirection result;
908 /* PAD_UNKNOWN is a little silly but we need some sort of
909 * error return value */
910 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
912 result = GST_PAD_DIRECTION (pad);
918 gst_pad_activate_default (GstPad * pad, GstObject * parent)
920 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
924 * gst_pad_mode_get_name:
925 * @mode: the pad mode
927 * Return the name of a pad mode, for use in debug messages mostly.
929 * Returns: short mnemonic for pad mode @mode
932 gst_pad_mode_get_name (GstPadMode mode)
935 case GST_PAD_MODE_NONE:
937 case GST_PAD_MODE_PUSH:
939 case GST_PAD_MODE_PULL:
948 pre_activate (GstPad * pad, GstPadMode new_mode)
951 case GST_PAD_MODE_NONE:
952 GST_OBJECT_LOCK (pad);
953 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
954 GST_PAD_SET_FLUSHING (pad);
955 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
956 GST_PAD_MODE (pad) = new_mode;
957 /* unlock blocked pads so element can resume and stop */
958 GST_PAD_BLOCK_BROADCAST (pad);
959 GST_OBJECT_UNLOCK (pad);
961 case GST_PAD_MODE_PUSH:
962 case GST_PAD_MODE_PULL:
963 GST_OBJECT_LOCK (pad);
964 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
965 gst_pad_mode_get_name (new_mode));
966 GST_PAD_UNSET_FLUSHING (pad);
967 pad->ABI.abi.last_flowret = GST_FLOW_OK;
968 GST_PAD_MODE (pad) = new_mode;
969 if (GST_PAD_IS_SINK (pad)) {
971 /* make sure the peer src pad sends us all events */
972 if ((peer = GST_PAD_PEER (pad))) {
973 gst_object_ref (peer);
974 GST_OBJECT_UNLOCK (pad);
976 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
977 GST_DEBUG_PAD_NAME (peer));
979 GST_OBJECT_LOCK (peer);
980 schedule_events (peer, NULL);
981 GST_OBJECT_UNLOCK (peer);
983 gst_object_unref (peer);
985 GST_OBJECT_UNLOCK (pad);
988 GST_OBJECT_UNLOCK (pad);
995 post_activate (GstPad * pad, GstPadMode new_mode)
998 case GST_PAD_MODE_NONE:
999 /* ensures that streaming stops */
1000 GST_PAD_STREAM_LOCK (pad);
1001 GST_DEBUG_OBJECT (pad, "stopped streaming");
1002 GST_OBJECT_LOCK (pad);
1003 remove_events (pad);
1004 GST_OBJECT_UNLOCK (pad);
1005 GST_PAD_STREAM_UNLOCK (pad);
1007 case GST_PAD_MODE_PUSH:
1008 case GST_PAD_MODE_PULL:
1015 * gst_pad_set_active:
1016 * @pad: the #GstPad to activate or deactivate.
1017 * @active: whether or not the pad should be active.
1019 * Activates or deactivates the given pad.
1020 * Normally called from within core state change functions.
1022 * If @active, makes sure the pad is active. If it is already active, either in
1023 * push or pull mode, just return. Otherwise dispatches to the pad's activate
1024 * function to perform the actual activation.
1026 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
1027 * and a %FALSE argument.
1029 * Returns: %TRUE if the operation was successful.
1034 gst_pad_set_active (GstPad * pad, gboolean active)
1038 gboolean ret = FALSE;
1040 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1042 GST_OBJECT_LOCK (pad);
1043 old = GST_PAD_MODE (pad);
1044 ACQUIRE_PARENT (pad, parent, no_parent);
1045 GST_OBJECT_UNLOCK (pad);
1048 if (old == GST_PAD_MODE_NONE) {
1049 GST_DEBUG_OBJECT (pad, "activating pad from none");
1050 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1052 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1054 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1055 gst_pad_mode_get_name (old));
1059 if (old == GST_PAD_MODE_NONE) {
1060 GST_DEBUG_OBJECT (pad, "pad was inactive");
1063 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1064 gst_pad_mode_get_name (old));
1065 ret = gst_pad_activate_mode (pad, old, FALSE);
1067 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1071 RELEASE_PARENT (parent);
1073 if (G_UNLIKELY (!ret))
1081 GST_DEBUG_OBJECT (pad, "no parent");
1082 GST_OBJECT_UNLOCK (pad);
1087 GST_OBJECT_LOCK (pad);
1089 g_critical ("Failed to deactivate pad %s:%s, very bad",
1090 GST_DEBUG_PAD_NAME (pad));
1092 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1094 GST_OBJECT_UNLOCK (pad);
1100 * gst_pad_activate_mode:
1101 * @pad: the #GstPad to activate or deactivate.
1102 * @mode: the requested activation mode
1103 * @active: whether or not the pad should be active.
1105 * Activates or deactivates the given pad in @mode via dispatching to the
1106 * pad's activatemodefunc. For use from within pad activation functions only.
1108 * If you don't know what this is, you probably don't want to call it.
1110 * Returns: %TRUE if the operation was successful.
1115 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1117 gboolean res = FALSE;
1119 GstPadMode old, new;
1120 GstPadDirection dir;
1123 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1125 GST_OBJECT_LOCK (pad);
1126 old = GST_PAD_MODE (pad);
1127 dir = GST_PAD_DIRECTION (pad);
1128 ACQUIRE_PARENT (pad, parent, no_parent);
1129 GST_OBJECT_UNLOCK (pad);
1131 new = active ? mode : GST_PAD_MODE_NONE;
1136 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1137 /* pad was activate in the wrong direction, deactivate it
1138 * and reactivate it in the requested mode */
1139 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1140 gst_pad_mode_get_name (old));
1142 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1143 goto deactivate_failed;
1147 case GST_PAD_MODE_PULL:
1149 if (dir == GST_PAD_SINK) {
1150 if ((peer = gst_pad_get_peer (pad))) {
1151 GST_DEBUG_OBJECT (pad, "calling peer");
1152 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1154 gst_object_unref (peer);
1156 /* there is no peer, this is only fatal when we activate. When we
1157 * deactivate, we must assume the application has unlinked the peer and
1158 * will deactivate it eventually. */
1162 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1165 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1166 goto failure; /* Can't activate pull on a src without a
1167 getrange function */
1175 /* Mark pad as needing reconfiguration */
1177 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1178 pre_activate (pad, new);
1180 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1181 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1185 /* can happen for sinks of passthrough elements */
1188 post_activate (pad, new);
1190 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1191 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1196 /* Clear sticky flags on deactivation */
1198 GST_OBJECT_LOCK (pad);
1199 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1200 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1201 GST_OBJECT_UNLOCK (pad);
1205 RELEASE_PARENT (parent);
1211 GST_DEBUG_OBJECT (pad, "no parent");
1212 GST_OBJECT_UNLOCK (pad);
1217 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1218 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1223 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1224 "failed to %s in switch to %s mode from %s mode",
1225 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1226 gst_pad_mode_get_name (old));
1231 GST_OBJECT_LOCK (peer);
1232 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1233 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1234 GST_OBJECT_UNLOCK (peer);
1235 gst_object_unref (peer);
1240 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1241 "pad in pull mode");
1246 GST_OBJECT_LOCK (pad);
1247 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1248 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1249 GST_PAD_SET_FLUSHING (pad);
1250 GST_PAD_MODE (pad) = old;
1251 GST_OBJECT_UNLOCK (pad);
1257 * gst_pad_is_active:
1258 * @pad: the #GstPad to query
1260 * Query if a pad is active
1262 * Returns: %TRUE if the pad is active.
1267 gst_pad_is_active (GstPad * pad)
1269 gboolean result = FALSE;
1271 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1273 GST_OBJECT_LOCK (pad);
1274 result = GST_PAD_IS_ACTIVE (pad);
1275 GST_OBJECT_UNLOCK (pad);
1281 cleanup_hook (GstPad * pad, GHook * hook)
1283 GstPadProbeType type;
1285 if (!G_HOOK_IS_VALID (hook))
1288 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1290 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1291 /* unblock when we remove the last blocking probe */
1293 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1296 /* Might have new probes now that want to be called */
1297 GST_PAD_BLOCK_BROADCAST (pad);
1299 if (pad->num_blocked == 0) {
1300 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1301 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1304 g_hook_destroy_link (&pad->probes, hook);
1309 * gst_pad_add_probe:
1310 * @pad: the #GstPad to add the probe to
1311 * @mask: the probe mask
1312 * @callback: #GstPadProbeCallback that will be called with notifications of
1314 * @user_data: (closure): user data passed to the callback
1315 * @destroy_data: #GDestroyNotify for user_data
1317 * Be notified of different states of pads. The provided callback is called for
1318 * every state that matches @mask.
1320 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1321 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1322 * happen that the probe can be run immediately and if the probe returns
1323 * GST_PAD_PROBE_REMOVE this functions returns 0.
1328 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1329 GstPadProbeCallback callback, gpointer user_data,
1330 GDestroyNotify destroy_data)
1335 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1336 g_return_val_if_fail (mask != 0, 0);
1338 GST_OBJECT_LOCK (pad);
1340 /* make a new probe */
1341 hook = g_hook_alloc (&pad->probes);
1343 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1346 /* when no contraints are given for the types, assume all types are
1348 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1349 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1350 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1351 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1353 /* store our flags and other fields */
1354 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1355 hook->func = callback;
1356 hook->data = user_data;
1357 hook->destroy = destroy_data;
1358 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1361 g_hook_prepend (&pad->probes, hook);
1363 /* incremenent cookie so that the new hook get's called */
1364 pad->priv->probe_list_cookie++;
1366 /* get the id of the hook, we return this and it can be used to remove the
1368 res = hook->hook_id;
1370 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1372 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1373 /* we have a block probe */
1375 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1376 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1377 "now %d blocking probes", pad->num_blocked);
1379 /* Might have new probes now that want to be called */
1380 GST_PAD_BLOCK_BROADCAST (pad);
1383 /* call the callback if we need to be called for idle callbacks */
1384 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1385 if (pad->priv->using > 0) {
1386 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1387 * flag above, the last thread to leave the push will do the callback. New
1388 * threads going into the push will block. */
1389 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1390 "pad is in use, delay idle callback");
1391 GST_OBJECT_UNLOCK (pad);
1393 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1394 GstPadProbeReturn ret;
1396 /* Keep another ref, the callback could destroy the pad */
1397 gst_object_ref (pad);
1398 pad->priv->idle_running++;
1400 /* the pad is idle now, we can signal the idle callback now */
1401 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1402 "pad is idle, trigger idle callback");
1403 GST_OBJECT_UNLOCK (pad);
1405 ret = callback (pad, &info, user_data);
1407 GST_OBJECT_LOCK (pad);
1409 case GST_PAD_PROBE_REMOVE:
1410 /* remove the probe */
1411 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1412 cleanup_hook (pad, hook);
1415 case GST_PAD_PROBE_DROP:
1416 GST_DEBUG_OBJECT (pad, "asked to drop item");
1418 case GST_PAD_PROBE_PASS:
1419 GST_DEBUG_OBJECT (pad, "asked to pass item");
1421 case GST_PAD_PROBE_OK:
1422 GST_DEBUG_OBJECT (pad, "probe returned OK");
1424 case GST_PAD_PROBE_HANDLED:
1425 GST_DEBUG_OBJECT (pad, "probe handled the data");
1428 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1431 pad->priv->idle_running--;
1432 if (pad->priv->idle_running == 0) {
1433 GST_PAD_BLOCK_BROADCAST (pad);
1435 GST_OBJECT_UNLOCK (pad);
1437 gst_object_unref (pad);
1440 GST_OBJECT_UNLOCK (pad);
1446 * gst_pad_remove_probe:
1447 * @pad: the #GstPad with the probe
1448 * @id: the probe id to remove
1450 * Remove the probe with @id from @pad.
1455 gst_pad_remove_probe (GstPad * pad, gulong id)
1459 g_return_if_fail (GST_IS_PAD (pad));
1461 GST_OBJECT_LOCK (pad);
1463 hook = g_hook_get (&pad->probes, id);
1467 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1469 cleanup_hook (pad, hook);
1470 GST_OBJECT_UNLOCK (pad);
1476 GST_OBJECT_UNLOCK (pad);
1477 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1483 * gst_pad_is_blocked:
1484 * @pad: the #GstPad to query
1486 * Checks if the pad is blocked or not. This function returns the
1487 * last requested state of the pad. It is not certain that the pad
1488 * is actually blocking at this point (see gst_pad_is_blocking()).
1490 * Returns: %TRUE if the pad is blocked.
1495 gst_pad_is_blocked (GstPad * pad)
1497 gboolean result = FALSE;
1499 g_return_val_if_fail (GST_IS_PAD (pad), result);
1501 GST_OBJECT_LOCK (pad);
1502 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1503 GST_OBJECT_UNLOCK (pad);
1509 * gst_pad_is_blocking:
1510 * @pad: the #GstPad to query
1512 * Checks if the pad is blocking or not. This is a guaranteed state
1513 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1515 * Returns: %TRUE if the pad is blocking.
1520 gst_pad_is_blocking (GstPad * pad)
1522 gboolean result = FALSE;
1524 g_return_val_if_fail (GST_IS_PAD (pad), result);
1526 GST_OBJECT_LOCK (pad);
1527 /* the blocking flag is only valid if the pad is not flushing */
1528 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1529 GST_OBJECT_UNLOCK (pad);
1535 * gst_pad_needs_reconfigure:
1536 * @pad: the #GstPad to check
1538 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1539 * if the flag was set.
1541 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1544 gst_pad_needs_reconfigure (GstPad * pad)
1546 gboolean reconfigure;
1548 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1550 GST_OBJECT_LOCK (pad);
1551 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1552 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1553 GST_OBJECT_UNLOCK (pad);
1559 * gst_pad_check_reconfigure:
1560 * @pad: the #GstPad to check
1562 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1563 * if the flag was set.
1565 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1568 gst_pad_check_reconfigure (GstPad * pad)
1570 gboolean reconfigure;
1572 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1574 GST_OBJECT_LOCK (pad);
1575 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1577 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1578 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1580 GST_OBJECT_UNLOCK (pad);
1586 * gst_pad_mark_reconfigure:
1587 * @pad: the #GstPad to mark
1589 * Mark a pad for needing reconfiguration. The next call to
1590 * gst_pad_check_reconfigure() will return %TRUE after this call.
1593 gst_pad_mark_reconfigure (GstPad * pad)
1595 g_return_if_fail (GST_IS_PAD (pad));
1597 GST_OBJECT_LOCK (pad);
1598 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1599 GST_OBJECT_UNLOCK (pad);
1603 * gst_pad_set_activate_function:
1605 * @f: the #GstPadActivateFunction to set.
1607 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1611 * gst_pad_set_activate_function_full:
1613 * @activate: the #GstPadActivateFunction to set.
1614 * @user_data: user_data passed to @notify
1615 * @notify: notify called when @activate will not be used anymore.
1617 * Sets the given activate function for @pad. The activate function will
1618 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1619 * Only makes sense to set on sink pads.
1621 * Call this function if your sink pad can start a pull-based task.
1624 gst_pad_set_activate_function_full (GstPad * pad,
1625 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1627 g_return_if_fail (GST_IS_PAD (pad));
1629 if (pad->activatenotify)
1630 pad->activatenotify (pad->activatedata);
1631 GST_PAD_ACTIVATEFUNC (pad) = activate;
1632 pad->activatedata = user_data;
1633 pad->activatenotify = notify;
1635 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1636 GST_DEBUG_FUNCPTR_NAME (activate));
1640 * gst_pad_set_activatemode_function:
1642 * @f: the #GstPadActivateModeFunction to set.
1644 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1648 * gst_pad_set_activatemode_function_full:
1650 * @activatemode: the #GstPadActivateModeFunction to set.
1651 * @user_data: user_data passed to @notify
1652 * @notify: notify called when @activatemode will not be used anymore.
1654 * Sets the given activate_mode function for the pad. An activate_mode function
1655 * prepares the element for data passing.
1658 gst_pad_set_activatemode_function_full (GstPad * pad,
1659 GstPadActivateModeFunction activatemode, gpointer user_data,
1660 GDestroyNotify notify)
1662 g_return_if_fail (GST_IS_PAD (pad));
1664 if (pad->activatemodenotify)
1665 pad->activatemodenotify (pad->activatemodedata);
1666 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1667 pad->activatemodedata = user_data;
1668 pad->activatemodenotify = notify;
1670 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1671 GST_DEBUG_FUNCPTR_NAME (activatemode));
1675 * gst_pad_set_chain_function:
1676 * @p: a sink #GstPad.
1677 * @f: the #GstPadChainFunction to set.
1679 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1683 * gst_pad_set_chain_function_full:
1684 * @pad: a sink #GstPad.
1685 * @chain: the #GstPadChainFunction to set.
1686 * @user_data: user_data passed to @notify
1687 * @notify: notify called when @chain will not be used anymore.
1689 * Sets the given chain function for the pad. The chain function is called to
1690 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1693 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1694 gpointer user_data, GDestroyNotify notify)
1696 g_return_if_fail (GST_IS_PAD (pad));
1697 g_return_if_fail (GST_PAD_IS_SINK (pad));
1699 if (pad->chainnotify)
1700 pad->chainnotify (pad->chaindata);
1701 GST_PAD_CHAINFUNC (pad) = chain;
1702 pad->chaindata = user_data;
1703 pad->chainnotify = notify;
1705 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1706 GST_DEBUG_FUNCPTR_NAME (chain));
1710 * gst_pad_set_chain_list_function:
1711 * @p: a sink #GstPad.
1712 * @f: the #GstPadChainListFunction to set.
1714 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1718 * gst_pad_set_chain_list_function_full:
1719 * @pad: a sink #GstPad.
1720 * @chainlist: the #GstPadChainListFunction to set.
1721 * @user_data: user_data passed to @notify
1722 * @notify: notify called when @chainlist will not be used anymore.
1724 * Sets the given chain list function for the pad. The chainlist function is
1725 * called to process a #GstBufferList input buffer list. See
1726 * #GstPadChainListFunction for more details.
1729 gst_pad_set_chain_list_function_full (GstPad * pad,
1730 GstPadChainListFunction chainlist, gpointer user_data,
1731 GDestroyNotify notify)
1733 g_return_if_fail (GST_IS_PAD (pad));
1734 g_return_if_fail (GST_PAD_IS_SINK (pad));
1736 if (pad->chainlistnotify)
1737 pad->chainlistnotify (pad->chainlistdata);
1738 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1739 pad->chainlistdata = user_data;
1740 pad->chainlistnotify = notify;
1742 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1743 GST_DEBUG_FUNCPTR_NAME (chainlist));
1747 * gst_pad_set_getrange_function:
1748 * @p: a source #GstPad.
1749 * @f: the #GstPadGetRangeFunction to set.
1751 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1755 * gst_pad_set_getrange_function_full:
1756 * @pad: a source #GstPad.
1757 * @get: the #GstPadGetRangeFunction to set.
1758 * @user_data: user_data passed to @notify
1759 * @notify: notify called when @get will not be used anymore.
1761 * Sets the given getrange function for the pad. The getrange function is
1762 * called to produce a new #GstBuffer to start the processing pipeline. see
1763 * #GstPadGetRangeFunction for a description of the getrange function.
1766 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1767 gpointer user_data, GDestroyNotify notify)
1769 g_return_if_fail (GST_IS_PAD (pad));
1770 g_return_if_fail (GST_PAD_IS_SRC (pad));
1772 if (pad->getrangenotify)
1773 pad->getrangenotify (pad->getrangedata);
1774 GST_PAD_GETRANGEFUNC (pad) = get;
1775 pad->getrangedata = user_data;
1776 pad->getrangenotify = notify;
1778 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1779 GST_DEBUG_FUNCPTR_NAME (get));
1783 * gst_pad_set_event_function:
1784 * @p: a #GstPad of either direction.
1785 * @f: the #GstPadEventFunction to set.
1787 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1791 * gst_pad_set_event_function_full:
1792 * @pad: a #GstPad of either direction.
1793 * @event: the #GstPadEventFunction to set.
1794 * @user_data: user_data passed to @notify
1795 * @notify: notify called when @event will not be used anymore.
1797 * Sets the given event handler for the pad.
1800 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1801 gpointer user_data, GDestroyNotify notify)
1803 g_return_if_fail (GST_IS_PAD (pad));
1805 if (pad->eventnotify)
1806 pad->eventnotify (pad->eventdata);
1807 GST_PAD_EVENTFUNC (pad) = event;
1808 pad->eventdata = user_data;
1809 pad->eventnotify = notify;
1811 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1812 GST_DEBUG_FUNCPTR_NAME (event));
1816 * gst_pad_set_query_function:
1817 * @p: a #GstPad of either direction.
1818 * @f: the #GstPadQueryFunction to set.
1820 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1824 * gst_pad_set_query_function_full:
1825 * @pad: a #GstPad of either direction.
1826 * @query: the #GstPadQueryFunction to set.
1827 * @user_data: user_data passed to @notify
1828 * @notify: notify called when @query will not be used anymore.
1830 * Set the given query function for the pad.
1833 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1834 gpointer user_data, GDestroyNotify notify)
1836 g_return_if_fail (GST_IS_PAD (pad));
1838 if (pad->querynotify)
1839 pad->querynotify (pad->querydata);
1840 GST_PAD_QUERYFUNC (pad) = query;
1841 pad->querydata = user_data;
1842 pad->querynotify = notify;
1844 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1845 GST_DEBUG_FUNCPTR_NAME (query));
1849 * gst_pad_set_iterate_internal_links_function:
1850 * @p: a #GstPad of either direction.
1851 * @f: the #GstPadIterIntLinkFunction to set.
1853 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1854 * for the user_data and notify.
1857 * gst_pad_set_iterate_internal_links_function_full:
1858 * @pad: a #GstPad of either direction.
1859 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1860 * @user_data: user_data passed to @notify
1861 * @notify: notify called when @iterintlink will not be used anymore.
1863 * Sets the given internal link iterator function for the pad.
1866 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1867 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1868 GDestroyNotify notify)
1870 g_return_if_fail (GST_IS_PAD (pad));
1872 if (pad->iterintlinknotify)
1873 pad->iterintlinknotify (pad->iterintlinkdata);
1874 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1875 pad->iterintlinkdata = user_data;
1876 pad->iterintlinknotify = notify;
1878 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1879 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1883 * gst_pad_set_link_function:
1885 * @f: the #GstPadLinkFunction to set.
1887 * Calls gst_pad_set_link_function_full() with %NULL
1888 * for the user_data and notify.
1891 * gst_pad_set_link_function_full:
1893 * @link: the #GstPadLinkFunction to set.
1894 * @user_data: user_data passed to @notify
1895 * @notify: notify called when @link will not be used anymore.
1897 * Sets the given link function for the pad. It will be called when
1898 * the pad is linked with another pad.
1900 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1903 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1904 * cannot be made for some reason.
1906 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1907 * of the peer sink pad, if present.
1910 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1911 gpointer user_data, GDestroyNotify notify)
1913 g_return_if_fail (GST_IS_PAD (pad));
1915 if (pad->linknotify)
1916 pad->linknotify (pad->linkdata);
1917 GST_PAD_LINKFUNC (pad) = link;
1918 pad->linkdata = user_data;
1919 pad->linknotify = notify;
1921 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1922 GST_DEBUG_FUNCPTR_NAME (link));
1926 * gst_pad_set_unlink_function:
1928 * @f: the #GstPadUnlinkFunction to set.
1930 * Calls gst_pad_set_unlink_function_full() with %NULL
1931 * for the user_data and notify.
1934 * gst_pad_set_unlink_function_full:
1936 * @unlink: the #GstPadUnlinkFunction to set.
1937 * @user_data: user_data passed to @notify
1938 * @notify: notify called when @unlink will not be used anymore.
1940 * Sets the given unlink function for the pad. It will be called
1941 * when the pad is unlinked.
1944 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1945 gpointer user_data, GDestroyNotify notify)
1947 g_return_if_fail (GST_IS_PAD (pad));
1949 if (pad->unlinknotify)
1950 pad->unlinknotify (pad->unlinkdata);
1951 GST_PAD_UNLINKFUNC (pad) = unlink;
1952 pad->unlinkdata = user_data;
1953 pad->unlinknotify = notify;
1955 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1956 GST_DEBUG_FUNCPTR_NAME (unlink));
1961 * @srcpad: the source #GstPad to unlink.
1962 * @sinkpad: the sink #GstPad to unlink.
1964 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1965 * signal on both pads.
1967 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
1968 * the pads were not linked together.
1973 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1975 gboolean result = FALSE;
1976 GstElement *parent = NULL;
1978 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1979 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1980 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1981 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1983 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1984 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1985 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1987 /* We need to notify the parent before taking any pad locks as the bin in
1988 * question might be waiting for a lock on the pad while holding its lock
1989 * that our message will try to take. */
1990 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1991 if (GST_IS_ELEMENT (parent)) {
1992 gst_element_post_message (parent,
1993 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1994 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1996 gst_object_unref (parent);
2001 GST_OBJECT_LOCK (srcpad);
2002 GST_OBJECT_LOCK (sinkpad);
2004 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
2005 goto not_linked_together;
2007 if (GST_PAD_UNLINKFUNC (srcpad)) {
2008 GstObject *tmpparent;
2010 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
2012 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
2013 RELEASE_PARENT (tmpparent);
2016 if (GST_PAD_UNLINKFUNC (sinkpad)) {
2017 GstObject *tmpparent;
2019 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
2021 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
2022 RELEASE_PARENT (tmpparent);
2026 /* first clear peers */
2027 GST_PAD_PEER (srcpad) = NULL;
2028 GST_PAD_PEER (sinkpad) = NULL;
2030 GST_OBJECT_UNLOCK (sinkpad);
2031 GST_OBJECT_UNLOCK (srcpad);
2033 /* fire off a signal to each of the pads telling them
2034 * that they've been unlinked */
2035 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
2036 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
2038 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
2039 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2044 if (parent != NULL) {
2045 gst_element_post_message (parent,
2046 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2047 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
2048 gst_object_unref (parent);
2053 not_linked_together:
2055 /* we do not emit a warning in this case because unlinking cannot
2056 * be made MT safe.*/
2057 GST_OBJECT_UNLOCK (sinkpad);
2058 GST_OBJECT_UNLOCK (srcpad);
2064 * gst_pad_is_linked:
2065 * @pad: pad to check
2067 * Checks if a @pad is linked to another pad or not.
2069 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2074 gst_pad_is_linked (GstPad * pad)
2078 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2080 GST_OBJECT_LOCK (pad);
2081 result = (GST_PAD_PEER (pad) != NULL);
2082 GST_OBJECT_UNLOCK (pad);
2087 /* get the caps from both pads and see if the intersection
2090 * This function should be called with the pad LOCK on both
2094 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2095 GstPadLinkCheck flags)
2097 GstCaps *srccaps = NULL;
2098 GstCaps *sinkcaps = NULL;
2099 gboolean compatible = FALSE;
2101 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2104 /* Doing the expensive caps checking takes priority over only checking the template caps */
2105 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2106 GST_OBJECT_UNLOCK (sink);
2107 GST_OBJECT_UNLOCK (src);
2109 srccaps = gst_pad_query_caps (src, NULL);
2110 sinkcaps = gst_pad_query_caps (sink, NULL);
2112 GST_OBJECT_LOCK (src);
2113 GST_OBJECT_LOCK (sink);
2115 /* If one of the two pads doesn't have a template, consider the intersection
2117 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2118 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2122 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2124 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2127 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2129 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2132 /* if we have caps on both pads we can check the intersection. If one
2133 * of the caps is %NULL, we return %TRUE. */
2134 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2136 gst_caps_unref (srccaps);
2138 gst_caps_unref (sinkcaps);
2142 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2143 gst_caps_unref (srccaps);
2144 gst_caps_unref (sinkcaps);
2147 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2148 (compatible ? "" : "not "));
2153 /* check if the grandparents of both pads are the same.
2154 * This check is required so that we don't try to link
2155 * pads from elements in different bins without ghostpads.
2157 * The LOCK should be held on both pads
2160 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2162 GstObject *psrc, *psink;
2164 psrc = GST_OBJECT_PARENT (src);
2165 psink = GST_OBJECT_PARENT (sink);
2167 /* if one of the pads has no parent, we allow the link */
2168 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2171 /* only care about parents that are elements */
2172 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2173 goto no_element_parent;
2175 /* if the parents are the same, we have a loop */
2176 if (G_UNLIKELY (psrc == psink))
2179 /* if they both have a parent, we check the grandparents. We can not lock
2180 * the parent because we hold on the child (pad) and the locking order is
2181 * parent >> child. */
2182 psrc = GST_OBJECT_PARENT (psrc);
2183 psink = GST_OBJECT_PARENT (psink);
2185 /* if they have grandparents but they are not the same */
2186 if (G_UNLIKELY (psrc != psink))
2187 goto wrong_grandparents;
2194 GST_CAT_DEBUG (GST_CAT_CAPS,
2195 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2196 GST_PTR_FORMAT, psrc, psink);
2201 GST_CAT_DEBUG (GST_CAT_CAPS,
2202 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2203 GST_PTR_FORMAT, psrc, psink);
2208 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2214 GST_CAT_DEBUG (GST_CAT_CAPS,
2215 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2216 GST_PTR_FORMAT, psrc, psink);
2221 /* FIXME leftover from an attempt at refactoring... */
2222 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2223 * the two pads will be locked in the srcpad, sinkpad order. */
2224 static GstPadLinkReturn
2225 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2227 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2228 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2230 GST_OBJECT_LOCK (srcpad);
2232 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2233 goto src_was_linked;
2235 GST_OBJECT_LOCK (sinkpad);
2237 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2238 goto sink_was_linked;
2240 /* check hierarchy, pads can only be linked if the grandparents
2242 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2243 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2244 goto wrong_hierarchy;
2246 /* check pad caps for non-empty intersection */
2247 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2250 /* FIXME check pad scheduling for non-empty intersection */
2252 return GST_PAD_LINK_OK;
2256 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2257 GST_DEBUG_PAD_NAME (srcpad),
2258 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2259 /* we do not emit a warning in this case because unlinking cannot
2260 * be made MT safe.*/
2261 GST_OBJECT_UNLOCK (srcpad);
2262 return GST_PAD_LINK_WAS_LINKED;
2266 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2267 GST_DEBUG_PAD_NAME (sinkpad),
2268 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2269 /* we do not emit a warning in this case because unlinking cannot
2270 * be made MT safe.*/
2271 GST_OBJECT_UNLOCK (sinkpad);
2272 GST_OBJECT_UNLOCK (srcpad);
2273 return GST_PAD_LINK_WAS_LINKED;
2277 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2278 GST_OBJECT_UNLOCK (sinkpad);
2279 GST_OBJECT_UNLOCK (srcpad);
2280 return GST_PAD_LINK_WRONG_HIERARCHY;
2284 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2285 GST_OBJECT_UNLOCK (sinkpad);
2286 GST_OBJECT_UNLOCK (srcpad);
2287 return GST_PAD_LINK_NOFORMAT;
2293 * @srcpad: the source #GstPad.
2294 * @sinkpad: the sink #GstPad.
2296 * Checks if the source pad and the sink pad are compatible so they can be
2299 * Returns: %TRUE if the pads can be linked.
2302 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2304 GstPadLinkReturn result;
2306 /* generic checks */
2307 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2308 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2310 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2311 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2313 /* gst_pad_link_prepare does everything for us, we only release the locks
2314 * on the pads that it gets us. If this function returns !OK the locks are not
2316 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2317 if (result != GST_PAD_LINK_OK)
2320 GST_OBJECT_UNLOCK (srcpad);
2321 GST_OBJECT_UNLOCK (sinkpad);
2324 return result == GST_PAD_LINK_OK;
2328 * gst_pad_link_full:
2329 * @srcpad: the source #GstPad to link.
2330 * @sinkpad: the sink #GstPad to link.
2331 * @flags: the checks to validate when linking
2333 * Links the source pad and the sink pad.
2335 * This variant of #gst_pad_link provides a more granular control on the
2336 * checks being done when linking. While providing some considerable speedups
2337 * the caller of this method must be aware that wrong usage of those flags
2338 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2339 * for more information.
2343 * Returns: A result code indicating if the connection worked or
2347 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2349 GstPadLinkReturn result;
2351 GstPadLinkFunction srcfunc, sinkfunc;
2353 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2354 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2355 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2356 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2357 GST_PAD_LINK_WRONG_DIRECTION);
2359 /* Notify the parent early. See gst_pad_unlink for details. */
2360 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2361 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2362 gst_element_post_message (parent,
2363 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2364 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2366 gst_object_unref (parent);
2371 /* prepare will also lock the two pads */
2372 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2374 if (G_UNLIKELY (result != GST_PAD_LINK_OK)) {
2375 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2376 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2377 gst_pad_link_get_name (result));
2381 /* must set peers before calling the link function */
2382 GST_PAD_PEER (srcpad) = sinkpad;
2383 GST_PAD_PEER (sinkpad) = srcpad;
2385 /* check events, when something is different, mark pending */
2386 schedule_events (srcpad, sinkpad);
2388 /* get the link functions */
2389 srcfunc = GST_PAD_LINKFUNC (srcpad);
2390 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2392 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2393 /* custom link functions, execute them */
2394 GST_OBJECT_UNLOCK (sinkpad);
2395 GST_OBJECT_UNLOCK (srcpad);
2398 GstObject *tmpparent;
2400 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2401 /* this one will call the peer link function */
2402 result = srcfunc (srcpad, tmpparent, sinkpad);
2403 RELEASE_PARENT (tmpparent);
2404 } else if (sinkfunc) {
2405 GstObject *tmpparent;
2407 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2408 /* if no source link function, we need to call the sink link
2409 * function ourselves. */
2410 result = sinkfunc (sinkpad, tmpparent, srcpad);
2411 RELEASE_PARENT (tmpparent);
2415 GST_OBJECT_LOCK (srcpad);
2416 GST_OBJECT_LOCK (sinkpad);
2418 /* we released the lock, check if the same pads are linked still */
2419 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2420 goto concurrent_link;
2422 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2425 GST_OBJECT_UNLOCK (sinkpad);
2426 GST_OBJECT_UNLOCK (srcpad);
2428 /* fire off a signal to each of the pads telling them
2429 * that they've been linked */
2430 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2431 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2433 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2434 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2436 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2439 if (G_LIKELY (parent)) {
2440 gst_element_post_message (parent,
2441 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2442 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2443 gst_object_unref (parent);
2451 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2452 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2453 GST_OBJECT_UNLOCK (sinkpad);
2454 GST_OBJECT_UNLOCK (srcpad);
2456 /* The other link operation succeeded first */
2457 result = GST_PAD_LINK_WAS_LINKED;
2462 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2463 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2464 gst_pad_link_get_name (result));
2466 GST_PAD_PEER (srcpad) = NULL;
2467 GST_PAD_PEER (sinkpad) = NULL;
2469 GST_OBJECT_UNLOCK (sinkpad);
2470 GST_OBJECT_UNLOCK (srcpad);
2478 * @srcpad: the source #GstPad to link.
2479 * @sinkpad: the sink #GstPad to link.
2481 * Links the source pad and the sink pad.
2483 * Returns: A result code indicating if the connection worked or
2489 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2491 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2495 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2497 GstPadTemplate **template_p;
2499 /* this function would need checks if it weren't static */
2501 GST_OBJECT_LOCK (pad);
2502 template_p = &pad->padtemplate;
2503 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2504 GST_OBJECT_UNLOCK (pad);
2507 gst_pad_template_pad_created (templ, pad);
2511 * gst_pad_get_pad_template:
2514 * Gets the template for @pad.
2516 * Returns: (transfer full) (nullable): the #GstPadTemplate from which
2517 * this pad was instantiated, or %NULL if this pad has no
2518 * template. Unref after usage.
2521 gst_pad_get_pad_template (GstPad * pad)
2523 GstPadTemplate *templ;
2525 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2527 templ = GST_PAD_PAD_TEMPLATE (pad);
2529 return (templ ? gst_object_ref (templ) : NULL);
2533 * gst_pad_has_current_caps:
2534 * @pad: a #GstPad to check
2536 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2538 * Returns: %TRUE when @pad has caps associated with it.
2541 gst_pad_has_current_caps (GstPad * pad)
2546 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2548 GST_OBJECT_LOCK (pad);
2549 caps = get_pad_caps (pad);
2550 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2551 "check current pad caps %" GST_PTR_FORMAT, caps);
2552 result = (caps != NULL);
2553 GST_OBJECT_UNLOCK (pad);
2559 * gst_pad_get_current_caps:
2560 * @pad: a #GstPad to get the current capabilities of.
2562 * Gets the capabilities currently configured on @pad with the last
2563 * #GST_EVENT_CAPS event.
2565 * Returns: the current caps of the pad with incremented ref-count.
2568 gst_pad_get_current_caps (GstPad * pad)
2572 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2574 GST_OBJECT_LOCK (pad);
2575 if ((result = get_pad_caps (pad)))
2576 gst_caps_ref (result);
2577 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2578 "get current pad caps %" GST_PTR_FORMAT, result);
2579 GST_OBJECT_UNLOCK (pad);
2585 * gst_pad_get_pad_template_caps:
2586 * @pad: a #GstPad to get the template capabilities from.
2588 * Gets the capabilities for @pad's template.
2590 * Returns: (transfer full): the #GstCaps of this pad template.
2591 * Unref after usage.
2594 gst_pad_get_pad_template_caps (GstPad * pad)
2596 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2598 if (GST_PAD_PAD_TEMPLATE (pad))
2599 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2601 return gst_caps_ref (GST_CAPS_ANY);
2606 * @pad: a #GstPad to get the peer of.
2608 * Gets the peer of @pad. This function refs the peer pad so
2609 * you need to unref it after use.
2611 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2616 gst_pad_get_peer (GstPad * pad)
2620 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2622 GST_OBJECT_LOCK (pad);
2623 result = GST_PAD_PEER (pad);
2625 gst_object_ref (result);
2626 GST_OBJECT_UNLOCK (pad);
2632 * gst_pad_get_allowed_caps:
2635 * Gets the capabilities of the allowed media types that can flow through
2636 * @pad and its peer.
2638 * The allowed capabilities is calculated as the intersection of the results of
2639 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2640 * on the resulting caps.
2642 * Returns: (transfer full) (nullable): the allowed #GstCaps of the
2643 * pad link. Unref the caps when you no longer need it. This
2644 * function returns %NULL when @pad has no peer.
2649 gst_pad_get_allowed_caps (GstPad * pad)
2652 GstCaps *caps = NULL;
2655 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2657 GST_OBJECT_LOCK (pad);
2658 if (G_UNLIKELY (GST_PAD_PEER (pad) == NULL))
2660 GST_OBJECT_UNLOCK (pad);
2662 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2664 mycaps = gst_pad_query_caps (pad, NULL);
2666 /* Query peer caps */
2667 query = gst_query_new_caps (mycaps);
2668 gst_pad_peer_query (pad, query);
2669 gst_query_parse_caps_result (query, &caps);
2670 gst_caps_ref (caps);
2671 gst_query_unref (query);
2673 gst_caps_unref (mycaps);
2675 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2682 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2683 GST_OBJECT_UNLOCK (pad);
2690 * gst_pad_iterate_internal_links_default:
2691 * @pad: the #GstPad to get the internal links of.
2692 * @parent: (allow-none): the parent of @pad or %NULL
2694 * Iterate the list of pads to which the given pad is linked to inside of
2695 * the parent element.
2696 * This is the default handler, and thus returns an iterator of all of the
2697 * pads inside the parent element with opposite direction.
2699 * The caller must free this iterator after use with gst_iterator_free().
2701 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
2702 * has no parent. Unref each returned pad with gst_object_unref().
2705 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2712 GstElement *eparent;
2714 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2716 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2717 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2719 GST_OBJECT_LOCK (pad);
2720 eparent = GST_PAD_PARENT (pad);
2721 if (!eparent || !GST_IS_ELEMENT (eparent))
2724 gst_object_ref (eparent);
2725 GST_OBJECT_UNLOCK (pad);
2728 if (pad->direction == GST_PAD_SRC)
2729 padlist = &eparent->sinkpads;
2731 padlist = &eparent->srcpads;
2733 GST_DEBUG_OBJECT (pad, "Making iterator");
2735 cookie = &eparent->pads_cookie;
2737 lock = GST_OBJECT_GET_LOCK (eparent);
2739 res = gst_iterator_new_list (GST_TYPE_PAD,
2740 lock, cookie, padlist, (GObject *) owner, NULL);
2742 gst_object_unref (owner);
2749 GST_OBJECT_UNLOCK (pad);
2750 GST_DEBUG_OBJECT (pad, "no parent element");
2756 * gst_pad_iterate_internal_links:
2757 * @pad: the GstPad to get the internal links of.
2759 * Gets an iterator for the pads to which the given pad is linked to inside
2760 * of the parent element.
2762 * Each #GstPad element yielded by the iterator will have its refcount increased,
2763 * so unref after use.
2765 * Free-function: gst_iterator_free
2767 * Returns: (transfer full) (nullable): a new #GstIterator of #GstPad
2768 * or %NULL when the pad does not have an iterator function
2769 * configured. Use gst_iterator_free() after usage.
2772 gst_pad_iterate_internal_links (GstPad * pad)
2774 GstIterator *res = NULL;
2777 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2779 GST_OBJECT_LOCK (pad);
2780 ACQUIRE_PARENT (pad, parent, no_parent);
2781 GST_OBJECT_UNLOCK (pad);
2783 if (GST_PAD_ITERINTLINKFUNC (pad))
2784 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2786 RELEASE_PARENT (parent);
2793 GST_DEBUG_OBJECT (pad, "no parent");
2794 GST_OBJECT_UNLOCK (pad);
2802 * @forward: (scope call): a #GstPadForwardFunction
2803 * @user_data: user data passed to @forward
2805 * Calls @forward for all internally linked pads of @pad. This function deals with
2806 * dynamically changing internal pads and will make sure that the @forward
2807 * function is only called once for each pad.
2809 * When @forward returns %TRUE, no further pads will be processed.
2811 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2814 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2817 gboolean result = FALSE;
2819 gboolean done = FALSE;
2820 GValue item = { 0, };
2821 GList *pushed_pads = NULL;
2823 iter = gst_pad_iterate_internal_links (pad);
2829 switch (gst_iterator_next (iter, &item)) {
2830 case GST_ITERATOR_OK:
2834 intpad = g_value_get_object (&item);
2836 /* if already pushed, skip. FIXME, find something faster to tag pads */
2837 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2838 g_value_reset (&item);
2842 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2843 GST_DEBUG_PAD_NAME (intpad));
2844 done = result = forward (intpad, user_data);
2846 pushed_pads = g_list_prepend (pushed_pads, intpad);
2848 g_value_reset (&item);
2851 case GST_ITERATOR_RESYNC:
2852 /* We don't reset the result here because we don't push the event
2853 * again on pads that got the event already and because we need
2854 * to consider the result of the previous pushes */
2855 gst_iterator_resync (iter);
2857 case GST_ITERATOR_ERROR:
2858 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2861 case GST_ITERATOR_DONE:
2866 g_value_unset (&item);
2867 gst_iterator_free (iter);
2869 g_list_free (pushed_pads);
2879 gboolean dispatched;
2883 event_forward_func (GstPad * pad, EventData * data)
2885 /* for each pad we send to, we should ref the event; it's up
2886 * to downstream to unref again when handled. */
2887 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2888 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2890 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2892 data->dispatched = TRUE;
2899 * gst_pad_event_default:
2900 * @pad: a #GstPad to call the default event handler on.
2901 * @parent: (allow-none): the parent of @pad or %NULL
2902 * @event: (transfer full): the #GstEvent to handle.
2904 * Invokes the default event handler for the given pad.
2906 * The EOS event will pause the task associated with @pad before it is forwarded
2907 * to all internally linked pads,
2909 * The event is sent to all pads internally linked to @pad. This function
2910 * takes ownership of @event.
2912 * Returns: %TRUE if the event was sent successfully.
2915 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2917 gboolean result, forward = TRUE;
2919 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2920 g_return_val_if_fail (event != NULL, FALSE);
2922 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2925 switch (GST_EVENT_TYPE (event)) {
2926 case GST_EVENT_CAPS:
2927 forward = GST_PAD_IS_PROXY_CAPS (pad);
2938 data.dispatched = FALSE;
2939 data.result = FALSE;
2941 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2943 /* for sinkpads without a parent element or without internal links, nothing
2944 * will be dispatched but we still want to return TRUE. */
2945 if (data.dispatched)
2946 result = data.result;
2951 gst_event_unref (event);
2956 /* Default accept caps implementation just checks against
2957 * the allowed caps for the pad */
2959 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2961 /* get the caps and see if it intersects to something not empty */
2962 GstCaps *caps, *allowed;
2965 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2967 /* first forward the query to internally linked pads when we are dealing with
2969 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2970 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2975 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2976 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2978 gst_query_parse_accept_caps (query, &caps);
2979 if (GST_PAD_IS_ACCEPT_TEMPLATE (pad))
2980 allowed = gst_pad_get_pad_template_caps (pad);
2982 allowed = gst_pad_query_caps (pad, caps);
2985 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
2986 GST_DEBUG_OBJECT (pad,
2987 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
2989 result = gst_caps_can_intersect (caps, allowed);
2991 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
2992 GST_PTR_FORMAT, allowed, caps);
2993 result = gst_caps_is_subset (caps, allowed);
2995 gst_caps_unref (allowed);
2997 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
3000 gst_query_set_accept_caps_result (query, result);
3006 /* Default caps implementation */
3008 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
3010 GstCaps *result = NULL, *filter;
3011 GstPadTemplate *templ;
3012 gboolean fixed_caps;
3014 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
3017 /* first try to proxy if we must */
3018 if (GST_PAD_IS_PROXY_CAPS (pad)) {
3019 if ((gst_pad_proxy_query_caps (pad, query))) {
3024 gst_query_parse_caps (query, &filter);
3026 /* no proxy or it failed, do default handling */
3027 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
3029 GST_OBJECT_LOCK (pad);
3031 /* fixed caps, try the negotiated caps first */
3032 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
3033 if ((result = get_pad_caps (pad)))
3034 goto filter_done_unlock;
3037 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
3038 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
3039 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
3040 goto filter_done_unlock;
3044 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3045 "non-fixed pad caps: trying pad caps");
3046 /* non fixed caps, try the negotiated caps */
3047 if ((result = get_pad_caps (pad)))
3048 goto filter_done_unlock;
3051 /* this almost never happens */
3052 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
3053 result = GST_CAPS_ANY;
3056 GST_OBJECT_UNLOCK (pad);
3058 /* run the filter on the result */
3060 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3061 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3062 GST_PTR_FORMAT, result, result, filter, filter);
3063 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3064 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3067 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3068 "using caps %p %" GST_PTR_FORMAT, result, result);
3069 result = gst_caps_ref (result);
3071 gst_query_set_caps_result (query, result);
3072 gst_caps_unref (result);
3078 /* Default latency implementation */
3082 GstClockTime min, max;
3086 query_latency_default_fold (const GValue * item, GValue * ret,
3089 GstPad *pad = g_value_get_object (item), *peer;
3090 LatencyFoldData *fold_data = user_data;
3092 gboolean res = FALSE;
3094 query = gst_query_new_latency ();
3096 peer = gst_pad_get_peer (pad);
3098 res = gst_pad_peer_query (pad, query);
3100 GST_LOG_OBJECT (pad, "No peer pad found, ignoring this pad");
3105 GstClockTime min, max;
3107 gst_query_parse_latency (query, &live, &min, &max);
3109 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3110 " max:%" G_GINT64_FORMAT, live ? "true" : "false", min, max);
3113 if (min > fold_data->min)
3114 fold_data->min = min;
3116 if (fold_data->max == GST_CLOCK_TIME_NONE)
3117 fold_data->max = max;
3118 else if (max < fold_data->max)
3119 fold_data->max = max;
3121 fold_data->live = TRUE;
3124 GST_DEBUG_OBJECT (pad, "latency query failed");
3125 g_value_set_boolean (ret, FALSE);
3128 gst_query_unref (query);
3130 gst_object_unref (peer);
3136 gst_pad_query_latency_default (GstPad * pad, GstQuery * query)
3139 GstIteratorResult res;
3140 GValue ret = G_VALUE_INIT;
3142 LatencyFoldData fold_data;
3144 it = gst_pad_iterate_internal_links (pad);
3146 GST_DEBUG_OBJECT (pad, "Can't iterate internal links");
3150 g_value_init (&ret, G_TYPE_BOOLEAN);
3153 fold_data.live = FALSE;
3155 fold_data.max = GST_CLOCK_TIME_NONE;
3157 g_value_set_boolean (&ret, TRUE);
3158 res = gst_iterator_fold (it, query_latency_default_fold, &ret, &fold_data);
3160 case GST_ITERATOR_OK:
3161 g_assert_not_reached ();
3163 case GST_ITERATOR_DONE:
3165 case GST_ITERATOR_ERROR:
3166 g_value_set_boolean (&ret, FALSE);
3168 case GST_ITERATOR_RESYNC:
3169 gst_iterator_resync (it);
3172 g_assert_not_reached ();
3175 gst_iterator_free (it);
3177 query_ret = g_value_get_boolean (&ret);
3179 GST_LOG_OBJECT (pad, "got latency live:%s min:%" G_GINT64_FORMAT
3180 " max:%" G_GINT64_FORMAT, fold_data.live ? "true" : "false",
3181 fold_data.min, fold_data.max);
3183 if (fold_data.min > fold_data.max) {
3184 GST_ERROR_OBJECT (pad, "minimum latency bigger than maximum latency");
3187 gst_query_set_latency (query, fold_data.live, fold_data.min, fold_data.max);
3189 GST_LOG_OBJECT (pad, "latency query failed");
3199 gboolean dispatched;
3203 query_forward_func (GstPad * pad, QueryData * data)
3205 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3206 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3208 data->result |= gst_pad_peer_query (pad, data->query);
3210 data->dispatched = TRUE;
3212 /* stop on first successful reply */
3213 return data->result;
3217 * gst_pad_query_default:
3218 * @pad: a #GstPad to call the default query handler on.
3219 * @parent: (allow-none): the parent of @pad or %NULL
3220 * @query: (transfer none): the #GstQuery to handle.
3222 * Invokes the default query handler for the given pad.
3223 * The query is sent to all pads internally linked to @pad. Note that
3224 * if there are many possible sink pads that are internally linked to
3225 * @pad, only one will be sent the query.
3226 * Multi-sinkpad elements should implement custom query handlers.
3228 * Returns: %TRUE if the query was performed successfully.
3231 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3233 gboolean forward, ret = FALSE;
3235 switch (GST_QUERY_TYPE (query)) {
3236 case GST_QUERY_SCHEDULING:
3237 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3239 case GST_QUERY_ALLOCATION:
3240 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3242 case GST_QUERY_ACCEPT_CAPS:
3243 ret = gst_pad_query_accept_caps_default (pad, query);
3246 case GST_QUERY_CAPS:
3247 ret = gst_pad_query_caps_default (pad, query);
3250 case GST_QUERY_LATENCY:
3251 ret = gst_pad_query_latency_default (pad, query);
3254 case GST_QUERY_POSITION:
3255 case GST_QUERY_SEEKING:
3256 case GST_QUERY_FORMATS:
3257 case GST_QUERY_JITTER:
3258 case GST_QUERY_RATE:
3259 case GST_QUERY_CONVERT:
3265 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3266 query, GST_QUERY_TYPE_NAME (query));
3272 data.dispatched = FALSE;
3273 data.result = FALSE;
3275 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3277 if (data.dispatched) {
3280 /* nothing dispatched, assume drained */
3281 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3291 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3293 GstPad *pad = data->pad;
3294 GstPadProbeInfo *info = data->info;
3295 GstPadProbeType type, flags;
3296 GstPadProbeCallback callback;
3297 GstPadProbeReturn ret;
3298 gpointer original_data;
3300 /* if we have called this callback, do nothing */
3301 if (PROBE_COOKIE (hook) == data->cookie) {
3302 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3303 "hook %lu, cookie %u already called", hook->hook_id,
3304 PROBE_COOKIE (hook));
3308 PROBE_COOKIE (hook) = data->cookie;
3310 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3312 original_data = info->data;
3314 /* one of the data types for non-idle probes */
3315 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3316 && (flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3318 /* one of the scheduling types */
3319 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3321 /* one of the blocking types must match */
3322 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3323 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3325 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3326 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3328 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3329 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3330 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3333 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3334 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3335 PROBE_COOKIE (hook), flags);
3337 data->marshalled = TRUE;
3339 callback = (GstPadProbeCallback) hook->func;
3340 if (callback == NULL)
3343 info->id = hook->hook_id;
3345 GST_OBJECT_UNLOCK (pad);
3347 ret = callback (pad, info, hook->data);
3349 GST_OBJECT_LOCK (pad);
3351 if (original_data != NULL && info->data == NULL) {
3352 GST_DEBUG_OBJECT (pad, "data item in pad probe info was dropped");
3353 info->type = GST_PAD_PROBE_TYPE_INVALID;
3354 data->dropped = TRUE;
3358 case GST_PAD_PROBE_REMOVE:
3359 /* remove the probe */
3360 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3361 cleanup_hook (pad, hook);
3363 case GST_PAD_PROBE_DROP:
3364 /* need to drop the data, make sure other probes don't get called
3366 GST_DEBUG_OBJECT (pad, "asked to drop item");
3367 info->type = GST_PAD_PROBE_TYPE_INVALID;
3368 data->dropped = TRUE;
3370 case GST_PAD_PROBE_HANDLED:
3371 GST_DEBUG_OBJECT (pad, "probe handled data");
3372 data->handled = TRUE;
3374 case GST_PAD_PROBE_PASS:
3375 /* inform the pad block to let things pass */
3376 GST_DEBUG_OBJECT (pad, "asked to pass item");
3379 case GST_PAD_PROBE_OK:
3380 GST_DEBUG_OBJECT (pad, "probe returned OK");
3383 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3390 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3391 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3392 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3397 /* a probe that does not take or return any data */
3398 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3400 if (G_UNLIKELY (pad->num_probes)) { \
3401 GstFlowReturn pval = defaultval; \
3402 /* pass NULL as the data item */ \
3403 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3404 info.ABI.abi.flow_ret = defaultval; \
3405 ret = do_probe_callbacks (pad, &info, defaultval); \
3406 if (G_UNLIKELY (ret != pval && ret != GST_FLOW_OK)) \
3411 #define PROBE_FULL(pad,mask,data,offs,size,label,handleable,handle_label) \
3413 if (G_UNLIKELY (pad->num_probes)) { \
3414 /* pass the data item */ \
3415 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3416 info.ABI.abi.flow_ret = GST_FLOW_OK; \
3417 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3418 /* store the possibly updated data item */ \
3419 data = GST_PAD_PROBE_INFO_DATA (&info); \
3420 /* if something went wrong, exit */ \
3421 if (G_UNLIKELY (ret != GST_FLOW_OK)) { \
3422 if (handleable && ret == GST_FLOW_CUSTOM_SUCCESS_1) { \
3423 ret = info.ABI.abi.flow_ret; \
3424 goto handle_label; \
3431 #define PROBE_PUSH(pad,mask,data,label) \
3432 PROBE_FULL(pad, mask, data, -1, -1, label, FALSE, label);
3433 #define PROBE_HANDLE(pad,mask,data,label,handle_label) \
3434 PROBE_FULL(pad, mask, data, -1, -1, label, TRUE, handle_label);
3435 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3436 PROBE_FULL(pad, mask, data, offs, size, label, FALSE, label);
3438 static GstFlowReturn
3439 do_pad_idle_probe_wait (GstPad * pad)
3441 while (GST_PAD_IS_RUNNING_IDLE_PROBE (pad)) {
3442 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3443 "waiting idle probe to be removed");
3444 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3445 GST_PAD_BLOCK_WAIT (pad);
3446 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3447 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3449 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3450 return GST_FLOW_FLUSHING;
3455 #define PROBE_TYPE_IS_SERIALIZED(i) \
3458 (((i)->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM | \
3459 GST_PAD_PROBE_TYPE_EVENT_FLUSH)) && \
3460 GST_EVENT_IS_SERIALIZED ((i)->data)) \
3462 (((i)->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) && \
3463 GST_QUERY_IS_SERIALIZED ((i)->data)) \
3465 ((i)->type & (GST_PAD_PROBE_TYPE_BUFFER | \
3466 GST_PAD_PROBE_TYPE_BUFFER_LIST)) \
3470 static GstFlowReturn
3471 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3472 GstFlowReturn defaultval)
3481 data.handled = FALSE;
3482 data.marshalled = FALSE;
3483 data.dropped = FALSE;
3484 data.cookie = ++pad->priv->probe_cookie;
3487 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3489 if (is_block && PROBE_TYPE_IS_SERIALIZED (info)) {
3490 if (do_pad_idle_probe_wait (pad) == GST_FLOW_FLUSHING)
3495 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3496 "do probes cookie %u", data.cookie);
3497 cookie = pad->priv->probe_list_cookie;
3499 g_hook_list_marshal (&pad->probes, TRUE,
3500 (GHookMarshaller) probe_hook_marshal, &data);
3502 /* if the list changed, call the new callbacks (they will not have their
3503 * cookie set to data.cookie */
3504 if (cookie != pad->priv->probe_list_cookie) {
3505 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3506 "probe list changed, restarting");
3510 /* the first item that dropped will stop the hooks and then we drop here */
3514 /* If one handler took care of it, let the the item pass */
3519 /* if no handler matched and we are blocking, let the item pass */
3520 if (!data.marshalled && is_block)
3523 /* At this point, all handlers returned either OK or PASS. If one handler
3524 * returned PASS, let the item pass */
3529 while (GST_PAD_IS_BLOCKED (pad)) {
3530 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3531 "we are blocked %d times", pad->num_blocked);
3533 /* we might have released the lock */
3534 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3537 /* now we block the streaming thread. It can be unlocked when we
3538 * deactivate the pad (which will also set the FLUSHING flag) or
3539 * when the pad is unblocked. A flushing event will also unblock
3540 * the pad after setting the FLUSHING flag. */
3541 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3542 "Waiting to be unblocked or set flushing");
3543 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3544 GST_PAD_BLOCK_WAIT (pad);
3545 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3546 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3548 /* if the list changed, call the new callbacks (they will not have their
3549 * cookie set to data.cookie */
3550 if (cookie != pad->priv->probe_list_cookie) {
3551 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3552 "probe list changed, restarting");
3556 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3566 GST_DEBUG_OBJECT (pad, "pad is flushing");
3567 return GST_FLOW_FLUSHING;
3571 GST_DEBUG_OBJECT (pad, "data is dropped");
3572 return GST_FLOW_CUSTOM_SUCCESS;
3576 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3577 GST_DEBUG_OBJECT (pad, "data is passed");
3582 GST_DEBUG_OBJECT (pad, "data was handled");
3583 return GST_FLOW_CUSTOM_SUCCESS_1;
3590 * gst_pad_get_offset:
3593 * Get the offset applied to the running time of @pad. @pad has to be a source
3596 * Returns: the offset.
3599 gst_pad_get_offset (GstPad * pad)
3603 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3605 GST_OBJECT_LOCK (pad);
3606 result = pad->offset;
3607 GST_OBJECT_UNLOCK (pad);
3613 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3615 ev->received = FALSE;
3620 * gst_pad_set_offset:
3622 * @offset: the offset
3624 * Set the offset that will be applied to the running time of @pad.
3627 gst_pad_set_offset (GstPad * pad, gint64 offset)
3629 g_return_if_fail (GST_IS_PAD (pad));
3631 GST_OBJECT_LOCK (pad);
3632 /* if nothing changed, do nothing */
3633 if (pad->offset == offset)
3636 pad->offset = offset;
3637 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3639 /* resend all sticky events with updated offset on next buffer push */
3640 events_foreach (pad, mark_event_not_received, NULL);
3641 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3644 GST_OBJECT_UNLOCK (pad);
3651 /* If TRUE and ret is not OK this means
3652 * that pushing the EOS event failed
3656 /* If called for an event this is
3657 * the event that would be pushed
3658 * next. Don't forward sticky events
3659 * that would come after that */
3663 /* should be called with pad LOCK */
3665 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3667 PushStickyData *data = user_data;
3668 GstEvent *event = ev->event;
3671 GST_DEBUG_OBJECT (pad, "event %s was already received",
3672 GST_EVENT_TYPE_NAME (event));
3676 /* If we're called because of an sticky event, only forward
3677 * events that would come before this new event and the
3679 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3680 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3681 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3682 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3684 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3685 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3688 switch (data->ret) {
3690 ev->received = TRUE;
3691 GST_DEBUG_OBJECT (pad, "event %s marked received",
3692 GST_EVENT_TYPE_NAME (event));
3694 case GST_FLOW_CUSTOM_SUCCESS:
3695 /* we can't assume the event is received when it was dropped */
3696 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3697 GST_EVENT_TYPE_NAME (event));
3698 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3699 data->ret = GST_FLOW_OK;
3701 case GST_FLOW_CUSTOM_SUCCESS_1:
3702 /* event was ignored and should be sent later */
3703 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3704 GST_EVENT_TYPE_NAME (event));
3705 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3706 data->ret = GST_FLOW_OK;
3708 case GST_FLOW_NOT_LINKED:
3709 /* not linked is not a problem, we are sticky so the event will be
3710 * sent later but only for non-EOS events */
3711 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3712 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3713 data->ret = GST_FLOW_OK;
3714 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3717 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3718 gst_flow_get_name (data->ret));
3719 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3723 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3724 data->was_eos = TRUE;
3726 return data->ret == GST_FLOW_OK;
3729 /* check sticky events and push them when needed. should be called
3731 static inline GstFlowReturn
3732 check_sticky (GstPad * pad, GstEvent * event)
3734 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3736 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3737 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3739 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3740 events_foreach (pad, push_sticky, &data);
3742 /* If there's an EOS event we must push it downstream
3743 * even if sending a previous sticky event failed.
3744 * Otherwise the pipeline might wait forever for EOS.
3746 * Only do this if pushing another event than the EOS
3749 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3750 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3752 if (ev && !ev->received) {
3753 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3754 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3755 /* the event could have been dropped. Because this can only
3756 * happen if the user asked for it, it's not an error */
3757 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3758 data.ret = GST_FLOW_OK;
3768 * @pad: a #GstPad to invoke the default query on.
3769 * @query: (transfer none): the #GstQuery to perform.
3771 * Dispatches a query to a pad. The query should have been allocated by the
3772 * caller via one of the type-specific allocation functions. The element that
3773 * the pad belongs to is responsible for filling the query with an appropriate
3774 * response, which should then be parsed with a type-specific query parsing
3777 * Again, the caller is responsible for both the allocation and deallocation of
3778 * the query structure.
3780 * Please also note that some queries might need a running pipeline to work.
3782 * Returns: %TRUE if the query could be performed.
3785 gst_pad_query (GstPad * pad, GstQuery * query)
3788 gboolean res, serialized;
3789 GstPadQueryFunction func;
3790 GstPadProbeType type;
3793 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3794 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3796 if (GST_PAD_IS_SRC (pad)) {
3797 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3798 goto wrong_direction;
3799 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3800 } else if (GST_PAD_IS_SINK (pad)) {
3801 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3802 goto wrong_direction;
3803 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3805 goto unknown_direction;
3807 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3808 GST_QUERY_TYPE_NAME (query));
3810 serialized = GST_QUERY_IS_SERIALIZED (query);
3811 if (G_UNLIKELY (serialized))
3812 GST_PAD_STREAM_LOCK (pad);
3814 GST_OBJECT_LOCK (pad);
3815 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3816 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3817 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3819 ACQUIRE_PARENT (pad, parent, no_parent);
3820 GST_OBJECT_UNLOCK (pad);
3822 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3825 res = func (pad, parent, query);
3827 RELEASE_PARENT (parent);
3829 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3830 GST_QUERY_TYPE_NAME (query), res);
3835 GST_OBJECT_LOCK (pad);
3836 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3837 GST_OBJECT_UNLOCK (pad);
3839 if (G_UNLIKELY (serialized))
3840 GST_PAD_STREAM_UNLOCK (pad);
3847 g_warning ("pad %s:%s query %s in wrong direction",
3848 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3853 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3858 GST_DEBUG_OBJECT (pad, "had no parent");
3859 GST_OBJECT_UNLOCK (pad);
3860 if (G_UNLIKELY (serialized))
3861 GST_PAD_STREAM_UNLOCK (pad);
3866 GST_DEBUG_OBJECT (pad, "had no query function");
3867 RELEASE_PARENT (parent);
3868 if (G_UNLIKELY (serialized))
3869 GST_PAD_STREAM_UNLOCK (pad);
3874 GST_DEBUG_OBJECT (pad, "query failed");
3875 if (G_UNLIKELY (serialized))
3876 GST_PAD_STREAM_UNLOCK (pad);
3881 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3882 GST_OBJECT_UNLOCK (pad);
3883 if (G_UNLIKELY (serialized))
3884 GST_PAD_STREAM_UNLOCK (pad);
3886 /* if a probe dropped without handling, we don't sent it further but assume
3887 * that the probe did not answer the query and return FALSE */
3888 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
3898 * gst_pad_peer_query:
3899 * @pad: a #GstPad to invoke the peer query on.
3900 * @query: (transfer none): the #GstQuery to perform.
3902 * Performs gst_pad_query() on the peer of @pad.
3904 * The caller is responsible for both the allocation and deallocation of
3905 * the query structure.
3907 * Returns: %TRUE if the query could be performed. This function returns %FALSE
3908 * if @pad has no peer.
3911 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3914 GstPadProbeType type;
3915 gboolean res, serialized;
3918 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3919 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3921 if (GST_PAD_IS_SRC (pad)) {
3922 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3923 goto wrong_direction;
3924 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3925 } else if (GST_PAD_IS_SINK (pad)) {
3926 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3927 goto wrong_direction;
3928 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3930 goto unknown_direction;
3932 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3933 GST_QUERY_TYPE_NAME (query));
3935 serialized = GST_QUERY_IS_SERIALIZED (query);
3937 GST_OBJECT_LOCK (pad);
3938 if (GST_PAD_IS_SRC (pad) && serialized) {
3939 /* all serialized queries on the srcpad trigger push of
3941 if (check_sticky (pad, NULL) != GST_FLOW_OK)
3945 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3946 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3947 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3949 peerpad = GST_PAD_PEER (pad);
3950 if (G_UNLIKELY (peerpad == NULL))
3953 gst_object_ref (peerpad);
3954 GST_OBJECT_UNLOCK (pad);
3956 res = gst_pad_query (peerpad, query);
3958 gst_object_unref (peerpad);
3963 GST_OBJECT_LOCK (pad);
3964 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3965 GST_OBJECT_UNLOCK (pad);
3972 g_warning ("pad %s:%s query %s in wrong direction",
3973 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3978 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3983 GST_WARNING_OBJECT (pad, "could not send sticky events");
3984 GST_OBJECT_UNLOCK (pad);
3989 GST_INFO_OBJECT (pad, "pad has no peer");
3990 GST_OBJECT_UNLOCK (pad);
3995 GST_DEBUG_OBJECT (pad, "query failed");
4000 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
4001 GST_OBJECT_UNLOCK (pad);
4003 /* if a probe dropped without handling, we don't sent it further but
4004 * assume that the probe did not answer the query and return FALSE */
4005 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
4014 /**********************************************************************
4015 * Data passing functions
4018 /* this is the chain function that does not perform the additional argument
4019 * checking for that little extra speed.
4021 static inline GstFlowReturn
4022 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
4026 gboolean handled = FALSE;
4028 GST_PAD_STREAM_LOCK (pad);
4030 GST_OBJECT_LOCK (pad);
4031 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4034 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4037 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4040 #ifndef G_DISABLE_ASSERT
4041 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4042 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4044 ":%s:<%s:%s> Got data flow before stream-start event",
4045 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4047 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4049 ":%s:<%s:%s> Got data flow before segment event",
4050 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4052 pad->priv->last_cookie = pad->priv->events_cookie;
4056 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4059 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4061 ACQUIRE_PARENT (pad, parent, no_parent);
4062 GST_OBJECT_UNLOCK (pad);
4064 /* NOTE: we read the chainfunc unlocked.
4065 * we cannot hold the lock for the pad so we might send
4066 * the data to the wrong function. This is not really a
4067 * problem since functions are assigned at creation time
4068 * and don't change that often... */
4069 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
4070 GstPadChainFunction chainfunc;
4072 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
4075 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4076 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
4077 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
4079 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
4081 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4082 "called chainfunction &%s with buffer %p, returned %s",
4083 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
4085 GstPadChainListFunction chainlistfunc;
4087 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
4090 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4091 "calling chainlistfunction &%s",
4092 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
4094 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
4096 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, pad,
4097 "called chainlistfunction &%s, returned %s",
4098 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
4101 RELEASE_PARENT (parent);
4103 GST_PAD_STREAM_UNLOCK (pad);
4110 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4111 "chaining, but pad was flushing");
4112 GST_OBJECT_UNLOCK (pad);
4113 GST_PAD_STREAM_UNLOCK (pad);
4114 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4115 return GST_FLOW_FLUSHING;
4119 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
4120 GST_OBJECT_UNLOCK (pad);
4121 GST_PAD_STREAM_UNLOCK (pad);
4122 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4123 return GST_FLOW_EOS;
4127 g_critical ("chain on pad %s:%s but it was not in push mode",
4128 GST_DEBUG_PAD_NAME (pad));
4129 GST_OBJECT_UNLOCK (pad);
4130 GST_PAD_STREAM_UNLOCK (pad);
4131 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4132 return GST_FLOW_ERROR;
4139 GST_OBJECT_UNLOCK (pad);
4140 GST_PAD_STREAM_UNLOCK (pad);
4141 /* We unref the buffer, except if the probe handled it (CUSTOM_SUCCESS_1) */
4143 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4146 case GST_FLOW_CUSTOM_SUCCESS:
4147 case GST_FLOW_CUSTOM_SUCCESS_1:
4148 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4152 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4159 GST_DEBUG_OBJECT (pad, "No parent when chaining %" GST_PTR_FORMAT, data);
4160 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4161 GST_OBJECT_UNLOCK (pad);
4162 GST_PAD_STREAM_UNLOCK (pad);
4163 return GST_FLOW_FLUSHING;
4167 RELEASE_PARENT (parent);
4168 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4169 g_critical ("chain on pad %s:%s but it has no chainfunction",
4170 GST_DEBUG_PAD_NAME (pad));
4171 GST_PAD_STREAM_UNLOCK (pad);
4172 return GST_FLOW_NOT_SUPPORTED;
4178 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4179 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
4182 * Chain a buffer to @pad.
4184 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4186 * If the buffer type is not acceptable for @pad (as negotiated with a
4187 * preceding GST_EVENT_CAPS event), this function returns
4188 * #GST_FLOW_NOT_NEGOTIATED.
4190 * The function proceeds calling the chain function installed on @pad (see
4191 * gst_pad_set_chain_function()) and the return value of that function is
4192 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4195 * In all cases, success or failure, the caller loses its reference to @buffer
4196 * after calling this function.
4198 * Returns: a #GstFlowReturn from the pad.
4203 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
4205 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4206 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4207 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4209 return gst_pad_chain_data_unchecked (pad,
4210 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4213 static GstFlowReturn
4214 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
4215 GstBufferList * list)
4221 GST_INFO_OBJECT (pad, "chaining each buffer in list individually");
4223 len = gst_buffer_list_length (list);
4226 for (i = 0; i < len; i++) {
4227 buffer = gst_buffer_list_get (list, i);
4229 gst_pad_chain_data_unchecked (pad,
4230 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
4231 gst_buffer_ref (buffer));
4232 if (ret != GST_FLOW_OK)
4235 gst_buffer_list_unref (list);
4241 * gst_pad_chain_list:
4242 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4243 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
4246 * Chain a bufferlist to @pad.
4248 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
4250 * If @pad was not negotiated properly with a CAPS event, this function
4251 * returns #GST_FLOW_NOT_NEGOTIATED.
4253 * The function proceeds calling the chainlist function installed on @pad (see
4254 * gst_pad_set_chain_list_function()) and the return value of that function is
4255 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
4256 * chainlist function.
4258 * In all cases, success or failure, the caller loses its reference to @list
4259 * after calling this function.
4263 * Returns: a #GstFlowReturn from the pad.
4266 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
4268 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4269 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4270 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4272 return gst_pad_chain_data_unchecked (pad,
4273 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4276 static GstFlowReturn
4277 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4281 gboolean handled = FALSE;
4283 GST_OBJECT_LOCK (pad);
4284 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4287 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4290 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4293 #ifndef G_DISABLE_ASSERT
4294 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4295 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4297 ":%s:<%s:%s> Got data flow before stream-start event",
4298 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4300 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4302 ":%s:<%s:%s> Got data flow before segment event",
4303 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4305 pad->priv->last_cookie = pad->priv->events_cookie;
4309 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4312 /* do block probes */
4313 PROBE_HANDLE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped,
4316 /* recheck sticky events because the probe might have cause a relink */
4317 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4320 /* do post-blocking probes */
4321 PROBE_HANDLE (pad, type, data, probe_stopped, probe_handled);
4323 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4326 /* take ref to peer pad before releasing the lock */
4327 gst_object_ref (peer);
4329 GST_OBJECT_UNLOCK (pad);
4331 ret = gst_pad_chain_data_unchecked (peer, type, data);
4334 gst_object_unref (peer);
4336 GST_OBJECT_LOCK (pad);
4337 pad->ABI.abi.last_flowret = ret;
4339 if (pad->priv->using == 0) {
4340 /* pad is not active anymore, trigger idle callbacks */
4341 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4342 probe_stopped, ret);
4344 GST_OBJECT_UNLOCK (pad);
4348 /* ERROR recovery here */
4352 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4353 "pushing, but pad was flushing");
4354 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4355 GST_OBJECT_UNLOCK (pad);
4356 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4357 return GST_FLOW_FLUSHING;
4361 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4362 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4363 GST_OBJECT_UNLOCK (pad);
4364 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4365 return GST_FLOW_EOS;
4369 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4370 GST_DEBUG_PAD_NAME (pad));
4371 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4372 GST_OBJECT_UNLOCK (pad);
4373 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4374 return GST_FLOW_ERROR;
4378 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4379 "error pushing events, return %s", gst_flow_get_name (ret));
4380 pad->ABI.abi.last_flowret = ret;
4381 GST_OBJECT_UNLOCK (pad);
4382 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4390 GST_OBJECT_UNLOCK (pad);
4391 if (data != NULL && !handled)
4392 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4395 case GST_FLOW_CUSTOM_SUCCESS:
4396 case GST_FLOW_CUSTOM_SUCCESS_1:
4397 GST_DEBUG_OBJECT (pad, "dropped or handled buffer");
4401 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4404 pad->ABI.abi.last_flowret = ret;
4409 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4410 "pushing, but it was not linked");
4411 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4412 GST_OBJECT_UNLOCK (pad);
4413 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4414 return GST_FLOW_NOT_LINKED;
4420 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4421 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4424 * Pushes a buffer to the peer of @pad.
4426 * This function will call installed block probes before triggering any
4427 * installed data probes.
4429 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4430 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4433 * In all cases, success or failure, the caller loses its reference to @buffer
4434 * after calling this function.
4436 * Returns: a #GstFlowReturn from the peer pad.
4441 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4443 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4444 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4445 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4447 return gst_pad_push_data (pad,
4448 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4452 * gst_pad_push_list:
4453 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4454 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4457 * Pushes a buffer list to the peer of @pad.
4459 * This function will call installed block probes before triggering any
4460 * installed data probes.
4462 * The function proceeds calling the chain function on the peer pad and returns
4463 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4464 * be returned. If the peer pad does not have any installed chainlist function
4465 * every group buffer of the list will be merged into a normal #GstBuffer and
4466 * chained via gst_pad_chain().
4468 * In all cases, success or failure, the caller loses its reference to @list
4469 * after calling this function.
4471 * Returns: a #GstFlowReturn from the peer pad.
4476 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4478 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4479 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4480 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4482 return gst_pad_push_data (pad,
4483 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4486 static GstFlowReturn
4487 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4488 GstBuffer ** buffer)
4491 GstPadGetRangeFunction getrangefunc;
4495 GST_PAD_STREAM_LOCK (pad);
4497 GST_OBJECT_LOCK (pad);
4498 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4501 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4504 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4509 /* when one of the probes returns DROPPED, probe_stopped will be called
4510 * and we skip calling the getrange function, res_buf should then contain a
4511 * valid result buffer */
4512 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4513 res_buf, offset, size, probe_stopped);
4515 /* recheck sticky events because the probe might have cause a relink */
4516 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4519 ACQUIRE_PARENT (pad, parent, no_parent);
4520 GST_OBJECT_UNLOCK (pad);
4522 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4525 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4526 "calling getrangefunc %s, offset %"
4527 G_GUINT64_FORMAT ", size %u",
4528 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4530 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4532 RELEASE_PARENT (parent);
4534 GST_OBJECT_LOCK (pad);
4535 if (G_UNLIKELY (ret != GST_FLOW_OK))
4536 goto get_range_failed;
4538 /* can only fire the signal if we have a valid buffer */
4540 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4541 res_buf, offset, size, probe_stopped_unref);
4542 pad->ABI.abi.last_flowret = ret;
4543 GST_OBJECT_UNLOCK (pad);
4545 GST_PAD_STREAM_UNLOCK (pad);
4554 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4555 "getrange, but pad was flushing");
4556 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4557 GST_OBJECT_UNLOCK (pad);
4558 GST_PAD_STREAM_UNLOCK (pad);
4559 return GST_FLOW_FLUSHING;
4563 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4564 GST_DEBUG_PAD_NAME (pad));
4565 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4566 GST_OBJECT_UNLOCK (pad);
4567 GST_PAD_STREAM_UNLOCK (pad);
4568 return GST_FLOW_ERROR;
4572 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4573 pad->ABI.abi.last_flowret = ret;
4574 GST_OBJECT_UNLOCK (pad);
4575 GST_PAD_STREAM_UNLOCK (pad);
4580 GST_DEBUG_OBJECT (pad, "no parent");
4581 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4582 GST_OBJECT_UNLOCK (pad);
4583 GST_PAD_STREAM_UNLOCK (pad);
4584 return GST_FLOW_FLUSHING;
4588 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4589 GST_DEBUG_PAD_NAME (pad));
4590 RELEASE_PARENT (parent);
4591 GST_PAD_STREAM_UNLOCK (pad);
4592 return GST_FLOW_NOT_SUPPORTED;
4596 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4597 "probe returned %s", gst_flow_get_name (ret));
4598 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4600 /* the probe filled the buffer and asks us to not call the getrange
4601 * anymore, we continue with the post probes then. */
4602 GST_DEBUG_OBJECT (pad, "handled buffer");
4606 /* no buffer, we are EOS */
4607 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4611 pad->ABI.abi.last_flowret = ret;
4612 GST_OBJECT_UNLOCK (pad);
4613 GST_PAD_STREAM_UNLOCK (pad);
4617 probe_stopped_unref:
4619 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4620 "probe returned %s", gst_flow_get_name (ret));
4621 /* if we drop here, it signals EOS */
4622 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4624 pad->ABI.abi.last_flowret = ret;
4625 GST_OBJECT_UNLOCK (pad);
4626 GST_PAD_STREAM_UNLOCK (pad);
4627 if (*buffer == NULL)
4628 gst_buffer_unref (res_buf);
4633 pad->ABI.abi.last_flowret = ret;
4634 GST_OBJECT_UNLOCK (pad);
4635 GST_PAD_STREAM_UNLOCK (pad);
4636 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4637 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4638 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4644 * gst_pad_get_range:
4645 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4646 * @offset: The start offset of the buffer
4647 * @size: The length of the buffer
4648 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4649 * returns #GST_FLOW_ERROR if %NULL.
4651 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4652 * immediately and @buffer is %NULL.
4654 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4655 * description of a getrange function. If @pad has no getrange function
4656 * installed (see gst_pad_set_getrange_function()) this function returns
4657 * #GST_FLOW_NOT_SUPPORTED.
4659 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4660 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4661 * must be freed with gst_buffer_unref() after usage.
4663 * When @buffer points to a variable that points to a valid #GstBuffer, the
4664 * buffer will be filled with the result data when this function returns
4665 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4666 * @size bytes will be filled in the result buffer and its size will be updated
4669 * Note that less than @size bytes can be returned in @buffer when, for example,
4670 * an EOS condition is near or when @buffer is not large enough to hold @size
4671 * bytes. The caller should check the result buffer size to get the result size.
4673 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4674 * will be unchanged.
4676 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4678 * Returns: a #GstFlowReturn from the pad.
4683 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4684 GstBuffer ** buffer)
4686 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4687 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4688 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4689 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4690 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4692 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4696 * gst_pad_pull_range:
4697 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4698 * @offset: The start offset of the buffer
4699 * @size: The length of the buffer
4700 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4701 * GST_FLOW_ERROR if %NULL.
4703 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4705 * This function will first trigger the pad block signal if it was
4708 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4709 * function returns the result of gst_pad_get_range() on the peer pad.
4710 * See gst_pad_get_range() for a list of return values and for the
4711 * semantics of the arguments of this function.
4713 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4714 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4715 * must be freed with gst_buffer_unref() after usage. When this function
4716 * returns any other result value, @buffer will still point to %NULL.
4718 * When @buffer points to a variable that points to a valid #GstBuffer, the
4719 * buffer will be filled with the result data when this function returns
4720 * #GST_FLOW_OK. When this function returns any other result value,
4721 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4722 * @size bytes will be filled in the result buffer and its size will be updated
4725 * Note that less than @size bytes can be returned in @buffer when, for example,
4726 * an EOS condition is near or when @buffer is not large enough to hold @size
4727 * bytes. The caller should check the result buffer size to get the result size.
4729 * Returns: a #GstFlowReturn from the peer pad.
4734 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4735 GstBuffer ** buffer)
4741 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4742 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4743 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4744 g_return_val_if_fail (*buffer == NULL || (GST_IS_BUFFER (*buffer)
4745 && gst_buffer_get_size (*buffer) >= size), GST_FLOW_ERROR);
4747 GST_OBJECT_LOCK (pad);
4748 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4751 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4756 /* when one of the probes returns DROPPED, probe_stopped will be
4757 * called and we skip calling the peer getrange function. *buffer should then
4758 * contain a valid buffer */
4759 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4760 res_buf, offset, size, probe_stopped);
4762 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4765 gst_object_ref (peer);
4767 GST_OBJECT_UNLOCK (pad);
4769 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4771 gst_object_unref (peer);
4773 GST_OBJECT_LOCK (pad);
4775 pad->ABI.abi.last_flowret = ret;
4776 if (pad->priv->using == 0) {
4777 /* pad is not active anymore, trigger idle callbacks */
4778 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4779 probe_stopped_unref, ret);
4782 if (G_UNLIKELY (ret != GST_FLOW_OK))
4783 goto pull_range_failed;
4786 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4787 res_buf, offset, size, probe_stopped_unref);
4789 GST_OBJECT_UNLOCK (pad);
4795 /* ERROR recovery here */
4798 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4799 "pullrange, but pad was flushing");
4800 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4801 GST_OBJECT_UNLOCK (pad);
4802 return GST_FLOW_FLUSHING;
4806 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4807 GST_DEBUG_PAD_NAME (pad));
4808 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4809 GST_OBJECT_UNLOCK (pad);
4810 return GST_FLOW_ERROR;
4814 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4815 gst_flow_get_name (ret));
4816 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4818 /* the probe filled the buffer and asks us to not forward to the peer
4819 * anymore, we continue with the post probes then */
4820 GST_DEBUG_OBJECT (pad, "handled buffer");
4824 /* no buffer, we are EOS then */
4825 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4829 pad->ABI.abi.last_flowret = ret;
4830 GST_OBJECT_UNLOCK (pad);
4835 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4836 "pulling range, but it was not linked");
4837 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4838 GST_OBJECT_UNLOCK (pad);
4839 return GST_FLOW_NOT_LINKED;
4843 pad->ABI.abi.last_flowret = ret;
4844 GST_OBJECT_UNLOCK (pad);
4845 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4846 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4847 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4850 probe_stopped_unref:
4852 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4853 "post probe returned %s", gst_flow_get_name (ret));
4855 /* if we drop here, it signals EOS */
4856 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4859 pad->ABI.abi.last_flowret = ret;
4860 GST_OBJECT_UNLOCK (pad);
4862 if (*buffer == NULL)
4863 gst_buffer_unref (res_buf);
4868 /* must be called with pad object lock */
4869 static GstFlowReturn
4870 store_sticky_event (GstPad * pad, GstEvent * event)
4875 gboolean res = FALSE;
4876 const gchar *name = NULL;
4877 gboolean insert = TRUE;
4879 type = GST_EVENT_TYPE (event);
4881 /* Store all sticky events except SEGMENT/EOS when we're flushing,
4882 * otherwise they can be dropped and nothing would ever resend them.
4883 * Only do that for activated pads though, everything else is a bug!
4885 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4886 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4887 || type == GST_EVENT_EOS))))
4890 /* Unset the EOS flag when received STREAM_START event, so pad can
4891 * store sticky event and then push it later */
4892 if (type == GST_EVENT_STREAM_START) {
4893 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4894 remove_event_by_type (pad, GST_EVENT_EOS);
4895 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4898 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4901 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4902 name = gst_structure_get_name (gst_event_get_structure (event));
4904 events = pad->priv->events;
4907 for (i = 0; i < len; i++) {
4908 PadEvent *ev = &g_array_index (events, PadEvent, i);
4910 if (ev->event == NULL)
4913 if (type == GST_EVENT_TYPE (ev->event)) {
4914 /* matching types, check matching name if needed */
4915 if (name && !gst_event_has_name (ev->event, name))
4919 if ((res = gst_event_replace (&ev->event, event)))
4920 ev->received = FALSE;
4926 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4927 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4928 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4929 * storing the sticky ordered we can check that this is respected. */
4930 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4931 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4933 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4934 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4935 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4936 gst_event_type_get_name (type));
4942 ev.event = gst_event_ref (event);
4943 ev.received = FALSE;
4944 g_array_insert_val (events, i, ev);
4949 pad->priv->events_cookie++;
4950 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4952 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4954 switch (GST_EVENT_TYPE (event)) {
4955 case GST_EVENT_CAPS:
4956 GST_OBJECT_UNLOCK (pad);
4958 GST_DEBUG_OBJECT (pad, "notify caps");
4959 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4961 GST_OBJECT_LOCK (pad);
4967 if (type == GST_EVENT_EOS) {
4968 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4969 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4972 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4977 GST_DEBUG_OBJECT (pad, "pad is flushing");
4978 return GST_FLOW_FLUSHING;
4982 GST_DEBUG_OBJECT (pad, "pad is EOS");
4983 return GST_FLOW_EOS;
4988 * gst_pad_store_sticky_event:
4990 * @event: a #GstEvent
4992 * Store the sticky @event on @pad
4994 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4995 * was flushing or #GST_FLOW_EOS when the pad was EOS.
5000 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
5004 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5005 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5007 GST_OBJECT_LOCK (pad);
5008 ret = store_sticky_event (pad, event);
5009 GST_OBJECT_UNLOCK (pad);
5015 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
5017 PushStickyData *data = user_data;
5019 /* Forward all sticky events before our current one that are pending */
5020 if (ev->event != data->event
5021 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
5022 return push_sticky (pad, ev, data);
5027 /* should be called with pad LOCK */
5028 static GstFlowReturn
5029 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
5030 GstPadProbeType type)
5034 GstEventType event_type;
5036 /* pass the adjusted event on. We need to do this even if
5037 * there is no peer pad because of the probes. */
5038 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
5040 /* Two checks to be made:
5041 * . (un)set the FLUSHING flag for flushing events,
5042 * . handle pad blocking */
5043 event_type = GST_EVENT_TYPE (event);
5044 switch (event_type) {
5045 case GST_EVENT_FLUSH_START:
5046 GST_PAD_SET_FLUSHING (pad);
5048 GST_PAD_BLOCK_BROADCAST (pad);
5049 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5051 case GST_EVENT_FLUSH_STOP:
5052 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5055 GST_PAD_UNSET_FLUSHING (pad);
5057 /* Remove sticky EOS events */
5058 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5059 remove_event_by_type (pad, GST_EVENT_EOS);
5060 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5061 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5062 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5064 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
5068 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5071 /* No need to check for EOS here as either the caller (gst_pad_push_event())
5072 * checked already or this is called as part of pushing sticky events,
5073 * in which case we still want to forward the EOS event downstream.
5076 switch (GST_EVENT_TYPE (event)) {
5077 case GST_EVENT_RECONFIGURE:
5078 if (GST_PAD_IS_SINK (pad))
5079 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5084 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
5085 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5090 /* send probes after modifying the events above */
5091 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5093 /* recheck sticky events because the probe might have cause a relink */
5094 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
5095 && (GST_EVENT_IS_SERIALIZED (event)
5096 || GST_EVENT_IS_STICKY (event))) {
5097 PushStickyData data = { GST_FLOW_OK, FALSE, event };
5098 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5100 /* Push all sticky events before our current one
5101 * that have changed */
5102 events_foreach (pad, sticky_changed, &data);
5105 /* now check the peer pad */
5106 peerpad = GST_PAD_PEER (pad);
5107 if (peerpad == NULL)
5110 gst_object_ref (peerpad);
5112 GST_OBJECT_UNLOCK (pad);
5114 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
5115 event, gst_event_type_get_name (event_type), peerpad);
5117 ret = gst_pad_send_event_unchecked (peerpad, event, type);
5119 /* Note: we gave away ownership of the event at this point but we can still
5120 * print the old pointer */
5121 GST_LOG_OBJECT (pad,
5122 "sent event %p (%s) to peerpad %" GST_PTR_FORMAT ", ret %s", event,
5123 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
5125 gst_object_unref (peerpad);
5127 GST_OBJECT_LOCK (pad);
5129 if (pad->priv->using == 0) {
5130 /* pad is not active anymore, trigger idle callbacks */
5131 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
5132 idle_probe_stopped, ret);
5136 /* ERROR handling */
5139 GST_DEBUG_OBJECT (pad, "We're flushing");
5140 gst_event_unref (event);
5141 return GST_FLOW_FLUSHING;
5145 GST_DEBUG_OBJECT (pad, "flush-stop on inactive pad");
5146 gst_event_unref (event);
5147 return GST_FLOW_FLUSHING;
5151 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5152 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5153 gst_event_unref (event);
5156 case GST_FLOW_CUSTOM_SUCCESS_1:
5157 GST_DEBUG_OBJECT (pad, "handled event");
5159 case GST_FLOW_CUSTOM_SUCCESS:
5160 GST_DEBUG_OBJECT (pad, "dropped event");
5163 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5170 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
5171 gst_event_type_get_name (GST_EVENT_TYPE (event)));
5172 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
5173 gst_event_unref (event);
5175 /* unlinked pads should not influence latency configuration */
5176 if (event_type == GST_EVENT_LATENCY)
5179 return GST_FLOW_NOT_LINKED;
5183 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
5189 * gst_pad_push_event:
5190 * @pad: a #GstPad to push the event to.
5191 * @event: (transfer full): the #GstEvent to send to the pad.
5193 * Sends the event to the peer of the given pad. This function is
5194 * mainly used by elements to send events to their peer
5197 * This function takes ownership of the provided event so you should
5198 * gst_event_ref() it if you want to reuse the event after this call.
5200 * Returns: %TRUE if the event was handled.
5205 gst_pad_push_event (GstPad * pad, GstEvent * event)
5207 gboolean res = FALSE;
5208 GstPadProbeType type;
5209 gboolean sticky, serialized;
5211 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5212 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
5214 if (GST_PAD_IS_SRC (pad)) {
5215 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5216 goto wrong_direction;
5217 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5218 } else if (GST_PAD_IS_SINK (pad)) {
5219 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5220 goto wrong_direction;
5221 /* events pushed on sinkpad never are sticky */
5222 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5224 goto unknown_direction;
5226 GST_OBJECT_LOCK (pad);
5227 sticky = GST_EVENT_IS_STICKY (event);
5228 serialized = GST_EVENT_IS_SERIALIZED (event);
5231 /* srcpad sticky events are stored immediately, the received flag is set
5232 * to FALSE and will be set to TRUE when we can successfully push the
5233 * event to the peer pad */
5234 switch (store_sticky_event (pad, event)) {
5235 case GST_FLOW_FLUSHING:
5243 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
5244 /* all serialized or sticky events on the srcpad trigger push of
5246 res = (check_sticky (pad, event) == GST_FLOW_OK);
5251 /* other events are pushed right away */
5252 ret = gst_pad_push_event_unchecked (pad, event, type);
5253 /* dropped events by a probe are not an error */
5254 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS
5255 || ret == GST_FLOW_CUSTOM_SUCCESS_1);
5257 /* Errors in sticky event pushing are no problem and ignored here
5258 * as they will cause more meaningful errors during data flow.
5259 * For EOS events, that are not followed by data flow, we still
5260 * return FALSE here though.
5262 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
5264 gst_event_unref (event);
5266 GST_OBJECT_UNLOCK (pad);
5270 /* ERROR handling */
5273 g_warning ("pad %s:%s pushing %s event in wrong direction",
5274 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5275 gst_event_unref (event);
5280 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5281 gst_event_unref (event);
5286 GST_DEBUG_OBJECT (pad, "We're flushing");
5287 GST_OBJECT_UNLOCK (pad);
5288 gst_event_unref (event);
5293 GST_DEBUG_OBJECT (pad, "We're EOS");
5294 GST_OBJECT_UNLOCK (pad);
5295 gst_event_unref (event);
5300 /* Check if we can call the event function with the given event */
5301 static GstFlowReturn
5302 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5306 switch (GST_EVENT_TYPE (event)) {
5307 case GST_EVENT_CAPS:
5309 /* backwards compatibility mode for caps */
5310 gst_event_parse_caps (event, &caps);
5312 if (!gst_pad_query_accept_caps (pad, caps))
5324 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5325 "caps %" GST_PTR_FORMAT " not accepted", caps);
5326 return GST_FLOW_NOT_NEGOTIATED;
5330 static GstFlowReturn
5331 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5332 GstPadProbeType type)
5335 GstEventType event_type;
5336 gboolean serialized, need_unlock = FALSE, sticky;
5337 GstPadEventFunction eventfunc;
5340 GST_OBJECT_LOCK (pad);
5342 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5344 if (GST_PAD_IS_SINK (pad))
5345 serialized = GST_EVENT_IS_SERIALIZED (event);
5348 sticky = GST_EVENT_IS_STICKY (event);
5349 event_type = GST_EVENT_TYPE (event);
5350 switch (event_type) {
5351 case GST_EVENT_FLUSH_START:
5352 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5353 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5355 /* can't even accept a flush begin event when flushing */
5356 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5359 GST_PAD_SET_FLUSHING (pad);
5360 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5362 case GST_EVENT_FLUSH_STOP:
5363 /* we can't accept flush-stop on inactive pads else the flushing flag
5364 * would be cleared and it would look like the pad can accept data.
5365 * Also, some elements restart a streaming thread in flush-stop which we
5366 * can't allow on inactive pads */
5367 if (G_UNLIKELY (!GST_PAD_IS_ACTIVE (pad)))
5370 GST_PAD_UNSET_FLUSHING (pad);
5371 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5372 /* Remove pending EOS events */
5373 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5374 remove_event_by_type (pad, GST_EVENT_EOS);
5375 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5376 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5377 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5379 GST_OBJECT_UNLOCK (pad);
5380 /* grab stream lock */
5381 GST_PAD_STREAM_LOCK (pad);
5383 GST_OBJECT_LOCK (pad);
5384 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5387 case GST_EVENT_RECONFIGURE:
5388 if (GST_PAD_IS_SRC (pad))
5389 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5391 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5392 "have event type %" GST_PTR_FORMAT, event);
5394 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5397 switch (event_type) {
5398 case GST_EVENT_STREAM_START:
5399 /* Remove sticky EOS events */
5400 GST_LOG_OBJECT (pad, "Removing pending EOS events");
5401 remove_event_by_type (pad, GST_EVENT_EOS);
5402 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5409 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5412 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5413 GST_OBJECT_UNLOCK (pad);
5414 GST_PAD_STREAM_LOCK (pad);
5416 GST_OBJECT_LOCK (pad);
5417 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5420 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5426 /* now do the probe */
5428 type | GST_PAD_PROBE_TYPE_PUSH |
5429 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5431 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5433 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5436 ACQUIRE_PARENT (pad, parent, no_parent);
5437 GST_OBJECT_UNLOCK (pad);
5439 ret = pre_eventfunc_check (pad, event);
5440 if (G_UNLIKELY (ret != GST_FLOW_OK))
5441 goto precheck_failed;
5444 gst_event_ref (event);
5446 if (eventfunc (pad, parent, event)) {
5449 /* something went wrong */
5450 switch (event_type) {
5451 case GST_EVENT_CAPS:
5452 ret = GST_FLOW_NOT_NEGOTIATED;
5455 ret = GST_FLOW_ERROR;
5459 RELEASE_PARENT (parent);
5461 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5464 if (ret == GST_FLOW_OK) {
5465 GST_OBJECT_LOCK (pad);
5466 /* after the event function accepted the event, we can store the sticky
5467 * event on the pad */
5468 switch (store_sticky_event (pad, event)) {
5469 case GST_FLOW_FLUSHING:
5476 GST_OBJECT_UNLOCK (pad);
5478 gst_event_unref (event);
5482 GST_PAD_STREAM_UNLOCK (pad);
5486 /* ERROR handling */
5489 GST_OBJECT_UNLOCK (pad);
5491 GST_PAD_STREAM_UNLOCK (pad);
5492 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5493 "Received event on flushing pad. Discarding");
5494 gst_event_unref (event);
5495 return GST_FLOW_FLUSHING;
5499 GST_OBJECT_UNLOCK (pad);
5501 GST_PAD_STREAM_UNLOCK (pad);
5502 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5503 "Received flush-stop on inactive pad. Discarding");
5504 gst_event_unref (event);
5505 return GST_FLOW_FLUSHING;
5509 GST_OBJECT_UNLOCK (pad);
5511 GST_PAD_STREAM_UNLOCK (pad);
5512 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5513 "Received event on EOS pad. Discarding");
5514 gst_event_unref (event);
5515 return GST_FLOW_EOS;
5519 GST_OBJECT_UNLOCK (pad);
5521 GST_PAD_STREAM_UNLOCK (pad);
5522 /* Only unref if unhandled */
5523 if (ret != GST_FLOW_CUSTOM_SUCCESS_1)
5524 gst_event_unref (event);
5527 case GST_FLOW_CUSTOM_SUCCESS_1:
5528 case GST_FLOW_CUSTOM_SUCCESS:
5529 GST_DEBUG_OBJECT (pad, "dropped or handled event");
5533 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5540 g_warning ("pad %s:%s has no event handler, file a bug.",
5541 GST_DEBUG_PAD_NAME (pad));
5542 GST_OBJECT_UNLOCK (pad);
5544 GST_PAD_STREAM_UNLOCK (pad);
5545 gst_event_unref (event);
5546 return GST_FLOW_NOT_SUPPORTED;
5550 GST_DEBUG_OBJECT (pad, "no parent");
5551 GST_OBJECT_UNLOCK (pad);
5553 GST_PAD_STREAM_UNLOCK (pad);
5554 gst_event_unref (event);
5555 return GST_FLOW_FLUSHING;
5559 GST_DEBUG_OBJECT (pad, "pre event check failed");
5560 RELEASE_PARENT (parent);
5562 GST_PAD_STREAM_UNLOCK (pad);
5563 gst_event_unref (event);
5569 * gst_pad_send_event:
5570 * @pad: a #GstPad to send the event to.
5571 * @event: (transfer full): the #GstEvent to send to the pad.
5573 * Sends the event to the pad. This function can be used
5574 * by applications to send events in the pipeline.
5576 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5577 * sink pad, @event should be a downstream event. For example, you would not
5578 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5579 * Furthermore, some downstream events have to be serialized with data flow,
5580 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5581 * the event needs to be serialized with data flow, this function will take the
5582 * pad's stream lock while calling its event function.
5584 * To find out whether an event type is upstream, downstream, or downstream and
5585 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5586 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5587 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5588 * plugin doesn't need to bother itself with this information; the core handles
5589 * all necessary locks and checks.
5591 * This function takes ownership of the provided event so you should
5592 * gst_event_ref() it if you want to reuse the event after this call.
5594 * Returns: %TRUE if the event was handled.
5597 gst_pad_send_event (GstPad * pad, GstEvent * event)
5600 GstPadProbeType type;
5602 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5603 g_return_val_if_fail (event != NULL, FALSE);
5605 if (GST_PAD_IS_SINK (pad)) {
5606 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5607 goto wrong_direction;
5608 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5609 } else if (GST_PAD_IS_SRC (pad)) {
5610 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5611 goto wrong_direction;
5612 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5614 goto unknown_direction;
5616 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5623 /* ERROR handling */
5626 g_warning ("pad %s:%s sending %s event in wrong direction",
5627 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5628 gst_event_unref (event);
5633 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5634 gst_event_unref (event);
5640 * gst_pad_set_element_private:
5641 * @pad: the #GstPad to set the private data of.
5642 * @priv: The private data to attach to the pad.
5644 * Set the given private data gpointer on the pad.
5645 * This function can only be used by the element that owns the pad.
5646 * No locking is performed in this function.
5649 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5651 pad->element_private = priv;
5655 * gst_pad_get_element_private:
5656 * @pad: the #GstPad to get the private data of.
5658 * Gets the private data of a pad.
5659 * No locking is performed in this function.
5661 * Returns: (transfer none): a #gpointer to the private data.
5664 gst_pad_get_element_private (GstPad * pad)
5666 return pad->element_private;
5670 * gst_pad_get_sticky_event:
5671 * @pad: the #GstPad to get the event from.
5672 * @event_type: the #GstEventType that should be retrieved.
5673 * @idx: the index of the event
5675 * Returns a new reference of the sticky event of type @event_type
5678 * Returns: (transfer full) (nullable): a #GstEvent of type
5679 * @event_type or %NULL when no event of @event_type was on
5680 * @pad. Unref after usage.
5683 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5685 GstEvent *event = NULL;
5688 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5689 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5691 GST_OBJECT_LOCK (pad);
5692 ev = find_event_by_type (pad, event_type, idx);
5693 if (ev && (event = ev->event))
5694 gst_event_ref (event);
5695 GST_OBJECT_UNLOCK (pad);
5702 GstPadStickyEventsForeachFunction func;
5707 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5709 ForeachDispatch *data = user_data;
5710 gboolean ret = TRUE;
5713 GST_OBJECT_UNLOCK (pad);
5715 ret = data->func (pad, &ev->event, data->user_data);
5717 GST_OBJECT_LOCK (pad);
5724 * gst_pad_sticky_events_foreach:
5725 * @pad: the #GstPad that should be used for iteration.
5726 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5727 * should be called for every event.
5728 * @user_data: (closure): the optional user data.
5730 * Iterates all sticky events on @pad and calls @foreach_func for every
5731 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5734 gst_pad_sticky_events_foreach (GstPad * pad,
5735 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5737 ForeachDispatch data;
5739 g_return_if_fail (GST_IS_PAD (pad));
5740 g_return_if_fail (foreach_func != NULL);
5742 data.func = foreach_func;
5743 data.user_data = user_data;
5745 GST_OBJECT_LOCK (pad);
5746 events_foreach (pad, foreach_dispatch_function, &data);
5747 GST_OBJECT_UNLOCK (pad);
5751 do_stream_status (GstPad * pad, GstStreamStatusType type,
5752 GThread * thread, GstTask * task)
5756 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5758 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5759 if (GST_IS_ELEMENT (parent)) {
5760 GstMessage *message;
5761 GValue value = { 0 };
5763 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5764 gchar *tname, *ename, *pname;
5766 /* create a good task name */
5767 ename = gst_element_get_name (parent);
5768 pname = gst_pad_get_name (pad);
5769 tname = g_strdup_printf ("%s:%s", ename, pname);
5773 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5777 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5780 g_value_init (&value, GST_TYPE_TASK);
5781 g_value_set_object (&value, task);
5782 gst_message_set_stream_status_object (message, &value);
5783 g_value_unset (&value);
5785 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5786 gst_element_post_message (parent, message);
5788 gst_object_unref (parent);
5793 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5795 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5800 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5802 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5807 * gst_pad_start_task:
5808 * @pad: the #GstPad to start the task of
5809 * @func: the task function to call
5810 * @user_data: user data passed to the task function
5811 * @notify: called when @user_data is no longer referenced
5813 * Starts a task that repeatedly calls @func with @user_data. This function
5814 * is mostly used in pad activation functions to start the dataflow.
5815 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5816 * before @func is called.
5818 * Returns: a %TRUE if the task could be started.
5821 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5822 GDestroyNotify notify)
5827 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5828 g_return_val_if_fail (func != NULL, FALSE);
5830 GST_DEBUG_OBJECT (pad, "start task");
5832 GST_OBJECT_LOCK (pad);
5833 task = GST_PAD_TASK (pad);
5835 task = gst_task_new (func, user_data, notify);
5836 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5837 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5838 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5839 GST_INFO_OBJECT (pad, "created task %p", task);
5840 GST_PAD_TASK (pad) = task;
5841 gst_object_ref (task);
5842 /* release lock to post the message */
5843 GST_OBJECT_UNLOCK (pad);
5845 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5847 gst_object_unref (task);
5849 GST_OBJECT_LOCK (pad);
5850 /* nobody else is supposed to have changed the pad now */
5851 if (GST_PAD_TASK (pad) != task)
5852 goto concurrent_stop;
5854 res = gst_task_set_state (task, GST_TASK_STARTED);
5855 GST_OBJECT_UNLOCK (pad);
5862 GST_OBJECT_UNLOCK (pad);
5868 * gst_pad_pause_task:
5869 * @pad: the #GstPad to pause the task of
5871 * Pause the task of @pad. This function will also wait until the
5872 * function executed by the task is finished if this function is not
5873 * called from the task function.
5875 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
5879 gst_pad_pause_task (GstPad * pad)
5884 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5886 GST_DEBUG_OBJECT (pad, "pause task");
5888 GST_OBJECT_LOCK (pad);
5889 task = GST_PAD_TASK (pad);
5892 res = gst_task_set_state (task, GST_TASK_PAUSED);
5893 GST_OBJECT_UNLOCK (pad);
5895 /* wait for task function to finish, this lock is recursive so it does nothing
5896 * when the pause is called from the task itself */
5897 GST_PAD_STREAM_LOCK (pad);
5898 GST_PAD_STREAM_UNLOCK (pad);
5904 GST_DEBUG_OBJECT (pad, "pad has no task");
5905 GST_OBJECT_UNLOCK (pad);
5911 * gst_pad_stop_task:
5912 * @pad: the #GstPad to stop the task of
5914 * Stop the task of @pad. This function will also make sure that the
5915 * function executed by the task will effectively stop if not called
5916 * from the GstTaskFunction.
5918 * This function will deadlock if called from the GstTaskFunction of
5919 * the task. Use gst_task_pause() instead.
5921 * Regardless of whether the pad has a task, the stream lock is acquired and
5922 * released so as to ensure that streaming through this pad has finished.
5924 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
5927 gst_pad_stop_task (GstPad * pad)
5932 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5934 GST_DEBUG_OBJECT (pad, "stop task");
5936 GST_OBJECT_LOCK (pad);
5937 task = GST_PAD_TASK (pad);
5940 GST_PAD_TASK (pad) = NULL;
5941 res = gst_task_set_state (task, GST_TASK_STOPPED);
5942 GST_OBJECT_UNLOCK (pad);
5944 GST_PAD_STREAM_LOCK (pad);
5945 GST_PAD_STREAM_UNLOCK (pad);
5947 if (!gst_task_join (task))
5950 gst_object_unref (task);
5956 GST_DEBUG_OBJECT (pad, "no task");
5957 GST_OBJECT_UNLOCK (pad);
5959 GST_PAD_STREAM_LOCK (pad);
5960 GST_PAD_STREAM_UNLOCK (pad);
5962 /* this is not an error */
5967 /* this is bad, possibly the application tried to join the task from
5968 * the task's thread. We install the task again so that it will be stopped
5969 * again from the right thread next time hopefully. */
5970 GST_OBJECT_LOCK (pad);
5971 GST_DEBUG_OBJECT (pad, "join failed");
5972 /* we can only install this task if there was no other task */
5973 if (GST_PAD_TASK (pad) == NULL)
5974 GST_PAD_TASK (pad) = task;
5975 GST_OBJECT_UNLOCK (pad);
5982 * gst_pad_probe_info_get_event:
5983 * @info: a #GstPadProbeInfo
5985 * Returns: (transfer none): The #GstEvent from the probe
5989 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5991 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5992 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5994 return GST_PAD_PROBE_INFO_EVENT (info);
5999 * gst_pad_probe_info_get_query:
6000 * @info: a #GstPadProbeInfo
6002 * Returns: (transfer none): The #GstQuery from the probe
6006 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
6008 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
6009 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
6011 return GST_PAD_PROBE_INFO_QUERY (info);
6015 * gst_pad_probe_info_get_buffer:
6016 * @info: a #GstPadProbeInfo
6018 * Returns: (transfer none): The #GstBuffer from the probe
6022 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
6024 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
6026 return GST_PAD_PROBE_INFO_BUFFER (info);
6030 * gst_pad_probe_info_get_bufferlist:
6031 * @info: a #GstPadProbeInfo
6033 * Returns: (transfer none): The #GstBufferlist from the probe
6037 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
6039 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
6041 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
6045 * gst_pad_get_last_flow_return:
6048 * Gets the #GstFlowReturn return from the last data passed by this pad.
6053 gst_pad_get_last_flow_return (GstPad * pad)
6057 GST_OBJECT_LOCK (pad);
6058 ret = GST_PAD_LAST_FLOW_RETURN (pad);
6059 GST_OBJECT_UNLOCK (pad);