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];
113 guint probe_list_cookie;
123 #define PROBE_COOKIE(h) (((GstProbe *)(h))->cookie)
128 GstPadProbeInfo *info;
135 static void gst_pad_dispose (GObject * object);
136 static void gst_pad_finalize (GObject * object);
137 static void gst_pad_set_property (GObject * object, guint prop_id,
138 const GValue * value, GParamSpec * pspec);
139 static void gst_pad_get_property (GObject * object, guint prop_id,
140 GValue * value, GParamSpec * pspec);
142 static GstCaps *gst_pad_get_caps_unlocked (GstPad * pad, GstCaps * filter);
143 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
144 static gboolean gst_pad_activate_default (GstPad * pad);
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_query_default);
303 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
304 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
305 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_fixate_caps_default);
309 gst_pad_init (GstPad * pad)
311 pad->priv = GST_PAD_GET_PRIVATE (pad);
313 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
315 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
316 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
317 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
318 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
319 GST_PAD_FIXATECAPSFUNC (pad) = gst_pad_fixate_caps_default;
320 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
322 GST_PAD_SET_FLUSHING (pad);
324 g_static_rec_mutex_init (&pad->stream_rec_lock);
326 pad->block_cond = g_cond_new ();
328 g_hook_list_init (&pad->probes, sizeof (GstProbe));
332 clear_event (PadEvent events[], guint idx)
334 gst_event_replace (&events[idx].event, NULL);
335 gst_event_replace (&events[idx].pending, NULL);
338 /* called when setting the pad inactive. It removes all sticky events from
341 clear_events (PadEvent events[])
345 for (i = 0; i < GST_EVENT_MAX_STICKY; i++)
346 clear_event (events, i);
349 /* The sticky event with @idx from the srcpad is copied to the
350 * pending event on the sinkpad (when different).
351 * This function applies the pad offsets in case of segment events.
352 * This will make sure that we send the event to the sinkpad event
353 * function when the next buffer of event arrives.
354 * Should be called with the OBJECT lock of both pads.
355 * This function returns TRUE when there is a pending event on the
358 replace_event (GstPad * srcpad, GstPad * sinkpad, guint idx)
360 PadEvent *srcev, *sinkev;
362 gboolean pending = FALSE;
364 srcev = &srcpad->priv->events[idx];
366 if ((event = srcev->event)) {
367 sinkev = &sinkpad->priv->events[idx];
369 switch (GST_EVENT_TYPE (event)) {
370 case GST_EVENT_SEGMENT:
375 offset = srcpad->offset + sinkpad->offset;
377 gst_event_copy_segment (event, &segment);
378 /* adjust the base time. FIXME, check negative times, try to tweak the
379 * start to do clipping on negative times */
380 segment.base += offset;
381 /* make a new event from the updated segment */
382 event = gst_event_new_segment (&segment);
389 if (sinkev->event != event) {
390 /* put in the pending entry when different */
391 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, srcpad,
392 "Putting event %p (%s) on pad %s:%s", event,
393 GST_EVENT_TYPE_NAME (event), GST_DEBUG_PAD_NAME (sinkpad));
394 gst_event_replace (&sinkev->pending, event);
403 prepare_event_update (GstPad * srcpad, GstPad * sinkpad)
408 /* make sure we push the events from the source to this new peer, for this we
409 * copy the events on the sinkpad and mark EVENTS_PENDING */
411 for (i = 0; i < GST_EVENT_MAX_STICKY; i++)
412 pending |= replace_event (srcpad, sinkpad, i);
414 /* we had some new pending events, set our flag */
416 GST_OBJECT_FLAG_SET (sinkpad, GST_PAD_NEED_EVENTS);
419 /* should be called with the OBJECT_LOCK */
421 get_pad_caps (GstPad * pad)
423 GstCaps *caps = NULL;
427 idx = GST_EVENT_STICKY_IDX_TYPE (GST_EVENT_CAPS);
428 /* we can only use the caps when we have successfully send the caps
429 * event to the event function and is thus in the active entry */
430 if ((event = pad->priv->events[idx].event))
431 gst_event_parse_caps (event, &caps);
437 gst_pad_dispose (GObject * object)
439 GstPad *pad = GST_PAD_CAST (object);
442 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
444 /* unlink the peer pad */
445 if ((peer = gst_pad_get_peer (pad))) {
446 /* window for MT unsafeness, someone else could unlink here
447 * and then we call unlink with wrong pads. The unlink
448 * function would catch this and safely return failed. */
449 if (GST_PAD_IS_SRC (pad))
450 gst_pad_unlink (pad, peer);
452 gst_pad_unlink (peer, pad);
454 gst_object_unref (peer);
457 gst_pad_set_pad_template (pad, NULL);
459 clear_events (pad->priv->events);
461 g_hook_list_clear (&pad->probes);
463 G_OBJECT_CLASS (parent_class)->dispose (object);
467 gst_pad_finalize (GObject * object)
469 GstPad *pad = GST_PAD_CAST (object);
472 /* in case the task is still around, clean it up */
473 if ((task = GST_PAD_TASK (pad))) {
474 gst_task_join (task);
475 GST_PAD_TASK (pad) = NULL;
476 gst_object_unref (task);
479 g_static_rec_mutex_free (&pad->stream_rec_lock);
480 g_cond_free (pad->block_cond);
482 G_OBJECT_CLASS (parent_class)->finalize (object);
486 gst_pad_set_property (GObject * object, guint prop_id,
487 const GValue * value, GParamSpec * pspec)
489 g_return_if_fail (GST_IS_PAD (object));
492 case PAD_PROP_DIRECTION:
493 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
495 case PAD_PROP_TEMPLATE:
496 gst_pad_set_pad_template (GST_PAD_CAST (object),
497 (GstPadTemplate *) g_value_get_object (value));
500 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
506 gst_pad_get_property (GObject * object, guint prop_id,
507 GValue * value, GParamSpec * pspec)
509 g_return_if_fail (GST_IS_PAD (object));
513 GST_OBJECT_LOCK (object);
514 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
515 GST_OBJECT_UNLOCK (object);
517 case PAD_PROP_DIRECTION:
518 g_value_set_enum (value, GST_PAD_DIRECTION (object));
520 case PAD_PROP_TEMPLATE:
521 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
524 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
531 * @name: the name of the new pad.
532 * @direction: the #GstPadDirection of the pad.
534 * Creates a new pad with the given name in the given direction.
535 * If name is NULL, a guaranteed unique name (across all pads)
537 * This function makes a copy of the name so you can safely free the name.
539 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
544 gst_pad_new (const gchar * name, GstPadDirection direction)
546 return g_object_new (GST_TYPE_PAD,
547 "name", name, "direction", direction, NULL);
551 * gst_pad_new_from_template:
552 * @templ: the pad template to use
553 * @name: the name of the element
555 * Creates a new pad with the given name from the given template.
556 * If name is NULL, a guaranteed unique name (across all pads)
558 * This function makes a copy of the name so you can safely free the name.
560 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
563 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
565 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
567 return g_object_new (GST_TYPE_PAD,
568 "name", name, "direction", templ->direction, "template", templ, NULL);
572 * gst_pad_new_from_static_template:
573 * @templ: the #GstStaticPadTemplate to use
574 * @name: the name of the element
576 * Creates a new pad with the given name from the given static template.
577 * If name is NULL, a guaranteed unique name (across all pads)
579 * This function makes a copy of the name so you can safely free the name.
581 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
584 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
588 GstPadTemplate *template;
590 template = gst_static_pad_template_get (templ);
591 pad = gst_pad_new_from_template (template, name);
592 gst_object_unref (template);
597 * gst_pad_get_direction:
598 * @pad: a #GstPad to get the direction of.
600 * Gets the direction of the pad. The direction of the pad is
601 * decided at construction time so this function does not take
604 * Returns: the #GstPadDirection of the pad.
609 gst_pad_get_direction (GstPad * pad)
611 GstPadDirection result;
613 /* PAD_UNKNOWN is a little silly but we need some sort of
614 * error return value */
615 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
617 result = GST_PAD_DIRECTION (pad);
623 gst_pad_activate_default (GstPad * pad)
625 return gst_pad_activate_push (pad, TRUE);
629 pre_activate (GstPad * pad, GstPadActivateMode new_mode)
632 case GST_PAD_ACTIVATE_PUSH:
633 case GST_PAD_ACTIVATE_PULL:
634 GST_OBJECT_LOCK (pad);
635 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE %d, unset flushing",
637 GST_PAD_UNSET_FLUSHING (pad);
638 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
639 GST_OBJECT_UNLOCK (pad);
641 case GST_PAD_ACTIVATE_NONE:
642 GST_OBJECT_LOCK (pad);
643 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE NONE, set flushing");
644 GST_PAD_SET_FLUSHING (pad);
645 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
646 /* unlock blocked pads so element can resume and stop */
647 GST_PAD_BLOCK_BROADCAST (pad);
648 GST_OBJECT_UNLOCK (pad);
654 post_activate (GstPad * pad, GstPadActivateMode new_mode)
657 case GST_PAD_ACTIVATE_PUSH:
658 case GST_PAD_ACTIVATE_PULL:
661 case GST_PAD_ACTIVATE_NONE:
662 /* ensures that streaming stops */
663 GST_PAD_STREAM_LOCK (pad);
664 GST_DEBUG_OBJECT (pad, "stopped streaming");
665 GST_OBJECT_LOCK (pad);
666 clear_events (pad->priv->events);
667 GST_OBJECT_UNLOCK (pad);
668 GST_PAD_STREAM_UNLOCK (pad);
674 * gst_pad_set_active:
675 * @pad: the #GstPad to activate or deactivate.
676 * @active: whether or not the pad should be active.
678 * Activates or deactivates the given pad.
679 * Normally called from within core state change functions.
681 * If @active, makes sure the pad is active. If it is already active, either in
682 * push or pull mode, just return. Otherwise dispatches to the pad's activate
683 * function to perform the actual activation.
685 * If not @active, checks the pad's current mode and calls
686 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
689 * Returns: #TRUE if the operation was successful.
694 gst_pad_set_active (GstPad * pad, gboolean active)
696 GstPadActivateMode old;
697 gboolean ret = FALSE;
699 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
701 GST_OBJECT_LOCK (pad);
702 old = GST_PAD_ACTIVATE_MODE (pad);
703 GST_OBJECT_UNLOCK (pad);
707 case GST_PAD_ACTIVATE_PUSH:
708 GST_DEBUG_OBJECT (pad, "activating pad from push");
711 case GST_PAD_ACTIVATE_PULL:
712 GST_DEBUG_OBJECT (pad, "activating pad from pull");
715 case GST_PAD_ACTIVATE_NONE:
716 GST_DEBUG_OBJECT (pad, "activating pad from none");
717 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad);
720 GST_DEBUG_OBJECT (pad, "unknown activation mode!");
725 case GST_PAD_ACTIVATE_PUSH:
726 GST_DEBUG_OBJECT (pad, "deactivating pad from push");
727 ret = gst_pad_activate_push (pad, FALSE);
729 case GST_PAD_ACTIVATE_PULL:
730 GST_DEBUG_OBJECT (pad, "deactivating pad from pull");
731 ret = gst_pad_activate_pull (pad, FALSE);
733 case GST_PAD_ACTIVATE_NONE:
734 GST_DEBUG_OBJECT (pad, "deactivating pad from none");
738 GST_DEBUG_OBJECT (pad, "unknown activation mode!");
744 GST_OBJECT_LOCK (pad);
746 g_critical ("Failed to deactivate pad %s:%s, very bad",
747 GST_DEBUG_PAD_NAME (pad));
749 GST_WARNING_OBJECT (pad, "Failed to activate pad");
751 GST_OBJECT_UNLOCK (pad);
754 GST_OBJECT_LOCK (pad);
755 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_RECONFIGURE);
756 GST_OBJECT_UNLOCK (pad);
764 * gst_pad_activate_pull:
765 * @pad: the #GstPad to activate or deactivate.
766 * @active: whether or not the pad should be active.
768 * Activates or deactivates the given pad in pull mode via dispatching to the
769 * pad's activatepullfunc. For use from within pad activation functions only.
770 * When called on sink pads, will first proxy the call to the peer pad, which
771 * is expected to activate its internally linked pads from within its
772 * activate_pull function.
774 * If you don't know what this is, you probably don't want to call it.
776 * Returns: TRUE if the operation was successful.
781 gst_pad_activate_pull (GstPad * pad, gboolean active)
783 GstPadActivateMode old, new;
786 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
788 GST_OBJECT_LOCK (pad);
789 old = GST_PAD_ACTIVATE_MODE (pad);
790 GST_OBJECT_UNLOCK (pad);
794 case GST_PAD_ACTIVATE_PULL:
795 GST_DEBUG_OBJECT (pad, "activating pad from pull, was ok");
797 case GST_PAD_ACTIVATE_PUSH:
798 GST_DEBUG_OBJECT (pad,
799 "activating pad from push, deactivate push first");
800 /* pad was activate in the wrong direction, deactivate it
801 * and reactivate it in pull mode */
802 if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
803 goto deactivate_failed;
804 /* fallthrough, pad is deactivated now. */
805 case GST_PAD_ACTIVATE_NONE:
806 GST_DEBUG_OBJECT (pad, "activating pad from none");
811 case GST_PAD_ACTIVATE_NONE:
812 GST_DEBUG_OBJECT (pad, "deactivating pad from none, was ok");
814 case GST_PAD_ACTIVATE_PUSH:
815 GST_DEBUG_OBJECT (pad, "deactivating pad from push, weird");
816 /* pad was activated in the other direction, deactivate it
817 * in push mode, this should not happen... */
818 if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
819 goto deactivate_failed;
820 /* everything is fine now */
822 case GST_PAD_ACTIVATE_PULL:
823 GST_DEBUG_OBJECT (pad, "deactivating pad from pull");
828 if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
829 if ((peer = gst_pad_get_peer (pad))) {
830 GST_DEBUG_OBJECT (pad, "calling peer");
831 if (G_UNLIKELY (!gst_pad_activate_pull (peer, active)))
833 gst_object_unref (peer);
835 /* there is no peer, this is only fatal when we activate. When we
836 * deactivate, we must assume the application has unlinked the peer and
837 * will deactivate it eventually. */
841 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
844 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
845 goto failure; /* Can't activate pull on a src without a
849 new = active ? GST_PAD_ACTIVATE_PULL : GST_PAD_ACTIVATE_NONE;
850 pre_activate (pad, new);
852 if (GST_PAD_ACTIVATEPULLFUNC (pad)) {
853 if (G_UNLIKELY (!GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active)))
856 /* can happen for sinks of passthrough elements */
859 post_activate (pad, new);
861 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode",
862 active ? "activated" : "deactivated");
868 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in pull mode",
869 active ? "activated" : "deactivated");
874 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
875 "failed to %s in switch to pull from mode %d",
876 (active ? "activate" : "deactivate"), old);
881 GST_OBJECT_LOCK (peer);
882 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
883 "activate_pull on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
884 GST_OBJECT_UNLOCK (peer);
885 gst_object_unref (peer);
890 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
896 GST_OBJECT_LOCK (pad);
897 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in pull mode",
898 active ? "activate" : "deactivate");
899 GST_PAD_SET_FLUSHING (pad);
900 GST_PAD_ACTIVATE_MODE (pad) = old;
901 GST_OBJECT_UNLOCK (pad);
907 * gst_pad_activate_push:
908 * @pad: the #GstPad to activate or deactivate.
909 * @active: whether the pad should be active or not.
911 * Activates or deactivates the given pad in push mode via dispatching to the
912 * pad's activatepushfunc. For use from within pad activation functions only.
914 * If you don't know what this is, you probably don't want to call it.
916 * Returns: %TRUE if the operation was successful.
921 gst_pad_activate_push (GstPad * pad, gboolean active)
923 GstPadActivateMode old, new;
925 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
926 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "trying to set %s in push mode",
927 active ? "activated" : "deactivated");
929 GST_OBJECT_LOCK (pad);
930 old = GST_PAD_ACTIVATE_MODE (pad);
931 GST_OBJECT_UNLOCK (pad);
935 case GST_PAD_ACTIVATE_PUSH:
936 GST_DEBUG_OBJECT (pad, "activating pad from push, was ok");
938 case GST_PAD_ACTIVATE_PULL:
939 GST_DEBUG_OBJECT (pad,
940 "activating pad from push, deactivating pull first");
941 /* pad was activate in the wrong direction, deactivate it
942 * an reactivate it in push mode */
943 if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
944 goto deactivate_failed;
945 /* fallthrough, pad is deactivated now. */
946 case GST_PAD_ACTIVATE_NONE:
947 GST_DEBUG_OBJECT (pad, "activating pad from none");
952 case GST_PAD_ACTIVATE_NONE:
953 GST_DEBUG_OBJECT (pad, "deactivating pad from none, was ok");
955 case GST_PAD_ACTIVATE_PULL:
956 GST_DEBUG_OBJECT (pad, "deactivating pad from pull, weird");
957 /* pad was activated in the other direction, deactivate it
958 * in pull mode, this should not happen... */
959 if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
960 goto deactivate_failed;
961 /* everything is fine now */
963 case GST_PAD_ACTIVATE_PUSH:
964 GST_DEBUG_OBJECT (pad, "deactivating pad from push");
969 new = active ? GST_PAD_ACTIVATE_PUSH : GST_PAD_ACTIVATE_NONE;
970 pre_activate (pad, new);
972 if (GST_PAD_ACTIVATEPUSHFUNC (pad)) {
973 if (G_UNLIKELY (!GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active))) {
977 /* quite ok, element relies on state change func to prepare itself */
980 post_activate (pad, new);
982 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in push mode",
983 active ? "activated" : "deactivated");
988 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in push mode",
989 active ? "activated" : "deactivated");
994 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
995 "failed to %s in switch to push from mode %d",
996 (active ? "activate" : "deactivate"), old);
1001 GST_OBJECT_LOCK (pad);
1002 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode",
1003 active ? "activate" : "deactivate");
1004 GST_PAD_SET_FLUSHING (pad);
1005 GST_PAD_ACTIVATE_MODE (pad) = old;
1006 GST_OBJECT_UNLOCK (pad);
1012 * gst_pad_is_active:
1013 * @pad: the #GstPad to query
1015 * Query if a pad is active
1017 * Returns: TRUE if the pad is active.
1022 gst_pad_is_active (GstPad * pad)
1024 gboolean result = FALSE;
1026 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1028 GST_OBJECT_LOCK (pad);
1029 result = GST_PAD_IS_ACTIVE (pad);
1030 GST_OBJECT_UNLOCK (pad);
1036 * gst_pad_add_probe:
1037 * @pad: the #GstPad to add the probe to
1038 * @mask: the probe mask
1039 * @callback: #GstPadProbeCallback that will be called with notifications of
1041 * @user_data: (closure): user data passed to the callback
1042 * @destroy_data: #GDestroyNotify for user_data
1044 * Be notified of different states of pads. The provided callback is called for
1045 * every state that matches @mask.
1047 * Returns: an id or 0 on error. The id can be used to remove the probe with
1048 * gst_pad_remove_probe().
1053 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1054 GstPadProbeCallback callback, gpointer user_data,
1055 GDestroyNotify destroy_data)
1060 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1061 g_return_val_if_fail (mask != 0, 0);
1063 GST_OBJECT_LOCK (pad);
1065 /* make a new probe */
1066 hook = g_hook_alloc (&pad->probes);
1068 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1071 /* when no contraints are given for the types, assume all types are
1073 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1074 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1075 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1076 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1078 /* store our flags and other fields */
1079 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1080 hook->func = callback;
1081 hook->data = user_data;
1082 hook->destroy = destroy_data;
1083 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1086 g_hook_prepend (&pad->probes, hook);
1088 /* incremenent cookie so that the new hook get's called */
1089 pad->priv->probe_list_cookie++;
1091 /* get the id of the hook, we return this and it can be used to remove the
1093 res = hook->hook_id;
1095 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1097 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1098 /* we have a block probe */
1100 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKED);
1101 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1102 "now %d blocking probes", pad->num_blocked);
1105 /* call the callback if we need to be called for idle callbacks */
1106 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1107 if (pad->priv->using > 0) {
1108 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1109 * flag above, the last thread to leave the push will do the callback. New
1110 * threads going into the push will block. */
1111 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1112 "pad is in use, delay idle callback");
1113 GST_OBJECT_UNLOCK (pad);
1115 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, };
1117 /* the pad is idle now, we can signal the idle callback now */
1118 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1119 "pad is idle, trigger idle callback");
1120 GST_OBJECT_UNLOCK (pad);
1122 callback (pad, &info, user_data);
1125 GST_OBJECT_UNLOCK (pad);
1131 cleanup_hook (GstPad * pad, GHook * hook)
1133 GstPadProbeType type;
1135 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1137 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1138 /* unblock when we remove the last blocking probe */
1140 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1142 if (pad->num_blocked == 0) {
1143 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1144 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKED);
1145 GST_PAD_BLOCK_BROADCAST (pad);
1148 g_hook_destroy_link (&pad->probes, hook);
1153 * gst_pad_remove_probe:
1154 * @pad: the #GstPad with the probe
1155 * @id: the probe id to remove
1157 * Remove the probe with @id from @pad.
1162 gst_pad_remove_probe (GstPad * pad, gulong id)
1166 g_return_if_fail (GST_IS_PAD (pad));
1168 GST_OBJECT_LOCK (pad);
1170 hook = g_hook_get (&pad->probes, id);
1174 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1176 cleanup_hook (pad, hook);
1177 GST_OBJECT_UNLOCK (pad);
1183 GST_OBJECT_UNLOCK (pad);
1184 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1190 * gst_pad_is_blocked:
1191 * @pad: the #GstPad to query
1193 * Checks if the pad is blocked or not. This function returns the
1194 * last requested state of the pad. It is not certain that the pad
1195 * is actually blocking at this point (see gst_pad_is_blocking()).
1197 * Returns: TRUE if the pad is blocked.
1202 gst_pad_is_blocked (GstPad * pad)
1204 gboolean result = FALSE;
1206 g_return_val_if_fail (GST_IS_PAD (pad), result);
1208 GST_OBJECT_LOCK (pad);
1209 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED);
1210 GST_OBJECT_UNLOCK (pad);
1216 * gst_pad_is_blocking:
1217 * @pad: the #GstPad to query
1219 * Checks if the pad is blocking or not. This is a guaranteed state
1220 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1222 * Returns: TRUE if the pad is blocking.
1229 gst_pad_is_blocking (GstPad * pad)
1231 gboolean result = FALSE;
1233 g_return_val_if_fail (GST_IS_PAD (pad), result);
1235 GST_OBJECT_LOCK (pad);
1236 /* the blocking flag is only valid if the pad is not flushing */
1237 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKING) &&
1238 !GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLUSHING);
1239 GST_OBJECT_UNLOCK (pad);
1245 * gst_pad_check_reconfigure:
1246 * @pad: the #GstPad to check
1248 * Check and clear the #GST_PAD_NEED_RECONFIGURE flag on @pad and return %TRUE
1249 * if the flag was set.
1251 * Returns: %TRUE is the GST_PAD_NEED_RECONFIGURE flag was set on @pad.
1254 gst_pad_check_reconfigure (GstPad * pad)
1256 gboolean reconfigure;
1258 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1260 GST_OBJECT_LOCK (pad);
1261 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1262 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_RECONFIGURE);
1263 GST_OBJECT_UNLOCK (pad);
1269 * gst_pad_mark_reconfigure:
1270 * @pad: the #GstPad to mark
1272 * Mark a pad for needing reconfiguration. The next call to
1273 * gst_pad_check_reconfigure() will return %TRUE after this call.
1276 gst_pad_mark_reconfigure (GstPad * pad)
1278 g_return_if_fail (GST_IS_PAD (pad));
1280 GST_OBJECT_LOCK (pad);
1281 GST_OBJECT_FLAG_SET (pad, GST_PAD_NEED_RECONFIGURE);
1282 GST_OBJECT_UNLOCK (pad);
1286 * gst_pad_set_activate_function:
1288 * @activate: the #GstPadActivateFunction to set.
1290 * Sets the given activate function for @pad. The activate function will
1291 * dispatch to gst_pad_activate_push() or gst_pad_activate_pull() to perform
1292 * the actual activation. Only makes sense to set on sink pads.
1294 * Call this function if your sink pad can start a pull-based task.
1297 gst_pad_set_activate_function (GstPad * pad, GstPadActivateFunction activate)
1299 g_return_if_fail (GST_IS_PAD (pad));
1301 GST_PAD_ACTIVATEFUNC (pad) = activate;
1302 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1303 GST_DEBUG_FUNCPTR_NAME (activate));
1307 * gst_pad_set_activatepull_function:
1309 * @activatepull: the #GstPadActivateModeFunction to set.
1311 * Sets the given activate_pull function for the pad. An activate_pull function
1312 * prepares the element and any upstream connections for pulling. See XXX
1313 * part-activation.txt for details.
1316 gst_pad_set_activatepull_function (GstPad * pad,
1317 GstPadActivateModeFunction activatepull)
1319 g_return_if_fail (GST_IS_PAD (pad));
1321 GST_PAD_ACTIVATEPULLFUNC (pad) = activatepull;
1322 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatepullfunc set to %s",
1323 GST_DEBUG_FUNCPTR_NAME (activatepull));
1327 * gst_pad_set_activatepush_function:
1329 * @activatepush: the #GstPadActivateModeFunction to set.
1331 * Sets the given activate_push function for the pad. An activate_push function
1332 * prepares the element for pushing. See XXX part-activation.txt for details.
1335 gst_pad_set_activatepush_function (GstPad * pad,
1336 GstPadActivateModeFunction activatepush)
1338 g_return_if_fail (GST_IS_PAD (pad));
1340 GST_PAD_ACTIVATEPUSHFUNC (pad) = activatepush;
1341 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatepushfunc set to %s",
1342 GST_DEBUG_FUNCPTR_NAME (activatepush));
1346 * gst_pad_set_chain_function:
1347 * @pad: a sink #GstPad.
1348 * @chain: the #GstPadChainFunction to set.
1350 * Sets the given chain function for the pad. The chain function is called to
1351 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1354 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
1356 g_return_if_fail (GST_IS_PAD (pad));
1357 g_return_if_fail (GST_PAD_IS_SINK (pad));
1359 GST_PAD_CHAINFUNC (pad) = chain;
1360 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1361 GST_DEBUG_FUNCPTR_NAME (chain));
1365 * gst_pad_set_chain_list_function:
1366 * @pad: a sink #GstPad.
1367 * @chainlist: the #GstPadChainListFunction to set.
1369 * Sets the given chain list function for the pad. The chainlist function is
1370 * called to process a #GstBufferList input buffer list. See
1371 * #GstPadChainListFunction for more details.
1376 gst_pad_set_chain_list_function (GstPad * pad,
1377 GstPadChainListFunction chainlist)
1379 g_return_if_fail (GST_IS_PAD (pad));
1380 g_return_if_fail (GST_PAD_IS_SINK (pad));
1382 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1383 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1384 GST_DEBUG_FUNCPTR_NAME (chainlist));
1388 * gst_pad_set_getrange_function:
1389 * @pad: a source #GstPad.
1390 * @get: the #GstPadGetRangeFunction to set.
1392 * Sets the given getrange function for the pad. The getrange function is
1393 * called to produce a new #GstBuffer to start the processing pipeline. see
1394 * #GstPadGetRangeFunction for a description of the getrange function.
1397 gst_pad_set_getrange_function (GstPad * pad, GstPadGetRangeFunction get)
1399 g_return_if_fail (GST_IS_PAD (pad));
1400 g_return_if_fail (GST_PAD_IS_SRC (pad));
1402 GST_PAD_GETRANGEFUNC (pad) = get;
1404 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1405 GST_DEBUG_FUNCPTR_NAME (get));
1409 * gst_pad_set_event_function:
1410 * @pad: a #GstPad of either direction.
1411 * @event: the #GstPadEventFunction to set.
1413 * Sets the given event handler for the pad.
1416 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
1418 g_return_if_fail (GST_IS_PAD (pad));
1420 GST_PAD_EVENTFUNC (pad) = event;
1422 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1423 GST_DEBUG_FUNCPTR_NAME (event));
1427 * gst_pad_set_query_function:
1428 * @pad: a #GstPad of either direction.
1429 * @query: the #GstPadQueryFunction to set.
1431 * Set the given query function for the pad.
1434 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
1436 g_return_if_fail (GST_IS_PAD (pad));
1438 GST_PAD_QUERYFUNC (pad) = query;
1440 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1441 GST_DEBUG_FUNCPTR_NAME (query));
1445 * gst_pad_set_iterate_internal_links_function:
1446 * @pad: a #GstPad of either direction.
1447 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1449 * Sets the given internal link iterator function for the pad.
1454 gst_pad_set_iterate_internal_links_function (GstPad * pad,
1455 GstPadIterIntLinkFunction iterintlink)
1457 g_return_if_fail (GST_IS_PAD (pad));
1459 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1460 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1461 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1465 * gst_pad_set_link_function:
1467 * @link: the #GstPadLinkFunction to set.
1469 * Sets the given link function for the pad. It will be called when
1470 * the pad is linked with another pad.
1472 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1475 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1476 * cannot be made for some reason.
1478 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1479 * of the peer sink pad, if present.
1482 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
1484 g_return_if_fail (GST_IS_PAD (pad));
1486 GST_PAD_LINKFUNC (pad) = link;
1487 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1488 GST_DEBUG_FUNCPTR_NAME (link));
1492 * gst_pad_set_unlink_function:
1494 * @unlink: the #GstPadUnlinkFunction to set.
1496 * Sets the given unlink function for the pad. It will be called
1497 * when the pad is unlinked.
1500 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
1502 g_return_if_fail (GST_IS_PAD (pad));
1504 GST_PAD_UNLINKFUNC (pad) = unlink;
1505 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1506 GST_DEBUG_FUNCPTR_NAME (unlink));
1510 * gst_pad_set_getcaps_function:
1512 * @getcaps: the #GstPadGetCapsFunction to set.
1514 * Sets the given getcaps function for the pad. @getcaps should return the
1515 * allowable caps for a pad in the context of the element's state, its link to
1516 * other elements, and the devices or files it has opened. These caps must be a
1517 * subset of the pad template caps. In the NULL state with no links, @getcaps
1518 * should ideally return the same caps as the pad template. In rare
1519 * circumstances, an object property can affect the caps returned by @getcaps,
1520 * but this is discouraged.
1522 * You do not need to call this function if @pad's allowed caps are always the
1523 * same as the pad template caps. This can only be true if the padtemplate
1524 * has fixed simple caps.
1526 * For most filters, the caps returned by @getcaps is directly affected by the
1527 * allowed caps on other pads. For demuxers and decoders, the caps returned by
1528 * the srcpad's getcaps function is directly related to the stream data. Again,
1529 * @getcaps should return the most specific caps it reasonably can, since this
1530 * helps with autoplugging.
1532 * Note that the return value from @getcaps is owned by the caller, so the
1533 * caller should unref the caps after usage.
1536 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
1538 g_return_if_fail (GST_IS_PAD (pad));
1540 GST_PAD_GETCAPSFUNC (pad) = getcaps;
1541 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getcapsfunc set to %s",
1542 GST_DEBUG_FUNCPTR_NAME (getcaps));
1546 * gst_pad_set_fixatecaps_function:
1548 * @fixatecaps: the #GstPadFixateCapsFunction to set.
1550 * Sets the given fixatecaps function for the pad. The fixatecaps function
1551 * will be called whenever the default values for a GstCaps needs to be
1555 gst_pad_set_fixatecaps_function (GstPad * pad,
1556 GstPadFixateCapsFunction fixatecaps)
1558 g_return_if_fail (GST_IS_PAD (pad));
1560 GST_PAD_FIXATECAPSFUNC (pad) = fixatecaps;
1561 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "fixatecapsfunc set to %s",
1562 GST_DEBUG_FUNCPTR_NAME (fixatecaps));
1567 * @srcpad: the source #GstPad to unlink.
1568 * @sinkpad: the sink #GstPad to unlink.
1570 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1571 * signal on both pads.
1573 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1574 * the pads were not linked together.
1579 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1581 gboolean result = FALSE;
1582 GstElement *parent = NULL;
1585 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1586 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1587 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1588 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1590 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1591 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1592 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1594 /* We need to notify the parent before taking any pad locks as the bin in
1595 * question might be waiting for a lock on the pad while holding its lock
1596 * that our message will try to take. */
1597 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1598 if (GST_IS_ELEMENT (parent)) {
1599 gst_element_post_message (parent,
1600 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1601 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1603 gst_object_unref (parent);
1608 GST_OBJECT_LOCK (srcpad);
1609 GST_OBJECT_LOCK (sinkpad);
1611 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1612 goto not_linked_together;
1614 if (GST_PAD_UNLINKFUNC (srcpad)) {
1615 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1617 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1618 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1621 /* first clear peers */
1622 GST_PAD_PEER (srcpad) = NULL;
1623 GST_PAD_PEER (sinkpad) = NULL;
1625 /* clear pending caps if any */
1626 for (i = 0; i < GST_EVENT_MAX_STICKY; i++)
1627 gst_event_replace (&sinkpad->priv->events[i].pending, NULL);
1629 GST_OBJECT_UNLOCK (sinkpad);
1630 GST_OBJECT_UNLOCK (srcpad);
1632 /* fire off a signal to each of the pads telling them
1633 * that they've been unlinked */
1634 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1635 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1637 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1638 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1643 if (parent != NULL) {
1644 gst_element_post_message (parent,
1645 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1646 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1647 gst_object_unref (parent);
1652 not_linked_together:
1654 /* we do not emit a warning in this case because unlinking cannot
1655 * be made MT safe.*/
1656 GST_OBJECT_UNLOCK (sinkpad);
1657 GST_OBJECT_UNLOCK (srcpad);
1663 * gst_pad_is_linked:
1664 * @pad: pad to check
1666 * Checks if a @pad is linked to another pad or not.
1668 * Returns: TRUE if the pad is linked, FALSE otherwise.
1673 gst_pad_is_linked (GstPad * pad)
1677 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1679 GST_OBJECT_LOCK (pad);
1680 result = (GST_PAD_PEER (pad) != NULL);
1681 GST_OBJECT_UNLOCK (pad);
1686 /* get the caps from both pads and see if the intersection
1689 * This function should be called with the pad LOCK on both
1693 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1694 GstPadLinkCheck flags)
1696 GstCaps *srccaps = NULL;
1697 GstCaps *sinkcaps = NULL;
1698 gboolean compatible = FALSE;
1700 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1703 /* Doing the expensive caps checking takes priority over only checking the template caps */
1704 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1705 srccaps = gst_pad_get_caps_unlocked (src, NULL);
1706 sinkcaps = gst_pad_get_caps_unlocked (sink, NULL);
1708 /* If one of the two pads doesn't have a template, consider the intersection
1710 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
1711 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
1715 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
1717 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
1720 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
1722 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
1725 /* if we have caps on both pads we can check the intersection. If one
1726 * of the caps is NULL, we return TRUE. */
1727 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1729 gst_caps_unref (srccaps);
1731 gst_caps_unref (sinkcaps);
1735 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
1736 gst_caps_unref (srccaps);
1737 gst_caps_unref (sinkcaps);
1740 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
1741 (compatible ? "" : "not"));
1746 /* check if the grandparents of both pads are the same.
1747 * This check is required so that we don't try to link
1748 * pads from elements in different bins without ghostpads.
1750 * The LOCK should be held on both pads
1753 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1755 GstObject *psrc, *psink;
1757 psrc = GST_OBJECT_PARENT (src);
1758 psink = GST_OBJECT_PARENT (sink);
1760 /* if one of the pads has no parent, we allow the link */
1761 if (G_UNLIKELY (psrc == NULL || psink == NULL))
1764 /* only care about parents that are elements */
1765 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
1766 goto no_element_parent;
1768 /* if the parents are the same, we have a loop */
1769 if (G_UNLIKELY (psrc == psink))
1772 /* if they both have a parent, we check the grandparents. We can not lock
1773 * the parent because we hold on the child (pad) and the locking order is
1774 * parent >> child. */
1775 psrc = GST_OBJECT_PARENT (psrc);
1776 psink = GST_OBJECT_PARENT (psink);
1778 /* if they have grandparents but they are not the same */
1779 if (G_UNLIKELY (psrc != psink))
1780 goto wrong_grandparents;
1787 GST_CAT_DEBUG (GST_CAT_CAPS,
1788 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
1789 GST_PTR_FORMAT, psrc, psink);
1794 GST_CAT_DEBUG (GST_CAT_CAPS,
1795 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
1796 GST_PTR_FORMAT, psrc, psink);
1801 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1807 GST_CAT_DEBUG (GST_CAT_CAPS,
1808 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1809 GST_PTR_FORMAT, psrc, psink);
1814 /* FIXME leftover from an attempt at refactoring... */
1815 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
1816 * the two pads will be locked in the srcpad, sinkpad order. */
1817 static GstPadLinkReturn
1818 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
1820 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1821 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1823 GST_OBJECT_LOCK (srcpad);
1825 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1826 goto src_was_linked;
1828 GST_OBJECT_LOCK (sinkpad);
1830 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1831 goto sink_was_linked;
1833 /* check hierarchy, pads can only be linked if the grandparents
1835 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
1836 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
1837 goto wrong_hierarchy;
1839 /* check pad caps for non-empty intersection */
1840 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
1843 /* FIXME check pad scheduling for non-empty intersection */
1845 return GST_PAD_LINK_OK;
1849 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
1850 GST_DEBUG_PAD_NAME (srcpad),
1851 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
1852 /* we do not emit a warning in this case because unlinking cannot
1853 * be made MT safe.*/
1854 GST_OBJECT_UNLOCK (srcpad);
1855 return GST_PAD_LINK_WAS_LINKED;
1859 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
1860 GST_DEBUG_PAD_NAME (sinkpad),
1861 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
1862 /* we do not emit a warning in this case because unlinking cannot
1863 * be made MT safe.*/
1864 GST_OBJECT_UNLOCK (sinkpad);
1865 GST_OBJECT_UNLOCK (srcpad);
1866 return GST_PAD_LINK_WAS_LINKED;
1870 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
1871 GST_OBJECT_UNLOCK (sinkpad);
1872 GST_OBJECT_UNLOCK (srcpad);
1873 return GST_PAD_LINK_WRONG_HIERARCHY;
1877 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1878 GST_OBJECT_UNLOCK (sinkpad);
1879 GST_OBJECT_UNLOCK (srcpad);
1880 return GST_PAD_LINK_NOFORMAT;
1886 * @srcpad: the source #GstPad.
1887 * @sinkpad: the sink #GstPad.
1889 * Checks if the source pad and the sink pad are compatible so they can be
1892 * Returns: TRUE if the pads can be linked.
1895 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1897 GstPadLinkReturn result;
1899 /* generic checks */
1900 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1901 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1903 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
1904 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1906 /* gst_pad_link_prepare does everything for us, we only release the locks
1907 * on the pads that it gets us. If this function returns !OK the locks are not
1909 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
1910 if (result != GST_PAD_LINK_OK)
1913 GST_OBJECT_UNLOCK (srcpad);
1914 GST_OBJECT_UNLOCK (sinkpad);
1917 return result == GST_PAD_LINK_OK;
1921 * gst_pad_link_full:
1922 * @srcpad: the source #GstPad to link.
1923 * @sinkpad: the sink #GstPad to link.
1924 * @flags: the checks to validate when linking
1926 * Links the source pad and the sink pad.
1928 * This variant of #gst_pad_link provides a more granular control on the
1929 * checks being done when linking. While providing some considerable speedups
1930 * the caller of this method must be aware that wrong usage of those flags
1931 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
1932 * for more information.
1936 * Returns: A result code indicating if the connection worked or
1942 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
1944 GstPadLinkReturn result;
1946 GstPadLinkFunction srcfunc, sinkfunc;
1948 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
1949 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
1950 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
1951 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
1952 GST_PAD_LINK_WRONG_DIRECTION);
1954 /* Notify the parent early. See gst_pad_unlink for details. */
1955 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
1956 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
1957 gst_element_post_message (parent,
1958 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1959 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
1961 gst_object_unref (parent);
1966 /* prepare will also lock the two pads */
1967 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
1969 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
1972 /* must set peers before calling the link function */
1973 GST_PAD_PEER (srcpad) = sinkpad;
1974 GST_PAD_PEER (sinkpad) = srcpad;
1976 /* make sure we update events */
1977 prepare_event_update (srcpad, sinkpad);
1979 /* get the link functions */
1980 srcfunc = GST_PAD_LINKFUNC (srcpad);
1981 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
1983 if (G_UNLIKELY (srcfunc || sinkfunc)) {
1984 /* custom link functions, execute them */
1985 GST_OBJECT_UNLOCK (sinkpad);
1986 GST_OBJECT_UNLOCK (srcpad);
1989 /* this one will call the peer link function */
1990 result = srcfunc (srcpad, sinkpad);
1991 } else if (sinkfunc) {
1992 /* if no source link function, we need to call the sink link
1993 * function ourselves. */
1994 result = sinkfunc (sinkpad, srcpad);
1997 GST_OBJECT_LOCK (srcpad);
1998 GST_OBJECT_LOCK (sinkpad);
2000 /* we released the lock, check if the same pads are linked still */
2001 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
2002 goto concurrent_link;
2004 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
2007 GST_OBJECT_UNLOCK (sinkpad);
2008 GST_OBJECT_UNLOCK (srcpad);
2010 /* fire off a signal to each of the pads telling them
2011 * that they've been linked */
2012 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
2013 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
2015 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
2016 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2018 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
2021 if (G_LIKELY (parent)) {
2022 gst_element_post_message (parent,
2023 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
2024 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
2025 gst_object_unref (parent);
2033 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
2034 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2035 GST_OBJECT_UNLOCK (sinkpad);
2036 GST_OBJECT_UNLOCK (srcpad);
2038 /* The other link operation succeeded first */
2039 result = GST_PAD_LINK_WAS_LINKED;
2044 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
2045 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2047 GST_PAD_PEER (srcpad) = NULL;
2048 GST_PAD_PEER (sinkpad) = NULL;
2050 GST_OBJECT_UNLOCK (sinkpad);
2051 GST_OBJECT_UNLOCK (srcpad);
2059 * @srcpad: the source #GstPad to link.
2060 * @sinkpad: the sink #GstPad to link.
2062 * Links the source pad and the sink pad.
2064 * Returns: A result code indicating if the connection worked or
2070 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2072 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2076 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2078 GstPadTemplate **template_p;
2080 /* this function would need checks if it weren't static */
2082 GST_OBJECT_LOCK (pad);
2083 template_p = &pad->padtemplate;
2084 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2085 GST_OBJECT_UNLOCK (pad);
2088 gst_pad_template_pad_created (templ, pad);
2092 * gst_pad_get_pad_template:
2095 * Gets the template for @pad.
2097 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2098 * instantiated, or %NULL if this pad has no template. Unref after
2102 gst_pad_get_pad_template (GstPad * pad)
2104 GstPadTemplate *templ;
2106 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2108 templ = GST_PAD_PAD_TEMPLATE (pad);
2110 return (templ ? gst_object_ref (templ) : NULL);
2114 caps_with_getcaps (GstPad * pad, GstCaps * filter)
2118 if (GST_PAD_GETCAPSFUNC (pad) == NULL)
2121 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2122 "dispatching to pad getcaps function with "
2123 "filter %" GST_PTR_FORMAT, filter);
2125 GST_OBJECT_FLAG_SET (pad, GST_PAD_IN_GETCAPS);
2126 GST_OBJECT_UNLOCK (pad);
2127 result = GST_PAD_GETCAPSFUNC (pad) (pad, filter);
2128 GST_OBJECT_LOCK (pad);
2129 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_IN_GETCAPS);
2131 if (G_UNLIKELY (result == NULL))
2134 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2135 "pad getcaps returned %" GST_PTR_FORMAT, result);
2137 #ifndef G_DISABLE_ASSERT
2138 /* check that the returned caps are a real subset of the template caps */
2139 if (GST_PAD_PAD_TEMPLATE (pad)) {
2140 const GstCaps *templ_caps =
2141 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2142 if (!gst_caps_is_subset (result, templ_caps)) {
2145 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
2146 "pad returned caps %" GST_PTR_FORMAT
2147 " which are not a real subset of its template caps %"
2148 GST_PTR_FORMAT, result, templ_caps);
2150 ("pad %s:%s returned caps which are not a real "
2151 "subset of its template caps", GST_DEBUG_PAD_NAME (pad));
2152 temp = gst_caps_intersect (templ_caps, result);
2153 gst_caps_unref (result);
2158 if (!gst_caps_is_subset (result, filter)) {
2161 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
2162 "pad returned caps %" GST_PTR_FORMAT
2163 " which are not a real subset of the filter caps %"
2164 GST_PTR_FORMAT, result, filter);
2165 g_warning ("pad %s:%s returned caps which are not a real "
2166 "subset of the filter caps", GST_DEBUG_PAD_NAME (pad));
2167 /* FIXME: Order? But shouldn't happen anyway... */
2168 temp = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2169 gst_caps_unref (result);
2180 g_critical ("pad %s:%s returned NULL caps from getcaps function",
2181 GST_DEBUG_PAD_NAME (pad));
2186 /* should be called with the pad LOCK held */
2187 /* refs the caps, so caller is responsible for getting it unreffed */
2189 gst_pad_get_caps_unlocked (GstPad * pad, GstCaps * filter)
2191 GstCaps *result = NULL;
2192 GstPadTemplate *templ;
2193 gboolean fixed_caps;
2195 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2197 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2200 /* fixed caps, try the negotiated caps first */
2201 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2202 if ((result = get_pad_caps (pad)))
2206 /* try the getcaps function next */
2207 if ((result = caps_with_getcaps (pad, filter)))
2210 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2211 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2212 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2217 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2218 "non-fixed pad caps: trying pad caps");
2219 /* non fixed caps, try the negotiated caps */
2220 if ((result = get_pad_caps (pad)))
2224 /* this almost never happens */
2225 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2226 result = gst_caps_new_empty ();
2230 /* run the filter on the result */
2232 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2233 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2234 GST_PTR_FORMAT, result, result, filter, filter);
2235 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2236 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2239 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2240 "using caps %p %" GST_PTR_FORMAT, result, result);
2241 result = gst_caps_ref (result);
2248 * gst_pad_has_current_caps:
2249 * @pad: a #GstPad to check
2251 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2253 * Returns: TRUE when @pad has caps associated with it.
2256 gst_pad_has_current_caps (GstPad * pad)
2261 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2263 GST_OBJECT_LOCK (pad);
2264 caps = get_pad_caps (pad);
2265 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2266 "check current pad caps %" GST_PTR_FORMAT, caps);
2267 result = (caps != NULL);
2268 GST_OBJECT_UNLOCK (pad);
2274 * gst_pad_get_current_caps:
2275 * @pad: a #GstPad to get the current capabilities of.
2277 * Gets the capabilities currently configured on @pad with the last
2278 * #GST_EVENT_CAPS event.
2280 * Returns: the current caps of the pad with incremented ref-count.
2283 gst_pad_get_current_caps (GstPad * pad)
2287 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2289 GST_OBJECT_LOCK (pad);
2290 if ((result = get_pad_caps (pad)))
2291 gst_caps_ref (result);
2292 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2293 "get current pad caps %" GST_PTR_FORMAT, result);
2294 GST_OBJECT_UNLOCK (pad);
2301 * @pad: a #GstPad to get the capabilities of.
2302 * @filter: suggested #GstCaps.
2304 * Gets the capabilities this pad can produce or consume.
2305 * Note that this method doesn't necessarily return the caps set by
2306 * gst_pad_set_caps() - use gst_pad_get_current_caps() for that instead.
2307 * gst_pad_get_caps returns all possible caps a pad can operate with, using
2308 * the pad's get_caps function;
2309 * this returns the pad template caps if not explicitly set.
2311 * When called on sinkpads @filter contains the caps that
2312 * upstream could produce in the order preferred by upstream. When
2313 * called on srcpads @filter contains the caps accepted by
2314 * downstream in the preffered order. @filter might be %NULL but
2315 * if it is not %NULL the returned caps will be a subset of @filter.
2317 * Note that this function does not return writable #GstCaps, use
2318 * gst_caps_make_writable() before modifying the caps.
2320 * Returns: (transfer full): the caps of the pad with incremented ref-count.
2323 gst_pad_get_caps (GstPad * pad, GstCaps * filter)
2325 GstCaps *result = NULL;
2327 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2328 g_return_val_if_fail (filter == NULL || GST_IS_CAPS (filter), NULL);
2330 GST_OBJECT_LOCK (pad);
2332 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2334 result = gst_pad_get_caps_unlocked (pad, filter);
2336 GST_OBJECT_UNLOCK (pad);
2343 * gst_pad_peer_get_caps:
2344 * @pad: a #GstPad to get the capabilities of.
2345 * @filter: a #GstCaps filter.
2347 * Gets the capabilities of the peer connected to this pad. Similar to
2348 * gst_pad_get_caps().
2350 * When called on srcpads @filter contains the caps that
2351 * upstream could produce in the order preferred by upstream. When
2352 * called on sinkpads @filter contains the caps accepted by
2353 * downstream in the preffered order. @filter might be %NULL but
2354 * if it is not %NULL the returned caps will be a subset of @filter.
2356 * Returns: the caps of the peer pad with incremented ref-count. This function
2357 * returns %NULL when there is no peer pad.
2360 gst_pad_peer_get_caps (GstPad * pad, GstCaps * filter)
2363 GstCaps *result = NULL;
2365 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2366 g_return_val_if_fail (filter == NULL || GST_IS_CAPS (filter), NULL);
2368 GST_OBJECT_LOCK (pad);
2370 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get peer caps");
2372 peerpad = GST_PAD_PEER (pad);
2373 if (G_UNLIKELY (peerpad == NULL))
2376 gst_object_ref (peerpad);
2377 GST_OBJECT_UNLOCK (pad);
2379 result = gst_pad_get_caps (peerpad, filter);
2381 gst_object_unref (peerpad);
2387 GST_OBJECT_UNLOCK (pad);
2393 gst_pad_fixate_caps_default (GstPad * pad, GstCaps * caps)
2395 /* default fixation */
2396 gst_caps_fixate (caps);
2400 * gst_pad_fixate_caps:
2401 * @pad: a #GstPad to fixate
2402 * @caps: the #GstCaps to fixate
2404 * Fixate a caps on the given pad. Modifies the caps in place, so you should
2405 * make sure that the caps are actually writable (see gst_caps_make_writable()).
2408 gst_pad_fixate_caps (GstPad * pad, GstCaps * caps)
2410 GstPadFixateCapsFunction fixatefunc;
2412 g_return_if_fail (GST_IS_PAD (pad));
2413 g_return_if_fail (caps != NULL);
2414 g_return_if_fail (!gst_caps_is_empty (caps));
2415 g_return_if_fail (!gst_caps_is_any (caps));
2417 if (gst_caps_is_fixed (caps) || gst_caps_is_any (caps))
2420 g_return_if_fail (gst_caps_is_writable (caps));
2422 if (G_LIKELY ((fixatefunc = GST_PAD_FIXATECAPSFUNC (pad))))
2423 fixatefunc (pad, caps);
2427 * gst_pad_accept_caps:
2428 * @pad: a #GstPad to check
2429 * @caps: a #GstCaps to check on the pad
2431 * Check if the given pad accepts the caps.
2433 * Returns: TRUE if the pad can accept the caps.
2436 gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
2441 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2442 g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
2444 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "accept caps of %p", caps);
2446 query = gst_query_new_accept_caps (caps);
2447 res = gst_pad_query (pad, query);
2449 GST_DEBUG_OBJECT (pad, "query returned %d", res);
2450 gst_query_parse_accept_caps_result (query, &res);
2452 gst_query_unref (query);
2458 * gst_pad_peer_accept_caps:
2459 * @pad: a #GstPad to check the peer of
2460 * @caps: a #GstCaps to check on the pad
2462 * Check if the peer of @pad accepts @caps. If @pad has no peer, this function
2465 * Returns: TRUE if the peer of @pad can accept the caps or @pad has no peer.
2468 gst_pad_peer_accept_caps (GstPad * pad, GstCaps * caps)
2473 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2474 g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
2476 query = gst_query_new_accept_caps (caps);
2477 result = gst_pad_peer_query (pad, query);
2478 gst_query_unref (query);
2485 * @pad: a #GstPad to set the capabilities of.
2486 * @caps: (transfer none): a #GstCaps to set.
2488 * Sets the capabilities of this pad. The caps must be fixed. Any previous
2489 * caps on the pad will be unreffed. This function refs the caps so you should
2490 * unref if as soon as you don't need it anymore.
2491 * It is possible to set NULL caps, which will make the pad unnegotiated
2494 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
2495 * or bad parameters were provided to this function.
2500 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
2503 gboolean res = TRUE;
2505 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2506 g_return_val_if_fail (caps != NULL && gst_caps_is_fixed (caps), FALSE);
2508 event = gst_event_new_caps (caps);
2510 if (GST_PAD_IS_SRC (pad))
2511 res = gst_pad_push_event (pad, event);
2513 res = gst_pad_send_event (pad, event);
2519 do_event_function (GstPad * pad, GstEvent * event,
2520 GstPadEventFunction eventfunc, gboolean * caps_notify)
2522 gboolean result = TRUE, call_event = TRUE;
2523 GstCaps *caps, *old, *templ;
2525 switch (GST_EVENT_TYPE (event)) {
2526 case GST_EVENT_CAPS:
2528 /* backwards compatibility mode for caps */
2529 gst_event_parse_caps (event, &caps);
2531 /* See if pad accepts the caps */
2532 templ = gst_pad_get_pad_template_caps (pad);
2533 if (!gst_caps_is_subset (caps, templ))
2536 /* check if it changed */
2537 if ((old = gst_pad_get_current_caps (pad))) {
2538 call_event = !gst_caps_is_equal (caps, old);
2539 gst_caps_unref (old);
2542 *caps_notify = TRUE;
2543 gst_caps_unref (templ);
2551 GST_DEBUG_OBJECT (pad, "calling event function with event %p", event);
2552 result = eventfunc (pad, event);
2554 gst_event_unref (event);
2561 gst_caps_unref (templ);
2562 gst_event_unref (event);
2563 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2564 "caps %" GST_PTR_FORMAT " not accepted", caps);
2569 /* function to send all pending events on the sinkpad to the event
2570 * function and collect the results. This function should be called with
2571 * the object lock. The object lock might be released by this function.
2573 static GstFlowReturn
2574 gst_pad_update_events (GstPad * pad)
2576 GstFlowReturn ret = GST_FLOW_OK;
2578 GstPadEventFunction eventfunc;
2580 gboolean caps_notify = FALSE;
2582 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
2585 for (i = 0; i < GST_EVENT_MAX_STICKY; i++) {
2589 ev = &pad->priv->events[i];
2591 /* skip without pending event */
2592 if ((event = gst_event_steal (&ev->pending)) == NULL)
2595 gst_event_ref (event);
2596 GST_OBJECT_UNLOCK (pad);
2598 res = do_event_function (pad, event, eventfunc, &caps_notify);
2600 /* things could have changed while we release the lock, check if we still
2601 * are handling the same event, if we don't something changed and we have
2602 * to try again. FIXME. we need a cookie here. FIXME, we also want to remove
2603 * that lock eventually and then do the retry elsewhere. */
2606 /* make the event active */
2607 gst_event_take (&ev->event, event);
2609 /* notify caps change when needed */
2611 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
2612 caps_notify = FALSE;
2615 gst_event_unref (event);
2616 ret = GST_FLOW_ERROR;
2618 GST_OBJECT_LOCK (pad);
2620 /* when we get here all events were successfully updated. */
2626 g_warning ("pad %s:%s has no event handler, file a bug.",
2627 GST_DEBUG_PAD_NAME (pad));
2628 return GST_FLOW_NOT_SUPPORTED;
2633 * gst_pad_get_pad_template_caps:
2634 * @pad: a #GstPad to get the template capabilities from.
2636 * Gets the capabilities for @pad's template.
2638 * Returns: (transfer full): the #GstCaps of this pad template.
2639 * Unref after usage.
2642 gst_pad_get_pad_template_caps (GstPad * pad)
2644 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2646 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2648 if (GST_PAD_PAD_TEMPLATE (pad))
2649 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2651 return gst_static_caps_get (&anycaps);
2656 * @pad: a #GstPad to get the peer of.
2658 * Gets the peer of @pad. This function refs the peer pad so
2659 * you need to unref it after use.
2661 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2666 gst_pad_get_peer (GstPad * pad)
2670 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2672 GST_OBJECT_LOCK (pad);
2673 result = GST_PAD_PEER (pad);
2675 gst_object_ref (result);
2676 GST_OBJECT_UNLOCK (pad);
2682 * gst_pad_get_allowed_caps:
2685 * Gets the capabilities of the allowed media types that can flow through
2686 * @pad and its peer.
2688 * The allowed capabilities is calculated as the intersection of the results of
2689 * calling gst_pad_get_caps() on @pad and its peer. The caller owns a reference
2690 * on the resulting caps.
2692 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2693 * caps when you no longer need it. This function returns NULL when @pad
2699 gst_pad_get_allowed_caps (GstPad * pad)
2706 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2708 GST_OBJECT_LOCK (pad);
2709 peer = GST_PAD_PEER (pad);
2710 if (G_UNLIKELY (peer == NULL))
2713 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2715 gst_object_ref (peer);
2716 GST_OBJECT_UNLOCK (pad);
2717 mycaps = gst_pad_get_caps (pad, NULL);
2719 peercaps = gst_pad_get_caps (peer, NULL);
2720 gst_object_unref (peer);
2722 caps = gst_caps_intersect (mycaps, peercaps);
2723 gst_caps_unref (peercaps);
2724 gst_caps_unref (mycaps);
2726 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2733 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2734 GST_OBJECT_UNLOCK (pad);
2741 * gst_pad_iterate_internal_links_default:
2742 * @pad: the #GstPad to get the internal links of.
2744 * Iterate the list of pads to which the given pad is linked to inside of
2745 * the parent element.
2746 * This is the default handler, and thus returns an iterator of all of the
2747 * pads inside the parent element with opposite direction.
2749 * The caller must free this iterator after use with gst_iterator_free().
2751 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2752 * returned pad with gst_object_unref().
2757 gst_pad_iterate_internal_links_default (GstPad * pad)
2765 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2770 GST_OBJECT_LOCK (pad);
2771 parent = GST_PAD_PARENT (pad);
2772 if (!parent || !GST_IS_ELEMENT (parent))
2775 gst_object_ref (parent);
2776 GST_OBJECT_UNLOCK (pad);
2778 if (pad->direction == GST_PAD_SRC)
2779 padlist = &parent->sinkpads;
2781 padlist = &parent->srcpads;
2783 GST_DEBUG_OBJECT (pad, "Making iterator");
2785 cookie = &parent->pads_cookie;
2787 lock = GST_OBJECT_GET_LOCK (parent);
2790 res = gst_iterator_new_list (GST_TYPE_PAD,
2791 lock, cookie, padlist, (GObject *) owner, NULL);
2793 gst_object_unref (owner);
2800 GST_OBJECT_UNLOCK (pad);
2801 GST_DEBUG_OBJECT (pad, "no parent element");
2807 * gst_pad_iterate_internal_links:
2808 * @pad: the GstPad to get the internal links of.
2810 * Gets an iterator for the pads to which the given pad is linked to inside
2811 * of the parent element.
2813 * Each #GstPad element yielded by the iterator will have its refcount increased,
2814 * so unref after use.
2816 * Free-function: gst_iterator_free
2818 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2819 * pad does not have an iterator function configured. Use
2820 * gst_iterator_free() after usage.
2825 gst_pad_iterate_internal_links (GstPad * pad)
2827 GstIterator *res = NULL;
2829 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2831 if (GST_PAD_ITERINTLINKFUNC (pad))
2832 res = GST_PAD_ITERINTLINKFUNC (pad) (pad);
2840 * @forward: a #GstPadForwardFunction
2841 * @user_data: user data passed to @forward
2843 * Calls @forward for all internally linked pads of @pad. This function deals with
2844 * dynamically changing internal pads and will make sure that the @forward
2845 * function is only called once for each pad.
2847 * When @forward returns TRUE, no further pads will be processed.
2849 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2852 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2855 gboolean result = FALSE;
2857 gboolean done = FALSE;
2858 GValue item = { 0, };
2859 GList *pushed_pads = NULL;
2861 iter = gst_pad_iterate_internal_links (pad);
2867 switch (gst_iterator_next (iter, &item)) {
2868 case GST_ITERATOR_OK:
2872 intpad = g_value_get_object (&item);
2874 /* if already pushed, skip. FIXME, find something faster to tag pads */
2875 if (g_list_find (pushed_pads, intpad)) {
2876 g_value_reset (&item);
2880 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2881 GST_DEBUG_PAD_NAME (intpad));
2882 done = result = forward (intpad, user_data);
2884 pushed_pads = g_list_prepend (pushed_pads, intpad);
2886 g_value_reset (&item);
2889 case GST_ITERATOR_RESYNC:
2890 /* We don't reset the result here because we don't push the event
2891 * again on pads that got the event already and because we need
2892 * to consider the result of the previous pushes */
2893 gst_iterator_resync (iter);
2895 case GST_ITERATOR_ERROR:
2896 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2899 case GST_ITERATOR_DONE:
2904 g_value_unset (&item);
2905 gst_iterator_free (iter);
2907 g_list_free (pushed_pads);
2917 gboolean dispatched;
2921 event_forward_func (GstPad * pad, EventData * data)
2923 /* for each pad we send to, we should ref the event; it's up
2924 * to downstream to unref again when handled. */
2925 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2926 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2928 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2930 data->dispatched = TRUE;
2937 * gst_pad_event_default:
2938 * @pad: a #GstPad to call the default event handler on.
2939 * @event: (transfer full): the #GstEvent to handle.
2941 * Invokes the default event handler for the given pad.
2943 * The EOS event will pause the task associated with @pad before it is forwarded
2944 * to all internally linked pads,
2946 * The CAPS event will never be forwarded.
2948 * The the event is sent to all pads internally linked to @pad. This function
2949 * takes ownership of @event.
2951 * Returns: TRUE if the event was sent successfully.
2954 gst_pad_event_default (GstPad * pad, GstEvent * event)
2959 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2960 g_return_val_if_fail (event != NULL, FALSE);
2962 GST_LOG_OBJECT (pad, "default event handler");
2964 switch (GST_EVENT_TYPE (event)) {
2967 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
2968 gst_pad_pause_task (pad);
2976 data.dispatched = FALSE;
2977 data.result = FALSE;
2979 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2981 /* for sinkpads without a parent element or without internal links, nothing
2982 * will be dispatched but we still want to return TRUE. */
2983 if (data.dispatched)
2984 result = data.result;
2988 gst_event_unref (event);
2993 /* Default accept caps implementation just checks against
2994 * the allowed caps for the pad */
2996 gst_pad_query_accept_caps (GstPad * pad, GstQuery * query)
2998 /* get the caps and see if it intersects to something not empty */
2999 GstCaps *caps, *allowed;
3002 gst_query_parse_accept_caps (query, &caps);
3004 GST_DEBUG_OBJECT (pad, "caps %" GST_PTR_FORMAT, caps);
3006 allowed = gst_pad_get_caps (pad, NULL);
3008 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
3009 result = gst_caps_is_subset (caps, allowed);
3010 gst_caps_unref (allowed);
3012 GST_DEBUG_OBJECT (pad, "no caps allowed on the pad");
3015 gst_query_set_accept_caps_result (query, result);
3021 * gst_pad_query_default:
3022 * @pad: a #GstPad to call the default query handler on.
3023 * @query: (transfer none): the #GstQuery to handle.
3025 * Invokes the default query handler for the given pad.
3026 * The query is sent to all pads internally linked to @pad. Note that
3027 * if there are many possible sink pads that are internally linked to
3028 * @pad, only one will be sent the query.
3029 * Multi-sinkpad elements should implement custom query handlers.
3031 * Returns: TRUE if the query was performed successfully.
3034 gst_pad_query_default (GstPad * pad, GstQuery * query)
3036 gboolean forward = TRUE, ret = FALSE;
3038 switch (GST_QUERY_TYPE (query)) {
3039 case GST_QUERY_SCHEDULING:
3042 case GST_QUERY_ACCEPT_CAPS:
3043 ret = gst_pad_query_accept_caps (pad, query);
3046 case GST_QUERY_POSITION:
3047 case GST_QUERY_SEEKING:
3048 case GST_QUERY_FORMATS:
3049 case GST_QUERY_LATENCY:
3050 case GST_QUERY_JITTER:
3051 case GST_QUERY_RATE:
3052 case GST_QUERY_CONVERT:
3053 case GST_QUERY_ALLOCATION:
3059 ret = gst_pad_forward
3060 (pad, (GstPadForwardFunction) gst_pad_peer_query, query);
3066 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
3068 GstPad *pad = data->pad;
3069 GstPadProbeInfo *info = data->info;
3070 GstPadProbeType type, flags;
3071 GstPadProbeCallback callback;
3072 GstPadProbeReturn ret;
3074 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3075 "hook %lu, cookie %u checking", hook->hook_id, PROBE_COOKIE (hook));
3077 /* if we have called this callback, do nothing */
3078 if (PROBE_COOKIE (hook) == data->cookie) {
3079 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3080 "hook %lu, cookie %u already called", hook->hook_id,
3081 PROBE_COOKIE (hook));
3085 PROBE_COOKIE (hook) = data->cookie;
3087 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
3090 /* one of the data types */
3091 if ((flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
3093 /* one of the scheduling types */
3094 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
3096 /* all of the blocking types must match */
3097 if ((flags & GST_PAD_PROBE_TYPE_BLOCKING) !=
3098 (type & GST_PAD_PROBE_TYPE_BLOCKING))
3101 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3102 "hook %lu with flags 0x%08x matches", hook->hook_id, flags);
3104 callback = (GstPadProbeCallback) hook->func;
3105 if (callback == NULL)
3108 GST_OBJECT_UNLOCK (pad);
3110 ret = callback (pad, info, hook->data);
3112 GST_OBJECT_LOCK (pad);
3113 data->marshalled = TRUE;
3116 case GST_PAD_PROBE_REMOVE:
3117 /* remove the probe */
3118 GST_DEBUG_OBJECT (pad, "asked to remove hook");
3119 cleanup_hook (pad, hook);
3121 case GST_PAD_PROBE_DROP:
3122 /* need to drop the data, make sure other probes don't get called
3124 GST_DEBUG_OBJECT (pad, "asked to drop item");
3125 info->type = GST_PAD_PROBE_TYPE_INVALID;
3126 data->dropped = TRUE;
3128 case GST_PAD_PROBE_PASS:
3129 /* inform the pad block to let things pass */
3130 GST_DEBUG_OBJECT (pad, "asked to pass item");
3134 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
3141 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3142 "hook %lu with flags 0x%08x does not match %08x", hook->hook_id,
3148 #define PROBE_PRE_PULL(pad,mask,data,offs,size,label,probed,defaultval) \
3150 if (G_UNLIKELY (pad->num_probes)) { \
3151 /* we start with passing NULL as the data item */ \
3152 GstPadProbeInfo info = { mask, NULL, offs, size }; \
3153 ret = do_probe_callbacks (pad, &info, defaultval); \
3154 /* store the possibly updated data item */ \
3155 data = GST_PAD_PROBE_INFO_DATA (&info); \
3156 /* if something went wrong, exit */ \
3157 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3159 /* otherwise check if the probe retured data */ \
3160 if (G_UNLIKELY (data != NULL)) \
3166 /* a probe that does not take or return any data */
3167 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
3169 if (G_UNLIKELY (pad->num_probes)) { \
3170 /* pass NULL as the data item */ \
3171 GstPadProbeInfo info = { mask, NULL, 0, 0 }; \
3172 ret = do_probe_callbacks (pad, &info, defaultval); \
3173 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3178 #define PROBE_FULL(pad,mask,data,offs,size,label,defaultval) \
3180 if (G_UNLIKELY (pad->num_probes)) { \
3181 GstPadProbeInfo info = { mask, data, offs, size }; \
3182 ret = do_probe_callbacks (pad, &info, defaultval); \
3183 data = GST_PAD_PROBE_INFO_DATA (&info); \
3184 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
3189 #define PROBE_PUSH(pad,mask,data,label) \
3190 PROBE_FULL(pad, mask, data, -1, -1, label, GST_FLOW_OK);
3191 #define PROBE_PULL(pad,mask,data,offs,size,label) \
3192 PROBE_FULL(pad, mask, data, offs, size, label, GST_FLOW_OK);
3194 static GstFlowReturn
3195 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
3196 GstFlowReturn defaultval)
3205 data.marshalled = FALSE;
3206 data.dropped = FALSE;
3207 data.cookie = ++pad->priv->probe_cookie;
3210 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
3213 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3214 "do probes cookie %u", data.cookie);
3215 cookie = pad->priv->probe_list_cookie;
3217 g_hook_list_marshal (&pad->probes, TRUE,
3218 (GHookMarshaller) probe_hook_marshal, &data);
3220 /* if the list changed, call the new callbacks (they will not have their
3221 * cookie set to data.cookie */
3222 if (cookie != pad->priv->probe_list_cookie) {
3223 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3224 "probe list changed, restarting");
3228 /* the first item that dropped will stop the hooks and then we drop here */
3232 /* if no handler matched and we are blocking, let the item pass */
3233 if (!data.marshalled && is_block)
3236 /* At this point, all handlers returned either OK or PASS. If one handler
3237 * returned PASS, let the item pass */
3242 while (GST_PAD_IS_BLOCKED (pad)) {
3243 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3244 "we are blocked %d times", pad->num_blocked);
3246 /* we might have released the lock */
3247 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3250 /* now we block the streaming thread. It can be unlocked when we
3251 * deactivate the pad (which will also set the FLUSHING flag) or
3252 * when the pad is unblocked. A flushing event will also unblock
3253 * the pad after setting the FLUSHING flag. */
3254 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3255 "Waiting to be unblocked or set flushing");
3256 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKING);
3257 GST_PAD_BLOCK_WAIT (pad);
3258 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKING);
3259 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3261 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3271 GST_DEBUG_OBJECT (pad, "pad is flushing");
3272 return GST_FLOW_WRONG_STATE;
3276 GST_DEBUG_OBJECT (pad, "data is dropped");
3277 return GST_FLOW_CUSTOM_SUCCESS;
3281 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3282 GST_DEBUG_OBJECT (pad, "data is passed");
3290 * gst_pad_get_offset:
3293 * Get the offset applied to the running time of @pad. @pad has to be a source
3296 * Returns: the offset.
3299 gst_pad_get_offset (GstPad * pad)
3303 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3305 GST_OBJECT_LOCK (pad);
3306 result = pad->offset;
3307 GST_OBJECT_UNLOCK (pad);
3313 * gst_pad_set_offset:
3315 * @offset: the offset
3317 * Set the offset that will be applied to the running time of @pad.
3320 gst_pad_set_offset (GstPad * pad, gint64 offset)
3326 g_return_if_fail (GST_IS_PAD (pad));
3328 GST_OBJECT_LOCK (pad);
3329 /* if nothing changed, do nothing */
3330 if (pad->offset == offset)
3333 pad->offset = offset;
3335 /* if no peer, we just updated the offset */
3336 if ((peer = GST_PAD_PEER (pad)) == NULL)
3339 /* switch pads around when dealing with a sinkpad */
3340 if (GST_PAD_IS_SINK (pad)) {
3341 /* ref the peer so it doesn't go away when we release the lock */
3342 tmp = gst_object_ref (peer);
3343 /* make sure we get the peer (the srcpad) */
3344 GST_OBJECT_UNLOCK (pad);
3350 GST_OBJECT_LOCK (pad);
3351 /* check if the pad didn't get relinked */
3352 if (GST_PAD_PEER (pad) != peer)
3355 /* we can release the ref now */
3356 gst_object_unref (peer);
3359 /* the index of the segment event in the array */
3360 idx = GST_EVENT_STICKY_IDX_TYPE (GST_EVENT_SEGMENT);
3362 /* lock order is srcpad >> sinkpad */
3363 GST_OBJECT_LOCK (peer);
3364 /* take the current segment event, adjust it and then place
3365 * it on the sinkpad. events on the srcpad are always active. */
3366 if (replace_event (pad, peer, idx))
3367 GST_OBJECT_FLAG_SET (peer, GST_PAD_NEED_EVENTS);
3369 GST_OBJECT_UNLOCK (peer);
3372 GST_OBJECT_UNLOCK (pad);
3378 * @pad: a #GstPad to invoke the default query on.
3379 * @query: (transfer none): the #GstQuery to perform.
3381 * Dispatches a query to a pad. The query should have been allocated by the
3382 * caller via one of the type-specific allocation functions. The element that
3383 * the pad belongs to is responsible for filling the query with an appropriate
3384 * response, which should then be parsed with a type-specific query parsing
3387 * Again, the caller is responsible for both the allocation and deallocation of
3388 * the query structure.
3390 * Please also note that some queries might need a running pipeline to work.
3392 * Returns: TRUE if the query could be performed.
3395 gst_pad_query (GstPad * pad, GstQuery * query)
3398 GstPadQueryFunction func;
3399 GstPadProbeType type;
3402 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3403 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3405 GST_DEBUG_OBJECT (pad, "sending query %p (%s)", query,
3406 GST_QUERY_TYPE_NAME (query));
3408 if (GST_PAD_IS_SRC (pad))
3409 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3411 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3413 GST_OBJECT_LOCK (pad);
3414 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3415 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3416 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3417 GST_OBJECT_UNLOCK (pad);
3419 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3422 res = func (pad, query);
3424 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3425 GST_QUERY_TYPE_NAME (query), res);
3430 GST_OBJECT_LOCK (pad);
3431 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3432 GST_OBJECT_UNLOCK (pad);
3438 GST_DEBUG_OBJECT (pad, "had no query function");
3443 GST_DEBUG_OBJECT (pad, "query failed");
3448 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3449 GST_OBJECT_UNLOCK (pad);
3455 * gst_pad_peer_query:
3456 * @pad: a #GstPad to invoke the peer query on.
3457 * @query: (transfer none): the #GstQuery to perform.
3459 * Performs gst_pad_query() on the peer of @pad.
3461 * The caller is responsible for both the allocation and deallocation of
3462 * the query structure.
3464 * Returns: TRUE if the query could be performed. This function returns %FALSE
3465 * if @pad has no peer.
3470 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3473 GstPadProbeType type;
3477 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3478 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3480 if (GST_PAD_IS_SRC (pad))
3481 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3483 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3485 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3486 GST_QUERY_TYPE_NAME (query));
3488 GST_OBJECT_LOCK (pad);
3489 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3490 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3491 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3493 peerpad = GST_PAD_PEER (pad);
3494 if (G_UNLIKELY (peerpad == NULL))
3497 gst_object_ref (peerpad);
3498 GST_OBJECT_UNLOCK (pad);
3500 res = gst_pad_query (peerpad, query);
3502 gst_object_unref (peerpad);
3507 GST_OBJECT_LOCK (pad);
3508 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3509 GST_OBJECT_UNLOCK (pad);
3516 GST_WARNING_OBJECT (pad, "pad has no peer");
3517 GST_OBJECT_UNLOCK (pad);
3522 GST_DEBUG_OBJECT (pad, "query failed");
3527 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3528 GST_OBJECT_UNLOCK (pad);
3533 /**********************************************************************
3534 * Data passing functions
3537 /* this is the chain function that does not perform the additional argument
3538 * checking for that little extra speed.
3540 static inline GstFlowReturn
3541 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3544 gboolean needs_events;
3546 GST_PAD_STREAM_LOCK (pad);
3548 GST_OBJECT_LOCK (pad);
3549 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3552 needs_events = GST_PAD_NEEDS_EVENTS (pad);
3553 if (G_UNLIKELY (needs_events)) {
3554 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_EVENTS);
3556 GST_DEBUG_OBJECT (pad, "need to update all events");
3557 ret = gst_pad_update_events (pad);
3558 if (G_UNLIKELY (ret != GST_FLOW_OK))
3562 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3564 PROBE_PUSH (pad, type, data, probe_stopped);
3566 GST_OBJECT_UNLOCK (pad);
3568 /* NOTE: we read the chainfunc unlocked.
3569 * we cannot hold the lock for the pad so we might send
3570 * the data to the wrong function. This is not really a
3571 * problem since functions are assigned at creation time
3572 * and don't change that often... */
3573 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3574 GstPadChainFunction chainfunc;
3576 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3579 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3580 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3581 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3583 ret = chainfunc (pad, GST_BUFFER_CAST (data));
3585 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3586 "called chainfunction &%s with buffer %p, returned %s",
3587 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3589 GstPadChainListFunction chainlistfunc;
3591 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3594 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3595 "calling chainlistfunction &%s",
3596 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3598 ret = chainlistfunc (pad, GST_BUFFER_LIST_CAST (data));
3600 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3601 "called chainlistfunction &%s, returned %s",
3602 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3605 GST_PAD_STREAM_UNLOCK (pad);
3612 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3613 "chaining, but pad was flushing");
3614 GST_OBJECT_UNLOCK (pad);
3615 GST_PAD_STREAM_UNLOCK (pad);
3616 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3617 return GST_FLOW_WRONG_STATE;
3621 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "events were not accepted");
3622 GST_OBJECT_UNLOCK (pad);
3623 GST_PAD_STREAM_UNLOCK (pad);
3624 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3629 GST_OBJECT_UNLOCK (pad);
3630 GST_PAD_STREAM_UNLOCK (pad);
3631 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3634 case GST_FLOW_CUSTOM_SUCCESS:
3635 GST_DEBUG_OBJECT (pad, "dropped buffer");
3639 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
3646 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3647 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3648 "pushing, but not chainhandler");
3649 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3650 ("push on pad %s:%s but it has no chainfunction",
3651 GST_DEBUG_PAD_NAME (pad)));
3652 GST_PAD_STREAM_UNLOCK (pad);
3653 return GST_FLOW_NOT_SUPPORTED;
3659 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3660 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3663 * Chain a buffer to @pad.
3665 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
3667 * If the buffer type is not acceptable for @pad (as negotiated with a
3668 * preceeding GST_EVENT_CAPS event), this function returns
3669 * #GST_FLOW_NOT_NEGOTIATED.
3671 * The function proceeds calling the chain function installed on @pad (see
3672 * gst_pad_set_chain_function()) and the return value of that function is
3673 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3676 * In all cases, success or failure, the caller loses its reference to @buffer
3677 * after calling this function.
3679 * Returns: a #GstFlowReturn from the pad.
3684 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3686 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3687 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3688 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3690 return gst_pad_chain_data_unchecked (pad,
3691 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3694 static GstFlowReturn
3695 gst_pad_chain_list_default (GstPad * pad, GstBufferList * list)
3701 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3703 len = gst_buffer_list_length (list);
3706 for (i = 0; i < len; i++) {
3707 buffer = gst_buffer_list_get (list, i);
3709 gst_pad_chain_data_unchecked (pad,
3710 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3711 gst_buffer_ref (buffer));
3712 if (ret != GST_FLOW_OK)
3715 gst_buffer_list_unref (list);
3721 * gst_pad_chain_list:
3722 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3723 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3726 * Chain a bufferlist to @pad.
3728 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
3730 * If @pad was not negotiated properly with a CAPS event, this function
3731 * returns #GST_FLOW_NOT_NEGOTIATED.
3733 * The function proceeds calling the chainlist function installed on @pad (see
3734 * gst_pad_set_chain_list_function()) and the return value of that function is
3735 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3736 * chainlist function.
3738 * In all cases, success or failure, the caller loses its reference to @list
3739 * after calling this function.
3743 * Returns: a #GstFlowReturn from the pad.
3748 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3750 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3751 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3752 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3754 return gst_pad_chain_data_unchecked (pad,
3755 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3758 static GstFlowReturn
3759 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3764 GST_OBJECT_LOCK (pad);
3765 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3768 /* do block probes */
3769 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3771 /* do post-blocking probes */
3772 PROBE_PUSH (pad, type, data, probe_stopped);
3774 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3777 /* take ref to peer pad before releasing the lock */
3778 gst_object_ref (peer);
3780 GST_OBJECT_UNLOCK (pad);
3782 ret = gst_pad_chain_data_unchecked (peer, type, data);
3784 gst_object_unref (peer);
3786 GST_OBJECT_LOCK (pad);
3788 if (pad->priv->using == 0) {
3789 /* pad is not active anymore, trigger idle callbacks */
3790 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3791 probe_stopped, ret);
3793 GST_OBJECT_UNLOCK (pad);
3797 /* ERROR recovery here */
3801 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3802 "pushing, but pad was flushing");
3803 GST_OBJECT_UNLOCK (pad);
3804 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3805 return GST_FLOW_WRONG_STATE;
3809 GST_OBJECT_UNLOCK (pad);
3810 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3813 case GST_FLOW_CUSTOM_SUCCESS:
3814 GST_DEBUG_OBJECT (pad, "dropped buffer");
3818 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
3825 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3826 "pushing, but it was not linked");
3827 GST_OBJECT_UNLOCK (pad);
3828 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3829 return GST_FLOW_NOT_LINKED;
3835 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3836 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
3839 * Pushes a buffer to the peer of @pad.
3841 * This function will call installed block probes before triggering any
3842 * installed data probes.
3844 * The function proceeds calling gst_pad_chain() on the peer pad and returns
3845 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3848 * In all cases, success or failure, the caller loses its reference to @buffer
3849 * after calling this function.
3851 * Returns: a #GstFlowReturn from the peer pad.
3856 gst_pad_push (GstPad * pad, GstBuffer * buffer)
3858 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3859 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3860 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3862 return gst_pad_push_data (pad,
3863 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3867 * gst_pad_push_list:
3868 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3869 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
3872 * Pushes a buffer list to the peer of @pad.
3874 * This function will call installed block probes before triggering any
3875 * installed data probes.
3877 * The function proceeds calling the chain function on the peer pad and returns
3878 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3879 * be returned. If the peer pad does not have any installed chainlist function
3880 * every group buffer of the list will be merged into a normal #GstBuffer and
3881 * chained via gst_pad_chain().
3883 * In all cases, success or failure, the caller loses its reference to @list
3884 * after calling this function.
3886 * Returns: a #GstFlowReturn from the peer pad.
3893 gst_pad_push_list (GstPad * pad, GstBufferList * list)
3895 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3896 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3897 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3899 return gst_pad_push_data (pad,
3900 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3903 static GstFlowReturn
3904 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
3905 GstBuffer ** buffer)
3908 GstPadGetRangeFunction getrangefunc;
3910 GST_PAD_STREAM_LOCK (pad);
3912 GST_OBJECT_LOCK (pad);
3913 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3916 /* when one of the probes returns a buffer, probed_data will be called and we
3917 * skip calling the getrange function */
3918 PROBE_PRE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
3919 *buffer, offset, size, probe_stopped, probed_data, GST_FLOW_OK);
3920 GST_OBJECT_UNLOCK (pad);
3922 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
3925 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3926 "calling getrangefunc %s, offset %"
3927 G_GUINT64_FORMAT ", size %u",
3928 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
3930 ret = getrangefunc (pad, offset, size, buffer);
3932 if (G_UNLIKELY (ret != GST_FLOW_OK))
3933 goto get_range_failed;
3935 /* can only fire the signal if we have a valid buffer */
3936 GST_OBJECT_LOCK (pad);
3938 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
3939 *buffer, offset, size, probe_stopped_unref);
3940 GST_OBJECT_UNLOCK (pad);
3942 GST_PAD_STREAM_UNLOCK (pad);
3949 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3950 "getrange, but pad was flushing");
3951 GST_OBJECT_UNLOCK (pad);
3952 GST_PAD_STREAM_UNLOCK (pad);
3953 return GST_FLOW_WRONG_STATE;
3957 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3958 ("getrange on pad %s:%s but it has no getrangefunction",
3959 GST_DEBUG_PAD_NAME (pad)));
3960 GST_PAD_STREAM_UNLOCK (pad);
3961 return GST_FLOW_NOT_SUPPORTED;
3965 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3966 "probe returned %s", gst_flow_get_name (ret));
3967 GST_OBJECT_UNLOCK (pad);
3968 GST_PAD_STREAM_UNLOCK (pad);
3971 probe_stopped_unref:
3973 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3974 "probe returned %s", gst_flow_get_name (ret));
3975 GST_OBJECT_UNLOCK (pad);
3976 GST_PAD_STREAM_UNLOCK (pad);
3977 gst_buffer_unref (*buffer);
3983 GST_PAD_STREAM_UNLOCK (pad);
3985 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
3986 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
3987 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
3993 * gst_pad_get_range:
3994 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
3995 * @offset: The start offset of the buffer
3996 * @size: The length of the buffer
3997 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
3998 * returns #GST_FLOW_ERROR if %NULL.
4000 * When @pad is flushing this function returns #GST_FLOW_WRONG_STATE
4001 * immediately and @buffer is %NULL.
4003 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
4004 * description of a getrange function. If @pad has no getrange function
4005 * installed (see gst_pad_set_getrange_function()) this function returns
4006 * #GST_FLOW_NOT_SUPPORTED.
4008 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
4010 * Returns: a #GstFlowReturn from the pad.
4015 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
4016 GstBuffer ** buffer)
4018 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4019 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
4020 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4022 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
4026 * gst_pad_pull_range:
4027 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
4028 * @offset: The start offset of the buffer
4029 * @size: The length of the buffer
4030 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
4031 * GST_FLOW_ERROR if %NULL.
4033 * Pulls a @buffer from the peer pad.
4035 * This function will first trigger the pad block signal if it was
4038 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
4039 * function returns the result of gst_pad_get_range() on the peer pad.
4040 * See gst_pad_get_range() for a list of return values and for the
4041 * semantics of the arguments of this function.
4043 * Returns: a #GstFlowReturn from the peer pad.
4044 * When this function returns #GST_FLOW_OK, @buffer will contain a valid
4045 * #GstBuffer that should be freed with gst_buffer_unref() after usage.
4046 * @buffer may not be used or freed when any other return value than
4047 * #GST_FLOW_OK is returned.
4052 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
4053 GstBuffer ** buffer)
4057 gboolean needs_events;
4059 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4060 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
4061 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
4063 GST_OBJECT_LOCK (pad);
4064 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4067 /* when one of the probes returns a buffer, probed_data will be called and we
4068 * skip calling the peer getrange function */
4069 PROBE_PRE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
4070 *buffer, offset, size, pre_probe_stopped, probed_data, GST_FLOW_OK);
4072 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
4075 gst_object_ref (peer);
4077 GST_OBJECT_UNLOCK (pad);
4079 ret = gst_pad_get_range_unchecked (peer, offset, size, buffer);
4081 gst_object_unref (peer);
4083 GST_OBJECT_LOCK (pad);
4085 if (pad->priv->using == 0) {
4086 /* pad is not active anymore, trigger idle callbacks */
4087 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
4088 post_probe_stopped, ret);
4091 if (G_UNLIKELY (ret != GST_FLOW_OK))
4092 goto pull_range_failed;
4095 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
4096 *buffer, offset, size, post_probe_stopped);
4098 needs_events = GST_PAD_NEEDS_EVENTS (pad);
4099 if (G_UNLIKELY (needs_events)) {
4100 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_EVENTS);
4102 GST_DEBUG_OBJECT (pad, "we need to update the events");
4103 ret = gst_pad_update_events (pad);
4104 if (G_UNLIKELY (ret != GST_FLOW_OK))
4107 GST_OBJECT_UNLOCK (pad);
4111 /* ERROR recovery here */
4114 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4115 "pullrange, but pad was flushing");
4116 GST_OBJECT_UNLOCK (pad);
4117 return GST_FLOW_WRONG_STATE;
4121 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
4122 gst_flow_get_name (ret));
4123 GST_OBJECT_UNLOCK (pad);
4128 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4129 "pulling range, but it was not linked");
4130 GST_OBJECT_UNLOCK (pad);
4131 return GST_FLOW_NOT_LINKED;
4136 GST_OBJECT_UNLOCK (pad);
4137 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
4138 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
4139 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
4144 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
4145 "post probe returned %s", gst_flow_get_name (ret));
4146 GST_OBJECT_UNLOCK (pad);
4147 if (ret == GST_FLOW_OK)
4148 gst_buffer_unref (*buffer);
4154 GST_OBJECT_UNLOCK (pad);
4155 gst_buffer_unref (*buffer);
4157 GST_CAT_WARNING_OBJECT (GST_CAT_SCHEDULING, pad,
4158 "pullrange returned events that were not accepted");
4164 * gst_pad_push_event:
4165 * @pad: a #GstPad to push the event to.
4166 * @event: (transfer full): the #GstEvent to send to the pad.
4168 * Sends the event to the peer of the given pad. This function is
4169 * mainly used by elements to send events to their peer
4172 * This function takes owership of the provided event so you should
4173 * gst_event_ref() it if you want to reuse the event after this call.
4175 * Returns: TRUE if the event was handled.
4180 gst_pad_push_event (GstPad * pad, GstEvent * event)
4185 gboolean stored = FALSE;
4186 GstPadProbeType type;
4188 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4189 g_return_val_if_fail (event != NULL, FALSE);
4190 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
4192 if (GST_EVENT_IS_DOWNSTREAM (event))
4193 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4195 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4197 GST_OBJECT_LOCK (pad);
4199 peerpad = GST_PAD_PEER (pad);
4201 /* Two checks to be made:
4202 * . (un)set the FLUSHING flag for flushing events,
4203 * . handle pad blocking */
4204 switch (GST_EVENT_TYPE (event)) {
4205 case GST_EVENT_FLUSH_START:
4206 GST_PAD_SET_FLUSHING (pad);
4208 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4209 /* flush start will have set the FLUSHING flag and will then
4210 * unlock all threads doing a GCond wait on the blocking pad. This
4211 * will typically unblock the STREAMING thread blocked on a pad. */
4212 GST_LOG_OBJECT (pad, "Pad is blocked, not forwarding flush-start, "
4213 "doing block signal.");
4214 GST_PAD_BLOCK_BROADCAST (pad);
4218 case GST_EVENT_FLUSH_STOP:
4219 GST_PAD_UNSET_FLUSHING (pad);
4221 /* Remove sticky EOS events */
4222 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4223 clear_event (pad->priv->events,
4224 GST_EVENT_STICKY_IDX_TYPE (GST_EVENT_EOS));
4226 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4227 GST_LOG_OBJECT (pad, "Pad is blocked, not forwarding flush-stop");
4233 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4236 /* store the event on the pad, but only on srcpads */
4237 if (GST_PAD_IS_SRC (pad) && GST_EVENT_IS_STICKY (event)) {
4240 idx = GST_EVENT_STICKY_IDX (event);
4241 GST_LOG_OBJECT (pad, "storing sticky event %s at index %u",
4242 GST_EVENT_TYPE_NAME (event), idx);
4244 /* srcpad sticky events always become active immediately */
4245 gst_event_replace (&pad->priv->events[idx].event, event);
4250 /* backwards compatibility mode for caps */
4251 switch (GST_EVENT_TYPE (event)) {
4252 case GST_EVENT_CAPS:
4254 GST_OBJECT_UNLOCK (pad);
4256 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4258 GST_OBJECT_LOCK (pad);
4259 /* the peerpad might have changed. Things we checked above could not
4261 peerpad = GST_PAD_PEER (pad);
4264 case GST_EVENT_SEGMENT:
4268 offset = pad->offset;
4269 /* check if we need to adjust the segment */
4270 if (offset != 0 && (peerpad != NULL)) {
4273 /* copy segment values */
4274 gst_event_copy_segment (event, &segment);
4275 gst_event_unref (event);
4277 /* adjust and make a new event with the offset applied */
4278 segment.base += offset;
4279 event = gst_event_new_segment (&segment);
4283 case GST_EVENT_RECONFIGURE:
4284 if (GST_PAD_IS_SINK (pad))
4285 GST_OBJECT_FLAG_SET (pad, GST_PAD_NEED_RECONFIGURE);
4291 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4292 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4298 /* send probes after modifying the events above */
4299 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4301 /* now check the peer pad */
4302 if (peerpad == NULL)
4305 gst_object_ref (peerpad);
4307 GST_OBJECT_UNLOCK (pad);
4309 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4310 event, GST_EVENT_TYPE_NAME (event), peerpad);
4312 result = gst_pad_send_event (peerpad, event);
4314 /* Note: we gave away ownership of the event at this point but we can still
4315 * print the old pointer */
4316 GST_LOG_OBJECT (pad,
4317 "sent event %p to peerpad %" GST_PTR_FORMAT ", result %d", event, peerpad,
4320 gst_object_unref (peerpad);
4322 GST_OBJECT_LOCK (pad);
4324 if (pad->priv->using == 0) {
4325 /* pad is not active anymore, trigger idle callbacks */
4326 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4327 probe_stopped, GST_FLOW_OK);
4329 GST_OBJECT_UNLOCK (pad);
4331 return result | stored;
4333 /* ERROR handling */
4336 GST_DEBUG_OBJECT (pad, "We're flushing");
4337 GST_OBJECT_UNLOCK (pad);
4338 gst_event_unref (event);
4343 GST_DEBUG_OBJECT (pad, "Probe returned %s", gst_flow_get_name (ret));
4344 GST_OBJECT_UNLOCK (pad);
4345 gst_event_unref (event);
4350 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4351 GST_OBJECT_UNLOCK (pad);
4352 gst_event_unref (event);
4358 * gst_pad_send_event:
4359 * @pad: a #GstPad to send the event to.
4360 * @event: (transfer full): the #GstEvent to send to the pad.
4362 * Sends the event to the pad. This function can be used
4363 * by applications to send events in the pipeline.
4365 * If @pad is a source pad, @event should be an upstream event. If @pad is a
4366 * sink pad, @event should be a downstream event. For example, you would not
4367 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
4368 * Furthermore, some downstream events have to be serialized with data flow,
4369 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
4370 * the event needs to be serialized with data flow, this function will take the
4371 * pad's stream lock while calling its event function.
4373 * To find out whether an event type is upstream, downstream, or downstream and
4374 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
4375 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
4376 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
4377 * plugin doesn't need to bother itself with this information; the core handles
4378 * all necessary locks and checks.
4380 * This function takes owership of the provided event so you should
4381 * gst_event_ref() it if you want to reuse the event after this call.
4383 * Returns: TRUE if the event was handled.
4386 gst_pad_send_event (GstPad * pad, GstEvent * event)
4389 gboolean result = FALSE;
4390 gboolean serialized, need_unlock = FALSE, needs_events, sticky;
4391 GstPadProbeType type;
4393 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4394 g_return_val_if_fail (event != NULL, FALSE);
4396 GST_OBJECT_LOCK (pad);
4397 if (GST_PAD_IS_SINK (pad)) {
4398 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4399 goto wrong_direction;
4400 serialized = GST_EVENT_IS_SERIALIZED (event);
4401 sticky = GST_EVENT_IS_STICKY (event);
4402 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4403 } else if (GST_PAD_IS_SRC (pad)) {
4404 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4405 goto wrong_direction;
4406 /* events on srcpad never are serialized and sticky */
4407 serialized = sticky = FALSE;
4408 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4410 goto unknown_direction;
4412 /* get the flag first, we clear it when we have a FLUSH or a non-serialized
4414 needs_events = GST_PAD_NEEDS_EVENTS (pad);
4416 switch (GST_EVENT_TYPE (event)) {
4417 case GST_EVENT_FLUSH_START:
4418 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4419 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4421 /* can't even accept a flush begin event when flushing */
4422 if (GST_PAD_IS_FLUSHING (pad))
4425 GST_PAD_SET_FLUSHING (pad);
4426 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4427 needs_events = FALSE;
4429 case GST_EVENT_FLUSH_STOP:
4430 if (G_LIKELY (GST_PAD_ACTIVATE_MODE (pad) != GST_PAD_ACTIVATE_NONE)) {
4431 GST_PAD_UNSET_FLUSHING (pad);
4432 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4434 /* Remove pending EOS events */
4435 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4436 clear_event (pad->priv->events,
4437 GST_EVENT_STICKY_IDX_TYPE (GST_EVENT_EOS));
4439 GST_OBJECT_UNLOCK (pad);
4440 /* grab stream lock */
4441 GST_PAD_STREAM_LOCK (pad);
4443 GST_OBJECT_LOCK (pad);
4444 needs_events = FALSE;
4446 case GST_EVENT_RECONFIGURE:
4447 if (GST_PAD_IS_SRC (pad))
4448 GST_OBJECT_FLAG_SET (pad, GST_PAD_NEED_RECONFIGURE);
4450 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "have event type %s",
4451 GST_EVENT_TYPE_NAME (event));
4454 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4455 GST_OBJECT_UNLOCK (pad);
4456 GST_PAD_STREAM_LOCK (pad);
4458 GST_OBJECT_LOCK (pad);
4460 /* don't forward events on non-serialized events */
4461 needs_events = FALSE;
4464 /* store the event on the pad, but only on srcpads. We need to store the
4465 * event before checking the flushing flag. */
4470 switch (GST_EVENT_TYPE (event)) {
4471 case GST_EVENT_SEGMENT:
4472 if (pad->offset != 0) {
4475 /* copy segment values */
4476 gst_event_copy_segment (event, &segment);
4477 gst_event_unref (event);
4479 /* adjust and make a new event with the offset applied */
4480 segment.base += pad->offset;
4481 event = gst_event_new_segment (&segment);
4488 idx = GST_EVENT_STICKY_IDX (event);
4489 ev = &pad->priv->events[idx];
4491 if (ev->event != event) {
4492 GST_LOG_OBJECT (pad, "storing sticky event %s at index %u",
4493 GST_EVENT_TYPE_NAME (event), idx);
4494 gst_event_replace (&ev->pending, event);
4495 /* set the flag so that we update the events next time. We would
4496 * usually update below but we might be flushing too. */
4497 GST_OBJECT_FLAG_SET (pad, GST_PAD_NEED_EVENTS);
4498 needs_events = TRUE;
4501 /* now do the probe */
4502 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4506 type | GST_PAD_PROBE_TYPE_PUSH |
4507 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4509 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4514 if (G_UNLIKELY (needs_events)) {
4517 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_EVENTS);
4519 GST_DEBUG_OBJECT (pad, "need to update all events");
4520 ret = gst_pad_update_events (pad);
4521 if (ret != GST_FLOW_OK)
4523 GST_OBJECT_UNLOCK (pad);
4525 gst_event_unref (event);
4530 /* ensure to pass on event;
4531 * note that a sticky event has already been updated above */
4532 if (G_LIKELY (!needs_events || !sticky)) {
4533 GstPadEventFunction eventfunc;
4535 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4538 GST_OBJECT_UNLOCK (pad);
4540 result = eventfunc (pad, event);
4544 GST_PAD_STREAM_UNLOCK (pad);
4546 GST_DEBUG_OBJECT (pad, "sent event, result %d", result);
4550 /* ERROR handling */
4553 g_warning ("pad %s:%s sending %s event in wrong direction",
4554 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4555 GST_OBJECT_UNLOCK (pad);
4556 gst_event_unref (event);
4561 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4562 GST_OBJECT_UNLOCK (pad);
4563 gst_event_unref (event);
4568 g_warning ("pad %s:%s has no event handler, file a bug.",
4569 GST_DEBUG_PAD_NAME (pad));
4570 GST_OBJECT_UNLOCK (pad);
4572 GST_PAD_STREAM_UNLOCK (pad);
4573 gst_event_unref (event);
4578 GST_OBJECT_UNLOCK (pad);
4580 GST_PAD_STREAM_UNLOCK (pad);
4581 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
4582 "Received event on flushing pad. Discarding");
4583 gst_event_unref (event);
4588 GST_DEBUG_OBJECT (pad, "probe returned %s", gst_flow_get_name (ret));
4589 GST_OBJECT_UNLOCK (pad);
4591 GST_PAD_STREAM_UNLOCK (pad);
4592 gst_event_unref (event);
4597 GST_OBJECT_UNLOCK (pad);
4599 GST_PAD_STREAM_UNLOCK (pad);
4600 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad, "Update events failed");
4601 gst_event_unref (event);
4609 * gst_pad_set_element_private:
4610 * @pad: the #GstPad to set the private data of.
4611 * @priv: The private data to attach to the pad.
4613 * Set the given private data gpointer on the pad.
4614 * This function can only be used by the element that owns the pad.
4615 * No locking is performed in this function.
4618 gst_pad_set_element_private (GstPad * pad, gpointer priv)
4620 pad->element_private = priv;
4624 * gst_pad_get_element_private:
4625 * @pad: the #GstPad to get the private data of.
4627 * Gets the private data of a pad.
4628 * No locking is performed in this function.
4630 * Returns: (transfer none): a #gpointer to the private data.
4633 gst_pad_get_element_private (GstPad * pad)
4635 return pad->element_private;
4639 * gst_pad_get_sticky_event:
4640 * @pad: the #GstPad to get the event from.
4641 * @event_type: the #GstEventType that should be retrieved.
4643 * Returns a new reference of the sticky event of type @event_type
4646 * Returns: (transfer full): a #GstEvent of type @event_type. Unref after usage.
4649 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type)
4651 GstEvent *event = NULL;
4654 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4655 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
4657 idx = GST_EVENT_STICKY_IDX_TYPE (event_type);
4659 GST_OBJECT_LOCK (pad);
4660 if ((event = pad->priv->events[idx].event)) {
4661 gst_event_ref (event);
4663 GST_OBJECT_UNLOCK (pad);
4669 * gst_pad_sticky_events_foreach:
4670 * @pad: the #GstPad that should be used for iteration.
4671 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that should be called for every event.
4672 * @user_data: (closure): the optional user data.
4674 * Iterates all active sticky events on @pad and calls @foreach_func for every
4675 * event. If @foreach_func returns something else than GST_FLOW_OK the iteration
4676 * is immediately stopped.
4678 * Returns: GST_FLOW_OK if iteration was successful
4681 gst_pad_sticky_events_foreach (GstPad * pad,
4682 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
4684 GstFlowReturn ret = GST_FLOW_OK;
4688 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4689 g_return_val_if_fail (foreach_func != NULL, GST_FLOW_ERROR);
4691 GST_OBJECT_LOCK (pad);
4694 for (i = 0; i < GST_EVENT_MAX_STICKY; i++) {
4698 ev = &pad->priv->events[i];
4700 /* skip without active event */
4701 if ((event = ev->event) == NULL)
4704 gst_event_ref (event);
4705 GST_OBJECT_UNLOCK (pad);
4707 res = foreach_func (pad, event, user_data);
4709 GST_OBJECT_LOCK (pad);
4710 gst_event_unref (event);
4712 if (res != GST_FLOW_OK) {
4717 /* things could have changed while we release the lock, check if we still
4718 * are handling the same event, if we don't something changed and we have
4719 * to try again. FIXME. we need a cookie here. */
4720 if (event != ev->event) {
4721 GST_DEBUG_OBJECT (pad, "events changed, restarting");
4725 GST_OBJECT_UNLOCK (pad);
4731 do_stream_status (GstPad * pad, GstStreamStatusType type,
4732 GThread * thread, GstTask * task)
4736 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
4738 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
4739 if (GST_IS_ELEMENT (parent)) {
4740 GstMessage *message;
4741 GValue value = { 0 };
4743 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
4744 gchar *tname, *ename, *pname;
4746 /* create a good task name */
4747 ename = gst_element_get_name (parent);
4748 pname = gst_pad_get_name (pad);
4749 tname = g_strdup_printf ("%s:%s", ename, pname);
4753 gst_object_set_name (GST_OBJECT_CAST (task), tname);
4757 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
4760 g_value_init (&value, GST_TYPE_TASK);
4761 g_value_set_object (&value, task);
4762 gst_message_set_stream_status_object (message, &value);
4763 g_value_unset (&value);
4765 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
4766 gst_element_post_message (parent, message);
4768 gst_object_unref (parent);
4773 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
4775 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
4780 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
4782 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
4786 static GstTaskThreadCallbacks thr_callbacks = {
4792 * gst_pad_start_task:
4793 * @pad: the #GstPad to start the task of
4794 * @func: the task function to call
4795 * @data: data passed to the task function
4797 * Starts a task that repeatedly calls @func with @data. This function
4798 * is mostly used in pad activation functions to start the dataflow.
4799 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
4800 * before @func is called.
4802 * Returns: a %TRUE if the task could be started.
4805 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
4810 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4811 g_return_val_if_fail (func != NULL, FALSE);
4813 GST_DEBUG_OBJECT (pad, "start task");
4815 GST_OBJECT_LOCK (pad);
4816 task = GST_PAD_TASK (pad);
4818 task = gst_task_new (func, data);
4819 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
4820 gst_task_set_thread_callbacks (task, &thr_callbacks, pad, NULL);
4821 GST_DEBUG_OBJECT (pad, "created task");
4822 GST_PAD_TASK (pad) = task;
4823 gst_object_ref (task);
4824 /* release lock to post the message */
4825 GST_OBJECT_UNLOCK (pad);
4827 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
4829 gst_object_unref (task);
4831 GST_OBJECT_LOCK (pad);
4832 /* nobody else is supposed to have changed the pad now */
4833 if (GST_PAD_TASK (pad) != task)
4834 goto concurrent_stop;
4836 res = gst_task_set_state (task, GST_TASK_STARTED);
4837 GST_OBJECT_UNLOCK (pad);
4844 GST_OBJECT_UNLOCK (pad);
4850 * gst_pad_pause_task:
4851 * @pad: the #GstPad to pause the task of
4853 * Pause the task of @pad. This function will also wait until the
4854 * function executed by the task is finished if this function is not
4855 * called from the task function.
4857 * Returns: a TRUE if the task could be paused or FALSE when the pad
4861 gst_pad_pause_task (GstPad * pad)
4866 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4868 GST_DEBUG_OBJECT (pad, "pause task");
4870 GST_OBJECT_LOCK (pad);
4871 task = GST_PAD_TASK (pad);
4874 res = gst_task_set_state (task, GST_TASK_PAUSED);
4875 GST_OBJECT_UNLOCK (pad);
4877 /* wait for task function to finish, this lock is recursive so it does nothing
4878 * when the pause is called from the task itself */
4879 GST_PAD_STREAM_LOCK (pad);
4880 GST_PAD_STREAM_UNLOCK (pad);
4886 GST_DEBUG_OBJECT (pad, "pad has no task");
4887 GST_OBJECT_UNLOCK (pad);
4893 * gst_pad_stop_task:
4894 * @pad: the #GstPad to stop the task of
4896 * Stop the task of @pad. This function will also make sure that the
4897 * function executed by the task will effectively stop if not called
4898 * from the GstTaskFunction.
4900 * This function will deadlock if called from the GstTaskFunction of
4901 * the task. Use gst_task_pause() instead.
4903 * Regardless of whether the pad has a task, the stream lock is acquired and
4904 * released so as to ensure that streaming through this pad has finished.
4906 * Returns: a TRUE if the task could be stopped or FALSE on error.
4909 gst_pad_stop_task (GstPad * pad)
4914 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4916 GST_DEBUG_OBJECT (pad, "stop task");
4918 GST_OBJECT_LOCK (pad);
4919 task = GST_PAD_TASK (pad);
4922 GST_PAD_TASK (pad) = NULL;
4923 res = gst_task_set_state (task, GST_TASK_STOPPED);
4924 GST_OBJECT_UNLOCK (pad);
4926 GST_PAD_STREAM_LOCK (pad);
4927 GST_PAD_STREAM_UNLOCK (pad);
4929 if (!gst_task_join (task))
4932 gst_object_unref (task);
4938 GST_DEBUG_OBJECT (pad, "no task");
4939 GST_OBJECT_UNLOCK (pad);
4941 GST_PAD_STREAM_LOCK (pad);
4942 GST_PAD_STREAM_UNLOCK (pad);
4944 /* this is not an error */
4949 /* this is bad, possibly the application tried to join the task from
4950 * the task's thread. We install the task again so that it will be stopped
4951 * again from the right thread next time hopefully. */
4952 GST_OBJECT_LOCK (pad);
4953 GST_DEBUG_OBJECT (pad, "join failed");
4954 /* we can only install this task if there was no other task */
4955 if (GST_PAD_TASK (pad) == NULL)
4956 GST_PAD_TASK (pad) = task;
4957 GST_OBJECT_UNLOCK (pad);