2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * @short_description: Object contained by elements that allows links to
26 * @see_also: #GstPadTemplate, #GstElement, #GstEvent
28 * A #GstElement is linked to other elements via "pads", which are extremely
29 * light-weight generic link points.
30 * After two pads are retrieved from an element with gst_element_get_pad(),
31 * the pads can be link with gst_pad_link(). (For quick links,
32 * you can also use gst_element_link(), which will make the obvious
33 * link for you if it's straightforward.)
35 * Pads are typically created from a #GstPadTemplate with
36 * gst_pad_new_from_template().
38 * Pads have #GstCaps attached to it to describe the media type they are
39 * capable of dealing with. gst_pad_get_caps() and gst_pad_set_caps() are
40 * used to manipulate the caps of the pads.
41 * Pads created from a pad template cannot set capabilities that are
42 * incompatible with the pad template capabilities.
44 * Pads without pad templates can be created with gst_pad_new(),
45 * which takes a direction and a name as an argument. If the name is NULL,
46 * then a guaranteed unique name will be assigned to it.
48 * gst_pad_get_parent() will retrieve the #GstElement that owns the pad.
50 * A #GstElement creating a pad will typically use the various
51 * gst_pad_set_*_function() calls to register callbacks for various events
54 * GstElements will use gst_pad_push() and gst_pad_pull_range() to push out
55 * or pull in a buffer.
57 * To send a #GstEvent on a pad, use gst_pad_send_event() and
58 * gst_pad_push_event().
60 * Last reviewed on 2006-07-06 (0.10.9)
63 #include "gst_private.h"
66 #include "gstpadtemplate.h"
67 #include "gstenumtypes.h"
68 #include "gstmarshal.h"
73 #include "glib-compat-private.h"
75 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
76 #define GST_CAT_DEFAULT GST_CAT_PADS
78 /* Pad signals and args */
96 #define GST_PAD_GET_PRIVATE(obj) \
97 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_PAD, GstPadPrivate))
99 /* we have a pending and an active event on the pad. On source pads only the
100 * active event is used. On sinkpads, events are copied to the pending entry and
101 * moved to the active event when the eventfunc returned TRUE. */
108 struct _GstPadPrivate
110 PadEvent events[GST_EVENT_MAX_STICKY];
122 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
127 GstPadProbeType mask;
129 GstPadProbeReturn ret;
134 static void gst_pad_dispose (GObject * object);
135 static void gst_pad_finalize (GObject * object);
136 static void gst_pad_set_property (GObject * object, guint prop_id,
137 const GValue * value, GParamSpec * pspec);
138 static void gst_pad_get_property (GObject * object, guint prop_id,
139 GValue * value, GParamSpec * pspec);
141 static GstCaps *gst_pad_get_caps_unlocked (GstPad * pad, GstCaps * filter);
142 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
143 static gboolean gst_pad_activate_default (GstPad * pad);
144 static gboolean gst_pad_acceptcaps_default (GstPad * pad, GstCaps * caps);
145 static void gst_pad_fixate_caps_default (GstPad * pad, GstCaps * caps);
146 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
147 GstBufferList * list);
149 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
151 static GParamSpec *pspec_caps = NULL;
153 /* quarks for probe signals */
154 static GQuark buffer_quark;
155 static GQuark buffer_list_quark;
156 static GQuark event_quark;
165 static GstFlowQuarks flow_quarks[] = {
166 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
167 {GST_FLOW_RESEND, "resend", 0},
168 {GST_FLOW_OK, "ok", 0},
169 {GST_FLOW_NOT_LINKED, "not-linked", 0},
170 {GST_FLOW_WRONG_STATE, "wrong-state", 0},
171 {GST_FLOW_EOS, "eos", 0},
172 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
173 {GST_FLOW_ERROR, "error", 0},
174 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
175 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
180 * @ret: a #GstFlowReturn to get the name of.
182 * Gets a string representing the given flow return.
184 * Returns: a static string with the name of the flow return.
187 gst_flow_get_name (GstFlowReturn ret)
191 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
193 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
194 if (ret == flow_quarks[i].ret)
195 return flow_quarks[i].name;
202 * @ret: a #GstFlowReturn to get the quark of.
204 * Get the unique quark for the given GstFlowReturn.
206 * Returns: the quark associated with the flow return or 0 if an
207 * invalid return was specified.
210 gst_flow_to_quark (GstFlowReturn ret)
214 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
216 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
217 if (ret == flow_quarks[i].ret)
218 return flow_quarks[i].quark;
227 buffer_quark = g_quark_from_static_string ("buffer"); \
228 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
229 event_quark = g_quark_from_static_string ("event"); \
231 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
232 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
235 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
236 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
239 #define gst_pad_parent_class parent_class
240 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
243 gst_pad_class_init (GstPadClass * klass)
245 GObjectClass *gobject_class;
246 GstObjectClass *gstobject_class;
248 gobject_class = G_OBJECT_CLASS (klass);
249 gstobject_class = GST_OBJECT_CLASS (klass);
251 g_type_class_add_private (klass, sizeof (GstPadPrivate));
253 gobject_class->dispose = gst_pad_dispose;
254 gobject_class->finalize = gst_pad_finalize;
255 gobject_class->set_property = gst_pad_set_property;
256 gobject_class->get_property = gst_pad_get_property;
260 * @pad: the pad that emitted the signal
261 * @peer: the peer pad that has been connected
263 * Signals that a pad has been linked to the peer pad.
265 gst_pad_signals[PAD_LINKED] =
266 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
267 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
268 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
271 * @pad: the pad that emitted the signal
272 * @peer: the peer pad that has been disconnected
274 * Signals that a pad has been unlinked from the peer pad.
276 gst_pad_signals[PAD_UNLINKED] =
277 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
278 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
279 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
281 pspec_caps = g_param_spec_boxed ("caps", "Caps",
282 "The capabilities of the pad", GST_TYPE_CAPS,
283 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
284 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
286 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
287 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
288 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
289 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
291 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
292 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
293 g_param_spec_object ("template", "Template",
294 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
295 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
297 gstobject_class->path_string_separator = ".";
299 /* Register common function pointer descriptions */
300 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
301 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
302 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_get_query_types_default);
303 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
304 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
305 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_acceptcaps_default);
306 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
307 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_fixate_caps_default);
311 gst_pad_init (GstPad * pad)
313 pad->priv = GST_PAD_GET_PRIVATE (pad);
315 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
317 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
318 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
319 GST_PAD_QUERYTYPEFUNC (pad) = gst_pad_get_query_types_default;
320 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
321 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
322 GST_PAD_ACCEPTCAPSFUNC (pad) = gst_pad_acceptcaps_default;
323 GST_PAD_FIXATECAPSFUNC (pad) = gst_pad_fixate_caps_default;
324 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
326 GST_PAD_SET_FLUSHING (pad);
328 g_static_rec_mutex_init (&pad->stream_rec_lock);
330 pad->block_cond = g_cond_new ();
332 g_hook_list_init (&pad->probes, sizeof (GstProbe));
336 clear_event (PadEvent events[], guint idx)
338 gst_event_replace (&events[idx].event, NULL);
339 gst_event_replace (&events[idx].pending, NULL);
342 /* called when setting the pad inactive. It removes all sticky events from
345 clear_events (PadEvent events[])
349 for (i = 0; i < GST_EVENT_MAX_STICKY; i++)
350 clear_event (events, i);
353 /* The sticky event with @idx from the srcpad is copied to the
354 * pending event on the sinkpad (when different).
355 * This function applies the pad offsets in case of segment events.
356 * This will make sure that we send the event to the sinkpad event
357 * function when the next buffer of event arrives.
358 * Should be called with the OBJECT lock of both pads.
359 * This function returns TRUE when there is a pending event on the
362 replace_event (GstPad * srcpad, GstPad * sinkpad, guint idx)
364 PadEvent *srcev, *sinkev;
366 gboolean pending = FALSE;
368 srcev = &srcpad->priv->events[idx];
370 if ((event = srcev->event)) {
371 sinkev = &sinkpad->priv->events[idx];
373 switch (GST_EVENT_TYPE (event)) {
374 case GST_EVENT_SEGMENT:
379 offset = srcpad->offset + sinkpad->offset;
381 gst_event_copy_segment (event, &segment);
382 /* adjust the base time. FIXME, check negative times, try to tweak the
383 * start to do clipping on negative times */
384 segment.base += offset;
385 /* make a new event from the updated segment */
386 event = gst_event_new_segment (&segment);
393 if (sinkev->event != event) {
394 /* put in the pending entry when different */
395 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, srcpad,
396 "Putting event %p (%s) on pad %s:%s", event,
397 GST_EVENT_TYPE_NAME (event), GST_DEBUG_PAD_NAME (sinkpad));
398 gst_event_replace (&sinkev->pending, event);
407 prepare_event_update (GstPad * srcpad, GstPad * sinkpad)
412 /* make sure we push the events from the source to this new peer, for this we
413 * copy the events on the sinkpad and mark EVENTS_PENDING */
415 for (i = 0; i < GST_EVENT_MAX_STICKY; i++)
416 pending |= replace_event (srcpad, sinkpad, i);
418 /* we had some new pending events, set our flag */
420 GST_OBJECT_FLAG_SET (sinkpad, GST_PAD_NEED_EVENTS);
423 /* should be called with the OBJECT_LOCK */
425 get_pad_caps (GstPad * pad)
427 GstCaps *caps = NULL;
431 idx = GST_EVENT_STICKY_IDX_TYPE (GST_EVENT_CAPS);
432 /* we can only use the caps when we have successfully send the caps
433 * event to the event function and is thus in the active entry */
434 if ((event = pad->priv->events[idx].event))
435 gst_event_parse_caps (event, &caps);
441 gst_pad_dispose (GObject * object)
443 GstPad *pad = GST_PAD_CAST (object);
446 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
448 /* unlink the peer pad */
449 if ((peer = gst_pad_get_peer (pad))) {
450 /* window for MT unsafeness, someone else could unlink here
451 * and then we call unlink with wrong pads. The unlink
452 * function would catch this and safely return failed. */
453 if (GST_PAD_IS_SRC (pad))
454 gst_pad_unlink (pad, peer);
456 gst_pad_unlink (peer, pad);
458 gst_object_unref (peer);
461 gst_pad_set_pad_template (pad, NULL);
463 clear_events (pad->priv->events);
465 g_hook_list_clear (&pad->probes);
467 G_OBJECT_CLASS (parent_class)->dispose (object);
471 gst_pad_finalize (GObject * object)
473 GstPad *pad = GST_PAD_CAST (object);
476 /* in case the task is still around, clean it up */
477 if ((task = GST_PAD_TASK (pad))) {
478 gst_task_join (task);
479 GST_PAD_TASK (pad) = NULL;
480 gst_object_unref (task);
483 g_static_rec_mutex_free (&pad->stream_rec_lock);
484 g_cond_free (pad->block_cond);
486 G_OBJECT_CLASS (parent_class)->finalize (object);
490 gst_pad_set_property (GObject * object, guint prop_id,
491 const GValue * value, GParamSpec * pspec)
493 g_return_if_fail (GST_IS_PAD (object));
496 case PAD_PROP_DIRECTION:
497 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
499 case PAD_PROP_TEMPLATE:
500 gst_pad_set_pad_template (GST_PAD_CAST (object),
501 (GstPadTemplate *) g_value_get_object (value));
504 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
510 gst_pad_get_property (GObject * object, guint prop_id,
511 GValue * value, GParamSpec * pspec)
513 g_return_if_fail (GST_IS_PAD (object));
517 GST_OBJECT_LOCK (object);
518 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
519 GST_OBJECT_UNLOCK (object);
521 case PAD_PROP_DIRECTION:
522 g_value_set_enum (value, GST_PAD_DIRECTION (object));
524 case PAD_PROP_TEMPLATE:
525 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
528 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
535 * @name: the name of the new pad.
536 * @direction: the #GstPadDirection of the pad.
538 * Creates a new pad with the given name in the given direction.
539 * If name is NULL, a guaranteed unique name (across all pads)
541 * This function makes a copy of the name so you can safely free the name.
543 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
548 gst_pad_new (const gchar * name, GstPadDirection direction)
550 return g_object_new (GST_TYPE_PAD,
551 "name", name, "direction", direction, NULL);
555 * gst_pad_new_from_template:
556 * @templ: the pad template to use
557 * @name: the name of the element
559 * Creates a new pad with the given name from the given template.
560 * If name is NULL, a guaranteed unique name (across all pads)
562 * This function makes a copy of the name so you can safely free the name.
564 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
567 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
569 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
571 return g_object_new (GST_TYPE_PAD,
572 "name", name, "direction", templ->direction, "template", templ, NULL);
576 * gst_pad_new_from_static_template:
577 * @templ: the #GstStaticPadTemplate to use
578 * @name: the name of the element
580 * Creates a new pad with the given name from the given static template.
581 * If name is NULL, a guaranteed unique name (across all pads)
583 * This function makes a copy of the name so you can safely free the name.
585 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
588 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
592 GstPadTemplate *template;
594 template = gst_static_pad_template_get (templ);
595 pad = gst_pad_new_from_template (template, name);
596 gst_object_unref (template);
601 * gst_pad_get_direction:
602 * @pad: a #GstPad to get the direction of.
604 * Gets the direction of the pad. The direction of the pad is
605 * decided at construction time so this function does not take
608 * Returns: the #GstPadDirection of the pad.
613 gst_pad_get_direction (GstPad * pad)
615 GstPadDirection result;
617 /* PAD_UNKNOWN is a little silly but we need some sort of
618 * error return value */
619 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
621 result = GST_PAD_DIRECTION (pad);
627 gst_pad_activate_default (GstPad * pad)
629 return gst_pad_activate_push (pad, TRUE);
633 pre_activate (GstPad * pad, GstPadActivateMode new_mode)
636 case GST_PAD_ACTIVATE_PUSH:
637 case GST_PAD_ACTIVATE_PULL:
638 GST_OBJECT_LOCK (pad);
639 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE %d, unset flushing",
641 GST_PAD_UNSET_FLUSHING (pad);
642 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
643 GST_OBJECT_UNLOCK (pad);
645 case GST_PAD_ACTIVATE_NONE:
646 GST_OBJECT_LOCK (pad);
647 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE NONE, set flushing");
648 GST_PAD_SET_FLUSHING (pad);
649 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
650 /* unlock blocked pads so element can resume and stop */
651 GST_PAD_BLOCK_BROADCAST (pad);
652 GST_OBJECT_UNLOCK (pad);
658 post_activate (GstPad * pad, GstPadActivateMode new_mode)
661 case GST_PAD_ACTIVATE_PUSH:
662 case GST_PAD_ACTIVATE_PULL:
665 case GST_PAD_ACTIVATE_NONE:
666 /* ensures that streaming stops */
667 GST_PAD_STREAM_LOCK (pad);
668 GST_DEBUG_OBJECT (pad, "stopped streaming");
669 GST_OBJECT_LOCK (pad);
670 clear_events (pad->priv->events);
671 GST_OBJECT_UNLOCK (pad);
672 GST_PAD_STREAM_UNLOCK (pad);
678 * gst_pad_set_active:
679 * @pad: the #GstPad to activate or deactivate.
680 * @active: whether or not the pad should be active.
682 * Activates or deactivates the given pad.
683 * Normally called from within core state change functions.
685 * If @active, makes sure the pad is active. If it is already active, either in
686 * push or pull mode, just return. Otherwise dispatches to the pad's activate
687 * function to perform the actual activation.
689 * If not @active, checks the pad's current mode and calls
690 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
693 * Returns: #TRUE if the operation was successful.
698 gst_pad_set_active (GstPad * pad, gboolean active)
700 GstPadActivateMode old;
701 gboolean ret = FALSE;
703 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
705 GST_OBJECT_LOCK (pad);
706 old = GST_PAD_ACTIVATE_MODE (pad);
707 GST_OBJECT_UNLOCK (pad);
711 case GST_PAD_ACTIVATE_PUSH:
712 GST_DEBUG_OBJECT (pad, "activating pad from push");
715 case GST_PAD_ACTIVATE_PULL:
716 GST_DEBUG_OBJECT (pad, "activating pad from pull");
719 case GST_PAD_ACTIVATE_NONE:
720 GST_DEBUG_OBJECT (pad, "activating pad from none");
721 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad);
724 GST_DEBUG_OBJECT (pad, "unknown activation mode!");
729 case GST_PAD_ACTIVATE_PUSH:
730 GST_DEBUG_OBJECT (pad, "deactivating pad from push");
731 ret = gst_pad_activate_push (pad, FALSE);
733 case GST_PAD_ACTIVATE_PULL:
734 GST_DEBUG_OBJECT (pad, "deactivating pad from pull");
735 ret = gst_pad_activate_pull (pad, FALSE);
737 case GST_PAD_ACTIVATE_NONE:
738 GST_DEBUG_OBJECT (pad, "deactivating pad from none");
742 GST_DEBUG_OBJECT (pad, "unknown activation mode!");
748 GST_OBJECT_LOCK (pad);
750 g_critical ("Failed to deactivate pad %s:%s, very bad",
751 GST_DEBUG_PAD_NAME (pad));
753 GST_WARNING_OBJECT (pad, "Failed to activate pad");
755 GST_OBJECT_UNLOCK (pad);
758 GST_OBJECT_LOCK (pad);
759 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_RECONFIGURE);
760 GST_OBJECT_UNLOCK (pad);
768 * gst_pad_activate_pull:
769 * @pad: the #GstPad to activate or deactivate.
770 * @active: whether or not the pad should be active.
772 * Activates or deactivates the given pad in pull mode via dispatching to the
773 * pad's activatepullfunc. For use from within pad activation functions only.
774 * When called on sink pads, will first proxy the call to the peer pad, which
775 * is expected to activate its internally linked pads from within its
776 * activate_pull function.
778 * If you don't know what this is, you probably don't want to call it.
780 * Returns: TRUE if the operation was successful.
785 gst_pad_activate_pull (GstPad * pad, gboolean active)
787 GstPadActivateMode old, new;
790 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
792 GST_OBJECT_LOCK (pad);
793 old = GST_PAD_ACTIVATE_MODE (pad);
794 GST_OBJECT_UNLOCK (pad);
798 case GST_PAD_ACTIVATE_PULL:
799 GST_DEBUG_OBJECT (pad, "activating pad from pull, was ok");
801 case GST_PAD_ACTIVATE_PUSH:
802 GST_DEBUG_OBJECT (pad,
803 "activating pad from push, deactivate push first");
804 /* pad was activate in the wrong direction, deactivate it
805 * and reactivate it in pull mode */
806 if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
807 goto deactivate_failed;
808 /* fallthrough, pad is deactivated now. */
809 case GST_PAD_ACTIVATE_NONE:
810 GST_DEBUG_OBJECT (pad, "activating pad from none");
815 case GST_PAD_ACTIVATE_NONE:
816 GST_DEBUG_OBJECT (pad, "deactivating pad from none, was ok");
818 case GST_PAD_ACTIVATE_PUSH:
819 GST_DEBUG_OBJECT (pad, "deactivating pad from push, weird");
820 /* pad was activated in the other direction, deactivate it
821 * in push mode, this should not happen... */
822 if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
823 goto deactivate_failed;
824 /* everything is fine now */
826 case GST_PAD_ACTIVATE_PULL:
827 GST_DEBUG_OBJECT (pad, "deactivating pad from pull");
832 if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
833 if ((peer = gst_pad_get_peer (pad))) {
834 GST_DEBUG_OBJECT (pad, "calling peer");
835 if (G_UNLIKELY (!gst_pad_activate_pull (peer, active)))
837 gst_object_unref (peer);
839 /* there is no peer, this is only fatal when we activate. When we
840 * deactivate, we must assume the application has unlinked the peer and
841 * will deactivate it eventually. */
845 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
848 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
849 goto failure; /* Can't activate pull on a src without a
853 new = active ? GST_PAD_ACTIVATE_PULL : GST_PAD_ACTIVATE_NONE;
854 pre_activate (pad, new);
856 if (GST_PAD_ACTIVATEPULLFUNC (pad)) {
857 if (G_UNLIKELY (!GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active)))
860 /* can happen for sinks of passthrough elements */
863 post_activate (pad, new);
865 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode",
866 active ? "activated" : "deactivated");
872 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in pull mode",
873 active ? "activated" : "deactivated");
878 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
879 "failed to %s in switch to pull from mode %d",
880 (active ? "activate" : "deactivate"), old);
885 GST_OBJECT_LOCK (peer);
886 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
887 "activate_pull on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
888 GST_OBJECT_UNLOCK (peer);
889 gst_object_unref (peer);
894 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
900 GST_OBJECT_LOCK (pad);
901 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in pull mode",
902 active ? "activate" : "deactivate");
903 GST_PAD_SET_FLUSHING (pad);
904 GST_PAD_ACTIVATE_MODE (pad) = old;
905 GST_OBJECT_UNLOCK (pad);
911 * gst_pad_activate_push:
912 * @pad: the #GstPad to activate or deactivate.
913 * @active: whether the pad should be active or not.
915 * Activates or deactivates the given pad in push mode via dispatching to the
916 * pad's activatepushfunc. For use from within pad activation functions only.
918 * If you don't know what this is, you probably don't want to call it.
920 * Returns: %TRUE if the operation was successful.
925 gst_pad_activate_push (GstPad * pad, gboolean active)
927 GstPadActivateMode old, new;
929 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
930 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "trying to set %s in push mode",
931 active ? "activated" : "deactivated");
933 GST_OBJECT_LOCK (pad);
934 old = GST_PAD_ACTIVATE_MODE (pad);
935 GST_OBJECT_UNLOCK (pad);
939 case GST_PAD_ACTIVATE_PUSH:
940 GST_DEBUG_OBJECT (pad, "activating pad from push, was ok");
942 case GST_PAD_ACTIVATE_PULL:
943 GST_DEBUG_OBJECT (pad,
944 "activating pad from push, deactivating pull first");
945 /* pad was activate in the wrong direction, deactivate it
946 * an reactivate it in push mode */
947 if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
948 goto deactivate_failed;
949 /* fallthrough, pad is deactivated now. */
950 case GST_PAD_ACTIVATE_NONE:
951 GST_DEBUG_OBJECT (pad, "activating pad from none");
956 case GST_PAD_ACTIVATE_NONE:
957 GST_DEBUG_OBJECT (pad, "deactivating pad from none, was ok");
959 case GST_PAD_ACTIVATE_PULL:
960 GST_DEBUG_OBJECT (pad, "deactivating pad from pull, weird");
961 /* pad was activated in the other direction, deactivate it
962 * in pull mode, this should not happen... */
963 if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
964 goto deactivate_failed;
965 /* everything is fine now */
967 case GST_PAD_ACTIVATE_PUSH:
968 GST_DEBUG_OBJECT (pad, "deactivating pad from push");
973 new = active ? GST_PAD_ACTIVATE_PUSH : GST_PAD_ACTIVATE_NONE;
974 pre_activate (pad, new);
976 if (GST_PAD_ACTIVATEPUSHFUNC (pad)) {
977 if (G_UNLIKELY (!GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active))) {
981 /* quite ok, element relies on state change func to prepare itself */
984 post_activate (pad, new);
986 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in push mode",
987 active ? "activated" : "deactivated");
992 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in push mode",
993 active ? "activated" : "deactivated");
998 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
999 "failed to %s in switch to push from mode %d",
1000 (active ? "activate" : "deactivate"), old);
1005 GST_OBJECT_LOCK (pad);
1006 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode",
1007 active ? "activate" : "deactivate");
1008 GST_PAD_SET_FLUSHING (pad);
1009 GST_PAD_ACTIVATE_MODE (pad) = old;
1010 GST_OBJECT_UNLOCK (pad);
1016 * gst_pad_is_active:
1017 * @pad: the #GstPad to query
1019 * Query if a pad is active
1021 * Returns: TRUE if the pad is active.
1026 gst_pad_is_active (GstPad * pad)
1028 gboolean result = FALSE;
1030 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1032 GST_OBJECT_LOCK (pad);
1033 result = GST_PAD_IS_ACTIVE (pad);
1034 GST_OBJECT_UNLOCK (pad);
1040 * gst_pad_add_probe:
1041 * @pad: the #GstPad to add the probe to
1042 * @mask: the probe mask
1043 * @callback: #GstPadProbeCallback that will be called with notifications of
1045 * @user_data: (closure): user data passed to the callback
1046 * @destroy_data: #GDestroyNotify for user_data
1048 * Be notified of different states of pads. The provided callback is called for
1049 * every state that matches @mask.
1052 * Pad probe handlers are only called for source pads in push mode
1053 * and sink pads in pull mode.
1056 * Returns: an id or 0 on error. The id can be used to remove the probe with
1057 * gst_pad_remove_probe().
1062 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1063 GstPadProbeCallback callback, gpointer user_data,
1064 GDestroyNotify destroy_data)
1069 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1070 g_return_val_if_fail (mask != 0, 0);
1072 GST_OBJECT_LOCK (pad);
1074 /* FIXME : I'm not checking for != GST_PAD_ACTIVATE_correct_direction
1075 * because the pad might not be activated yet.
1076 * This means that _add_probe() might return a valid probeid ...
1077 * which will potentially never be called if the pad
1078 * is activated in the wrong direction */
1079 if (G_UNLIKELY ((mask & GST_PAD_PROBE_TYPE_PUSH) &&
1080 (GST_PAD_ACTIVATE_MODE (pad) == GST_PAD_ACTIVATE_PULL)))
1081 goto wrong_direction;
1082 if (G_UNLIKELY ((mask & GST_PAD_PROBE_TYPE_PULL) &&
1083 (GST_PAD_ACTIVATE_MODE (pad) == GST_PAD_ACTIVATE_PUSH)))
1084 goto wrong_direction;
1086 /* make a new probe */
1087 hook = g_hook_alloc (&pad->probes);
1089 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1092 /* when no contraints are given for the types, assume all types are
1094 if ((mask & GST_PAD_PROBE_TYPE_DATA) == 0)
1095 mask |= GST_PAD_PROBE_TYPE_DATA;
1096 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1097 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1099 /* store our flags and other fields */
1100 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1101 hook->func = callback;
1102 hook->data = user_data;
1103 hook->destroy = destroy_data;
1104 PROBE_COOKIE (hook) = 0;
1106 /* incremenent cookie so that the new hook get's called */
1107 pad->priv->probe_cookie++;
1110 g_hook_prepend (&pad->probes, hook);
1113 /* get the id of the hook, we return this and it can be used to remove the
1115 res = hook->hook_id;
1117 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1119 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1120 /* we have a block probe */
1122 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKED);
1123 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1124 "now %d blocking probes", pad->num_blocked);
1127 /* call the callback if we need to be called for idle callbacks */
1128 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1129 if (pad->priv->using > 0) {
1130 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1131 * flag above, the last thread to leave the push will do the callback. New
1132 * threads going into the push will block. */
1133 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1134 "pad is in use, delay idle callback");
1135 GST_OBJECT_UNLOCK (pad);
1137 /* the pad is idle now, we can signal the idle callback now */
1138 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1139 "pad is idle, trigger idle callback");
1140 GST_OBJECT_UNLOCK (pad);
1142 callback (pad, GST_PAD_PROBE_TYPE_IDLE, NULL, user_data);
1145 GST_OBJECT_UNLOCK (pad);
1151 GST_CAT_INFO_OBJECT (GST_CAT_SCHEDULING, pad, "pad block on the wrong pad, "
1152 "block src pads in push mode and sink pads in pull mode.");
1153 GST_OBJECT_UNLOCK (pad);
1160 cleanup_hook (GstPad * pad, GHook * hook)
1162 GstPadProbeType type;
1164 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1166 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1167 /* unblock when we remove the last blocking probe */
1169 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1171 if (pad->num_blocked == 0) {
1172 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1173 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKED);
1174 GST_PAD_BLOCK_BROADCAST (pad);
1177 g_hook_destroy_link (&pad->probes, hook);
1182 * gst_pad_remove_probe:
1183 * @pad: the #GstPad with the probe
1184 * @id: the probe id to remove
1186 * Remove the probe with @id from @pad.
1191 gst_pad_remove_probe (GstPad * pad, gulong id)
1195 g_return_if_fail (GST_IS_PAD (pad));
1197 GST_OBJECT_LOCK (pad);
1199 hook = g_hook_get (&pad->probes, id);
1203 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1205 cleanup_hook (pad, hook);
1206 GST_OBJECT_UNLOCK (pad);
1212 GST_OBJECT_UNLOCK (pad);
1213 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1219 * gst_pad_is_blocked:
1220 * @pad: the #GstPad to query
1222 * Checks if the pad is blocked or not. This function returns the
1223 * last requested state of the pad. It is not certain that the pad
1224 * is actually blocking at this point (see gst_pad_is_blocking()).
1226 * Returns: TRUE if the pad is blocked.
1231 gst_pad_is_blocked (GstPad * pad)
1233 gboolean result = FALSE;
1235 g_return_val_if_fail (GST_IS_PAD (pad), result);
1237 GST_OBJECT_LOCK (pad);
1238 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED);
1239 GST_OBJECT_UNLOCK (pad);
1245 * gst_pad_is_blocking:
1246 * @pad: the #GstPad to query
1248 * Checks if the pad is blocking or not. This is a guaranteed state
1249 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1251 * Returns: TRUE if the pad is blocking.
1258 gst_pad_is_blocking (GstPad * pad)
1260 gboolean result = FALSE;
1262 g_return_val_if_fail (GST_IS_PAD (pad), result);
1264 GST_OBJECT_LOCK (pad);
1265 /* the blocking flag is only valid if the pad is not flushing */
1266 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKING) &&
1267 !GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLUSHING);
1268 GST_OBJECT_UNLOCK (pad);
1274 * gst_pad_check_reconfigure:
1275 * @pad: the #GstPad to check
1277 * Check and clear the #GST_PAD_NEED_RECONFIGURE flag on @pad and return %TRUE
1278 * if the flag was set.
1280 * Returns: %TRUE is the GST_PAD_NEED_RECONFIGURE flag was set on @pad.
1283 gst_pad_check_reconfigure (GstPad * pad)
1285 gboolean reconfigure;
1287 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1289 GST_OBJECT_LOCK (pad);
1290 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1291 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_RECONFIGURE);
1292 GST_OBJECT_UNLOCK (pad);
1298 * gst_pad_mark_reconfigure:
1299 * @pad: the #GstPad to mark
1301 * Mark a pad for needing reconfiguration. The next call to
1302 * gst_pad_check_reconfigure() will return %TRUE after this call.
1305 gst_pad_mark_reconfigure (GstPad * pad)
1307 g_return_if_fail (GST_IS_PAD (pad));
1309 GST_OBJECT_LOCK (pad);
1310 GST_OBJECT_FLAG_SET (pad, GST_PAD_NEED_RECONFIGURE);
1311 GST_OBJECT_UNLOCK (pad);
1315 * gst_pad_set_activate_function:
1317 * @activate: the #GstPadActivateFunction to set.
1319 * Sets the given activate function for @pad. The activate function will
1320 * dispatch to gst_pad_activate_push() or gst_pad_activate_pull() to perform
1321 * the actual activation. Only makes sense to set on sink pads.
1323 * Call this function if your sink pad can start a pull-based task.
1326 gst_pad_set_activate_function (GstPad * pad, GstPadActivateFunction activate)
1328 g_return_if_fail (GST_IS_PAD (pad));
1330 GST_PAD_ACTIVATEFUNC (pad) = activate;
1331 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1332 GST_DEBUG_FUNCPTR_NAME (activate));
1336 * gst_pad_set_activatepull_function:
1338 * @activatepull: the #GstPadActivateModeFunction to set.
1340 * Sets the given activate_pull function for the pad. An activate_pull function
1341 * prepares the element and any upstream connections for pulling. See XXX
1342 * part-activation.txt for details.
1345 gst_pad_set_activatepull_function (GstPad * pad,
1346 GstPadActivateModeFunction activatepull)
1348 g_return_if_fail (GST_IS_PAD (pad));
1350 GST_PAD_ACTIVATEPULLFUNC (pad) = activatepull;
1351 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatepullfunc set to %s",
1352 GST_DEBUG_FUNCPTR_NAME (activatepull));
1356 * gst_pad_set_activatepush_function:
1358 * @activatepush: the #GstPadActivateModeFunction to set.
1360 * Sets the given activate_push function for the pad. An activate_push function
1361 * prepares the element for pushing. See XXX part-activation.txt for details.
1364 gst_pad_set_activatepush_function (GstPad * pad,
1365 GstPadActivateModeFunction activatepush)
1367 g_return_if_fail (GST_IS_PAD (pad));
1369 GST_PAD_ACTIVATEPUSHFUNC (pad) = activatepush;
1370 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatepushfunc set to %s",
1371 GST_DEBUG_FUNCPTR_NAME (activatepush));
1375 * gst_pad_set_chain_function:
1376 * @pad: a sink #GstPad.
1377 * @chain: the #GstPadChainFunction to set.
1379 * Sets the given chain function for the pad. The chain function is called to
1380 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1383 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
1385 g_return_if_fail (GST_IS_PAD (pad));
1386 g_return_if_fail (GST_PAD_IS_SINK (pad));
1388 GST_PAD_CHAINFUNC (pad) = chain;
1389 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1390 GST_DEBUG_FUNCPTR_NAME (chain));
1394 * gst_pad_set_chain_list_function:
1395 * @pad: a sink #GstPad.
1396 * @chainlist: the #GstPadChainListFunction to set.
1398 * Sets the given chain list function for the pad. The chainlist function is
1399 * called to process a #GstBufferList input buffer list. See
1400 * #GstPadChainListFunction for more details.
1405 gst_pad_set_chain_list_function (GstPad * pad,
1406 GstPadChainListFunction chainlist)
1408 g_return_if_fail (GST_IS_PAD (pad));
1409 g_return_if_fail (GST_PAD_IS_SINK (pad));
1411 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1412 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1413 GST_DEBUG_FUNCPTR_NAME (chainlist));
1417 * gst_pad_set_getrange_function:
1418 * @pad: a source #GstPad.
1419 * @get: the #GstPadGetRangeFunction to set.
1421 * Sets the given getrange function for the pad. The getrange function is
1422 * called to produce a new #GstBuffer to start the processing pipeline. see
1423 * #GstPadGetRangeFunction for a description of the getrange function.
1426 gst_pad_set_getrange_function (GstPad * pad, GstPadGetRangeFunction get)
1428 g_return_if_fail (GST_IS_PAD (pad));
1429 g_return_if_fail (GST_PAD_IS_SRC (pad));
1431 GST_PAD_GETRANGEFUNC (pad) = get;
1433 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1434 GST_DEBUG_FUNCPTR_NAME (get));
1438 * gst_pad_set_event_function:
1439 * @pad: a #GstPad of either direction.
1440 * @event: the #GstPadEventFunction to set.
1442 * Sets the given event handler for the pad.
1445 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
1447 g_return_if_fail (GST_IS_PAD (pad));
1449 GST_PAD_EVENTFUNC (pad) = event;
1451 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1452 GST_DEBUG_FUNCPTR_NAME (event));
1456 * gst_pad_set_query_function:
1457 * @pad: a #GstPad of either direction.
1458 * @query: the #GstPadQueryFunction to set.
1460 * Set the given query function for the pad.
1463 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
1465 g_return_if_fail (GST_IS_PAD (pad));
1467 GST_PAD_QUERYFUNC (pad) = query;
1469 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1470 GST_DEBUG_FUNCPTR_NAME (query));
1474 * gst_pad_set_query_type_function:
1475 * @pad: a #GstPad of either direction.
1476 * @type_func: the #GstPadQueryTypeFunction to set.
1478 * Set the given query type function for the pad.
1481 gst_pad_set_query_type_function (GstPad * pad,
1482 GstPadQueryTypeFunction type_func)
1484 g_return_if_fail (GST_IS_PAD (pad));
1486 GST_PAD_QUERYTYPEFUNC (pad) = type_func;
1488 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "querytypefunc set to %s",
1489 GST_DEBUG_FUNCPTR_NAME (type_func));
1493 * gst_pad_get_query_types:
1496 * Get an array of supported queries that can be performed
1499 * Returns: (transfer none) (array zero-terminated=1): a zero-terminated array
1502 const GstQueryType *
1503 gst_pad_get_query_types (GstPad * pad)
1505 GstPadQueryTypeFunction func;
1507 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1509 if (G_UNLIKELY ((func = GST_PAD_QUERYTYPEFUNC (pad)) == NULL))
1521 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
1525 if ((peer = gst_pad_get_peer (pad))) {
1526 *data = gst_pad_get_query_types (peer);
1527 gst_object_unref (peer);
1533 * gst_pad_get_query_types_default:
1536 * Invoke the default query types function on the pad. This function will get
1537 * the supported query type from the peer of an internally linked pad of @pad.
1539 * Returns: (transfer none) (array zero-terminated=1): a zero-terminated array
1540 * of #GstQueryType, or NULL if none of the internally-linked pads has a
1541 * query types function.
1543 const GstQueryType *
1544 gst_pad_get_query_types_default (GstPad * pad)
1546 GstQueryType *result = NULL;
1548 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1550 gst_pad_forward (pad, (GstPadForwardFunction)
1551 gst_pad_get_query_types_dispatcher, &result);
1557 * gst_pad_set_iterate_internal_links_function:
1558 * @pad: a #GstPad of either direction.
1559 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1561 * Sets the given internal link iterator function for the pad.
1566 gst_pad_set_iterate_internal_links_function (GstPad * pad,
1567 GstPadIterIntLinkFunction iterintlink)
1569 g_return_if_fail (GST_IS_PAD (pad));
1571 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1572 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1573 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1577 * gst_pad_set_link_function:
1579 * @link: the #GstPadLinkFunction to set.
1581 * Sets the given link function for the pad. It will be called when
1582 * the pad is linked with another pad.
1584 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1587 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1588 * cannot be made for some reason.
1590 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1591 * of the peer sink pad, if present.
1594 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
1596 g_return_if_fail (GST_IS_PAD (pad));
1598 GST_PAD_LINKFUNC (pad) = link;
1599 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1600 GST_DEBUG_FUNCPTR_NAME (link));
1604 * gst_pad_set_unlink_function:
1606 * @unlink: the #GstPadUnlinkFunction to set.
1608 * Sets the given unlink function for the pad. It will be called
1609 * when the pad is unlinked.
1612 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
1614 g_return_if_fail (GST_IS_PAD (pad));
1616 GST_PAD_UNLINKFUNC (pad) = unlink;
1617 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1618 GST_DEBUG_FUNCPTR_NAME (unlink));
1622 * gst_pad_set_getcaps_function:
1624 * @getcaps: the #GstPadGetCapsFunction to set.
1626 * Sets the given getcaps function for the pad. @getcaps should return the
1627 * allowable caps for a pad in the context of the element's state, its link to
1628 * other elements, and the devices or files it has opened. These caps must be a
1629 * subset of the pad template caps. In the NULL state with no links, @getcaps
1630 * should ideally return the same caps as the pad template. In rare
1631 * circumstances, an object property can affect the caps returned by @getcaps,
1632 * but this is discouraged.
1634 * You do not need to call this function if @pad's allowed caps are always the
1635 * same as the pad template caps. This can only be true if the padtemplate
1636 * has fixed simple caps.
1638 * For most filters, the caps returned by @getcaps is directly affected by the
1639 * allowed caps on other pads. For demuxers and decoders, the caps returned by
1640 * the srcpad's getcaps function is directly related to the stream data. Again,
1641 * @getcaps should return the most specific caps it reasonably can, since this
1642 * helps with autoplugging.
1644 * Note that the return value from @getcaps is owned by the caller, so the
1645 * caller should unref the caps after usage.
1648 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
1650 g_return_if_fail (GST_IS_PAD (pad));
1652 GST_PAD_GETCAPSFUNC (pad) = getcaps;
1653 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getcapsfunc set to %s",
1654 GST_DEBUG_FUNCPTR_NAME (getcaps));
1658 * gst_pad_set_acceptcaps_function:
1660 * @acceptcaps: the #GstPadAcceptCapsFunction to set.
1662 * Sets the given acceptcaps function for the pad. The acceptcaps function
1663 * will be called to check if the pad can accept the given caps. Setting the
1664 * acceptcaps function to NULL restores the default behaviour of allowing
1665 * any caps that matches the caps from gst_pad_get_caps().
1668 gst_pad_set_acceptcaps_function (GstPad * pad,
1669 GstPadAcceptCapsFunction acceptcaps)
1671 g_return_if_fail (GST_IS_PAD (pad));
1673 GST_PAD_ACCEPTCAPSFUNC (pad) = acceptcaps;
1674 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "acceptcapsfunc set to %s",
1675 GST_DEBUG_FUNCPTR_NAME (acceptcaps));
1679 * gst_pad_set_fixatecaps_function:
1681 * @fixatecaps: the #GstPadFixateCapsFunction to set.
1683 * Sets the given fixatecaps function for the pad. The fixatecaps function
1684 * will be called whenever the default values for a GstCaps needs to be
1688 gst_pad_set_fixatecaps_function (GstPad * pad,
1689 GstPadFixateCapsFunction fixatecaps)
1691 g_return_if_fail (GST_IS_PAD (pad));
1693 GST_PAD_FIXATECAPSFUNC (pad) = fixatecaps;
1694 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "fixatecapsfunc set to %s",
1695 GST_DEBUG_FUNCPTR_NAME (fixatecaps));
1700 * @srcpad: the source #GstPad to unlink.
1701 * @sinkpad: the sink #GstPad to unlink.
1703 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1704 * signal on both pads.
1706 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1707 * the pads were not linked together.
1712 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1714 gboolean result = FALSE;
1715 GstElement *parent = NULL;
1718 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1719 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1720 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1721 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1723 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1724 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1725 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1727 /* We need to notify the parent before taking any pad locks as the bin in
1728 * question might be waiting for a lock on the pad while holding its lock
1729 * that our message will try to take. */
1730 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1731 if (GST_IS_ELEMENT (parent)) {
1732 gst_element_post_message (parent,
1733 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1734 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1736 gst_object_unref (parent);
1741 GST_OBJECT_LOCK (srcpad);
1742 GST_OBJECT_LOCK (sinkpad);
1744 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1745 goto not_linked_together;
1747 if (GST_PAD_UNLINKFUNC (srcpad)) {
1748 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1750 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1751 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1754 /* first clear peers */
1755 GST_PAD_PEER (srcpad) = NULL;
1756 GST_PAD_PEER (sinkpad) = NULL;
1758 /* clear pending caps if any */
1759 for (i = 0; i < GST_EVENT_MAX_STICKY; i++)
1760 gst_event_replace (&sinkpad->priv->events[i].pending, NULL);
1762 GST_OBJECT_UNLOCK (sinkpad);
1763 GST_OBJECT_UNLOCK (srcpad);
1765 /* fire off a signal to each of the pads telling them
1766 * that they've been unlinked */
1767 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1768 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1770 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1771 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1776 if (parent != NULL) {
1777 gst_element_post_message (parent,
1778 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1779 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1780 gst_object_unref (parent);
1785 not_linked_together:
1787 /* we do not emit a warning in this case because unlinking cannot
1788 * be made MT safe.*/
1789 GST_OBJECT_UNLOCK (sinkpad);
1790 GST_OBJECT_UNLOCK (srcpad);
1796 * gst_pad_is_linked:
1797 * @pad: pad to check
1799 * Checks if a @pad is linked to another pad or not.
1801 * Returns: TRUE if the pad is linked, FALSE otherwise.
1806 gst_pad_is_linked (GstPad * pad)
1810 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1812 GST_OBJECT_LOCK (pad);
1813 result = (GST_PAD_PEER (pad) != NULL);
1814 GST_OBJECT_UNLOCK (pad);
1819 /* get the caps from both pads and see if the intersection
1822 * This function should be called with the pad LOCK on both
1826 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1827 GstPadLinkCheck flags)
1829 GstCaps *srccaps = NULL;
1830 GstCaps *sinkcaps = NULL;
1831 gboolean compatible = FALSE;
1833 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1836 /* Doing the expensive caps checking takes priority over only checking the template caps */
1837 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1838 srccaps = gst_pad_get_caps_unlocked (src, NULL);
1839 sinkcaps = gst_pad_get_caps_unlocked (sink, NULL);
1841 /* If one of the two pads doesn't have a template, consider the intersection
1843 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
1844 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
1848 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
1850 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
1853 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
1855 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
1858 /* if we have caps on both pads we can check the intersection. If one
1859 * of the caps is NULL, we return TRUE. */
1860 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1862 gst_caps_unref (srccaps);
1864 gst_caps_unref (sinkcaps);
1868 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
1869 gst_caps_unref (srccaps);
1870 gst_caps_unref (sinkcaps);
1873 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
1874 (compatible ? "" : "not"));
1879 /* check if the grandparents of both pads are the same.
1880 * This check is required so that we don't try to link
1881 * pads from elements in different bins without ghostpads.
1883 * The LOCK should be held on both pads
1886 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1888 GstObject *psrc, *psink;
1890 psrc = GST_OBJECT_PARENT (src);
1891 psink = GST_OBJECT_PARENT (sink);
1893 /* if one of the pads has no parent, we allow the link */
1894 if (G_UNLIKELY (psrc == NULL || psink == NULL))
1897 /* only care about parents that are elements */
1898 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
1899 goto no_element_parent;
1901 /* if the parents are the same, we have a loop */
1902 if (G_UNLIKELY (psrc == psink))
1905 /* if they both have a parent, we check the grandparents. We can not lock
1906 * the parent because we hold on the child (pad) and the locking order is
1907 * parent >> child. */
1908 psrc = GST_OBJECT_PARENT (psrc);
1909 psink = GST_OBJECT_PARENT (psink);
1911 /* if they have grandparents but they are not the same */
1912 if (G_UNLIKELY (psrc != psink))
1913 goto wrong_grandparents;
1920 GST_CAT_DEBUG (GST_CAT_CAPS,
1921 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
1922 GST_PTR_FORMAT, psrc, psink);
1927 GST_CAT_DEBUG (GST_CAT_CAPS,
1928 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
1929 GST_PTR_FORMAT, psrc, psink);
1934 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1940 GST_CAT_DEBUG (GST_CAT_CAPS,
1941 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1942 GST_PTR_FORMAT, psrc, psink);
1947 /* FIXME leftover from an attempt at refactoring... */
1948 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
1949 * the two pads will be locked in the srcpad, sinkpad order. */
1950 static GstPadLinkReturn
1951 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
1953 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1954 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1956 GST_OBJECT_LOCK (srcpad);
1958 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1959 goto src_was_linked;
1961 GST_OBJECT_LOCK (sinkpad);
1963 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1964 goto sink_was_linked;
1966 /* check hierarchy, pads can only be linked if the grandparents
1968 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
1969 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
1970 goto wrong_hierarchy;
1972 /* check pad caps for non-empty intersection */
1973 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
1976 /* FIXME check pad scheduling for non-empty intersection */
1978 return GST_PAD_LINK_OK;
1982 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
1983 GST_DEBUG_PAD_NAME (srcpad),
1984 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
1985 /* we do not emit a warning in this case because unlinking cannot
1986 * be made MT safe.*/
1987 GST_OBJECT_UNLOCK (srcpad);
1988 return GST_PAD_LINK_WAS_LINKED;
1992 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
1993 GST_DEBUG_PAD_NAME (sinkpad),
1994 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
1995 /* we do not emit a warning in this case because unlinking cannot
1996 * be made MT safe.*/
1997 GST_OBJECT_UNLOCK (sinkpad);
1998 GST_OBJECT_UNLOCK (srcpad);
1999 return GST_PAD_LINK_WAS_LINKED;
2003 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
2004 GST_OBJECT_UNLOCK (sinkpad);
2005 GST_OBJECT_UNLOCK (srcpad);
2006 return GST_PAD_LINK_WRONG_HIERARCHY;
2010 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
2011 GST_OBJECT_UNLOCK (sinkpad);
2012 GST_OBJECT_UNLOCK (srcpad);
2013 return GST_PAD_LINK_NOFORMAT;
2019 * @srcpad: the source #GstPad.
2020 * @sinkpad: the sink #GstPad.
2022 * Checks if the source pad and the sink pad are compatible so they can be
2025 * Returns: TRUE if the pads can be linked.
2028 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
2030 GstPadLinkReturn result;
2032 /* generic checks */
2033 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2034 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2036 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
2037 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2039 /* gst_pad_link_prepare does everything for us, we only release the locks
2040 * on the pads that it gets us. If this function returns !OK the locks are not
2042 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2043 if (result != GST_PAD_LINK_OK)
2046 GST_OBJECT_UNLOCK (srcpad);
2047 GST_OBJECT_UNLOCK (sinkpad);
2050 return result == GST_PAD_LINK_OK;
2054 * gst_pad_link_full:
2055 * @srcpad: the source #GstPad to link.
2056 * @sinkpad: the sink #GstPad to link.
2057 * @flags: the checks to validate when linking
2059 * Links the source pad and the sink pad.
2061 * This variant of #gst_pad_link provides a more granular control on the
2062 * checks being done when linking. While providing some considerable speedups
2063 * the caller of this method must be aware that wrong usage of those flags
2064 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
2065 * for more information.
2069 * Returns: A result code indicating if the connection worked or
2075 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
2077 GstPadLinkReturn result;
2079 GstPadLinkFunction srcfunc, sinkfunc;
2081 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
2082 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
2083 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
2084 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
2085 GST_PAD_LINK_WRONG_DIRECTION);
2087 /* Notify the parent early. See gst_pad_unlink for details. */
2088 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
2089 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
2090 gst_element_post_message (parent,
2091 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2092 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
2094 gst_object_unref (parent);
2099 /* prepare will also lock the two pads */
2100 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
2102 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2105 /* must set peers before calling the link function */
2106 GST_PAD_PEER (srcpad) = sinkpad;
2107 GST_PAD_PEER (sinkpad) = srcpad;
2109 /* make sure we update events */
2110 prepare_event_update (srcpad, sinkpad);
2112 /* get the link functions */
2113 srcfunc = GST_PAD_LINKFUNC (srcpad);
2114 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
2116 if (G_UNLIKELY (srcfunc || sinkfunc)) {
2117 /* custom link functions, execute them */
2118 GST_OBJECT_UNLOCK (sinkpad);
2119 GST_OBJECT_UNLOCK (srcpad);
2122 /* this one will call the peer link function */
2123 result = srcfunc (srcpad, sinkpad);
2124 } else if (sinkfunc) {
2125 /* if no source link function, we need to call the sink link
2126 * function ourselves. */
2127 result = sinkfunc (sinkpad, srcpad);
2130 GST_OBJECT_LOCK (srcpad);
2131 GST_OBJECT_LOCK (sinkpad);
2133 /* we released the lock, check if the same pads are linked still */
2134 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2135 goto concurrent_link;
2137 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2140 GST_OBJECT_UNLOCK (sinkpad);
2141 GST_OBJECT_UNLOCK (srcpad);
2143 /* fire off a signal to each of the pads telling them
2144 * that they've been linked */
2145 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2146 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2148 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2149 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2151 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2154 if (G_LIKELY (parent)) {
2155 gst_element_post_message (parent,
2156 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2157 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2158 gst_object_unref (parent);
2166 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2167 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2168 GST_OBJECT_UNLOCK (sinkpad);
2169 GST_OBJECT_UNLOCK (srcpad);
2171 /* The other link operation succeeded first */
2172 result = GST_PAD_LINK_WAS_LINKED;
2177 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2178 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2180 GST_PAD_PEER (srcpad) = NULL;
2181 GST_PAD_PEER (sinkpad) = NULL;
2183 GST_OBJECT_UNLOCK (sinkpad);
2184 GST_OBJECT_UNLOCK (srcpad);
2192 * @srcpad: the source #GstPad to link.
2193 * @sinkpad: the sink #GstPad to link.
2195 * Links the source pad and the sink pad.
2197 * Returns: A result code indicating if the connection worked or
2203 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2205 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2209 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2211 GstPadTemplate **template_p;
2213 /* this function would need checks if it weren't static */
2215 GST_OBJECT_LOCK (pad);
2216 template_p = &pad->padtemplate;
2217 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2218 GST_OBJECT_UNLOCK (pad);
2221 gst_pad_template_pad_created (templ, pad);
2225 * gst_pad_get_pad_template:
2228 * Gets the template for @pad.
2230 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2231 * instantiated, or %NULL if this pad has no template. Unref after
2235 gst_pad_get_pad_template (GstPad * pad)
2237 GstPadTemplate *templ;
2239 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2241 templ = GST_PAD_PAD_TEMPLATE (pad);
2243 return (templ ? gst_object_ref (templ) : NULL);
2247 caps_with_getcaps (GstPad * pad, GstCaps * filter)
2251 if (GST_PAD_GETCAPSFUNC (pad) == NULL)
2254 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2255 "dispatching to pad getcaps function with "
2256 "filter %" GST_PTR_FORMAT, filter);
2258 GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_GETCAPS);
2259 GST_OBJECT_UNLOCK (pad);
2260 result = GST_PAD_GETCAPSFUNC (pad) (pad, filter);
2261 GST_OBJECT_LOCK (pad);
2262 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_GETCAPS);
2264 if (G_UNLIKELY (result == NULL))
2267 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2268 "pad getcaps returned %" GST_PTR_FORMAT, result);
2270 #ifndef G_DISABLE_ASSERT
2271 /* check that the returned caps are a real subset of the template caps */
2272 if (GST_PAD_PAD_TEMPLATE (pad)) {
2273 const GstCaps *templ_caps =
2274 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2275 if (!gst_caps_is_subset (result, templ_caps)) {
2278 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
2279 "pad returned caps %" GST_PTR_FORMAT
2280 " which are not a real subset of its template caps %"
2281 GST_PTR_FORMAT, result, templ_caps);
2283 ("pad %s:%s returned caps which are not a real "
2284 "subset of its template caps", GST_DEBUG_PAD_NAME (pad));
2285 temp = gst_caps_intersect (templ_caps, result);
2286 gst_caps_unref (result);
2291 if (!gst_caps_is_subset (result, filter)) {
2294 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
2295 "pad returned caps %" GST_PTR_FORMAT
2296 " which are not a real subset of the filter caps %"
2297 GST_PTR_FORMAT, result, filter);
2298 g_warning ("pad %s:%s returned caps which are not a real "
2299 "subset of the filter caps", GST_DEBUG_PAD_NAME (pad));
2300 /* FIXME: Order? But shouldn't happen anyway... */
2301 temp = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2302 gst_caps_unref (result);
2313 g_critical ("pad %s:%s returned NULL caps from getcaps function",
2314 GST_DEBUG_PAD_NAME (pad));
2319 /* should be called with the pad LOCK held */
2320 /* refs the caps, so caller is responsible for getting it unreffed */
2322 gst_pad_get_caps_unlocked (GstPad * pad, GstCaps * filter)
2324 GstCaps *result = NULL;
2325 GstPadTemplate *templ;
2326 gboolean fixed_caps;
2328 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2330 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2333 /* fixed caps, try the negotiated caps first */
2334 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2335 if ((result = get_pad_caps (pad)))
2339 /* try the getcaps function next */
2340 if ((result = caps_with_getcaps (pad, filter)))
2343 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2344 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2345 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2350 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2351 "non-fixed pad caps: trying pad caps");
2352 /* non fixed caps, try the negotiated caps */
2353 if ((result = get_pad_caps (pad)))
2357 /* this almost never happens */
2358 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2359 result = gst_caps_new_empty ();
2363 /* run the filter on the result */
2365 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2366 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2367 GST_PTR_FORMAT, result, result, filter, filter);
2368 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2369 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2372 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2373 "using caps %p %" GST_PTR_FORMAT, result, result);
2374 result = gst_caps_ref (result);
2381 * gst_pad_has_current_caps:
2382 * @pad: a #GstPad to check
2384 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2386 * Returns: TRUE when @pad has caps associated with it.
2389 gst_pad_has_current_caps (GstPad * pad)
2394 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2396 GST_OBJECT_LOCK (pad);
2397 caps = get_pad_caps (pad);
2398 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2399 "check current pad caps %" GST_PTR_FORMAT, caps);
2400 result = (caps != NULL);
2401 GST_OBJECT_UNLOCK (pad);
2407 * gst_pad_get_current_caps:
2408 * @pad: a #GstPad to get the current capabilities of.
2410 * Gets the capabilities currently configured on @pad with the last
2411 * #GST_EVENT_CAPS event.
2413 * Returns: the current caps of the pad with incremented ref-count.
2416 gst_pad_get_current_caps (GstPad * pad)
2420 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2422 GST_OBJECT_LOCK (pad);
2423 if ((result = get_pad_caps (pad)))
2424 gst_caps_ref (result);
2425 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2426 "get current pad caps %" GST_PTR_FORMAT, result);
2427 GST_OBJECT_UNLOCK (pad);
2434 * @pad: a #GstPad to get the capabilities of.
2435 * @filter: suggested #GstCaps.
2437 * Gets the capabilities this pad can produce or consume.
2438 * Note that this method doesn't necessarily return the caps set by
2439 * gst_pad_set_caps() - use gst_pad_get_current_caps() for that instead.
2440 * gst_pad_get_caps returns all possible caps a pad can operate with, using
2441 * the pad's get_caps function;
2442 * this returns the pad template caps if not explicitly set.
2444 * When called on sinkpads @filter contains the caps that
2445 * upstream could produce in the order preferred by upstream. When
2446 * called on srcpads @filter contains the caps accepted by
2447 * downstream in the preffered order. @filter might be %NULL but
2448 * if it is not %NULL the returned caps will be a subset of @filter.
2450 * Note that this function does not return writable #GstCaps, use
2451 * gst_caps_make_writable() before modifying the caps.
2453 * Returns: (transfer full): the caps of the pad with incremented ref-count.
2456 gst_pad_get_caps (GstPad * pad, GstCaps * filter)
2458 GstCaps *result = NULL;
2460 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2461 g_return_val_if_fail (filter == NULL || GST_IS_CAPS (filter), NULL);
2463 GST_OBJECT_LOCK (pad);
2465 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2467 result = gst_pad_get_caps_unlocked (pad, filter);
2469 GST_OBJECT_UNLOCK (pad);
2476 * gst_pad_peer_get_caps:
2477 * @pad: a #GstPad to get the capabilities of.
2478 * @filter: a #GstCaps filter.
2480 * Gets the capabilities of the peer connected to this pad. Similar to
2481 * gst_pad_get_caps().
2483 * When called on srcpads @filter contains the caps that
2484 * upstream could produce in the order preferred by upstream. When
2485 * called on sinkpads @filter contains the caps accepted by
2486 * downstream in the preffered order. @filter might be %NULL but
2487 * if it is not %NULL the returned caps will be a subset of @filter.
2489 * Returns: the caps of the peer pad with incremented ref-count. This function
2490 * returns %NULL when there is no peer pad.
2493 gst_pad_peer_get_caps (GstPad * pad, GstCaps * filter)
2496 GstCaps *result = NULL;
2498 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2499 g_return_val_if_fail (filter == NULL || GST_IS_CAPS (filter), NULL);
2501 GST_OBJECT_LOCK (pad);
2503 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get peer caps");
2505 peerpad = GST_PAD_PEER (pad);
2506 if (G_UNLIKELY (peerpad == NULL))
2509 gst_object_ref (peerpad);
2510 GST_OBJECT_UNLOCK (pad);
2512 result = gst_pad_get_caps (peerpad, filter);
2514 gst_object_unref (peerpad);
2520 GST_OBJECT_UNLOCK (pad);
2526 gst_pad_fixate_caps_default (GstPad * pad, GstCaps * caps)
2528 /* default fixation */
2529 gst_caps_fixate (caps);
2533 * gst_pad_fixate_caps:
2534 * @pad: a #GstPad to fixate
2535 * @caps: the #GstCaps to fixate
2537 * Fixate a caps on the given pad. Modifies the caps in place, so you should
2538 * make sure that the caps are actually writable (see gst_caps_make_writable()).
2541 gst_pad_fixate_caps (GstPad * pad, GstCaps * caps)
2543 GstPadFixateCapsFunction fixatefunc;
2545 g_return_if_fail (GST_IS_PAD (pad));
2546 g_return_if_fail (caps != NULL);
2547 g_return_if_fail (!gst_caps_is_empty (caps));
2548 g_return_if_fail (!gst_caps_is_any (caps));
2550 if (gst_caps_is_fixed (caps) || gst_caps_is_any (caps))
2553 g_return_if_fail (gst_caps_is_writable (caps));
2555 if (G_LIKELY ((fixatefunc = GST_PAD_FIXATECAPSFUNC (pad))))
2556 fixatefunc (pad, caps);
2559 /* Default accept caps implementation just checks against
2560 * against the allowed caps for the pad */
2562 gst_pad_acceptcaps_default (GstPad * pad, GstCaps * caps)
2564 /* get the caps and see if it intersects to something not empty */
2566 gboolean result = FALSE;
2568 GST_DEBUG_OBJECT (pad, "caps %" GST_PTR_FORMAT, caps);
2570 allowed = gst_pad_get_caps (pad, NULL);
2572 goto nothing_allowed;
2574 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
2576 result = gst_caps_is_subset (caps, allowed);
2578 gst_caps_unref (allowed);
2585 GST_DEBUG_OBJECT (pad, "no caps allowed on the pad");
2591 * gst_pad_accept_caps:
2592 * @pad: a #GstPad to check
2593 * @caps: a #GstCaps to check on the pad
2595 * Check if the given pad accepts the caps.
2597 * Returns: TRUE if the pad can accept the caps.
2600 gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
2603 GstPadAcceptCapsFunction acceptfunc;
2605 GstCaps *existing = NULL;
2608 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2610 /* any pad can be unnegotiated */
2614 /* lock for checking the existing caps */
2615 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "accept caps of %p", caps);
2617 GST_OBJECT_LOCK (pad);
2618 /* The current caps on a pad are trivially acceptable */
2619 if (G_LIKELY ((existing = GST_PAD_CAPS (pad)))) {
2620 if (caps == existing || gst_caps_is_equal (caps, existing))
2623 GST_OBJECT_UNLOCK (pad);
2625 acceptfunc = GST_PAD_ACCEPTCAPSFUNC (pad);
2627 /* Only null if the element explicitly unset it */
2628 if (G_UNLIKELY (acceptfunc == NULL))
2631 /* we can call the function */
2632 result = acceptfunc (pad, caps);
2633 GST_DEBUG_OBJECT (pad, "acceptfunc returned %d", result);
2640 GST_DEBUG_OBJECT (pad, "pad had same caps");
2641 GST_OBJECT_UNLOCK (pad);
2647 GST_DEBUG_OBJECT (pad, "no acceptcaps function");
2653 * gst_pad_peer_accept_caps:
2654 * @pad: a #GstPad to check the peer of
2655 * @caps: a #GstCaps to check on the pad
2657 * Check if the peer of @pad accepts @caps. If @pad has no peer, this function
2660 * Returns: TRUE if the peer of @pad can accept the caps or @pad has no peer.
2663 gst_pad_peer_accept_caps (GstPad * pad, GstCaps * caps)
2668 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2670 GST_OBJECT_LOCK (pad);
2672 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "peer accept caps of (%p)", pad);
2674 peerpad = GST_PAD_PEER (pad);
2675 if (G_UNLIKELY (peerpad == NULL))
2678 gst_object_ref (peerpad);
2679 /* release lock before calling external methods but keep ref to pad */
2680 GST_OBJECT_UNLOCK (pad);
2682 result = gst_pad_accept_caps (peerpad, caps);
2684 gst_object_unref (peerpad);
2690 GST_OBJECT_UNLOCK (pad);
2697 * @pad: a #GstPad to set the capabilities of.
2698 * @caps: (transfer none): a #GstCaps to set.
2700 * Sets the capabilities of this pad. The caps must be fixed. Any previous
2701 * caps on the pad will be unreffed. This function refs the caps so you should
2702 * unref if as soon as you don't need it anymore.
2703 * It is possible to set NULL caps, which will make the pad unnegotiated
2706 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
2707 * or bad parameters were provided to this function.
2712 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
2715 gboolean res = TRUE;
2717 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2718 g_return_val_if_fail (caps != NULL && gst_caps_is_fixed (caps), FALSE);
2720 event = gst_event_new_caps (caps);
2722 if (GST_PAD_IS_SRC (pad))
2723 res = gst_pad_push_event (pad, event);
2725 res = gst_pad_send_event (pad, event);
2731 do_event_function (GstPad * pad, GstEvent * event,
2732 GstPadEventFunction eventfunc, gboolean * caps_notify)
2734 gboolean result = TRUE, call_event = TRUE;
2735 GstCaps *caps, *old, *templ;
2737 switch (GST_EVENT_TYPE (event)) {
2738 case GST_EVENT_CAPS:
2740 /* backwards compatibility mode for caps */
2741 gst_event_parse_caps (event, &caps);
2743 /* See if pad accepts the caps */
2744 templ = gst_pad_get_pad_template_caps (pad);
2745 if (!gst_caps_is_subset (caps, templ))
2748 /* check if it changed */
2749 if ((old = gst_pad_get_current_caps (pad))) {
2750 call_event = !gst_caps_is_equal (caps, old);
2751 gst_caps_unref (old);
2754 *caps_notify = TRUE;
2755 gst_caps_unref (templ);
2763 GST_DEBUG_OBJECT (pad, "calling event function with event %p", event);
2764 result = eventfunc (pad, event);
2766 gst_event_unref (event);
2773 gst_caps_unref (templ);
2774 gst_event_unref (event);
2775 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2776 "caps %" GST_PTR_FORMAT " not accepted", caps);
2781 /* function to send all pending events on the sinkpad to the event
2782 * function and collect the results. This function should be called with
2783 * the object lock. The object lock might be released by this function.
2785 static GstFlowReturn
2786 gst_pad_update_events (GstPad * pad)
2788 GstFlowReturn ret = GST_FLOW_OK;
2790 GstPadEventFunction eventfunc;
2792 gboolean caps_notify = FALSE;
2794 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
2797 for (i = 0; i < GST_EVENT_MAX_STICKY; i++) {
2801 ev = &pad->priv->events[i];
2803 /* skip without pending event */
2804 if ((event = gst_event_steal (&ev->pending)) == NULL)
2807 gst_event_ref (event);
2808 GST_OBJECT_UNLOCK (pad);
2810 res = do_event_function (pad, event, eventfunc, &caps_notify);
2812 /* things could have changed while we release the lock, check if we still
2813 * are handling the same event, if we don't something changed and we have
2814 * to try again. FIXME. we need a cookie here. FIXME, we also want to remove
2815 * that lock eventually and then do the retry elsewhere. */
2818 /* make the event active */
2819 gst_event_take (&ev->event, event);
2821 /* notify caps change when needed */
2823 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
2824 caps_notify = FALSE;
2827 gst_event_unref (event);
2828 ret = GST_FLOW_ERROR;
2830 GST_OBJECT_LOCK (pad);
2832 /* when we get here all events were successfully updated. */
2838 g_warning ("pad %s:%s has no event handler, file a bug.",
2839 GST_DEBUG_PAD_NAME (pad));
2840 return GST_FLOW_NOT_SUPPORTED;
2845 * gst_pad_get_pad_template_caps:
2846 * @pad: a #GstPad to get the template capabilities from.
2848 * Gets the capabilities for @pad's template.
2850 * Returns: (transfer full): the #GstCaps of this pad template.
2851 * Unref after usage.
2854 gst_pad_get_pad_template_caps (GstPad * pad)
2856 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2858 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2860 if (GST_PAD_PAD_TEMPLATE (pad))
2861 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2863 return gst_static_caps_get (&anycaps);
2868 * @pad: a #GstPad to get the peer of.
2870 * Gets the peer of @pad. This function refs the peer pad so
2871 * you need to unref it after use.
2873 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2878 gst_pad_get_peer (GstPad * pad)
2882 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2884 GST_OBJECT_LOCK (pad);
2885 result = GST_PAD_PEER (pad);
2887 gst_object_ref (result);
2888 GST_OBJECT_UNLOCK (pad);
2894 * gst_pad_get_allowed_caps:
2897 * Gets the capabilities of the allowed media types that can flow through
2898 * @pad and its peer.
2900 * The allowed capabilities is calculated as the intersection of the results of
2901 * calling gst_pad_get_caps() on @pad and its peer. The caller owns a reference
2902 * on the resulting caps.
2904 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2905 * caps when you no longer need it. This function returns NULL when @pad
2911 gst_pad_get_allowed_caps (GstPad * pad)
2918 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2920 GST_OBJECT_LOCK (pad);
2921 peer = GST_PAD_PEER (pad);
2922 if (G_UNLIKELY (peer == NULL))
2925 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2927 gst_object_ref (peer);
2928 GST_OBJECT_UNLOCK (pad);
2929 mycaps = gst_pad_get_caps (pad, NULL);
2931 peercaps = gst_pad_get_caps (peer, NULL);
2932 gst_object_unref (peer);
2934 caps = gst_caps_intersect (mycaps, peercaps);
2935 gst_caps_unref (peercaps);
2936 gst_caps_unref (mycaps);
2938 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2945 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2946 GST_OBJECT_UNLOCK (pad);
2953 * gst_pad_iterate_internal_links_default:
2954 * @pad: the #GstPad to get the internal links of.
2956 * Iterate the list of pads to which the given pad is linked to inside of
2957 * the parent element.
2958 * This is the default handler, and thus returns an iterator of all of the
2959 * pads inside the parent element with opposite direction.
2961 * The caller must free this iterator after use with gst_iterator_free().
2963 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2964 * returned pad with gst_object_unref().
2969 gst_pad_iterate_internal_links_default (GstPad * pad)
2977 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2982 GST_OBJECT_LOCK (pad);
2983 parent = GST_PAD_PARENT (pad);
2984 if (!parent || !GST_IS_ELEMENT (parent))
2987 gst_object_ref (parent);
2988 GST_OBJECT_UNLOCK (pad);
2990 if (pad->direction == GST_PAD_SRC)
2991 padlist = &parent->sinkpads;
2993 padlist = &parent->srcpads;
2995 GST_DEBUG_OBJECT (pad, "Making iterator");
2997 cookie = &parent->pads_cookie;
2999 lock = GST_OBJECT_GET_LOCK (parent);
3002 res = gst_iterator_new_list (GST_TYPE_PAD,
3003 lock, cookie, padlist, (GObject *) owner, NULL);
3005 gst_object_unref (owner);
3012 GST_OBJECT_UNLOCK (pad);
3013 GST_DEBUG_OBJECT (pad, "no parent element");
3019 * gst_pad_iterate_internal_links:
3020 * @pad: the GstPad to get the internal links of.
3022 * Gets an iterator for the pads to which the given pad is linked to inside
3023 * of the parent element.
3025 * Each #GstPad element yielded by the iterator will have its refcount increased,
3026 * so unref after use.
3028 * Free-function: gst_iterator_free
3030 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
3031 * pad does not have an iterator function configured. Use
3032 * gst_iterator_free() after usage.
3037 gst_pad_iterate_internal_links (GstPad * pad)
3039 GstIterator *res = NULL;
3041 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3043 if (GST_PAD_ITERINTLINKFUNC (pad))
3044 res = GST_PAD_ITERINTLINKFUNC (pad) (pad);
3052 * @forward: a #GstPadForwardFunction
3053 * @user_data: user data passed to @forward
3055 * Calls @forward for all internally linked pads of @pad. This function deals with
3056 * dynamically changing internal pads and will make sure that the @forward
3057 * function is only called once for each pad.
3059 * When @forward returns TRUE, no further pads will be processed.
3061 * Returns: TRUE if one of the dispatcher functions returned TRUE.
3064 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
3067 gboolean result = FALSE;
3069 gboolean done = FALSE;
3070 GValue item = { 0, };
3071 GList *pushed_pads = NULL;
3073 iter = gst_pad_iterate_internal_links (pad);
3079 switch (gst_iterator_next (iter, &item)) {
3080 case GST_ITERATOR_OK:
3084 intpad = g_value_get_object (&item);
3086 /* if already pushed, skip. FIXME, find something faster to tag pads */
3087 if (g_list_find (pushed_pads, intpad)) {
3088 g_value_reset (&item);
3092 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
3093 GST_DEBUG_PAD_NAME (intpad));
3094 done = result = forward (intpad, user_data);
3096 pushed_pads = g_list_prepend (pushed_pads, intpad);
3098 g_value_reset (&item);
3101 case GST_ITERATOR_RESYNC:
3102 /* We don't reset the result here because we don't push the event
3103 * again on pads that got the event already and because we need
3104 * to consider the result of the previous pushes */
3105 gst_iterator_resync (iter);
3107 case GST_ITERATOR_ERROR:
3108 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
3111 case GST_ITERATOR_DONE:
3116 g_value_unset (&item);
3117 gst_iterator_free (iter);
3119 g_list_free (pushed_pads);
3129 gboolean dispatched;
3133 event_forward_func (GstPad * pad, EventData * data)
3135 /* for each pad we send to, we should ref the event; it's up
3136 * to downstream to unref again when handled. */
3137 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
3138 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
3140 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
3142 data->dispatched = TRUE;
3149 * gst_pad_event_default:
3150 * @pad: a #GstPad to call the default event handler on.
3151 * @event: (transfer full): the #GstEvent to handle.
3153 * Invokes the default event handler for the given pad.
3155 * The EOS event will pause the task associated with @pad before it is forwarded
3156 * to all internally linked pads,
3158 * The CAPS event will never be forwarded.
3160 * The the event is sent to all pads internally linked to @pad. This function
3161 * takes ownership of @event.
3163 * Returns: TRUE if the event was sent successfully.
3166 gst_pad_event_default (GstPad * pad, GstEvent * event)
3171 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3172 g_return_val_if_fail (event != NULL, FALSE);
3174 GST_LOG_OBJECT (pad, "default event handler");
3176 switch (GST_EVENT_TYPE (event)) {
3179 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
3180 gst_pad_pause_task (pad);
3188 data.dispatched = FALSE;
3189 data.result = FALSE;
3191 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
3193 /* for sinkpads without a parent element or without internal links, nothing
3194 * will be dispatched but we still want to return TRUE. */
3195 if (data.dispatched)
3196 result = data.result;
3200 gst_event_unref (event);
3207 * @pad: a #GstPad to invoke the default query on.
3208 * @query: (transfer none): the #GstQuery to perform.
3210 * Dispatches a query to a pad. The query should have been allocated by the
3211 * caller via one of the type-specific allocation functions. The element that
3212 * the pad belongs to is responsible for filling the query with an appropriate
3213 * response, which should then be parsed with a type-specific query parsing
3216 * Again, the caller is responsible for both the allocation and deallocation of
3217 * the query structure.
3219 * Please also note that some queries might need a running pipeline to work.
3221 * Returns: TRUE if the query could be performed.
3224 gst_pad_query (GstPad * pad, GstQuery * query)
3227 GstPadQueryFunction func;
3229 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3230 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3232 GST_DEBUG_OBJECT (pad, "sending query %p (%s)", query,
3233 GST_QUERY_TYPE_NAME (query));
3235 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3238 res = func (pad, query);
3240 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3241 GST_QUERY_TYPE_NAME (query), res);
3247 GST_DEBUG_OBJECT (pad, "had no query function");
3253 * gst_pad_peer_query:
3254 * @pad: a #GstPad to invoke the peer query on.
3255 * @query: (transfer none): the #GstQuery to perform.
3257 * Performs gst_pad_query() on the peer of @pad.
3259 * The caller is responsible for both the allocation and deallocation of
3260 * the query structure.
3262 * Returns: TRUE if the query could be performed. This function returns %FALSE
3263 * if @pad has no peer.
3268 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3273 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3274 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3276 GST_OBJECT_LOCK (pad);
3278 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3279 GST_QUERY_TYPE_NAME (query));
3281 peerpad = GST_PAD_PEER (pad);
3282 if (G_UNLIKELY (peerpad == NULL))
3285 gst_object_ref (peerpad);
3286 GST_OBJECT_UNLOCK (pad);
3288 result = gst_pad_query (peerpad, query);
3290 gst_object_unref (peerpad);
3297 GST_WARNING_OBJECT (pad, "pad has no peer");
3298 GST_OBJECT_UNLOCK (pad);
3304 * gst_pad_query_default:
3305 * @pad: a #GstPad to call the default query handler on.
3306 * @query: (transfer none): the #GstQuery to handle.
3308 * Invokes the default query handler for the given pad.
3309 * The query is sent to all pads internally linked to @pad. Note that
3310 * if there are many possible sink pads that are internally linked to
3311 * @pad, only one will be sent the query.
3312 * Multi-sinkpad elements should implement custom query handlers.
3314 * Returns: TRUE if the query was performed successfully.
3317 gst_pad_query_default (GstPad * pad, GstQuery * query)
3319 gboolean forward = TRUE, ret = FALSE;
3321 switch (GST_QUERY_TYPE (query)) {
3322 case GST_QUERY_SCHEDULING:
3325 case GST_QUERY_POSITION:
3326 case GST_QUERY_SEEKING:
3327 case GST_QUERY_FORMATS:
3328 case GST_QUERY_LATENCY:
3329 case GST_QUERY_JITTER:
3330 case GST_QUERY_RATE:
3331 case GST_QUERY_CONVERT:
3332 case GST_QUERY_ALLOCATION:
3338 ret = gst_pad_forward
3339 (pad, (GstPadForwardFunction) gst_pad_peer_query, query);
3345 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3347 GstPad *pad = data->pad;
3348 GstPadProbeType flags;
3349 GstPadProbeCallback callback;
3350 GstPadProbeReturn ret;
3352 /* if we have called this callback, do nothing */
3353 if (PROBE_COOKIE (hook) == data->cookie)
3356 PROBE_COOKIE (hook) = data->cookie;
3358 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3360 /* one of the data types */
3361 if ((flags & GST_PAD_PROBE_TYPE_DATA & data->mask) == 0)
3363 /* one of the scheduling types */
3364 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & data->mask) == 0)
3366 /* all of the blocking types must match */
3367 if ((flags & GST_PAD_PROBE_TYPE_BLOCKING) !=
3368 (data->mask & GST_PAD_PROBE_TYPE_BLOCKING))
3371 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3372 "hook %lu with flags 0x%08x matches", hook->hook_id, flags);
3374 callback = (GstPadProbeCallback) hook->func;
3375 if (callback == NULL)
3378 GST_OBJECT_UNLOCK (pad);
3380 ret = callback (pad, data->mask, data->type_data, hook->data);
3382 GST_OBJECT_LOCK (pad);
3385 case GST_PAD_PROBE_REMOVE:
3386 /* remove the probe */
3387 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3388 cleanup_hook (pad, hook);
3390 case GST_PAD_PROBE_DROP:
3391 /* need to drop the data, make sure other probes don't get called
3393 GST_DEBUG_OBJECT (pad, "asked to drop item");
3394 data->mask = GST_PAD_PROBE_TYPE_INVALID;
3395 data->ret = GST_PAD_PROBE_DROP;
3397 case GST_PAD_PROBE_PASS:
3398 /* inform the pad block to let things pass */
3399 GST_DEBUG_OBJECT (pad, "asked to pass item");
3403 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3408 #define PROBE_FULL(pad,mask,data,label,defaultval) \
3410 if (G_UNLIKELY (pad->num_probes)) { \
3411 ret = do_probe_callbacks (pad, mask, data, defaultval); \
3412 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3417 #define PROBE(pad,mask,data,label) \
3418 PROBE_FULL(pad, mask, data, label, GST_FLOW_OK);
3420 static GstFlowReturn
3421 do_probe_callbacks (GstPad * pad, GstPadProbeType mask, gpointer type_data,
3422 GstFlowReturn defaultval)
3429 data.type_data = type_data;
3430 data.ret = GST_PAD_PROBE_OK;
3432 data.cookie = pad->priv->probe_cookie++;
3435 cookie = pad->priv->probe_cookie;
3437 g_hook_list_marshal (&pad->probes, FALSE,
3438 (GHookMarshaller) probe_hook_marshal, &data);
3440 /* if the list changed, call the new callbacks (they will not have their
3441 * cookie set to data.cookie */
3442 if (cookie != pad->priv->probe_cookie) {
3443 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3444 "probe list changed, restarting");
3448 if (data.ret == GST_PAD_PROBE_DROP)
3454 if (mask & GST_PAD_PROBE_TYPE_BLOCK) {
3455 while (GST_PAD_IS_BLOCKED (pad)) {
3456 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3457 "we are blocked %d times", pad->num_blocked);
3459 /* we might have released the lock */
3460 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3463 /* now we block the streaming thread. It can be unlocked when we
3464 * deactivate the pad (which will also set the FLUSHING flag) or
3465 * when the pad is unblocked. A flushing event will also unblock
3466 * the pad after setting the FLUSHING flag. */
3467 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3468 "Waiting to be unblocked or set flushing");
3469 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKING);
3470 GST_PAD_BLOCK_WAIT (pad);
3471 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKING);
3472 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3474 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3484 GST_DEBUG_OBJECT (pad, "pad is flushing");
3485 return GST_FLOW_WRONG_STATE;
3489 GST_DEBUG_OBJECT (pad, "data is dropped");
3490 return GST_FLOW_CUSTOM_SUCCESS;
3494 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3495 GST_DEBUG_OBJECT (pad, "data is passed");
3503 * gst_pad_get_offset:
3506 * Get the offset applied to the running time of @pad. @pad has to be a source
3509 * Returns: the offset.
3512 gst_pad_get_offset (GstPad * pad)
3516 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3518 GST_OBJECT_LOCK (pad);
3519 result = pad->offset;
3520 GST_OBJECT_UNLOCK (pad);
3526 * gst_pad_set_offset:
3528 * @offset: the offset
3530 * Set the offset that will be applied to the running time of @pad.
3533 gst_pad_set_offset (GstPad * pad, gint64 offset)
3539 g_return_if_fail (GST_IS_PAD (pad));
3541 GST_OBJECT_LOCK (pad);
3542 /* if nothing changed, do nothing */
3543 if (pad->offset == offset)
3546 pad->offset = offset;
3548 /* if no peer, we just updated the offset */
3549 if ((peer = GST_PAD_PEER (pad)) == NULL)
3552 /* switch pads around when dealing with a sinkpad */
3553 if (GST_PAD_IS_SINK (pad)) {
3554 /* ref the peer so it doesn't go away when we release the lock */
3555 tmp = gst_object_ref (peer);
3556 /* make sure we get the peer (the srcpad) */
3557 GST_OBJECT_UNLOCK (pad);
3563 GST_OBJECT_LOCK (pad);
3564 /* check if the pad didn't get relinked */
3565 if (GST_PAD_PEER (pad) != peer)
3568 /* we can release the ref now */
3569 gst_object_unref (peer);
3572 /* the index of the segment event in the array */
3573 idx = GST_EVENT_STICKY_IDX_TYPE (GST_EVENT_SEGMENT);
3575 /* lock order is srcpad >> sinkpad */
3576 GST_OBJECT_LOCK (peer);
3577 /* take the current segment event, adjust it and then place
3578 * it on the sinkpad. events on the srcpad are always active. */
3579 if (replace_event (pad, peer, idx))
3580 GST_OBJECT_FLAG_SET (peer, GST_PAD_NEED_EVENTS);
3582 GST_OBJECT_UNLOCK (peer);
3585 GST_OBJECT_UNLOCK (pad);
3589 /**********************************************************************
3590 * Data passing functions
3593 /* this is the chain function that does not perform the additional argument
3594 * checking for that little extra speed.
3596 static inline GstFlowReturn
3597 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3600 gboolean needs_events;
3602 GST_PAD_STREAM_LOCK (pad);
3604 GST_OBJECT_LOCK (pad);
3605 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3608 needs_events = GST_PAD_NEEDS_EVENTS (pad);
3609 if (G_UNLIKELY (needs_events)) {
3610 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_EVENTS);
3612 GST_DEBUG_OBJECT (pad, "need to update all events");
3613 ret = gst_pad_update_events (pad);
3614 if (G_UNLIKELY (ret != GST_FLOW_OK))
3618 PROBE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3620 PROBE (pad, type, data, probe_stopped);
3622 GST_OBJECT_UNLOCK (pad);
3624 /* NOTE: we read the chainfunc unlocked.
3625 * we cannot hold the lock for the pad so we might send
3626 * the data to the wrong function. This is not really a
3627 * problem since functions are assigned at creation time
3628 * and don't change that often... */
3629 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3630 GstPadChainFunction chainfunc;
3632 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3635 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3636 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3637 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3639 ret = chainfunc (pad, GST_BUFFER_CAST (data));
3641 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3642 "called chainfunction &%s with buffer %p, returned %s",
3643 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3645 GstPadChainListFunction chainlistfunc;
3647 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3650 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3651 "calling chainlistfunction &%s",
3652 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3654 ret = chainlistfunc (pad, GST_BUFFER_LIST_CAST (data));
3656 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3657 "called chainlistfunction &%s, returned %s",
3658 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3661 GST_PAD_STREAM_UNLOCK (pad);
3668 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3669 "chaining, but pad was flushing");
3670 GST_OBJECT_UNLOCK (pad);
3671 GST_PAD_STREAM_UNLOCK (pad);
3672 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3673 return GST_FLOW_WRONG_STATE;
3677 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "events were not accepted");
3678 GST_OBJECT_UNLOCK (pad);
3679 GST_PAD_STREAM_UNLOCK (pad);
3680 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3685 GST_OBJECT_UNLOCK (pad);
3686 GST_PAD_STREAM_UNLOCK (pad);
3687 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3690 case GST_FLOW_CUSTOM_SUCCESS:
3691 GST_DEBUG_OBJECT (pad, "dropped buffer");
3695 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
3702 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3703 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3704 "pushing, but not chainhandler");
3705 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3706 ("push on pad %s:%s but it has no chainfunction",
3707 GST_DEBUG_PAD_NAME (pad)));
3708 GST_PAD_STREAM_UNLOCK (pad);
3709 return GST_FLOW_NOT_SUPPORTED;
3715 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3716 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3719 * Chain a buffer to @pad.
3721 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
3723 * If the buffer type is not acceptable for @pad (as negotiated with a
3724 * preceeding GST_EVENT_CAPS event), this function returns
3725 * #GST_FLOW_NOT_NEGOTIATED.
3727 * The function proceeds calling the chain function installed on @pad (see
3728 * gst_pad_set_chain_function()) and the return value of that function is
3729 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3732 * In all cases, success or failure, the caller loses its reference to @buffer
3733 * after calling this function.
3735 * Returns: a #GstFlowReturn from the pad.
3740 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3742 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3743 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3744 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3746 return gst_pad_chain_data_unchecked (pad,
3747 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3750 static GstFlowReturn
3751 gst_pad_chain_list_default (GstPad * pad, GstBufferList * list)
3757 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3759 len = gst_buffer_list_length (list);
3762 for (i = 0; i < len; i++) {
3763 buffer = gst_buffer_list_get (list, i);
3765 gst_pad_chain_data_unchecked (pad,
3766 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3767 gst_buffer_ref (buffer));
3768 if (ret != GST_FLOW_OK)
3771 gst_buffer_list_unref (list);
3777 * gst_pad_chain_list:
3778 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3779 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3782 * Chain a bufferlist to @pad.
3784 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
3786 * If @pad was not negotiated properly with a CAPS event, this function
3787 * returns #GST_FLOW_NOT_NEGOTIATED.
3789 * The function proceeds calling the chainlist function installed on @pad (see
3790 * gst_pad_set_chain_list_function()) and the return value of that function is
3791 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3792 * chainlist function.
3794 * In all cases, success or failure, the caller loses its reference to @list
3795 * after calling this function.
3799 * Returns: a #GstFlowReturn from the pad.
3804 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3806 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3807 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3808 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3810 return gst_pad_chain_data_unchecked (pad,
3811 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3814 static GstFlowReturn
3815 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3820 GST_OBJECT_LOCK (pad);
3821 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3824 /* do block probes */
3825 PROBE (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3827 /* do post-blocking probes */
3828 PROBE (pad, type, data, probe_stopped);
3830 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3833 /* take ref to peer pad before releasing the lock */
3834 gst_object_ref (peer);
3836 GST_OBJECT_UNLOCK (pad);
3838 ret = gst_pad_chain_data_unchecked (peer, type, data);
3840 gst_object_unref (peer);
3842 GST_OBJECT_LOCK (pad);
3844 if (pad->priv->using == 0) {
3845 /* pad is not active anymore, trigger idle callbacks */
3846 PROBE_FULL (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE, NULL,
3847 probe_stopped, ret);
3849 GST_OBJECT_UNLOCK (pad);
3853 /* ERROR recovery here */
3857 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3858 "pushing, but pad was flushing");
3859 GST_OBJECT_UNLOCK (pad);
3860 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3861 return GST_FLOW_WRONG_STATE;
3865 GST_OBJECT_UNLOCK (pad);
3866 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3869 case GST_FLOW_CUSTOM_SUCCESS:
3870 GST_DEBUG_OBJECT (pad, "dropped buffer");
3874 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
3881 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3882 "pushing, but it was not linked");
3883 GST_OBJECT_UNLOCK (pad);
3884 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3885 return GST_FLOW_NOT_LINKED;
3891 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3892 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
3895 * Pushes a buffer to the peer of @pad.
3897 * This function will call installed block probes before triggering any
3898 * installed data probes.
3900 * The function proceeds calling gst_pad_chain() on the peer pad and returns
3901 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3904 * In all cases, success or failure, the caller loses its reference to @buffer
3905 * after calling this function.
3907 * Returns: a #GstFlowReturn from the peer pad.
3912 gst_pad_push (GstPad * pad, GstBuffer * buffer)
3914 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3915 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3916 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3918 return gst_pad_push_data (pad,
3919 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3923 * gst_pad_push_list:
3924 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3925 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
3928 * Pushes a buffer list to the peer of @pad.
3930 * This function will call installed block probes before triggering any
3931 * installed data probes.
3933 * The function proceeds calling the chain function on the peer pad and returns
3934 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3935 * be returned. If the peer pad does not have any installed chainlist function
3936 * every group buffer of the list will be merged into a normal #GstBuffer and
3937 * chained via gst_pad_chain().
3939 * In all cases, success or failure, the caller loses its reference to @list
3940 * after calling this function.
3942 * Returns: a #GstFlowReturn from the peer pad.
3949 gst_pad_push_list (GstPad * pad, GstBufferList * list)
3951 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3952 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3953 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3955 return gst_pad_push_data (pad,
3956 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3959 static GstFlowReturn
3960 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
3961 GstBuffer ** buffer)
3964 GstPadGetRangeFunction getrangefunc;
3966 GST_PAD_STREAM_LOCK (pad);
3968 GST_OBJECT_LOCK (pad);
3969 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3972 PROBE (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK, NULL,
3974 GST_OBJECT_UNLOCK (pad);
3976 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
3979 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3980 "calling getrangefunc %s, offset %"
3981 G_GUINT64_FORMAT ", size %u",
3982 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
3984 ret = getrangefunc (pad, offset, size, buffer);
3986 if (G_UNLIKELY (ret != GST_FLOW_OK))
3987 goto get_range_failed;
3989 /* can only fire the signal if we have a valid buffer */
3990 GST_OBJECT_LOCK (pad);
3991 PROBE (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER, *buffer,
3992 probe_stopped_unref);
3993 GST_OBJECT_UNLOCK (pad);
3995 GST_PAD_STREAM_UNLOCK (pad);
4002 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4003 "getrange, but pad was flushing");
4004 GST_OBJECT_UNLOCK (pad);
4005 GST_PAD_STREAM_UNLOCK (pad);
4006 return GST_FLOW_WRONG_STATE;
4010 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
4011 ("getrange on pad %s:%s but it has no getrangefunction",
4012 GST_DEBUG_PAD_NAME (pad)));
4013 GST_PAD_STREAM_UNLOCK (pad);
4014 return GST_FLOW_NOT_SUPPORTED;
4018 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4019 "probe returned %s", gst_flow_get_name (ret));
4020 GST_OBJECT_UNLOCK (pad);
4021 GST_PAD_STREAM_UNLOCK (pad);
4024 probe_stopped_unref:
4026 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4027 "probe returned %s", gst_flow_get_name (ret));
4028 GST_OBJECT_UNLOCK (pad);
4029 GST_PAD_STREAM_UNLOCK (pad);
4030 gst_buffer_unref (*buffer);
4036 GST_PAD_STREAM_UNLOCK (pad);
4038 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4039 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4040 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
4046 * gst_pad_get_range:
4047 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
4048 * @offset: The start offset of the buffer
4049 * @size: The length of the buffer
4050 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
4051 * returns #GST_FLOW_ERROR if %NULL.
4053 * When @pad is flushing this function returns #GST_FLOW_WRONG_STATE
4054 * immediately and @buffer is %NULL.
4056 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4057 * description of a getrange function. If @pad has no getrange function
4058 * installed (see gst_pad_set_getrange_function()) this function returns
4059 * #GST_FLOW_NOT_SUPPORTED.
4061 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
4063 * Returns: a #GstFlowReturn from the pad.
4068 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4069 GstBuffer ** buffer)
4071 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4072 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4073 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4075 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4079 * gst_pad_pull_range:
4080 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4081 * @offset: The start offset of the buffer
4082 * @size: The length of the buffer
4083 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4084 * GST_FLOW_ERROR if %NULL.
4086 * Pulls a @buffer from the peer pad.
4088 * This function will first trigger the pad block signal if it was
4091 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4092 * function returns the result of gst_pad_get_range() on the peer pad.
4093 * See gst_pad_get_range() for a list of return values and for the
4094 * semantics of the arguments of this function.
4096 * Returns: a #GstFlowReturn from the peer pad.
4097 * When this function returns #GST_FLOW_OK, @buffer will contain a valid
4098 * #GstBuffer that should be freed with gst_buffer_unref() after usage.
4099 * @buffer may not be used or freed when any other return value than
4100 * #GST_FLOW_OK is returned.
4105 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4106 GstBuffer ** buffer)
4110 gboolean needs_events;
4112 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4113 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4114 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4116 GST_OBJECT_LOCK (pad);
4117 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4120 PROBE (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK, NULL,
4123 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4126 gst_object_ref (peer);
4128 GST_OBJECT_UNLOCK (pad);
4130 ret = gst_pad_get_range_unchecked (peer, offset, size, buffer);
4132 gst_object_unref (peer);
4134 GST_OBJECT_LOCK (pad);
4136 if (pad->priv->using == 0) {
4137 /* pad is not active anymore, trigger idle callbacks */
4138 PROBE (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE, NULL,
4139 post_probe_stopped);
4142 if (G_UNLIKELY (ret != GST_FLOW_OK))
4143 goto pull_range_failed;
4145 PROBE (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER, buffer,
4146 post_probe_stopped);
4148 needs_events = GST_PAD_NEEDS_EVENTS (pad);
4149 if (G_UNLIKELY (needs_events)) {
4150 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_EVENTS);
4152 GST_DEBUG_OBJECT (pad, "we need to update the events");
4153 ret = gst_pad_update_events (pad);
4154 if (G_UNLIKELY (ret != GST_FLOW_OK))
4157 GST_OBJECT_UNLOCK (pad);
4161 /* ERROR recovery here */
4164 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4165 "pullrange, but pad was flushing");
4166 GST_OBJECT_UNLOCK (pad);
4167 return GST_FLOW_WRONG_STATE;
4171 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4172 gst_flow_get_name (ret));
4173 GST_OBJECT_UNLOCK (pad);
4178 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4179 "pulling range, but it was not linked");
4180 GST_OBJECT_UNLOCK (pad);
4181 return GST_FLOW_NOT_LINKED;
4186 GST_OBJECT_UNLOCK (pad);
4187 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4188 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4189 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4194 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4195 "post probe returned %s", gst_flow_get_name (ret));
4196 GST_OBJECT_UNLOCK (pad);
4197 if (ret == GST_FLOW_OK)
4198 gst_buffer_unref (*buffer);
4204 GST_OBJECT_UNLOCK (pad);
4205 gst_buffer_unref (*buffer);
4207 GST_CAT_WARNING_OBJECT (GST_CAT_SCHEDULING, pad,
4208 "pullrange returned events that were not accepted");
4214 * gst_pad_push_event:
4215 * @pad: a #GstPad to push the event to.
4216 * @event: (transfer full): the #GstEvent to send to the pad.
4218 * Sends the event to the peer of the given pad. This function is
4219 * mainly used by elements to send events to their peer
4222 * This function takes owership of the provided event so you should
4223 * gst_event_ref() it if you want to reuse the event after this call.
4225 * Returns: TRUE if the event was handled.
4230 gst_pad_push_event (GstPad * pad, GstEvent * event)
4235 gboolean stored = FALSE;
4237 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4238 g_return_val_if_fail (event != NULL, FALSE);
4239 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4241 GST_OBJECT_LOCK (pad);
4243 peerpad = GST_PAD_PEER (pad);
4245 /* Two checks to be made:
4246 * . (un)set the FLUSHING flag for flushing events,
4247 * . handle pad blocking */
4248 switch (GST_EVENT_TYPE (event)) {
4249 case GST_EVENT_FLUSH_START:
4250 GST_PAD_SET_FLUSHING (pad);
4252 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4253 /* flush start will have set the FLUSHING flag and will then
4254 * unlock all threads doing a GCond wait on the blocking pad. This
4255 * will typically unblock the STREAMING thread blocked on a pad. */
4256 GST_LOG_OBJECT (pad, "Pad is blocked, not forwarding flush-start, "
4257 "doing block signal.");
4258 GST_PAD_BLOCK_BROADCAST (pad);
4262 case GST_EVENT_FLUSH_STOP:
4263 GST_PAD_UNSET_FLUSHING (pad);
4265 /* Remove sticky EOS events */
4266 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4267 clear_event (pad->priv->events,
4268 GST_EVENT_STICKY_IDX_TYPE (GST_EVENT_EOS));
4270 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4271 GST_LOG_OBJECT (pad, "Pad is blocked, not forwarding flush-stop");
4277 /* store the event on the pad, but only on srcpads */
4278 if (GST_PAD_IS_SRC (pad) && GST_EVENT_IS_STICKY (event)) {
4281 idx = GST_EVENT_STICKY_IDX (event);
4282 GST_LOG_OBJECT (pad, "storing sticky event %s at index %u",
4283 GST_EVENT_TYPE_NAME (event), idx);
4285 /* srcpad sticky events always become active immediately */
4286 gst_event_replace (&pad->priv->events[idx].event, event);
4291 /* backwards compatibility mode for caps */
4292 switch (GST_EVENT_TYPE (event)) {
4293 case GST_EVENT_CAPS:
4295 GST_OBJECT_UNLOCK (pad);
4297 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4299 GST_OBJECT_LOCK (pad);
4300 /* the peerpad might have changed. Things we checked above could not
4302 peerpad = GST_PAD_PEER (pad);
4305 case GST_EVENT_SEGMENT:
4309 offset = pad->offset;
4310 /* check if we need to adjust the segment */
4311 if (offset != 0 && (peerpad != NULL)) {
4314 /* copy segment values */
4315 gst_event_copy_segment (event, &segment);
4316 gst_event_unref (event);
4318 /* adjust and make a new event with the offset applied */
4319 segment.base += offset;
4320 event = gst_event_new_segment (&segment);
4324 case GST_EVENT_RECONFIGURE:
4325 if (GST_PAD_IS_SINK (pad))
4326 GST_OBJECT_FLAG_SET (pad, GST_PAD_NEED_RECONFIGURE);
4332 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4335 PROBE (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_EVENT
4336 | GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4342 /* send probes after modifying the events above */
4343 PROBE (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_EVENT, event,
4346 /* now check the peer pad */
4347 if (peerpad == NULL)
4350 gst_object_ref (peerpad);
4352 GST_OBJECT_UNLOCK (pad);
4354 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4355 event, GST_EVENT_TYPE_NAME (event), peerpad);
4357 result = gst_pad_send_event (peerpad, event);
4359 /* Note: we gave away ownership of the event at this point but we can still
4360 * print the old pointer */
4361 GST_LOG_OBJECT (pad,
4362 "sent event %p to peerpad %" GST_PTR_FORMAT ", result %d", event, peerpad,
4365 gst_object_unref (peerpad);
4367 GST_OBJECT_LOCK (pad);
4369 if (pad->priv->using == 0) {
4370 /* pad is not active anymore, trigger idle callbacks */
4371 PROBE (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE, NULL,
4374 GST_OBJECT_UNLOCK (pad);
4376 return result | stored;
4378 /* ERROR handling */
4381 GST_DEBUG_OBJECT (pad, "We're flushing");
4382 GST_OBJECT_UNLOCK (pad);
4383 gst_event_unref (event);
4388 GST_DEBUG_OBJECT (pad, "Probe returned %s", gst_flow_get_name (ret));
4389 GST_OBJECT_UNLOCK (pad);
4390 gst_event_unref (event);
4395 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4396 GST_OBJECT_UNLOCK (pad);
4397 gst_event_unref (event);
4403 * gst_pad_send_event:
4404 * @pad: a #GstPad to send the event to.
4405 * @event: (transfer full): the #GstEvent to send to the pad.
4407 * Sends the event to the pad. This function can be used
4408 * by applications to send events in the pipeline.
4410 * If @pad is a source pad, @event should be an upstream event. If @pad is a
4411 * sink pad, @event should be a downstream event. For example, you would not
4412 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
4413 * Furthermore, some downstream events have to be serialized with data flow,
4414 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
4415 * the event needs to be serialized with data flow, this function will take the
4416 * pad's stream lock while calling its event function.
4418 * To find out whether an event type is upstream, downstream, or downstream and
4419 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
4420 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
4421 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
4422 * plugin doesn't need to bother itself with this information; the core handles
4423 * all necessary locks and checks.
4425 * This function takes owership of the provided event so you should
4426 * gst_event_ref() it if you want to reuse the event after this call.
4428 * Returns: TRUE if the event was handled.
4431 gst_pad_send_event (GstPad * pad, GstEvent * event)
4434 gboolean result = FALSE;
4435 gboolean serialized, need_unlock = FALSE, needs_events, sticky;
4437 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4438 g_return_val_if_fail (event != NULL, FALSE);
4440 GST_OBJECT_LOCK (pad);
4441 if (GST_PAD_IS_SINK (pad)) {
4442 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4443 goto wrong_direction;
4444 serialized = GST_EVENT_IS_SERIALIZED (event);
4445 sticky = GST_EVENT_IS_STICKY (event);
4446 } else if (GST_PAD_IS_SRC (pad)) {
4447 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4448 goto wrong_direction;
4449 /* events on srcpad never are serialized and sticky */
4450 serialized = sticky = FALSE;
4452 goto unknown_direction;
4454 /* get the flag first, we clear it when we have a FLUSH or a non-serialized
4456 needs_events = GST_PAD_NEEDS_EVENTS (pad);
4458 switch (GST_EVENT_TYPE (event)) {
4459 case GST_EVENT_FLUSH_START:
4460 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4461 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4463 /* can't even accept a flush begin event when flushing */
4464 if (GST_PAD_IS_FLUSHING (pad))
4467 GST_PAD_SET_FLUSHING (pad);
4468 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4469 needs_events = FALSE;
4471 case GST_EVENT_FLUSH_STOP:
4472 if (G_LIKELY (GST_PAD_ACTIVATE_MODE (pad) != GST_PAD_ACTIVATE_NONE)) {
4473 GST_PAD_UNSET_FLUSHING (pad);
4474 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4476 /* Remove pending EOS events */
4477 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4478 clear_event (pad->priv->events,
4479 GST_EVENT_STICKY_IDX_TYPE (GST_EVENT_EOS));
4481 GST_OBJECT_UNLOCK (pad);
4482 /* grab stream lock */
4483 GST_PAD_STREAM_LOCK (pad);
4485 GST_OBJECT_LOCK (pad);
4486 needs_events = FALSE;
4488 case GST_EVENT_RECONFIGURE:
4489 if (GST_PAD_IS_SRC (pad))
4490 GST_OBJECT_FLAG_SET (pad, GST_PAD_NEED_RECONFIGURE);
4492 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "have event type %s",
4493 GST_EVENT_TYPE_NAME (event));
4496 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4497 GST_OBJECT_UNLOCK (pad);
4498 GST_PAD_STREAM_LOCK (pad);
4500 GST_OBJECT_LOCK (pad);
4502 /* don't forward events on non-serialized events */
4503 needs_events = FALSE;
4506 /* store the event on the pad, but only on srcpads. We need to store the
4507 * event before checking the flushing flag. */
4512 switch (GST_EVENT_TYPE (event)) {
4513 case GST_EVENT_SEGMENT:
4514 if (pad->offset != 0) {
4517 /* copy segment values */
4518 gst_event_copy_segment (event, &segment);
4519 gst_event_unref (event);
4521 /* adjust and make a new event with the offset applied */
4522 segment.base += pad->offset;
4523 event = gst_event_new_segment (&segment);
4530 idx = GST_EVENT_STICKY_IDX (event);
4531 ev = &pad->priv->events[idx];
4533 if (ev->event != event) {
4534 GST_LOG_OBJECT (pad, "storing sticky event %s at index %u",
4535 GST_EVENT_TYPE_NAME (event), idx);
4536 gst_event_replace (&ev->pending, event);
4537 /* set the flag so that we update the events next time. We would
4538 * usually update below but we might be flushing too. */
4539 GST_OBJECT_FLAG_SET (pad, GST_PAD_NEED_EVENTS);
4540 needs_events = TRUE;
4543 /* now do the probe */
4544 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4548 GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_EVENT |
4549 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4551 PROBE (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_EVENT, event,
4557 if (G_UNLIKELY (needs_events)) {
4560 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_EVENTS);
4562 GST_DEBUG_OBJECT (pad, "need to update all events");
4563 ret = gst_pad_update_events (pad);
4564 if (ret != GST_FLOW_OK)
4566 GST_OBJECT_UNLOCK (pad);
4568 gst_event_unref (event);
4573 /* ensure to pass on event;
4574 * note that a sticky event has already been updated above */
4575 if (G_LIKELY (!needs_events || !sticky)) {
4576 GstPadEventFunction eventfunc;
4578 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4581 GST_OBJECT_UNLOCK (pad);
4583 result = eventfunc (pad, event);
4587 GST_PAD_STREAM_UNLOCK (pad);
4589 GST_DEBUG_OBJECT (pad, "sent event, result %d", result);
4593 /* ERROR handling */
4596 g_warning ("pad %s:%s sending %s event in wrong direction",
4597 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4598 GST_OBJECT_UNLOCK (pad);
4599 gst_event_unref (event);
4604 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4605 GST_OBJECT_UNLOCK (pad);
4606 gst_event_unref (event);
4611 g_warning ("pad %s:%s has no event handler, file a bug.",
4612 GST_DEBUG_PAD_NAME (pad));
4613 GST_OBJECT_UNLOCK (pad);
4615 GST_PAD_STREAM_UNLOCK (pad);
4616 gst_event_unref (event);
4621 GST_OBJECT_UNLOCK (pad);
4623 GST_PAD_STREAM_UNLOCK (pad);
4624 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
4625 "Received event on flushing pad. Discarding");
4626 gst_event_unref (event);
4631 GST_DEBUG_OBJECT (pad, "probe returned %s", gst_flow_get_name (ret));
4632 GST_OBJECT_UNLOCK (pad);
4634 GST_PAD_STREAM_UNLOCK (pad);
4635 gst_event_unref (event);
4640 GST_OBJECT_UNLOCK (pad);
4642 GST_PAD_STREAM_UNLOCK (pad);
4643 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad, "Update events failed");
4644 gst_event_unref (event);
4650 * gst_pad_set_element_private:
4651 * @pad: the #GstPad to set the private data of.
4652 * @priv: The private data to attach to the pad.
4654 * Set the given private data gpointer on the pad.
4655 * This function can only be used by the element that owns the pad.
4656 * No locking is performed in this function.
4659 gst_pad_set_element_private (GstPad * pad, gpointer priv)
4661 pad->element_private = priv;
4665 * gst_pad_get_element_private:
4666 * @pad: the #GstPad to get the private data of.
4668 * Gets the private data of a pad.
4669 * No locking is performed in this function.
4671 * Returns: (transfer none): a #gpointer to the private data.
4674 gst_pad_get_element_private (GstPad * pad)
4676 return pad->element_private;
4680 * gst_pad_get_sticky_event:
4681 * @pad: the #GstPad to get the event from.
4682 * @event_type: the #GstEventType that should be retrieved.
4684 * Returns a new reference of the sticky event of type @event_type
4687 * Returns: (transfer full): a #GstEvent of type @event_type. Unref after usage.
4690 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type)
4692 GstEvent *event = NULL;
4695 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4696 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
4698 idx = GST_EVENT_STICKY_IDX_TYPE (event_type);
4700 GST_OBJECT_LOCK (pad);
4701 if ((event = pad->priv->events[idx].event)) {
4702 gst_event_ref (event);
4704 GST_OBJECT_UNLOCK (pad);
4710 * gst_pad_sticky_events_foreach:
4711 * @pad: the #GstPad that should be used for iteration.
4712 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that should be called for every event.
4713 * @user_data: (closure): the optional user data.
4715 * Iterates all active sticky events on @pad and calls @foreach_func for every
4716 * event. If @foreach_func returns something else than GST_FLOW_OK the iteration
4717 * is immediately stopped.
4719 * Returns: GST_FLOW_OK if iteration was successful
4722 gst_pad_sticky_events_foreach (GstPad * pad,
4723 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
4725 GstFlowReturn ret = GST_FLOW_OK;
4729 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4730 g_return_val_if_fail (foreach_func != NULL, GST_FLOW_ERROR);
4732 GST_OBJECT_LOCK (pad);
4735 for (i = 0; i < GST_EVENT_MAX_STICKY; i++) {
4739 ev = &pad->priv->events[i];
4741 /* skip without active event */
4742 if ((event = ev->event) == NULL)
4745 gst_event_ref (event);
4746 GST_OBJECT_UNLOCK (pad);
4748 res = foreach_func (pad, event, user_data);
4750 GST_OBJECT_LOCK (pad);
4751 gst_event_unref (event);
4753 if (res != GST_FLOW_OK) {
4758 /* things could have changed while we release the lock, check if we still
4759 * are handling the same event, if we don't something changed and we have
4760 * to try again. FIXME. we need a cookie here. */
4761 if (event != ev->event) {
4762 GST_DEBUG_OBJECT (pad, "events changed, restarting");
4766 GST_OBJECT_UNLOCK (pad);
4772 do_stream_status (GstPad * pad, GstStreamStatusType type,
4773 GThread * thread, GstTask * task)
4777 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
4779 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
4780 if (GST_IS_ELEMENT (parent)) {
4781 GstMessage *message;
4782 GValue value = { 0 };
4784 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
4785 gchar *tname, *ename, *pname;
4787 /* create a good task name */
4788 ename = gst_element_get_name (parent);
4789 pname = gst_pad_get_name (pad);
4790 tname = g_strdup_printf ("%s:%s", ename, pname);
4794 gst_object_set_name (GST_OBJECT_CAST (task), tname);
4798 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
4801 g_value_init (&value, GST_TYPE_TASK);
4802 g_value_set_object (&value, task);
4803 gst_message_set_stream_status_object (message, &value);
4804 g_value_unset (&value);
4806 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
4807 gst_element_post_message (parent, message);
4809 gst_object_unref (parent);
4814 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
4816 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
4821 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
4823 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
4827 static GstTaskThreadCallbacks thr_callbacks = {
4833 * gst_pad_start_task:
4834 * @pad: the #GstPad to start the task of
4835 * @func: the task function to call
4836 * @data: data passed to the task function
4838 * Starts a task that repeatedly calls @func with @data. This function
4839 * is mostly used in pad activation functions to start the dataflow.
4840 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
4841 * before @func is called.
4843 * Returns: a %TRUE if the task could be started.
4846 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
4851 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4852 g_return_val_if_fail (func != NULL, FALSE);
4854 GST_DEBUG_OBJECT (pad, "start task");
4856 GST_OBJECT_LOCK (pad);
4857 task = GST_PAD_TASK (pad);
4859 task = gst_task_new (func, data);
4860 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
4861 gst_task_set_thread_callbacks (task, &thr_callbacks, pad, NULL);
4862 GST_DEBUG_OBJECT (pad, "created task");
4863 GST_PAD_TASK (pad) = task;
4864 gst_object_ref (task);
4865 /* release lock to post the message */
4866 GST_OBJECT_UNLOCK (pad);
4868 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
4870 gst_object_unref (task);
4872 GST_OBJECT_LOCK (pad);
4873 /* nobody else is supposed to have changed the pad now */
4874 if (GST_PAD_TASK (pad) != task)
4875 goto concurrent_stop;
4877 res = gst_task_set_state (task, GST_TASK_STARTED);
4878 GST_OBJECT_UNLOCK (pad);
4885 GST_OBJECT_UNLOCK (pad);
4891 * gst_pad_pause_task:
4892 * @pad: the #GstPad to pause the task of
4894 * Pause the task of @pad. This function will also wait until the
4895 * function executed by the task is finished if this function is not
4896 * called from the task function.
4898 * Returns: a TRUE if the task could be paused or FALSE when the pad
4902 gst_pad_pause_task (GstPad * pad)
4907 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4909 GST_DEBUG_OBJECT (pad, "pause task");
4911 GST_OBJECT_LOCK (pad);
4912 task = GST_PAD_TASK (pad);
4915 res = gst_task_set_state (task, GST_TASK_PAUSED);
4916 GST_OBJECT_UNLOCK (pad);
4918 /* wait for task function to finish, this lock is recursive so it does nothing
4919 * when the pause is called from the task itself */
4920 GST_PAD_STREAM_LOCK (pad);
4921 GST_PAD_STREAM_UNLOCK (pad);
4927 GST_DEBUG_OBJECT (pad, "pad has no task");
4928 GST_OBJECT_UNLOCK (pad);
4934 * gst_pad_stop_task:
4935 * @pad: the #GstPad to stop the task of
4937 * Stop the task of @pad. This function will also make sure that the
4938 * function executed by the task will effectively stop if not called
4939 * from the GstTaskFunction.
4941 * This function will deadlock if called from the GstTaskFunction of
4942 * the task. Use gst_task_pause() instead.
4944 * Regardless of whether the pad has a task, the stream lock is acquired and
4945 * released so as to ensure that streaming through this pad has finished.
4947 * Returns: a TRUE if the task could be stopped or FALSE on error.
4950 gst_pad_stop_task (GstPad * pad)
4955 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4957 GST_DEBUG_OBJECT (pad, "stop task");
4959 GST_OBJECT_LOCK (pad);
4960 task = GST_PAD_TASK (pad);
4963 GST_PAD_TASK (pad) = NULL;
4964 res = gst_task_set_state (task, GST_TASK_STOPPED);
4965 GST_OBJECT_UNLOCK (pad);
4967 GST_PAD_STREAM_LOCK (pad);
4968 GST_PAD_STREAM_UNLOCK (pad);
4970 if (!gst_task_join (task))
4973 gst_object_unref (task);
4979 GST_DEBUG_OBJECT (pad, "no task");
4980 GST_OBJECT_UNLOCK (pad);
4982 GST_PAD_STREAM_LOCK (pad);
4983 GST_PAD_STREAM_UNLOCK (pad);
4985 /* this is not an error */
4990 /* this is bad, possibly the application tried to join the task from
4991 * the task's thread. We install the task again so that it will be stopped
4992 * again from the right thread next time hopefully. */
4993 GST_OBJECT_LOCK (pad);
4994 GST_DEBUG_OBJECT (pad, "join failed");
4995 /* we can only install this task if there was no other task */
4996 if (GST_PAD_TASK (pad) == NULL)
4997 GST_PAD_TASK (pad) = task;
4998 GST_OBJECT_UNLOCK (pad);