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.
23 #include "gst_private.h"
26 #include "gstenumtypes.h"
27 #include "gstmarshal.h"
29 #include "gstelement.h"
31 #include "gstscheduler.h"
37 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
38 #define DEBUG_DATA(obj,data,notice) G_STMT_START{\
40 GST_CAT_DEBUG_OBJECT (debug_dataflow, obj, "NULL data value"); \
41 } else if (GST_IS_EVENT (data)) { \
42 GST_CAT_DEBUG_OBJECT (debug_dataflow, obj, "%s event %p (type %d, refcount %d)", notice, data, \
43 GST_EVENT_TYPE (data), GST_DATA_REFCOUNT_VALUE (data)); \
45 GST_CAT_LOG_OBJECT (debug_dataflow, obj, "%s buffer %p (size %u, refcount %d)", notice, data, \
46 GST_BUFFER_SIZE (data), GST_BUFFER_REFCOUNT_VALUE (data)); \
49 #define GST_CAT_DEFAULT GST_CAT_PADS
58 static GstObject *padtemplate_parent_class = NULL;
59 static guint gst_pad_template_signals[TEMPL_LAST_SIGNAL] = { 0 };
61 /* Pad signals and args */
80 GType _gst_pad_type = 0;
82 static void gst_pad_class_init (GstPadClass * klass);
83 static void gst_pad_init (GstPad * pad);
84 static void gst_pad_dispose (GObject * object);
85 static void gst_pad_finalize (GObject * object);
86 static void gst_pad_set_property (GObject * object, guint prop_id,
87 const GValue * value, GParamSpec * pspec);
88 static void gst_pad_get_property (GObject * object, guint prop_id,
89 GValue * value, GParamSpec * pspec);
91 static GstCaps *gst_pad_get_caps_unlocked (GstPad * pad);
92 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
93 static gboolean gst_pad_activate_default (GstPad * pad);
95 #ifndef GST_DISABLE_LOADSAVE
96 static xmlNodePtr gst_pad_save_thyself (GstObject * object, xmlNodePtr parent);
99 static GstObjectClass *pad_parent_class = NULL;
100 static guint gst_pad_signals[PAD_LAST_SIGNAL] = { 0 };
103 gst_pad_get_type (void)
105 if (!_gst_pad_type) {
106 static const GTypeInfo pad_info = {
107 sizeof (GstPadClass), NULL, NULL,
108 (GClassInitFunc) gst_pad_class_init, NULL, NULL,
111 (GInstanceInitFunc) gst_pad_init, NULL
114 _gst_pad_type = g_type_register_static (GST_TYPE_OBJECT, "GstPad",
117 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW",
118 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads");
120 return _gst_pad_type;
124 gst_pad_class_init (GstPadClass * klass)
126 GObjectClass *gobject_class;
129 GstObjectClass *gstobject_class;
131 gobject_class = (GObjectClass *) klass;
132 gstobject_class = (GstObjectClass *) klass;
134 pad_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
136 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_pad_dispose);
137 gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_pad_finalize);
138 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_pad_set_property);
139 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_pad_get_property);
141 gst_pad_signals[PAD_LINKED] =
142 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
143 G_STRUCT_OFFSET (GstPadClass, linked), NULL, NULL,
144 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
145 gst_pad_signals[PAD_UNLINKED] =
146 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
147 G_STRUCT_OFFSET (GstPadClass, unlinked), NULL, NULL,
148 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
149 gst_pad_signals[PAD_REQUEST_LINK] =
150 g_signal_new ("request_link", G_TYPE_FROM_CLASS (klass),
151 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstPadClass, request_link), NULL,
152 NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 0);
154 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_CAPS,
155 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
156 GST_TYPE_CAPS, G_PARAM_READABLE));
157 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_DIRECTION,
158 g_param_spec_enum ("direction", "Direction", "The direction of the pad",
159 GST_TYPE_PAD_DIRECTION, GST_PAD_UNKNOWN,
160 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
161 g_object_class_install_property (G_OBJECT_CLASS (klass), PAD_PROP_TEMPLATE,
162 g_param_spec_object ("template", "Template",
163 "The GstPadTemplate of this pad", GST_TYPE_PAD_TEMPLATE,
164 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
166 #ifndef GST_DISABLE_LOADSAVE
167 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
169 gstobject_class->path_string_separator = ".";
173 gst_pad_init (GstPad * pad)
175 pad->direction = GST_PAD_UNKNOWN;
178 pad->chainfunc = NULL;
182 pad->linkfunc = NULL;
183 pad->getcapsfunc = NULL;
185 pad->activatefunc = gst_pad_activate_default;
186 pad->eventfunc = gst_pad_event_default;
187 pad->querytypefunc = gst_pad_get_query_types_default;
188 pad->queryfunc = gst_pad_query_default;
189 pad->intlinkfunc = gst_pad_get_internal_links_default;
191 GST_PAD_UNSET_FLUSHING (pad);
193 pad->preroll_lock = g_mutex_new ();
194 pad->preroll_cond = g_cond_new ();
196 pad->stream_rec_lock = g_new (GStaticRecMutex, 1);
197 g_static_rec_mutex_init (pad->stream_rec_lock);
199 pad->block_cond = g_cond_new ();
203 gst_pad_dispose (GObject * object)
205 GstPad *pad = GST_PAD (object);
207 gst_pad_set_pad_template (pad, NULL);
208 /* FIXME, we have links to many other things like caps
209 * and the peer pad... */
211 /* No linked pad can ever be disposed.
212 * It has to have a parent to be linked
213 * and a parent would hold a reference */
214 /* FIXME: what about if g_object_dispose is explicitly called on the pad? Is
215 that legal? otherwise we could assert GST_OBJECT_PARENT (pad) == NULL as
217 g_assert (GST_PAD_PEER (pad) == NULL);
219 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s",
220 GST_DEBUG_PAD_NAME (pad));
223 gst_caps_replace (&GST_PAD_CAPS (pad), NULL);
225 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
226 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
227 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
229 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
232 G_OBJECT_CLASS (pad_parent_class)->dispose (object);
236 gst_pad_finalize (GObject * object)
238 GstPad *pad = GST_PAD (object);
240 if (pad->stream_rec_lock) {
241 g_static_rec_mutex_free (pad->stream_rec_lock);
242 pad->stream_rec_lock = NULL;
244 if (pad->preroll_lock) {
245 g_mutex_free (pad->preroll_lock);
246 g_cond_free (pad->preroll_cond);
247 pad->preroll_lock = NULL;
248 pad->preroll_cond = NULL;
250 if (pad->block_cond) {
251 g_cond_free (pad->block_cond);
252 pad->block_cond = NULL;
255 G_OBJECT_CLASS (pad_parent_class)->finalize (object);
259 gst_pad_set_property (GObject * object, guint prop_id,
260 const GValue * value, GParamSpec * pspec)
262 g_return_if_fail (GST_IS_PAD (object));
265 case PAD_PROP_DIRECTION:
266 GST_PAD_DIRECTION (object) = g_value_get_enum (value);
268 case PAD_PROP_TEMPLATE:
269 gst_pad_set_pad_template (GST_PAD_CAST (object),
270 (GstPadTemplate *) g_value_dup_object (value));
273 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
279 gst_pad_get_property (GObject * object, guint prop_id,
280 GValue * value, GParamSpec * pspec)
282 g_return_if_fail (GST_IS_PAD (object));
286 g_value_set_boxed (value, GST_PAD_CAPS (object));
288 case PAD_PROP_DIRECTION:
289 g_value_set_enum (value, GST_PAD_DIRECTION (object));
291 case PAD_PROP_TEMPLATE:
292 g_value_set_object (value, GST_PAD_TEMPLATE (object));
295 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
302 * @name: the name of the new pad.
303 * @direction: the #GstPadDirection of the pad.
305 * Creates a new pad with the given name in the given direction.
306 * If name is NULL, a guaranteed unique name (across all pads)
308 * This function makes a copy of the name so you can safely free the name.
310 * Returns: a new #GstPad, or NULL in case of an error.
315 gst_pad_new (const gchar * name, GstPadDirection direction)
317 return g_object_new (GST_TYPE_PAD,
318 "name", name, "direction", direction, NULL);
322 * gst_pad_new_from_template:
323 * @templ: the pad template to use
324 * @name: the name of the element
326 * Creates a new pad with the given name from the given template.
327 * If name is NULL, a guaranteed unique name (across all pads)
329 * This function makes a copy of the name so you can safely free the name.
331 * Returns: a new #GstPad, or NULL in case of an error.
334 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
336 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
338 return g_object_new (GST_TYPE_PAD,
339 "name", name, "direction", templ->direction, "template", templ, NULL);
343 * gst_pad_get_parent:
346 * Gets the parent of @pad, cast to a #GstElement. If a @pad has no parent or
347 * its parent is not an element, return NULL.
349 * Returns: The parent of the pad. The caller has a reference on the parent, so
350 * unref when you're finished with it.
355 gst_pad_get_parent (GstPad * pad)
359 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
361 p = gst_object_get_parent (GST_OBJECT_CAST (pad));
363 if (p && !GST_IS_ELEMENT (p)) {
364 gst_object_unref (p);
368 return GST_ELEMENT_CAST (p);
372 * gst_pad_get_direction:
373 * @pad: a #GstPad to get the direction of.
375 * Gets the direction of the pad. The direction of the pad is
376 * decided at construction time so this function does not take
379 * Returns: the #GstPadDirection of the pad.
384 gst_pad_get_direction (GstPad * pad)
386 GstPadDirection result;
388 /* PAD_UNKNOWN is a little silly but we need some sort of
389 * error return value */
390 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
393 result = GST_PAD_DIRECTION (pad);
400 gst_pad_activate_default (GstPad * pad)
402 return gst_pad_activate_push (pad, TRUE);
406 pre_activate_switch (GstPad * pad, gboolean new_active)
412 GST_PAD_SET_FLUSHING (pad);
413 /* unlock blocked pads so element can resume and stop */
414 GST_PAD_BLOCK_SIGNAL (pad);
420 post_activate_switch (GstPad * pad, gboolean new_active)
424 GST_PAD_UNSET_FLUSHING (pad);
427 /* make streaming stop */
428 GST_STREAM_LOCK (pad);
429 GST_STREAM_UNLOCK (pad);
434 * gst_pad_set_active:
435 * @pad: the #GstPad to activate or deactivate.
436 * @active: whether or not the pad should be active.
438 * Activates or deactivates the given pad. Must be called with the STATE_LOCK.
439 * Normally called from within core state change functions.
441 * If @active, makes sure the pad is active. If it is already active, either in
442 * push or pull mode, just return. Otherwise dispatches to the pad's activate
443 * function to perform the actual activation.
445 * If not @active, checks the pad's current mode and calls
446 * gst_pad_activate_push() or gst_pad_activate_pull(), as appropriate, with a
449 * Returns: TRUE if the operation was successfull.
451 * MT safe. Must be called with STATE_LOCK.
454 gst_pad_set_active (GstPad * pad, gboolean active)
457 gboolean ret = FALSE;
459 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
462 old = GST_PAD_ACTIVATE_MODE (pad);
467 case GST_ACTIVATE_PUSH:
468 case GST_ACTIVATE_PULL:
471 case GST_ACTIVATE_NONE:
472 ret = (GST_PAD_ACTIVATEFUNC (pad)) (pad);
477 case GST_ACTIVATE_PUSH:
478 ret = gst_pad_activate_push (pad, FALSE);
480 case GST_ACTIVATE_PULL:
481 ret = gst_pad_activate_pull (pad, FALSE);
483 case GST_ACTIVATE_NONE:
493 * gst_pad_activate_pull:
494 * @pad: the #GstPad to activate or deactivate.
495 * @active: whether or not the pad should be active.
497 * Activates or deactivates the given pad in pull mode via dispatching to the
498 * pad's activatepullfunc. For use from within pad activation functions only.
499 * When called on sink pads, will first proxy the call to the peer pad, which is
500 * expected to activate its internally linked pads from within its activate_pull
503 * If you don't know what this is, you probably don't want to call it.
505 * Returns: TRUE if the operation was successfull.
510 gst_pad_activate_pull (GstPad * pad, gboolean active)
514 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
517 old = GST_PAD_ACTIVATE_MODE (pad);
520 if ((active && old == GST_ACTIVATE_PULL)
521 || (!active && old == GST_ACTIVATE_NONE))
525 g_return_val_if_fail (old == GST_ACTIVATE_NONE, FALSE);
527 g_return_val_if_fail (old == GST_ACTIVATE_PULL, FALSE);
530 if (gst_pad_get_direction (pad) == GST_PAD_SINK) {
531 GstPad *peer = gst_pad_get_peer (pad);
534 if (!gst_pad_activate_pull (peer, active)) {
536 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad,
537 "activate_pull on peer (%s:%s) failed", GST_DEBUG_PAD_NAME (peer));
539 gst_object_unref (peer);
545 pre_activate_switch (pad, active);
547 if (GST_PAD_ACTIVATEPULLFUNC (pad)) {
548 if (GST_PAD_ACTIVATEPULLFUNC (pad) (pad, active)) {
554 /* can happen for sinks of passthrough elements */
560 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in pull mode",
561 active ? "activated" : "deactivated");
568 GST_PAD_ACTIVATE_MODE (pad) =
569 active ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE;
571 post_activate_switch (pad, active);
573 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in pull mode",
574 active ? "activated" : "deactivated");
580 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in pull mode",
581 active ? "activate" : "deactivate");
587 * gst_pad_activate_push:
588 * @pad: the #GstPad to activate or deactivate.
589 * @active: whether or not the pad should be active.
591 * Activates or deactivates the given pad in push mode via dispatching to the
592 * pad's activatepushfunc. For use from within pad activation functions only.
594 * If you don't know what this is, you probably don't want to call it.
596 * Returns: TRUE if the operation was successfull.
601 gst_pad_activate_push (GstPad * pad, gboolean active)
605 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
608 old = GST_PAD_ACTIVATE_MODE (pad);
611 if ((active && old == GST_ACTIVATE_PUSH)
612 || (!active && old == GST_ACTIVATE_NONE))
616 g_return_val_if_fail (old == GST_ACTIVATE_NONE, FALSE);
618 g_return_val_if_fail (old == GST_ACTIVATE_PUSH, FALSE);
621 pre_activate_switch (pad, active);
623 if (GST_PAD_ACTIVATEPUSHFUNC (pad)) {
624 if (GST_PAD_ACTIVATEPUSHFUNC (pad) (pad, active)) {
630 /* quite ok, element relies on state change func to prepare itself */
636 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "already %s in push mode",
637 active ? "activated" : "deactivated");
644 GST_PAD_ACTIVATE_MODE (pad) =
645 active ? GST_ACTIVATE_PUSH : GST_ACTIVATE_NONE;
647 post_activate_switch (pad, active);
649 GST_CAT_DEBUG_OBJECT (GST_CAT_PADS, pad, "%s in push mode",
650 active ? "activated" : "deactivated");
656 GST_CAT_INFO_OBJECT (GST_CAT_PADS, pad, "failed to %s in push mode",
657 active ? "activate" : "deactivate");
664 * @pad: the #GstPad to query
666 * Query if a pad is active
668 * Returns: TRUE if the pad is active.
673 gst_pad_is_active (GstPad * pad)
675 gboolean result = FALSE;
677 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
680 result = GST_PAD_MODE_ACTIVATE (GST_PAD_ACTIVATE_MODE (pad));
687 * gst_pad_set_blocked_async:
688 * @pad: the #GstPad to block or unblock
689 * @blocked: boolean indicating we should block or unblock
690 * @callback: #GstPadBlockCallback that will be called when the
691 * operation succeeds.
692 * @user_data: user data passed to the callback
694 * Blocks or unblocks the dataflow on a pad. The provided callback
695 * is called when the operation succeeds. This can take a while as
696 * the pad can only become blocked when real dataflow is happening.
697 * When the pipeline is stalled, for example in PAUSED, this can
698 * take an indeterminate amount of time.
699 * You can pass NULL as the callback to make this call block. Be
700 * carefull with this blocking call as it might not return for
701 * reasons stated above.
703 * Returns: TRUE if the pad could be blocked. This function can fail
704 * if wrong parameters were passed or the pad was already in the
710 gst_pad_set_blocked_async (GstPad * pad, gboolean blocked,
711 GstPadBlockCallback callback, gpointer user_data)
713 gboolean was_blocked;
715 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
719 was_blocked = GST_PAD_IS_BLOCKED (pad);
721 if (G_UNLIKELY (was_blocked == blocked))
722 goto had_right_state;
725 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocking pad %s:%s",
726 GST_DEBUG_PAD_NAME (pad));
728 GST_FLAG_SET (pad, GST_PAD_BLOCKED);
729 pad->block_callback = callback;
730 pad->block_data = user_data;
732 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for block");
733 GST_PAD_BLOCK_WAIT (pad);
734 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "blocked");
737 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocking pad %s:%s",
738 GST_DEBUG_PAD_NAME (pad));
740 GST_FLAG_UNSET (pad, GST_PAD_BLOCKED);
742 pad->block_callback = callback;
743 pad->block_data = user_data;
746 GST_PAD_BLOCK_SIGNAL (pad);
748 GST_PAD_BLOCK_SIGNAL (pad);
749 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "waiting for unblock");
750 GST_PAD_BLOCK_WAIT (pad);
751 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "unblocked");
760 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
761 "pad %s:%s was in right state", GST_DEBUG_PAD_NAME (pad));
768 * gst_pad_set_blocked:
769 * @pad: the #GstPad to block or unblock
770 * @blocked: boolean indicating we should block or unblock
772 * Blocks or unblocks the dataflow on a pad. This function is
773 * a shortcut for @gst_pad_set_blocked_async() with a NULL
776 * Returns: TRUE if the pad could be blocked. This function can fail
777 * wrong parameters were passed or the pad was already in the
783 gst_pad_set_blocked (GstPad * pad, gboolean blocked)
785 return gst_pad_set_blocked_async (pad, blocked, NULL, NULL);
789 * gst_pad_is_blocked:
790 * @pad: the #GstPad to query
792 * Checks if the pad is blocked or not. This function returns the
793 * last requested state of the pad. It is not certain that the pad
794 * is actually blocked at this point.
796 * Returns: TRUE if the pad is blocked.
801 gst_pad_is_blocked (GstPad * pad)
803 gboolean result = FALSE;
805 g_return_val_if_fail (GST_IS_PAD (pad), result);
808 result = GST_FLAG_IS_SET (pad, GST_PAD_BLOCKED);
815 * gst_pad_set_activate_function:
816 * @pad: a sink #GstPad.
817 * @chain: the #GstPadActivateFunction to set.
819 * Sets the given activate function for the pad. The activate function will
820 * dispatch to activate_push or activate_pull to perform the actual activation.
821 * Only makes sense to set on sink pads.
823 * Call this function if your sink pad can start a pull-based task.
826 gst_pad_set_activate_function (GstPad * pad, GstPadActivateFunction activate)
828 g_return_if_fail (GST_IS_PAD (pad));
830 GST_PAD_ACTIVATEFUNC (pad) = activate;
831 GST_CAT_DEBUG (GST_CAT_PADS, "activatefunc for %s:%s set to %s",
832 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activate));
836 * gst_pad_set_activatepull_function:
837 * @pad: a sink #GstPad.
838 * @chain: the #GstPadActivateModeFunction to set.
840 * Sets the given activate_pull function for the pad. An activate_pull function
841 * prepares the element and any upstream connections for pulling. See XXX
842 * part-activation.txt for details.
845 gst_pad_set_activatepull_function (GstPad * pad,
846 GstPadActivateModeFunction activatepull)
848 g_return_if_fail (GST_IS_PAD (pad));
850 GST_PAD_ACTIVATEPULLFUNC (pad) = activatepull;
851 GST_CAT_DEBUG (GST_CAT_PADS, "activatepullfunc for %s:%s set to %s",
852 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activatepull));
856 * gst_pad_set_activatepush_function:
857 * @pad: a sink #GstPad.
858 * @chain: the #GstPadActivateModeFunction to set.
860 * Sets the given activate_push function for the pad. An activate_push function
861 * prepares the element for pushing. See XXX part-activation.txt for details.
864 gst_pad_set_activatepush_function (GstPad * pad,
865 GstPadActivateModeFunction activatepush)
867 g_return_if_fail (GST_IS_PAD (pad));
869 GST_PAD_ACTIVATEPUSHFUNC (pad) = activatepush;
870 GST_CAT_DEBUG (GST_CAT_PADS, "activatepushfunc for %s:%s set to %s",
871 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (activatepush));
875 * gst_pad_set_loop_function:
876 * @pad: a sink #GstPad.
877 * @chain: the #GstPadLoopFunction to set.
879 * Sets the given loop function for the pad. The loop function is called
880 * repeadedly to pull/push buffers from/to the peer pad.
883 gst_pad_set_loop_function (GstPad * pad, GstPadLoopFunction loop)
885 g_return_if_fail (GST_IS_PAD (pad));
887 GST_PAD_LOOPFUNC (pad) = loop;
888 GST_CAT_DEBUG (GST_CAT_PADS, "loopfunc for %s:%s set to %s",
889 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (loop));
893 * gst_pad_set_chain_function:
894 * @pad: a sink #GstPad.
895 * @chain: the #GstPadChainFunction to set.
897 * Sets the given chain function for the pad. The chain function is called to
898 * process a #GstBuffer input buffer.
901 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
903 g_return_if_fail (GST_IS_PAD (pad));
904 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
906 GST_PAD_CHAINFUNC (pad) = chain;
907 GST_CAT_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
908 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
912 * gst_pad_set_getrange_function:
913 * @pad: a source #GstPad.
914 * @get: the #GstPadGetRangeFunction to set.
916 * Sets the given getrange function for the pad. The getrange function is called to
917 * produce a new #GstBuffer to start the processing pipeline. Getrange functions cannot
921 gst_pad_set_getrange_function (GstPad * pad, GstPadGetRangeFunction get)
923 g_return_if_fail (GST_IS_PAD (pad));
924 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
926 GST_PAD_GETRANGEFUNC (pad) = get;
928 GST_CAT_DEBUG (GST_CAT_PADS, "getrangefunc for %s:%s set to %s",
929 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
933 * gst_pad_set_checkgetrange_function:
934 * @pad: a source #GstPad.
935 * @check: the #GstPadCheckGetRangeFunction to set.
937 * Sets the given checkgetrange function for the pad. Implement this function on
938 * a pad if you dynamically support getrange based scheduling on the pad.
941 gst_pad_set_checkgetrange_function (GstPad * pad,
942 GstPadCheckGetRangeFunction check)
944 g_return_if_fail (GST_IS_PAD (pad));
945 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
947 GST_PAD_CHECKGETRANGEFUNC (pad) = check;
949 GST_CAT_DEBUG (GST_CAT_PADS, "checkgetrangefunc for %s:%s set to %s",
950 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (check));
954 * gst_pad_set_event_function:
955 * @pad: a source #GstPad.
956 * @event: the #GstPadEventFunction to set.
958 * Sets the given event handler for the pad.
961 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
963 g_return_if_fail (GST_IS_PAD (pad));
965 GST_PAD_EVENTFUNC (pad) = event;
967 GST_CAT_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
968 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
972 * gst_pad_set_query_function:
973 * @pad: a #GstPad of either direction.
974 * @query: the #GstPadQueryFunction to set.
976 * Set the given query function for the pad.
979 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
981 g_return_if_fail (GST_IS_PAD (pad));
983 GST_PAD_QUERYFUNC (pad) = query;
985 GST_CAT_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
986 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
990 * gst_pad_set_query_type_function:
991 * @pad: a #GstPad of either direction.
992 * @type_func: the #GstPadQueryTypeFunction to set.
994 * Set the given query type function for the pad.
997 gst_pad_set_query_type_function (GstPad * pad,
998 GstPadQueryTypeFunction type_func)
1000 g_return_if_fail (GST_IS_PAD (pad));
1002 GST_PAD_QUERYTYPEFUNC (pad) = type_func;
1004 GST_CAT_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
1005 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
1009 * gst_pad_get_query_types:
1012 * Get an array of supported queries that can be performed
1015 * Returns: a zero-terminated array of #GstQueryType.
1017 const GstQueryType *
1018 gst_pad_get_query_types (GstPad * pad)
1020 GstPadQueryTypeFunction func;
1022 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1024 if (G_UNLIKELY ((func = GST_PAD_QUERYTYPEFUNC (pad)) == NULL))
1036 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
1038 *data = gst_pad_get_query_types (pad);
1044 * gst_pad_get_query_types_default:
1047 * Invoke the default dispatcher for the query types on
1050 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
1051 * internally-linked pads has a query types function.
1053 const GstQueryType *
1054 gst_pad_get_query_types_default (GstPad * pad)
1056 GstQueryType *result = NULL;
1058 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1060 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
1061 gst_pad_get_query_types_dispatcher, &result);
1067 * gst_pad_set_internal_link_function:
1068 * @pad: a #GstPad of either direction.
1069 * @intlink: the #GstPadIntLinkFunction to set.
1071 * Sets the given internal link function for the pad.
1074 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
1076 g_return_if_fail (GST_IS_PAD (pad));
1078 GST_PAD_INTLINKFUNC (pad) = intlink;
1079 GST_CAT_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
1080 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
1084 * gst_pad_set_link_function:
1086 * @link: the #GstPadLinkFunction to set.
1088 * Sets the given link function for the pad. It will be called when the pad is
1089 * linked or relinked with caps. The caps passed to the link function is
1090 * the caps for the connnection. It can contain a non fixed caps.
1092 * The return value GST_PAD_LINK_OK should be used when the connection can be
1095 * The return value GST_PAD_LINK_REFUSED should be used when the connection
1096 * cannot be made for some reason.
1099 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
1101 g_return_if_fail (GST_IS_PAD (pad));
1103 GST_PAD_LINKFUNC (pad) = link;
1104 GST_CAT_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
1105 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
1109 * gst_pad_set_unlink_function:
1111 * @unlink: the #GstPadUnlinkFunction to set.
1113 * Sets the given unlink function for the pad. It will be called
1114 * when the pad is unlinked.
1117 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
1119 g_return_if_fail (GST_IS_PAD (pad));
1121 GST_PAD_UNLINKFUNC (pad) = unlink;
1122 GST_CAT_DEBUG (GST_CAT_PADS, "unlinkfunc for %s:%s set to %s",
1123 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (unlink));
1127 * gst_pad_set_getcaps_function:
1129 * @getcaps: the #GstPadGetCapsFunction to set.
1131 * Sets the given getcaps function for the pad. @getcaps should return the
1132 * allowable caps for a pad in the context of the element's state, its link to
1133 * other elements, and the devices or files it has opened. These caps must be a
1134 * subset of the pad template caps. In the NULL state with no links, @getcaps
1135 * should ideally return the same caps as the pad template. In rare
1136 * circumstances, an object property can affect the caps returned by @getcaps,
1137 * but this is discouraged.
1139 * You do not need to call this function if @pad's allowed caps are always the
1140 * same as the pad template caps. This can only be true if the padtemplate
1141 * has fixed simple caps.
1143 * For most filters, the caps returned by @getcaps is directly affected by the
1144 * allowed caps on other pads. For demuxers and decoders, the caps returned by
1145 * the srcpad's getcaps function is directly related to the stream data. Again,
1146 * @getcaps should return the most specific caps it reasonably can, since this
1147 * helps with autoplugging.
1149 * Note that the return value from @getcaps is owned by the caller, so the caller
1150 * should unref the caps after usage.
1153 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
1155 g_return_if_fail (GST_IS_PAD (pad));
1157 GST_PAD_GETCAPSFUNC (pad) = getcaps;
1158 GST_CAT_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
1159 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
1163 * gst_pad_set_acceptcaps_function:
1165 * @acceptcaps: the #GstPadAcceptCapsFunction to set.
1167 * Sets the given acceptcaps function for the pad. The acceptcaps function
1168 * will be called to check if the pad can accept the given caps.
1171 gst_pad_set_acceptcaps_function (GstPad * pad,
1172 GstPadAcceptCapsFunction acceptcaps)
1174 g_return_if_fail (GST_IS_PAD (pad));
1176 GST_PAD_ACCEPTCAPSFUNC (pad) = acceptcaps;
1177 GST_CAT_DEBUG (GST_CAT_PADS, "acceptcapsfunc for %s:%s set to %s",
1178 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (acceptcaps));
1182 * gst_pad_set_fixatecaps_function:
1184 * @fixatecaps: the #GstPadFixateCapsFunction to set.
1186 * Sets the given fixatecaps function for the pad. The fixatecaps function
1187 * will be called whenever the default values for a GstCaps needs to be
1191 gst_pad_set_fixatecaps_function (GstPad * pad,
1192 GstPadFixateCapsFunction fixatecaps)
1194 g_return_if_fail (GST_IS_PAD (pad));
1196 GST_PAD_FIXATECAPSFUNC (pad) = fixatecaps;
1197 GST_CAT_DEBUG (GST_CAT_PADS, "fixatecapsfunc for %s:%s set to %s",
1198 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (fixatecaps));
1202 * gst_pad_set_setcaps_function:
1204 * @setcaps: the #GstPadSetCapsFunction to set.
1206 * Sets the given setcaps function for the pad. The setcaps function
1207 * will be called whenever a buffer with a new media type is pushed or
1208 * pulled from the pad. The pad/element needs to update it's internal
1209 * structures to process the new media type. If this new type is not
1210 * acceptable, the setcaps function should return FALSE.
1213 gst_pad_set_setcaps_function (GstPad * pad, GstPadSetCapsFunction setcaps)
1215 g_return_if_fail (GST_IS_PAD (pad));
1217 GST_PAD_SETCAPSFUNC (pad) = setcaps;
1218 GST_CAT_DEBUG (GST_CAT_PADS, "setcapsfunc for %s:%s set to %s",
1219 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (setcaps));
1223 * gst_pad_set_bufferalloc_function:
1224 * @pad: a sink #GstPad.
1225 * @bufalloc: the #GstPadBufferAllocFunction to set.
1227 * Sets the given bufferalloc function for the pad. Note that the
1228 * bufferalloc function can only be set on sinkpads.
1231 gst_pad_set_bufferalloc_function (GstPad * pad,
1232 GstPadBufferAllocFunction bufalloc)
1234 g_return_if_fail (GST_IS_PAD (pad));
1235 g_return_if_fail (GST_PAD_IS_SINK (pad));
1237 GST_PAD_BUFFERALLOCFUNC (pad) = bufalloc;
1238 GST_CAT_DEBUG (GST_CAT_PADS, "bufferallocfunc for %s:%s set to %s",
1239 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufalloc));
1244 * @srcpad: the source #GstPad to unlink.
1245 * @sinkpad: the sink #GstPad to unlink.
1247 * Unlinks the source pad from the sink pad. Will emit the "unlinked" signal on
1250 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1251 * the pads were not linked together.
1256 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1258 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1259 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1261 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1262 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1263 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1267 if (G_UNLIKELY (GST_PAD_DIRECTION (srcpad) != GST_PAD_SRC))
1272 if (G_UNLIKELY (GST_PAD_DIRECTION (sinkpad) != GST_PAD_SINK))
1275 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1276 goto not_linked_together;
1278 if (GST_PAD_UNLINKFUNC (srcpad)) {
1279 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1281 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1282 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1285 /* first clear peers */
1286 GST_PAD_PEER (srcpad) = NULL;
1287 GST_PAD_PEER (sinkpad) = NULL;
1289 GST_UNLOCK (sinkpad);
1290 GST_UNLOCK (srcpad);
1292 /* fire off a signal to each of the pads telling them
1293 * that they've been unlinked */
1294 g_signal_emit (G_OBJECT (srcpad), gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1295 g_signal_emit (G_OBJECT (sinkpad), gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1297 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1298 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1304 g_critical ("pad %s is not a source pad", GST_PAD_NAME (srcpad));
1305 GST_UNLOCK (srcpad);
1310 g_critical ("pad %s is not a sink pad", GST_PAD_NAME (sinkpad));
1311 GST_UNLOCK (sinkpad);
1312 GST_UNLOCK (srcpad);
1315 not_linked_together:
1317 /* we do not emit a warning in this case because unlinking cannot
1318 * be made MT safe.*/
1319 GST_UNLOCK (sinkpad);
1320 GST_UNLOCK (srcpad);
1326 * gst_pad_is_linked:
1327 * @pad: pad to check
1329 * Checks if a @pad is linked to another pad or not.
1331 * Returns: TRUE if the pad is linked, FALSE otherwise.
1336 gst_pad_is_linked (GstPad * pad)
1340 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1343 result = (GST_PAD_PEER (pad) != NULL);
1350 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink)
1355 srccaps = gst_pad_get_caps_unlocked (src);
1356 sinkcaps = gst_pad_get_caps_unlocked (sink);
1357 GST_CAT_DEBUG (GST_CAT_CAPS, "got caps %p and %p", srccaps, sinkcaps);
1359 if (srccaps && sinkcaps) {
1362 icaps = gst_caps_intersect (srccaps, sinkcaps);
1363 gst_caps_unref (srccaps);
1364 gst_caps_unref (sinkcaps);
1366 GST_CAT_DEBUG (GST_CAT_CAPS,
1367 "intersection caps %p %" GST_PTR_FORMAT, icaps, icaps);
1369 if (!icaps || gst_caps_is_empty (icaps))
1377 /* FIXME leftover from an attempt at refactoring... */
1378 /* call with the two pads unlocked */
1379 static GstPadLinkReturn
1380 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad)
1382 /* generic checks */
1383 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
1384 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
1386 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1387 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1391 if (G_UNLIKELY (GST_PAD_DIRECTION (srcpad) != GST_PAD_SRC))
1394 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1395 goto src_was_linked;
1399 if (G_UNLIKELY (GST_PAD_DIRECTION (sinkpad) != GST_PAD_SINK))
1402 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1403 goto sink_was_linked;
1405 /* check pad caps for non-empty intersection */
1406 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad)) {
1410 /* FIXME check pad scheduling for non-empty intersection */
1412 return GST_PAD_LINK_OK;
1416 g_critical ("pad %s is not a source pad", GST_PAD_NAME (srcpad));
1417 GST_UNLOCK (srcpad);
1418 return GST_PAD_LINK_WRONG_DIRECTION;
1422 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was linked",
1423 GST_DEBUG_PAD_NAME (srcpad));
1424 /* we do not emit a warning in this case because unlinking cannot
1425 * be made MT safe.*/
1426 GST_UNLOCK (srcpad);
1427 return GST_PAD_LINK_WAS_LINKED;
1431 g_critical ("pad %s is not a sink pad", GST_PAD_NAME (sinkpad));
1432 GST_UNLOCK (sinkpad);
1433 GST_UNLOCK (srcpad);
1434 return GST_PAD_LINK_WRONG_DIRECTION;
1438 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was linked",
1439 GST_DEBUG_PAD_NAME (sinkpad));
1440 /* we do not emit a warning in this case because unlinking cannot
1441 * be made MT safe.*/
1442 GST_UNLOCK (sinkpad);
1443 GST_UNLOCK (srcpad);
1444 return GST_PAD_LINK_WAS_LINKED;
1448 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1449 GST_UNLOCK (sinkpad);
1450 GST_UNLOCK (srcpad);
1451 return GST_PAD_LINK_NOFORMAT;
1457 * @srcpad: the source #GstPad to link.
1458 * @sinkpad: the sink #GstPad to link.
1460 * Links the source pad and the sink pad.
1462 * Returns: A result code indicating if the connection worked or
1468 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
1470 GstPadLinkReturn result;
1472 /* prepare will also lock the two pads */
1473 result = gst_pad_link_prepare (srcpad, sinkpad);
1475 if (result != GST_PAD_LINK_OK)
1476 goto prepare_failed;
1478 GST_UNLOCK (sinkpad);
1479 GST_UNLOCK (srcpad);
1481 /* FIXME released the locks here, concurrent thread might link
1482 * something else. */
1483 if (GST_PAD_LINKFUNC (srcpad)) {
1484 /* this one will call the peer link function */
1485 result = GST_PAD_LINKFUNC (srcpad) (srcpad, sinkpad);
1486 } else if (GST_PAD_LINKFUNC (sinkpad)) {
1487 /* if no source link function, we need to call the sink link
1488 * function ourselves. */
1489 result = GST_PAD_LINKFUNC (sinkpad) (sinkpad, srcpad);
1491 result = GST_PAD_LINK_OK;
1497 if (result == GST_PAD_LINK_OK) {
1498 GST_PAD_PEER (srcpad) = sinkpad;
1499 GST_PAD_PEER (sinkpad) = srcpad;
1501 GST_UNLOCK (sinkpad);
1502 GST_UNLOCK (srcpad);
1504 /* fire off a signal to each of the pads telling them
1505 * that they've been linked */
1506 g_signal_emit (G_OBJECT (srcpad), gst_pad_signals[PAD_LINKED], 0, sinkpad);
1507 g_signal_emit (G_OBJECT (sinkpad), gst_pad_signals[PAD_LINKED], 0, srcpad);
1509 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1510 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1512 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
1513 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1515 GST_UNLOCK (sinkpad);
1516 GST_UNLOCK (srcpad);
1527 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
1529 /* this function would need checks if it weren't static */
1532 gst_object_replace ((GstObject **) & pad->padtemplate, (GstObject *) templ);
1536 gst_object_sink (GST_OBJECT (templ));
1537 g_signal_emit (G_OBJECT (templ),
1538 gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
1543 * gst_pad_get_pad_template:
1546 * Gets the template for @pad.
1548 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
1549 * if this pad has no template.
1551 * FIXME: currently returns an unrefcounted padtemplate.
1554 gst_pad_get_pad_template (GstPad * pad)
1556 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1558 return GST_PAD_PAD_TEMPLATE (pad);
1562 /* should be called with the pad LOCK held */
1563 /* refs the caps, so caller is responsible for getting it unreffed */
1565 gst_pad_get_caps_unlocked (GstPad * pad)
1567 GstCaps *result = NULL;
1569 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1570 GST_DEBUG_PAD_NAME (pad), pad);
1572 if (GST_PAD_GETCAPSFUNC (pad)) {
1573 GST_CAT_DEBUG (GST_CAT_CAPS, "dispatching to pad getcaps function");
1575 GST_FLAG_SET (pad, GST_PAD_IN_GETCAPS);
1577 result = GST_PAD_GETCAPSFUNC (pad) (pad);
1579 GST_FLAG_UNSET (pad, GST_PAD_IN_GETCAPS);
1581 if (result == NULL) {
1582 g_critical ("pad %s:%s returned NULL caps from getcaps function",
1583 GST_DEBUG_PAD_NAME (pad));
1585 #ifndef G_DISABLE_ASSERT
1586 /* check that the returned caps are a real subset of the template caps */
1587 if (GST_PAD_PAD_TEMPLATE (pad)) {
1588 const GstCaps *templ_caps =
1589 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
1590 if (!gst_caps_is_subset (result, templ_caps)) {
1593 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
1594 "pad returned caps %" GST_PTR_FORMAT
1595 " which are not a real subset of its template caps %"
1596 GST_PTR_FORMAT, result, templ_caps);
1598 ("pad %s:%s returned caps that are not a real subset of its template caps",
1599 GST_DEBUG_PAD_NAME (pad));
1600 temp = gst_caps_intersect (templ_caps, result);
1601 gst_caps_unref (result);
1609 if (GST_PAD_PAD_TEMPLATE (pad)) {
1610 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
1612 result = GST_PAD_TEMPLATE_CAPS (templ);
1613 GST_CAT_DEBUG (GST_CAT_CAPS,
1614 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
1617 result = gst_caps_ref (result);
1620 if (GST_PAD_CAPS (pad)) {
1621 result = GST_PAD_CAPS (pad);
1623 GST_CAT_DEBUG (GST_CAT_CAPS,
1624 "using pad caps %p %" GST_PTR_FORMAT, result, result);
1626 result = gst_caps_ref (result);
1630 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
1631 result = gst_caps_new_empty ();
1639 * @pad: a #GstPad to get the capabilities of.
1641 * Gets the capabilities of this pad.
1643 * Returns: the #GstCaps of this pad. This function returns a new caps, so use
1644 * gst_caps_unref to get rid of it.
1649 gst_pad_get_caps (GstPad * pad)
1651 GstCaps *result = NULL;
1653 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1657 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1658 GST_DEBUG_PAD_NAME (pad), pad);
1660 if (G_UNLIKELY (GST_PAD_IS_IN_GETCAPS (pad)))
1661 goto was_dispatching;
1663 result = gst_pad_get_caps_unlocked (pad);
1670 GST_CAT_DEBUG (GST_CAT_CAPS,
1671 "pad %s:%s is already dispatching!", GST_DEBUG_PAD_NAME (pad));
1672 g_warning ("pad %s:%s recursively called getcaps!",
1673 GST_DEBUG_PAD_NAME (pad));
1680 * gst_pad_peer_get_caps:
1681 * @pad: a #GstPad to get the peer capabilities of.
1683 * Gets the capabilities of the peer connected to this pad.
1685 * Returns: the #GstCaps of the peer pad. This function returns a new caps, so use
1686 * gst_caps_unref to get rid of it. this function returns NULL if there is no
1687 * peer pad or when this function is called recursively from a getcaps function.
1690 gst_pad_peer_get_caps (GstPad * pad)
1693 GstCaps *result = NULL;
1695 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1699 GST_CAT_DEBUG (GST_CAT_CAPS, "get peer caps of %s:%s (%p)",
1700 GST_DEBUG_PAD_NAME (pad), pad);
1702 peerpad = GST_PAD_PEER (pad);
1703 if (G_UNLIKELY (peerpad == NULL))
1706 if (G_UNLIKELY (GST_PAD_IS_IN_GETCAPS (peerpad)))
1707 goto was_dispatching;
1709 gst_object_ref (peerpad);
1712 result = gst_pad_get_caps (peerpad);
1714 gst_object_unref (peerpad);
1725 GST_CAT_DEBUG (GST_CAT_CAPS,
1726 "pad %s:%s is already dispatching!", GST_DEBUG_PAD_NAME (pad));
1727 g_warning ("pad %s:%s recursively called getcaps!",
1728 GST_DEBUG_PAD_NAME (pad));
1735 * gst_pad_fixate_caps:
1736 * @pad: a #GstPad to fixate
1738 * Fixate a caps on the given pad.
1740 * Returns: a fixated #GstCaps.
1743 gst_pad_fixate_caps (GstPad * pad, GstCaps * caps)
1745 /* FIXME, implement me, call the fixate function for the pad */
1750 * gst_pad_accept_caps:
1751 * @pad: a #GstPad to check
1753 * Check if the given pad accepts the caps.
1755 * Returns: TRUE if the pad can accept the caps.
1758 gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
1762 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1766 GST_CAT_DEBUG (GST_CAT_CAPS, "pad accept caps of %s:%s (%p)",
1767 GST_DEBUG_PAD_NAME (pad), pad);
1769 if (GST_PAD_ACCEPTCAPSFUNC (pad)) {
1770 /* we can call the function */
1771 result = GST_PAD_ACCEPTCAPSFUNC (pad) (pad, caps);
1773 /* else see get the caps and see if it intersects to something
1778 allowed = gst_pad_get_caps_unlocked (pad);
1779 intersect = gst_caps_intersect (allowed, caps);
1780 if (gst_caps_is_empty (intersect))
1791 * gst_pad_peer_accept_caps:
1792 * @pad: a #GstPad to check
1794 * Check if the given pad accepts the caps.
1796 * Returns: TRUE if the pad can accept the caps.
1799 gst_pad_peer_accept_caps (GstPad * pad, GstCaps * caps)
1804 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1808 GST_CAT_DEBUG (GST_CAT_CAPS, "peer accept caps of %s:%s (%p)",
1809 GST_DEBUG_PAD_NAME (pad), pad);
1811 peerpad = GST_PAD_PEER (pad);
1812 if (G_UNLIKELY (peerpad == NULL))
1815 result = gst_pad_accept_caps (peerpad, caps);
1829 * @pad: a #GstPad to set the capabilities of.
1830 * @caps: a #GstCaps to set.
1832 * Sets the capabilities of this pad. The caps must be fixed. Any previous
1833 * caps on the pad will be unreffed. This function refs the caps so you should
1834 * unref if as soon as you don't need it anymore.
1835 * It is possible to set NULL caps, which will make the pad unnegotiated
1838 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
1839 * or bad parameters were provided to this function.
1844 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
1846 GstPadSetCapsFunction setcaps;
1848 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1851 setcaps = GST_PAD_SETCAPSFUNC (pad);
1853 /* call setcaps function to configure the pad */
1854 if (setcaps != NULL) {
1855 if (!GST_PAD_IS_IN_SETCAPS (pad)) {
1856 GST_FLAG_SET (pad, GST_PAD_IN_SETCAPS);
1858 if (!setcaps (pad, caps))
1861 GST_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
1863 GST_CAT_DEBUG (GST_CAT_CAPS, "pad %s:%s was dispatching",
1864 GST_DEBUG_PAD_NAME (pad));
1868 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
1869 GST_CAT_DEBUG (GST_CAT_CAPS, "%s:%s caps %" GST_PTR_FORMAT,
1870 GST_DEBUG_PAD_NAME (pad), caps);
1873 g_object_notify (G_OBJECT (pad), "caps");
1880 GST_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
1882 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " could not be set",
1889 gst_pad_configure_sink (GstPad * pad, GstCaps * caps)
1891 GstPadAcceptCapsFunction acceptcaps;
1892 GstPadSetCapsFunction setcaps;
1895 acceptcaps = GST_PAD_ACCEPTCAPSFUNC (pad);
1896 setcaps = GST_PAD_SETCAPSFUNC (pad);
1898 /* See if pad accepts the caps, by calling acceptcaps, only
1899 * needed if no setcaps function */
1900 if (setcaps == NULL && acceptcaps != NULL) {
1901 if (!acceptcaps (pad, caps))
1904 /* set caps on pad if call succeeds */
1905 res = gst_pad_set_caps (pad, caps);
1906 /* no need to unref the caps here, set_caps takes a ref and
1907 * our ref goes away when we leave this function. */
1913 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " not accepted", caps);
1919 gst_pad_configure_src (GstPad * pad, GstCaps * caps)
1921 GstPadAcceptCapsFunction acceptcaps;
1922 GstPadSetCapsFunction setcaps;
1925 acceptcaps = GST_PAD_ACCEPTCAPSFUNC (pad);
1926 setcaps = GST_PAD_SETCAPSFUNC (pad);
1928 /* See if pad accepts the caps, by calling acceptcaps, only
1929 * needed if no setcaps function */
1930 if (setcaps == NULL && acceptcaps != NULL) {
1931 if (!acceptcaps (pad, caps))
1934 /* set caps on pad if call succeeds */
1935 res = gst_pad_set_caps (pad, caps);
1936 /* no need to unref the caps here, set_caps takes a ref and
1937 * our ref goes away when we leave this function. */
1943 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " not accepted", caps);
1949 * gst_pad_get_pad_template_caps:
1950 * @pad: a #GstPad to get the template capabilities from.
1952 * Gets the capabilities for @pad's template.
1954 * Returns: the #GstCaps of this pad template. If you intend to keep a reference
1955 * on the caps, make a copy (see gst_caps_copy ()).
1958 gst_pad_get_pad_template_caps (GstPad * pad)
1960 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
1962 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1964 if (GST_PAD_PAD_TEMPLATE (pad))
1965 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
1967 return gst_static_caps_get (&anycaps);
1973 * @pad: a #GstPad to get the peer of.
1975 * Gets the peer of @pad. This function refs the peer pad so
1976 * you need to unref it after use.
1978 * Returns: the peer #GstPad. Unref after usage.
1983 gst_pad_get_peer (GstPad * pad)
1987 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1990 result = GST_PAD_PEER (pad);
1992 gst_object_ref (result);
1999 * gst_pad_get_allowed_caps:
2000 * @srcpad: a #GstPad, it must a a source pad.
2002 * Gets the capabilities of the allowed media types that can flow through
2003 * @srcpad and its peer. The pad must be a source pad.
2004 * The caller must free the resulting caps.
2006 * Returns: the allowed #GstCaps of the pad link. Free the caps when
2007 * you no longer need it. This function returns NULL when the @srcpad has no
2013 gst_pad_get_allowed_caps (GstPad * srcpad)
2020 g_return_val_if_fail (GST_IS_PAD (srcpad), NULL);
2021 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), NULL);
2025 peer = GST_PAD_PEER (srcpad);
2026 if (G_UNLIKELY (peer == NULL))
2029 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting allowed caps",
2030 GST_DEBUG_PAD_NAME (srcpad));
2032 gst_object_ref (peer);
2033 GST_UNLOCK (srcpad);
2034 mycaps = gst_pad_get_caps (srcpad);
2036 peercaps = gst_pad_get_caps (peer);
2037 gst_object_unref (peer);
2039 caps = gst_caps_intersect (mycaps, peercaps);
2040 gst_caps_unref (peercaps);
2041 gst_caps_unref (mycaps);
2043 GST_CAT_DEBUG (GST_CAT_CAPS, "allowed caps %" GST_PTR_FORMAT, caps);
2049 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer",
2050 GST_DEBUG_PAD_NAME (srcpad));
2051 GST_UNLOCK (srcpad);
2058 * gst_pad_get_negotiated_caps:
2061 * Gets the capabilities of the media type that currently flows through @pad
2064 * This function can be used on both src and sinkpads. Note that srcpads are
2065 * always negotiated before sinkpads so it is possible that the negotiated caps
2066 * on the srcpad do not match the negotiated caps of the peer.
2068 * Returns: the negotiated #GstCaps of the pad link. Free the caps when
2069 * you no longer need it. This function returns NULL when the @pad has no
2070 * peer or is not negotiated yet.
2075 gst_pad_get_negotiated_caps (GstPad * pad)
2080 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2084 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2087 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting negotiated caps",
2088 GST_DEBUG_PAD_NAME (pad));
2090 caps = GST_PAD_CAPS (pad);
2092 gst_caps_ref (caps);
2095 GST_CAT_DEBUG (GST_CAT_CAPS, "negotiated caps %" GST_PTR_FORMAT, caps);
2101 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer",
2102 GST_DEBUG_PAD_NAME (pad));
2110 * gst_pad_alloc_buffer:
2111 * @pad: a source #GstPad
2112 * @offset: the offset of the new buffer in the stream
2113 * @size: the size of the new buffer
2114 * @caps: the caps of the new buffer
2115 * @buf: a newly allocated buffer
2117 * Allocates a new, empty buffer optimized to push to pad @pad. This
2118 * function only works if @pad is a source pad and has a peer.
2120 * You need to check the caps of the buffer after performing this
2121 * function and renegotiate to the format if needed.
2123 * A new, empty #GstBuffer will be put in the @buf argument.
2125 * Returns: a result code indicating success of the operation. Any
2126 * result code other than GST_FLOW_OK is an error and @buf should
2128 * An error can occur if the pad is not connected or when the downstream
2129 * peer elements cannot provide an acceptable buffer.
2134 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size, GstCaps * caps,
2139 GstPadBufferAllocFunction bufferallocfunc;
2140 gboolean caps_changed;
2142 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2143 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
2144 g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
2147 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2150 gst_object_ref (peer);
2153 if (G_LIKELY ((bufferallocfunc = peer->bufferallocfunc) == NULL))
2157 /* when the peer is flushing we cannot give a buffer */
2158 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (peer)))
2161 GST_CAT_DEBUG (GST_CAT_PADS,
2162 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s",
2163 GST_DEBUG_FUNCPTR_NAME (bufferallocfunc),
2164 &bufferallocfunc, GST_DEBUG_PAD_NAME (peer));
2167 ret = bufferallocfunc (peer, offset, size, caps, buf);
2169 if (G_UNLIKELY (ret != GST_FLOW_OK))
2171 if (G_UNLIKELY (*buf == NULL))
2175 gst_object_unref (peer);
2177 /* FIXME, move capnego this into a base class? */
2178 caps = GST_BUFFER_CAPS (*buf);
2179 caps_changed = caps && caps != GST_PAD_CAPS (pad);
2180 /* we got a new datatype on the pad, see if it can handle it */
2181 if (G_UNLIKELY (caps_changed)) {
2182 GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
2183 if (G_UNLIKELY (!gst_pad_configure_src (pad, caps)))
2184 goto not_negotiated;
2190 /* pad has no peer */
2191 GST_CAT_DEBUG (GST_CAT_PADS,
2192 "%s:%s called bufferallocfunc but had no peer, returning NULL",
2193 GST_DEBUG_PAD_NAME (pad));
2195 return GST_FLOW_NOT_CONNECTED;
2199 /* peer was flushing */
2201 gst_object_unref (peer);
2202 GST_CAT_DEBUG (GST_CAT_PADS,
2203 "%s:%s called bufferallocfunc but peer was flushing, returning NULL",
2204 GST_DEBUG_PAD_NAME (pad));
2205 return GST_FLOW_WRONG_STATE;
2207 /* fallback case, allocate a buffer of our own, add pad caps. */
2210 GST_CAT_DEBUG (GST_CAT_PADS,
2211 "%s:%s fallback buffer alloc", GST_DEBUG_PAD_NAME (pad));
2212 *buf = gst_buffer_new_and_alloc (size);
2213 gst_buffer_set_caps (*buf, caps);
2221 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2222 "alloc function retured unacceptable buffer");
2223 return GST_FLOW_NOT_NEGOTIATED;
2227 gst_object_unref (peer);
2228 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2229 "alloc function retured error %d", ret);
2235 * gst_pad_get_internal_links_default:
2236 * @pad: the #GstPad to get the internal links of.
2238 * Gets a list of pads to which the given pad is linked to
2239 * inside of the parent element.
2240 * This is the default handler, and thus returns a list of all of the
2241 * pads inside the parent element with opposite direction.
2242 * The caller must free this list after use.
2244 * Returns: a newly allocated #GList of pads.
2249 gst_pad_get_internal_links_default (GstPad * pad)
2254 GstPadDirection direction;
2256 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2258 direction = pad->direction;
2260 parent = GST_PAD_PARENT (pad);
2261 parent_pads = parent->pads;
2263 while (parent_pads) {
2264 GstPad *parent_pad = GST_PAD_CAST (parent_pads->data);
2266 if (parent_pad->direction != direction) {
2267 res = g_list_prepend (res, parent_pad);
2270 parent_pads = g_list_next (parent_pads);
2277 * gst_pad_get_internal_links:
2278 * @pad: the #GstPad to get the internal links of.
2280 * Gets a list of pads to which the given pad is linked to
2281 * inside of the parent element.
2282 * The caller must free this list after use.
2284 * Returns: a newly allocated #GList of pads.
2289 gst_pad_get_internal_links (GstPad * pad)
2293 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2295 if (GST_PAD_INTLINKFUNC (pad))
2296 res = GST_PAD_INTLINKFUNC (pad) (pad);
2303 gst_pad_event_default_dispatch (GstPad * pad, GstEvent * event)
2308 GST_INFO_OBJECT (pad, "Sending event %p to all internally linked pads",
2311 result = (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
2313 orig = pads = gst_pad_get_internal_links (pad);
2316 GstPad *eventpad = GST_PAD_CAST (pads->data);
2318 pads = g_list_next (pads);
2320 /* for all of the internally-linked pads that are actually linked */
2321 if (GST_PAD_IS_LINKED (eventpad)) {
2322 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
2323 /* for each pad we send to, we should ref the event; it's up
2324 * to downstream to unref again when handled. */
2325 GST_LOG_OBJECT (pad, "Reffing and sending event %p to %s:%s", event,
2326 GST_DEBUG_PAD_NAME (eventpad));
2327 gst_event_ref (event);
2328 gst_pad_push_event (eventpad, event);
2330 /* we only send the event on one pad, multi-sinkpad elements
2331 * should implement a handler */
2332 GST_LOG_OBJECT (pad, "sending event %p to one sink pad %s:%s", event,
2333 GST_DEBUG_PAD_NAME (eventpad));
2334 result = gst_pad_push_event (eventpad, event);
2339 /* we handled the incoming event so we unref once */
2340 GST_LOG_OBJECT (pad, "handled event %p, unreffing", event);
2341 gst_event_unref (event);
2350 * gst_pad_event_default:
2351 * @pad: a #GstPad to call the default event handler on.
2352 * @event: the #GstEvent to handle.
2354 * Invokes the default event handler for the given pad. End-of-stream and
2355 * discontinuity events are handled specially, and then the event is sent to all
2356 * pads internally linked to @pad. Note that if there are many possible sink
2357 * pads that are internally linked to @pad, only one will be sent an event.
2358 * Multi-sinkpad elements should implement custom event handlers.
2360 * Returns: TRUE if the event was sent succesfully.
2363 gst_pad_event_default (GstPad * pad, GstEvent * event)
2365 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2366 g_return_val_if_fail (event != NULL, FALSE);
2368 switch (GST_EVENT_TYPE (event)) {
2371 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
2372 gst_pad_pause_task (pad);
2378 return gst_pad_event_default_dispatch (pad, event);
2382 * gst_pad_dispatcher:
2383 * @pad: a #GstPad to dispatch.
2384 * @dispatch: the #GstDispatcherFunction to call.
2385 * @data: gpointer user data passed to the dispatcher function.
2387 * Invokes the given dispatcher function on all pads that are
2388 * internally linked to the given pad.
2389 * The GstPadDispatcherFunction should return TRUE when no further pads
2390 * need to be processed.
2392 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2395 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
2398 gboolean res = FALSE;
2399 GList *int_pads, *orig;
2401 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2402 g_return_val_if_fail (dispatch != NULL, FALSE);
2404 orig = int_pads = gst_pad_get_internal_links (pad);
2407 GstPad *int_pad = GST_PAD_CAST (int_pads->data);
2408 GstPad *int_peer = GST_PAD_PEER (int_pad);
2411 res = dispatch (int_peer, data);
2415 int_pads = g_list_next (int_pads);
2425 * @pad: a #GstPad to invoke the default query on.
2426 * @query: the #GstQuery to perform.
2428 * Dispatches a query to a pad. The query should have been allocated by the
2429 * caller via one of the type-specific allocation functions in gstquery.h. The
2430 * element is responsible for filling the query with an appropriate response,
2431 * which should then be parsed with a type-specific query parsing function.
2433 * Again, the caller is responsible for both the allocation and deallocation of
2434 * the query structure.
2436 * Returns: TRUE if the query could be performed.
2439 gst_pad_query (GstPad * pad, GstQuery * query)
2441 GstPadQueryFunction func;
2443 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2444 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
2446 GST_DEBUG ("sending query %p to pad %s:%s", query, GST_DEBUG_PAD_NAME (pad));
2448 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
2451 return func (pad, query);
2455 GST_DEBUG ("pad had no query function");
2461 gst_pad_query_default (GstPad * pad, GstQuery * query)
2463 switch (GST_QUERY_TYPE (query)) {
2464 case GST_QUERY_POSITION:
2465 case GST_QUERY_SEEKING:
2466 case GST_QUERY_FORMATS:
2467 case GST_QUERY_LATENCY:
2468 case GST_QUERY_JITTER:
2469 case GST_QUERY_RATE:
2470 case GST_QUERY_CONVERT:
2472 return gst_pad_dispatcher
2473 (pad, (GstPadDispatcherFunction) gst_pad_query, query);
2477 #ifndef GST_DISABLE_LOADSAVE
2478 /* FIXME: why isn't this on a GstElement ? */
2480 * gst_pad_load_and_link:
2481 * @self: an #xmlNodePtr to read the description from.
2482 * @parent: the #GstObject element that owns the pad.
2484 * Reads the pad definition from the XML node and links the given pad
2485 * in the element to a pad of an element up in the hierarchy.
2488 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
2490 xmlNodePtr field = self->xmlChildrenNode;
2491 GstPad *pad = NULL, *targetpad;
2495 GstObject *grandparent;
2499 if (!strcmp ((char *) field->name, "name")) {
2500 name = (gchar *) xmlNodeGetContent (field);
2501 pad = gst_element_get_pad (GST_ELEMENT (parent), name);
2503 } else if (!strcmp ((char *) field->name, "peer")) {
2504 peer = (gchar *) xmlNodeGetContent (field);
2506 field = field->next;
2508 g_return_if_fail (pad != NULL);
2513 split = g_strsplit (peer, ".", 2);
2515 if (split[0] == NULL || split[1] == NULL) {
2516 GST_CAT_DEBUG (GST_CAT_XML,
2517 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
2518 peer, GST_DEBUG_PAD_NAME (pad));
2525 g_return_if_fail (split[0] != NULL);
2526 g_return_if_fail (split[1] != NULL);
2528 grandparent = gst_object_get_parent (parent);
2530 if (grandparent && GST_IS_BIN (grandparent)) {
2531 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2538 targetpad = gst_element_get_pad (target, split[1]);
2540 if (targetpad == NULL)
2543 gst_pad_link (pad, targetpad);
2550 * gst_pad_save_thyself:
2551 * @pad: a #GstPad to save.
2552 * @parent: the parent #xmlNodePtr to save the description in.
2554 * Saves the pad into an xml representation.
2556 * Returns: the #xmlNodePtr representation of the pad.
2559 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
2564 g_return_val_if_fail (GST_IS_PAD (object), NULL);
2566 pad = GST_PAD (object);
2568 xmlNewChild (parent, NULL, (xmlChar *) "name",
2569 (xmlChar *) GST_PAD_NAME (pad));
2570 if (GST_PAD_PEER (pad) != NULL) {
2573 peer = GST_PAD_PEER (pad);
2574 /* first check to see if the peer's parent's parent is the same */
2575 /* we just save it off */
2576 content = g_strdup_printf ("%s.%s",
2577 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
2578 xmlNewChild (parent, NULL, (xmlChar *) "peer", (xmlChar *) content);
2581 xmlNewChild (parent, NULL, (xmlChar *) "peer", NULL);
2588 * gst_ghost_pad_save_thyself:
2589 * @pad: a ghost #GstPad to save.
2590 * @parent: the parent #xmlNodePtr to save the description in.
2592 * Saves the ghost pad into an xml representation.
2594 * Returns: the #xmlNodePtr representation of the pad.
2597 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
2601 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2603 self = xmlNewChild (parent, NULL, (xmlChar *) "ghostpad", NULL);
2604 xmlNewChild (self, NULL, (xmlChar *) "name", (xmlChar *) GST_PAD_NAME (pad));
2605 xmlNewChild (self, NULL, (xmlChar *) "parent",
2606 (xmlChar *) GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
2608 /* FIXME FIXME FIXME! */
2613 #endif /* GST_DISABLE_LOADSAVE */
2616 * should be called with pad lock held
2621 handle_pad_block (GstPad * pad)
2623 GstPadBlockCallback callback;
2626 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2627 "signal block taken on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
2629 /* need to grab extra ref for the callbacks */
2630 gst_object_ref (pad);
2632 callback = pad->block_callback;
2634 user_data = pad->block_data;
2636 callback (pad, TRUE, user_data);
2639 GST_PAD_BLOCK_SIGNAL (pad);
2642 while (GST_PAD_IS_BLOCKED (pad))
2643 GST_PAD_BLOCK_WAIT (pad);
2645 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got unblocked");
2647 callback = pad->block_callback;
2649 user_data = pad->block_data;
2651 callback (pad, FALSE, user_data);
2654 GST_PAD_BLOCK_SIGNAL (pad);
2657 gst_object_unref (pad);
2660 /**********************************************************************
2661 * Data passing functions
2666 * @pad: a sink #GstPad.
2667 * @buffer: the #GstBuffer to send.
2669 * Chain a buffer to @pad.
2671 * Returns: a #GstFlowReturn from the pad.
2676 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
2679 gboolean caps_changed;
2680 GstPadChainFunction chainfunc;
2683 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2684 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
2686 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
2687 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
2689 GST_STREAM_LOCK (pad);
2692 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2695 caps = GST_BUFFER_CAPS (buffer);
2696 caps_changed = caps && caps != GST_PAD_CAPS (pad);
2699 /* we got a new datatype on the pad, see if it can handle it */
2700 if (G_UNLIKELY (caps_changed)) {
2701 GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
2702 if (G_UNLIKELY (!gst_pad_configure_sink (pad, caps)))
2703 goto not_negotiated;
2706 /* NOTE: we read the chainfunc unlocked.
2707 * we cannot hold the lock for the pad so we might send
2708 * the data to the wrong function. This is not really a
2709 * problem since functions are assigned at creation time
2710 * and don't change that often... */
2711 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
2714 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2715 "calling chainfunction &%s of pad %s:%s",
2716 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_DEBUG_PAD_NAME (pad));
2718 ret = chainfunc (pad, buffer);
2719 GST_STREAM_UNLOCK (pad);
2726 gst_buffer_unref (buffer);
2727 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2728 "pushing, but pad was flushing");
2730 GST_STREAM_UNLOCK (pad);
2731 return GST_FLOW_UNEXPECTED;
2735 gst_buffer_unref (buffer);
2736 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2737 "pushing buffer but pad did not accept");
2738 GST_STREAM_UNLOCK (pad);
2739 return GST_FLOW_NOT_NEGOTIATED;
2743 gst_buffer_unref (buffer);
2744 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2745 "pushing, but not chainhandler");
2746 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
2747 ("push on pad %s:%s but it has no chainfunction",
2748 GST_DEBUG_PAD_NAME (pad)));
2749 GST_STREAM_UNLOCK (pad);
2750 return GST_FLOW_ERROR;
2756 * @pad: a source #GstPad.
2757 * @buffer: the #GstBuffer to push.
2759 * Pushes a buffer to the peer of @pad. @pad must be linked.
2761 * Returns: a #GstFlowReturn from the peer pad.
2766 gst_pad_push (GstPad * pad, GstBuffer * buffer)
2771 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2772 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR);
2773 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
2774 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
2777 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
2778 handle_pad_block (pad);
2780 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2783 gst_object_ref (peer);
2786 ret = gst_pad_chain (peer, buffer);
2788 gst_object_unref (peer);
2792 /* ERROR recovery here */
2795 gst_buffer_unref (buffer);
2796 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2797 "pushing, but it was not linked");
2799 return GST_FLOW_NOT_CONNECTED;
2804 * gst_pad_check_pull_range:
2805 * @pad: a sink #GstPad.
2807 * Checks if a #gst_pad_pull_range() can be performed on the peer
2808 * source pad. This function is used by plugins that want to check
2809 * if they can use random access on the peer source pad.
2811 * The peer sourcepad can implement a custom #GstPadCheckGetRangeFunction
2812 * if it needs to perform some logic to determine if pull_range is
2815 * Returns: a gboolean with the result.
2820 gst_pad_check_pull_range (GstPad * pad)
2824 GstPadCheckGetRangeFunction checkgetrangefunc;
2826 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2829 if (GST_PAD_DIRECTION (pad) != GST_PAD_SINK)
2830 goto wrong_direction;
2832 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2835 gst_object_ref (peer);
2838 /* see note in above function */
2839 if (G_LIKELY ((checkgetrangefunc = peer->checkgetrangefunc) == NULL)) {
2840 ret = GST_PAD_GETRANGEFUNC (peer) != NULL;
2842 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2843 "calling checkgetrangefunc %s of peer pad %s:%s",
2844 GST_DEBUG_FUNCPTR_NAME (checkgetrangefunc), GST_DEBUG_PAD_NAME (peer));
2846 ret = checkgetrangefunc (peer);
2849 gst_object_unref (peer);
2853 /* ERROR recovery here */
2861 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2862 "checking pull range, but it was not linked");
2869 * gst_pad_get_range:
2870 * @pad: a src #GstPad.
2871 * @buffer: a pointer to hold the #GstBuffer.
2872 * @offset: The start offset of the buffer
2873 * @length: The length of the buffer
2875 * Calls the getrange function of @pad.
2877 * Returns: a #GstFlowReturn from the pad.
2882 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
2883 GstBuffer ** buffer)
2886 GstPadGetRangeFunction getrangefunc;
2888 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2889 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR);
2890 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
2892 GST_STREAM_LOCK (pad);
2895 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2899 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
2902 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2903 "calling getrangefunc %s of peer pad %s:%s, offset %"
2904 G_GUINT64_FORMAT ", size %u",
2905 GST_DEBUG_FUNCPTR_NAME (getrangefunc), GST_DEBUG_PAD_NAME (pad),
2908 ret = getrangefunc (pad, offset, size, buffer);
2910 GST_STREAM_UNLOCK (pad);
2917 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2918 "pulling range, but pad was flushing");
2920 GST_STREAM_UNLOCK (pad);
2921 return GST_FLOW_UNEXPECTED;
2925 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
2926 ("pullrange on pad %s:%s but it has no getrangefunction",
2927 GST_DEBUG_PAD_NAME (pad)));
2928 GST_STREAM_UNLOCK (pad);
2929 return GST_FLOW_ERROR;
2935 * gst_pad_pull_range:
2936 * @pad: a sink #GstPad.
2937 * @buffer: a pointer to hold the #GstBuffer.
2938 * @offset: The start offset of the buffer
2939 * @length: The length of the buffer
2941 * Pulls a buffer from the peer pad. @pad must be linked.
2943 * Returns: a #GstFlowReturn from the peer pad.
2948 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
2949 GstBuffer ** buffer)
2954 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2955 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
2957 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
2961 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
2962 handle_pad_block (pad);
2964 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2967 gst_object_ref (peer);
2970 ret = gst_pad_get_range (peer, offset, size, buffer);
2972 gst_object_unref (peer);
2976 /* ERROR recovery here */
2979 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2980 "pulling range, but it was not linked");
2982 return GST_FLOW_NOT_CONNECTED;
2987 * gst_pad_push_event:
2988 * @pad: a #GstPad to push the event to.
2989 * @event: the #GstEvent to send to the pad.
2991 * Sends the event to the peer of the given pad. This function is
2992 * mainly used by elements to send events to their peer
2995 * Returns: TRUE if the event was handled.
3000 gst_pad_push_event (GstPad * pad, GstEvent * event)
3005 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3006 g_return_val_if_fail (event != NULL, FALSE);
3009 peerpad = GST_PAD_PEER (pad);
3010 if (peerpad == NULL)
3013 gst_object_ref (peerpad);
3016 result = gst_pad_send_event (peerpad, event);
3018 gst_object_unref (peerpad);
3022 /* ERROR handling */
3025 gst_event_unref (event);
3032 * gst_pad_send_event:
3033 * @pad: a #GstPad to send the event to.
3034 * @event: the #GstEvent to send to the pad.
3036 * Sends the event to the pad. This function can be used
3037 * by applications to send events in the pipeline.
3039 * Returns: TRUE if the event was handled.
3042 gst_pad_send_event (GstPad * pad, GstEvent * event)
3044 gboolean result = FALSE;
3045 GstPadEventFunction eventfunc;
3047 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3048 g_return_val_if_fail (event != NULL, FALSE);
3052 if (GST_EVENT_SRC (event) == NULL)
3053 GST_EVENT_SRC (event) = gst_object_ref (pad);
3055 switch (GST_EVENT_TYPE (event)) {
3056 case GST_EVENT_FLUSH:
3057 GST_CAT_DEBUG (GST_CAT_EVENT, "have event type %d (FLUSH) on pad %s:%s",
3058 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (pad));
3060 if (GST_EVENT_FLUSH_DONE (event)) {
3061 GST_PAD_UNSET_FLUSHING (pad);
3062 GST_CAT_DEBUG (GST_CAT_EVENT, "cleared flush flag");
3064 /* can't even accept a flush begin event when flushing */
3065 if (GST_PAD_IS_FLUSHING (pad))
3067 GST_PAD_SET_FLUSHING (pad);
3068 GST_CAT_DEBUG (GST_CAT_EVENT, "set flush flag");
3072 GST_CAT_DEBUG (GST_CAT_EVENT, "have event type %d on pad %s:%s",
3073 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (pad));
3075 if (GST_PAD_IS_FLUSHING (pad))
3080 if ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL)
3083 gst_object_ref (pad);
3086 result = eventfunc (GST_PAD_CAST (pad), event);
3088 gst_object_unref (pad);
3092 /* ERROR handling */
3095 g_warning ("pad %s:%s has no event handler, file a bug.",
3096 GST_DEBUG_PAD_NAME (pad));
3098 gst_event_unref (event);
3104 GST_CAT_DEBUG (GST_CAT_EVENT, "Received event on flushing pad. Discarding");
3105 gst_event_unref (event);
3110 /************************************************************************
3115 static void gst_pad_template_class_init (GstPadTemplateClass * klass);
3116 static void gst_pad_template_init (GstPadTemplate * templ);
3117 static void gst_pad_template_dispose (GObject * object);
3120 gst_pad_template_get_type (void)
3122 static GType padtemplate_type = 0;
3124 if (!padtemplate_type) {
3125 static const GTypeInfo padtemplate_info = {
3126 sizeof (GstPadTemplateClass), NULL, NULL,
3127 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
3128 sizeof (GstPadTemplate),
3130 (GInstanceInitFunc) gst_pad_template_init, NULL
3134 g_type_register_static (GST_TYPE_OBJECT, "GstPadTemplate",
3135 &padtemplate_info, 0);
3137 return padtemplate_type;
3141 gst_pad_template_class_init (GstPadTemplateClass * klass)
3143 GObjectClass *gobject_class;
3144 GstObjectClass *gstobject_class;
3146 gobject_class = (GObjectClass *) klass;
3147 gstobject_class = (GstObjectClass *) klass;
3149 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
3151 gst_pad_template_signals[TEMPL_PAD_CREATED] =
3152 g_signal_new ("pad-created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
3153 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
3154 NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
3156 gobject_class->dispose = gst_pad_template_dispose;
3158 gstobject_class->path_string_separator = "*";
3162 gst_pad_template_init (GstPadTemplate * templ)
3167 gst_pad_template_dispose (GObject * object)
3169 GstPadTemplate *templ = GST_PAD_TEMPLATE (object);
3171 g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
3172 if (GST_PAD_TEMPLATE_CAPS (templ)) {
3173 gst_caps_unref (GST_PAD_TEMPLATE_CAPS (templ));
3176 G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object);
3179 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
3181 * SOMETIMES padtemplates can do whatever they want, they are provided by the
3183 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
3184 * 'sink%d' template is automatically selected), so we need to restrict their
3188 name_is_valid (const gchar * name, GstPadPresence presence)
3192 if (presence == GST_PAD_ALWAYS) {
3193 if (strchr (name, '%')) {
3194 g_warning ("invalid name template %s: conversion specifications are not"
3195 " allowed for GST_PAD_ALWAYS padtemplates", name);
3198 } else if (presence == GST_PAD_REQUEST) {
3199 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
3200 g_warning ("invalid name template %s: only one conversion specification"
3201 " allowed in GST_PAD_REQUEST padtemplate", name);
3204 if (str && (*(str + 1) != 's' && *(str + 1) != 'd')) {
3205 g_warning ("invalid name template %s: conversion specification must be of"
3206 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
3209 if (str && (*(str + 2) != '\0')) {
3210 g_warning ("invalid name template %s: conversion specification must"
3211 " appear at the end of the GST_PAD_REQUEST padtemplate name", name);
3220 * gst_static_pad_template_get:
3221 * @pad_template: the static pad template
3223 * Converts a #GstStaticPadTemplate into a #GstPadTemplate.
3225 * Returns: a new #GstPadTemplate.
3228 gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
3230 GstPadTemplate *new;
3232 if (!name_is_valid (pad_template->name_template, pad_template->presence))
3235 new = g_object_new (gst_pad_template_get_type (),
3236 "name", pad_template->name_template, NULL);
3238 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (pad_template->name_template);
3239 GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction;
3240 GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence;
3242 GST_PAD_TEMPLATE_CAPS (new) =
3243 gst_caps_copy (gst_static_caps_get (&pad_template->static_caps));
3249 * gst_pad_template_new:
3250 * @name_template: the name template.
3251 * @direction: the #GstPadDirection of the template.
3252 * @presence: the #GstPadPresence of the pad.
3253 * @caps: a #GstCaps set for the template. The caps are taken ownership of.
3255 * Creates a new pad template with a name according to the given template
3256 * and with the given arguments. This functions takes ownership of the provided
3257 * caps, so be sure to not use them afterwards.
3259 * Returns: a new #GstPadTemplate.
3262 gst_pad_template_new (const gchar * name_template,
3263 GstPadDirection direction, GstPadPresence presence, GstCaps * caps)
3265 GstPadTemplate *new;
3267 g_return_val_if_fail (name_template != NULL, NULL);
3268 g_return_val_if_fail (caps != NULL, NULL);
3269 g_return_val_if_fail (direction == GST_PAD_SRC
3270 || direction == GST_PAD_SINK, NULL);
3271 g_return_val_if_fail (presence == GST_PAD_ALWAYS
3272 || presence == GST_PAD_SOMETIMES || presence == GST_PAD_REQUEST, NULL);
3274 if (!name_is_valid (name_template, presence))
3277 new = g_object_new (gst_pad_template_get_type (),
3278 "name", name_template, NULL);
3280 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
3281 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
3282 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
3283 GST_PAD_TEMPLATE_CAPS (new) = caps;
3289 * gst_static_pad_template_get_caps:
3290 * @templ: a #GstStaticPadTemplate to get capabilities of.
3292 * Gets the capabilities of the static pad template.
3294 * Returns: the #GstCaps of the static pad template. If you need to keep a
3295 * reference to the caps, take a ref (see gst_caps_ref ()).
3298 gst_static_pad_template_get_caps (GstStaticPadTemplate * templ)
3300 g_return_val_if_fail (templ, NULL);
3302 return (GstCaps *) gst_static_caps_get (&templ->static_caps);
3306 * gst_pad_template_get_caps:
3307 * @templ: a #GstPadTemplate to get capabilities of.
3309 * Gets the capabilities of the pad template.
3311 * Returns: the #GstCaps of the pad template. If you need to keep a reference to
3312 * the caps, take a ref (see gst_caps_ref ()).
3315 gst_pad_template_get_caps (GstPadTemplate * templ)
3317 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
3319 return GST_PAD_TEMPLATE_CAPS (templ);
3323 * gst_pad_set_element_private:
3324 * @pad: the #GstPad to set the private data of.
3325 * @priv: The private data to attach to the pad.
3327 * Set the given private data gpointer on the pad.
3328 * This function can only be used by the element that owns the pad.
3331 gst_pad_set_element_private (GstPad * pad, gpointer priv)
3333 pad->element_private = priv;
3337 * gst_pad_get_element_private:
3338 * @pad: the #GstPad to get the private data of.
3340 * Gets the private data of a pad.
3342 * Returns: a #gpointer to the private data.
3345 gst_pad_get_element_private (GstPad * pad)
3347 return pad->element_private;
3351 * gst_pad_start_task:
3352 * @pad: the #GstPad to start the task of
3353 * @func: the task function to call
3354 * @data: data passed to the task function
3356 * Starts a task that repeadedly calls @func with @data. This function
3357 * is nostly used in the pad activation function to start the
3358 * dataflow. This function will automatically acauire the STREAM_LOCK of
3359 * the pad before calling @func.
3361 * Returns: a TRUE if the task could be started. FALSE when the pad has
3362 * no parent or the parent has no scheduler.
3365 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
3368 GstScheduler *sched;
3371 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3372 g_return_val_if_fail (func != NULL, FALSE);
3375 parent = GST_PAD_PARENT (pad);
3377 if (parent == NULL || !GST_IS_ELEMENT (parent))
3380 sched = GST_ELEMENT_SCHEDULER (parent);
3384 task = GST_PAD_TASK (pad);
3386 task = gst_scheduler_create_task (sched, func, data);
3387 gst_task_set_lock (task, GST_STREAM_GET_LOCK (pad));
3389 GST_PAD_TASK (pad) = task;
3393 gst_task_start (task);
3401 GST_DEBUG ("no parent");
3407 GST_DEBUG ("no scheduler");
3413 * gst_pad_pause_task:
3414 * @pad: the #GstPad to pause the task of
3416 * Pause the task of @pad. This function will also make sure that the
3417 * function executed by the task will effectively stop.
3419 * Returns: a TRUE if the task could be paused or FALSE when the pad
3423 gst_pad_pause_task (GstPad * pad)
3427 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3430 task = GST_PAD_TASK (pad);
3433 gst_task_pause (task);
3436 GST_STREAM_LOCK (pad);
3437 GST_STREAM_UNLOCK (pad);
3449 * gst_pad_stop_task:
3450 * @pad: the #GstPad to stop the task of
3452 * Stop the task of @pad. This function will also make sure that the
3453 * function executed by the task will effectively stop.
3455 * Returns: a TRUE if the task could be stopped or FALSE when the pad
3459 gst_pad_stop_task (GstPad * pad)
3463 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3466 task = GST_PAD_TASK (pad);
3469 GST_PAD_TASK (pad) = NULL;
3472 gst_task_stop (task);
3474 GST_STREAM_LOCK (pad);
3475 GST_STREAM_UNLOCK (pad);
3477 gst_object_unref (task);