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_query_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 void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
143 static gboolean gst_pad_activate_default (GstPad * pad);
144 static GstFlowReturn gst_pad_chain_list_default (GstPad * pad,
145 GstBufferList * list);
147 static guint gst_pad_signals[LAST_SIGNAL] = { 0 };
149 static GParamSpec *pspec_caps = NULL;
151 /* quarks for probe signals */
152 static GQuark buffer_quark;
153 static GQuark buffer_list_quark;
154 static GQuark event_quark;
163 static GstFlowQuarks flow_quarks[] = {
164 {GST_FLOW_CUSTOM_SUCCESS, "custom-success", 0},
165 {GST_FLOW_RESEND, "resend", 0},
166 {GST_FLOW_OK, "ok", 0},
167 {GST_FLOW_NOT_LINKED, "not-linked", 0},
168 {GST_FLOW_WRONG_STATE, "wrong-state", 0},
169 {GST_FLOW_EOS, "eos", 0},
170 {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0},
171 {GST_FLOW_ERROR, "error", 0},
172 {GST_FLOW_NOT_SUPPORTED, "not-supported", 0},
173 {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}
178 * @ret: a #GstFlowReturn to get the name of.
180 * Gets a string representing the given flow return.
182 * Returns: a static string with the name of the flow return.
185 gst_flow_get_name (GstFlowReturn ret)
189 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
191 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
192 if (ret == flow_quarks[i].ret)
193 return flow_quarks[i].name;
200 * @ret: a #GstFlowReturn to get the quark of.
202 * Get the unique quark for the given GstFlowReturn.
204 * Returns: the quark associated with the flow return or 0 if an
205 * invalid return was specified.
208 gst_flow_to_quark (GstFlowReturn ret)
212 ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS);
214 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) {
215 if (ret == flow_quarks[i].ret)
216 return flow_quarks[i].quark;
225 buffer_quark = g_quark_from_static_string ("buffer"); \
226 buffer_list_quark = g_quark_from_static_string ("bufferlist"); \
227 event_quark = g_quark_from_static_string ("event"); \
229 for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \
230 flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \
233 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \
234 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \
237 #define gst_pad_parent_class parent_class
238 G_DEFINE_TYPE_WITH_CODE (GstPad, gst_pad, GST_TYPE_OBJECT, _do_init);
241 gst_pad_class_init (GstPadClass * klass)
243 GObjectClass *gobject_class;
244 GstObjectClass *gstobject_class;
246 gobject_class = G_OBJECT_CLASS (klass);
247 gstobject_class = GST_OBJECT_CLASS (klass);
249 g_type_class_add_private (klass, sizeof (GstPadPrivate));
251 gobject_class->dispose = gst_pad_dispose;
252 gobject_class->finalize = gst_pad_finalize;
253 gobject_class->set_property = gst_pad_set_property;
254 gobject_class->get_property = gst_pad_get_property;
258 * @pad: the pad that emitted the signal
259 * @peer: the peer pad that has been connected
261 * Signals that a pad has been linked to the peer pad.
263 gst_pad_signals[PAD_LINKED] =
264 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
265 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
266 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
269 * @pad: the pad that emitted the signal
270 * @peer: the peer pad that has been disconnected
272 * Signals that a pad has been unlinked from the peer pad.
274 gst_pad_signals[PAD_UNLINKED] =
275 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
276 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
277 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
279 pspec_caps = g_param_spec_boxed ("caps", "Caps",
280 "The capabilities of the pad", GST_TYPE_CAPS,
281 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
282 g_object_class_install_property (gobject_class, PAD_PROP_CAPS, pspec_caps);
284 g_object_class_install_property (gobject_class, PAD_PROP_DIRECTION,
285 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
286 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
287 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
289 /* FIXME, Make G_PARAM_CONSTRUCT_ONLY when we fix ghostpads. */
290 g_object_class_install_property (gobject_class, PAD_PROP_TEMPLATE,
291 g_param_spec_object ("template", "Template",
292 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
293 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
295 gstobject_class->path_string_separator = ".";
297 /* Register common function pointer descriptions */
298 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_activate_default);
299 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_event_default);
300 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_query_default);
301 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
302 GST_DEBUG_REGISTER_FUNCPTR (gst_pad_chain_list_default);
306 gst_pad_init (GstPad * pad)
308 pad->priv = GST_PAD_GET_PRIVATE (pad);
310 GST_PAD_DIRECTION (pad) = GST_PAD_UNKNOWN;
312 GST_PAD_ACTIVATEFUNC (pad) = gst_pad_activate_default;
313 GST_PAD_EVENTFUNC (pad) = gst_pad_event_default;
314 GST_PAD_QUERYFUNC (pad) = gst_pad_query_default;
315 GST_PAD_ITERINTLINKFUNC (pad) = gst_pad_iterate_internal_links_default;
316 GST_PAD_CHAINLISTFUNC (pad) = gst_pad_chain_list_default;
318 GST_PAD_SET_FLUSHING (pad);
320 g_static_rec_mutex_init (&pad->stream_rec_lock);
322 pad->block_cond = g_cond_new ();
324 g_hook_list_init (&pad->probes, sizeof (GstProbe));
328 clear_event (PadEvent events[], guint idx)
330 gst_event_replace (&events[idx].event, NULL);
331 gst_event_replace (&events[idx].pending, NULL);
334 /* called when setting the pad inactive. It removes all sticky events from
337 clear_events (PadEvent events[])
341 for (i = 0; i < GST_EVENT_MAX_STICKY; i++)
342 clear_event (events, i);
345 /* The sticky event with @idx from the srcpad is copied to the
346 * pending event on the sinkpad (when different).
347 * This function applies the pad offsets in case of segment events.
348 * This will make sure that we send the event to the sinkpad event
349 * function when the next buffer of event arrives.
350 * Should be called with the OBJECT lock of both pads.
351 * This function returns TRUE when there is a pending event on the
354 replace_event (GstPad * srcpad, GstPad * sinkpad, guint idx)
356 PadEvent *srcev, *sinkev;
358 gboolean pending = FALSE;
360 srcev = &srcpad->priv->events[idx];
362 if ((event = srcev->event)) {
363 sinkev = &sinkpad->priv->events[idx];
365 switch (GST_EVENT_TYPE (event)) {
366 case GST_EVENT_SEGMENT:
371 offset = srcpad->offset + sinkpad->offset;
373 gst_event_copy_segment (event, &segment);
374 /* adjust the base time. FIXME, check negative times, try to tweak the
375 * start to do clipping on negative times */
376 segment.base += offset;
377 /* make a new event from the updated segment */
378 event = gst_event_new_segment (&segment);
385 if (sinkev->event != event) {
386 /* put in the pending entry when different */
387 GST_CAT_DEBUG_OBJECT (GST_CAT_SCHEDULING, srcpad,
388 "Putting event %p (%s) on pad %s:%s", event,
389 GST_EVENT_TYPE_NAME (event), GST_DEBUG_PAD_NAME (sinkpad));
390 gst_event_replace (&sinkev->pending, event);
399 prepare_event_update (GstPad * srcpad, GstPad * sinkpad)
404 /* make sure we push the events from the source to this new peer, for this we
405 * copy the events on the sinkpad and mark EVENTS_PENDING */
407 for (i = 0; i < GST_EVENT_MAX_STICKY; i++)
408 pending |= replace_event (srcpad, sinkpad, i);
410 /* we had some new pending events, set our flag */
412 GST_OBJECT_FLAG_SET (sinkpad, GST_PAD_NEED_EVENTS);
415 /* should be called with the OBJECT_LOCK */
417 get_pad_caps (GstPad * pad)
419 GstCaps *caps = NULL;
423 idx = GST_EVENT_STICKY_IDX_TYPE (GST_EVENT_CAPS);
424 /* we can only use the caps when we have successfully send the caps
425 * event to the event function and is thus in the active entry */
426 if ((event = pad->priv->events[idx].event))
427 gst_event_parse_caps (event, &caps);
433 gst_pad_dispose (GObject * object)
435 GstPad *pad = GST_PAD_CAST (object);
438 GST_CAT_DEBUG_OBJECT (GST_CAT_REFCOUNTING, pad, "dispose");
440 /* unlink the peer pad */
441 if ((peer = gst_pad_get_peer (pad))) {
442 /* window for MT unsafeness, someone else could unlink here
443 * and then we call unlink with wrong pads. The unlink
444 * function would catch this and safely return failed. */
445 if (GST_PAD_IS_SRC (pad))
446 gst_pad_unlink (pad, peer);
448 gst_pad_unlink (peer, pad);
450 gst_object_unref (peer);
453 gst_pad_set_pad_template (pad, NULL);
455 clear_events (pad->priv->events);
457 g_hook_list_clear (&pad->probes);
459 G_OBJECT_CLASS (parent_class)->dispose (object);
463 gst_pad_finalize (GObject * object)
465 GstPad *pad = GST_PAD_CAST (object);
468 /* in case the task is still around, clean it up */
469 if ((task = GST_PAD_TASK (pad))) {
470 gst_task_join (task);
471 GST_PAD_TASK (pad) = NULL;
472 gst_object_unref (task);
475 g_static_rec_mutex_free (&pad->stream_rec_lock);
476 g_cond_free (pad->block_cond);
478 G_OBJECT_CLASS (parent_class)->finalize (object);
482 gst_pad_set_property (GObject * object, guint prop_id,
483 const GValue * value, GParamSpec * pspec)
485 g_return_if_fail (GST_IS_PAD (object));
488 case PAD_PROP_DIRECTION:
489 GST_PAD_DIRECTION (object) = (GstPadDirection) g_value_get_enum (value);
491 case PAD_PROP_TEMPLATE:
492 gst_pad_set_pad_template (GST_PAD_CAST (object),
493 (GstPadTemplate *) g_value_get_object (value));
496 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
502 gst_pad_get_property (GObject * object, guint prop_id,
503 GValue * value, GParamSpec * pspec)
505 g_return_if_fail (GST_IS_PAD (object));
509 GST_OBJECT_LOCK (object);
510 g_value_set_boxed (value, get_pad_caps (GST_PAD_CAST (object)));
511 GST_OBJECT_UNLOCK (object);
513 case PAD_PROP_DIRECTION:
514 g_value_set_enum (value, GST_PAD_DIRECTION (object));
516 case PAD_PROP_TEMPLATE:
517 g_value_set_object (value, GST_PAD_PAD_TEMPLATE (object));
520 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
527 * @name: the name of the new pad.
528 * @direction: the #GstPadDirection of the pad.
530 * Creates a new pad with the given name in the given direction.
531 * If name is NULL, a guaranteed unique name (across all pads)
533 * This function makes a copy of the name so you can safely free the name.
535 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
540 gst_pad_new (const gchar * name, GstPadDirection direction)
542 return g_object_new (GST_TYPE_PAD,
543 "name", name, "direction", direction, NULL);
547 * gst_pad_new_from_template:
548 * @templ: the pad template to use
549 * @name: the name of the element
551 * Creates a new pad with the given name from the given template.
552 * If name is NULL, a guaranteed unique name (across all pads)
554 * This function makes a copy of the name so you can safely free the name.
556 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
559 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
561 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
563 return g_object_new (GST_TYPE_PAD,
564 "name", name, "direction", templ->direction, "template", templ, NULL);
568 * gst_pad_new_from_static_template:
569 * @templ: the #GstStaticPadTemplate to use
570 * @name: the name of the element
572 * Creates a new pad with the given name from the given static template.
573 * If name is NULL, a guaranteed unique name (across all pads)
575 * This function makes a copy of the name so you can safely free the name.
577 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
580 gst_pad_new_from_static_template (GstStaticPadTemplate * templ,
584 GstPadTemplate *template;
586 template = gst_static_pad_template_get (templ);
587 pad = gst_pad_new_from_template (template, name);
588 gst_object_unref (template);
593 * gst_pad_get_direction:
594 * @pad: a #GstPad to get the direction of.
596 * Gets the direction of the pad. The direction of the pad is
597 * decided at construction time so this function does not take
600 * Returns: the #GstPadDirection of the pad.
605 gst_pad_get_direction (GstPad * pad)
607 GstPadDirection result;
609 /* PAD_UNKNOWN is a little silly but we need some sort of
610 * error return value */
611 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
613 result = GST_PAD_DIRECTION (pad);
619 gst_pad_activate_default (GstPad * pad)
621 return gst_pad_activate_push (pad, TRUE);
625 pre_activate (GstPad * pad, GstPadActivateMode new_mode)
628 case GST_PAD_ACTIVATE_PUSH:
629 case GST_PAD_ACTIVATE_PULL:
630 GST_OBJECT_LOCK (pad);
631 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE %d, unset flushing",
633 GST_PAD_UNSET_FLUSHING (pad);
634 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
635 GST_OBJECT_UNLOCK (pad);
637 case GST_PAD_ACTIVATE_NONE:
638 GST_OBJECT_LOCK (pad);
639 GST_DEBUG_OBJECT (pad, "setting ACTIVATE_MODE NONE, set flushing");
640 GST_PAD_SET_FLUSHING (pad);
641 GST_PAD_ACTIVATE_MODE (pad) = new_mode;
642 /* unlock blocked pads so element can resume and stop */
643 GST_PAD_BLOCK_BROADCAST (pad);
644 GST_OBJECT_UNLOCK (pad);
650 post_activate (GstPad * pad, GstPadActivateMode new_mode)
653 case GST_PAD_ACTIVATE_PUSH:
654 case GST_PAD_ACTIVATE_PULL:
657 case GST_PAD_ACTIVATE_NONE:
658 /* ensures that streaming stops */
659 GST_PAD_STREAM_LOCK (pad);
660 GST_DEBUG_OBJECT (pad, "stopped streaming");
661 GST_OBJECT_LOCK (pad);
662 clear_events (pad->priv->events);
663 GST_OBJECT_UNLOCK (pad);
664 GST_PAD_STREAM_UNLOCK (pad);
670 * gst_pad_set_active:
671 * @pad: the #GstPad to activate or deactivate.
672 * @active: whether or not the pad should be active.
674 * Activates or deactivates the given pad.
675 * Normally called from within core state change functions.
677 * If @active, makes sure the pad is active. If it is already active, either in
678 * push or pull mode, just return. Otherwise dispatches to the pad's activate
679 * function to perform the actual activation.
681 * If not @active, checks the pad's current mode and calls
682 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
685 * Returns: #TRUE if the operation was successful.
690 gst_pad_set_active (GstPad * pad, gboolean active)
692 GstPadActivateMode old;
693 gboolean ret = FALSE;
695 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
697 GST_OBJECT_LOCK (pad);
698 old = GST_PAD_ACTIVATE_MODE (pad);
699 GST_OBJECT_UNLOCK (pad);
703 case GST_PAD_ACTIVATE_PUSH:
704 GST_DEBUG_OBJECT (pad, "activating pad from push");
707 case GST_PAD_ACTIVATE_PULL:
708 GST_DEBUG_OBJECT (pad, "activating pad from pull");
711 case GST_PAD_ACTIVATE_NONE:
712 GST_DEBUG_OBJECT (pad, "activating pad from none");
713 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad);
716 GST_DEBUG_OBJECT (pad, "unknown activation mode!");
721 case GST_PAD_ACTIVATE_PUSH:
722 GST_DEBUG_OBJECT (pad, "deactivating pad from push");
723 ret = gst_pad_activate_push (pad, FALSE);
725 case GST_PAD_ACTIVATE_PULL:
726 GST_DEBUG_OBJECT (pad, "deactivating pad from pull");
727 ret = gst_pad_activate_pull (pad, FALSE);
729 case GST_PAD_ACTIVATE_NONE:
730 GST_DEBUG_OBJECT (pad, "deactivating pad from none");
734 GST_DEBUG_OBJECT (pad, "unknown activation mode!");
740 GST_OBJECT_LOCK (pad);
742 g_critical ("Failed to deactivate pad %s:%s, very bad",
743 GST_DEBUG_PAD_NAME (pad));
745 GST_WARNING_OBJECT (pad, "Failed to activate pad");
747 GST_OBJECT_UNLOCK (pad);
750 GST_OBJECT_LOCK (pad);
751 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_RECONFIGURE);
752 GST_OBJECT_UNLOCK (pad);
760 * gst_pad_activate_pull:
761 * @pad: the #GstPad to activate or deactivate.
762 * @active: whether or not the pad should be active.
764 * Activates or deactivates the given pad in pull mode via dispatching to the
765 * pad's activatepullfunc. For use from within pad activation functions only.
766 * When called on sink pads, will first proxy the call to the peer pad, which
767 * is expected to activate its internally linked pads from within its
768 * activate_pull function.
770 * If you don't know what this is, you probably don't want to call it.
772 * Returns: TRUE if the operation was successful.
777 gst_pad_activate_pull (GstPad * pad, gboolean active)
779 GstPadActivateMode old, new;
782 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
784 GST_OBJECT_LOCK (pad);
785 old = GST_PAD_ACTIVATE_MODE (pad);
786 GST_OBJECT_UNLOCK (pad);
790 case GST_PAD_ACTIVATE_PULL:
791 GST_DEBUG_OBJECT (pad, "activating pad from pull, was ok");
793 case GST_PAD_ACTIVATE_PUSH:
794 GST_DEBUG_OBJECT (pad,
795 "activating pad from push, deactivate push first");
796 /* pad was activate in the wrong direction, deactivate it
797 * and reactivate it in pull mode */
798 if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
799 goto deactivate_failed;
800 /* fallthrough, pad is deactivated now. */
801 case GST_PAD_ACTIVATE_NONE:
802 GST_DEBUG_OBJECT (pad, "activating pad from none");
807 case GST_PAD_ACTIVATE_NONE:
808 GST_DEBUG_OBJECT (pad, "deactivating pad from none, was ok");
810 case GST_PAD_ACTIVATE_PUSH:
811 GST_DEBUG_OBJECT (pad, "deactivating pad from push, weird");
812 /* pad was activated in the other direction, deactivate it
813 * in push mode, this should not happen... */
814 if (G_UNLIKELY (!gst_pad_activate_push (pad, FALSE)))
815 goto deactivate_failed;
816 /* everything is fine now */
818 case GST_PAD_ACTIVATE_PULL:
819 GST_DEBUG_OBJECT (pad, "deactivating pad from pull");
824 if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
825 if ((peer = gst_pad_get_peer (pad))) {
826 GST_DEBUG_OBJECT (pad, "calling peer");
827 if (G_UNLIKELY (!gst_pad_activate_pull (peer, active)))
829 gst_object_unref (peer);
831 /* there is no peer, this is only fatal when we activate. When we
832 * deactivate, we must assume the application has unlinked the peer and
833 * will deactivate it eventually. */
837 GST_DEBUG_OBJECT (pad, "deactivating unlinked pad");
840 if (G_UNLIKELY (GST_PAD_GETRANGEFUNC (pad) == NULL))
841 goto failure; /* Can't activate pull on a src without a
845 new = active ? GST_PAD_ACTIVATE_PULL : GST_PAD_ACTIVATE_NONE;
846 pre_activate (pad, new);
848 if (GST_PAD_ACTIVATEPULLFUNC (pad)) {
849 if (G_UNLIKELY (!GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active)))
852 /* can happen for sinks of passthrough elements */
855 post_activate (pad, new);
857 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode",
858 active ? "activated" : "deactivated");
864 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in pull mode",
865 active ? "activated" : "deactivated");
870 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
871 "failed to %s in switch to pull from mode %d",
872 (active ? "activate" : "deactivate"), old);
877 GST_OBJECT_LOCK (peer);
878 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
879 "activate_pull on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
880 GST_OBJECT_UNLOCK (peer);
881 gst_object_unref (peer);
886 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "can't activate unlinked sink "
892 GST_OBJECT_LOCK (pad);
893 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in pull mode",
894 active ? "activate" : "deactivate");
895 GST_PAD_SET_FLUSHING (pad);
896 GST_PAD_ACTIVATE_MODE (pad) = old;
897 GST_OBJECT_UNLOCK (pad);
903 * gst_pad_activate_push:
904 * @pad: the #GstPad to activate or deactivate.
905 * @active: whether the pad should be active or not.
907 * Activates or deactivates the given pad in push mode via dispatching to the
908 * pad's activatepushfunc. For use from within pad activation functions only.
910 * If you don't know what this is, you probably don't want to call it.
912 * Returns: %TRUE if the operation was successful.
917 gst_pad_activate_push (GstPad * pad, gboolean active)
919 GstPadActivateMode old, new;
921 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
922 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "trying to set %s in push mode",
923 active ? "activated" : "deactivated");
925 GST_OBJECT_LOCK (pad);
926 old = GST_PAD_ACTIVATE_MODE (pad);
927 GST_OBJECT_UNLOCK (pad);
931 case GST_PAD_ACTIVATE_PUSH:
932 GST_DEBUG_OBJECT (pad, "activating pad from push, was ok");
934 case GST_PAD_ACTIVATE_PULL:
935 GST_DEBUG_OBJECT (pad,
936 "activating pad from push, deactivating pull first");
937 /* pad was activate in the wrong direction, deactivate it
938 * an reactivate it in push mode */
939 if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
940 goto deactivate_failed;
941 /* fallthrough, pad is deactivated now. */
942 case GST_PAD_ACTIVATE_NONE:
943 GST_DEBUG_OBJECT (pad, "activating pad from none");
948 case GST_PAD_ACTIVATE_NONE:
949 GST_DEBUG_OBJECT (pad, "deactivating pad from none, was ok");
951 case GST_PAD_ACTIVATE_PULL:
952 GST_DEBUG_OBJECT (pad, "deactivating pad from pull, weird");
953 /* pad was activated in the other direction, deactivate it
954 * in pull mode, this should not happen... */
955 if (G_UNLIKELY (!gst_pad_activate_pull (pad, FALSE)))
956 goto deactivate_failed;
957 /* everything is fine now */
959 case GST_PAD_ACTIVATE_PUSH:
960 GST_DEBUG_OBJECT (pad, "deactivating pad from push");
965 new = active ? GST_PAD_ACTIVATE_PUSH : GST_PAD_ACTIVATE_NONE;
966 pre_activate (pad, new);
968 if (GST_PAD_ACTIVATEPUSHFUNC (pad)) {
969 if (G_UNLIKELY (!GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active))) {
973 /* quite ok, element relies on state change func to prepare itself */
976 post_activate (pad, new);
978 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in push mode",
979 active ? "activated" : "deactivated");
984 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in push mode",
985 active ? "activated" : "deactivated");
990 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
991 "failed to %s in switch to push from mode %d",
992 (active ? "activate" : "deactivate"), old);
997 GST_OBJECT_LOCK (pad);
998 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode",
999 active ? "activate" : "deactivate");
1000 GST_PAD_SET_FLUSHING (pad);
1001 GST_PAD_ACTIVATE_MODE (pad) = old;
1002 GST_OBJECT_UNLOCK (pad);
1008 * gst_pad_is_active:
1009 * @pad: the #GstPad to query
1011 * Query if a pad is active
1013 * Returns: TRUE if the pad is active.
1018 gst_pad_is_active (GstPad * pad)
1020 gboolean result = FALSE;
1022 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1024 GST_OBJECT_LOCK (pad);
1025 result = GST_PAD_IS_ACTIVE (pad);
1026 GST_OBJECT_UNLOCK (pad);
1032 * gst_pad_add_probe:
1033 * @pad: the #GstPad to add the probe to
1034 * @mask: the probe mask
1035 * @callback: #GstPadProbeCallback that will be called with notifications of
1037 * @user_data: (closure): user data passed to the callback
1038 * @destroy_data: #GDestroyNotify for user_data
1040 * Be notified of different states of pads. The provided callback is called for
1041 * every state that matches @mask.
1043 * Returns: an id or 0 on error. The id can be used to remove the probe with
1044 * gst_pad_remove_probe().
1049 gst_pad_add_probe (GstPad * pad, GstPadProbeType mask,
1050 GstPadProbeCallback callback, gpointer user_data,
1051 GDestroyNotify destroy_data)
1056 g_return_val_if_fail (GST_IS_PAD (pad), 0);
1057 g_return_val_if_fail (mask != 0, 0);
1059 GST_OBJECT_LOCK (pad);
1061 /* make a new probe */
1062 hook = g_hook_alloc (&pad->probes);
1064 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "adding probe for mask 0x%08x",
1067 /* when no contraints are given for the types, assume all types are
1069 if ((mask & GST_PAD_PROBE_TYPE_ALL_BOTH) == 0)
1070 mask |= GST_PAD_PROBE_TYPE_ALL_BOTH;
1071 if ((mask & GST_PAD_PROBE_TYPE_SCHEDULING) == 0)
1072 mask |= GST_PAD_PROBE_TYPE_SCHEDULING;
1074 /* store our flags and other fields */
1075 hook->flags |= (mask << G_HOOK_FLAG_USER_SHIFT);
1076 hook->func = callback;
1077 hook->data = user_data;
1078 hook->destroy = destroy_data;
1079 PROBE_COOKIE (hook) = (pad->priv->probe_cookie - 1);
1082 g_hook_prepend (&pad->probes, hook);
1084 /* incremenent cookie so that the new hook get's called */
1085 pad->priv->probe_list_cookie++;
1087 /* get the id of the hook, we return this and it can be used to remove the
1089 res = hook->hook_id;
1091 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got probe id %lu", res);
1093 if (mask & GST_PAD_PROBE_TYPE_BLOCKING) {
1094 /* we have a block probe */
1096 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKED);
1097 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "added blocking probe, "
1098 "now %d blocking probes", pad->num_blocked);
1101 /* call the callback if we need to be called for idle callbacks */
1102 if ((mask & GST_PAD_PROBE_TYPE_IDLE) && (callback != NULL)) {
1103 if (pad->priv->using > 0) {
1104 /* the pad is in use, we can't signal the idle callback yet. Since we set the
1105 * flag above, the last thread to leave the push will do the callback. New
1106 * threads going into the push will block. */
1107 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1108 "pad is in use, delay idle callback");
1109 GST_OBJECT_UNLOCK (pad);
1111 GstPadProbeInfo info = { GST_PAD_PROBE_TYPE_IDLE, };
1113 /* the pad is idle now, we can signal the idle callback now */
1114 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
1115 "pad is idle, trigger idle callback");
1116 GST_OBJECT_UNLOCK (pad);
1118 callback (pad, &info, user_data);
1121 GST_OBJECT_UNLOCK (pad);
1127 cleanup_hook (GstPad * pad, GHook * hook)
1129 GstPadProbeType type;
1131 type = (hook->flags) >> G_HOOK_FLAG_USER_SHIFT;
1133 if (type & GST_PAD_PROBE_TYPE_BLOCKING) {
1134 /* unblock when we remove the last blocking probe */
1136 GST_DEBUG_OBJECT (pad, "remove blocking probe, now %d left",
1138 if (pad->num_blocked == 0) {
1139 GST_DEBUG_OBJECT (pad, "last blocking probe removed, unblocking");
1140 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKED);
1141 GST_PAD_BLOCK_BROADCAST (pad);
1144 g_hook_destroy_link (&pad->probes, hook);
1149 * gst_pad_remove_probe:
1150 * @pad: the #GstPad with the probe
1151 * @id: the probe id to remove
1153 * Remove the probe with @id from @pad.
1158 gst_pad_remove_probe (GstPad * pad, gulong id)
1162 g_return_if_fail (GST_IS_PAD (pad));
1164 GST_OBJECT_LOCK (pad);
1166 hook = g_hook_get (&pad->probes, id);
1170 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "removing hook %ld",
1172 cleanup_hook (pad, hook);
1173 GST_OBJECT_UNLOCK (pad);
1179 GST_OBJECT_UNLOCK (pad);
1180 g_warning ("%s: pad `%p' has no probe with id `%lu'", G_STRLOC, pad, id);
1186 * gst_pad_is_blocked:
1187 * @pad: the #GstPad to query
1189 * Checks if the pad is blocked or not. This function returns the
1190 * last requested state of the pad. It is not certain that the pad
1191 * is actually blocking at this point (see gst_pad_is_blocking()).
1193 * Returns: TRUE if the pad is blocked.
1198 gst_pad_is_blocked (GstPad * pad)
1200 gboolean result = FALSE;
1202 g_return_val_if_fail (GST_IS_PAD (pad), result);
1204 GST_OBJECT_LOCK (pad);
1205 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED);
1206 GST_OBJECT_UNLOCK (pad);
1212 * gst_pad_is_blocking:
1213 * @pad: the #GstPad to query
1215 * Checks if the pad is blocking or not. This is a guaranteed state
1216 * of whether the pad is actually blocking on a #GstBuffer or a #GstEvent.
1218 * Returns: TRUE if the pad is blocking.
1225 gst_pad_is_blocking (GstPad * pad)
1227 gboolean result = FALSE;
1229 g_return_val_if_fail (GST_IS_PAD (pad), result);
1231 GST_OBJECT_LOCK (pad);
1232 /* the blocking flag is only valid if the pad is not flushing */
1233 result = GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKING) &&
1234 !GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLUSHING);
1235 GST_OBJECT_UNLOCK (pad);
1241 * gst_pad_check_reconfigure:
1242 * @pad: the #GstPad to check
1244 * Check and clear the #GST_PAD_NEED_RECONFIGURE flag on @pad and return %TRUE
1245 * if the flag was set.
1247 * Returns: %TRUE is the GST_PAD_NEED_RECONFIGURE flag was set on @pad.
1250 gst_pad_check_reconfigure (GstPad * pad)
1252 gboolean reconfigure;
1254 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1256 GST_OBJECT_LOCK (pad);
1257 reconfigure = GST_PAD_NEEDS_RECONFIGURE (pad);
1258 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_RECONFIGURE);
1259 GST_OBJECT_UNLOCK (pad);
1265 * gst_pad_mark_reconfigure:
1266 * @pad: the #GstPad to mark
1268 * Mark a pad for needing reconfiguration. The next call to
1269 * gst_pad_check_reconfigure() will return %TRUE after this call.
1272 gst_pad_mark_reconfigure (GstPad * pad)
1274 g_return_if_fail (GST_IS_PAD (pad));
1276 GST_OBJECT_LOCK (pad);
1277 GST_OBJECT_FLAG_SET (pad, GST_PAD_NEED_RECONFIGURE);
1278 GST_OBJECT_UNLOCK (pad);
1282 * gst_pad_set_activate_function:
1284 * @activate: the #GstPadActivateFunction to set.
1286 * Sets the given activate function for @pad. The activate function will
1287 * dispatch to gst_pad_activate_push() or gst_pad_activate_pull() to perform
1288 * the actual activation. Only makes sense to set on sink pads.
1290 * Call this function if your sink pad can start a pull-based task.
1293 gst_pad_set_activate_function (GstPad * pad, GstPadActivateFunction activate)
1295 g_return_if_fail (GST_IS_PAD (pad));
1297 GST_PAD_ACTIVATEFUNC (pad) = activate;
1298 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatefunc set to %s",
1299 GST_DEBUG_FUNCPTR_NAME (activate));
1303 * gst_pad_set_activatepull_function:
1305 * @activatepull: the #GstPadActivateModeFunction to set.
1307 * Sets the given activate_pull function for the pad. An activate_pull function
1308 * prepares the element and any upstream connections for pulling. See XXX
1309 * part-activation.txt for details.
1312 gst_pad_set_activatepull_function (GstPad * pad,
1313 GstPadActivateModeFunction activatepull)
1315 g_return_if_fail (GST_IS_PAD (pad));
1317 GST_PAD_ACTIVATEPULLFUNC (pad) = activatepull;
1318 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatepullfunc set to %s",
1319 GST_DEBUG_FUNCPTR_NAME (activatepull));
1323 * gst_pad_set_activatepush_function:
1325 * @activatepush: the #GstPadActivateModeFunction to set.
1327 * Sets the given activate_push function for the pad. An activate_push function
1328 * prepares the element for pushing. See XXX part-activation.txt for details.
1331 gst_pad_set_activatepush_function (GstPad * pad,
1332 GstPadActivateModeFunction activatepush)
1334 g_return_if_fail (GST_IS_PAD (pad));
1336 GST_PAD_ACTIVATEPUSHFUNC (pad) = activatepush;
1337 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "activatepushfunc set to %s",
1338 GST_DEBUG_FUNCPTR_NAME (activatepush));
1342 * gst_pad_set_chain_function:
1343 * @pad: a sink #GstPad.
1344 * @chain: the #GstPadChainFunction to set.
1346 * Sets the given chain function for the pad. The chain function is called to
1347 * process a #GstBuffer input buffer. see #GstPadChainFunction for more details.
1350 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
1352 g_return_if_fail (GST_IS_PAD (pad));
1353 g_return_if_fail (GST_PAD_IS_SINK (pad));
1355 GST_PAD_CHAINFUNC (pad) = chain;
1356 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainfunc set to %s",
1357 GST_DEBUG_FUNCPTR_NAME (chain));
1361 * gst_pad_set_chain_list_function:
1362 * @pad: a sink #GstPad.
1363 * @chainlist: the #GstPadChainListFunction to set.
1365 * Sets the given chain list function for the pad. The chainlist function is
1366 * called to process a #GstBufferList input buffer list. See
1367 * #GstPadChainListFunction for more details.
1372 gst_pad_set_chain_list_function (GstPad * pad,
1373 GstPadChainListFunction chainlist)
1375 g_return_if_fail (GST_IS_PAD (pad));
1376 g_return_if_fail (GST_PAD_IS_SINK (pad));
1378 GST_PAD_CHAINLISTFUNC (pad) = chainlist;
1379 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "chainlistfunc set to %s",
1380 GST_DEBUG_FUNCPTR_NAME (chainlist));
1384 * gst_pad_set_getrange_function:
1385 * @pad: a source #GstPad.
1386 * @get: the #GstPadGetRangeFunction to set.
1388 * Sets the given getrange function for the pad. The getrange function is
1389 * called to produce a new #GstBuffer to start the processing pipeline. see
1390 * #GstPadGetRangeFunction for a description of the getrange function.
1393 gst_pad_set_getrange_function (GstPad * pad, GstPadGetRangeFunction get)
1395 g_return_if_fail (GST_IS_PAD (pad));
1396 g_return_if_fail (GST_PAD_IS_SRC (pad));
1398 GST_PAD_GETRANGEFUNC (pad) = get;
1400 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "getrangefunc set to %s",
1401 GST_DEBUG_FUNCPTR_NAME (get));
1405 * gst_pad_set_event_function:
1406 * @pad: a #GstPad of either direction.
1407 * @event: the #GstPadEventFunction to set.
1409 * Sets the given event handler for the pad.
1412 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
1414 g_return_if_fail (GST_IS_PAD (pad));
1416 GST_PAD_EVENTFUNC (pad) = event;
1418 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "eventfunc for set to %s",
1419 GST_DEBUG_FUNCPTR_NAME (event));
1423 * gst_pad_set_query_function:
1424 * @pad: a #GstPad of either direction.
1425 * @query: the #GstPadQueryFunction to set.
1427 * Set the given query function for the pad.
1430 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
1432 g_return_if_fail (GST_IS_PAD (pad));
1434 GST_PAD_QUERYFUNC (pad) = query;
1436 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "queryfunc set to %s",
1437 GST_DEBUG_FUNCPTR_NAME (query));
1441 * gst_pad_set_iterate_internal_links_function:
1442 * @pad: a #GstPad of either direction.
1443 * @iterintlink: the #GstPadIterIntLinkFunction to set.
1445 * Sets the given internal link iterator function for the pad.
1450 gst_pad_set_iterate_internal_links_function (GstPad * pad,
1451 GstPadIterIntLinkFunction iterintlink)
1453 g_return_if_fail (GST_IS_PAD (pad));
1455 GST_PAD_ITERINTLINKFUNC (pad) = iterintlink;
1456 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "internal link iterator set to %s",
1457 GST_DEBUG_FUNCPTR_NAME (iterintlink));
1461 * gst_pad_set_link_function:
1463 * @link: the #GstPadLinkFunction to set.
1465 * Sets the given link function for the pad. It will be called when
1466 * the pad is linked with another pad.
1468 * The return value #GST_PAD_LINK_OK should be used when the connection can be
1471 * The return value #GST_PAD_LINK_REFUSED should be used when the connection
1472 * cannot be made for some reason.
1474 * If @link is installed on a source pad, it should call the #GstPadLinkFunction
1475 * of the peer sink pad, if present.
1478 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
1480 g_return_if_fail (GST_IS_PAD (pad));
1482 GST_PAD_LINKFUNC (pad) = link;
1483 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "linkfunc set to %s",
1484 GST_DEBUG_FUNCPTR_NAME (link));
1488 * gst_pad_set_unlink_function:
1490 * @unlink: the #GstPadUnlinkFunction to set.
1492 * Sets the given unlink function for the pad. It will be called
1493 * when the pad is unlinked.
1496 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
1498 g_return_if_fail (GST_IS_PAD (pad));
1500 GST_PAD_UNLINKFUNC (pad) = unlink;
1501 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "unlinkfunc set to %s",
1502 GST_DEBUG_FUNCPTR_NAME (unlink));
1507 * @srcpad: the source #GstPad to unlink.
1508 * @sinkpad: the sink #GstPad to unlink.
1510 * Unlinks the source pad from the sink pad. Will emit the #GstPad::unlinked
1511 * signal on both pads.
1513 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1514 * the pads were not linked together.
1519 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1521 gboolean result = FALSE;
1522 GstElement *parent = NULL;
1525 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1526 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), FALSE);
1527 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1528 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad), FALSE);
1530 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1531 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1532 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1534 /* We need to notify the parent before taking any pad locks as the bin in
1535 * question might be waiting for a lock on the pad while holding its lock
1536 * that our message will try to take. */
1537 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad)))) {
1538 if (GST_IS_ELEMENT (parent)) {
1539 gst_element_post_message (parent,
1540 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1541 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, TRUE));
1543 gst_object_unref (parent);
1548 GST_OBJECT_LOCK (srcpad);
1549 GST_OBJECT_LOCK (sinkpad);
1551 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1552 goto not_linked_together;
1554 if (GST_PAD_UNLINKFUNC (srcpad)) {
1555 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1557 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1558 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1561 /* first clear peers */
1562 GST_PAD_PEER (srcpad) = NULL;
1563 GST_PAD_PEER (sinkpad) = NULL;
1565 /* clear pending caps if any */
1566 for (i = 0; i < GST_EVENT_MAX_STICKY; i++)
1567 gst_event_replace (&sinkpad->priv->events[i].pending, NULL);
1569 GST_OBJECT_UNLOCK (sinkpad);
1570 GST_OBJECT_UNLOCK (srcpad);
1572 /* fire off a signal to each of the pads telling them
1573 * that they've been unlinked */
1574 g_signal_emit (srcpad, gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1575 g_signal_emit (sinkpad, gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1577 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1578 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1583 if (parent != NULL) {
1584 gst_element_post_message (parent,
1585 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1586 GST_STRUCTURE_CHANGE_TYPE_PAD_UNLINK, parent, FALSE));
1587 gst_object_unref (parent);
1592 not_linked_together:
1594 /* we do not emit a warning in this case because unlinking cannot
1595 * be made MT safe.*/
1596 GST_OBJECT_UNLOCK (sinkpad);
1597 GST_OBJECT_UNLOCK (srcpad);
1603 * gst_pad_is_linked:
1604 * @pad: pad to check
1606 * Checks if a @pad is linked to another pad or not.
1608 * Returns: TRUE if the pad is linked, FALSE otherwise.
1613 gst_pad_is_linked (GstPad * pad)
1617 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1619 GST_OBJECT_LOCK (pad);
1620 result = (GST_PAD_PEER (pad) != NULL);
1621 GST_OBJECT_UNLOCK (pad);
1626 /* get the caps from both pads and see if the intersection
1629 * This function should be called with the pad LOCK on both
1633 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink,
1634 GstPadLinkCheck flags)
1636 GstCaps *srccaps = NULL;
1637 GstCaps *sinkcaps = NULL;
1638 gboolean compatible = FALSE;
1640 if (!(flags & (GST_PAD_LINK_CHECK_CAPS | GST_PAD_LINK_CHECK_TEMPLATE_CAPS)))
1643 /* Doing the expensive caps checking takes priority over only checking the template caps */
1644 if (flags & GST_PAD_LINK_CHECK_CAPS) {
1645 GST_OBJECT_UNLOCK (src);
1646 srccaps = gst_pad_query_caps (src, NULL);
1647 GST_OBJECT_LOCK (src);
1648 GST_OBJECT_UNLOCK (sink);
1649 sinkcaps = gst_pad_query_caps (sink, NULL);
1650 GST_OBJECT_LOCK (sink);
1652 /* If one of the two pads doesn't have a template, consider the intersection
1654 if (G_UNLIKELY ((GST_PAD_PAD_TEMPLATE (src) == NULL)
1655 || (GST_PAD_PAD_TEMPLATE (sink) == NULL))) {
1659 srccaps = gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (src)));
1661 gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (sink)));
1664 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, src, "src caps %" GST_PTR_FORMAT,
1666 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, sink, "sink caps %" GST_PTR_FORMAT,
1669 /* if we have caps on both pads we can check the intersection. If one
1670 * of the caps is NULL, we return TRUE. */
1671 if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
1673 gst_caps_unref (srccaps);
1675 gst_caps_unref (sinkcaps);
1679 compatible = gst_caps_can_intersect (srccaps, sinkcaps);
1680 gst_caps_unref (srccaps);
1681 gst_caps_unref (sinkcaps);
1684 GST_CAT_DEBUG (GST_CAT_CAPS, "caps are %scompatible",
1685 (compatible ? "" : "not"));
1690 /* check if the grandparents of both pads are the same.
1691 * This check is required so that we don't try to link
1692 * pads from elements in different bins without ghostpads.
1694 * The LOCK should be held on both pads
1697 gst_pad_link_check_hierarchy (GstPad * src, GstPad * sink)
1699 GstObject *psrc, *psink;
1701 psrc = GST_OBJECT_PARENT (src);
1702 psink = GST_OBJECT_PARENT (sink);
1704 /* if one of the pads has no parent, we allow the link */
1705 if (G_UNLIKELY (psrc == NULL || psink == NULL))
1708 /* only care about parents that are elements */
1709 if (G_UNLIKELY (!GST_IS_ELEMENT (psrc) || !GST_IS_ELEMENT (psink)))
1710 goto no_element_parent;
1712 /* if the parents are the same, we have a loop */
1713 if (G_UNLIKELY (psrc == psink))
1716 /* if they both have a parent, we check the grandparents. We can not lock
1717 * the parent because we hold on the child (pad) and the locking order is
1718 * parent >> child. */
1719 psrc = GST_OBJECT_PARENT (psrc);
1720 psink = GST_OBJECT_PARENT (psink);
1722 /* if they have grandparents but they are not the same */
1723 if (G_UNLIKELY (psrc != psink))
1724 goto wrong_grandparents;
1731 GST_CAT_DEBUG (GST_CAT_CAPS,
1732 "one of the pads has no parent %" GST_PTR_FORMAT " and %"
1733 GST_PTR_FORMAT, psrc, psink);
1738 GST_CAT_DEBUG (GST_CAT_CAPS,
1739 "one of the pads has no element parent %" GST_PTR_FORMAT " and %"
1740 GST_PTR_FORMAT, psrc, psink);
1745 GST_CAT_DEBUG (GST_CAT_CAPS, "pads have same parent %" GST_PTR_FORMAT,
1751 GST_CAT_DEBUG (GST_CAT_CAPS,
1752 "pads have different grandparents %" GST_PTR_FORMAT " and %"
1753 GST_PTR_FORMAT, psrc, psink);
1758 /* FIXME leftover from an attempt at refactoring... */
1759 /* call with the two pads unlocked, when this function returns GST_PAD_LINK_OK,
1760 * the two pads will be locked in the srcpad, sinkpad order. */
1761 static GstPadLinkReturn
1762 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
1764 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1765 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1767 GST_OBJECT_LOCK (srcpad);
1769 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1770 goto src_was_linked;
1772 GST_OBJECT_LOCK (sinkpad);
1774 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1775 goto sink_was_linked;
1777 /* check hierarchy, pads can only be linked if the grandparents
1779 if ((flags & GST_PAD_LINK_CHECK_HIERARCHY)
1780 && !gst_pad_link_check_hierarchy (srcpad, sinkpad))
1781 goto wrong_hierarchy;
1783 /* check pad caps for non-empty intersection */
1784 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad, flags))
1787 /* FIXME check pad scheduling for non-empty intersection */
1789 return GST_PAD_LINK_OK;
1793 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was already linked to %s:%s",
1794 GST_DEBUG_PAD_NAME (srcpad),
1795 GST_DEBUG_PAD_NAME (GST_PAD_PEER (srcpad)));
1796 /* we do not emit a warning in this case because unlinking cannot
1797 * be made MT safe.*/
1798 GST_OBJECT_UNLOCK (srcpad);
1799 return GST_PAD_LINK_WAS_LINKED;
1803 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was already linked to %s:%s",
1804 GST_DEBUG_PAD_NAME (sinkpad),
1805 GST_DEBUG_PAD_NAME (GST_PAD_PEER (sinkpad)));
1806 /* we do not emit a warning in this case because unlinking cannot
1807 * be made MT safe.*/
1808 GST_OBJECT_UNLOCK (sinkpad);
1809 GST_OBJECT_UNLOCK (srcpad);
1810 return GST_PAD_LINK_WAS_LINKED;
1814 GST_CAT_INFO (GST_CAT_PADS, "pads have wrong hierarchy");
1815 GST_OBJECT_UNLOCK (sinkpad);
1816 GST_OBJECT_UNLOCK (srcpad);
1817 return GST_PAD_LINK_WRONG_HIERARCHY;
1821 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1822 GST_OBJECT_UNLOCK (sinkpad);
1823 GST_OBJECT_UNLOCK (srcpad);
1824 return GST_PAD_LINK_NOFORMAT;
1830 * @srcpad: the source #GstPad.
1831 * @sinkpad: the sink #GstPad.
1833 * Checks if the source pad and the sink pad are compatible so they can be
1836 * Returns: TRUE if the pads can be linked.
1839 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1841 GstPadLinkReturn result;
1843 /* generic checks */
1844 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1845 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1847 GST_CAT_INFO (GST_CAT_PADS, "check if %s:%s can link with %s:%s",
1848 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1850 /* gst_pad_link_prepare does everything for us, we only release the locks
1851 * on the pads that it gets us. If this function returns !OK the locks are not
1853 result = gst_pad_link_prepare (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
1854 if (result != GST_PAD_LINK_OK)
1857 GST_OBJECT_UNLOCK (srcpad);
1858 GST_OBJECT_UNLOCK (sinkpad);
1861 return result == GST_PAD_LINK_OK;
1865 * gst_pad_link_full:
1866 * @srcpad: the source #GstPad to link.
1867 * @sinkpad: the sink #GstPad to link.
1868 * @flags: the checks to validate when linking
1870 * Links the source pad and the sink pad.
1872 * This variant of #gst_pad_link provides a more granular control on the
1873 * checks being done when linking. While providing some considerable speedups
1874 * the caller of this method must be aware that wrong usage of those flags
1875 * can cause severe issues. Refer to the documentation of #GstPadLinkCheck
1876 * for more information.
1880 * Returns: A result code indicating if the connection worked or
1886 gst_pad_link_full (GstPad * srcpad, GstPad * sinkpad, GstPadLinkCheck flags)
1888 GstPadLinkReturn result;
1890 GstPadLinkFunction srcfunc, sinkfunc;
1892 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
1893 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), GST_PAD_LINK_WRONG_DIRECTION);
1894 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
1895 g_return_val_if_fail (GST_PAD_IS_SINK (sinkpad),
1896 GST_PAD_LINK_WRONG_DIRECTION);
1898 /* Notify the parent early. See gst_pad_unlink for details. */
1899 if (G_LIKELY ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (srcpad))))) {
1900 if (G_LIKELY (GST_IS_ELEMENT (parent))) {
1901 gst_element_post_message (parent,
1902 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1903 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, TRUE));
1905 gst_object_unref (parent);
1910 /* prepare will also lock the two pads */
1911 result = gst_pad_link_prepare (srcpad, sinkpad, flags);
1913 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
1916 /* must set peers before calling the link function */
1917 GST_PAD_PEER (srcpad) = sinkpad;
1918 GST_PAD_PEER (sinkpad) = srcpad;
1920 /* make sure we update events */
1921 prepare_event_update (srcpad, sinkpad);
1923 /* get the link functions */
1924 srcfunc = GST_PAD_LINKFUNC (srcpad);
1925 sinkfunc = GST_PAD_LINKFUNC (sinkpad);
1927 if (G_UNLIKELY (srcfunc || sinkfunc)) {
1928 /* custom link functions, execute them */
1929 GST_OBJECT_UNLOCK (sinkpad);
1930 GST_OBJECT_UNLOCK (srcpad);
1933 /* this one will call the peer link function */
1934 result = srcfunc (srcpad, sinkpad);
1935 } else if (sinkfunc) {
1936 /* if no source link function, we need to call the sink link
1937 * function ourselves. */
1938 result = sinkfunc (sinkpad, srcpad);
1941 GST_OBJECT_LOCK (srcpad);
1942 GST_OBJECT_LOCK (sinkpad);
1944 /* we released the lock, check if the same pads are linked still */
1945 if (GST_PAD_PEER (srcpad) != sinkpad || GST_PAD_PEER (sinkpad) != srcpad)
1946 goto concurrent_link;
1948 if (G_UNLIKELY (result != GST_PAD_LINK_OK))
1951 GST_OBJECT_UNLOCK (sinkpad);
1952 GST_OBJECT_UNLOCK (srcpad);
1954 /* fire off a signal to each of the pads telling them
1955 * that they've been linked */
1956 g_signal_emit (srcpad, gst_pad_signals[PAD_LINKED], 0, sinkpad);
1957 g_signal_emit (sinkpad, gst_pad_signals[PAD_LINKED], 0, srcpad);
1959 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1960 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1962 gst_pad_send_event (srcpad, gst_event_new_reconfigure ());
1965 if (G_LIKELY (parent)) {
1966 gst_element_post_message (parent,
1967 gst_message_new_structure_change (GST_OBJECT_CAST (sinkpad),
1968 GST_STRUCTURE_CHANGE_TYPE_PAD_LINK, parent, FALSE));
1969 gst_object_unref (parent);
1977 GST_CAT_INFO (GST_CAT_PADS, "concurrent link between %s:%s and %s:%s",
1978 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1979 GST_OBJECT_UNLOCK (sinkpad);
1980 GST_OBJECT_UNLOCK (srcpad);
1982 /* The other link operation succeeded first */
1983 result = GST_PAD_LINK_WAS_LINKED;
1988 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
1989 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1991 GST_PAD_PEER (srcpad) = NULL;
1992 GST_PAD_PEER (sinkpad) = NULL;
1994 GST_OBJECT_UNLOCK (sinkpad);
1995 GST_OBJECT_UNLOCK (srcpad);
2003 * @srcpad: the source #GstPad to link.
2004 * @sinkpad: the sink #GstPad to link.
2006 * Links the source pad and the sink pad.
2008 * Returns: A result code indicating if the connection worked or
2014 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
2016 return gst_pad_link_full (srcpad, sinkpad, GST_PAD_LINK_CHECK_DEFAULT);
2020 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
2022 GstPadTemplate **template_p;
2024 /* this function would need checks if it weren't static */
2026 GST_OBJECT_LOCK (pad);
2027 template_p = &pad->padtemplate;
2028 gst_object_replace ((GstObject **) template_p, (GstObject *) templ);
2029 GST_OBJECT_UNLOCK (pad);
2032 gst_pad_template_pad_created (templ, pad);
2036 * gst_pad_get_pad_template:
2039 * Gets the template for @pad.
2041 * Returns: (transfer full): the #GstPadTemplate from which this pad was
2042 * instantiated, or %NULL if this pad has no template. Unref after
2046 gst_pad_get_pad_template (GstPad * pad)
2048 GstPadTemplate *templ;
2050 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2052 templ = GST_PAD_PAD_TEMPLATE (pad);
2054 return (templ ? gst_object_ref (templ) : NULL);
2058 * gst_pad_has_current_caps:
2059 * @pad: a #GstPad to check
2061 * Check if @pad has caps set on it with a #GST_EVENT_CAPS event.
2063 * Returns: TRUE when @pad has caps associated with it.
2066 gst_pad_has_current_caps (GstPad * pad)
2071 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2073 GST_OBJECT_LOCK (pad);
2074 caps = get_pad_caps (pad);
2075 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2076 "check current pad caps %" GST_PTR_FORMAT, caps);
2077 result = (caps != NULL);
2078 GST_OBJECT_UNLOCK (pad);
2084 * gst_pad_get_current_caps:
2085 * @pad: a #GstPad to get the current capabilities of.
2087 * Gets the capabilities currently configured on @pad with the last
2088 * #GST_EVENT_CAPS event.
2090 * Returns: the current caps of the pad with incremented ref-count.
2093 gst_pad_get_current_caps (GstPad * pad)
2097 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2099 GST_OBJECT_LOCK (pad);
2100 if ((result = get_pad_caps (pad)))
2101 gst_caps_ref (result);
2102 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2103 "get current pad caps %" GST_PTR_FORMAT, result);
2104 GST_OBJECT_UNLOCK (pad);
2111 * @pad: a #GstPad to set the capabilities of.
2112 * @caps: (transfer none): a #GstCaps to set.
2114 * Sets the capabilities of this pad. The caps must be fixed. Any previous
2115 * caps on the pad will be unreffed. This function refs the caps so you should
2116 * unref if as soon as you don't need it anymore.
2117 * It is possible to set NULL caps, which will make the pad unnegotiated
2120 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
2121 * or bad parameters were provided to this function.
2126 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
2129 gboolean res = TRUE;
2131 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2132 g_return_val_if_fail (caps != NULL && gst_caps_is_fixed (caps), FALSE);
2134 event = gst_event_new_caps (caps);
2136 if (GST_PAD_IS_SRC (pad))
2137 res = gst_pad_push_event (pad, event);
2139 res = gst_pad_send_event (pad, event);
2145 do_event_function (GstPad * pad, GstEvent * event,
2146 GstPadEventFunction eventfunc, gboolean * caps_notify)
2148 gboolean result = TRUE, call_event = TRUE;
2149 GstCaps *caps, *old, *templ;
2151 switch (GST_EVENT_TYPE (event)) {
2152 case GST_EVENT_CAPS:
2154 /* backwards compatibility mode for caps */
2155 gst_event_parse_caps (event, &caps);
2157 /* See if pad accepts the caps */
2158 templ = gst_pad_get_pad_template_caps (pad);
2159 if (!gst_caps_is_subset (caps, templ))
2162 /* check if it changed */
2163 if ((old = gst_pad_get_current_caps (pad))) {
2164 call_event = !gst_caps_is_equal (caps, old);
2165 gst_caps_unref (old);
2168 *caps_notify = TRUE;
2169 gst_caps_unref (templ);
2177 GST_DEBUG_OBJECT (pad, "calling event function with event %p", event);
2178 result = eventfunc (pad, event);
2180 gst_event_unref (event);
2187 gst_caps_unref (templ);
2188 gst_event_unref (event);
2189 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2190 "caps %" GST_PTR_FORMAT " not accepted", caps);
2195 #define ACQUIRE_PARENT(pad, parent, label) \
2197 if (G_LIKELY ((parent = GST_OBJECT_PARENT (pad)))) \
2198 gst_object_ref (parent); \
2199 else if (G_LIKELY (GST_PAD_NEEDS_PARENT (pad))) \
2203 #define RELEASE_PARENT(parent) \
2205 if (G_LIKELY (parent)) \
2206 gst_object_unref (parent); \
2209 /* function to send all pending events on the sinkpad to the event
2210 * function and collect the results. This function should be called with
2211 * the object lock. The object lock might be released by this function.
2213 static GstFlowReturn
2214 gst_pad_update_events (GstPad * pad)
2217 GstFlowReturn ret = GST_FLOW_OK;
2219 GstPadEventFunction eventfunc;
2221 gboolean caps_notify = FALSE;
2224 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
2227 for (i = 0; i < GST_EVENT_MAX_STICKY; i++) {
2230 ev = &pad->priv->events[i];
2232 /* skip without pending event */
2233 if ((event = gst_event_steal (&ev->pending)) == NULL)
2236 ACQUIRE_PARENT (pad, parent, no_parent);
2238 gst_event_ref (event);
2239 GST_OBJECT_UNLOCK (pad);
2241 res = do_event_function (pad, event, eventfunc, &caps_notify);
2243 RELEASE_PARENT (parent);
2245 /* things could have changed while we release the lock, check if we still
2246 * are handling the same event, if we don't something changed and we have
2247 * to try again. FIXME. we need a cookie here. FIXME, we also want to remove
2248 * that lock eventually and then do the retry elsewhere. */
2251 /* make the event active */
2252 gst_event_take (&ev->event, event);
2254 /* notify caps change when needed */
2256 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
2257 caps_notify = FALSE;
2260 gst_event_unref (event);
2261 ret = GST_FLOW_ERROR;
2263 GST_OBJECT_LOCK (pad);
2265 /* when we get here all events were successfully updated. */
2271 g_warning ("pad %s:%s has no event handler, file a bug.",
2272 GST_DEBUG_PAD_NAME (pad));
2273 return GST_FLOW_NOT_SUPPORTED;
2277 GST_DEBUG_OBJECT (pad, "pad has no parent");
2278 gst_event_take (&ev->pending, event);
2279 return GST_FLOW_WRONG_STATE;
2284 * gst_pad_get_pad_template_caps:
2285 * @pad: a #GstPad to get the template capabilities from.
2287 * Gets the capabilities for @pad's template.
2289 * Returns: (transfer full): the #GstCaps of this pad template.
2290 * Unref after usage.
2293 gst_pad_get_pad_template_caps (GstPad * pad)
2295 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2297 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2299 if (GST_PAD_PAD_TEMPLATE (pad))
2300 return gst_pad_template_get_caps (GST_PAD_PAD_TEMPLATE (pad));
2302 return gst_static_caps_get (&anycaps);
2307 * @pad: a #GstPad to get the peer of.
2309 * Gets the peer of @pad. This function refs the peer pad so
2310 * you need to unref it after use.
2312 * Returns: (transfer full): the peer #GstPad. Unref after usage.
2317 gst_pad_get_peer (GstPad * pad)
2321 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2323 GST_OBJECT_LOCK (pad);
2324 result = GST_PAD_PEER (pad);
2326 gst_object_ref (result);
2327 GST_OBJECT_UNLOCK (pad);
2333 * gst_pad_get_allowed_caps:
2336 * Gets the capabilities of the allowed media types that can flow through
2337 * @pad and its peer.
2339 * The allowed capabilities is calculated as the intersection of the results of
2340 * calling gst_pad_query_caps() on @pad and its peer. The caller owns a reference
2341 * on the resulting caps.
2343 * Returns: (transfer full): the allowed #GstCaps of the pad link. Unref the
2344 * caps when you no longer need it. This function returns NULL when @pad
2350 gst_pad_get_allowed_caps (GstPad * pad)
2357 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2359 GST_OBJECT_LOCK (pad);
2360 peer = GST_PAD_PEER (pad);
2361 if (G_UNLIKELY (peer == NULL))
2364 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "getting allowed caps");
2366 gst_object_ref (peer);
2367 GST_OBJECT_UNLOCK (pad);
2368 mycaps = gst_pad_query_caps (pad, NULL);
2370 peercaps = gst_pad_query_caps (peer, NULL);
2371 gst_object_unref (peer);
2373 caps = gst_caps_intersect (mycaps, peercaps);
2374 gst_caps_unref (peercaps);
2375 gst_caps_unref (mycaps);
2377 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "allowed caps %" GST_PTR_FORMAT,
2384 GST_CAT_DEBUG_OBJECT (GST_CAT_PROPERTIES, pad, "no peer");
2385 GST_OBJECT_UNLOCK (pad);
2392 * gst_pad_iterate_internal_links_default:
2393 * @pad: the #GstPad to get the internal links of.
2395 * Iterate the list of pads to which the given pad is linked to inside of
2396 * the parent element.
2397 * This is the default handler, and thus returns an iterator of all of the
2398 * pads inside the parent element with opposite direction.
2400 * The caller must free this iterator after use with gst_iterator_free().
2402 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
2403 * returned pad with gst_object_unref().
2408 gst_pad_iterate_internal_links_default (GstPad * pad)
2416 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2421 GST_OBJECT_LOCK (pad);
2422 parent = GST_PAD_PARENT (pad);
2423 if (!parent || !GST_IS_ELEMENT (parent))
2426 gst_object_ref (parent);
2427 GST_OBJECT_UNLOCK (pad);
2429 if (pad->direction == GST_PAD_SRC)
2430 padlist = &parent->sinkpads;
2432 padlist = &parent->srcpads;
2434 GST_DEBUG_OBJECT (pad, "Making iterator");
2436 cookie = &parent->pads_cookie;
2438 lock = GST_OBJECT_GET_LOCK (parent);
2441 res = gst_iterator_new_list (GST_TYPE_PAD,
2442 lock, cookie, padlist, (GObject *) owner, NULL);
2444 gst_object_unref (owner);
2451 GST_OBJECT_UNLOCK (pad);
2452 GST_DEBUG_OBJECT (pad, "no parent element");
2458 * gst_pad_iterate_internal_links:
2459 * @pad: the GstPad to get the internal links of.
2461 * Gets an iterator for the pads to which the given pad is linked to inside
2462 * of the parent element.
2464 * Each #GstPad element yielded by the iterator will have its refcount increased,
2465 * so unref after use.
2467 * Free-function: gst_iterator_free
2469 * Returns: (transfer full): a new #GstIterator of #GstPad or %NULL when the
2470 * pad does not have an iterator function configured. Use
2471 * gst_iterator_free() after usage.
2476 gst_pad_iterate_internal_links (GstPad * pad)
2478 GstIterator *res = NULL;
2481 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2483 GST_OBJECT_LOCK (pad);
2484 ACQUIRE_PARENT (pad, parent, no_parent);
2485 GST_OBJECT_UNLOCK (pad);
2487 if (GST_PAD_ITERINTLINKFUNC (pad))
2488 res = GST_PAD_ITERINTLINKFUNC (pad) (pad);
2490 RELEASE_PARENT (parent);
2497 GST_DEBUG_OBJECT (pad, "no parent");
2498 GST_OBJECT_UNLOCK (pad);
2506 * @forward: a #GstPadForwardFunction
2507 * @user_data: user data passed to @forward
2509 * Calls @forward for all internally linked pads of @pad. This function deals with
2510 * dynamically changing internal pads and will make sure that the @forward
2511 * function is only called once for each pad.
2513 * When @forward returns TRUE, no further pads will be processed.
2515 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2518 gst_pad_forward (GstPad * pad, GstPadForwardFunction forward,
2521 gboolean result = FALSE;
2523 gboolean done = FALSE;
2524 GValue item = { 0, };
2525 GList *pushed_pads = NULL;
2527 iter = gst_pad_iterate_internal_links (pad);
2533 switch (gst_iterator_next (iter, &item)) {
2534 case GST_ITERATOR_OK:
2538 intpad = g_value_get_object (&item);
2540 /* if already pushed, skip. FIXME, find something faster to tag pads */
2541 if (g_list_find (pushed_pads, intpad)) {
2542 g_value_reset (&item);
2546 GST_LOG_OBJECT (pad, "calling forward function on pad %s:%s",
2547 GST_DEBUG_PAD_NAME (intpad));
2548 done = result = forward (intpad, user_data);
2550 pushed_pads = g_list_prepend (pushed_pads, intpad);
2552 g_value_reset (&item);
2555 case GST_ITERATOR_RESYNC:
2556 /* We don't reset the result here because we don't push the event
2557 * again on pads that got the event already and because we need
2558 * to consider the result of the previous pushes */
2559 gst_iterator_resync (iter);
2561 case GST_ITERATOR_ERROR:
2562 GST_ERROR_OBJECT (pad, "Could not iterate over internally linked pads");
2565 case GST_ITERATOR_DONE:
2570 g_value_unset (&item);
2571 gst_iterator_free (iter);
2573 g_list_free (pushed_pads);
2583 gboolean dispatched;
2587 event_forward_func (GstPad * pad, EventData * data)
2589 /* for each pad we send to, we should ref the event; it's up
2590 * to downstream to unref again when handled. */
2591 GST_LOG_OBJECT (pad, "Reffing and pushing event %p (%s) to %s:%s",
2592 data->event, GST_EVENT_TYPE_NAME (data->event), GST_DEBUG_PAD_NAME (pad));
2594 data->result |= gst_pad_push_event (pad, gst_event_ref (data->event));
2596 data->dispatched = TRUE;
2603 * gst_pad_event_default:
2604 * @pad: a #GstPad to call the default event handler on.
2605 * @event: (transfer full): the #GstEvent to handle.
2607 * Invokes the default event handler for the given pad.
2609 * The EOS event will pause the task associated with @pad before it is forwarded
2610 * to all internally linked pads,
2612 * The the event is sent to all pads internally linked to @pad. This function
2613 * takes ownership of @event.
2615 * Returns: TRUE if the event was sent successfully.
2618 gst_pad_event_default (GstPad * pad, GstEvent * event)
2620 gboolean result, forward = TRUE;
2622 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2623 g_return_val_if_fail (event != NULL, FALSE);
2625 GST_LOG_OBJECT (pad, "default event handler");
2627 switch (GST_EVENT_TYPE (event)) {
2630 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
2631 gst_pad_pause_task (pad);
2634 case GST_EVENT_CAPS:
2635 forward = GST_PAD_IS_PROXY_CAPS (pad);
2646 data.dispatched = FALSE;
2647 data.result = FALSE;
2649 gst_pad_forward (pad, (GstPadForwardFunction) event_forward_func, &data);
2651 /* for sinkpads without a parent element or without internal links, nothing
2652 * will be dispatched but we still want to return TRUE. */
2653 if (data.dispatched)
2654 result = data.result;
2659 gst_event_unref (event);
2664 /* Default accept caps implementation just checks against
2665 * the allowed caps for the pad */
2667 gst_pad_query_accept_caps_default (GstPad * pad, GstQuery * query)
2669 /* get the caps and see if it intersects to something not empty */
2670 GstCaps *caps, *allowed;
2673 GST_DEBUG_OBJECT (pad, "query accept-caps %" GST_PTR_FORMAT, query);
2675 /* first forward the query to internally linked pads when we are dealing with
2677 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2678 if ((result = gst_pad_proxy_query_accept_caps (pad, query))) {
2683 allowed = gst_pad_query_caps (pad, NULL);
2684 gst_query_parse_accept_caps (query, &caps);
2687 GST_DEBUG_OBJECT (pad, "allowed caps %" GST_PTR_FORMAT, allowed);
2688 result = gst_caps_is_subset (caps, allowed);
2689 gst_caps_unref (allowed);
2691 GST_DEBUG_OBJECT (pad, "no caps allowed on the pad");
2694 gst_query_set_accept_caps_result (query, result);
2700 /* Default caps implementation */
2702 gst_pad_query_caps_default (GstPad * pad, GstQuery * query)
2704 GstCaps *result = NULL, *filter;
2705 GstPadTemplate *templ;
2706 gboolean fixed_caps;
2708 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
2710 gst_query_parse_caps (query, &filter);
2712 /* first try to proxy if we must */
2713 if (GST_PAD_IS_PROXY_CAPS (pad)) {
2714 if ((gst_pad_proxy_query_caps (pad, query))) {
2715 gst_query_parse_caps_result (query, &result);
2720 /* no proxy or it failed, do default handling */
2721 fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
2723 GST_OBJECT_LOCK (pad);
2725 /* fixed caps, try the negotiated caps first */
2726 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "fixed pad caps: trying pad caps");
2727 if ((result = get_pad_caps (pad)))
2728 goto filter_done_unlock;
2731 if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
2732 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "trying pad template caps");
2733 if ((result = GST_PAD_TEMPLATE_CAPS (templ)))
2734 goto filter_done_unlock;
2738 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2739 "non-fixed pad caps: trying pad caps");
2740 /* non fixed caps, try the negotiated caps */
2741 if ((result = get_pad_caps (pad)))
2742 goto filter_done_unlock;
2744 GST_OBJECT_UNLOCK (pad);
2746 /* this almost never happens */
2747 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "pad has no caps");
2748 result = gst_caps_new_empty ();
2753 GST_OBJECT_UNLOCK (pad);
2756 /* run the filter on the result */
2758 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2759 "using caps %p %" GST_PTR_FORMAT " with filter %p %"
2760 GST_PTR_FORMAT, result, result, filter, filter);
2761 result = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
2762 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "result %p %" GST_PTR_FORMAT,
2765 GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
2766 "using caps %p %" GST_PTR_FORMAT, result, result);
2767 result = gst_caps_ref (result);
2771 gst_query_set_caps_result (query, result);
2772 gst_caps_unref (result);
2778 * gst_pad_query_default:
2779 * @pad: a #GstPad to call the default query handler on.
2780 * @query: (transfer none): the #GstQuery to handle.
2782 * Invokes the default query handler for the given pad.
2783 * The query is sent to all pads internally linked to @pad. Note that
2784 * if there are many possible sink pads that are internally linked to
2785 * @pad, only one will be sent the query.
2786 * Multi-sinkpad elements should implement custom query handlers.
2788 * Returns: TRUE if the query was performed successfully.
2791 gst_pad_query_default (GstPad * pad, GstQuery * query)
2793 gboolean forward = TRUE, ret = FALSE;
2795 switch (GST_QUERY_TYPE (query)) {
2796 case GST_QUERY_SCHEDULING:
2799 case GST_QUERY_ACCEPT_CAPS:
2800 ret = gst_pad_query_accept_caps_default (pad, query);
2803 case GST_QUERY_CAPS:
2804 ret = gst_pad_query_caps_default (pad, query);
2807 case GST_QUERY_POSITION:
2808 case GST_QUERY_SEEKING:
2809 case GST_QUERY_FORMATS:
2810 case GST_QUERY_LATENCY:
2811 case GST_QUERY_JITTER:
2812 case GST_QUERY_RATE:
2813 case GST_QUERY_CONVERT:
2814 case GST_QUERY_ALLOCATION:
2820 ret = gst_pad_forward
2821 (pad, (GstPadForwardFunction) gst_pad_peer_query, query);
2827 probe_hook_marshal (GHook * hook, ProbeMarshall * data)
2829 GstPad *pad = data->pad;
2830 GstPadProbeInfo *info = data->info;
2831 GstPadProbeType type, flags;
2832 GstPadProbeCallback callback;
2833 GstPadProbeReturn ret;
2835 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2836 "hook %lu, cookie %u checking", hook->hook_id, PROBE_COOKIE (hook));
2838 /* if we have called this callback, do nothing */
2839 if (PROBE_COOKIE (hook) == data->cookie) {
2840 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2841 "hook %lu, cookie %u already called", hook->hook_id,
2842 PROBE_COOKIE (hook));
2846 PROBE_COOKIE (hook) = data->cookie;
2848 flags = hook->flags >> G_HOOK_FLAG_USER_SHIFT;
2851 /* one of the data types */
2852 if ((flags & GST_PAD_PROBE_TYPE_ALL_BOTH & type) == 0)
2854 /* one of the scheduling types */
2855 if ((flags & GST_PAD_PROBE_TYPE_SCHEDULING & type) == 0)
2857 /* all of the blocking types must match */
2858 if ((flags & GST_PAD_PROBE_TYPE_BLOCKING) !=
2859 (type & GST_PAD_PROBE_TYPE_BLOCKING))
2862 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2863 "hook %lu with flags 0x%08x matches", hook->hook_id, flags);
2865 callback = (GstPadProbeCallback) hook->func;
2866 if (callback == NULL)
2869 GST_OBJECT_UNLOCK (pad);
2871 ret = callback (pad, info, hook->data);
2873 GST_OBJECT_LOCK (pad);
2874 data->marshalled = TRUE;
2877 case GST_PAD_PROBE_REMOVE:
2878 /* remove the probe */
2879 GST_DEBUG_OBJECT (pad, "asked to remove hook");
2880 cleanup_hook (pad, hook);
2882 case GST_PAD_PROBE_DROP:
2883 /* need to drop the data, make sure other probes don't get called
2885 GST_DEBUG_OBJECT (pad, "asked to drop item");
2886 info->type = GST_PAD_PROBE_TYPE_INVALID;
2887 data->dropped = TRUE;
2889 case GST_PAD_PROBE_PASS:
2890 /* inform the pad block to let things pass */
2891 GST_DEBUG_OBJECT (pad, "asked to pass item");
2895 GST_DEBUG_OBJECT (pad, "probe returned %d", ret);
2902 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2903 "hook %lu with flags 0x%08x does not match %08x", hook->hook_id,
2909 #define PROBE_PRE_PULL(pad,mask,data,offs,size,label,probed,defaultval) \
2911 if (G_UNLIKELY (pad->num_probes)) { \
2912 /* we start with passing NULL as the data item */ \
2913 GstPadProbeInfo info = { mask, NULL, offs, size }; \
2914 ret = do_probe_callbacks (pad, &info, defaultval); \
2915 /* store the possibly updated data item */ \
2916 data = GST_PAD_PROBE_INFO_DATA (&info); \
2917 /* if something went wrong, exit */ \
2918 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2920 /* otherwise check if the probe retured data */ \
2921 if (G_UNLIKELY (data != NULL)) \
2927 /* a probe that does not take or return any data */
2928 #define PROBE_NO_DATA(pad,mask,label,defaultval) \
2930 if (G_UNLIKELY (pad->num_probes)) { \
2931 /* pass NULL as the data item */ \
2932 GstPadProbeInfo info = { mask, NULL, 0, 0 }; \
2933 ret = do_probe_callbacks (pad, &info, defaultval); \
2934 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2939 #define PROBE_FULL(pad,mask,data,offs,size,label,defaultval) \
2941 if (G_UNLIKELY (pad->num_probes)) { \
2942 GstPadProbeInfo info = { mask, data, offs, size }; \
2943 ret = do_probe_callbacks (pad, &info, defaultval); \
2944 data = GST_PAD_PROBE_INFO_DATA (&info); \
2945 if (G_UNLIKELY (ret != defaultval && ret != GST_FLOW_OK)) \
2950 #define PROBE_PUSH(pad,mask,data,label) \
2951 PROBE_FULL(pad, mask, data, -1, -1, label, GST_FLOW_OK);
2952 #define PROBE_PULL(pad,mask,data,offs,size,label) \
2953 PROBE_FULL(pad, mask, data, offs, size, label, GST_FLOW_OK);
2955 static GstFlowReturn
2956 do_probe_callbacks (GstPad * pad, GstPadProbeInfo * info,
2957 GstFlowReturn defaultval)
2966 data.marshalled = FALSE;
2967 data.dropped = FALSE;
2968 data.cookie = ++pad->priv->probe_cookie;
2971 (info->type & GST_PAD_PROBE_TYPE_BLOCK) == GST_PAD_PROBE_TYPE_BLOCK;
2974 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2975 "do probes cookie %u", data.cookie);
2976 cookie = pad->priv->probe_list_cookie;
2978 g_hook_list_marshal (&pad->probes, TRUE,
2979 (GHookMarshaller) probe_hook_marshal, &data);
2981 /* if the list changed, call the new callbacks (they will not have their
2982 * cookie set to data.cookie */
2983 if (cookie != pad->priv->probe_list_cookie) {
2984 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2985 "probe list changed, restarting");
2989 /* the first item that dropped will stop the hooks and then we drop here */
2993 /* if no handler matched and we are blocking, let the item pass */
2994 if (!data.marshalled && is_block)
2997 /* At this point, all handlers returned either OK or PASS. If one handler
2998 * returned PASS, let the item pass */
3003 while (GST_PAD_IS_BLOCKED (pad)) {
3004 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3005 "we are blocked %d times", pad->num_blocked);
3007 /* we might have released the lock */
3008 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3011 /* now we block the streaming thread. It can be unlocked when we
3012 * deactivate the pad (which will also set the FLUSHING flag) or
3013 * when the pad is unblocked. A flushing event will also unblock
3014 * the pad after setting the FLUSHING flag. */
3015 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3016 "Waiting to be unblocked or set flushing");
3017 GST_OBJECT_FLAG_SET (pad, GST_PAD_BLOCKING);
3018 GST_PAD_BLOCK_WAIT (pad);
3019 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_BLOCKING);
3020 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "We got unblocked");
3022 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3032 GST_DEBUG_OBJECT (pad, "pad is flushing");
3033 return GST_FLOW_WRONG_STATE;
3037 GST_DEBUG_OBJECT (pad, "data is dropped");
3038 return GST_FLOW_CUSTOM_SUCCESS;
3042 /* FIXME : Should we return FLOW_OK or the defaultval ?? */
3043 GST_DEBUG_OBJECT (pad, "data is passed");
3051 * gst_pad_get_offset:
3054 * Get the offset applied to the running time of @pad. @pad has to be a source
3057 * Returns: the offset.
3060 gst_pad_get_offset (GstPad * pad)
3064 g_return_val_if_fail (GST_IS_PAD (pad), 0);
3066 GST_OBJECT_LOCK (pad);
3067 result = pad->offset;
3068 GST_OBJECT_UNLOCK (pad);
3074 * gst_pad_set_offset:
3076 * @offset: the offset
3078 * Set the offset that will be applied to the running time of @pad.
3081 gst_pad_set_offset (GstPad * pad, gint64 offset)
3087 g_return_if_fail (GST_IS_PAD (pad));
3089 GST_OBJECT_LOCK (pad);
3090 /* if nothing changed, do nothing */
3091 if (pad->offset == offset)
3094 pad->offset = offset;
3096 /* if no peer, we just updated the offset */
3097 if ((peer = GST_PAD_PEER (pad)) == NULL)
3100 /* switch pads around when dealing with a sinkpad */
3101 if (GST_PAD_IS_SINK (pad)) {
3102 /* ref the peer so it doesn't go away when we release the lock */
3103 tmp = gst_object_ref (peer);
3104 /* make sure we get the peer (the srcpad) */
3105 GST_OBJECT_UNLOCK (pad);
3111 GST_OBJECT_LOCK (pad);
3112 /* check if the pad didn't get relinked */
3113 if (GST_PAD_PEER (pad) != peer)
3116 /* we can release the ref now */
3117 gst_object_unref (peer);
3120 /* the index of the segment event in the array */
3121 idx = GST_EVENT_STICKY_IDX_TYPE (GST_EVENT_SEGMENT);
3123 /* lock order is srcpad >> sinkpad */
3124 GST_OBJECT_LOCK (peer);
3125 /* take the current segment event, adjust it and then place
3126 * it on the sinkpad. events on the srcpad are always active. */
3127 if (replace_event (pad, peer, idx))
3128 GST_OBJECT_FLAG_SET (peer, GST_PAD_NEED_EVENTS);
3130 GST_OBJECT_UNLOCK (peer);
3133 GST_OBJECT_UNLOCK (pad);
3139 * @pad: a #GstPad to invoke the default query on.
3140 * @query: (transfer none): the #GstQuery to perform.
3142 * Dispatches a query to a pad. The query should have been allocated by the
3143 * caller via one of the type-specific allocation functions. The element that
3144 * the pad belongs to is responsible for filling the query with an appropriate
3145 * response, which should then be parsed with a type-specific query parsing
3148 * Again, the caller is responsible for both the allocation and deallocation of
3149 * the query structure.
3151 * Please also note that some queries might need a running pipeline to work.
3153 * Returns: TRUE if the query could be performed.
3156 gst_pad_query (GstPad * pad, GstQuery * query)
3160 GstPadQueryFunction func;
3161 GstPadProbeType type;
3164 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3165 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3167 GST_DEBUG_OBJECT (pad, "sending query %p (%s)", query,
3168 GST_QUERY_TYPE_NAME (query));
3170 if (GST_PAD_IS_SRC (pad))
3171 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3173 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3175 GST_OBJECT_LOCK (pad);
3176 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3177 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3178 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3180 ACQUIRE_PARENT (pad, parent, no_parent);
3181 GST_OBJECT_UNLOCK (pad);
3183 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
3186 res = func (pad, query);
3188 RELEASE_PARENT (parent);
3190 GST_DEBUG_OBJECT (pad, "sent query %p (%s), result %d", query,
3191 GST_QUERY_TYPE_NAME (query), res);
3196 GST_OBJECT_LOCK (pad);
3197 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3198 GST_OBJECT_UNLOCK (pad);
3205 GST_DEBUG_OBJECT (pad, "had no parent");
3206 GST_OBJECT_UNLOCK (pad);
3211 GST_DEBUG_OBJECT (pad, "had no query function");
3216 GST_DEBUG_OBJECT (pad, "query failed");
3221 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3222 GST_OBJECT_UNLOCK (pad);
3228 * gst_pad_peer_query:
3229 * @pad: a #GstPad to invoke the peer query on.
3230 * @query: (transfer none): the #GstQuery to perform.
3232 * Performs gst_pad_query() on the peer of @pad.
3234 * The caller is responsible for both the allocation and deallocation of
3235 * the query structure.
3237 * Returns: TRUE if the query could be performed. This function returns %FALSE
3238 * if @pad has no peer.
3243 gst_pad_peer_query (GstPad * pad, GstQuery * query)
3246 GstPadProbeType type;
3250 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3251 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
3253 if (GST_PAD_IS_SRC (pad))
3254 type = GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM;
3256 type = GST_PAD_PROBE_TYPE_QUERY_UPSTREAM;
3258 GST_DEBUG_OBJECT (pad, "peer query %p (%s)", query,
3259 GST_QUERY_TYPE_NAME (query));
3261 GST_OBJECT_LOCK (pad);
3262 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
3263 GST_PAD_PROBE_TYPE_BLOCK, query, probe_stopped);
3264 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, query, probe_stopped);
3266 peerpad = GST_PAD_PEER (pad);
3267 if (G_UNLIKELY (peerpad == NULL))
3270 gst_object_ref (peerpad);
3271 GST_OBJECT_UNLOCK (pad);
3273 res = gst_pad_query (peerpad, query);
3275 gst_object_unref (peerpad);
3280 GST_OBJECT_LOCK (pad);
3281 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PULL, query, probe_stopped);
3282 GST_OBJECT_UNLOCK (pad);
3289 GST_WARNING_OBJECT (pad, "pad has no peer");
3290 GST_OBJECT_UNLOCK (pad);
3295 GST_DEBUG_OBJECT (pad, "query failed");
3300 GST_DEBUG_OBJECT (pad, "probe stopped: %s", gst_flow_get_name (ret));
3301 GST_OBJECT_UNLOCK (pad);
3306 /**********************************************************************
3307 * Data passing functions
3310 /* this is the chain function that does not perform the additional argument
3311 * checking for that little extra speed.
3313 static inline GstFlowReturn
3314 gst_pad_chain_data_unchecked (GstPad * pad, GstPadProbeType type, void *data)
3317 gboolean needs_events;
3319 GST_PAD_STREAM_LOCK (pad);
3321 GST_OBJECT_LOCK (pad);
3322 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3325 needs_events = GST_PAD_NEEDS_EVENTS (pad);
3326 if (G_UNLIKELY (needs_events)) {
3327 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_EVENTS);
3329 GST_DEBUG_OBJECT (pad, "need to update all events");
3330 ret = gst_pad_update_events (pad);
3331 if (G_UNLIKELY (ret != GST_FLOW_OK))
3335 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3337 PROBE_PUSH (pad, type, data, probe_stopped);
3339 GST_OBJECT_UNLOCK (pad);
3341 /* NOTE: we read the chainfunc unlocked.
3342 * we cannot hold the lock for the pad so we might send
3343 * the data to the wrong function. This is not really a
3344 * problem since functions are assigned at creation time
3345 * and don't change that often... */
3346 if (G_LIKELY (type & GST_PAD_PROBE_TYPE_BUFFER)) {
3347 GstPadChainFunction chainfunc;
3349 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
3352 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3353 "calling chainfunction &%s with buffer %" GST_PTR_FORMAT,
3354 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_BUFFER (data));
3356 ret = chainfunc (pad, GST_BUFFER_CAST (data));
3358 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3359 "called chainfunction &%s with buffer %p, returned %s",
3360 GST_DEBUG_FUNCPTR_NAME (chainfunc), data, gst_flow_get_name (ret));
3362 GstPadChainListFunction chainlistfunc;
3364 if (G_UNLIKELY ((chainlistfunc = GST_PAD_CHAINLISTFUNC (pad)) == NULL))
3367 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3368 "calling chainlistfunction &%s",
3369 GST_DEBUG_FUNCPTR_NAME (chainlistfunc));
3371 ret = chainlistfunc (pad, GST_BUFFER_LIST_CAST (data));
3373 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3374 "called chainlistfunction &%s, returned %s",
3375 GST_DEBUG_FUNCPTR_NAME (chainlistfunc), gst_flow_get_name (ret));
3378 GST_PAD_STREAM_UNLOCK (pad);
3385 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3386 "chaining, but pad was flushing");
3387 GST_OBJECT_UNLOCK (pad);
3388 GST_PAD_STREAM_UNLOCK (pad);
3389 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3390 return GST_FLOW_WRONG_STATE;
3394 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "events were not accepted");
3395 GST_OBJECT_UNLOCK (pad);
3396 GST_PAD_STREAM_UNLOCK (pad);
3397 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3402 GST_OBJECT_UNLOCK (pad);
3403 GST_PAD_STREAM_UNLOCK (pad);
3404 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3407 case GST_FLOW_CUSTOM_SUCCESS:
3408 GST_DEBUG_OBJECT (pad, "dropped buffer");
3412 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
3419 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3420 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3421 "pushing, but not chainhandler");
3422 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3423 ("push on pad %s:%s but it has no chainfunction",
3424 GST_DEBUG_PAD_NAME (pad)));
3425 GST_PAD_STREAM_UNLOCK (pad);
3426 return GST_FLOW_NOT_SUPPORTED;
3432 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3433 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
3436 * Chain a buffer to @pad.
3438 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
3440 * If the buffer type is not acceptable for @pad (as negotiated with a
3441 * preceeding GST_EVENT_CAPS event), this function returns
3442 * #GST_FLOW_NOT_NEGOTIATED.
3444 * The function proceeds calling the chain function installed on @pad (see
3445 * gst_pad_set_chain_function()) and the return value of that function is
3446 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3449 * In all cases, success or failure, the caller loses its reference to @buffer
3450 * after calling this function.
3452 * Returns: a #GstFlowReturn from the pad.
3457 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
3459 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3460 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3461 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3463 return gst_pad_chain_data_unchecked (pad,
3464 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3467 static GstFlowReturn
3468 gst_pad_chain_list_default (GstPad * pad, GstBufferList * list)
3474 GST_INFO_OBJECT (pad, "chaining each group in list as a merged buffer");
3476 len = gst_buffer_list_length (list);
3479 for (i = 0; i < len; i++) {
3480 buffer = gst_buffer_list_get (list, i);
3482 gst_pad_chain_data_unchecked (pad,
3483 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH,
3484 gst_buffer_ref (buffer));
3485 if (ret != GST_FLOW_OK)
3488 gst_buffer_list_unref (list);
3494 * gst_pad_chain_list:
3495 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3496 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
3499 * Chain a bufferlist to @pad.
3501 * The function returns #GST_FLOW_WRONG_STATE if the pad was flushing.
3503 * If @pad was not negotiated properly with a CAPS event, this function
3504 * returns #GST_FLOW_NOT_NEGOTIATED.
3506 * The function proceeds calling the chainlist function installed on @pad (see
3507 * gst_pad_set_chain_list_function()) and the return value of that function is
3508 * returned to the caller. #GST_FLOW_NOT_SUPPORTED is returned if @pad has no
3509 * chainlist function.
3511 * In all cases, success or failure, the caller loses its reference to @list
3512 * after calling this function.
3516 * Returns: a #GstFlowReturn from the pad.
3521 gst_pad_chain_list (GstPad * pad, GstBufferList * list)
3523 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3524 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3525 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3527 return gst_pad_chain_data_unchecked (pad,
3528 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3531 static GstFlowReturn
3532 gst_pad_push_data (GstPad * pad, GstPadProbeType type, void *data)
3537 GST_OBJECT_LOCK (pad);
3538 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3541 /* do block probes */
3542 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_BLOCK, data, probe_stopped);
3544 /* do post-blocking probes */
3545 PROBE_PUSH (pad, type, data, probe_stopped);
3547 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3550 /* take ref to peer pad before releasing the lock */
3551 gst_object_ref (peer);
3553 GST_OBJECT_UNLOCK (pad);
3555 ret = gst_pad_chain_data_unchecked (peer, type, data);
3557 gst_object_unref (peer);
3559 GST_OBJECT_LOCK (pad);
3561 if (pad->priv->using == 0) {
3562 /* pad is not active anymore, trigger idle callbacks */
3563 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
3564 probe_stopped, ret);
3566 GST_OBJECT_UNLOCK (pad);
3570 /* ERROR recovery here */
3574 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3575 "pushing, but pad was flushing");
3576 GST_OBJECT_UNLOCK (pad);
3577 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3578 return GST_FLOW_WRONG_STATE;
3582 GST_OBJECT_UNLOCK (pad);
3583 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3586 case GST_FLOW_CUSTOM_SUCCESS:
3587 GST_DEBUG_OBJECT (pad, "dropped buffer");
3591 GST_DEBUG_OBJECT (pad, "en error occured %s", gst_flow_get_name (ret));
3598 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3599 "pushing, but it was not linked");
3600 GST_OBJECT_UNLOCK (pad);
3601 gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
3602 return GST_FLOW_NOT_LINKED;
3608 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3609 * @buffer: (transfer full): the #GstBuffer to push returns GST_FLOW_ERROR
3612 * Pushes a buffer to the peer of @pad.
3614 * This function will call installed block probes before triggering any
3615 * installed data probes.
3617 * The function proceeds calling gst_pad_chain() on the peer pad and returns
3618 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3621 * In all cases, success or failure, the caller loses its reference to @buffer
3622 * after calling this function.
3624 * Returns: a #GstFlowReturn from the peer pad.
3629 gst_pad_push (GstPad * pad, GstBuffer * buffer)
3631 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3632 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3633 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
3635 return gst_pad_push_data (pad,
3636 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_PUSH, buffer);
3640 * gst_pad_push_list:
3641 * @pad: a source #GstPad, returns #GST_FLOW_ERROR if not.
3642 * @list: (transfer full): the #GstBufferList to push returns GST_FLOW_ERROR
3645 * Pushes a buffer list to the peer of @pad.
3647 * This function will call installed block probes before triggering any
3648 * installed data probes.
3650 * The function proceeds calling the chain function on the peer pad and returns
3651 * the value from that function. If @pad has no peer, #GST_FLOW_NOT_LINKED will
3652 * be returned. If the peer pad does not have any installed chainlist function
3653 * every group buffer of the list will be merged into a normal #GstBuffer and
3654 * chained via gst_pad_chain().
3656 * In all cases, success or failure, the caller loses its reference to @list
3657 * after calling this function.
3659 * Returns: a #GstFlowReturn from the peer pad.
3666 gst_pad_push_list (GstPad * pad, GstBufferList * list)
3668 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3669 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3670 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
3672 return gst_pad_push_data (pad,
3673 GST_PAD_PROBE_TYPE_BUFFER_LIST | GST_PAD_PROBE_TYPE_PUSH, list);
3676 static GstFlowReturn
3677 gst_pad_get_range_unchecked (GstPad * pad, guint64 offset, guint size,
3678 GstBuffer ** buffer)
3681 GstPadGetRangeFunction getrangefunc;
3683 GST_PAD_STREAM_LOCK (pad);
3685 GST_OBJECT_LOCK (pad);
3686 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3689 /* when one of the probes returns a buffer, probed_data will be called and we
3690 * skip calling the getrange function */
3691 PROBE_PRE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
3692 *buffer, offset, size, probe_stopped, probed_data, GST_FLOW_OK);
3693 GST_OBJECT_UNLOCK (pad);
3695 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
3698 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3699 "calling getrangefunc %s, offset %"
3700 G_GUINT64_FORMAT ", size %u",
3701 GST_DEBUG_FUNCPTR_NAME (getrangefunc), offset, size);
3703 ret = getrangefunc (pad, offset, size, buffer);
3705 if (G_UNLIKELY (ret != GST_FLOW_OK))
3706 goto get_range_failed;
3708 /* can only fire the signal if we have a valid buffer */
3709 GST_OBJECT_LOCK (pad);
3711 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
3712 *buffer, offset, size, probe_stopped_unref);
3713 GST_OBJECT_UNLOCK (pad);
3715 GST_PAD_STREAM_UNLOCK (pad);
3722 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3723 "getrange, but pad was flushing");
3724 GST_OBJECT_UNLOCK (pad);
3725 GST_PAD_STREAM_UNLOCK (pad);
3726 return GST_FLOW_WRONG_STATE;
3730 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3731 ("getrange on pad %s:%s but it has no getrangefunction",
3732 GST_DEBUG_PAD_NAME (pad)));
3733 GST_PAD_STREAM_UNLOCK (pad);
3734 return GST_FLOW_NOT_SUPPORTED;
3738 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3739 "probe returned %s", gst_flow_get_name (ret));
3740 GST_OBJECT_UNLOCK (pad);
3741 GST_PAD_STREAM_UNLOCK (pad);
3744 probe_stopped_unref:
3746 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3747 "probe returned %s", gst_flow_get_name (ret));
3748 GST_OBJECT_UNLOCK (pad);
3749 GST_PAD_STREAM_UNLOCK (pad);
3750 gst_buffer_unref (*buffer);
3756 GST_PAD_STREAM_UNLOCK (pad);
3758 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
3759 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
3760 pad, "getrange failed, flow: %s", gst_flow_get_name (ret));
3766 * gst_pad_get_range:
3767 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
3768 * @offset: The start offset of the buffer
3769 * @size: The length of the buffer
3770 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
3771 * returns #GST_FLOW_ERROR if %NULL.
3773 * When @pad is flushing this function returns #GST_FLOW_WRONG_STATE
3774 * immediately and @buffer is %NULL.
3776 * Calls the getrange function of @pad, see #GstPadGetRangeFunction for a
3777 * description of a getrange function. If @pad has no getrange function
3778 * installed (see gst_pad_set_getrange_function()) this function returns
3779 * #GST_FLOW_NOT_SUPPORTED.
3781 * This is a lowlevel function. Usualy gst_pad_pull_range() is used.
3783 * Returns: a #GstFlowReturn from the pad.
3788 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
3789 GstBuffer ** buffer)
3791 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3792 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
3793 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3795 return gst_pad_get_range_unchecked (pad, offset, size, buffer);
3799 * gst_pad_pull_range:
3800 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
3801 * @offset: The start offset of the buffer
3802 * @size: The length of the buffer
3803 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer, returns
3804 * GST_FLOW_ERROR if %NULL.
3806 * Pulls a @buffer from the peer pad.
3808 * This function will first trigger the pad block signal if it was
3811 * When @pad is not linked #GST_FLOW_NOT_LINKED is returned else this
3812 * function returns the result of gst_pad_get_range() on the peer pad.
3813 * See gst_pad_get_range() for a list of return values and for the
3814 * semantics of the arguments of this function.
3816 * Returns: a #GstFlowReturn from the peer pad.
3817 * When this function returns #GST_FLOW_OK, @buffer will contain a valid
3818 * #GstBuffer that should be freed with gst_buffer_unref() after usage.
3819 * @buffer may not be used or freed when any other return value than
3820 * #GST_FLOW_OK is returned.
3825 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
3826 GstBuffer ** buffer)
3830 gboolean needs_events;
3832 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
3833 g_return_val_if_fail (GST_PAD_IS_SINK (pad), GST_FLOW_ERROR);
3834 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
3836 GST_OBJECT_LOCK (pad);
3837 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
3840 /* when one of the probes returns a buffer, probed_data will be called and we
3841 * skip calling the peer getrange function */
3842 PROBE_PRE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BLOCK,
3843 *buffer, offset, size, pre_probe_stopped, probed_data, GST_FLOW_OK);
3845 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
3848 gst_object_ref (peer);
3850 GST_OBJECT_UNLOCK (pad);
3852 ret = gst_pad_get_range_unchecked (peer, offset, size, buffer);
3854 gst_object_unref (peer);
3856 GST_OBJECT_LOCK (pad);
3858 if (pad->priv->using == 0) {
3859 /* pad is not active anymore, trigger idle callbacks */
3860 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_IDLE,
3861 post_probe_stopped, ret);
3864 if (G_UNLIKELY (ret != GST_FLOW_OK))
3865 goto pull_range_failed;
3868 PROBE_PULL (pad, GST_PAD_PROBE_TYPE_PULL | GST_PAD_PROBE_TYPE_BUFFER,
3869 *buffer, offset, size, post_probe_stopped);
3871 needs_events = GST_PAD_NEEDS_EVENTS (pad);
3872 if (G_UNLIKELY (needs_events)) {
3873 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_EVENTS);
3875 GST_DEBUG_OBJECT (pad, "we need to update the events");
3876 ret = gst_pad_update_events (pad);
3877 if (G_UNLIKELY (ret != GST_FLOW_OK))
3880 GST_OBJECT_UNLOCK (pad);
3884 /* ERROR recovery here */
3887 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3888 "pullrange, but pad was flushing");
3889 GST_OBJECT_UNLOCK (pad);
3890 return GST_FLOW_WRONG_STATE;
3894 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pre probe returned %s",
3895 gst_flow_get_name (ret));
3896 GST_OBJECT_UNLOCK (pad);
3901 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3902 "pulling range, but it was not linked");
3903 GST_OBJECT_UNLOCK (pad);
3904 return GST_FLOW_NOT_LINKED;
3909 GST_OBJECT_UNLOCK (pad);
3910 GST_CAT_LEVEL_LOG (GST_CAT_SCHEDULING,
3911 (ret >= GST_FLOW_EOS) ? GST_LEVEL_INFO : GST_LEVEL_WARNING,
3912 pad, "pullrange failed, flow: %s", gst_flow_get_name (ret));
3917 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3918 "post probe returned %s", gst_flow_get_name (ret));
3919 GST_OBJECT_UNLOCK (pad);
3920 if (ret == GST_FLOW_OK)
3921 gst_buffer_unref (*buffer);
3927 GST_OBJECT_UNLOCK (pad);
3928 gst_buffer_unref (*buffer);
3930 GST_CAT_WARNING_OBJECT (GST_CAT_SCHEDULING, pad,
3931 "pullrange returned events that were not accepted");
3937 * gst_pad_push_event:
3938 * @pad: a #GstPad to push the event to.
3939 * @event: (transfer full): the #GstEvent to send to the pad.
3941 * Sends the event to the peer of the given pad. This function is
3942 * mainly used by elements to send events to their peer
3945 * This function takes owership of the provided event so you should
3946 * gst_event_ref() it if you want to reuse the event after this call.
3948 * Returns: TRUE if the event was handled.
3953 gst_pad_push_event (GstPad * pad, GstEvent * event)
3958 gboolean stored = FALSE;
3959 GstPadProbeType type;
3961 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3962 g_return_val_if_fail (event != NULL, FALSE);
3963 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
3965 if (GST_EVENT_IS_DOWNSTREAM (event))
3966 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
3968 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
3970 GST_OBJECT_LOCK (pad);
3972 peerpad = GST_PAD_PEER (pad);
3974 /* Two checks to be made:
3975 * . (un)set the FLUSHING flag for flushing events,
3976 * . handle pad blocking */
3977 switch (GST_EVENT_TYPE (event)) {
3978 case GST_EVENT_FLUSH_START:
3979 GST_PAD_SET_FLUSHING (pad);
3981 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
3982 /* flush start will have set the FLUSHING flag and will then
3983 * unlock all threads doing a GCond wait on the blocking pad. This
3984 * will typically unblock the STREAMING thread blocked on a pad. */
3985 GST_LOG_OBJECT (pad, "Pad is blocked, not forwarding flush-start, "
3986 "doing block signal.");
3987 GST_PAD_BLOCK_BROADCAST (pad);
3991 case GST_EVENT_FLUSH_STOP:
3992 GST_PAD_UNSET_FLUSHING (pad);
3994 /* Remove sticky EOS events */
3995 GST_LOG_OBJECT (pad, "Removing pending EOS events");
3996 clear_event (pad->priv->events,
3997 GST_EVENT_STICKY_IDX_TYPE (GST_EVENT_EOS));
3999 if (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad))) {
4000 GST_LOG_OBJECT (pad, "Pad is blocked, not forwarding flush-stop");
4006 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4009 /* store the event on the pad, but only on srcpads */
4010 if (GST_PAD_IS_SRC (pad) && GST_EVENT_IS_STICKY (event)) {
4013 idx = GST_EVENT_STICKY_IDX (event);
4014 GST_LOG_OBJECT (pad, "storing sticky event %s at index %u",
4015 GST_EVENT_TYPE_NAME (event), idx);
4017 /* srcpad sticky events always become active immediately */
4018 gst_event_replace (&pad->priv->events[idx].event, event);
4023 /* backwards compatibility mode for caps */
4024 switch (GST_EVENT_TYPE (event)) {
4025 case GST_EVENT_CAPS:
4027 GST_OBJECT_UNLOCK (pad);
4029 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
4031 GST_OBJECT_LOCK (pad);
4032 /* the peerpad might have changed. Things we checked above could not
4034 peerpad = GST_PAD_PEER (pad);
4037 case GST_EVENT_SEGMENT:
4041 offset = pad->offset;
4042 /* check if we need to adjust the segment */
4043 if (offset != 0 && (peerpad != NULL)) {
4046 /* copy segment values */
4047 gst_event_copy_segment (event, &segment);
4048 gst_event_unref (event);
4050 /* adjust and make a new event with the offset applied */
4051 segment.base += offset;
4052 event = gst_event_new_segment (&segment);
4056 case GST_EVENT_RECONFIGURE:
4057 if (GST_PAD_IS_SINK (pad))
4058 GST_OBJECT_FLAG_SET (pad, GST_PAD_NEED_RECONFIGURE);
4064 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH |
4065 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4071 /* send probes after modifying the events above */
4072 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4074 /* now check the peer pad */
4075 if (peerpad == NULL)
4078 gst_object_ref (peerpad);
4080 GST_OBJECT_UNLOCK (pad);
4082 GST_LOG_OBJECT (pad, "sending event %p (%s) to peerpad %" GST_PTR_FORMAT,
4083 event, GST_EVENT_TYPE_NAME (event), peerpad);
4085 result = gst_pad_send_event (peerpad, event);
4087 /* Note: we gave away ownership of the event at this point but we can still
4088 * print the old pointer */
4089 GST_LOG_OBJECT (pad,
4090 "sent event %p to peerpad %" GST_PTR_FORMAT ", result %d", event, peerpad,
4093 gst_object_unref (peerpad);
4095 GST_OBJECT_LOCK (pad);
4097 if (pad->priv->using == 0) {
4098 /* pad is not active anymore, trigger idle callbacks */
4099 PROBE_NO_DATA (pad, GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_IDLE,
4100 probe_stopped, GST_FLOW_OK);
4102 GST_OBJECT_UNLOCK (pad);
4104 return result | stored;
4106 /* ERROR handling */
4109 GST_DEBUG_OBJECT (pad, "We're flushing");
4110 GST_OBJECT_UNLOCK (pad);
4111 gst_event_unref (event);
4116 GST_DEBUG_OBJECT (pad, "Probe returned %s", gst_flow_get_name (ret));
4117 GST_OBJECT_UNLOCK (pad);
4118 gst_event_unref (event);
4123 GST_DEBUG_OBJECT (pad, "Dropping event because pad is not linked");
4124 GST_OBJECT_UNLOCK (pad);
4125 gst_event_unref (event);
4131 * gst_pad_send_event:
4132 * @pad: a #GstPad to send the event to.
4133 * @event: (transfer full): the #GstEvent to send to the pad.
4135 * Sends the event to the pad. This function can be used
4136 * by applications to send events in the pipeline.
4138 * If @pad is a source pad, @event should be an upstream event. If @pad is a
4139 * sink pad, @event should be a downstream event. For example, you would not
4140 * send a #GST_EVENT_EOS on a src pad; EOS events only propagate downstream.
4141 * Furthermore, some downstream events have to be serialized with data flow,
4142 * like EOS, while some can travel out-of-band, like #GST_EVENT_FLUSH_START. If
4143 * the event needs to be serialized with data flow, this function will take the
4144 * pad's stream lock while calling its event function.
4146 * To find out whether an event type is upstream, downstream, or downstream and
4147 * serialized, see #GstEventTypeFlags, gst_event_type_get_flags(),
4148 * #GST_EVENT_IS_UPSTREAM, #GST_EVENT_IS_DOWNSTREAM, and
4149 * #GST_EVENT_IS_SERIALIZED. Note that in practice that an application or
4150 * plugin doesn't need to bother itself with this information; the core handles
4151 * all necessary locks and checks.
4153 * This function takes owership of the provided event so you should
4154 * gst_event_ref() it if you want to reuse the event after this call.
4156 * Returns: TRUE if the event was handled.
4159 gst_pad_send_event (GstPad * pad, GstEvent * event)
4162 gboolean result = FALSE;
4163 gboolean serialized, need_unlock = FALSE, needs_events, sticky;
4164 GstPadProbeType type;
4166 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4167 g_return_val_if_fail (event != NULL, FALSE);
4169 GST_OBJECT_LOCK (pad);
4170 if (GST_PAD_IS_SINK (pad)) {
4171 if (G_UNLIKELY (!GST_EVENT_IS_DOWNSTREAM (event)))
4172 goto wrong_direction;
4173 serialized = GST_EVENT_IS_SERIALIZED (event);
4174 sticky = GST_EVENT_IS_STICKY (event);
4175 type = GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM;
4176 } else if (GST_PAD_IS_SRC (pad)) {
4177 if (G_UNLIKELY (!GST_EVENT_IS_UPSTREAM (event)))
4178 goto wrong_direction;
4179 /* events on srcpad never are serialized and sticky */
4180 serialized = sticky = FALSE;
4181 type = GST_PAD_PROBE_TYPE_EVENT_UPSTREAM;
4183 goto unknown_direction;
4185 /* get the flag first, we clear it when we have a FLUSH or a non-serialized
4187 needs_events = GST_PAD_NEEDS_EVENTS (pad);
4189 switch (GST_EVENT_TYPE (event)) {
4190 case GST_EVENT_FLUSH_START:
4191 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad,
4192 "have event type %d (FLUSH_START)", GST_EVENT_TYPE (event));
4194 /* can't even accept a flush begin event when flushing */
4195 if (GST_PAD_IS_FLUSHING (pad))
4198 GST_PAD_SET_FLUSHING (pad);
4199 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "set flush flag");
4200 needs_events = FALSE;
4202 case GST_EVENT_FLUSH_STOP:
4203 if (G_LIKELY (GST_PAD_ACTIVATE_MODE (pad) != GST_PAD_ACTIVATE_NONE)) {
4204 GST_PAD_UNSET_FLUSHING (pad);
4205 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "cleared flush flag");
4207 /* Remove pending EOS events */
4208 GST_LOG_OBJECT (pad, "Removing pending EOS events");
4209 clear_event (pad->priv->events,
4210 GST_EVENT_STICKY_IDX_TYPE (GST_EVENT_EOS));
4212 GST_OBJECT_UNLOCK (pad);
4213 /* grab stream lock */
4214 GST_PAD_STREAM_LOCK (pad);
4216 GST_OBJECT_LOCK (pad);
4217 needs_events = FALSE;
4219 case GST_EVENT_RECONFIGURE:
4220 if (GST_PAD_IS_SRC (pad))
4221 GST_OBJECT_FLAG_SET (pad, GST_PAD_NEED_RECONFIGURE);
4223 GST_CAT_DEBUG_OBJECT (GST_CAT_EVENT, pad, "have event type %s",
4224 GST_EVENT_TYPE_NAME (event));
4226 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
4230 /* lock order: STREAM_LOCK, LOCK, recheck flushing. */
4231 GST_OBJECT_UNLOCK (pad);
4232 GST_PAD_STREAM_LOCK (pad);
4234 GST_OBJECT_LOCK (pad);
4236 /* don't forward events on non-serialized events */
4237 needs_events = FALSE;
4240 /* store the event on the pad, but only on srcpads. We need to store the
4241 * event before checking the flushing flag. */
4246 switch (GST_EVENT_TYPE (event)) {
4247 case GST_EVENT_SEGMENT:
4248 if (pad->offset != 0) {
4251 /* copy segment values */
4252 gst_event_copy_segment (event, &segment);
4253 gst_event_unref (event);
4255 /* adjust and make a new event with the offset applied */
4256 segment.base += pad->offset;
4257 event = gst_event_new_segment (&segment);
4264 idx = GST_EVENT_STICKY_IDX (event);
4265 ev = &pad->priv->events[idx];
4267 if (ev->event != event) {
4268 GST_LOG_OBJECT (pad, "storing sticky event %s at index %u",
4269 GST_EVENT_TYPE_NAME (event), idx);
4270 gst_event_replace (&ev->pending, event);
4271 /* set the flag so that we update the events next time. We would
4272 * usually update below but we might be flushing too. */
4273 GST_OBJECT_FLAG_SET (pad, GST_PAD_NEED_EVENTS);
4274 needs_events = TRUE;
4277 /* now do the probe */
4279 type | GST_PAD_PROBE_TYPE_PUSH |
4280 GST_PAD_PROBE_TYPE_BLOCK, event, probe_stopped);
4282 PROBE_PUSH (pad, type | GST_PAD_PROBE_TYPE_PUSH, event, probe_stopped);
4287 if (G_UNLIKELY (needs_events)) {
4290 GST_OBJECT_FLAG_UNSET (pad, GST_PAD_NEED_EVENTS);
4292 GST_DEBUG_OBJECT (pad, "need to update all events");
4293 ret = gst_pad_update_events (pad);
4294 if (ret != GST_FLOW_OK)
4296 GST_OBJECT_UNLOCK (pad);
4298 gst_event_unref (event);
4303 /* ensure to pass on event;
4304 * note that a sticky event has already been updated above */
4305 if (G_LIKELY (!needs_events || !sticky)) {
4306 GstPadEventFunction eventfunc;
4309 if (G_UNLIKELY ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL))
4312 ACQUIRE_PARENT (pad, parent, no_parent);
4313 GST_OBJECT_UNLOCK (pad);
4315 result = eventfunc (pad, event);
4317 RELEASE_PARENT (parent);
4321 GST_PAD_STREAM_UNLOCK (pad);
4323 GST_DEBUG_OBJECT (pad, "sent event, result %d", result);
4327 /* ERROR handling */
4330 g_warning ("pad %s:%s sending %s event in wrong direction",
4331 GST_DEBUG_PAD_NAME (pad), GST_EVENT_TYPE_NAME (event));
4332 GST_OBJECT_UNLOCK (pad);
4333 gst_event_unref (event);
4338 g_warning ("pad %s:%s has invalid direction", GST_DEBUG_PAD_NAME (pad));
4339 GST_OBJECT_UNLOCK (pad);
4340 gst_event_unref (event);
4345 g_warning ("pad %s:%s has no event handler, file a bug.",
4346 GST_DEBUG_PAD_NAME (pad));
4347 GST_OBJECT_UNLOCK (pad);
4349 GST_PAD_STREAM_UNLOCK (pad);
4350 gst_event_unref (event);
4355 GST_DEBUG_OBJECT (pad, "no parent");
4356 GST_OBJECT_UNLOCK (pad);
4358 GST_PAD_STREAM_UNLOCK (pad);
4359 gst_event_unref (event);
4364 GST_OBJECT_UNLOCK (pad);
4366 GST_PAD_STREAM_UNLOCK (pad);
4367 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad,
4368 "Received event on flushing pad. Discarding");
4369 gst_event_unref (event);
4374 GST_DEBUG_OBJECT (pad, "probe returned %s", gst_flow_get_name (ret));
4375 GST_OBJECT_UNLOCK (pad);
4377 GST_PAD_STREAM_UNLOCK (pad);
4378 gst_event_unref (event);
4383 GST_OBJECT_UNLOCK (pad);
4385 GST_PAD_STREAM_UNLOCK (pad);
4386 GST_CAT_INFO_OBJECT (GST_CAT_EVENT, pad, "Update events failed");
4387 gst_event_unref (event);
4395 * gst_pad_set_element_private:
4396 * @pad: the #GstPad to set the private data of.
4397 * @priv: The private data to attach to the pad.
4399 * Set the given private data gpointer on the pad.
4400 * This function can only be used by the element that owns the pad.
4401 * No locking is performed in this function.
4404 gst_pad_set_element_private (GstPad * pad, gpointer priv)
4406 pad->element_private = priv;
4410 * gst_pad_get_element_private:
4411 * @pad: the #GstPad to get the private data of.
4413 * Gets the private data of a pad.
4414 * No locking is performed in this function.
4416 * Returns: (transfer none): a #gpointer to the private data.
4419 gst_pad_get_element_private (GstPad * pad)
4421 return pad->element_private;
4425 * gst_pad_get_sticky_event:
4426 * @pad: the #GstPad to get the event from.
4427 * @event_type: the #GstEventType that should be retrieved.
4429 * Returns a new reference of the sticky event of type @event_type
4432 * Returns: (transfer full): a #GstEvent of type @event_type. Unref after usage.
4435 gst_pad_get_sticky_event (GstPad * pad, GstEventType event_type)
4437 GstEvent *event = NULL;
4440 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4441 g_return_val_if_fail ((event_type & GST_EVENT_TYPE_STICKY) != 0, NULL);
4443 idx = GST_EVENT_STICKY_IDX_TYPE (event_type);
4445 GST_OBJECT_LOCK (pad);
4446 if ((event = pad->priv->events[idx].event)) {
4447 gst_event_ref (event);
4449 GST_OBJECT_UNLOCK (pad);
4455 * gst_pad_sticky_events_foreach:
4456 * @pad: the #GstPad that should be used for iteration.
4457 * @foreach_func: (scope call): the #GstPadStickyEventsForeachFunction that should be called for every event.
4458 * @user_data: (closure): the optional user data.
4460 * Iterates all active sticky events on @pad and calls @foreach_func for every
4461 * event. If @foreach_func returns something else than GST_FLOW_OK the iteration
4462 * is immediately stopped.
4464 * Returns: GST_FLOW_OK if iteration was successful
4467 gst_pad_sticky_events_foreach (GstPad * pad,
4468 GstPadStickyEventsForeachFunction foreach_func, gpointer user_data)
4470 GstFlowReturn ret = GST_FLOW_OK;
4474 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
4475 g_return_val_if_fail (foreach_func != NULL, GST_FLOW_ERROR);
4477 GST_OBJECT_LOCK (pad);
4480 for (i = 0; i < GST_EVENT_MAX_STICKY; i++) {
4484 ev = &pad->priv->events[i];
4486 /* skip without active event */
4487 if ((event = ev->event) == NULL)
4490 gst_event_ref (event);
4491 GST_OBJECT_UNLOCK (pad);
4493 res = foreach_func (pad, event, user_data);
4495 GST_OBJECT_LOCK (pad);
4496 gst_event_unref (event);
4498 if (res != GST_FLOW_OK) {
4503 /* things could have changed while we release the lock, check if we still
4504 * are handling the same event, if we don't something changed and we have
4505 * to try again. FIXME. we need a cookie here. */
4506 if (event != ev->event) {
4507 GST_DEBUG_OBJECT (pad, "events changed, restarting");
4511 GST_OBJECT_UNLOCK (pad);
4517 do_stream_status (GstPad * pad, GstStreamStatusType type,
4518 GThread * thread, GstTask * task)
4522 GST_DEBUG_OBJECT (pad, "doing stream-status %d", type);
4524 if ((parent = GST_ELEMENT_CAST (gst_pad_get_parent (pad)))) {
4525 if (GST_IS_ELEMENT (parent)) {
4526 GstMessage *message;
4527 GValue value = { 0 };
4529 if (type == GST_STREAM_STATUS_TYPE_ENTER) {
4530 gchar *tname, *ename, *pname;
4532 /* create a good task name */
4533 ename = gst_element_get_name (parent);
4534 pname = gst_pad_get_name (pad);
4535 tname = g_strdup_printf ("%s:%s", ename, pname);
4539 gst_object_set_name (GST_OBJECT_CAST (task), tname);
4543 message = gst_message_new_stream_status (GST_OBJECT_CAST (pad),
4546 g_value_init (&value, GST_TYPE_TASK);
4547 g_value_set_object (&value, task);
4548 gst_message_set_stream_status_object (message, &value);
4549 g_value_unset (&value);
4551 GST_DEBUG_OBJECT (pad, "posting stream-status %d", type);
4552 gst_element_post_message (parent, message);
4554 gst_object_unref (parent);
4559 pad_enter_thread (GstTask * task, GThread * thread, gpointer user_data)
4561 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_ENTER,
4566 pad_leave_thread (GstTask * task, GThread * thread, gpointer user_data)
4568 do_stream_status (GST_PAD_CAST (user_data), GST_STREAM_STATUS_TYPE_LEAVE,
4572 static GstTaskThreadCallbacks thr_callbacks = {
4578 * gst_pad_start_task:
4579 * @pad: the #GstPad to start the task of
4580 * @func: the task function to call
4581 * @data: data passed to the task function
4583 * Starts a task that repeatedly calls @func with @data. This function
4584 * is mostly used in pad activation functions to start the dataflow.
4585 * The #GST_PAD_STREAM_LOCK of @pad will automatically be acquired
4586 * before @func is called.
4588 * Returns: a %TRUE if the task could be started.
4591 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
4596 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4597 g_return_val_if_fail (func != NULL, FALSE);
4599 GST_DEBUG_OBJECT (pad, "start task");
4601 GST_OBJECT_LOCK (pad);
4602 task = GST_PAD_TASK (pad);
4604 task = gst_task_new (func, data);
4605 gst_task_set_lock (task, GST_PAD_GET_STREAM_LOCK (pad));
4606 gst_task_set_thread_callbacks (task, &thr_callbacks, pad, NULL);
4607 GST_DEBUG_OBJECT (pad, "created task");
4608 GST_PAD_TASK (pad) = task;
4609 gst_object_ref (task);
4610 /* release lock to post the message */
4611 GST_OBJECT_UNLOCK (pad);
4613 do_stream_status (pad, GST_STREAM_STATUS_TYPE_CREATE, NULL, task);
4615 gst_object_unref (task);
4617 GST_OBJECT_LOCK (pad);
4618 /* nobody else is supposed to have changed the pad now */
4619 if (GST_PAD_TASK (pad) != task)
4620 goto concurrent_stop;
4622 res = gst_task_set_state (task, GST_TASK_STARTED);
4623 GST_OBJECT_UNLOCK (pad);
4630 GST_OBJECT_UNLOCK (pad);
4636 * gst_pad_pause_task:
4637 * @pad: the #GstPad to pause the task of
4639 * Pause the task of @pad. This function will also wait until the
4640 * function executed by the task is finished if this function is not
4641 * called from the task function.
4643 * Returns: a TRUE if the task could be paused or FALSE when the pad
4647 gst_pad_pause_task (GstPad * pad)
4652 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4654 GST_DEBUG_OBJECT (pad, "pause task");
4656 GST_OBJECT_LOCK (pad);
4657 task = GST_PAD_TASK (pad);
4660 res = gst_task_set_state (task, GST_TASK_PAUSED);
4661 GST_OBJECT_UNLOCK (pad);
4663 /* wait for task function to finish, this lock is recursive so it does nothing
4664 * when the pause is called from the task itself */
4665 GST_PAD_STREAM_LOCK (pad);
4666 GST_PAD_STREAM_UNLOCK (pad);
4672 GST_DEBUG_OBJECT (pad, "pad has no task");
4673 GST_OBJECT_UNLOCK (pad);
4679 * gst_pad_stop_task:
4680 * @pad: the #GstPad to stop the task of
4682 * Stop the task of @pad. This function will also make sure that the
4683 * function executed by the task will effectively stop if not called
4684 * from the GstTaskFunction.
4686 * This function will deadlock if called from the GstTaskFunction of
4687 * the task. Use gst_task_pause() instead.
4689 * Regardless of whether the pad has a task, the stream lock is acquired and
4690 * released so as to ensure that streaming through this pad has finished.
4692 * Returns: a TRUE if the task could be stopped or FALSE on error.
4695 gst_pad_stop_task (GstPad * pad)
4700 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4702 GST_DEBUG_OBJECT (pad, "stop task");
4704 GST_OBJECT_LOCK (pad);
4705 task = GST_PAD_TASK (pad);
4708 GST_PAD_TASK (pad) = NULL;
4709 res = gst_task_set_state (task, GST_TASK_STOPPED);
4710 GST_OBJECT_UNLOCK (pad);
4712 GST_PAD_STREAM_LOCK (pad);
4713 GST_PAD_STREAM_UNLOCK (pad);
4715 if (!gst_task_join (task))
4718 gst_object_unref (task);
4724 GST_DEBUG_OBJECT (pad, "no task");
4725 GST_OBJECT_UNLOCK (pad);
4727 GST_PAD_STREAM_LOCK (pad);
4728 GST_PAD_STREAM_UNLOCK (pad);
4730 /* this is not an error */
4735 /* this is bad, possibly the application tried to join the task from
4736 * the task's thread. We install the task again so that it will be stopped
4737 * again from the right thread next time hopefully. */
4738 GST_OBJECT_LOCK (pad);
4739 GST_DEBUG_OBJECT (pad, "join failed");
4740 /* we can only install this task if there was no other task */
4741 if (GST_PAD_TASK (pad) == NULL)
4742 GST_PAD_TASK (pad) = task;
4743 GST_OBJECT_UNLOCK (pad);