2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 * @short_description: Object contained by elements that allows links to
26 * @see_also: #GstPadTemplate, #GstElement, #GstEvent, #GstQuery, #GstBuffer
28 * A #GstElement is linked to other elements via "pads", which are extremely
29 * light-weight generic link points.
31 * Pads have a #GstPadDirection, source pads produce data, sink pads consume
34 * Pads are typically created from a #GstPadTemplate with
35 * gst_pad_new_from_template() and are then added to a #GstElement. This usually
36 * happens when the element is created but it can also happen dynamically based
37 * on the data that the element is processing or based on the pads that the
38 * application requests.
40 * Pads without pad templates can be created with gst_pad_new(),
41 * which takes a direction and a name as an argument. If the name is %NULL,
42 * then a guaranteed unique name will be assigned to it.
44 * A #GstElement creating a pad will typically use the various
45 * gst_pad_set_*_function() calls to register callbacks for events, queries or
46 * dataflow on the pads.
48 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
50 * After two pads are retrieved from an element by gst_element_get_static_pad(),
51 * the pads can be linked with gst_pad_link(). (For quick links,
52 * you can also use gst_element_link(), which will make the obvious
53 * link for you if it's straightforward.). Pads can be unlinked again with
54 * gst_pad_unlink(). gst_pad_get_peer() can be used to check what the pad is
57 * Before dataflow is possible on the pads, they need to be activated with
58 * gst_pad_set_active().
60 * gst_pad_query() and gst_pad_peer_query() can be used to query various
61 * properties of the pad and the stream.
63 * To send a #GstEvent on a pad, use gst_pad_send_event() and
64 * gst_pad_push_event(). Some events will be sticky on the pad, meaning that
65 * after they pass on the pad they can be queried later with
66 * gst_pad_get_sticky_event() and gst_pad_sticky_events_foreach().
67 * gst_pad_get_current_caps() and gst_pad_has_current_caps() are convenience
68 * functions to query the current sticky CAPS event on a pad.
70 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
71 * or pull in a buffer.
73 * The dataflow, events and queries that happen on a pad can be monitored with
74 * probes that can be installed with gst_pad_add_probe(). gst_pad_is_blocked()
75 * can be used to check if a block probe is installed on the pad.
76 * gst_pad_is_blocking() checks if the blocking probe is currently blocking the
77 * pad. gst_pad_remove_probe() is used to remove a previously installed probe
78 * and unblock blocking probes if any.
80 * Pad have an offset that can be retrieved with gst_pad_get_offset(). This
81 * offset will be applied to the running_time of all data passing over the pad.
82 * gst_pad_set_offset() can be used to change the offset.
84 * Convenience functions exist to start, pause and stop the task on a pad with
85 * gst_pad_start_task(), gst_pad_pause_task() and gst_pad_stop_task()
89 #include "gst_private.h"
92 #include "gstpadtemplate.h"
93 #include "gstenumtypes.h"
98 #include "glib-compat-private.h"
100 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
101 #define GST_CAT_DEFAULT GST_CAT_PADS
103 /* Pad signals and args */
121 #define GST_PAD_GET_PRIVATE(obj) \
122 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
124 /* we have a pending and an active event on the pad. On source pads only the
125 * active event is used. On sinkpads, events are copied to the pending entry and
126 * moved to the active event when the eventfunc returned %TRUE. */
133 struct _GstPadPrivate
140 guint probe_list_cookie;
150 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
155 GstPadProbeInfo *info;
162 static void gst_pad_dispose (GObject * object);
163 static void gst_pad_finalize (GObject * object);
164 static void gst_pad_set_property (GObject * object, guint prop_id,
165 const GValue * value, GParamSpec * pspec);
166 static void gst_pad_get_property (GObject * object, guint prop_id,
167 GValue * value, GParamSpec * pspec);
169 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
170 static gboolean gst_pad_activate_default (GstPad * pad, GstObject * parent);
171 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
172 GstObject * parent, GstBufferList * list);
174 static GstFlowReturn gst_pad_send_event_unchecked (GstPad * pad,
175 GstEvent * event, GstPadProbeType type);
176 static GstFlowReturn gst_pad_push_event_unchecked (GstPad * pad,
177 GstEvent * event, GstPadProbeType type);
179 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
181 static GParamSpec *pspec_caps = NULL;
183 /* quarks for probe signals */
184 static GQuark buffer_quark;
185 static GQuark buffer_list_quark;
186 static GQuark event_quark;
195 static GstFlowQuarks flow_quarks[] = {
196 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
197 {GST_FLOW_OK, "ok", 0},
198 {GST_FLOW_NOT_LINKED, "not-linked", 0},
199 {GST_FLOW_FLUSHING, "flushing", 0},
200 {GST_FLOW_EOS, "eos", 0},
201 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
202 {GST_FLOW_ERROR, "error", 0},
203 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
204 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
209 * @ret: a #GstFlowReturn to get the name of.
211 * Gets a string representing the given flow return.
213 * Returns: a static string with the name of the flow return.
216 gst_flow_get_name (GstFlowReturn ret)
220 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
222 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
223 if (ret == flow_quarks[i].ret)
224 return flow_quarks[i].name;
231 * @ret: a #GstFlowReturn to get the quark of.
233 * Get the unique quark for the given GstFlowReturn.
235 * Returns: the quark associated with the flow return or 0 if an
236 * invalid return was specified.
239 gst_flow_to_quark (GstFlowReturn ret)
243 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
245 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
246 if (ret == flow_quarks[i].ret)
247 return flow_quarks[i].quark;
253 * gst_pad_link_get_name:
254 * @ret: a #GstPadLinkReturn to get the name of.
256 * Gets a string representing the given pad-link return.
258 * Returns: a static string with the name of the pad-link return.
263 gst_pad_link_get_name (GstPadLinkReturn ret)
266 case GST_PAD_LINK_OK:
268 case GST_PAD_LINK_WRONG_HIERARCHY:
269 return "wrong hierarchy";
270 case GST_PAD_LINK_WAS_LINKED:
272 case GST_PAD_LINK_WRONG_DIRECTION:
273 return "wrong direction";
274 case GST_PAD_LINK_NOFORMAT:
275 return "no common format";
276 case GST_PAD_LINK_NOSCHED:
277 return "incompatible scheduling";
278 case GST_PAD_LINK_REFUSED:
281 g_return_val_if_reached ("unknown");
288 buffer_quark = g_quark_from_static_string ("buffer"); \
289 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
290 event_quark = g_quark_from_static_string ("event"); \
292 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
293 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
296 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
297 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
300 #define gst_pad_parent_class parent_class
301 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
304 gst_pad_class_init (GstPadClass * klass)
306 GObjectClass *gobject_class;
307 GstObjectClass *gstobject_class;
309 gobject_class = G_OBJECT_CLASS (klass);
310 gstobject_class = GST_OBJECT_CLASS (klass);
312 g_type_class_add_private (klass, sizeof (GstPadPrivate));
314 gobject_class->dispose = gst_pad_dispose;
315 gobject_class->finalize = gst_pad_finalize;
316 gobject_class->set_property = gst_pad_set_property;
317 gobject_class->get_property = gst_pad_get_property;
321 * @pad: the pad that emitted the signal
322 * @peer: the peer pad that has been connected
324 * Signals that a pad has been linked to the peer pad.
326 gst_pad_signals[PAD_LINKED] =
327 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
328 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
329 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
332 * @pad: the pad that emitted the signal
333 * @peer: the peer pad that has been disconnected
335 * Signals that a pad has been unlinked from the peer pad.
337 gst_pad_signals[PAD_UNLINKED] =
338 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
339 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
340 g_cclosure_marshal_generic, G_TYPE_NONE, 1, GST_TYPE_PAD);
342 pspec_caps = g_param_spec_boxed ("caps", "Caps",
343 "The capabilities of the pad", GST_TYPE_CAPS,
344 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
345 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
347 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
348 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
349 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
350 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
352 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
353 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
354 g_param_spec_object ("template", "Template",
355 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
356 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
358 gstobject_class->path_string_separator = ".";
360 /* Register common function pointer descriptions */
361 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
362 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
363 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
364 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
365 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
369 gst_pad_init (GstPad * pad)
371 pad->priv = GST_PAD_GET_PRIVATE (pad);
373 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
375 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
376 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
377 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
378 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
379 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
381 GST_PAD_SET_FLUSHING (pad);
383 g_rec_mutex_init (&pad->stream_rec_lock);
385 g_cond_init (&pad->block_cond);
387 g_hook_list_init (&pad->probes, sizeof (GstProbe));
389 pad->priv->events = g_array_sized_new (FALSE, TRUE, sizeof (PadEvent), 16);
390 pad->priv->events_cookie = 0;
391 pad->priv->last_cookie = -1;
392 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
395 /* called when setting the pad inactive. It removes all sticky events from
396 * the pad. must be called with object lock */
398 remove_events (GstPad * pad)
403 events = pad->priv->events;
406 for (i = 0; i < len; i++) {
407 PadEvent *ev = &g_array_index (events, PadEvent, i);
408 GstEvent *event = ev->event;
412 if (event && GST_EVENT_TYPE (event) == GST_EVENT_CAPS) {
413 GST_OBJECT_UNLOCK (pad);
415 GST_DEBUG_OBJECT (pad, "notify caps");
416 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
418 GST_OBJECT_LOCK (pad);
420 gst_event_unref (event);
422 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
423 g_array_set_size (events, 0);
424 pad->priv->events_cookie++;
427 /* should be called with object lock */
429 find_event_by_type (GstPad * pad, GstEventType type, guint idx)
435 events = pad->priv->events;
438 for (i = 0; i < len; i++) {
439 ev = &g_array_index (events, PadEvent, i);
440 if (ev->event == NULL)
443 if (GST_EVENT_TYPE (ev->event) == type) {
454 /* should be called with OBJECT lock */
456 find_event (GstPad * pad, GstEvent * event)
462 events = pad->priv->events;
465 for (i = 0; i < len; i++) {
466 ev = &g_array_index (events, PadEvent, i);
467 if (event == ev->event)
475 /* should be called with OBJECT lock */
477 remove_event_by_type (GstPad * pad, GstEventType type)
483 events = pad->priv->events;
488 ev = &g_array_index (events, PadEvent, i);
489 if (ev->event == NULL)
492 if (GST_EVENT_TYPE (ev->event) != type)
495 gst_event_unref (ev->event);
496 g_array_remove_index (events, i);
498 pad->priv->events_cookie++;
506 /* check all events on srcpad against those on sinkpad. All events that are not
507 * on sinkpad are marked as received=%FALSE and the PENDING_EVENTS is set on the
508 * srcpad so that the events will be sent next time */
509 /* should be called with srcpad and sinkpad LOCKS */
511 schedule_events (GstPad * srcpad, GstPad * sinkpad)
516 gboolean pending = FALSE;
518 events = srcpad->priv->events;
521 for (i = 0; i < len; i++) {
522 ev = &g_array_index (events, PadEvent, i);
523 if (ev->event == NULL)
526 if (sinkpad == NULL || !find_event (sinkpad, ev->event)) {
527 ev->received = FALSE;
532 GST_OBJECT_FLAG_SET (srcpad, GST_PAD_FLAG_PENDING_EVENTS);
535 typedef gboolean (*PadEventFunction) (GstPad * pad, PadEvent * ev,
538 /* should be called with pad LOCK */
540 events_foreach (GstPad * pad, PadEventFunction func, gpointer user_data)
547 events = pad->priv->events;
550 cookie = pad->priv->events_cookie;
554 PadEvent *ev, ev_ret;
556 ev = &g_array_index (events, PadEvent, i);
557 if (G_UNLIKELY (ev->event == NULL))
560 /* take aditional ref, func might release the lock */
561 ev_ret.event = gst_event_ref (ev->event);
562 ev_ret.received = ev->received;
564 ret = func (pad, &ev_ret, user_data);
566 /* recheck the cookie, lock might have been released and the list could have
568 if (G_UNLIKELY (cookie != pad->priv->events_cookie)) {
569 if (G_LIKELY (ev_ret.event))
570 gst_event_unref (ev_ret.event);
574 /* store the received state */
575 ev->received = ev_ret.received;
577 /* if the event changed, we need to do something */
578 if (G_UNLIKELY (ev->event != ev_ret.event)) {
579 if (G_UNLIKELY (ev_ret.event == NULL)) {
580 /* function unreffed and set the event to NULL, remove it */
581 gst_event_unref (ev->event);
582 g_array_remove_index (events, i);
584 cookie = ++pad->priv->events_cookie;
587 /* function gave a new event for us */
588 gst_event_take (&ev->event, ev_ret.event);
591 /* just unref, nothing changed */
592 gst_event_unref (ev_ret.event);
601 /* should be called with LOCK */
603 apply_pad_offset (GstPad * pad, GstEvent * event, gboolean upstream)
605 /* check if we need to adjust the segment */
606 if (pad->offset != 0) {
609 GST_DEBUG_OBJECT (pad, "apply pad offset %" GST_TIME_FORMAT,
610 GST_TIME_ARGS (pad->offset));
612 if (GST_EVENT_TYPE (event) == GST_EVENT_SEGMENT) {
615 g_assert (!upstream);
617 /* copy segment values */
618 gst_event_copy_segment (event, &segment);
619 gst_event_unref (event);
621 gst_segment_offset_running_time (&segment, segment.format, pad->offset);
622 event = gst_event_new_segment (&segment);
625 event = gst_event_make_writable (event);
626 offset = gst_event_get_running_time_offset (event);
628 offset -= pad->offset;
630 offset += pad->offset;
631 gst_event_set_running_time_offset (event, offset);
636 /* should be called with the OBJECT_LOCK */
638 get_pad_caps (GstPad * pad)
640 GstCaps *caps = NULL;
643 ev = find_event_by_type (pad, GST_EVENT_CAPS, 0);
645 gst_event_parse_caps (ev->event, &caps);
651 gst_pad_dispose (GObject * object)
653 GstPad *pad = GST_PAD_CAST (object);
656 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
658 /* unlink the peer pad */
659 if ((peer = gst_pad_get_peer (pad))) {
660 /* window for MT unsafeness, someone else could unlink here
661 * and then we call unlink with wrong pads. The unlink
662 * function would catch this and safely return failed. */
663 if (GST_PAD_IS_SRC (pad))
664 gst_pad_unlink (pad, peer);
666 gst_pad_unlink (peer, pad);
668 gst_object_unref (peer);
671 gst_pad_set_pad_template (pad, NULL);
673 GST_OBJECT_LOCK (pad);
675 GST_OBJECT_UNLOCK (pad);
677 g_hook_list_clear (&pad->probes);
679 G_OBJECT_CLASS (parent_class)->dispose (object);
683 gst_pad_finalize (GObject * object)
685 GstPad *pad = GST_PAD_CAST (object);
688 /* in case the task is still around, clean it up */
689 if ((task = GST_PAD_TASK (pad))) {
690 gst_task_join (task);
691 GST_PAD_TASK (pad) = NULL;
692 gst_object_unref (task);
695 if (pad->activatenotify)
696 pad->activatenotify (pad->activatedata);
697 if (pad->activatemodenotify)
698 pad->activatemodenotify (pad->activatemodedata);
700 pad->linknotify (pad->linkdata);
701 if (pad->unlinknotify)
702 pad->unlinknotify (pad->unlinkdata);
703 if (pad->chainnotify)
704 pad->chainnotify (pad->chaindata);
705 if (pad->chainlistnotify)
706 pad->chainlistnotify (pad->chainlistdata);
707 if (pad->getrangenotify)
708 pad->getrangenotify (pad->getrangedata);
709 if (pad->eventnotify)
710 pad->eventnotify (pad->eventdata);
711 if (pad->querynotify)
712 pad->querynotify (pad->querydata);
713 if (pad->iterintlinknotify)
714 pad->iterintlinknotify (pad->iterintlinkdata);
716 g_rec_mutex_clear (&pad->stream_rec_lock);
717 g_cond_clear (&pad->block_cond);
718 g_array_free (pad->priv->events, TRUE);
720 G_OBJECT_CLASS (parent_class)->finalize (object);
724 gst_pad_set_property (GObject * object, guint prop_id,
725 const GValue * value, GParamSpec * pspec)
727 g_return_if_fail (GST_IS_PAD (object));
730 case PAD_PROP_DIRECTION:
731 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
733 case PAD_PROP_TEMPLATE:
734 gst_pad_set_pad_template (GST_PAD_CAST (object),
735 (GstPadTemplate *) g_value_get_object (value));
738 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
744 gst_pad_get_property (GObject * object, guint prop_id,
745 GValue * value, GParamSpec * pspec)
747 g_return_if_fail (GST_IS_PAD (object));
751 GST_OBJECT_LOCK (object);
752 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
753 GST_OBJECT_UNLOCK (object);
755 case PAD_PROP_DIRECTION:
756 g_value_set_enum (value, GST_PAD_DIRECTION (object));
758 case PAD_PROP_TEMPLATE:
759 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
762 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
769 * @name: the name of the new pad.
770 * @direction: the #GstPadDirection of the pad.
772 * Creates a new pad with the given name in the given direction.
773 * If name is %NULL, a guaranteed unique name (across all pads)
775 * This function makes a copy of the name so you can safely free the name.
777 * Returns: (transfer floating): a new #GstPad, or %NULL in case of an error.
782 gst_pad_new (const gchar * name, GstPadDirection direction)
784 return g_object_new (GST_TYPE_PAD,
785 "name", name, "direction", direction, NULL);
789 * gst_pad_new_from_template:
790 * @templ: the pad template to use
791 * @name: the name of the element
793 * Creates a new pad with the given name from the given template.
794 * If name is %NULL, a guaranteed unique name (across all pads)
796 * This function makes a copy of the name so you can safely free the name.
798 * Returns: (transfer floating): a new #GstPad, or %NULL in case of an error.
801 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
803 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
805 return g_object_new (GST_TYPE_PAD,
806 "name", name, "direction", templ->direction, "template", templ, NULL);
810 * gst_pad_new_from_static_template:
811 * @templ: the #GstStaticPadTemplate to use
812 * @name: the name of the element
814 * Creates a new pad with the given name from the given static template.
815 * If name is %NULL, a guaranteed unique name (across all pads)
817 * This function makes a copy of the name so you can safely free the name.
819 * Returns: (transfer floating): a new #GstPad, or %NULL in case of an error.
822 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
826 GstPadTemplate *template;
828 template = gst_static_pad_template_get (templ);
829 pad = gst_pad_new_from_template (template, name);
830 gst_object_unref (template);
834 #define ACQUIRE_PARENT(pad, parent, label) \
836 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
837 gst_object_ref (parent); \
838 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
842 #define RELEASE_PARENT(parent) \
844 if (G_LIKELY (parent)) \
845 gst_object_unref (parent); \
849 * gst_pad_get_direction:
850 * @pad: a #GstPad to get the direction of.
852 * Gets the direction of the pad. The direction of the pad is
853 * decided at construction time so this function does not take
856 * Returns: the #GstPadDirection of the pad.
861 gst_pad_get_direction (GstPad * pad)
863 GstPadDirection result;
865 /* PAD_UNKNOWN is a little silly but we need some sort of
866 * error return value */
867 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
869 result = GST_PAD_DIRECTION (pad);
875 gst_pad_activate_default (GstPad * pad, GstObject * parent)
877 return gst_pad_activate_mode (pad, GST_PAD_MODE_PUSH, TRUE);
881 * gst_pad_mode_get_name:
882 * @mode: the pad mode
884 * Return the name of a pad mode, for use in debug messages mostly.
886 * Returns: short mnemonic for pad mode @mode
889 gst_pad_mode_get_name (GstPadMode mode)
892 case GST_PAD_MODE_NONE:
894 case GST_PAD_MODE_PUSH:
896 case GST_PAD_MODE_PULL:
905 pre_activate (GstPad * pad, GstPadMode new_mode)
908 case GST_PAD_MODE_NONE:
909 GST_OBJECT_LOCK (pad);
910 GST_DEBUG_OBJECT (pad, "setting PAD_MODE NONE, set flushing");
911 GST_PAD_SET_FLUSHING (pad);
912 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
913 GST_PAD_MODE (pad) = new_mode;
914 /* unlock blocked pads so element can resume and stop */
915 GST_PAD_BLOCK_BROADCAST (pad);
916 GST_OBJECT_UNLOCK (pad);
918 case GST_PAD_MODE_PUSH:
919 case GST_PAD_MODE_PULL:
920 GST_OBJECT_LOCK (pad);
921 GST_DEBUG_OBJECT (pad, "setting pad into %s mode, unset flushing",
922 gst_pad_mode_get_name (new_mode));
923 GST_PAD_UNSET_FLUSHING (pad);
924 pad->ABI.abi.last_flowret = GST_FLOW_OK;
925 GST_PAD_MODE (pad) = new_mode;
926 if (GST_PAD_IS_SINK (pad)) {
928 /* make sure the peer src pad sends us all events */
929 if ((peer = GST_PAD_PEER (pad))) {
930 gst_object_ref (peer);
931 GST_OBJECT_UNLOCK (pad);
933 GST_DEBUG_OBJECT (pad, "reschedule events on peer %s:%s",
934 GST_DEBUG_PAD_NAME (peer));
936 GST_OBJECT_LOCK (peer);
937 schedule_events (peer, NULL);
938 GST_OBJECT_UNLOCK (peer);
940 gst_object_unref (peer);
942 GST_OBJECT_UNLOCK (pad);
945 GST_OBJECT_UNLOCK (pad);
952 post_activate (GstPad * pad, GstPadMode new_mode)
955 case GST_PAD_MODE_NONE:
956 /* ensures that streaming stops */
957 GST_PAD_STREAM_LOCK (pad);
958 GST_DEBUG_OBJECT (pad, "stopped streaming");
959 GST_OBJECT_LOCK (pad);
961 GST_OBJECT_UNLOCK (pad);
962 GST_PAD_STREAM_UNLOCK (pad);
964 case GST_PAD_MODE_PUSH:
965 case GST_PAD_MODE_PULL:
972 * gst_pad_set_active:
973 * @pad: the #GstPad to activate or deactivate.
974 * @active: whether or not the pad should be active.
976 * Activates or deactivates the given pad.
977 * Normally called from within core state change functions.
979 * If @active, makes sure the pad is active. If it is already active, either in
980 * push or pull mode, just return. Otherwise dispatches to the pad's activate
981 * function to perform the actual activation.
983 * If not @active, calls gst_pad_activate_mode() with the pad's current mode
984 * and a %FALSE argument.
986 * Returns: %TRUE if the operation was successful.
991 gst_pad_set_active (GstPad * pad, gboolean active)
995 gboolean ret = FALSE;
997 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
999 GST_OBJECT_LOCK (pad);
1000 old = GST_PAD_MODE (pad);
1001 ACQUIRE_PARENT (pad, parent, no_parent);
1002 GST_OBJECT_UNLOCK (pad);
1005 if (old == GST_PAD_MODE_NONE) {
1006 GST_DEBUG_OBJECT (pad, "activating pad from none");
1007 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad, parent);
1009 pad->ABI.abi.last_flowret = GST_FLOW_OK;
1011 GST_DEBUG_OBJECT (pad, "pad was active in %s mode",
1012 gst_pad_mode_get_name (old));
1016 if (old == GST_PAD_MODE_NONE) {
1017 GST_DEBUG_OBJECT (pad, "pad was inactive");
1020 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1021 gst_pad_mode_get_name (old));
1022 ret = gst_pad_activate_mode (pad, old, FALSE);
1024 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
1028 RELEASE_PARENT (parent);
1030 if (G_UNLIKELY (!ret))
1038 GST_DEBUG_OBJECT (pad, "no parent");
1039 GST_OBJECT_UNLOCK (pad);
1044 GST_OBJECT_LOCK (pad);
1046 g_critical ("Failed to deactivate pad %s:%s, very bad",
1047 GST_DEBUG_PAD_NAME (pad));
1049 GST_WARNING_OBJECT (pad, "Failed to activate pad");
1051 GST_OBJECT_UNLOCK (pad);
1057 * gst_pad_activate_mode:
1058 * @pad: the #GstPad to activate or deactivate.
1059 * @mode: the requested activation mode
1060 * @active: whether or not the pad should be active.
1062 * Activates or deactivates the given pad in @mode via dispatching to the
1063 * pad's activatemodefunc. For use from within pad activation functions only.
1065 * If you don't know what this is, you probably don't want to call it.
1067 * Returns: %TRUE if the operation was successful.
1072 gst_pad_activate_mode (GstPad * pad, GstPadMode mode, gboolean active)
1074 gboolean res = FALSE;
1076 GstPadMode old, new;
1077 GstPadDirection dir;
1080 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1082 GST_OBJECT_LOCK (pad);
1083 old = GST_PAD_MODE (pad);
1084 dir = GST_PAD_DIRECTION (pad);
1085 ACQUIRE_PARENT (pad, parent, no_parent);
1086 GST_OBJECT_UNLOCK (pad);
1088 new = active ? mode : GST_PAD_MODE_NONE;
1093 if (active && old != mode && old != GST_PAD_MODE_NONE) {
1094 /* pad was activate in the wrong direction, deactivate it
1095 * and reactivate it in the requested mode */
1096 GST_DEBUG_OBJECT (pad, "deactivating pad from %s mode",
1097 gst_pad_mode_get_name (old));
1099 if (G_UNLIKELY (!gst_pad_activate_mode (pad, old, FALSE)))
1100 goto deactivate_failed;
1104 case GST_PAD_MODE_PULL:
1106 if (dir == GST_PAD_SINK) {
1107 if ((peer = gst_pad_get_peer (pad))) {
1108 GST_DEBUG_OBJECT (pad, "calling peer");
1109 if (G_UNLIKELY (!gst_pad_activate_mode (peer, mode, active)))
1111 gst_object_unref (peer);
1113 /* there is no peer, this is only fatal when we activate. When we
1114 * deactivate, we must assume the application has unlinked the peer and
1115 * will deactivate it eventually. */
1119 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
1122 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
1123 goto failure; /* Can't activate pull on a src without a
1124 getrange function */
1132 /* Mark pad as needing reconfiguration */
1134 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1135 pre_activate (pad, new);
1137 if (GST_PAD_ACTIVATEMODEFUNC (pad)) {
1138 if (G_UNLIKELY (!GST_PAD_ACTIVATEMODEFUNC (pad) (pad, parent, mode,
1142 /* can happen for sinks of passthrough elements */
1145 post_activate (pad, new);
1147 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in %s mode",
1148 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1153 /* Clear sticky flags on deactivation */
1155 GST_OBJECT_LOCK (pad);
1156 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1157 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
1158 GST_OBJECT_UNLOCK (pad);
1162 RELEASE_PARENT (parent);
1168 GST_DEBUG_OBJECT (pad, "no parent");
1169 GST_OBJECT_UNLOCK (pad);
1174 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in %s mode",
1175 active ? "activated" : "deactivated", gst_pad_mode_get_name (mode));
1180 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1181 "failed to %s in switch to %s mode from %s mode",
1182 (active ? "activate" : "deactivate"), gst_pad_mode_get_name (mode),
1183 gst_pad_mode_get_name (old));
1188 GST_OBJECT_LOCK (peer);
1189 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
1190 "activate_mode on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
1191 GST_OBJECT_UNLOCK (peer);
1192 gst_object_unref (peer);
1197 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
1198 "pad in pull mode");
1203 GST_OBJECT_LOCK (pad);
1204 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in %s mode",
1205 active ? "activate" : "deactivate", gst_pad_mode_get_name (mode));
1206 GST_PAD_SET_FLUSHING (pad);
1207 GST_PAD_MODE (pad) = old;
1208 GST_OBJECT_UNLOCK (pad);
1214 * gst_pad_is_active:
1215 * @pad: the #GstPad to query
1217 * Query if a pad is active
1219 * Returns: %TRUE if the pad is active.
1224 gst_pad_is_active (GstPad * pad)
1226 gboolean result = FALSE;
1228 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1230 GST_OBJECT_LOCK (pad);
1231 result = GST_PAD_IS_ACTIVE (pad);
1232 GST_OBJECT_UNLOCK (pad);
1238 cleanup_hook (GstPad * pad, GHook * hook)
1240 GstPadProbeType type;
1242 if (!G_HOOK_IS_VALID (hook))
1245 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1247 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1248 /* unblock when we remove the last blocking probe */
1250 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1253 /* Might have new probes now that want to be called */
1254 GST_PAD_BLOCK_BROADCAST (pad);
1256 if (pad->num_blocked == 0) {
1257 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1258 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKED);
1261 g_hook_destroy_link (&pad->probes, hook);
1266 * gst_pad_add_probe:
1267 * @pad: the #GstPad to add the probe to
1268 * @mask: the probe mask
1269 * @callback: #GstPadProbeCallback that will be called with notifications of
1271 * @user_data: (closure): user data passed to the callback
1272 * @destroy_data: #GDestroyNotify for user_data
1274 * Be notified of different states of pads. The provided callback is called for
1275 * every state that matches @mask.
1277 * Returns: an id or 0 if no probe is pending. The id can be used to remove the
1278 * probe with gst_pad_remove_probe(). When using GST_PAD_PROBE_TYPE_IDLE it can
1279 * happend that the probe can be run immediately and if the probe returns
1280 * GST_PAD_PROBE_REMOVE this functions returns 0.
1285 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1286 GstPadProbeCallback callback, gpointer user_data,
1287 GDestroyNotify destroy_data)
1292 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1293 g_return_val_if_fail (mask != 0, 0);
1295 GST_OBJECT_LOCK (pad);
1297 /* make a new probe */
1298 hook = g_hook_alloc (&pad->probes);
1300 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1303 /* when no contraints are given for the types, assume all types are
1305 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1306 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1307 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1308 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1310 /* store our flags and other fields */
1311 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1312 hook->func = callback;
1313 hook->data = user_data;
1314 hook->destroy = destroy_data;
1315 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1318 g_hook_prepend (&pad->probes, hook);
1320 /* incremenent cookie so that the new hook get's called */
1321 pad->priv->probe_list_cookie++;
1323 /* get the id of the hook, we return this and it can be used to remove the
1325 res = hook->hook_id;
1327 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1329 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1330 /* we have a block probe */
1332 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKED);
1333 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1334 "now %d blocking probes", pad->num_blocked);
1336 /* Might have new probes now that want to be called */
1337 GST_PAD_BLOCK_BROADCAST (pad);
1340 /* call the callback if we need to be called for idle callbacks */
1341 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1342 if (pad->priv->using > 0) {
1343 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1344 * flag above, the last thread to leave the push will do the callback. New
1345 * threads going into the push will block. */
1346 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1347 "pad is in use, delay idle callback");
1348 GST_OBJECT_UNLOCK (pad);
1350 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, res, };
1351 GstPadProbeReturn ret;
1353 /* Keep another ref, the callback could destroy the pad */
1354 gst_object_ref (pad);
1356 /* the pad is idle now, we can signal the idle callback now */
1357 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1358 "pad is idle, trigger idle callback");
1359 GST_OBJECT_UNLOCK (pad);
1361 ret = callback (pad, &info, user_data);
1363 GST_OBJECT_LOCK (pad);
1365 case GST_PAD_PROBE_REMOVE:
1366 /* remove the probe */
1367 GST_DEBUG_OBJECT (pad, "asked to remove hook");
1368 cleanup_hook (pad, hook);
1371 case GST_PAD_PROBE_DROP:
1372 GST_DEBUG_OBJECT (pad, "asked to drop item");
1374 case GST_PAD_PROBE_PASS:
1375 GST_DEBUG_OBJECT (pad, "asked to pass item");
1377 case GST_PAD_PROBE_OK:
1378 GST_DEBUG_OBJECT (pad, "probe returned OK");
1381 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
1384 GST_OBJECT_UNLOCK (pad);
1386 gst_object_unref (pad);
1389 GST_OBJECT_UNLOCK (pad);
1395 * gst_pad_remove_probe:
1396 * @pad: the #GstPad with the probe
1397 * @id: the probe id to remove
1399 * Remove the probe with @id from @pad.
1404 gst_pad_remove_probe (GstPad * pad, gulong id)
1408 g_return_if_fail (GST_IS_PAD (pad));
1410 GST_OBJECT_LOCK (pad);
1412 hook = g_hook_get (&pad->probes, id);
1416 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1418 cleanup_hook (pad, hook);
1419 GST_OBJECT_UNLOCK (pad);
1425 GST_OBJECT_UNLOCK (pad);
1426 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1432 * gst_pad_is_blocked:
1433 * @pad: the #GstPad to query
1435 * Checks if the pad is blocked or not. This function returns the
1436 * last requested state of the pad. It is not certain that the pad
1437 * is actually blocking at this point (see gst_pad_is_blocking()).
1439 * Returns: %TRUE if the pad is blocked.
1444 gst_pad_is_blocked (GstPad * pad)
1446 gboolean result = FALSE;
1448 g_return_val_if_fail (GST_IS_PAD (pad), result);
1450 GST_OBJECT_LOCK (pad);
1451 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLAG_BLOCKED);
1452 GST_OBJECT_UNLOCK (pad);
1458 * gst_pad_is_blocking:
1459 * @pad: the #GstPad to query
1461 * Checks if the pad is blocking or not. This is a guaranteed state
1462 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1464 * Returns: %TRUE if the pad is blocking.
1469 gst_pad_is_blocking (GstPad * pad)
1471 gboolean result = FALSE;
1473 g_return_val_if_fail (GST_IS_PAD (pad), result);
1475 GST_OBJECT_LOCK (pad);
1476 /* the blocking flag is only valid if the pad is not flushing */
1477 result = GST_PAD_IS_BLOCKING (pad) && !GST_PAD_IS_FLUSHING (pad);
1478 GST_OBJECT_UNLOCK (pad);
1484 * gst_pad_needs_reconfigure:
1485 * @pad: the #GstPad to check
1487 * Check the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1488 * if the flag was set.
1490 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag is set on @pad.
1493 gst_pad_needs_reconfigure (GstPad * pad)
1495 gboolean reconfigure;
1497 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1499 GST_OBJECT_LOCK (pad);
1500 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1501 GST_DEBUG_OBJECT (pad, "peeking RECONFIGURE flag %d", reconfigure);
1502 GST_OBJECT_UNLOCK (pad);
1508 * gst_pad_check_reconfigure:
1509 * @pad: the #GstPad to check
1511 * Check and clear the #GST_PAD_FLAG_NEED_RECONFIGURE flag on @pad and return %TRUE
1512 * if the flag was set.
1514 * Returns: %TRUE is the GST_PAD_FLAG_NEED_RECONFIGURE flag was set on @pad.
1517 gst_pad_check_reconfigure (GstPad * pad)
1519 gboolean reconfigure;
1521 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1523 GST_OBJECT_LOCK (pad);
1524 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1526 GST_DEBUG_OBJECT (pad, "remove RECONFIGURE flag");
1527 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1529 GST_OBJECT_UNLOCK (pad);
1535 * gst_pad_mark_reconfigure:
1536 * @pad: the #GstPad to mark
1538 * Mark a pad for needing reconfiguration. The next call to
1539 * gst_pad_check_reconfigure() will return %TRUE after this call.
1542 gst_pad_mark_reconfigure (GstPad * pad)
1544 g_return_if_fail (GST_IS_PAD (pad));
1546 GST_OBJECT_LOCK (pad);
1547 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
1548 GST_OBJECT_UNLOCK (pad);
1552 * gst_pad_set_activate_function:
1554 * @f: the #GstPadActivateFunction to set.
1556 * Calls gst_pad_set_activate_function_full() with %NULL for the user_data and
1560 * gst_pad_set_activate_function_full:
1562 * @activate: the #GstPadActivateFunction to set.
1563 * @user_data: user_data passed to @notify
1564 * @notify: notify called when @activate will not be used anymore.
1566 * Sets the given activate function for @pad. The activate function will
1567 * dispatch to gst_pad_activate_mode() to perform the actual activation.
1568 * Only makes sense to set on sink pads.
1570 * Call this function if your sink pad can start a pull-based task.
1573 gst_pad_set_activate_function_full (GstPad * pad,
1574 GstPadActivateFunction activate, gpointer user_data, GDestroyNotify notify)
1576 g_return_if_fail (GST_IS_PAD (pad));
1578 if (pad->activatenotify)
1579 pad->activatenotify (pad->activatedata);
1580 GST_PAD_ACTIVATEFUNC (pad) = activate;
1581 pad->activatedata = user_data;
1582 pad->activatenotify = notify;
1584 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1585 GST_DEBUG_FUNCPTR_NAME (activate));
1589 * gst_pad_set_activatemode_function:
1591 * @f: the #GstPadActivateModeFunction to set.
1593 * Calls gst_pad_set_activatemode_function_full() with %NULL for the user_data and
1597 * gst_pad_set_activatemode_function_full:
1599 * @activatemode: the #GstPadActivateModeFunction to set.
1600 * @user_data: user_data passed to @notify
1601 * @notify: notify called when @activatemode will not be used anymore.
1603 * Sets the given activate_mode function for the pad. An activate_mode function
1604 * prepares the element for data passing.
1607 gst_pad_set_activatemode_function_full (GstPad * pad,
1608 GstPadActivateModeFunction activatemode, gpointer user_data,
1609 GDestroyNotify notify)
1611 g_return_if_fail (GST_IS_PAD (pad));
1613 if (pad->activatemodenotify)
1614 pad->activatemodenotify (pad->activatemodedata);
1615 GST_PAD_ACTIVATEMODEFUNC (pad) = activatemode;
1616 pad->activatemodedata = user_data;
1617 pad->activatemodenotify = notify;
1619 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatemodefunc set to %s",
1620 GST_DEBUG_FUNCPTR_NAME (activatemode));
1624 * gst_pad_set_chain_function:
1625 * @p: a sink #GstPad.
1626 * @f: the #GstPadChainFunction to set.
1628 * Calls gst_pad_set_chain_function_full() with %NULL for the user_data and
1632 * gst_pad_set_chain_function_full:
1633 * @pad: a sink #GstPad.
1634 * @chain: the #GstPadChainFunction to set.
1635 * @user_data: user_data passed to @notify
1636 * @notify: notify called when @chain will not be used anymore.
1638 * Sets the given chain function for the pad. The chain function is called to
1639 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1642 gst_pad_set_chain_function_full (GstPad * pad, GstPadChainFunction chain,
1643 gpointer user_data, GDestroyNotify notify)
1645 g_return_if_fail (GST_IS_PAD (pad));
1646 g_return_if_fail (GST_PAD_IS_SINK (pad));
1648 if (pad->chainnotify)
1649 pad->chainnotify (pad->chaindata);
1650 GST_PAD_CHAINFUNC (pad) = chain;
1651 pad->chaindata = user_data;
1652 pad->chainnotify = notify;
1654 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1655 GST_DEBUG_FUNCPTR_NAME (chain));
1659 * gst_pad_set_chain_list_function:
1660 * @p: a sink #GstPad.
1661 * @f: the #GstPadChainListFunction to set.
1663 * Calls gst_pad_set_chain_list_function_full() with %NULL for the user_data and
1667 * gst_pad_set_chain_list_function_full:
1668 * @pad: a sink #GstPad.
1669 * @chainlist: the #GstPadChainListFunction to set.
1670 * @user_data: user_data passed to @notify
1671 * @notify: notify called when @chainlist will not be used anymore.
1673 * Sets the given chain list function for the pad. The chainlist function is
1674 * called to process a #GstBufferList input buffer list. See
1675 * #GstPadChainListFunction for more details.
1678 gst_pad_set_chain_list_function_full (GstPad * pad,
1679 GstPadChainListFunction chainlist, gpointer user_data,
1680 GDestroyNotify notify)
1682 g_return_if_fail (GST_IS_PAD (pad));
1683 g_return_if_fail (GST_PAD_IS_SINK (pad));
1685 if (pad->chainlistnotify)
1686 pad->chainlistnotify (pad->chainlistdata);
1687 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1688 pad->chainlistdata = user_data;
1689 pad->chainlistnotify = notify;
1691 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1692 GST_DEBUG_FUNCPTR_NAME (chainlist));
1696 * gst_pad_set_getrange_function:
1697 * @p: a source #GstPad.
1698 * @f: the #GstPadGetRangeFunction to set.
1700 * Calls gst_pad_set_getrange_function_full() with %NULL for the user_data and
1704 * gst_pad_set_getrange_function_full:
1705 * @pad: a source #GstPad.
1706 * @get: the #GstPadGetRangeFunction to set.
1707 * @user_data: user_data passed to @notify
1708 * @notify: notify called when @get will not be used anymore.
1710 * Sets the given getrange function for the pad. The getrange function is
1711 * called to produce a new #GstBuffer to start the processing pipeline. see
1712 * #GstPadGetRangeFunction for a description of the getrange function.
1715 gst_pad_set_getrange_function_full (GstPad * pad, GstPadGetRangeFunction get,
1716 gpointer user_data, GDestroyNotify notify)
1718 g_return_if_fail (GST_IS_PAD (pad));
1719 g_return_if_fail (GST_PAD_IS_SRC (pad));
1721 if (pad->getrangenotify)
1722 pad->getrangenotify (pad->getrangedata);
1723 GST_PAD_GETRANGEFUNC (pad) = get;
1724 pad->getrangedata = user_data;
1725 pad->getrangenotify = notify;
1727 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1728 GST_DEBUG_FUNCPTR_NAME (get));
1732 * gst_pad_set_event_function:
1733 * @p: a #GstPad of either direction.
1734 * @f: the #GstPadEventFunction to set.
1736 * Calls gst_pad_set_event_function_full() with %NULL for the user_data and
1740 * gst_pad_set_event_function_full:
1741 * @pad: a #GstPad of either direction.
1742 * @event: the #GstPadEventFunction to set.
1743 * @user_data: user_data passed to @notify
1744 * @notify: notify called when @event will not be used anymore.
1746 * Sets the given event handler for the pad.
1749 gst_pad_set_event_function_full (GstPad * pad, GstPadEventFunction event,
1750 gpointer user_data, GDestroyNotify notify)
1752 g_return_if_fail (GST_IS_PAD (pad));
1754 if (pad->eventnotify)
1755 pad->eventnotify (pad->eventdata);
1756 GST_PAD_EVENTFUNC (pad) = event;
1757 pad->eventdata = user_data;
1758 pad->eventnotify = notify;
1760 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1761 GST_DEBUG_FUNCPTR_NAME (event));
1765 * gst_pad_set_query_function:
1766 * @p: a #GstPad of either direction.
1767 * @f: the #GstPadQueryFunction to set.
1769 * Calls gst_pad_set_query_function_full() with %NULL for the user_data and
1773 * gst_pad_set_query_function_full:
1774 * @pad: a #GstPad of either direction.
1775 * @query: the #GstPadQueryFunction to set.
1776 * @user_data: user_data passed to @notify
1777 * @notify: notify called when @query will not be used anymore.
1779 * Set the given query function for the pad.
1782 gst_pad_set_query_function_full (GstPad * pad, GstPadQueryFunction query,
1783 gpointer user_data, GDestroyNotify notify)
1785 g_return_if_fail (GST_IS_PAD (pad));
1787 if (pad->querynotify)
1788 pad->querynotify (pad->querydata);
1789 GST_PAD_QUERYFUNC (pad) = query;
1790 pad->querydata = user_data;
1791 pad->querynotify = notify;
1793 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1794 GST_DEBUG_FUNCPTR_NAME (query));
1798 * gst_pad_set_iterate_internal_links_function:
1799 * @p: a #GstPad of either direction.
1800 * @f: the #GstPadIterIntLinkFunction to set.
1802 * Calls gst_pad_set_iterate_internal_links_function_full() with %NULL
1803 * for the user_data and notify.
1806 * gst_pad_set_iterate_internal_links_function_full:
1807 * @pad: a #GstPad of either direction.
1808 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1809 * @user_data: user_data passed to @notify
1810 * @notify: notify called when @iterintlink will not be used anymore.
1812 * Sets the given internal link iterator function for the pad.
1815 gst_pad_set_iterate_internal_links_function_full (GstPad * pad,
1816 GstPadIterIntLinkFunction iterintlink, gpointer user_data,
1817 GDestroyNotify notify)
1819 g_return_if_fail (GST_IS_PAD (pad));
1821 if (pad->iterintlinknotify)
1822 pad->iterintlinknotify (pad->iterintlinkdata);
1823 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1824 pad->iterintlinkdata = user_data;
1825 pad->iterintlinknotify = notify;
1827 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1828 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1832 * gst_pad_set_link_function:
1834 * @f: the #GstPadLinkFunction to set.
1836 * Calls gst_pad_set_link_function_full() with %NULL
1837 * for the user_data and notify.
1840 * gst_pad_set_link_function_full:
1842 * @link: the #GstPadLinkFunction to set.
1843 * @user_data: user_data passed to @notify
1844 * @notify: notify called when @link will not be used anymore.
1846 * Sets the given link function for the pad. It will be called when
1847 * the pad is linked with another pad.
1849 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1852 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1853 * cannot be made for some reason.
1855 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1856 * of the peer sink pad, if present.
1859 gst_pad_set_link_function_full (GstPad * pad, GstPadLinkFunction link,
1860 gpointer user_data, GDestroyNotify notify)
1862 g_return_if_fail (GST_IS_PAD (pad));
1864 if (pad->linknotify)
1865 pad->linknotify (pad->linkdata);
1866 GST_PAD_LINKFUNC (pad) = link;
1867 pad->linkdata = user_data;
1868 pad->linknotify = notify;
1870 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1871 GST_DEBUG_FUNCPTR_NAME (link));
1875 * gst_pad_set_unlink_function:
1877 * @f: the #GstPadUnlinkFunction to set.
1879 * Calls gst_pad_set_unlink_function_full() with %NULL
1880 * for the user_data and notify.
1883 * gst_pad_set_unlink_function_full:
1885 * @unlink: the #GstPadUnlinkFunction to set.
1886 * @user_data: user_data passed to @notify
1887 * @notify: notify called when @unlink will not be used anymore.
1889 * Sets the given unlink function for the pad. It will be called
1890 * when the pad is unlinked.
1893 gst_pad_set_unlink_function_full (GstPad * pad, GstPadUnlinkFunction unlink,
1894 gpointer user_data, GDestroyNotify notify)
1896 g_return_if_fail (GST_IS_PAD (pad));
1898 if (pad->unlinknotify)
1899 pad->unlinknotify (pad->unlinkdata);
1900 GST_PAD_UNLINKFUNC (pad) = unlink;
1901 pad->unlinkdata = user_data;
1902 pad->unlinknotify = notify;
1904 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1905 GST_DEBUG_FUNCPTR_NAME (unlink));
1910 * @srcpad: the source #GstPad to unlink.
1911 * @sinkpad: the sink #GstPad to unlink.
1913 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1914 * signal on both pads.
1916 * Returns: %TRUE if the pads were unlinked. This function returns %FALSE if
1917 * the pads were not linked together.
1922 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1924 gboolean result = FALSE;
1925 GstElement *parent = NULL;
1927 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1928 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1929 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1930 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1932 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1933 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1934 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1936 /* We need to notify the parent before taking any pad locks as the bin in
1937 * question might be waiting for a lock on the pad while holding its lock
1938 * that our message will try to take. */
1939 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1940 if (GST_IS_ELEMENT (parent)) {
1941 gst_element_post_message (parent,
1942 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1943 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1945 gst_object_unref (parent);
1950 GST_OBJECT_LOCK (srcpad);
1951 GST_OBJECT_LOCK (sinkpad);
1953 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1954 goto not_linked_together;
1956 if (GST_PAD_UNLINKFUNC (srcpad)) {
1957 GstObject *tmpparent;
1959 ACQUIRE_PARENT (srcpad, tmpparent, no_src_parent);
1961 GST_PAD_UNLINKFUNC (srcpad) (srcpad, tmpparent);
1962 RELEASE_PARENT (tmpparent);
1965 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1966 GstObject *tmpparent;
1968 ACQUIRE_PARENT (sinkpad, tmpparent, no_sink_parent);
1970 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad, tmpparent);
1971 RELEASE_PARENT (tmpparent);
1975 /* first clear peers */
1976 GST_PAD_PEER (srcpad) = NULL;
1977 GST_PAD_PEER (sinkpad) = NULL;
1979 GST_OBJECT_UNLOCK (sinkpad);
1980 GST_OBJECT_UNLOCK (srcpad);
1982 /* fire off a signal to each of the pads telling them
1983 * that they've been unlinked */
1984 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1985 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1987 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1988 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1993 if (parent != NULL) {
1994 gst_element_post_message (parent,
1995 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1996 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1997 gst_object_unref (parent);
2002 not_linked_together:
2004 /* we do not emit a warning in this case because unlinking cannot
2005 * be made MT safe.*/
2006 GST_OBJECT_UNLOCK (sinkpad);
2007 GST_OBJECT_UNLOCK (srcpad);
2013 * gst_pad_is_linked:
2014 * @pad: pad to check
2016 * Checks if a @pad is linked to another pad or not.
2018 * Returns: %TRUE if the pad is linked, %FALSE otherwise.
2023 gst_pad_is_linked (GstPad * pad)
2027 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2029 GST_OBJECT_LOCK (pad);
2030 result = (GST_PAD_PEER (pad) != NULL);
2031 GST_OBJECT_UNLOCK (pad);
2036 /* get the caps from both pads and see if the intersection
2039 * This function should be called with the pad LOCK on both
2043 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
2044 GstPadLinkCheck flags)
2046 GstCaps *srccaps = NULL;
2047 GstCaps *sinkcaps = NULL;
2048 gboolean compatible = FALSE;
2050 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
2053 /* Doing the expensive caps checking takes priority over only checking the template caps */
2054 if (flags & GST_PAD_LINK_CHECK_CAPS) {
2055 GST_OBJECT_UNLOCK (sink);
2056 GST_OBJECT_UNLOCK (src);
2058 srccaps = gst_pad_query_caps (src, NULL);
2059 sinkcaps = gst_pad_query_caps (sink, NULL);
2061 GST_OBJECT_LOCK (src);
2062 GST_OBJECT_LOCK (sink);
2064 /* If one of the two pads doesn't have a template, consider the intersection
2066 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
2067 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
2071 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
2073 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
2076 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
2078 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
2081 /* if we have caps on both pads we can check the intersection. If one
2082 * of the caps is %NULL, we return %TRUE. */
2083 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
2085 gst_caps_unref (srccaps);
2087 gst_caps_unref (sinkcaps);
2091 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
2092 gst_caps_unref (srccaps);
2093 gst_caps_unref (sinkcaps);
2096 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
2097 (compatible ? "" : "not "));
2102 /* check if the grandparents of both pads are the same.
2103 * This check is required so that we don't try to link
2104 * pads from elements in different bins without ghostpads.
2106 * The LOCK should be held on both pads
2109 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
2111 GstObject *psrc, *psink;
2113 psrc = GST_OBJECT_PARENT (src);
2114 psink = GST_OBJECT_PARENT (sink);
2116 /* if one of the pads has no parent, we allow the link */
2117 if (G_UNLIKELY (psrc == NULL || psink == NULL))
2120 /* only care about parents that are elements */
2121 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
2122 goto no_element_parent;
2124 /* if the parents are the same, we have a loop */
2125 if (G_UNLIKELY (psrc == psink))
2128 /* if they both have a parent, we check the grandparents. We can not lock
2129 * the parent because we hold on the child (pad) and the locking order is
2130 * parent >> child. */
2131 psrc = GST_OBJECT_PARENT (psrc);
2132 psink = GST_OBJECT_PARENT (psink);
2134 /* if they have grandparents but they are not the same */
2135 if (G_UNLIKELY (psrc != psink))
2136 goto wrong_grandparents;
2143 GST_CAT_DEBUG (GST_CAT_CAPS,
2144 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
2145 GST_PTR_FORMAT, psrc, psink);
2150 GST_CAT_DEBUG (GST_CAT_CAPS,
2151 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
2152 GST_PTR_FORMAT, psrc, psink);
2157 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
2163 GST_CAT_DEBUG (GST_CAT_CAPS,
2164 "pads have different grandparents %" GST_PTR_FORMAT " and %"
2165 GST_PTR_FORMAT, psrc, psink);
2170 /* FIXME leftover from an attempt at refactoring... */
2171 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
2172 * the two pads will be locked in the srcpad, sinkpad order. */
2173 static GstPadLinkReturn
2174 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2176 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
2177 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2179 GST_OBJECT_LOCK (srcpad);
2181 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
2182 goto src_was_linked;
2184 GST_OBJECT_LOCK (sinkpad);
2186 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
2187 goto sink_was_linked;
2189 /* check hierarchy, pads can only be linked if the grandparents
2191 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
2192 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
2193 goto wrong_hierarchy;
2195 /* check pad caps for non-empty intersection */
2196 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
2199 /* FIXME check pad scheduling for non-empty intersection */
2201 return GST_PAD_LINK_OK;
2205 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
2206 GST_DEBUG_PAD_NAME (srcpad),
2207 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
2208 /* we do not emit a warning in this case because unlinking cannot
2209 * be made MT safe.*/
2210 GST_OBJECT_UNLOCK (srcpad);
2211 return GST_PAD_LINK_WAS_LINKED;
2215 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
2216 GST_DEBUG_PAD_NAME (sinkpad),
2217 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
2218 /* we do not emit a warning in this case because unlinking cannot
2219 * be made MT safe.*/
2220 GST_OBJECT_UNLOCK (sinkpad);
2221 GST_OBJECT_UNLOCK (srcpad);
2222 return GST_PAD_LINK_WAS_LINKED;
2226 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2227 GST_OBJECT_UNLOCK (sinkpad);
2228 GST_OBJECT_UNLOCK (srcpad);
2229 return GST_PAD_LINK_WRONG_HIERARCHY;
2233 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2234 GST_OBJECT_UNLOCK (sinkpad);
2235 GST_OBJECT_UNLOCK (srcpad);
2236 return GST_PAD_LINK_NOFORMAT;
2242 * @srcpad: the source #GstPad.
2243 * @sinkpad: the sink #GstPad.
2245 * Checks if the source pad and the sink pad are compatible so they can be
2248 * Returns: %TRUE if the pads can be linked.
2251 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2253 GstPadLinkReturn result;
2255 /* generic checks */
2256 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2257 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2259 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2260 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2262 /* gst_pad_link_prepare does everything for us, we only release the locks
2263 * on the pads that it gets us. If this function returns !OK the locks are not
2265 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2266 if (result != GST_PAD_LINK_OK)
2269 GST_OBJECT_UNLOCK (srcpad);
2270 GST_OBJECT_UNLOCK (sinkpad);
2273 return result == GST_PAD_LINK_OK;
2277 * gst_pad_link_full:
2278 * @srcpad: the source #GstPad to link.
2279 * @sinkpad: the sink #GstPad to link.
2280 * @flags: the checks to validate when linking
2282 * Links the source pad and the sink pad.
2284 * This variant of #gst_pad_link provides a more granular control on the
2285 * checks being done when linking. While providing some considerable speedups
2286 * the caller of this method must be aware that wrong usage of those flags
2287 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2288 * for more information.
2292 * Returns: A result code indicating if the connection worked or
2296 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2298 GstPadLinkReturn result;
2300 GstPadLinkFunction srcfunc, sinkfunc;
2302 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2303 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2304 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2305 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2306 GST_PAD_LINK_WRONG_DIRECTION);
2308 /* Notify the parent early. See gst_pad_unlink for details. */
2309 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2310 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2311 gst_element_post_message (parent,
2312 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2313 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2315 gst_object_unref (parent);
2320 /* prepare will also lock the two pads */
2321 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2323 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2326 /* must set peers before calling the link function */
2327 GST_PAD_PEER (srcpad) = sinkpad;
2328 GST_PAD_PEER (sinkpad) = srcpad;
2330 /* check events, when something is different, mark pending */
2331 schedule_events (srcpad, sinkpad);
2333 /* get the link functions */
2334 srcfunc = GST_PAD_LINKFUNC (srcpad);
2335 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2337 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2338 /* custom link functions, execute them */
2339 GST_OBJECT_UNLOCK (sinkpad);
2340 GST_OBJECT_UNLOCK (srcpad);
2343 GstObject *tmpparent;
2345 ACQUIRE_PARENT (srcpad, tmpparent, no_parent);
2346 /* this one will call the peer link function */
2347 result = srcfunc (srcpad, tmpparent, sinkpad);
2348 RELEASE_PARENT (tmpparent);
2349 } else if (sinkfunc) {
2350 GstObject *tmpparent;
2352 ACQUIRE_PARENT (sinkpad, tmpparent, no_parent);
2353 /* if no source link function, we need to call the sink link
2354 * function ourselves. */
2355 result = sinkfunc (sinkpad, tmpparent, srcpad);
2356 RELEASE_PARENT (tmpparent);
2360 GST_OBJECT_LOCK (srcpad);
2361 GST_OBJECT_LOCK (sinkpad);
2363 /* we released the lock, check if the same pads are linked still */
2364 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2365 goto concurrent_link;
2367 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2370 GST_OBJECT_UNLOCK (sinkpad);
2371 GST_OBJECT_UNLOCK (srcpad);
2373 /* fire off a signal to each of the pads telling them
2374 * that they've been linked */
2375 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2376 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2378 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2379 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2381 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2384 if (G_LIKELY (parent)) {
2385 gst_element_post_message (parent,
2386 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2387 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2388 gst_object_unref (parent);
2396 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2397 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2398 GST_OBJECT_UNLOCK (sinkpad);
2399 GST_OBJECT_UNLOCK (srcpad);
2401 /* The other link operation succeeded first */
2402 result = GST_PAD_LINK_WAS_LINKED;
2407 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed: %s",
2408 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2409 gst_pad_link_get_name (result));
2411 GST_PAD_PEER (srcpad) = NULL;
2412 GST_PAD_PEER (sinkpad) = NULL;
2414 GST_OBJECT_UNLOCK (sinkpad);
2415 GST_OBJECT_UNLOCK (srcpad);
2423 * @srcpad: the source #GstPad to link.
2424 * @sinkpad: the sink #GstPad to link.
2426 * Links the source pad and the sink pad.
2428 * Returns: A result code indicating if the connection worked or
2434 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2436 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2440 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2442 GstPadTemplate **template_p;
2444 /* this function would need checks if it weren't static */
2446 GST_OBJECT_LOCK (pad);
2447 template_p = &pad->padtemplate;
2448 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2449 GST_OBJECT_UNLOCK (pad);
2452 gst_pad_template_pad_created (templ, pad);
2456 * gst_pad_get_pad_template:
2459 * Gets the template for @pad.
2461 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2462 * instantiated, or %NULL if this pad has no template. Unref after
2466 gst_pad_get_pad_template (GstPad * pad)
2468 GstPadTemplate *templ;
2470 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2472 templ = GST_PAD_PAD_TEMPLATE (pad);
2474 return (templ ? gst_object_ref (templ) : NULL);
2478 * gst_pad_has_current_caps:
2479 * @pad: a #GstPad to check
2481 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2483 * Returns: %TRUE when @pad has caps associated with it.
2486 gst_pad_has_current_caps (GstPad * pad)
2491 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2493 GST_OBJECT_LOCK (pad);
2494 caps = get_pad_caps (pad);
2495 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2496 "check current pad caps %" GST_PTR_FORMAT, caps);
2497 result = (caps != NULL);
2498 GST_OBJECT_UNLOCK (pad);
2504 * gst_pad_get_current_caps:
2505 * @pad: a #GstPad to get the current capabilities of.
2507 * Gets the capabilities currently configured on @pad with the last
2508 * #GST_EVENT_CAPS event.
2510 * Returns: the current caps of the pad with incremented ref-count.
2513 gst_pad_get_current_caps (GstPad * pad)
2517 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2519 GST_OBJECT_LOCK (pad);
2520 if ((result = get_pad_caps (pad)))
2521 gst_caps_ref (result);
2522 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2523 "get current pad caps %" GST_PTR_FORMAT, result);
2524 GST_OBJECT_UNLOCK (pad);
2530 * gst_pad_get_pad_template_caps:
2531 * @pad: a #GstPad to get the template capabilities from.
2533 * Gets the capabilities for @pad's template.
2535 * Returns: (transfer full): the #GstCaps of this pad template.
2536 * Unref after usage.
2539 gst_pad_get_pad_template_caps (GstPad * pad)
2541 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2543 if (GST_PAD_PAD_TEMPLATE (pad))
2544 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2546 return gst_caps_ref (GST_CAPS_ANY);
2551 * @pad: a #GstPad to get the peer of.
2553 * Gets the peer of @pad. This function refs the peer pad so
2554 * you need to unref it after use.
2556 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2561 gst_pad_get_peer (GstPad * pad)
2565 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2567 GST_OBJECT_LOCK (pad);
2568 result = GST_PAD_PEER (pad);
2570 gst_object_ref (result);
2571 GST_OBJECT_UNLOCK (pad);
2577 * gst_pad_get_allowed_caps:
2580 * Gets the capabilities of the allowed media types that can flow through
2581 * @pad and its peer.
2583 * The allowed capabilities is calculated as the intersection of the results of
2584 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2585 * on the resulting caps.
2587 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2588 * caps when you no longer need it. This function returns %NULL when @pad
2594 gst_pad_get_allowed_caps (GstPad * pad)
2600 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2602 GST_OBJECT_LOCK (pad);
2603 peer = GST_PAD_PEER (pad);
2604 if (G_UNLIKELY (peer == NULL))
2607 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2609 gst_object_ref (peer);
2610 GST_OBJECT_UNLOCK (pad);
2611 mycaps = gst_pad_query_caps (pad, NULL);
2613 caps = gst_pad_query_caps (peer, mycaps);
2614 gst_object_unref (peer);
2616 gst_caps_unref (mycaps);
2618 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2625 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2626 GST_OBJECT_UNLOCK (pad);
2633 * gst_pad_iterate_internal_links_default:
2634 * @pad: the #GstPad to get the internal links of.
2635 * @parent: (allow-none): the parent of @pad or %NULL
2637 * Iterate the list of pads to which the given pad is linked to inside of
2638 * the parent element.
2639 * This is the default handler, and thus returns an iterator of all of the
2640 * pads inside the parent element with opposite direction.
2642 * The caller must free this iterator after use with gst_iterator_free().
2644 * Returns: a #GstIterator of #GstPad, or %NULL if @pad has no parent. Unref each
2645 * returned pad with gst_object_unref().
2648 gst_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
2655 GstElement *eparent;
2657 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2659 if (parent != NULL && GST_IS_ELEMENT (parent)) {
2660 eparent = GST_ELEMENT_CAST (gst_object_ref (parent));
2662 GST_OBJECT_LOCK (pad);
2663 eparent = GST_PAD_PARENT (pad);
2664 if (!eparent || !GST_IS_ELEMENT (eparent))
2667 gst_object_ref (eparent);
2668 GST_OBJECT_UNLOCK (pad);
2671 if (pad->direction == GST_PAD_SRC)
2672 padlist = &eparent->sinkpads;
2674 padlist = &eparent->srcpads;
2676 GST_DEBUG_OBJECT (pad, "Making iterator");
2678 cookie = &eparent->pads_cookie;
2680 lock = GST_OBJECT_GET_LOCK (eparent);
2682 res = gst_iterator_new_list (GST_TYPE_PAD,
2683 lock, cookie, padlist, (GObject *) owner, NULL);
2685 gst_object_unref (owner);
2692 GST_OBJECT_UNLOCK (pad);
2693 GST_DEBUG_OBJECT (pad, "no parent element");
2699 * gst_pad_iterate_internal_links:
2700 * @pad: the GstPad to get the internal links of.
2702 * Gets an iterator for the pads to which the given pad is linked to inside
2703 * of the parent element.
2705 * Each #GstPad element yielded by the iterator will have its refcount increased,
2706 * so unref after use.
2708 * Free-function: gst_iterator_free
2710 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2711 * pad does not have an iterator function configured. Use
2712 * gst_iterator_free() after usage.
2715 gst_pad_iterate_internal_links (GstPad * pad)
2717 GstIterator *res = NULL;
2720 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2722 GST_OBJECT_LOCK (pad);
2723 ACQUIRE_PARENT (pad, parent, no_parent);
2724 GST_OBJECT_UNLOCK (pad);
2726 if (GST_PAD_ITERINTLINKFUNC (pad))
2727 res = GST_PAD_ITERINTLINKFUNC (pad) (pad, parent);
2729 RELEASE_PARENT (parent);
2736 GST_DEBUG_OBJECT (pad, "no parent");
2737 GST_OBJECT_UNLOCK (pad);
2745 * @forward: (scope call): a #GstPadForwardFunction
2746 * @user_data: user data passed to @forward
2748 * Calls @forward for all internally linked pads of @pad. This function deals with
2749 * dynamically changing internal pads and will make sure that the @forward
2750 * function is only called once for each pad.
2752 * When @forward returns %TRUE, no further pads will be processed.
2754 * Returns: %TRUE if one of the dispatcher functions returned %TRUE.
2757 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2760 gboolean result = FALSE;
2762 gboolean done = FALSE;
2763 GValue item = { 0, };
2764 GList *pushed_pads = NULL;
2766 iter = gst_pad_iterate_internal_links (pad);
2772 switch (gst_iterator_next (iter, &item)) {
2773 case GST_ITERATOR_OK:
2777 intpad = g_value_get_object (&item);
2779 /* if already pushed, skip. FIXME, find something faster to tag pads */
2780 if (intpad == NULL || g_list_find (pushed_pads, intpad)) {
2781 g_value_reset (&item);
2785 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2786 GST_DEBUG_PAD_NAME (intpad));
2787 done = result = forward (intpad, user_data);
2789 pushed_pads = g_list_prepend (pushed_pads, intpad);
2791 g_value_reset (&item);
2794 case GST_ITERATOR_RESYNC:
2795 /* We don't reset the result here because we don't push the event
2796 * again on pads that got the event already and because we need
2797 * to consider the result of the previous pushes */
2798 gst_iterator_resync (iter);
2800 case GST_ITERATOR_ERROR:
2801 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2804 case GST_ITERATOR_DONE:
2809 g_value_unset (&item);
2810 gst_iterator_free (iter);
2812 g_list_free (pushed_pads);
2822 gboolean dispatched;
2826 event_forward_func (GstPad * pad, EventData * data)
2828 /* for each pad we send to, we should ref the event; it's up
2829 * to downstream to unref again when handled. */
2830 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2831 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2833 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2835 data->dispatched = TRUE;
2842 * gst_pad_event_default:
2843 * @pad: a #GstPad to call the default event handler on.
2844 * @parent: (allow-none): the parent of @pad or %NULL
2845 * @event: (transfer full): the #GstEvent to handle.
2847 * Invokes the default event handler for the given pad.
2849 * The EOS event will pause the task associated with @pad before it is forwarded
2850 * to all internally linked pads,
2852 * The the event is sent to all pads internally linked to @pad. This function
2853 * takes ownership of @event.
2855 * Returns: %TRUE if the event was sent successfully.
2858 gst_pad_event_default (GstPad * pad, GstObject * parent, GstEvent * event)
2860 gboolean result, forward = TRUE;
2862 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2863 g_return_val_if_fail (event != NULL, FALSE);
2865 GST_LOG_OBJECT (pad, "default event handler for event %" GST_PTR_FORMAT,
2868 switch (GST_EVENT_TYPE (event)) {
2869 case GST_EVENT_CAPS:
2870 forward = GST_PAD_IS_PROXY_CAPS (pad);
2881 data.dispatched = FALSE;
2882 data.result = FALSE;
2884 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2886 /* for sinkpads without a parent element or without internal links, nothing
2887 * will be dispatched but we still want to return TRUE. */
2888 if (data.dispatched)
2889 result = data.result;
2894 gst_event_unref (event);
2899 /* Default accept caps implementation just checks against
2900 * the allowed caps for the pad */
2902 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2904 /* get the caps and see if it intersects to something not empty */
2905 GstCaps *caps, *allowed;
2908 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2910 /* first forward the query to internally linked pads when we are dealing with
2912 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2913 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2918 GST_CAT_DEBUG_OBJECT (GST_CAT_PERFORMANCE, pad,
2919 "fallback ACCEPT_CAPS query, consider implementing a specialized version");
2921 gst_query_parse_accept_caps (query, &caps);
2922 allowed = gst_pad_query_caps (pad, caps);
2925 if (GST_PAD_IS_ACCEPT_INTERSECT (pad)) {
2926 GST_DEBUG_OBJECT (pad,
2927 "allowed caps intersect %" GST_PTR_FORMAT ", caps %" GST_PTR_FORMAT,
2929 result = gst_caps_can_intersect (caps, allowed);
2931 GST_DEBUG_OBJECT (pad, "allowed caps subset %" GST_PTR_FORMAT ", caps %"
2932 GST_PTR_FORMAT, allowed, caps);
2933 result = gst_caps_is_subset (caps, allowed);
2935 gst_caps_unref (allowed);
2937 GST_DEBUG_OBJECT (pad, "no compatible caps allowed on the pad");
2940 gst_query_set_accept_caps_result (query, result);
2946 /* Default caps implementation */
2948 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2950 GstCaps *result = NULL, *filter;
2951 GstPadTemplate *templ;
2952 gboolean fixed_caps;
2954 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "query caps %" GST_PTR_FORMAT,
2957 /* first try to proxy if we must */
2958 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2959 if ((gst_pad_proxy_query_caps (pad, query))) {
2964 gst_query_parse_caps (query, &filter);
2966 /* no proxy or it failed, do default handling */
2967 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2969 GST_OBJECT_LOCK (pad);
2971 /* fixed caps, try the negotiated caps first */
2972 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2973 if ((result = get_pad_caps (pad)))
2974 goto filter_done_unlock;
2977 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2978 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2979 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2980 goto filter_done_unlock;
2984 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2985 "non-fixed pad caps: trying pad caps");
2986 /* non fixed caps, try the negotiated caps */
2987 if ((result = get_pad_caps (pad)))
2988 goto filter_done_unlock;
2991 /* this almost never happens */
2992 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2993 result = GST_CAPS_ANY;
2996 GST_OBJECT_UNLOCK (pad);
2998 /* run the filter on the result */
3000 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3001 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
3002 GST_PTR_FORMAT, result, result, filter, filter);
3003 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
3004 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
3007 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
3008 "using caps %p %" GST_PTR_FORMAT, result, result);
3009 result = gst_caps_ref (result);
3011 gst_query_set_caps_result (query, result);
3012 gst_caps_unref (result);
3022 gboolean dispatched;
3026 query_forward_func (GstPad * pad, QueryData * data)
3028 GST_LOG_OBJECT (pad, "query peer %p (%s) of %s:%s",
3029 data->query, GST_QUERY_TYPE_NAME (data->query), GST_DEBUG_PAD_NAME (pad));
3031 data->result |= gst_pad_peer_query (pad, data->query);
3033 data->dispatched = TRUE;
3035 /* stop on first successful reply */
3036 return data->result;
3040 * gst_pad_query_default:
3041 * @pad: a #GstPad to call the default query handler on.
3042 * @parent: (allow-none): the parent of @pad or %NULL
3043 * @query: (transfer none): the #GstQuery to handle.
3045 * Invokes the default query handler for the given pad.
3046 * The query is sent to all pads internally linked to @pad. Note that
3047 * if there are many possible sink pads that are internally linked to
3048 * @pad, only one will be sent the query.
3049 * Multi-sinkpad elements should implement custom query handlers.
3051 * Returns: %TRUE if the query was performed successfully.
3054 gst_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
3056 gboolean forward, ret = FALSE;
3058 switch (GST_QUERY_TYPE (query)) {
3059 case GST_QUERY_SCHEDULING:
3060 forward = GST_PAD_IS_PROXY_SCHEDULING (pad);
3062 case GST_QUERY_ALLOCATION:
3063 forward = GST_PAD_IS_PROXY_ALLOCATION (pad);
3065 case GST_QUERY_ACCEPT_CAPS:
3066 ret = gst_pad_query_accept_caps_default (pad, query);
3069 case GST_QUERY_CAPS:
3070 ret = gst_pad_query_caps_default (pad, query);
3073 case GST_QUERY_POSITION:
3074 case GST_QUERY_SEEKING:
3075 case GST_QUERY_FORMATS:
3076 case GST_QUERY_LATENCY:
3077 case GST_QUERY_JITTER:
3078 case GST_QUERY_RATE:
3079 case GST_QUERY_CONVERT:
3085 GST_DEBUG_OBJECT (pad, "%sforwarding %p (%s) query", (forward ? "" : "not "),
3086 query, GST_QUERY_TYPE_NAME (query));
3092 data.dispatched = FALSE;
3093 data.result = FALSE;
3095 gst_pad_forward (pad, (GstPadForwardFunction) query_forward_func, &data);
3097 if (data.dispatched) {
3100 /* nothing dispatched, assume drained */
3101 if (GST_QUERY_TYPE (query) == GST_QUERY_DRAIN)
3111 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3113 GstPad *pad = data->pad;
3114 GstPadProbeInfo *info = data->info;
3115 GstPadProbeType type, flags;
3116 GstPadProbeCallback callback;
3117 GstPadProbeReturn ret;
3119 /* if we have called this callback, do nothing */
3120 if (PROBE_COOKIE (hook) == data->cookie) {
3121 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3122 "hook %lu, cookie %u already called", hook->hook_id,
3123 PROBE_COOKIE (hook));
3127 PROBE_COOKIE (hook) = data->cookie;
3129 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3132 /* one of the data types for non-idle probes */
3133 if ((type & GST_PAD_PROBE_TYPE_IDLE) == 0
3134 && (flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3136 /* one of the scheduling types */
3137 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3139 /* one of the blocking types must match */
3140 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) &&
3141 (flags & GST_PAD_PROBE_TYPE_BLOCKING & type) == 0)
3143 if ((type & GST_PAD_PROBE_TYPE_BLOCKING) == 0 &&
3144 (flags & GST_PAD_PROBE_TYPE_BLOCKING))
3146 /* only probes that have GST_PAD_PROBE_TYPE_EVENT_FLUSH set */
3147 if ((type & GST_PAD_PROBE_TYPE_EVENT_FLUSH) &&
3148 (flags & GST_PAD_PROBE_TYPE_EVENT_FLUSH & type) == 0)
3151 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3152 "hook %lu, cookie %u with flags 0x%08x matches", hook->hook_id,
3153 PROBE_COOKIE (hook), flags);
3155 data->marshalled = TRUE;
3157 callback = (GstPadProbeCallback) hook->func;
3158 if (callback == NULL)
3161 info->id = hook->hook_id;
3163 GST_OBJECT_UNLOCK (pad);
3165 ret = callback (pad, info, hook->data);
3167 GST_OBJECT_LOCK (pad);
3170 case GST_PAD_PROBE_REMOVE:
3171 /* remove the probe */
3172 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3173 cleanup_hook (pad, hook);
3175 case GST_PAD_PROBE_DROP:
3176 /* need to drop the data, make sure other probes don't get called
3178 GST_DEBUG_OBJECT (pad, "asked to drop item");
3179 info->type = GST_PAD_PROBE_TYPE_INVALID;
3180 data->dropped = TRUE;
3182 case GST_PAD_PROBE_PASS:
3183 /* inform the pad block to let things pass */
3184 GST_DEBUG_OBJECT (pad, "asked to pass item");
3187 case GST_PAD_PROBE_OK:
3188 GST_DEBUG_OBJECT (pad, "probe returned OK");
3191 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3198 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3199 "hook %lu, cookie %u with flags 0x%08x does not match %08x",
3200 hook->hook_id, PROBE_COOKIE (hook), flags, info->type);
3205 /* a probe that does not take or return any data */
3206 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3208 if (G_UNLIKELY (pad->num_probes)) { \
3209 /* pass NULL as the data item */ \
3210 GstPadProbeInfo info = { mask, 0, NULL, 0, 0 }; \
3211 ret = do_probe_callbacks (pad, &info, defaultval); \
3212 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3217 #define PROBE_FULL(pad,mask,data,offs,size,label) \
3219 if (G_UNLIKELY (pad->num_probes)) { \
3220 /* pass the data item */ \
3221 GstPadProbeInfo info = { mask, 0, data, offs, size }; \
3222 ret = do_probe_callbacks (pad, &info, GST_FLOW_OK); \
3223 /* store the possibly updated data item */ \
3224 data = GST_PAD_PROBE_INFO_DATA (&info); \
3225 /* if something went wrong, exit */ \
3226 if (G_UNLIKELY (ret != GST_FLOW_OK)) \
3231 #define PROBE_PUSH(pad,mask,data,label) \
3232 PROBE_FULL(pad, mask, data, -1, -1, label);
3233 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3234 PROBE_FULL(pad, mask, data, offs, size, label);
3236 static GstFlowReturn
3237 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3238 GstFlowReturn defaultval)
3247 data.marshalled = FALSE;
3248 data.dropped = FALSE;
3249 data.cookie = ++pad->priv->probe_cookie;
3252 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3255 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3256 "do probes cookie %u", data.cookie);
3257 cookie = pad->priv->probe_list_cookie;
3259 g_hook_list_marshal (&pad->probes, TRUE,
3260 (GHookMarshaller) probe_hook_marshal, &data);
3262 /* if the list changed, call the new callbacks (they will not have their
3263 * cookie set to data.cookie */
3264 if (cookie != pad->priv->probe_list_cookie) {
3265 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3266 "probe list changed, restarting");
3270 /* the first item that dropped will stop the hooks and then we drop here */
3274 /* if no handler matched and we are blocking, let the item pass */
3275 if (!data.marshalled && is_block)
3278 /* At this point, all handlers returned either OK or PASS. If one handler
3279 * returned PASS, let the item pass */
3284 while (GST_PAD_IS_BLOCKED (pad)) {
3285 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3286 "we are blocked %d times", pad->num_blocked);
3288 /* we might have released the lock */
3289 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3292 /* now we block the streaming thread. It can be unlocked when we
3293 * deactivate the pad (which will also set the FLUSHING flag) or
3294 * when the pad is unblocked. A flushing event will also unblock
3295 * the pad after setting the FLUSHING flag. */
3296 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3297 "Waiting to be unblocked or set flushing");
3298 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_BLOCKING);
3299 GST_PAD_BLOCK_WAIT (pad);
3300 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_BLOCKING);
3301 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3303 /* if the list changed, call the new callbacks (they will not have their
3304 * cookie set to data.cookie */
3305 if (cookie != pad->priv->probe_list_cookie) {
3306 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3307 "probe list changed, restarting");
3311 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3321 GST_DEBUG_OBJECT (pad, "pad is flushing");
3322 return GST_FLOW_FLUSHING;
3326 GST_DEBUG_OBJECT (pad, "data is dropped");
3327 return GST_FLOW_CUSTOM_SUCCESS;
3331 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3332 GST_DEBUG_OBJECT (pad, "data is passed");
3340 * gst_pad_get_offset:
3343 * Get the offset applied to the running time of @pad. @pad has to be a source
3346 * Returns: the offset.
3349 gst_pad_get_offset (GstPad * pad)
3353 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3355 GST_OBJECT_LOCK (pad);
3356 result = pad->offset;
3357 GST_OBJECT_UNLOCK (pad);
3363 mark_event_not_received (GstPad * pad, PadEvent * ev, gpointer user_data)
3365 ev->received = FALSE;
3370 * gst_pad_set_offset:
3372 * @offset: the offset
3374 * Set the offset that will be applied to the running time of @pad.
3377 gst_pad_set_offset (GstPad * pad, gint64 offset)
3379 g_return_if_fail (GST_IS_PAD (pad));
3381 GST_OBJECT_LOCK (pad);
3382 /* if nothing changed, do nothing */
3383 if (pad->offset == offset)
3386 pad->offset = offset;
3387 GST_DEBUG_OBJECT (pad, "changed offset to %" G_GINT64_FORMAT, offset);
3389 /* resend all sticky events with updated offset on next buffer push */
3390 events_foreach (pad, mark_event_not_received, NULL);
3391 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3394 GST_OBJECT_UNLOCK (pad);
3401 /* If TRUE and ret is not OK this means
3402 * that pushing the EOS event failed
3406 /* If called for an event this is
3407 * the event that would be pushed
3408 * next. Don't forward sticky events
3409 * that would come after that */
3413 /* should be called with pad LOCK */
3415 push_sticky (GstPad * pad, PadEvent * ev, gpointer user_data)
3417 PushStickyData *data = user_data;
3418 GstEvent *event = ev->event;
3421 GST_DEBUG_OBJECT (pad, "event %s was already received",
3422 GST_EVENT_TYPE_NAME (event));
3426 /* If we're called because of an sticky event, only forward
3427 * events that would come before this new event and the
3429 if (data->event && GST_EVENT_IS_STICKY (data->event) &&
3430 GST_EVENT_TYPE (data->event) <= GST_EVENT_SEGMENT &&
3431 GST_EVENT_TYPE (data->event) < GST_EVENT_TYPE (event)) {
3432 data->ret = GST_FLOW_CUSTOM_SUCCESS_1;
3434 data->ret = gst_pad_push_event_unchecked (pad, gst_event_ref (event),
3435 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3438 switch (data->ret) {
3440 ev->received = TRUE;
3441 GST_DEBUG_OBJECT (pad, "event %s marked received",
3442 GST_EVENT_TYPE_NAME (event));
3444 case GST_FLOW_CUSTOM_SUCCESS:
3445 /* we can't assume the event is received when it was dropped */
3446 GST_DEBUG_OBJECT (pad, "event %s was dropped, mark pending",
3447 GST_EVENT_TYPE_NAME (event));
3448 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3449 data->ret = GST_FLOW_OK;
3451 case GST_FLOW_CUSTOM_SUCCESS_1:
3452 /* event was ignored and should be sent later */
3453 GST_DEBUG_OBJECT (pad, "event %s was ignored, mark pending",
3454 GST_EVENT_TYPE_NAME (event));
3455 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3456 data->ret = GST_FLOW_OK;
3458 case GST_FLOW_NOT_LINKED:
3459 /* not linked is not a problem, we are sticky so the event will be
3460 * sent later but only for non-EOS events */
3461 GST_DEBUG_OBJECT (pad, "pad was not linked, mark pending");
3462 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
3463 data->ret = GST_FLOW_OK;
3464 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3467 GST_DEBUG_OBJECT (pad, "result %s, mark pending events",
3468 gst_flow_get_name (data->ret));
3469 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3473 if (data->ret != GST_FLOW_OK && GST_EVENT_TYPE (event) == GST_EVENT_EOS)
3474 data->was_eos = TRUE;
3476 return data->ret == GST_FLOW_OK;
3479 /* check sticky events and push them when needed. should be called
3481 static inline GstFlowReturn
3482 check_sticky (GstPad * pad, GstEvent * event)
3484 PushStickyData data = { GST_FLOW_OK, FALSE, event };
3486 if (G_UNLIKELY (GST_PAD_HAS_PENDING_EVENTS (pad))) {
3487 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
3489 GST_DEBUG_OBJECT (pad, "pushing all sticky events");
3490 events_foreach (pad, push_sticky, &data);
3492 /* If there's an EOS event we must push it downstream
3493 * even if sending a previous sticky event failed.
3494 * Otherwise the pipeline might wait forever for EOS.
3496 * Only do this if pushing another event than the EOS
3499 if (data.ret != GST_FLOW_OK && !data.was_eos) {
3500 PadEvent *ev = find_event_by_type (pad, GST_EVENT_EOS, 0);
3502 if (ev && !ev->received) {
3503 data.ret = gst_pad_push_event_unchecked (pad, gst_event_ref (ev->event),
3504 GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM);
3505 /* the event could have been dropped. Because this can only
3506 * happen if the user asked for it, it's not an error */
3507 if (data.ret == GST_FLOW_CUSTOM_SUCCESS)
3508 data.ret = GST_FLOW_OK;
3518 * @pad: a #GstPad to invoke the default query on.
3519 * @query: (transfer none): the #GstQuery to perform.
3521 * Dispatches a query to a pad. The query should have been allocated by the
3522 * caller via one of the type-specific allocation functions. The element that
3523 * the pad belongs to is responsible for filling the query with an appropriate
3524 * response, which should then be parsed with a type-specific query parsing
3527 * Again, the caller is responsible for both the allocation and deallocation of
3528 * the query structure.
3530 * Please also note that some queries might need a running pipeline to work.
3532 * Returns: %TRUE if the query could be performed.
3535 gst_pad_query (GstPad * pad, GstQuery * query)
3538 gboolean res, serialized;
3539 GstPadQueryFunction func;
3540 GstPadProbeType type;
3543 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3544 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3546 if (GST_PAD_IS_SRC (pad)) {
3547 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3548 goto wrong_direction;
3549 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3550 } else if (GST_PAD_IS_SINK (pad)) {
3551 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3552 goto wrong_direction;
3553 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3555 goto unknown_direction;
3557 GST_DEBUG_OBJECT (pad, "doing query %p (%s)", query,
3558 GST_QUERY_TYPE_NAME (query));
3560 serialized = GST_QUERY_IS_SERIALIZED (query);
3561 if (G_UNLIKELY (serialized))
3562 GST_PAD_STREAM_LOCK (pad);
3564 GST_OBJECT_LOCK (pad);
3565 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3566 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3567 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3569 ACQUIRE_PARENT (pad, parent, no_parent);
3570 GST_OBJECT_UNLOCK (pad);
3572 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3575 res = func (pad, parent, query);
3577 RELEASE_PARENT (parent);
3579 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3580 GST_QUERY_TYPE_NAME (query), res);
3585 GST_OBJECT_LOCK (pad);
3586 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3587 GST_OBJECT_UNLOCK (pad);
3589 if (G_UNLIKELY (serialized))
3590 GST_PAD_STREAM_UNLOCK (pad);
3597 g_warning ("pad %s:%s query %s in wrong direction",
3598 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3603 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3608 GST_DEBUG_OBJECT (pad, "had no parent");
3609 GST_OBJECT_UNLOCK (pad);
3610 if (G_UNLIKELY (serialized))
3611 GST_PAD_STREAM_UNLOCK (pad);
3616 GST_DEBUG_OBJECT (pad, "had no query function");
3617 RELEASE_PARENT (parent);
3618 if (G_UNLIKELY (serialized))
3619 GST_PAD_STREAM_UNLOCK (pad);
3624 GST_DEBUG_OBJECT (pad, "query failed");
3625 if (G_UNLIKELY (serialized))
3626 GST_PAD_STREAM_UNLOCK (pad);
3631 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3632 GST_OBJECT_UNLOCK (pad);
3633 if (G_UNLIKELY (serialized))
3634 GST_PAD_STREAM_UNLOCK (pad);
3636 /* if a probe dropped, we don't sent it further but assume that the probe
3637 * answered the query and return TRUE */
3638 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3648 * gst_pad_peer_query:
3649 * @pad: a #GstPad to invoke the peer query on.
3650 * @query: (transfer none): the #GstQuery to perform.
3652 * Performs gst_pad_query() on the peer of @pad.
3654 * The caller is responsible for both the allocation and deallocation of
3655 * the query structure.
3657 * Returns: %TRUE if the query could be performed. This function returns %FALSE
3658 * if @pad has no peer.
3661 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3664 GstPadProbeType type;
3665 gboolean res, serialized;
3668 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3669 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3671 if (GST_PAD_IS_SRC (pad)) {
3672 if (G_UNLIKELY (!GST_QUERY_IS_DOWNSTREAM (query)))
3673 goto wrong_direction;
3674 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3675 } else if (GST_PAD_IS_SINK (pad)) {
3676 if (G_UNLIKELY (!GST_QUERY_IS_UPSTREAM (query)))
3677 goto wrong_direction;
3678 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3680 goto unknown_direction;
3682 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3683 GST_QUERY_TYPE_NAME (query));
3685 serialized = GST_QUERY_IS_SERIALIZED (query);
3687 GST_OBJECT_LOCK (pad);
3688 if (GST_PAD_IS_SRC (pad) && serialized) {
3689 /* all serialized queries on the srcpad trigger push of
3691 if (check_sticky (pad, NULL) != GST_FLOW_OK)
3695 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3696 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3697 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3699 peerpad = GST_PAD_PEER (pad);
3700 if (G_UNLIKELY (peerpad == NULL))
3703 gst_object_ref (peerpad);
3704 GST_OBJECT_UNLOCK (pad);
3706 res = gst_pad_query (peerpad, query);
3708 gst_object_unref (peerpad);
3713 GST_OBJECT_LOCK (pad);
3714 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3715 GST_OBJECT_UNLOCK (pad);
3722 g_warning ("pad %s:%s query %s in wrong direction",
3723 GST_DEBUG_PAD_NAME (pad), GST_QUERY_TYPE_NAME (query));
3728 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
3733 GST_WARNING_OBJECT (pad, "could not send sticky events");
3734 GST_OBJECT_UNLOCK (pad);
3739 GST_INFO_OBJECT (pad, "pad has no peer");
3740 GST_OBJECT_UNLOCK (pad);
3745 GST_DEBUG_OBJECT (pad, "query failed");
3750 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3751 GST_OBJECT_UNLOCK (pad);
3753 /* if a probe dropped, we don't sent it further but assume that the probe
3754 * answered the query and return TRUE */
3755 if (ret == GST_FLOW_CUSTOM_SUCCESS)
3764 /**********************************************************************
3765 * Data passing functions
3768 /* this is the chain function that does not perform the additional argument
3769 * checking for that little extra speed.
3771 static inline GstFlowReturn
3772 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3777 GST_PAD_STREAM_LOCK (pad);
3779 GST_OBJECT_LOCK (pad);
3780 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3783 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
3786 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
3789 #ifndef G_DISABLE_ASSERT
3790 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
3791 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
3793 ":%s:<%s:%s> Got data flow before stream-start event",
3794 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3796 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
3798 ":%s:<%s:%s> Got data flow before segment event",
3799 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
3801 pad->priv->last_cookie = pad->priv->events_cookie;
3805 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3807 PROBE_PUSH (pad, type, data, probe_stopped);
3809 parent = GST_OBJECT_PARENT (pad);
3810 GST_OBJECT_UNLOCK (pad);
3812 /* NOTE: we read the chainfunc unlocked.
3813 * we cannot hold the lock for the pad so we might send
3814 * the data to the wrong function. This is not really a
3815 * problem since functions are assigned at creation time
3816 * and don't change that often... */
3817 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3818 GstPadChainFunction chainfunc;
3820 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3823 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3824 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3825 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3827 ret = chainfunc (pad, parent, GST_BUFFER_CAST (data));
3829 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3830 "called chainfunction &%s with buffer %p, returned %s",
3831 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3833 GstPadChainListFunction chainlistfunc;
3835 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3838 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3839 "calling chainlistfunction &%s",
3840 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3842 ret = chainlistfunc (pad, parent, GST_BUFFER_LIST_CAST (data));
3844 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3845 "called chainlistfunction &%s, returned %s",
3846 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3849 GST_PAD_STREAM_UNLOCK (pad);
3856 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3857 "chaining, but pad was flushing");
3858 GST_OBJECT_UNLOCK (pad);
3859 GST_PAD_STREAM_UNLOCK (pad);
3860 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3861 return GST_FLOW_FLUSHING;
3865 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "chaining, but pad was EOS");
3866 GST_OBJECT_UNLOCK (pad);
3867 GST_PAD_STREAM_UNLOCK (pad);
3868 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3869 return GST_FLOW_EOS;
3873 g_critical ("chain on pad %s:%s but it was not in push mode",
3874 GST_DEBUG_PAD_NAME (pad));
3875 GST_OBJECT_UNLOCK (pad);
3876 GST_PAD_STREAM_UNLOCK (pad);
3877 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3878 return GST_FLOW_ERROR;
3882 GST_OBJECT_UNLOCK (pad);
3883 GST_PAD_STREAM_UNLOCK (pad);
3884 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3887 case GST_FLOW_CUSTOM_SUCCESS:
3888 GST_DEBUG_OBJECT (pad, "dropped buffer");
3892 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
3899 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3900 g_critical ("chain on pad %s:%s but it has no chainfunction",
3901 GST_DEBUG_PAD_NAME (pad));
3902 GST_PAD_STREAM_UNLOCK (pad);
3903 return GST_FLOW_NOT_SUPPORTED;
3909 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3910 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3913 * Chain a buffer to @pad.
3915 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3917 * If the buffer type is not acceptable for @pad (as negotiated with a
3918 * preceding GST_EVENT_CAPS event), this function returns
3919 * #GST_FLOW_NOT_NEGOTIATED.
3921 * The function proceeds calling the chain function installed on @pad (see
3922 * gst_pad_set_chain_function()) and the return value of that function is
3923 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3926 * In all cases, success or failure, the caller loses its reference to @buffer
3927 * after calling this function.
3929 * Returns: a #GstFlowReturn from the pad.
3934 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3936 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3937 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3938 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3940 return gst_pad_chain_data_unchecked (pad,
3941 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3944 static GstFlowReturn
3945 gst_pad_chain_list_default (GstPad * pad, GstObject * parent,
3946 GstBufferList * list)
3952 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3954 len = gst_buffer_list_length (list);
3957 for (i = 0; i < len; i++) {
3958 buffer = gst_buffer_list_get (list, i);
3960 gst_pad_chain_data_unchecked (pad,
3961 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3962 gst_buffer_ref (buffer));
3963 if (ret != GST_FLOW_OK)
3966 gst_buffer_list_unref (list);
3972 * gst_pad_chain_list:
3973 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3974 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3977 * Chain a bufferlist to @pad.
3979 * The function returns #GST_FLOW_FLUSHING if the pad was flushing.
3981 * If @pad was not negotiated properly with a CAPS event, this function
3982 * returns #GST_FLOW_NOT_NEGOTIATED.
3984 * The function proceeds calling the chainlist function installed on @pad (see
3985 * gst_pad_set_chain_list_function()) and the return value of that function is
3986 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3987 * chainlist function.
3989 * In all cases, success or failure, the caller loses its reference to @list
3990 * after calling this function.
3994 * Returns: a #GstFlowReturn from the pad.
3997 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3999 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4000 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4001 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4003 return gst_pad_chain_data_unchecked (pad,
4004 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4007 static GstFlowReturn
4008 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
4013 GST_OBJECT_LOCK (pad);
4014 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4017 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4020 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PUSH))
4023 #ifndef G_DISABLE_ASSERT
4024 if (G_UNLIKELY (pad->priv->last_cookie != pad->priv->events_cookie)) {
4025 if (!find_event_by_type (pad, GST_EVENT_STREAM_START, 0)) {
4027 ":%s:<%s:%s> Got data flow before stream-start event",
4028 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4030 if (!find_event_by_type (pad, GST_EVENT_SEGMENT, 0)) {
4032 ":%s:<%s:%s> Got data flow before segment event",
4033 G_STRFUNC, GST_DEBUG_PAD_NAME (pad));
4035 pad->priv->last_cookie = pad->priv->events_cookie;
4039 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4042 /* do block probes */
4043 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
4045 /* recheck sticky events because the probe might have cause a relink */
4046 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4049 /* do post-blocking probes */
4050 PROBE_PUSH (pad, type, data, probe_stopped);
4052 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4055 /* take ref to peer pad before releasing the lock */
4056 gst_object_ref (peer);
4058 GST_OBJECT_UNLOCK (pad);
4060 ret = gst_pad_chain_data_unchecked (peer, type, data);
4062 gst_object_unref (peer);
4064 GST_OBJECT_LOCK (pad);
4065 pad->ABI.abi.last_flowret = ret;
4067 if (pad->priv->using == 0) {
4068 /* pad is not active anymore, trigger idle callbacks */
4069 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4070 probe_stopped, ret);
4072 GST_OBJECT_UNLOCK (pad);
4076 /* ERROR recovery here */
4080 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4081 "pushing, but pad was flushing");
4082 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4083 GST_OBJECT_UNLOCK (pad);
4084 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4085 return GST_FLOW_FLUSHING;
4089 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing, but pad was EOS");
4090 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4091 GST_OBJECT_UNLOCK (pad);
4092 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4093 return GST_FLOW_EOS;
4097 g_critical ("pushing on pad %s:%s but it was not activated in push mode",
4098 GST_DEBUG_PAD_NAME (pad));
4099 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4100 GST_OBJECT_UNLOCK (pad);
4101 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4102 return GST_FLOW_ERROR;
4106 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4107 "error pushing events, return %s", gst_flow_get_name (ret));
4108 pad->ABI.abi.last_flowret = ret;
4109 GST_OBJECT_UNLOCK (pad);
4110 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4115 GST_OBJECT_UNLOCK (pad);
4116 pad->ABI.abi.last_flowret =
4117 ret == GST_FLOW_CUSTOM_SUCCESS ? GST_FLOW_OK : ret;
4118 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4121 case GST_FLOW_CUSTOM_SUCCESS:
4122 GST_DEBUG_OBJECT (pad, "dropped buffer");
4126 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4133 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4134 "pushing, but it was not linked");
4135 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4136 GST_OBJECT_UNLOCK (pad);
4137 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
4138 return GST_FLOW_NOT_LINKED;
4144 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4145 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
4148 * Pushes a buffer to the peer of @pad.
4150 * This function will call installed block probes before triggering any
4151 * installed data probes.
4153 * The function proceeds calling gst_pad_chain() on the peer pad and returns
4154 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4157 * In all cases, success or failure, the caller loses its reference to @buffer
4158 * after calling this function.
4160 * Returns: a #GstFlowReturn from the peer pad.
4165 gst_pad_push (GstPad * pad, GstBuffer * buffer)
4167 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4168 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4169 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
4171 return gst_pad_push_data (pad,
4172 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
4176 * gst_pad_push_list:
4177 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
4178 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
4181 * Pushes a buffer list to the peer of @pad.
4183 * This function will call installed block probes before triggering any
4184 * installed data probes.
4186 * The function proceeds calling the chain function on the peer pad and returns
4187 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
4188 * be returned. If the peer pad does not have any installed chainlist function
4189 * every group buffer of the list will be merged into a normal #GstBuffer and
4190 * chained via gst_pad_chain().
4192 * In all cases, success or failure, the caller loses its reference to @list
4193 * after calling this function.
4195 * Returns: a #GstFlowReturn from the peer pad.
4200 gst_pad_push_list (GstPad * pad, GstBufferList * list)
4202 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4203 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4204 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
4206 return gst_pad_push_data (pad,
4207 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
4210 static GstFlowReturn
4211 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
4212 GstBuffer ** buffer)
4215 GstPadGetRangeFunction getrangefunc;
4219 GST_PAD_STREAM_LOCK (pad);
4221 GST_OBJECT_LOCK (pad);
4222 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4225 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4228 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4233 /* when one of the probes returns DROPPED, probe_stopped will be called
4234 * and we skip calling the getrange function, res_buf should then contain a
4235 * valid result buffer */
4236 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4237 res_buf, offset, size, probe_stopped);
4239 /* recheck sticky events because the probe might have cause a relink */
4240 if (G_UNLIKELY ((ret = check_sticky (pad, NULL))) != GST_FLOW_OK)
4243 ACQUIRE_PARENT (pad, parent, no_parent);
4244 GST_OBJECT_UNLOCK (pad);
4246 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
4249 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4250 "calling getrangefunc %s, offset %"
4251 G_GUINT64_FORMAT ", size %u",
4252 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
4254 ret = getrangefunc (pad, parent, offset, size, &res_buf);
4256 RELEASE_PARENT (parent);
4258 GST_OBJECT_LOCK (pad);
4259 if (G_UNLIKELY (ret != GST_FLOW_OK))
4260 goto get_range_failed;
4262 /* can only fire the signal if we have a valid buffer */
4264 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4265 res_buf, offset, size, probe_stopped_unref);
4266 pad->ABI.abi.last_flowret = ret;
4267 GST_OBJECT_UNLOCK (pad);
4269 GST_PAD_STREAM_UNLOCK (pad);
4278 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4279 "getrange, but pad was flushing");
4280 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4281 GST_OBJECT_UNLOCK (pad);
4282 GST_PAD_STREAM_UNLOCK (pad);
4283 return GST_FLOW_FLUSHING;
4287 g_critical ("getrange on pad %s:%s but it was not activated in pull mode",
4288 GST_DEBUG_PAD_NAME (pad));
4289 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4290 GST_OBJECT_UNLOCK (pad);
4291 GST_PAD_STREAM_UNLOCK (pad);
4292 return GST_FLOW_ERROR;
4296 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "error pushing events");
4297 pad->ABI.abi.last_flowret = ret;
4298 GST_OBJECT_UNLOCK (pad);
4299 GST_PAD_STREAM_UNLOCK (pad);
4304 GST_DEBUG_OBJECT (pad, "no parent");
4305 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4306 GST_OBJECT_UNLOCK (pad);
4307 GST_PAD_STREAM_UNLOCK (pad);
4308 return GST_FLOW_FLUSHING;
4312 g_critical ("getrange on pad %s:%s but it has no getrangefunction",
4313 GST_DEBUG_PAD_NAME (pad));
4314 RELEASE_PARENT (parent);
4315 GST_PAD_STREAM_UNLOCK (pad);
4316 return GST_FLOW_NOT_SUPPORTED;
4320 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4321 "probe returned %s", gst_flow_get_name (ret));
4322 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4324 /* the probe filled the buffer and asks us to not call the getrange
4325 * anymore, we continue with the post probes then. */
4326 GST_DEBUG_OBJECT (pad, "handled buffer");
4330 /* no buffer, we are EOS */
4331 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4335 pad->ABI.abi.last_flowret = ret;
4336 GST_OBJECT_UNLOCK (pad);
4337 GST_PAD_STREAM_UNLOCK (pad);
4341 probe_stopped_unref:
4343 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4344 "probe returned %s", gst_flow_get_name (ret));
4345 /* if we drop here, it signals EOS */
4346 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4348 pad->ABI.abi.last_flowret = ret;
4349 GST_OBJECT_UNLOCK (pad);
4350 GST_PAD_STREAM_UNLOCK (pad);
4351 if (*buffer == NULL)
4352 gst_buffer_unref (res_buf);
4357 pad->ABI.abi.last_flowret = ret;
4358 GST_OBJECT_UNLOCK (pad);
4359 GST_PAD_STREAM_UNLOCK (pad);
4360 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4361 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4362 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4368 * gst_pad_get_range:
4369 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4370 * @offset: The start offset of the buffer
4371 * @size: The length of the buffer
4372 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4373 * returns #GST_FLOW_ERROR if %NULL.
4375 * When @pad is flushing this function returns #GST_FLOW_FLUSHING
4376 * immediately and @buffer is %NULL.
4378 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4379 * description of a getrange function. If @pad has no getrange function
4380 * installed (see gst_pad_set_getrange_function()) this function returns
4381 * #GST_FLOW_NOT_SUPPORTED.
4383 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4384 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4385 * must be freed with gst_buffer_unref() after usage.
4387 * When @buffer points to a variable that points to a valid #GstBuffer, the
4388 * buffer will be filled with the result data when this function returns
4389 * #GST_FLOW_OK. If the provided buffer is larger than @size, only
4390 * @size bytes will be filled in the result buffer and its size will be updated
4393 * Note that less than @size bytes can be returned in @buffer when, for example,
4394 * an EOS condition is near or when @buffer is not large enough to hold @size
4395 * bytes. The caller should check the result buffer size to get the result size.
4397 * When this function returns any other result value than #GST_FLOW_OK, @buffer
4398 * will be unchanged.
4400 * This is a lowlevel function. Usually gst_pad_pull_range() is used.
4402 * Returns: a #GstFlowReturn from the pad.
4407 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4408 GstBuffer ** buffer)
4410 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4411 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4412 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4413 g_return_val_if_fail (*buffer == NULL
4414 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4416 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4420 * gst_pad_pull_range:
4421 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4422 * @offset: The start offset of the buffer
4423 * @size: The length of the buffer
4424 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4425 * GST_FLOW_ERROR if %NULL.
4427 * Pulls a @buffer from the peer pad or fills up a provided buffer.
4429 * This function will first trigger the pad block signal if it was
4432 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4433 * function returns the result of gst_pad_get_range() on the peer pad.
4434 * See gst_pad_get_range() for a list of return values and for the
4435 * semantics of the arguments of this function.
4437 * If @buffer points to a variable holding %NULL, a valid new #GstBuffer will be
4438 * placed in @buffer when this function returns #GST_FLOW_OK. The new buffer
4439 * must be freed with gst_buffer_unref() after usage. When this function
4440 * returns any other result value, @buffer will still point to %NULL.
4442 * When @buffer points to a variable that points to a valid #GstBuffer, the
4443 * buffer will be filled with the result data when this function returns
4444 * #GST_FLOW_OK. When this function returns any other result value,
4445 * @buffer will be unchanged. If the provided buffer is larger than @size, only
4446 * @size bytes will be filled in the result buffer and its size will be updated
4449 * Note that less than @size bytes can be returned in @buffer when, for example,
4450 * an EOS condition is near or when @buffer is not large enough to hold @size
4451 * bytes. The caller should check the result buffer size to get the result size.
4453 * Returns: a #GstFlowReturn from the peer pad.
4458 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4459 GstBuffer ** buffer)
4465 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4466 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4467 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4468 g_return_val_if_fail (*buffer == NULL
4469 || GST_IS_BUFFER (*buffer), GST_FLOW_ERROR);
4471 GST_OBJECT_LOCK (pad);
4472 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4475 if (G_UNLIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_PULL))
4480 /* when one of the probes returns DROPPED, probe_stopped will be
4481 * called and we skip calling the peer getrange function. *buffer should then
4482 * contain a valid buffer */
4483 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4484 res_buf, offset, size, probe_stopped);
4486 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4489 gst_object_ref (peer);
4491 GST_OBJECT_UNLOCK (pad);
4493 ret = gst_pad_get_range_unchecked (peer, offset, size, &res_buf);
4495 gst_object_unref (peer);
4497 GST_OBJECT_LOCK (pad);
4499 pad->ABI.abi.last_flowret = ret;
4500 if (pad->priv->using == 0) {
4501 /* pad is not active anymore, trigger idle callbacks */
4502 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4503 probe_stopped_unref, ret);
4506 if (G_UNLIKELY (ret != GST_FLOW_OK))
4507 goto pull_range_failed;
4510 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4511 res_buf, offset, size, probe_stopped_unref);
4513 GST_OBJECT_UNLOCK (pad);
4519 /* ERROR recovery here */
4522 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4523 "pullrange, but pad was flushing");
4524 pad->ABI.abi.last_flowret = GST_FLOW_FLUSHING;
4525 GST_OBJECT_UNLOCK (pad);
4526 return GST_FLOW_FLUSHING;
4530 g_critical ("pullrange on pad %s:%s but it was not activated in pull mode",
4531 GST_DEBUG_PAD_NAME (pad));
4532 pad->ABI.abi.last_flowret = GST_FLOW_ERROR;
4533 GST_OBJECT_UNLOCK (pad);
4534 return GST_FLOW_ERROR;
4538 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4539 gst_flow_get_name (ret));
4540 if (ret == GST_FLOW_CUSTOM_SUCCESS) {
4542 /* the probe filled the buffer and asks us to not forward to the peer
4543 * anymore, we continue with the post probes then */
4544 GST_DEBUG_OBJECT (pad, "handled buffer");
4548 /* no buffer, we are EOS then */
4549 GST_DEBUG_OBJECT (pad, "no buffer, return EOS");
4553 pad->ABI.abi.last_flowret = ret;
4554 GST_OBJECT_UNLOCK (pad);
4559 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4560 "pulling range, but it was not linked");
4561 pad->ABI.abi.last_flowret = GST_FLOW_NOT_LINKED;
4562 GST_OBJECT_UNLOCK (pad);
4563 return GST_FLOW_NOT_LINKED;
4567 pad->ABI.abi.last_flowret = ret;
4568 GST_OBJECT_UNLOCK (pad);
4569 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4570 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4571 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4574 probe_stopped_unref:
4576 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4577 "post probe returned %s", gst_flow_get_name (ret));
4579 /* if we drop here, it signals EOS */
4580 if (ret == GST_FLOW_CUSTOM_SUCCESS)
4583 pad->ABI.abi.last_flowret = ret;
4584 GST_OBJECT_UNLOCK (pad);
4586 if (*buffer == NULL)
4587 gst_buffer_unref (res_buf);
4592 /* must be called with pad object lock */
4593 static GstFlowReturn
4594 store_sticky_event (GstPad * pad, GstEvent * event)
4599 gboolean res = FALSE;
4600 const gchar *name = NULL;
4601 gboolean insert = TRUE;
4603 type = GST_EVENT_TYPE (event);
4605 /* Store all sticky events except SEGMENT/EOS when we're flushing,
4606 * otherwise they can be dropped and nothing would ever resend them.
4607 * Only do that for activated pads though, everything else is a bug!
4609 if (G_UNLIKELY (GST_PAD_MODE (pad) == GST_PAD_MODE_NONE
4610 || (GST_PAD_IS_FLUSHING (pad) && (type == GST_EVENT_SEGMENT
4611 || type == GST_EVENT_EOS))))
4614 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
4617 if (type & GST_EVENT_TYPE_STICKY_MULTI)
4618 name = gst_structure_get_name (gst_event_get_structure (event));
4620 events = pad->priv->events;
4623 for (i = 0; i < len; i++) {
4624 PadEvent *ev = &g_array_index (events, PadEvent, i);
4626 if (ev->event == NULL)
4629 if (type == GST_EVENT_TYPE (ev->event)) {
4630 /* matching types, check matching name if needed */
4631 if (name && !gst_event_has_name (ev->event, name))
4635 if ((res = gst_event_replace (&ev->event, event)))
4636 ev->received = FALSE;
4642 if (type < GST_EVENT_TYPE (ev->event) || (type != GST_EVENT_TYPE (ev->event)
4643 && GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS)) {
4644 /* STREAM_START, CAPS and SEGMENT must be delivered in this order. By
4645 * storing the sticky ordered we can check that this is respected. */
4646 if (G_UNLIKELY (GST_EVENT_TYPE (ev->event) <= GST_EVENT_SEGMENT
4647 || GST_EVENT_TYPE (ev->event) == GST_EVENT_EOS))
4649 ":%s:<%s:%s> Sticky event misordering, got '%s' before '%s'",
4650 G_STRFUNC, GST_DEBUG_PAD_NAME (pad),
4651 gst_event_type_get_name (GST_EVENT_TYPE (ev->event)),
4652 gst_event_type_get_name (type));
4658 ev.event = gst_event_ref (event);
4659 ev.received = FALSE;
4660 g_array_insert_val (events, i, ev);
4665 pad->priv->events_cookie++;
4666 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4668 GST_LOG_OBJECT (pad, "stored sticky event %s", GST_EVENT_TYPE_NAME (event));
4670 switch (GST_EVENT_TYPE (event)) {
4671 case GST_EVENT_CAPS:
4672 GST_OBJECT_UNLOCK (pad);
4674 GST_DEBUG_OBJECT (pad, "notify caps");
4675 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4677 GST_OBJECT_LOCK (pad);
4683 if (type == GST_EVENT_EOS) {
4684 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_EOS);
4685 pad->ABI.abi.last_flowret = GST_FLOW_EOS;
4688 return GST_PAD_IS_FLUSHING (pad) ? GST_FLOW_FLUSHING : GST_FLOW_OK;
4693 GST_DEBUG_OBJECT (pad, "pad is flushing");
4694 return GST_FLOW_FLUSHING;
4698 GST_DEBUG_OBJECT (pad, "pad is EOS");
4699 return GST_FLOW_EOS;
4704 * gst_pad_store_sticky_event:
4706 * @event: a #GstEvent
4708 * Store the sticky @event on @pad
4710 * Returns: #GST_FLOW_OK on success, #GST_FLOW_FLUSHING when the pad
4711 * was flushing or #GST_FLOW_EOS when the pad was EOS.
4716 gst_pad_store_sticky_event (GstPad * pad, GstEvent * event)
4720 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4721 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4723 GST_OBJECT_LOCK (pad);
4724 ret = store_sticky_event (pad, event);
4725 GST_OBJECT_UNLOCK (pad);
4731 sticky_changed (GstPad * pad, PadEvent * ev, gpointer user_data)
4733 PushStickyData *data = user_data;
4735 /* Forward all sticky events before our current one that are pending */
4736 if (ev->event != data->event
4737 && GST_EVENT_TYPE (ev->event) < GST_EVENT_TYPE (data->event))
4738 return push_sticky (pad, ev, data);
4743 /* should be called with pad LOCK */
4744 static GstFlowReturn
4745 gst_pad_push_event_unchecked (GstPad * pad, GstEvent * event,
4746 GstPadProbeType type)
4750 GstEventType event_type;
4752 /* pass the adjusted event on. We need to do this even if
4753 * there is no peer pad because of the probes. */
4754 event = apply_pad_offset (pad, event, GST_PAD_IS_SINK (pad));
4756 /* Two checks to be made:
4757 * . (un)set the FLUSHING flag for flushing events,
4758 * . handle pad blocking */
4759 event_type = GST_EVENT_TYPE (event);
4760 switch (event_type) {
4761 case GST_EVENT_FLUSH_START:
4762 GST_PAD_SET_FLUSHING (pad);
4764 GST_PAD_BLOCK_BROADCAST (pad);
4765 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4767 case GST_EVENT_FLUSH_STOP:
4768 GST_PAD_UNSET_FLUSHING (pad);
4770 /* Remove sticky EOS events */
4771 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4772 remove_event_by_type (pad, GST_EVENT_EOS);
4773 remove_event_by_type (pad, GST_EVENT_SEGMENT);
4774 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
4775 pad->ABI.abi.last_flowret = GST_FLOW_OK;
4777 type |= GST_PAD_PROBE_TYPE_EVENT_FLUSH;
4781 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4784 /* No need to check for EOS here as either the caller (gst_pad_push_event())
4785 * checked already or this is called as part of pushing sticky events,
4786 * in which case we still want to forward the EOS event downstream.
4789 switch (GST_EVENT_TYPE (event)) {
4790 case GST_EVENT_RECONFIGURE:
4791 if (GST_PAD_IS_SINK (pad))
4792 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
4797 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4798 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4803 /* send probes after modifying the events above */
4804 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4806 /* recheck sticky events because the probe might have cause a relink */
4807 if (GST_PAD_HAS_PENDING_EVENTS (pad) && GST_PAD_IS_SRC (pad)
4808 && (GST_EVENT_IS_SERIALIZED (event)
4809 || GST_EVENT_IS_STICKY (event))) {
4810 PushStickyData data = { GST_FLOW_OK, FALSE, event };
4811 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4813 /* Push all sticky events before our current one
4814 * that have changed */
4815 events_foreach (pad, sticky_changed, &data);
4818 /* now check the peer pad */
4819 peerpad = GST_PAD_PEER (pad);
4820 if (peerpad == NULL)
4823 gst_object_ref (peerpad);
4825 GST_OBJECT_UNLOCK (pad);
4827 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4828 event, gst_event_type_get_name (event_type), peerpad);
4830 ret = gst_pad_send_event_unchecked (peerpad, event, type);
4832 /* Note: we gave away ownership of the event at this point but we can still
4833 * print the old pointer */
4834 GST_LOG_OBJECT (pad,
4835 "sent event %p to (%s) peerpad %" GST_PTR_FORMAT ", ret %s", event,
4836 gst_event_type_get_name (event_type), peerpad, gst_flow_get_name (ret));
4838 gst_object_unref (peerpad);
4840 GST_OBJECT_LOCK (pad);
4842 if (pad->priv->using == 0) {
4843 /* pad is not active anymore, trigger idle callbacks */
4844 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4845 idle_probe_stopped, ret);
4849 /* ERROR handling */
4852 GST_DEBUG_OBJECT (pad, "We're flushing");
4853 gst_event_unref (event);
4854 return GST_FLOW_FLUSHING;
4858 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4859 gst_event_unref (event);
4862 case GST_FLOW_CUSTOM_SUCCESS:
4863 GST_DEBUG_OBJECT (pad, "dropped event");
4866 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
4873 GST_DEBUG_OBJECT (pad, "Dropping event %s because pad is not linked",
4874 gst_event_type_get_name (GST_EVENT_TYPE (event)));
4875 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_PENDING_EVENTS);
4876 gst_event_unref (event);
4878 /* unlinked pads should not influence latency configuration */
4879 if (event_type == GST_EVENT_LATENCY)
4882 return GST_FLOW_NOT_LINKED;
4886 GST_DEBUG_OBJECT (pad, "Idle probe returned %s", gst_flow_get_name (ret));
4892 * gst_pad_push_event:
4893 * @pad: a #GstPad to push the event to.
4894 * @event: (transfer full): the #GstEvent to send to the pad.
4896 * Sends the event to the peer of the given pad. This function is
4897 * mainly used by elements to send events to their peer
4900 * This function takes ownership of the provided event so you should
4901 * gst_event_ref() it if you want to reuse the event after this call.
4903 * Returns: %TRUE if the event was handled.
4908 gst_pad_push_event (GstPad * pad, GstEvent * event)
4910 gboolean res = FALSE;
4911 GstPadProbeType type;
4912 gboolean sticky, serialized;
4914 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4915 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4917 if (GST_PAD_IS_SRC (pad)) {
4918 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4919 goto wrong_direction;
4920 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4921 } else if (GST_PAD_IS_SINK (pad)) {
4922 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4923 goto wrong_direction;
4924 /* events pushed on sinkpad never are sticky */
4925 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4927 goto unknown_direction;
4929 GST_OBJECT_LOCK (pad);
4930 sticky = GST_EVENT_IS_STICKY (event);
4931 serialized = GST_EVENT_IS_SERIALIZED (event);
4934 /* srcpad sticky events are stored immediately, the received flag is set
4935 * to FALSE and will be set to TRUE when we can successfully push the
4936 * event to the peer pad */
4937 switch (store_sticky_event (pad, event)) {
4938 case GST_FLOW_FLUSHING:
4946 if (GST_PAD_IS_SRC (pad) && (serialized || sticky)) {
4947 /* all serialized or sticky events on the srcpad trigger push of
4949 res = (check_sticky (pad, event) == GST_FLOW_OK);
4954 /* other events are pushed right away */
4955 ret = gst_pad_push_event_unchecked (pad, event, type);
4956 /* dropped events by a probe are not an error */
4957 res = (ret == GST_FLOW_OK || ret == GST_FLOW_CUSTOM_SUCCESS);
4959 /* Errors in sticky event pushing are no problem and ignored here
4960 * as they will cause more meaningful errors during data flow.
4961 * For EOS events, that are not followed by data flow, we still
4962 * return FALSE here though.
4964 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
4966 gst_event_unref (event);
4968 GST_OBJECT_UNLOCK (pad);
4972 /* ERROR handling */
4975 g_warning ("pad %s:%s pushing %s event in wrong direction",
4976 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4977 gst_event_unref (event);
4982 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4983 gst_event_unref (event);
4988 GST_DEBUG_OBJECT (pad, "We're flushing");
4989 GST_OBJECT_UNLOCK (pad);
4990 gst_event_unref (event);
4995 GST_DEBUG_OBJECT (pad, "We're EOS");
4996 GST_OBJECT_UNLOCK (pad);
4997 gst_event_unref (event);
5002 /* Check if we can call the event function with the given event */
5003 static GstFlowReturn
5004 pre_eventfunc_check (GstPad * pad, GstEvent * event)
5008 switch (GST_EVENT_TYPE (event)) {
5009 case GST_EVENT_CAPS:
5011 /* backwards compatibility mode for caps */
5012 gst_event_parse_caps (event, &caps);
5014 if (!gst_pad_query_accept_caps (pad, caps))
5026 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
5027 "caps %" GST_PTR_FORMAT " not accepted", caps);
5028 return GST_FLOW_NOT_NEGOTIATED;
5032 static GstFlowReturn
5033 gst_pad_send_event_unchecked (GstPad * pad, GstEvent * event,
5034 GstPadProbeType type)
5037 GstEventType event_type;
5038 gboolean serialized, need_unlock = FALSE, sticky;
5039 GstPadEventFunction eventfunc;
5042 GST_OBJECT_LOCK (pad);
5044 event = apply_pad_offset (pad, event, GST_PAD_IS_SRC (pad));
5046 if (GST_PAD_IS_SINK (pad))
5047 serialized = GST_EVENT_IS_SERIALIZED (event);
5050 sticky = GST_EVENT_IS_STICKY (event);
5051 event_type = GST_EVENT_TYPE (event);
5052 switch (event_type) {
5053 case GST_EVENT_FLUSH_START:
5054 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5055 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
5057 /* can't even accept a flush begin event when flushing */
5058 if (GST_PAD_IS_FLUSHING (pad))
5061 GST_PAD_SET_FLUSHING (pad);
5062 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
5064 case GST_EVENT_FLUSH_STOP:
5065 if (G_LIKELY (GST_PAD_MODE (pad) != GST_PAD_MODE_NONE)) {
5066 GST_PAD_UNSET_FLUSHING (pad);
5067 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
5069 /* Remove pending EOS events */
5070 GST_LOG_OBJECT (pad, "Removing pending EOS and SEGMENT events");
5071 remove_event_by_type (pad, GST_EVENT_EOS);
5072 remove_event_by_type (pad, GST_EVENT_SEGMENT);
5073 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLAG_EOS);
5074 pad->ABI.abi.last_flowret = GST_FLOW_OK;
5076 GST_OBJECT_UNLOCK (pad);
5077 /* grab stream lock */
5078 GST_PAD_STREAM_LOCK (pad);
5080 GST_OBJECT_LOCK (pad);
5081 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5084 case GST_EVENT_RECONFIGURE:
5085 if (GST_PAD_IS_SRC (pad))
5086 GST_OBJECT_FLAG_SET (pad, GST_PAD_FLAG_NEED_RECONFIGURE);
5088 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
5089 "have event type %" GST_PTR_FORMAT, event);
5091 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5095 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5098 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
5099 GST_OBJECT_UNLOCK (pad);
5100 GST_PAD_STREAM_LOCK (pad);
5102 GST_OBJECT_LOCK (pad);
5103 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
5106 if (G_UNLIKELY (GST_PAD_IS_EOS (pad)))
5112 /* now do the probe */
5114 type | GST_PAD_PROBE_TYPE_PUSH |
5115 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
5117 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
5119 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
5122 ACQUIRE_PARENT (pad, parent, no_parent);
5123 GST_OBJECT_UNLOCK (pad);
5125 ret = pre_eventfunc_check (pad, event);
5126 if (G_UNLIKELY (ret != GST_FLOW_OK))
5127 goto precheck_failed;
5130 gst_event_ref (event);
5132 if (eventfunc (pad, parent, event)) {
5135 /* something went wrong */
5136 switch (event_type) {
5137 case GST_EVENT_CAPS:
5138 ret = GST_FLOW_NOT_NEGOTIATED;
5141 ret = GST_FLOW_ERROR;
5145 RELEASE_PARENT (parent);
5147 GST_DEBUG_OBJECT (pad, "sent event, ret %s", gst_flow_get_name (ret));
5150 if (ret == GST_FLOW_OK) {
5151 GST_OBJECT_LOCK (pad);
5152 /* after the event function accepted the event, we can store the sticky
5153 * event on the pad */
5154 switch (store_sticky_event (pad, event)) {
5155 case GST_FLOW_FLUSHING:
5162 GST_OBJECT_UNLOCK (pad);
5164 gst_event_unref (event);
5168 GST_PAD_STREAM_UNLOCK (pad);
5172 /* ERROR handling */
5175 GST_OBJECT_UNLOCK (pad);
5177 GST_PAD_STREAM_UNLOCK (pad);
5178 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5179 "Received event on flushing pad. Discarding");
5180 gst_event_unref (event);
5181 return GST_FLOW_FLUSHING;
5185 GST_OBJECT_UNLOCK (pad);
5187 GST_PAD_STREAM_UNLOCK (pad);
5188 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
5189 "Received event on EOS pad. Discarding");
5190 gst_event_unref (event);
5191 return GST_FLOW_EOS;
5195 GST_OBJECT_UNLOCK (pad);
5197 GST_PAD_STREAM_UNLOCK (pad);
5198 gst_event_unref (event);
5201 case GST_FLOW_CUSTOM_SUCCESS:
5202 GST_DEBUG_OBJECT (pad, "dropped event");
5206 GST_DEBUG_OBJECT (pad, "an error occurred %s", gst_flow_get_name (ret));
5213 g_warning ("pad %s:%s has no event handler, file a bug.",
5214 GST_DEBUG_PAD_NAME (pad));
5215 GST_OBJECT_UNLOCK (pad);
5217 GST_PAD_STREAM_UNLOCK (pad);
5218 gst_event_unref (event);
5219 return GST_FLOW_NOT_SUPPORTED;
5223 GST_DEBUG_OBJECT (pad, "no parent");
5224 GST_OBJECT_UNLOCK (pad);
5226 GST_PAD_STREAM_UNLOCK (pad);
5227 gst_event_unref (event);
5228 return GST_FLOW_FLUSHING;
5232 GST_DEBUG_OBJECT (pad, "pre event check failed");
5233 RELEASE_PARENT (parent);
5235 GST_PAD_STREAM_UNLOCK (pad);
5236 gst_event_unref (event);
5242 * gst_pad_send_event:
5243 * @pad: a #GstPad to send the event to.
5244 * @event: (transfer full): the #GstEvent to send to the pad.
5246 * Sends the event to the pad. This function can be used
5247 * by applications to send events in the pipeline.
5249 * If @pad is a source pad, @event should be an upstream event. If @pad is a
5250 * sink pad, @event should be a downstream event. For example, you would not
5251 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
5252 * Furthermore, some downstream events have to be serialized with data flow,
5253 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
5254 * the event needs to be serialized with data flow, this function will take the
5255 * pad's stream lock while calling its event function.
5257 * To find out whether an event type is upstream, downstream, or downstream and
5258 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
5259 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
5260 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
5261 * plugin doesn't need to bother itself with this information; the core handles
5262 * all necessary locks and checks.
5264 * This function takes ownership of the provided event so you should
5265 * gst_event_ref() it if you want to reuse the event after this call.
5267 * Returns: %TRUE if the event was handled.
5270 gst_pad_send_event (GstPad * pad, GstEvent * event)
5273 GstPadProbeType type;
5275 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5276 g_return_val_if_fail (event != NULL, FALSE);
5278 if (GST_PAD_IS_SINK (pad)) {
5279 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
5280 goto wrong_direction;
5281 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
5282 } else if (GST_PAD_IS_SRC (pad)) {
5283 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
5284 goto wrong_direction;
5285 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
5287 goto unknown_direction;
5289 if (gst_pad_send_event_unchecked (pad, event, type) != GST_FLOW_OK)
5296 /* ERROR handling */
5299 g_warning ("pad %s:%s sending %s event in wrong direction",
5300 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
5301 gst_event_unref (event);
5306 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
5307 gst_event_unref (event);
5313 * gst_pad_set_element_private:
5314 * @pad: the #GstPad to set the private data of.
5315 * @priv: The private data to attach to the pad.
5317 * Set the given private data gpointer on the pad.
5318 * This function can only be used by the element that owns the pad.
5319 * No locking is performed in this function.
5322 gst_pad_set_element_private (GstPad * pad, gpointer priv)
5324 pad->element_private = priv;
5328 * gst_pad_get_element_private:
5329 * @pad: the #GstPad to get the private data of.
5331 * Gets the private data of a pad.
5332 * No locking is performed in this function.
5334 * Returns: (transfer none): a #gpointer to the private data.
5337 gst_pad_get_element_private (GstPad * pad)
5339 return pad->element_private;
5343 * gst_pad_get_sticky_event:
5344 * @pad: the #GstPad to get the event from.
5345 * @event_type: the #GstEventType that should be retrieved.
5346 * @idx: the index of the event
5348 * Returns a new reference of the sticky event of type @event_type
5351 * Returns: (transfer full): a #GstEvent of type @event_type or %NULL when no
5352 * event of @event_type was on @pad. Unref after usage.
5355 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type, guint idx)
5357 GstEvent *event = NULL;
5360 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
5361 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
5363 GST_OBJECT_LOCK (pad);
5364 ev = find_event_by_type (pad, event_type, idx);
5365 if (ev && (event = ev->event))
5366 gst_event_ref (event);
5367 GST_OBJECT_UNLOCK (pad);
5374 GstPadStickyEventsForeachFunction func;
5379 foreach_dispatch_function (GstPad * pad, PadEvent * ev, gpointer user_data)
5381 ForeachDispatch *data = user_data;
5382 gboolean ret = TRUE;
5385 GST_OBJECT_UNLOCK (pad);
5387 ret = data->func (pad, &ev->event, data->user_data);
5389 GST_OBJECT_LOCK (pad);
5396 * gst_pad_sticky_events_foreach:
5397 * @pad: the #GstPad that should be used for iteration.
5398 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that
5399 * should be called for every event.
5400 * @user_data: (closure): the optional user data.
5402 * Iterates all sticky events on @pad and calls @foreach_func for every
5403 * event. If @foreach_func returns %FALSE the iteration is immediately stopped.
5406 gst_pad_sticky_events_foreach (GstPad * pad,
5407 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
5409 ForeachDispatch data;
5411 g_return_if_fail (GST_IS_PAD (pad));
5412 g_return_if_fail (foreach_func != NULL);
5414 data.func = foreach_func;
5415 data.user_data = user_data;
5417 GST_OBJECT_LOCK (pad);
5418 events_foreach (pad, foreach_dispatch_function, &data);
5419 GST_OBJECT_UNLOCK (pad);
5423 do_stream_status (GstPad * pad, GstStreamStatusType type,
5424 GThread * thread, GstTask * task)
5428 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
5430 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
5431 if (GST_IS_ELEMENT (parent)) {
5432 GstMessage *message;
5433 GValue value = { 0 };
5435 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
5436 gchar *tname, *ename, *pname;
5438 /* create a good task name */
5439 ename = gst_element_get_name (parent);
5440 pname = gst_pad_get_name (pad);
5441 tname = g_strdup_printf ("%s:%s", ename, pname);
5445 gst_object_set_name (GST_OBJECT_CAST (task), tname);
5449 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
5452 g_value_init (&value, GST_TYPE_TASK);
5453 g_value_set_object (&value, task);
5454 gst_message_set_stream_status_object (message, &value);
5455 g_value_unset (&value);
5457 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
5458 gst_element_post_message (parent, message);
5460 gst_object_unref (parent);
5465 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
5467 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
5472 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
5474 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
5479 * gst_pad_start_task:
5480 * @pad: the #GstPad to start the task of
5481 * @func: the task function to call
5482 * @user_data: user data passed to the task function
5483 * @notify: called when @user_data is no longer referenced
5485 * Starts a task that repeatedly calls @func with @user_data. This function
5486 * is mostly used in pad activation functions to start the dataflow.
5487 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
5488 * before @func is called.
5490 * Returns: a %TRUE if the task could be started.
5493 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer user_data,
5494 GDestroyNotify notify)
5499 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5500 g_return_val_if_fail (func != NULL, FALSE);
5502 GST_DEBUG_OBJECT (pad, "start task");
5504 GST_OBJECT_LOCK (pad);
5505 task = GST_PAD_TASK (pad);
5507 task = gst_task_new (func, user_data, notify);
5508 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
5509 gst_task_set_enter_callback (task, pad_enter_thread, pad, NULL);
5510 gst_task_set_leave_callback (task, pad_leave_thread, pad, NULL);
5511 GST_INFO_OBJECT (pad, "created task %p", task);
5512 GST_PAD_TASK (pad) = task;
5513 gst_object_ref (task);
5514 /* release lock to post the message */
5515 GST_OBJECT_UNLOCK (pad);
5517 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
5519 gst_object_unref (task);
5521 GST_OBJECT_LOCK (pad);
5522 /* nobody else is supposed to have changed the pad now */
5523 if (GST_PAD_TASK (pad) != task)
5524 goto concurrent_stop;
5526 res = gst_task_set_state (task, GST_TASK_STARTED);
5527 GST_OBJECT_UNLOCK (pad);
5534 GST_OBJECT_UNLOCK (pad);
5540 * gst_pad_pause_task:
5541 * @pad: the #GstPad to pause the task of
5543 * Pause the task of @pad. This function will also wait until the
5544 * function executed by the task is finished if this function is not
5545 * called from the task function.
5547 * Returns: a %TRUE if the task could be paused or %FALSE when the pad
5551 gst_pad_pause_task (GstPad * pad)
5556 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5558 GST_DEBUG_OBJECT (pad, "pause task");
5560 GST_OBJECT_LOCK (pad);
5561 task = GST_PAD_TASK (pad);
5564 res = gst_task_set_state (task, GST_TASK_PAUSED);
5565 GST_OBJECT_UNLOCK (pad);
5567 /* wait for task function to finish, this lock is recursive so it does nothing
5568 * when the pause is called from the task itself */
5569 GST_PAD_STREAM_LOCK (pad);
5570 GST_PAD_STREAM_UNLOCK (pad);
5576 GST_DEBUG_OBJECT (pad, "pad has no task");
5577 GST_OBJECT_UNLOCK (pad);
5583 * gst_pad_stop_task:
5584 * @pad: the #GstPad to stop the task of
5586 * Stop the task of @pad. This function will also make sure that the
5587 * function executed by the task will effectively stop if not called
5588 * from the GstTaskFunction.
5590 * This function will deadlock if called from the GstTaskFunction of
5591 * the task. Use gst_task_pause() instead.
5593 * Regardless of whether the pad has a task, the stream lock is acquired and
5594 * released so as to ensure that streaming through this pad has finished.
5596 * Returns: a %TRUE if the task could be stopped or %FALSE on error.
5599 gst_pad_stop_task (GstPad * pad)
5604 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
5606 GST_DEBUG_OBJECT (pad, "stop task");
5608 GST_OBJECT_LOCK (pad);
5609 task = GST_PAD_TASK (pad);
5612 GST_PAD_TASK (pad) = NULL;
5613 res = gst_task_set_state (task, GST_TASK_STOPPED);
5614 GST_OBJECT_UNLOCK (pad);
5616 GST_PAD_STREAM_LOCK (pad);
5617 GST_PAD_STREAM_UNLOCK (pad);
5619 if (!gst_task_join (task))
5622 gst_object_unref (task);
5628 GST_DEBUG_OBJECT (pad, "no task");
5629 GST_OBJECT_UNLOCK (pad);
5631 GST_PAD_STREAM_LOCK (pad);
5632 GST_PAD_STREAM_UNLOCK (pad);
5634 /* this is not an error */
5639 /* this is bad, possibly the application tried to join the task from
5640 * the task's thread. We install the task again so that it will be stopped
5641 * again from the right thread next time hopefully. */
5642 GST_OBJECT_LOCK (pad);
5643 GST_DEBUG_OBJECT (pad, "join failed");
5644 /* we can only install this task if there was no other task */
5645 if (GST_PAD_TASK (pad) == NULL)
5646 GST_PAD_TASK (pad) = task;
5647 GST_OBJECT_UNLOCK (pad);
5654 * gst_pad_probe_info_get_event:
5655 * @info: a #GstPadProbeInfo
5657 * Returns: (transfer none): The #GstEvent from the probe
5661 gst_pad_probe_info_get_event (GstPadProbeInfo * info)
5663 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM |
5664 GST_PAD_PROBE_TYPE_EVENT_UPSTREAM), NULL);
5666 return GST_PAD_PROBE_INFO_EVENT (info);
5671 * gst_pad_probe_info_get_query:
5672 * @info: a #GstPadProbeInfo
5674 * Returns: (transfer none): The #GstQuery from the probe
5678 gst_pad_probe_info_get_query (GstPadProbeInfo * info)
5680 g_return_val_if_fail (info->type & (GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM |
5681 GST_PAD_PROBE_TYPE_QUERY_UPSTREAM), NULL);
5683 return GST_PAD_PROBE_INFO_QUERY (info);
5687 * gst_pad_probe_info_get_buffer:
5688 * @info: a #GstPadProbeInfo
5690 * Returns: (transfer none): The #GstBuffer from the probe
5694 gst_pad_probe_info_get_buffer (GstPadProbeInfo * info)
5696 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER, NULL);
5698 return GST_PAD_PROBE_INFO_BUFFER (info);
5702 * gst_pad_probe_info_get_bufferlist:
5703 * @info: a #GstPadProbeInfo
5705 * Returns: (transfer none): The #GstBufferlist from the probe
5709 gst_pad_probe_info_get_buffer_list (GstPadProbeInfo * info)
5711 g_return_val_if_fail (info->type & GST_PAD_PROBE_TYPE_BUFFER_LIST, NULL);
5713 return GST_PAD_PROBE_INFO_BUFFER_LIST (info);
5717 * gst_pad_get_last_flow_return:
5720 * Gets the #GstFlowReturn return from the last data passed by this pad.
5725 gst_pad_get_last_flow_return (GstPad * pad)
5729 GST_OBJECT_LOCK (pad);
5730 ret = GST_PAD_LAST_FLOW_RETURN (pad);
5731 GST_OBJECT_UNLOCK (pad);