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_chain_function:
876 * @pad: a sink #GstPad.
877 * @chain: the #GstPadChainFunction to set.
879 * Sets the given chain function for the pad. The chain function is called to
880 * process a #GstBuffer input buffer.
883 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
885 g_return_if_fail (GST_IS_PAD (pad));
886 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
888 GST_PAD_CHAINFUNC (pad) = chain;
889 GST_CAT_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
890 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
894 * gst_pad_set_getrange_function:
895 * @pad: a source #GstPad.
896 * @get: the #GstPadGetRangeFunction to set.
898 * Sets the given getrange function for the pad. The getrange function is called to
899 * produce a new #GstBuffer to start the processing pipeline. Getrange functions cannot
903 gst_pad_set_getrange_function (GstPad * pad, GstPadGetRangeFunction get)
905 g_return_if_fail (GST_IS_PAD (pad));
906 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
908 GST_PAD_GETRANGEFUNC (pad) = get;
910 GST_CAT_DEBUG (GST_CAT_PADS, "getrangefunc for %s:%s set to %s",
911 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
915 * gst_pad_set_checkgetrange_function:
916 * @pad: a source #GstPad.
917 * @check: the #GstPadCheckGetRangeFunction to set.
919 * Sets the given checkgetrange function for the pad. Implement this function on
920 * a pad if you dynamically support getrange based scheduling on the pad.
923 gst_pad_set_checkgetrange_function (GstPad * pad,
924 GstPadCheckGetRangeFunction check)
926 g_return_if_fail (GST_IS_PAD (pad));
927 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
929 GST_PAD_CHECKGETRANGEFUNC (pad) = check;
931 GST_CAT_DEBUG (GST_CAT_PADS, "checkgetrangefunc for %s:%s set to %s",
932 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (check));
936 * gst_pad_set_event_function:
937 * @pad: a source #GstPad.
938 * @event: the #GstPadEventFunction to set.
940 * Sets the given event handler for the pad.
943 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
945 g_return_if_fail (GST_IS_PAD (pad));
947 GST_PAD_EVENTFUNC (pad) = event;
949 GST_CAT_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
950 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
954 * gst_pad_set_query_function:
955 * @pad: a #GstPad of either direction.
956 * @query: the #GstPadQueryFunction to set.
958 * Set the given query function for the pad.
961 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
963 g_return_if_fail (GST_IS_PAD (pad));
965 GST_PAD_QUERYFUNC (pad) = query;
967 GST_CAT_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
968 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
972 * gst_pad_set_query_type_function:
973 * @pad: a #GstPad of either direction.
974 * @type_func: the #GstPadQueryTypeFunction to set.
976 * Set the given query type function for the pad.
979 gst_pad_set_query_type_function (GstPad * pad,
980 GstPadQueryTypeFunction type_func)
982 g_return_if_fail (GST_IS_PAD (pad));
984 GST_PAD_QUERYTYPEFUNC (pad) = type_func;
986 GST_CAT_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
987 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
991 * gst_pad_get_query_types:
994 * Get an array of supported queries that can be performed
997 * Returns: a zero-terminated array of #GstQueryType.
1000 gst_pad_get_query_types (GstPad * pad)
1002 GstPadQueryTypeFunction func;
1004 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1006 if (G_UNLIKELY ((func = GST_PAD_QUERYTYPEFUNC (pad)) == NULL))
1018 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
1020 *data = gst_pad_get_query_types (pad);
1026 * gst_pad_get_query_types_default:
1029 * Invoke the default dispatcher for the query types on
1032 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
1033 * internally-linked pads has a query types function.
1035 const GstQueryType *
1036 gst_pad_get_query_types_default (GstPad * pad)
1038 GstQueryType *result = NULL;
1040 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1042 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
1043 gst_pad_get_query_types_dispatcher, &result);
1049 * gst_pad_set_internal_link_function:
1050 * @pad: a #GstPad of either direction.
1051 * @intlink: the #GstPadIntLinkFunction to set.
1053 * Sets the given internal link function for the pad.
1056 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
1058 g_return_if_fail (GST_IS_PAD (pad));
1060 GST_PAD_INTLINKFUNC (pad) = intlink;
1061 GST_CAT_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
1062 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
1066 * gst_pad_set_link_function:
1068 * @link: the #GstPadLinkFunction to set.
1070 * Sets the given link function for the pad. It will be called when the pad is
1071 * linked or relinked with caps. The caps passed to the link function is
1072 * the caps for the connnection. It can contain a non fixed caps.
1074 * The return value GST_PAD_LINK_OK should be used when the connection can be
1077 * The return value GST_PAD_LINK_REFUSED should be used when the connection
1078 * cannot be made for some reason.
1081 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
1083 g_return_if_fail (GST_IS_PAD (pad));
1085 GST_PAD_LINKFUNC (pad) = link;
1086 GST_CAT_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
1087 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
1091 * gst_pad_set_unlink_function:
1093 * @unlink: the #GstPadUnlinkFunction to set.
1095 * Sets the given unlink function for the pad. It will be called
1096 * when the pad is unlinked.
1099 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
1101 g_return_if_fail (GST_IS_PAD (pad));
1103 GST_PAD_UNLINKFUNC (pad) = unlink;
1104 GST_CAT_DEBUG (GST_CAT_PADS, "unlinkfunc for %s:%s set to %s",
1105 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (unlink));
1109 * gst_pad_set_getcaps_function:
1111 * @getcaps: the #GstPadGetCapsFunction to set.
1113 * Sets the given getcaps function for the pad. @getcaps should return the
1114 * allowable caps for a pad in the context of the element's state, its link to
1115 * other elements, and the devices or files it has opened. These caps must be a
1116 * subset of the pad template caps. In the NULL state with no links, @getcaps
1117 * should ideally return the same caps as the pad template. In rare
1118 * circumstances, an object property can affect the caps returned by @getcaps,
1119 * but this is discouraged.
1121 * You do not need to call this function if @pad's allowed caps are always the
1122 * same as the pad template caps. This can only be true if the padtemplate
1123 * has fixed simple caps.
1125 * For most filters, the caps returned by @getcaps is directly affected by the
1126 * allowed caps on other pads. For demuxers and decoders, the caps returned by
1127 * the srcpad's getcaps function is directly related to the stream data. Again,
1128 * @getcaps should return the most specific caps it reasonably can, since this
1129 * helps with autoplugging.
1131 * Note that the return value from @getcaps is owned by the caller, so the caller
1132 * should unref the caps after usage.
1135 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
1137 g_return_if_fail (GST_IS_PAD (pad));
1139 GST_PAD_GETCAPSFUNC (pad) = getcaps;
1140 GST_CAT_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
1141 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
1145 * gst_pad_set_acceptcaps_function:
1147 * @acceptcaps: the #GstPadAcceptCapsFunction to set.
1149 * Sets the given acceptcaps function for the pad. The acceptcaps function
1150 * will be called to check if the pad can accept the given caps.
1153 gst_pad_set_acceptcaps_function (GstPad * pad,
1154 GstPadAcceptCapsFunction acceptcaps)
1156 g_return_if_fail (GST_IS_PAD (pad));
1158 GST_PAD_ACCEPTCAPSFUNC (pad) = acceptcaps;
1159 GST_CAT_DEBUG (GST_CAT_PADS, "acceptcapsfunc for %s:%s set to %s",
1160 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (acceptcaps));
1164 * gst_pad_set_fixatecaps_function:
1166 * @fixatecaps: the #GstPadFixateCapsFunction to set.
1168 * Sets the given fixatecaps function for the pad. The fixatecaps function
1169 * will be called whenever the default values for a GstCaps needs to be
1173 gst_pad_set_fixatecaps_function (GstPad * pad,
1174 GstPadFixateCapsFunction fixatecaps)
1176 g_return_if_fail (GST_IS_PAD (pad));
1178 GST_PAD_FIXATECAPSFUNC (pad) = fixatecaps;
1179 GST_CAT_DEBUG (GST_CAT_PADS, "fixatecapsfunc for %s:%s set to %s",
1180 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (fixatecaps));
1184 * gst_pad_set_setcaps_function:
1186 * @setcaps: the #GstPadSetCapsFunction to set.
1188 * Sets the given setcaps function for the pad. The setcaps function
1189 * will be called whenever a buffer with a new media type is pushed or
1190 * pulled from the pad. The pad/element needs to update it's internal
1191 * structures to process the new media type. If this new type is not
1192 * acceptable, the setcaps function should return FALSE.
1195 gst_pad_set_setcaps_function (GstPad * pad, GstPadSetCapsFunction setcaps)
1197 g_return_if_fail (GST_IS_PAD (pad));
1199 GST_PAD_SETCAPSFUNC (pad) = setcaps;
1200 GST_CAT_DEBUG (GST_CAT_PADS, "setcapsfunc for %s:%s set to %s",
1201 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (setcaps));
1205 * gst_pad_set_bufferalloc_function:
1206 * @pad: a sink #GstPad.
1207 * @bufalloc: the #GstPadBufferAllocFunction to set.
1209 * Sets the given bufferalloc function for the pad. Note that the
1210 * bufferalloc function can only be set on sinkpads.
1213 gst_pad_set_bufferalloc_function (GstPad * pad,
1214 GstPadBufferAllocFunction bufalloc)
1216 g_return_if_fail (GST_IS_PAD (pad));
1217 g_return_if_fail (GST_PAD_IS_SINK (pad));
1219 GST_PAD_BUFFERALLOCFUNC (pad) = bufalloc;
1220 GST_CAT_DEBUG (GST_CAT_PADS, "bufferallocfunc for %s:%s set to %s",
1221 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufalloc));
1226 * @srcpad: the source #GstPad to unlink.
1227 * @sinkpad: the sink #GstPad to unlink.
1229 * Unlinks the source pad from the sink pad. Will emit the "unlinked" signal on
1232 * Returns: TRUE if the pads were unlinked. This function returns FALSE if
1233 * the pads were not linked together.
1238 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
1240 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1241 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1243 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
1244 GST_DEBUG_PAD_NAME (srcpad), srcpad,
1245 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
1249 if (G_UNLIKELY (GST_PAD_DIRECTION (srcpad) != GST_PAD_SRC))
1254 if (G_UNLIKELY (GST_PAD_DIRECTION (sinkpad) != GST_PAD_SINK))
1257 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != sinkpad))
1258 goto not_linked_together;
1260 if (GST_PAD_UNLINKFUNC (srcpad)) {
1261 GST_PAD_UNLINKFUNC (srcpad) (srcpad);
1263 if (GST_PAD_UNLINKFUNC (sinkpad)) {
1264 GST_PAD_UNLINKFUNC (sinkpad) (sinkpad);
1267 /* first clear peers */
1268 GST_PAD_PEER (srcpad) = NULL;
1269 GST_PAD_PEER (sinkpad) = NULL;
1271 GST_UNLOCK (sinkpad);
1272 GST_UNLOCK (srcpad);
1274 /* fire off a signal to each of the pads telling them
1275 * that they've been unlinked */
1276 g_signal_emit (G_OBJECT (srcpad), gst_pad_signals[PAD_UNLINKED], 0, sinkpad);
1277 g_signal_emit (G_OBJECT (sinkpad), gst_pad_signals[PAD_UNLINKED], 0, srcpad);
1279 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1280 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1286 g_critical ("pad %s is not a source pad", GST_PAD_NAME (srcpad));
1287 GST_UNLOCK (srcpad);
1292 g_critical ("pad %s is not a sink pad", GST_PAD_NAME (sinkpad));
1293 GST_UNLOCK (sinkpad);
1294 GST_UNLOCK (srcpad);
1297 not_linked_together:
1299 /* we do not emit a warning in this case because unlinking cannot
1300 * be made MT safe.*/
1301 GST_UNLOCK (sinkpad);
1302 GST_UNLOCK (srcpad);
1308 * gst_pad_is_linked:
1309 * @pad: pad to check
1311 * Checks if a @pad is linked to another pad or not.
1313 * Returns: TRUE if the pad is linked, FALSE otherwise.
1318 gst_pad_is_linked (GstPad * pad)
1322 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1325 result = (GST_PAD_PEER (pad) != NULL);
1332 gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink)
1337 srccaps = gst_pad_get_caps_unlocked (src);
1338 sinkcaps = gst_pad_get_caps_unlocked (sink);
1339 GST_CAT_DEBUG (GST_CAT_CAPS, "got caps %p and %p", srccaps, sinkcaps);
1341 if (srccaps && sinkcaps) {
1344 icaps = gst_caps_intersect (srccaps, sinkcaps);
1345 gst_caps_unref (srccaps);
1346 gst_caps_unref (sinkcaps);
1348 GST_CAT_DEBUG (GST_CAT_CAPS,
1349 "intersection caps %p %" GST_PTR_FORMAT, icaps, icaps);
1351 if (!icaps || gst_caps_is_empty (icaps))
1359 /* FIXME leftover from an attempt at refactoring... */
1360 /* call with the two pads unlocked */
1361 static GstPadLinkReturn
1362 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad)
1364 /* generic checks */
1365 g_return_val_if_fail (GST_IS_PAD (srcpad), GST_PAD_LINK_REFUSED);
1366 g_return_val_if_fail (GST_IS_PAD (sinkpad), GST_PAD_LINK_REFUSED);
1368 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1369 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1373 if (G_UNLIKELY (GST_PAD_DIRECTION (srcpad) != GST_PAD_SRC))
1376 if (G_UNLIKELY (GST_PAD_PEER (srcpad) != NULL))
1377 goto src_was_linked;
1381 if (G_UNLIKELY (GST_PAD_DIRECTION (sinkpad) != GST_PAD_SINK))
1384 if (G_UNLIKELY (GST_PAD_PEER (sinkpad) != NULL))
1385 goto sink_was_linked;
1387 /* check pad caps for non-empty intersection */
1388 if (!gst_pad_link_check_compatible_unlocked (srcpad, sinkpad)) {
1392 /* FIXME check pad scheduling for non-empty intersection */
1394 return GST_PAD_LINK_OK;
1398 g_critical ("pad %s is not a source pad", GST_PAD_NAME (srcpad));
1399 GST_UNLOCK (srcpad);
1400 return GST_PAD_LINK_WRONG_DIRECTION;
1404 GST_CAT_INFO (GST_CAT_PADS, "src %s:%s was linked",
1405 GST_DEBUG_PAD_NAME (srcpad));
1406 /* we do not emit a warning in this case because unlinking cannot
1407 * be made MT safe.*/
1408 GST_UNLOCK (srcpad);
1409 return GST_PAD_LINK_WAS_LINKED;
1413 g_critical ("pad %s is not a sink pad", GST_PAD_NAME (sinkpad));
1414 GST_UNLOCK (sinkpad);
1415 GST_UNLOCK (srcpad);
1416 return GST_PAD_LINK_WRONG_DIRECTION;
1420 GST_CAT_INFO (GST_CAT_PADS, "sink %s:%s was linked",
1421 GST_DEBUG_PAD_NAME (sinkpad));
1422 /* we do not emit a warning in this case because unlinking cannot
1423 * be made MT safe.*/
1424 GST_UNLOCK (sinkpad);
1425 GST_UNLOCK (srcpad);
1426 return GST_PAD_LINK_WAS_LINKED;
1430 GST_CAT_INFO (GST_CAT_PADS, "caps are incompatible");
1431 GST_UNLOCK (sinkpad);
1432 GST_UNLOCK (srcpad);
1433 return GST_PAD_LINK_NOFORMAT;
1439 * @srcpad: the source #GstPad to link.
1440 * @sinkpad: the sink #GstPad to link.
1442 * Links the source pad and the sink pad.
1444 * Returns: A result code indicating if the connection worked or
1450 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
1452 GstPadLinkReturn result;
1454 /* prepare will also lock the two pads */
1455 result = gst_pad_link_prepare (srcpad, sinkpad);
1457 if (result != GST_PAD_LINK_OK)
1458 goto prepare_failed;
1460 GST_UNLOCK (sinkpad);
1461 GST_UNLOCK (srcpad);
1463 /* FIXME released the locks here, concurrent thread might link
1464 * something else. */
1465 if (GST_PAD_LINKFUNC (srcpad)) {
1466 /* this one will call the peer link function */
1467 result = GST_PAD_LINKFUNC (srcpad) (srcpad, sinkpad);
1468 } else if (GST_PAD_LINKFUNC (sinkpad)) {
1469 /* if no source link function, we need to call the sink link
1470 * function ourselves. */
1471 result = GST_PAD_LINKFUNC (sinkpad) (sinkpad, srcpad);
1473 result = GST_PAD_LINK_OK;
1479 if (result == GST_PAD_LINK_OK) {
1480 GST_PAD_PEER (srcpad) = sinkpad;
1481 GST_PAD_PEER (sinkpad) = srcpad;
1483 GST_UNLOCK (sinkpad);
1484 GST_UNLOCK (srcpad);
1486 /* fire off a signal to each of the pads telling them
1487 * that they've been linked */
1488 g_signal_emit (G_OBJECT (srcpad), gst_pad_signals[PAD_LINKED], 0, sinkpad);
1489 g_signal_emit (G_OBJECT (sinkpad), gst_pad_signals[PAD_LINKED], 0, srcpad);
1491 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1492 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1494 GST_CAT_INFO (GST_CAT_PADS, "link between %s:%s and %s:%s failed",
1495 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1497 GST_UNLOCK (sinkpad);
1498 GST_UNLOCK (srcpad);
1509 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
1511 /* this function would need checks if it weren't static */
1514 gst_object_replace ((GstObject **) & pad->padtemplate, (GstObject *) templ);
1518 gst_object_sink (GST_OBJECT (templ));
1519 g_signal_emit (G_OBJECT (templ),
1520 gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
1525 * gst_pad_get_pad_template:
1528 * Gets the template for @pad.
1530 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
1531 * if this pad has no template.
1533 * FIXME: currently returns an unrefcounted padtemplate.
1536 gst_pad_get_pad_template (GstPad * pad)
1538 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1540 return GST_PAD_PAD_TEMPLATE (pad);
1544 /* should be called with the pad LOCK held */
1545 /* refs the caps, so caller is responsible for getting it unreffed */
1547 gst_pad_get_caps_unlocked (GstPad * pad)
1549 GstCaps *result = NULL;
1551 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1552 GST_DEBUG_PAD_NAME (pad), pad);
1554 if (GST_PAD_GETCAPSFUNC (pad)) {
1555 GST_CAT_DEBUG (GST_CAT_CAPS, "dispatching to pad getcaps function");
1557 GST_FLAG_SET (pad, GST_PAD_IN_GETCAPS);
1559 result = GST_PAD_GETCAPSFUNC (pad) (pad);
1561 GST_FLAG_UNSET (pad, GST_PAD_IN_GETCAPS);
1563 if (result == NULL) {
1564 g_critical ("pad %s:%s returned NULL caps from getcaps function",
1565 GST_DEBUG_PAD_NAME (pad));
1567 #ifndef G_DISABLE_ASSERT
1568 /* check that the returned caps are a real subset of the template caps */
1569 if (GST_PAD_PAD_TEMPLATE (pad)) {
1570 const GstCaps *templ_caps =
1571 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
1572 if (!gst_caps_is_subset (result, templ_caps)) {
1575 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
1576 "pad returned caps %" GST_PTR_FORMAT
1577 " which are not a real subset of its template caps %"
1578 GST_PTR_FORMAT, result, templ_caps);
1580 ("pad %s:%s returned caps that are not a real subset of its template caps",
1581 GST_DEBUG_PAD_NAME (pad));
1582 temp = gst_caps_intersect (templ_caps, result);
1583 gst_caps_unref (result);
1591 if (GST_PAD_PAD_TEMPLATE (pad)) {
1592 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
1594 result = GST_PAD_TEMPLATE_CAPS (templ);
1595 GST_CAT_DEBUG (GST_CAT_CAPS,
1596 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
1599 result = gst_caps_ref (result);
1602 if (GST_PAD_CAPS (pad)) {
1603 result = GST_PAD_CAPS (pad);
1605 GST_CAT_DEBUG (GST_CAT_CAPS,
1606 "using pad caps %p %" GST_PTR_FORMAT, result, result);
1608 result = gst_caps_ref (result);
1612 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
1613 result = gst_caps_new_empty ();
1621 * @pad: a #GstPad to get the capabilities of.
1623 * Gets the capabilities of this pad.
1625 * Returns: the #GstCaps of this pad. This function returns a new caps, so use
1626 * gst_caps_unref to get rid of it.
1631 gst_pad_get_caps (GstPad * pad)
1633 GstCaps *result = NULL;
1635 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1639 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1640 GST_DEBUG_PAD_NAME (pad), pad);
1642 if (G_UNLIKELY (GST_PAD_IS_IN_GETCAPS (pad)))
1643 goto was_dispatching;
1645 result = gst_pad_get_caps_unlocked (pad);
1652 GST_CAT_DEBUG (GST_CAT_CAPS,
1653 "pad %s:%s is already dispatching!", GST_DEBUG_PAD_NAME (pad));
1654 g_warning ("pad %s:%s recursively called getcaps!",
1655 GST_DEBUG_PAD_NAME (pad));
1662 * gst_pad_peer_get_caps:
1663 * @pad: a #GstPad to get the peer capabilities of.
1665 * Gets the capabilities of the peer connected to this pad.
1667 * Returns: the #GstCaps of the peer pad. This function returns a new caps, so use
1668 * gst_caps_unref to get rid of it. this function returns NULL if there is no
1669 * peer pad or when this function is called recursively from a getcaps function.
1672 gst_pad_peer_get_caps (GstPad * pad)
1675 GstCaps *result = NULL;
1677 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1681 GST_CAT_DEBUG (GST_CAT_CAPS, "get peer caps of %s:%s (%p)",
1682 GST_DEBUG_PAD_NAME (pad), pad);
1684 peerpad = GST_PAD_PEER (pad);
1685 if (G_UNLIKELY (peerpad == NULL))
1688 if (G_UNLIKELY (GST_PAD_IS_IN_GETCAPS (peerpad)))
1689 goto was_dispatching;
1691 gst_object_ref (peerpad);
1694 result = gst_pad_get_caps (peerpad);
1696 gst_object_unref (peerpad);
1707 GST_CAT_DEBUG (GST_CAT_CAPS,
1708 "pad %s:%s is already dispatching!", GST_DEBUG_PAD_NAME (pad));
1709 g_warning ("pad %s:%s recursively called getcaps!",
1710 GST_DEBUG_PAD_NAME (pad));
1717 * gst_pad_fixate_caps:
1718 * @pad: a #GstPad to fixate
1720 * Fixate a caps on the given pad.
1722 * Returns: a fixated #GstCaps.
1725 gst_pad_fixate_caps (GstPad * pad, GstCaps * caps)
1727 /* FIXME, implement me, call the fixate function for the pad */
1732 * gst_pad_accept_caps:
1733 * @pad: a #GstPad to check
1735 * Check if the given pad accepts the caps.
1737 * Returns: TRUE if the pad can accept the caps.
1740 gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
1744 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1748 GST_CAT_DEBUG (GST_CAT_CAPS, "pad accept caps of %s:%s (%p)",
1749 GST_DEBUG_PAD_NAME (pad), pad);
1751 if (GST_PAD_ACCEPTCAPSFUNC (pad)) {
1752 /* we can call the function */
1753 result = GST_PAD_ACCEPTCAPSFUNC (pad) (pad, caps);
1755 /* else see get the caps and see if it intersects to something
1760 allowed = gst_pad_get_caps_unlocked (pad);
1761 intersect = gst_caps_intersect (allowed, caps);
1762 if (gst_caps_is_empty (intersect))
1773 * gst_pad_peer_accept_caps:
1774 * @pad: a #GstPad to check
1776 * Check if the given pad accepts the caps.
1778 * Returns: TRUE if the pad can accept the caps.
1781 gst_pad_peer_accept_caps (GstPad * pad, GstCaps * caps)
1786 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1790 GST_CAT_DEBUG (GST_CAT_CAPS, "peer accept caps of %s:%s (%p)",
1791 GST_DEBUG_PAD_NAME (pad), pad);
1793 peerpad = GST_PAD_PEER (pad);
1794 if (G_UNLIKELY (peerpad == NULL))
1797 result = gst_pad_accept_caps (peerpad, caps);
1811 * @pad: a #GstPad to set the capabilities of.
1812 * @caps: a #GstCaps to set.
1814 * Sets the capabilities of this pad. The caps must be fixed. Any previous
1815 * caps on the pad will be unreffed. This function refs the caps so you should
1816 * unref if as soon as you don't need it anymore.
1817 * It is possible to set NULL caps, which will make the pad unnegotiated
1820 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
1821 * or bad parameters were provided to this function.
1826 gst_pad_set_caps (GstPad * pad, GstCaps * caps)
1828 GstPadSetCapsFunction setcaps;
1830 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1833 setcaps = GST_PAD_SETCAPSFUNC (pad);
1835 /* call setcaps function to configure the pad */
1836 if (setcaps != NULL) {
1837 if (!GST_PAD_IS_IN_SETCAPS (pad)) {
1838 GST_FLAG_SET (pad, GST_PAD_IN_SETCAPS);
1840 if (!setcaps (pad, caps))
1843 GST_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
1845 GST_CAT_DEBUG (GST_CAT_CAPS, "pad %s:%s was dispatching",
1846 GST_DEBUG_PAD_NAME (pad));
1850 gst_caps_replace (&GST_PAD_CAPS (pad), caps);
1851 GST_CAT_DEBUG (GST_CAT_CAPS, "%s:%s caps %" GST_PTR_FORMAT,
1852 GST_DEBUG_PAD_NAME (pad), caps);
1855 g_object_notify (G_OBJECT (pad), "caps");
1862 GST_FLAG_UNSET (pad, GST_PAD_IN_SETCAPS);
1864 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " could not be set",
1871 gst_pad_configure_sink (GstPad * pad, GstCaps * caps)
1873 GstPadAcceptCapsFunction acceptcaps;
1874 GstPadSetCapsFunction setcaps;
1877 acceptcaps = GST_PAD_ACCEPTCAPSFUNC (pad);
1878 setcaps = GST_PAD_SETCAPSFUNC (pad);
1880 /* See if pad accepts the caps, by calling acceptcaps, only
1881 * needed if no setcaps function */
1882 if (setcaps == NULL && acceptcaps != NULL) {
1883 if (!acceptcaps (pad, caps))
1886 /* set caps on pad if call succeeds */
1887 res = gst_pad_set_caps (pad, caps);
1888 /* no need to unref the caps here, set_caps takes a ref and
1889 * our ref goes away when we leave this function. */
1895 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " not accepted", caps);
1901 gst_pad_configure_src (GstPad * pad, GstCaps * caps)
1903 GstPadAcceptCapsFunction acceptcaps;
1904 GstPadSetCapsFunction setcaps;
1907 acceptcaps = GST_PAD_ACCEPTCAPSFUNC (pad);
1908 setcaps = GST_PAD_SETCAPSFUNC (pad);
1910 /* See if pad accepts the caps, by calling acceptcaps, only
1911 * needed if no setcaps function */
1912 if (setcaps == NULL && acceptcaps != NULL) {
1913 if (!acceptcaps (pad, caps))
1916 /* set caps on pad if call succeeds */
1917 res = gst_pad_set_caps (pad, caps);
1918 /* no need to unref the caps here, set_caps takes a ref and
1919 * our ref goes away when we leave this function. */
1925 GST_CAT_DEBUG (GST_CAT_CAPS, "caps %" GST_PTR_FORMAT " not accepted", caps);
1931 * gst_pad_get_pad_template_caps:
1932 * @pad: a #GstPad to get the template capabilities from.
1934 * Gets the capabilities for @pad's template.
1936 * Returns: the #GstCaps of this pad template. If you intend to keep a reference
1937 * on the caps, make a copy (see gst_caps_copy ()).
1940 gst_pad_get_pad_template_caps (GstPad * pad)
1942 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
1944 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1946 if (GST_PAD_PAD_TEMPLATE (pad))
1947 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
1949 return gst_static_caps_get (&anycaps);
1955 * @pad: a #GstPad to get the peer of.
1957 * Gets the peer of @pad. This function refs the peer pad so
1958 * you need to unref it after use.
1960 * Returns: the peer #GstPad. Unref after usage.
1965 gst_pad_get_peer (GstPad * pad)
1969 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1972 result = GST_PAD_PEER (pad);
1974 gst_object_ref (result);
1981 * gst_pad_get_allowed_caps:
1982 * @srcpad: a #GstPad, it must a a source pad.
1984 * Gets the capabilities of the allowed media types that can flow through
1985 * @srcpad and its peer. The pad must be a source pad.
1986 * The caller must free the resulting caps.
1988 * Returns: the allowed #GstCaps of the pad link. Free the caps when
1989 * you no longer need it. This function returns NULL when the @srcpad has no
1995 gst_pad_get_allowed_caps (GstPad * srcpad)
2002 g_return_val_if_fail (GST_IS_PAD (srcpad), NULL);
2003 g_return_val_if_fail (GST_PAD_IS_SRC (srcpad), NULL);
2007 peer = GST_PAD_PEER (srcpad);
2008 if (G_UNLIKELY (peer == NULL))
2011 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting allowed caps",
2012 GST_DEBUG_PAD_NAME (srcpad));
2014 gst_object_ref (peer);
2015 GST_UNLOCK (srcpad);
2016 mycaps = gst_pad_get_caps (srcpad);
2018 peercaps = gst_pad_get_caps (peer);
2019 gst_object_unref (peer);
2021 caps = gst_caps_intersect (mycaps, peercaps);
2022 gst_caps_unref (peercaps);
2023 gst_caps_unref (mycaps);
2025 GST_CAT_DEBUG (GST_CAT_CAPS, "allowed caps %" GST_PTR_FORMAT, caps);
2031 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer",
2032 GST_DEBUG_PAD_NAME (srcpad));
2033 GST_UNLOCK (srcpad);
2040 * gst_pad_get_negotiated_caps:
2043 * Gets the capabilities of the media type that currently flows through @pad
2046 * This function can be used on both src and sinkpads. Note that srcpads are
2047 * always negotiated before sinkpads so it is possible that the negotiated caps
2048 * on the srcpad do not match the negotiated caps of the peer.
2050 * Returns: the negotiated #GstCaps of the pad link. Free the caps when
2051 * you no longer need it. This function returns NULL when the @pad has no
2052 * peer or is not negotiated yet.
2057 gst_pad_get_negotiated_caps (GstPad * pad)
2062 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2066 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2069 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting negotiated caps",
2070 GST_DEBUG_PAD_NAME (pad));
2072 caps = GST_PAD_CAPS (pad);
2074 gst_caps_ref (caps);
2077 GST_CAT_DEBUG (GST_CAT_CAPS, "negotiated caps %" GST_PTR_FORMAT, caps);
2083 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer",
2084 GST_DEBUG_PAD_NAME (pad));
2092 * gst_pad_alloc_buffer:
2093 * @pad: a source #GstPad
2094 * @offset: the offset of the new buffer in the stream
2095 * @size: the size of the new buffer
2096 * @caps: the caps of the new buffer
2097 * @buf: a newly allocated buffer
2099 * Allocates a new, empty buffer optimized to push to pad @pad. This
2100 * function only works if @pad is a source pad and has a peer.
2102 * You need to check the caps of the buffer after performing this
2103 * function and renegotiate to the format if needed.
2105 * A new, empty #GstBuffer will be put in the @buf argument.
2107 * Returns: a result code indicating success of the operation. Any
2108 * result code other than GST_FLOW_OK is an error and @buf should
2110 * An error can occur if the pad is not connected or when the downstream
2111 * peer elements cannot provide an acceptable buffer.
2116 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size, GstCaps * caps,
2121 GstPadBufferAllocFunction bufferallocfunc;
2122 gboolean caps_changed;
2124 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2125 g_return_val_if_fail (GST_PAD_IS_SRC (pad), GST_FLOW_ERROR);
2126 g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
2129 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2132 gst_object_ref (peer);
2135 if (G_LIKELY ((bufferallocfunc = peer->bufferallocfunc) == NULL))
2139 /* when the peer is flushing we cannot give a buffer */
2140 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (peer)))
2143 GST_CAT_DEBUG (GST_CAT_PADS,
2144 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s",
2145 GST_DEBUG_FUNCPTR_NAME (bufferallocfunc),
2146 &bufferallocfunc, GST_DEBUG_PAD_NAME (peer));
2149 ret = bufferallocfunc (peer, offset, size, caps, buf);
2151 if (G_UNLIKELY (ret != GST_FLOW_OK))
2153 if (G_UNLIKELY (*buf == NULL))
2157 gst_object_unref (peer);
2159 /* FIXME, move capnego this into a base class? */
2160 caps = GST_BUFFER_CAPS (*buf);
2161 caps_changed = caps && caps != GST_PAD_CAPS (pad);
2162 /* we got a new datatype on the pad, see if it can handle it */
2163 if (G_UNLIKELY (caps_changed)) {
2164 GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
2165 if (G_UNLIKELY (!gst_pad_configure_src (pad, caps)))
2166 goto not_negotiated;
2172 /* pad has no peer */
2173 GST_CAT_DEBUG (GST_CAT_PADS,
2174 "%s:%s called bufferallocfunc but had no peer",
2175 GST_DEBUG_PAD_NAME (pad));
2177 return GST_FLOW_NOT_LINKED;
2181 /* peer was flushing */
2183 gst_object_unref (peer);
2184 GST_CAT_DEBUG (GST_CAT_PADS,
2185 "%s:%s called bufferallocfunc but peer was flushing",
2186 GST_DEBUG_PAD_NAME (pad));
2187 return GST_FLOW_WRONG_STATE;
2189 /* fallback case, allocate a buffer of our own, add pad caps. */
2192 GST_CAT_DEBUG (GST_CAT_PADS,
2193 "%s:%s fallback buffer alloc", GST_DEBUG_PAD_NAME (pad));
2194 *buf = gst_buffer_new_and_alloc (size);
2195 gst_buffer_set_caps (*buf, caps);
2203 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2204 "alloc function retured unacceptable buffer");
2205 return GST_FLOW_NOT_NEGOTIATED;
2209 gst_object_unref (peer);
2210 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2211 "alloc function retured error %d", ret);
2217 * gst_pad_get_internal_links_default:
2218 * @pad: the #GstPad to get the internal links of.
2220 * Gets a list of pads to which the given pad is linked to
2221 * inside of the parent element.
2222 * This is the default handler, and thus returns a list of all of the
2223 * pads inside the parent element with opposite direction.
2224 * The caller must free this list after use.
2226 * Returns: a newly allocated #GList of pads.
2231 gst_pad_get_internal_links_default (GstPad * pad)
2236 GstPadDirection direction;
2238 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2240 direction = pad->direction;
2242 parent = GST_PAD_PARENT (pad);
2243 parent_pads = parent->pads;
2245 while (parent_pads) {
2246 GstPad *parent_pad = GST_PAD_CAST (parent_pads->data);
2248 if (parent_pad->direction != direction) {
2249 res = g_list_prepend (res, parent_pad);
2252 parent_pads = g_list_next (parent_pads);
2259 * gst_pad_get_internal_links:
2260 * @pad: the #GstPad to get the internal links of.
2262 * Gets a list of pads to which the given pad is linked to
2263 * inside of the parent element.
2264 * The caller must free this list after use.
2266 * Returns: a newly allocated #GList of pads.
2271 gst_pad_get_internal_links (GstPad * pad)
2275 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2277 if (GST_PAD_INTLINKFUNC (pad))
2278 res = GST_PAD_INTLINKFUNC (pad) (pad);
2285 gst_pad_event_default_dispatch (GstPad * pad, GstEvent * event)
2290 GST_INFO_OBJECT (pad, "Sending event %p to all internally linked pads",
2293 result = (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
2295 orig = pads = gst_pad_get_internal_links (pad);
2298 GstPad *eventpad = GST_PAD_CAST (pads->data);
2300 pads = g_list_next (pads);
2302 /* for all of the internally-linked pads that are actually linked */
2303 if (GST_PAD_IS_LINKED (eventpad)) {
2304 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
2305 /* for each pad we send to, we should ref the event; it's up
2306 * to downstream to unref again when handled. */
2307 GST_LOG_OBJECT (pad, "Reffing and sending event %p to %s:%s", event,
2308 GST_DEBUG_PAD_NAME (eventpad));
2309 gst_event_ref (event);
2310 gst_pad_push_event (eventpad, event);
2312 /* we only send the event on one pad, multi-sinkpad elements
2313 * should implement a handler */
2314 GST_LOG_OBJECT (pad, "sending event %p to one sink pad %s:%s", event,
2315 GST_DEBUG_PAD_NAME (eventpad));
2316 result = gst_pad_push_event (eventpad, event);
2321 /* we handled the incoming event so we unref once */
2322 GST_LOG_OBJECT (pad, "handled event %p, unreffing", event);
2323 gst_event_unref (event);
2332 * gst_pad_event_default:
2333 * @pad: a #GstPad to call the default event handler on.
2334 * @event: the #GstEvent to handle.
2336 * Invokes the default event handler for the given pad. End-of-stream and
2337 * discontinuity events are handled specially, and then the event is sent to all
2338 * pads internally linked to @pad. Note that if there are many possible sink
2339 * pads that are internally linked to @pad, only one will be sent an event.
2340 * Multi-sinkpad elements should implement custom event handlers.
2342 * Returns: TRUE if the event was sent succesfully.
2345 gst_pad_event_default (GstPad * pad, GstEvent * event)
2347 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2348 g_return_val_if_fail (event != NULL, FALSE);
2350 switch (GST_EVENT_TYPE (event)) {
2353 GST_DEBUG_OBJECT (pad, "pausing task because of eos");
2354 gst_pad_pause_task (pad);
2360 return gst_pad_event_default_dispatch (pad, event);
2364 * gst_pad_dispatcher:
2365 * @pad: a #GstPad to dispatch.
2366 * @dispatch: the #GstDispatcherFunction to call.
2367 * @data: gpointer user data passed to the dispatcher function.
2369 * Invokes the given dispatcher function on all pads that are
2370 * internally linked to the given pad.
2371 * The GstPadDispatcherFunction should return TRUE when no further pads
2372 * need to be processed.
2374 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2377 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
2380 gboolean res = FALSE;
2381 GList *int_pads, *orig;
2383 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2384 g_return_val_if_fail (dispatch != NULL, FALSE);
2386 orig = int_pads = gst_pad_get_internal_links (pad);
2389 GstPad *int_pad = GST_PAD_CAST (int_pads->data);
2390 GstPad *int_peer = GST_PAD_PEER (int_pad);
2393 res = dispatch (int_peer, data);
2397 int_pads = g_list_next (int_pads);
2407 * @pad: a #GstPad to invoke the default query on.
2408 * @query: the #GstQuery to perform.
2410 * Dispatches a query to a pad. The query should have been allocated by the
2411 * caller via one of the type-specific allocation functions in gstquery.h. The
2412 * element is responsible for filling the query with an appropriate response,
2413 * which should then be parsed with a type-specific query parsing function.
2415 * Again, the caller is responsible for both the allocation and deallocation of
2416 * the query structure.
2418 * Returns: TRUE if the query could be performed.
2421 gst_pad_query (GstPad * pad, GstQuery * query)
2423 GstPadQueryFunction func;
2425 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2426 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
2428 GST_DEBUG ("sending query %p to pad %s:%s", query, GST_DEBUG_PAD_NAME (pad));
2430 if ((func = GST_PAD_QUERYFUNC (pad)) == NULL)
2433 return func (pad, query);
2437 GST_DEBUG ("pad had no query function");
2443 gst_pad_query_default (GstPad * pad, GstQuery * query)
2445 switch (GST_QUERY_TYPE (query)) {
2446 case GST_QUERY_POSITION:
2447 case GST_QUERY_SEEKING:
2448 case GST_QUERY_FORMATS:
2449 case GST_QUERY_LATENCY:
2450 case GST_QUERY_JITTER:
2451 case GST_QUERY_RATE:
2452 case GST_QUERY_CONVERT:
2454 return gst_pad_dispatcher
2455 (pad, (GstPadDispatcherFunction) gst_pad_query, query);
2459 #ifndef GST_DISABLE_LOADSAVE
2460 /* FIXME: why isn't this on a GstElement ? */
2462 * gst_pad_load_and_link:
2463 * @self: an #xmlNodePtr to read the description from.
2464 * @parent: the #GstObject element that owns the pad.
2466 * Reads the pad definition from the XML node and links the given pad
2467 * in the element to a pad of an element up in the hierarchy.
2470 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
2472 xmlNodePtr field = self->xmlChildrenNode;
2473 GstPad *pad = NULL, *targetpad;
2477 GstObject *grandparent;
2481 if (!strcmp ((char *) field->name, "name")) {
2482 name = (gchar *) xmlNodeGetContent (field);
2483 pad = gst_element_get_pad (GST_ELEMENT (parent), name);
2485 } else if (!strcmp ((char *) field->name, "peer")) {
2486 peer = (gchar *) xmlNodeGetContent (field);
2488 field = field->next;
2490 g_return_if_fail (pad != NULL);
2495 split = g_strsplit (peer, ".", 2);
2497 if (split[0] == NULL || split[1] == NULL) {
2498 GST_CAT_DEBUG (GST_CAT_XML,
2499 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
2500 peer, GST_DEBUG_PAD_NAME (pad));
2507 g_return_if_fail (split[0] != NULL);
2508 g_return_if_fail (split[1] != NULL);
2510 grandparent = gst_object_get_parent (parent);
2512 if (grandparent && GST_IS_BIN (grandparent)) {
2513 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2520 targetpad = gst_element_get_pad (target, split[1]);
2522 if (targetpad == NULL)
2525 gst_pad_link (pad, targetpad);
2532 * gst_pad_save_thyself:
2533 * @pad: a #GstPad to save.
2534 * @parent: the parent #xmlNodePtr to save the description in.
2536 * Saves the pad into an xml representation.
2538 * Returns: the #xmlNodePtr representation of the pad.
2541 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
2546 g_return_val_if_fail (GST_IS_PAD (object), NULL);
2548 pad = GST_PAD (object);
2550 xmlNewChild (parent, NULL, (xmlChar *) "name",
2551 (xmlChar *) GST_PAD_NAME (pad));
2552 if (GST_PAD_PEER (pad) != NULL) {
2555 peer = GST_PAD_PEER (pad);
2556 /* first check to see if the peer's parent's parent is the same */
2557 /* we just save it off */
2558 content = g_strdup_printf ("%s.%s",
2559 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
2560 xmlNewChild (parent, NULL, (xmlChar *) "peer", (xmlChar *) content);
2563 xmlNewChild (parent, NULL, (xmlChar *) "peer", NULL);
2570 * gst_ghost_pad_save_thyself:
2571 * @pad: a ghost #GstPad to save.
2572 * @parent: the parent #xmlNodePtr to save the description in.
2574 * Saves the ghost pad into an xml representation.
2576 * Returns: the #xmlNodePtr representation of the pad.
2579 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
2583 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2585 self = xmlNewChild (parent, NULL, (xmlChar *) "ghostpad", NULL);
2586 xmlNewChild (self, NULL, (xmlChar *) "name", (xmlChar *) GST_PAD_NAME (pad));
2587 xmlNewChild (self, NULL, (xmlChar *) "parent",
2588 (xmlChar *) GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
2590 /* FIXME FIXME FIXME! */
2595 #endif /* GST_DISABLE_LOADSAVE */
2598 * should be called with pad lock held
2603 handle_pad_block (GstPad * pad)
2605 GstPadBlockCallback callback;
2608 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2609 "signal block taken on pad %s:%s", GST_DEBUG_PAD_NAME (pad));
2611 /* need to grab extra ref for the callbacks */
2612 gst_object_ref (pad);
2614 callback = pad->block_callback;
2616 user_data = pad->block_data;
2618 callback (pad, TRUE, user_data);
2621 GST_PAD_BLOCK_SIGNAL (pad);
2624 while (GST_PAD_IS_BLOCKED (pad))
2625 GST_PAD_BLOCK_WAIT (pad);
2627 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "got unblocked");
2629 callback = pad->block_callback;
2631 user_data = pad->block_data;
2633 callback (pad, FALSE, user_data);
2636 GST_PAD_BLOCK_SIGNAL (pad);
2639 gst_object_unref (pad);
2642 /**********************************************************************
2643 * Data passing functions
2648 * @pad: a sink #GstPad.
2649 * @buffer: the #GstBuffer to send.
2651 * Chain a buffer to @pad.
2653 * Returns: a #GstFlowReturn from the pad.
2658 gst_pad_chain (GstPad * pad, GstBuffer * buffer)
2661 gboolean caps_changed;
2662 GstPadChainFunction chainfunc;
2665 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2666 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
2668 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
2669 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
2671 GST_STREAM_LOCK (pad);
2674 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2677 caps = GST_BUFFER_CAPS (buffer);
2678 caps_changed = caps && caps != GST_PAD_CAPS (pad);
2681 /* we got a new datatype on the pad, see if it can handle it */
2682 if (G_UNLIKELY (caps_changed)) {
2683 GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
2684 if (G_UNLIKELY (!gst_pad_configure_sink (pad, caps)))
2685 goto not_negotiated;
2688 /* NOTE: we read the chainfunc unlocked.
2689 * we cannot hold the lock for the pad so we might send
2690 * the data to the wrong function. This is not really a
2691 * problem since functions are assigned at creation time
2692 * and don't change that often... */
2693 if (G_UNLIKELY ((chainfunc = GST_PAD_CHAINFUNC (pad)) == NULL))
2696 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2697 "calling chainfunction &%s of pad %s:%s",
2698 GST_DEBUG_FUNCPTR_NAME (chainfunc), GST_DEBUG_PAD_NAME (pad));
2700 ret = chainfunc (pad, buffer);
2701 GST_STREAM_UNLOCK (pad);
2708 gst_buffer_unref (buffer);
2709 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2710 "pushing, but pad was flushing");
2712 GST_STREAM_UNLOCK (pad);
2713 return GST_FLOW_UNEXPECTED;
2717 gst_buffer_unref (buffer);
2718 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2719 "pushing buffer but pad did not accept");
2720 GST_STREAM_UNLOCK (pad);
2721 return GST_FLOW_NOT_NEGOTIATED;
2725 gst_buffer_unref (buffer);
2726 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2727 "pushing, but not chainhandler");
2728 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
2729 ("push on pad %s:%s but it has no chainfunction",
2730 GST_DEBUG_PAD_NAME (pad)));
2731 GST_STREAM_UNLOCK (pad);
2732 return GST_FLOW_ERROR;
2738 * @pad: a source #GstPad.
2739 * @buffer: the #GstBuffer to push.
2741 * Pushes a buffer to the peer of @pad. @pad must be linked.
2743 * Returns: a #GstFlowReturn from the peer pad.
2748 gst_pad_push (GstPad * pad, GstBuffer * buffer)
2753 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2754 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR);
2755 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
2756 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
2759 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
2760 handle_pad_block (pad);
2762 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2765 gst_object_ref (peer);
2768 ret = gst_pad_chain (peer, buffer);
2770 gst_object_unref (peer);
2774 /* ERROR recovery here */
2777 gst_buffer_unref (buffer);
2778 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2779 "pushing, but it was not linked");
2781 return GST_FLOW_NOT_LINKED;
2786 * gst_pad_check_pull_range:
2787 * @pad: a sink #GstPad.
2789 * Checks if a #gst_pad_pull_range() can be performed on the peer
2790 * source pad. This function is used by plugins that want to check
2791 * if they can use random access on the peer source pad.
2793 * The peer sourcepad can implement a custom #GstPadCheckGetRangeFunction
2794 * if it needs to perform some logic to determine if pull_range is
2797 * Returns: a gboolean with the result.
2802 gst_pad_check_pull_range (GstPad * pad)
2806 GstPadCheckGetRangeFunction checkgetrangefunc;
2808 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2811 if (GST_PAD_DIRECTION (pad) != GST_PAD_SINK)
2812 goto wrong_direction;
2814 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2817 gst_object_ref (peer);
2820 /* see note in above function */
2821 if (G_LIKELY ((checkgetrangefunc = peer->checkgetrangefunc) == NULL)) {
2822 ret = GST_PAD_GETRANGEFUNC (peer) != NULL;
2824 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2825 "calling checkgetrangefunc %s of peer pad %s:%s",
2826 GST_DEBUG_FUNCPTR_NAME (checkgetrangefunc), GST_DEBUG_PAD_NAME (peer));
2828 ret = checkgetrangefunc (peer);
2831 gst_object_unref (peer);
2835 /* ERROR recovery here */
2843 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2844 "checking pull range, but it was not linked");
2851 * gst_pad_get_range:
2852 * @pad: a src #GstPad.
2853 * @buffer: a pointer to hold the #GstBuffer.
2854 * @offset: The start offset of the buffer
2855 * @length: The length of the buffer
2857 * Calls the getrange function of @pad.
2859 * Returns: a #GstFlowReturn from the pad.
2864 gst_pad_get_range (GstPad * pad, guint64 offset, guint size,
2865 GstBuffer ** buffer)
2868 GstPadGetRangeFunction getrangefunc;
2870 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2871 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC, GST_FLOW_ERROR);
2872 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
2874 GST_STREAM_LOCK (pad);
2877 if (G_UNLIKELY (GST_PAD_IS_FLUSHING (pad)))
2881 if (G_UNLIKELY ((getrangefunc = GST_PAD_GETRANGEFUNC (pad)) == NULL))
2884 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2885 "calling getrangefunc %s of peer pad %s:%s, offset %"
2886 G_GUINT64_FORMAT ", size %u",
2887 GST_DEBUG_FUNCPTR_NAME (getrangefunc), GST_DEBUG_PAD_NAME (pad),
2890 ret = getrangefunc (pad, offset, size, buffer);
2892 GST_STREAM_UNLOCK (pad);
2899 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2900 "pulling range, but pad was flushing");
2902 GST_STREAM_UNLOCK (pad);
2903 return GST_FLOW_UNEXPECTED;
2907 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
2908 ("pullrange on pad %s:%s but it has no getrangefunction",
2909 GST_DEBUG_PAD_NAME (pad)));
2910 GST_STREAM_UNLOCK (pad);
2911 return GST_FLOW_ERROR;
2917 * gst_pad_pull_range:
2918 * @pad: a sink #GstPad.
2919 * @buffer: a pointer to hold the #GstBuffer.
2920 * @offset: The start offset of the buffer
2921 * @length: The length of the buffer
2923 * Pulls a buffer from the peer pad. @pad must be linked.
2925 * Returns: a #GstFlowReturn from the peer pad.
2930 gst_pad_pull_range (GstPad * pad, guint64 offset, guint size,
2931 GstBuffer ** buffer)
2936 g_return_val_if_fail (GST_IS_PAD (pad), GST_FLOW_ERROR);
2937 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
2939 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
2943 while (G_UNLIKELY (GST_PAD_IS_BLOCKED (pad)))
2944 handle_pad_block (pad);
2946 if (G_UNLIKELY ((peer = GST_PAD_PEER (pad)) == NULL))
2949 gst_object_ref (peer);
2952 ret = gst_pad_get_range (peer, offset, size, buffer);
2954 gst_object_unref (peer);
2958 /* ERROR recovery here */
2961 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
2962 "pulling range, but it was not linked");
2964 return GST_FLOW_NOT_LINKED;
2969 * gst_pad_push_event:
2970 * @pad: a #GstPad to push the event to.
2971 * @event: the #GstEvent to send to the pad.
2973 * Sends the event to the peer of the given pad. This function is
2974 * mainly used by elements to send events to their peer
2977 * Returns: TRUE if the event was handled.
2982 gst_pad_push_event (GstPad * pad, GstEvent * event)
2987 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2988 g_return_val_if_fail (event != NULL, FALSE);
2991 peerpad = GST_PAD_PEER (pad);
2992 if (peerpad == NULL)
2995 gst_object_ref (peerpad);
2998 result = gst_pad_send_event (peerpad, event);
3000 gst_object_unref (peerpad);
3004 /* ERROR handling */
3007 gst_event_unref (event);
3014 * gst_pad_send_event:
3015 * @pad: a #GstPad to send the event to.
3016 * @event: the #GstEvent to send to the pad.
3018 * Sends the event to the pad. This function can be used
3019 * by applications to send events in the pipeline.
3021 * Returns: TRUE if the event was handled.
3024 gst_pad_send_event (GstPad * pad, GstEvent * event)
3026 gboolean result = FALSE;
3027 GstPadEventFunction eventfunc;
3029 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3030 g_return_val_if_fail (event != NULL, FALSE);
3034 if (GST_EVENT_SRC (event) == NULL)
3035 GST_EVENT_SRC (event) = gst_object_ref (pad);
3037 switch (GST_EVENT_TYPE (event)) {
3038 case GST_EVENT_FLUSH:
3039 GST_CAT_DEBUG (GST_CAT_EVENT, "have event type %d (FLUSH) on pad %s:%s",
3040 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (pad));
3042 if (GST_EVENT_FLUSH_DONE (event)) {
3043 GST_PAD_UNSET_FLUSHING (pad);
3044 GST_CAT_DEBUG (GST_CAT_EVENT, "cleared flush flag");
3046 /* can't even accept a flush begin event when flushing */
3047 if (GST_PAD_IS_FLUSHING (pad))
3049 GST_PAD_SET_FLUSHING (pad);
3050 GST_CAT_DEBUG (GST_CAT_EVENT, "set flush flag");
3054 GST_CAT_DEBUG (GST_CAT_EVENT, "have event type %d on pad %s:%s",
3055 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (pad));
3057 if (GST_PAD_IS_FLUSHING (pad))
3062 if ((eventfunc = GST_PAD_EVENTFUNC (pad)) == NULL)
3065 gst_object_ref (pad);
3068 result = eventfunc (GST_PAD_CAST (pad), event);
3070 gst_object_unref (pad);
3074 /* ERROR handling */
3077 g_warning ("pad %s:%s has no event handler, file a bug.",
3078 GST_DEBUG_PAD_NAME (pad));
3080 gst_event_unref (event);
3086 GST_CAT_DEBUG (GST_CAT_EVENT, "Received event on flushing pad. Discarding");
3087 gst_event_unref (event);
3092 /************************************************************************
3097 static void gst_pad_template_class_init (GstPadTemplateClass * klass);
3098 static void gst_pad_template_init (GstPadTemplate * templ);
3099 static void gst_pad_template_dispose (GObject * object);
3102 gst_pad_template_get_type (void)
3104 static GType padtemplate_type = 0;
3106 if (!padtemplate_type) {
3107 static const GTypeInfo padtemplate_info = {
3108 sizeof (GstPadTemplateClass), NULL, NULL,
3109 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
3110 sizeof (GstPadTemplate),
3112 (GInstanceInitFunc) gst_pad_template_init, NULL
3116 g_type_register_static (GST_TYPE_OBJECT, "GstPadTemplate",
3117 &padtemplate_info, 0);
3119 return padtemplate_type;
3123 gst_pad_template_class_init (GstPadTemplateClass * klass)
3125 GObjectClass *gobject_class;
3126 GstObjectClass *gstobject_class;
3128 gobject_class = (GObjectClass *) klass;
3129 gstobject_class = (GstObjectClass *) klass;
3131 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
3133 gst_pad_template_signals[TEMPL_PAD_CREATED] =
3134 g_signal_new ("pad-created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
3135 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
3136 NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
3138 gobject_class->dispose = gst_pad_template_dispose;
3140 gstobject_class->path_string_separator = "*";
3144 gst_pad_template_init (GstPadTemplate * templ)
3149 gst_pad_template_dispose (GObject * object)
3151 GstPadTemplate *templ = GST_PAD_TEMPLATE (object);
3153 g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
3154 if (GST_PAD_TEMPLATE_CAPS (templ)) {
3155 gst_caps_unref (GST_PAD_TEMPLATE_CAPS (templ));
3158 G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object);
3161 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
3163 * SOMETIMES padtemplates can do whatever they want, they are provided by the
3165 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
3166 * 'sink%d' template is automatically selected), so we need to restrict their
3170 name_is_valid (const gchar * name, GstPadPresence presence)
3174 if (presence == GST_PAD_ALWAYS) {
3175 if (strchr (name, '%')) {
3176 g_warning ("invalid name template %s: conversion specifications are not"
3177 " allowed for GST_PAD_ALWAYS padtemplates", name);
3180 } else if (presence == GST_PAD_REQUEST) {
3181 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
3182 g_warning ("invalid name template %s: only one conversion specification"
3183 " allowed in GST_PAD_REQUEST padtemplate", name);
3186 if (str && (*(str + 1) != 's' && *(str + 1) != 'd')) {
3187 g_warning ("invalid name template %s: conversion specification must be of"
3188 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
3191 if (str && (*(str + 2) != '\0')) {
3192 g_warning ("invalid name template %s: conversion specification must"
3193 " appear at the end of the GST_PAD_REQUEST padtemplate name", name);
3202 * gst_static_pad_template_get:
3203 * @pad_template: the static pad template
3205 * Converts a #GstStaticPadTemplate into a #GstPadTemplate.
3207 * Returns: a new #GstPadTemplate.
3210 gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
3212 GstPadTemplate *new;
3214 if (!name_is_valid (pad_template->name_template, pad_template->presence))
3217 new = g_object_new (gst_pad_template_get_type (),
3218 "name", pad_template->name_template, NULL);
3220 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (pad_template->name_template);
3221 GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction;
3222 GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence;
3224 GST_PAD_TEMPLATE_CAPS (new) =
3225 gst_caps_copy (gst_static_caps_get (&pad_template->static_caps));
3231 * gst_pad_template_new:
3232 * @name_template: the name template.
3233 * @direction: the #GstPadDirection of the template.
3234 * @presence: the #GstPadPresence of the pad.
3235 * @caps: a #GstCaps set for the template. The caps are taken ownership of.
3237 * Creates a new pad template with a name according to the given template
3238 * and with the given arguments. This functions takes ownership of the provided
3239 * caps, so be sure to not use them afterwards.
3241 * Returns: a new #GstPadTemplate.
3244 gst_pad_template_new (const gchar * name_template,
3245 GstPadDirection direction, GstPadPresence presence, GstCaps * caps)
3247 GstPadTemplate *new;
3249 g_return_val_if_fail (name_template != NULL, NULL);
3250 g_return_val_if_fail (caps != NULL, NULL);
3251 g_return_val_if_fail (direction == GST_PAD_SRC
3252 || direction == GST_PAD_SINK, NULL);
3253 g_return_val_if_fail (presence == GST_PAD_ALWAYS
3254 || presence == GST_PAD_SOMETIMES || presence == GST_PAD_REQUEST, NULL);
3256 if (!name_is_valid (name_template, presence))
3259 new = g_object_new (gst_pad_template_get_type (),
3260 "name", name_template, NULL);
3262 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
3263 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
3264 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
3265 GST_PAD_TEMPLATE_CAPS (new) = caps;
3271 * gst_static_pad_template_get_caps:
3272 * @templ: a #GstStaticPadTemplate to get capabilities of.
3274 * Gets the capabilities of the static pad template.
3276 * Returns: the #GstCaps of the static pad template. If you need to keep a
3277 * reference to the caps, take a ref (see gst_caps_ref ()).
3280 gst_static_pad_template_get_caps (GstStaticPadTemplate * templ)
3282 g_return_val_if_fail (templ, NULL);
3284 return (GstCaps *) gst_static_caps_get (&templ->static_caps);
3288 * gst_pad_template_get_caps:
3289 * @templ: a #GstPadTemplate to get capabilities of.
3291 * Gets the capabilities of the pad template.
3293 * Returns: the #GstCaps of the pad template. If you need to keep a reference to
3294 * the caps, take a ref (see gst_caps_ref ()).
3297 gst_pad_template_get_caps (GstPadTemplate * templ)
3299 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
3301 return GST_PAD_TEMPLATE_CAPS (templ);
3305 * gst_pad_set_element_private:
3306 * @pad: the #GstPad to set the private data of.
3307 * @priv: The private data to attach to the pad.
3309 * Set the given private data gpointer on the pad.
3310 * This function can only be used by the element that owns the pad.
3313 gst_pad_set_element_private (GstPad * pad, gpointer priv)
3315 pad->element_private = priv;
3319 * gst_pad_get_element_private:
3320 * @pad: the #GstPad to get the private data of.
3322 * Gets the private data of a pad.
3324 * Returns: a #gpointer to the private data.
3327 gst_pad_get_element_private (GstPad * pad)
3329 return pad->element_private;
3333 * gst_pad_start_task:
3334 * @pad: the #GstPad to start the task of
3335 * @func: the task function to call
3336 * @data: data passed to the task function
3338 * Starts a task that repeadedly calls @func with @data. This function
3339 * is nostly used in the pad activation function to start the
3340 * dataflow. This function will automatically acauire the STREAM_LOCK of
3341 * the pad before calling @func.
3343 * Returns: a TRUE if the task could be started. FALSE when the pad has
3344 * no parent or the parent has no scheduler.
3347 gst_pad_start_task (GstPad * pad, GstTaskFunction func, gpointer data)
3350 GstScheduler *sched;
3353 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3354 g_return_val_if_fail (func != NULL, FALSE);
3357 parent = GST_PAD_PARENT (pad);
3359 if (parent == NULL || !GST_IS_ELEMENT (parent))
3362 sched = GST_ELEMENT_SCHEDULER (parent);
3366 task = GST_PAD_TASK (pad);
3368 task = gst_scheduler_create_task (sched, func, data);
3369 gst_task_set_lock (task, GST_STREAM_GET_LOCK (pad));
3371 GST_PAD_TASK (pad) = task;
3375 gst_task_start (task);
3383 GST_DEBUG ("no parent");
3389 GST_DEBUG ("no scheduler");
3395 * gst_pad_pause_task:
3396 * @pad: the #GstPad to pause the task of
3398 * Pause the task of @pad. This function will also make sure that the
3399 * function executed by the task will effectively stop.
3401 * Returns: a TRUE if the task could be paused or FALSE when the pad
3405 gst_pad_pause_task (GstPad * pad)
3409 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3412 task = GST_PAD_TASK (pad);
3415 gst_task_pause (task);
3418 GST_STREAM_LOCK (pad);
3419 GST_STREAM_UNLOCK (pad);
3431 * gst_pad_stop_task:
3432 * @pad: the #GstPad to stop the task of
3434 * Stop the task of @pad. This function will also make sure that the
3435 * function executed by the task will effectively stop.
3437 * Returns: a TRUE if the task could be stopped or FALSE when the pad
3441 gst_pad_stop_task (GstPad * pad)
3445 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3448 task = GST_PAD_TASK (pad);
3451 GST_PAD_TASK (pad) = NULL;
3454 gst_task_stop (task);
3456 GST_STREAM_LOCK (pad);
3457 GST_STREAM_UNLOCK (pad);
3459 gst_object_unref (task);