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"
27 #include "gstelement.h"
29 #include "gstscheduler.h"
35 #define GST_CAT_DEFAULT GST_CAT_PADS
38 #define gst_caps_debug(a,b) GST_DEBUG_CAPS(b,a)
47 static GstObject *padtemplate_parent_class = NULL;
48 static guint gst_pad_template_signals[TEMPL_LAST_SIGNAL] = { 0 };
50 GType _gst_pad_type = 0;
52 /***** Start with the base GstPad class *****/
53 static void gst_pad_class_init (GstPadClass *klass);
54 static void gst_pad_init (GstPad *pad);
55 static void gst_pad_dispose (GObject *object);
57 static void gst_pad_set_pad_template (GstPad *pad, GstPadTemplate *templ);
58 static GstCaps * _gst_pad_default_fixate_func (GstPad *pad, const GstCaps *caps);
60 static gboolean gst_pad_link_try (GstPadLink *link);
61 static void gst_pad_link_free (GstPadLink *link);
63 #ifndef GST_DISABLE_LOADSAVE
64 static xmlNodePtr gst_pad_save_thyself (GstObject *object, xmlNodePtr parent);
67 static GstObject *pad_parent_class = NULL;
70 gst_pad_get_type (void)
73 static const GTypeInfo pad_info = {
74 sizeof (GstPadClass), NULL, NULL,
75 (GClassInitFunc) gst_pad_class_init, NULL, NULL,
78 (GInstanceInitFunc) gst_pad_init, NULL
80 _gst_pad_type = g_type_register_static (GST_TYPE_OBJECT, "GstPad",
87 gst_pad_class_init (GstPadClass *klass)
89 GObjectClass *gobject_class;
91 gobject_class = (GObjectClass*) klass;
93 pad_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
95 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_pad_dispose);
99 gst_pad_init (GstPad *pad)
101 /* all structs are initialized to NULL by glib */
104 gst_pad_dispose (GObject *object)
106 GstPad *pad = GST_PAD (object);
108 gst_pad_set_pad_template (pad, NULL);
110 G_OBJECT_CLASS (pad_parent_class)->dispose (object);
115 /***** Then do the Real Pad *****/
116 /* Pad signals and args */
118 REAL_CAPS_NEGO_FAILED,
133 static void gst_real_pad_class_init (GstRealPadClass *klass);
134 static void gst_real_pad_init (GstRealPad *pad);
135 static void gst_real_pad_dispose (GObject *object);
137 static gboolean _gst_real_pad_fixate_accumulator (GSignalInvocationHint *ihint,
138 GValue *return_accu, const GValue *handler_return, gpointer dummy);
139 static void gst_real_pad_set_property (GObject *object, guint prop_id,
142 static void gst_real_pad_get_property (GObject *object, guint prop_id,
146 GType _gst_real_pad_type = 0;
148 static GstPad *real_pad_parent_class = NULL;
149 static guint gst_real_pad_signals[REAL_LAST_SIGNAL] = { 0 };
152 gst_real_pad_get_type (void) {
153 if (!_gst_real_pad_type) {
154 static const GTypeInfo pad_info = {
155 sizeof (GstRealPadClass), NULL, NULL,
156 (GClassInitFunc) gst_real_pad_class_init, NULL, NULL,
159 (GInstanceInitFunc) gst_real_pad_init, NULL
161 _gst_real_pad_type = g_type_register_static (GST_TYPE_PAD, "GstRealPad",
164 return _gst_real_pad_type;
168 gst_real_pad_class_init (GstRealPadClass *klass)
170 GObjectClass *gobject_class;
171 GstObjectClass *gstobject_class;
173 gobject_class = (GObjectClass*) klass;
174 gstobject_class = (GstObjectClass*) klass;
176 real_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
178 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_real_pad_dispose);
179 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_real_pad_set_property);
180 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_real_pad_get_property);
182 gst_real_pad_signals[REAL_CAPS_NEGO_FAILED] =
183 g_signal_new ("caps_nego_failed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
184 G_STRUCT_OFFSET (GstRealPadClass, caps_nego_failed), NULL, NULL,
185 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
187 gst_real_pad_signals[REAL_LINKED] =
188 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
189 G_STRUCT_OFFSET (GstRealPadClass, linked), NULL, NULL,
190 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
192 gst_real_pad_signals[REAL_UNLINKED] =
193 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
194 G_STRUCT_OFFSET (GstRealPadClass, unlinked), NULL, NULL,
195 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
197 gst_real_pad_signals[REAL_FIXATE] =
198 g_signal_new ("fixate", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
199 G_STRUCT_OFFSET (GstRealPadClass, appfixatefunc),
200 _gst_real_pad_fixate_accumulator, NULL,
201 gst_marshal_POINTER__POINTER, G_TYPE_POINTER, 1,
204 /* gtk_object_add_arg_type ("GstRealPad::active", G_TYPE_BOOLEAN, */
205 /* GTK_ARG_READWRITE, REAL_ARG_ACTIVE); */
206 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_ACTIVE,
207 g_param_spec_boolean ("active", "Active", "Whether the pad is active.",
208 TRUE, G_PARAM_READWRITE));
209 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_CAPS,
210 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
211 GST_TYPE_CAPS, G_PARAM_READABLE));
213 #ifndef GST_DISABLE_LOADSAVE
214 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
216 gstobject_class->path_string_separator = ".";
220 _gst_real_pad_fixate_accumulator (GSignalInvocationHint *ihint,
221 GValue *return_accu, const GValue *handler_return, gpointer dummy)
223 if (g_value_get_pointer (handler_return)) {
224 g_value_copy (handler_return, return_accu);
225 /* stop emission if something was returned */
232 gst_real_pad_init (GstRealPad *pad)
234 pad->direction = GST_PAD_UNKNOWN;
237 pad->chainfunc = NULL;
240 pad->chainhandler = NULL;
241 pad->gethandler = NULL;
243 pad->ghostpads = NULL;
246 pad->linkfunc = NULL;
247 pad->getcapsfunc = NULL;
249 pad->eventfunc = gst_pad_event_default;
250 pad->convertfunc = gst_pad_convert_default;
251 pad->queryfunc = gst_pad_query_default;
252 pad->intlinkfunc = gst_pad_get_internal_links_default;
254 pad->eventmaskfunc = gst_pad_get_event_masks_default;
255 pad->formatsfunc = gst_pad_get_formats_default;
256 pad->querytypefunc = gst_pad_get_query_types_default;
258 GST_FLAG_SET (pad, GST_PAD_DISABLED);
259 GST_FLAG_UNSET (pad, GST_PAD_NEGOTIATING);
261 gst_probe_dispatcher_init (&pad->probedisp);
265 gst_real_pad_set_property (GObject *object, guint prop_id,
266 const GValue *value, GParamSpec *pspec)
268 g_return_if_fail (GST_IS_PAD (object));
271 case REAL_ARG_ACTIVE:
272 gst_pad_set_active (GST_PAD (object), g_value_get_boolean (value));
275 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
281 gst_real_pad_get_property (GObject *object, guint prop_id,
282 GValue *value, GParamSpec *pspec)
284 g_return_if_fail (GST_IS_PAD (object));
287 case REAL_ARG_ACTIVE:
288 g_value_set_boolean (value, !GST_FLAG_IS_SET (object, GST_PAD_DISABLED));
291 g_value_set_boxed (value, GST_PAD_CAPS (GST_REAL_PAD (object)));
294 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
301 * gst_pad_custom_new:
302 * @type: the #Gtype of the pad.
303 * @name: the name of the new pad.
304 * @direction: the #GstPadDirection of the pad.
306 * Creates a new pad with the given name and type in the given direction.
307 * If name is NULL, a guaranteed unique name (across all pads)
310 * Returns: a new #GstPad, or NULL in case of an error.
313 gst_pad_custom_new (GType type, const gchar *name,
314 GstPadDirection direction)
318 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
320 pad = g_object_new (type, NULL);
321 gst_object_set_name (GST_OBJECT (pad), name);
322 GST_RPAD_DIRECTION (pad) = direction;
324 return GST_PAD (pad);
329 * @name: the name of the new pad.
330 * @direction: the #GstPadDirection of the pad.
332 * Creates a new real pad with the given name in the given direction.
333 * If name is NULL, a guaranteed unique name (across all pads)
336 * Returns: a new #GstPad, or NULL in case of an error.
339 gst_pad_new (const gchar *name,
340 GstPadDirection direction)
342 return gst_pad_custom_new (gst_real_pad_get_type (), name, direction);
346 * gst_pad_custom_new_from_template:
347 * @type: the custom #GType of the pad.
348 * @templ: the #GstPadTemplate to instantiate from.
349 * @name: the name of the new pad.
351 * Creates a new custom pad with the given name from the given template.
352 * If name is NULL, a guaranteed unique name (across all pads)
355 * Returns: a new #GstPad, or NULL in case of an error.
358 gst_pad_custom_new_from_template (GType type, GstPadTemplate *templ,
363 g_return_val_if_fail (templ != NULL, NULL);
365 pad = gst_pad_new (name, templ->direction);
366 gst_pad_set_pad_template (pad, templ);
372 * gst_pad_new_from_template:
373 * @templ: the pad template to use
374 * @name: the name of the element
376 * Creates a new real pad with the given name from the given template.
377 * If name is NULL, a guaranteed unique name (across all pads)
380 * Returns: a new #GstPad, or NULL in case of an error.
383 gst_pad_new_from_template (GstPadTemplate *templ, const gchar *name)
385 return gst_pad_custom_new_from_template (gst_real_pad_get_type (),
390 * gst_pad_get_direction:
391 * @pad: a #GstPad to get the direction of.
393 * Gets the direction of the pad.
395 * Returns: the #GstPadDirection of the pad.
398 gst_pad_get_direction (GstPad *pad)
400 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
402 return GST_PAD_DIRECTION (pad);
406 * gst_pad_set_active:
407 * @pad: the #GstPad to activate or deactivate.
408 * @active: TRUE to activate the pad.
410 * Activates or deactivates the given pad.
413 gst_pad_set_active (GstPad *pad, gboolean active)
418 g_return_if_fail (GST_IS_PAD (pad));
420 old = GST_PAD_IS_ACTIVE (pad);
425 realpad = GST_PAD_REALIZE (pad);
428 GST_CAT_DEBUG (GST_CAT_PADS, "activating pad %s:%s",
429 GST_DEBUG_PAD_NAME (realpad));
430 GST_FLAG_UNSET (realpad, GST_PAD_DISABLED);
432 GST_CAT_DEBUG (GST_CAT_PADS, "de-activating pad %s:%s",
433 GST_DEBUG_PAD_NAME (realpad));
434 GST_FLAG_SET (realpad, GST_PAD_DISABLED);
437 g_object_notify (G_OBJECT (realpad), "active");
442 * @pad: the #GstPad to query
444 * Query if a pad is active
446 * Returns: TRUE if the pad is active.
449 gst_pad_is_active (GstPad *pad)
451 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
453 return !GST_FLAG_IS_SET (pad, GST_PAD_DISABLED);
458 * @pad: a #GstPad to set the name of.
459 * @name: the name of the pad.
461 * Sets the name of a pad. If name is NULL, then a guaranteed unique
462 * name will be assigned.
465 gst_pad_set_name (GstPad *pad, const gchar *name)
467 g_return_if_fail (GST_IS_PAD (pad));
469 gst_object_set_name (GST_OBJECT (pad), name);
474 * @pad: a #GstPad to get the name of.
476 * Gets the name of a pad.
478 * Returns: the name of the pad. This is not a newly allocated pointer
479 * so you must not free it.
482 gst_pad_get_name (GstPad *pad)
484 g_return_val_if_fail (pad != NULL, NULL);
485 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
487 return GST_OBJECT_NAME (pad);
491 * gst_pad_set_chain_function:
492 * @pad: a #GstPad to set the chain function for.
493 * @chain: the #GstPadChainFunction to set.
495 * Sets the given chain function for the pad.
498 gst_pad_set_chain_function (GstPad *pad, GstPadChainFunction chain)
500 g_return_if_fail (pad != NULL);
501 g_return_if_fail (GST_IS_REAL_PAD (pad));
502 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SINK);
504 GST_RPAD_CHAINFUNC (pad) = chain;
505 GST_CAT_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
506 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
510 * gst_pad_set_get_function:
511 * @pad: a #GstPad to set the get function for.
512 * @get: the #GstPadGetFunction to set.
514 * Sets the given get function for the pad.
517 gst_pad_set_get_function (GstPad *pad,
518 GstPadGetFunction get)
520 g_return_if_fail (pad != NULL);
521 g_return_if_fail (GST_IS_REAL_PAD (pad));
522 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SRC);
524 GST_RPAD_GETFUNC (pad) = get;
526 GST_CAT_DEBUG (GST_CAT_PADS, "getfunc for %s:%s set to %s",
527 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
531 * gst_pad_set_event_function:
532 * @pad: a #GstPad to set the event handler for.
533 * @event: the #GstPadEventFunction to set.
535 * Sets the given event handler for the pad.
538 gst_pad_set_event_function (GstPad *pad,
539 GstPadEventFunction event)
541 g_return_if_fail (GST_IS_REAL_PAD (pad));
542 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SRC);
544 GST_RPAD_EVENTFUNC (pad) = event;
546 GST_CAT_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
547 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
551 * gst_pad_set_event_mask_function:
552 * @pad: a #GstPad to set the event mask function for.
553 * @mask_func: the #GstPadEventMaskFunction to set.
555 * Sets the given event mask function for the pad.
558 gst_pad_set_event_mask_function (GstPad *pad,
559 GstPadEventMaskFunction mask_func)
561 g_return_if_fail (GST_IS_REAL_PAD (pad));
563 GST_RPAD_EVENTMASKFUNC (pad) = mask_func;
565 GST_CAT_DEBUG (GST_CAT_PADS, "eventmaskfunc for %s:%s set to %s",
566 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (mask_func));
570 * gst_pad_get_event_masks:
571 * @pad: a #GstPad to get the event mask for.
573 * Gets the array of eventmasks from the given pad.
575 * Returns: an array with eventmasks, the list is ended
579 gst_pad_get_event_masks (GstPad *pad)
586 rpad = GST_PAD_REALIZE (pad);
588 g_return_val_if_fail (rpad, FALSE);
590 if (GST_RPAD_EVENTMASKFUNC (rpad))
591 return GST_RPAD_EVENTMASKFUNC (rpad) (GST_PAD (pad));
597 gst_pad_get_event_masks_dispatcher (GstPad *pad, const GstEventMask **data)
599 *data = gst_pad_get_event_masks (pad);
605 * gst_pad_get_event_masks_default:
606 * @pad: a #GstPad to get the event mask for.
608 * Invokes the default event masks dispatcher on the pad.
610 * Returns: an array with eventmasks, the list is ended
614 gst_pad_get_event_masks_default (GstPad *pad)
616 GstEventMask *result = NULL;
618 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
619 gst_pad_get_event_masks_dispatcher, &result);
625 * gst_pad_set_convert_function:
626 * @pad: a #GstPad to set the convert function for.
627 * @convert: the #GstPadConvertFunction to set.
629 * Sets the given convert function for the pad.
632 gst_pad_set_convert_function (GstPad *pad,
633 GstPadConvertFunction convert)
635 g_return_if_fail (pad != NULL);
636 g_return_if_fail (GST_IS_REAL_PAD (pad));
638 GST_RPAD_CONVERTFUNC (pad) = convert;
640 GST_CAT_DEBUG (GST_CAT_PADS, "convertfunc for %s:%s set to %s",
641 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (convert));
645 * gst_pad_set_query_function:
646 * @pad: the #GstPad to set the query function for.
647 * @query: the #GstPadQueryFunction to set.
649 * Set the given query function for the pad.
652 gst_pad_set_query_function (GstPad *pad, GstPadQueryFunction query)
654 g_return_if_fail (pad != NULL);
655 g_return_if_fail (GST_IS_REAL_PAD (pad));
657 GST_RPAD_QUERYFUNC (pad) = query;
659 GST_CAT_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
660 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
664 * gst_pad_set_query_type_function:
665 * @pad: the #GstPad to set the query type function for.
666 * @type_func: the #GstPadQueryTypeFunction to set.
668 * Set the given query type function for the pad.
671 gst_pad_set_query_type_function (GstPad *pad, GstPadQueryTypeFunction type_func)
673 g_return_if_fail (pad != NULL);
674 g_return_if_fail (GST_IS_REAL_PAD (pad));
676 GST_RPAD_QUERYTYPEFUNC (pad) = type_func;
678 GST_CAT_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
679 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
683 * gst_pad_get_query_types:
684 * @pad: the #GstPad to query
686 * Get an array of supported queries that can be performed
689 * Returns: an array of querytypes anded with 0.
692 gst_pad_get_query_types (GstPad *pad)
699 rpad = GST_PAD_REALIZE (pad);
701 g_return_val_if_fail (rpad, FALSE);
703 if (GST_RPAD_QUERYTYPEFUNC (rpad))
704 return GST_RPAD_QUERYTYPEFUNC (rpad) (GST_PAD (pad));
710 gst_pad_get_query_types_dispatcher (GstPad *pad, const GstQueryType **data)
712 *data = gst_pad_get_query_types (pad);
718 * gst_pad_get_query_types_default:
719 * @pad: the #GstPad to query
721 * Invoke the default dispatcher for the query types on
724 * Returns: an array of querytypes anded with 0.
727 gst_pad_get_query_types_default (GstPad *pad)
729 GstQueryType *result = NULL;
731 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
732 gst_pad_get_query_types_dispatcher, &result);
738 * gst_pad_set_internal_link_function:
739 * @pad: a #GstPad to set the internal link function for.
740 * @intlink: the #GstPadIntLinkFunction to set.
742 * Sets the given internal link function for the pad.
745 gst_pad_set_internal_link_function (GstPad *pad,
746 GstPadIntLinkFunction intlink)
748 g_return_if_fail (pad != NULL);
749 g_return_if_fail (GST_IS_REAL_PAD (pad));
751 GST_RPAD_INTLINKFUNC (pad) = intlink;
752 GST_CAT_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
753 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
757 * gst_pad_set_formats_function:
758 * @pad: the #GstPad to set the formats function for.
759 * @formats: the #GstPadFormatsFunction to set.
761 * Sets the given formats function for the pad.
764 gst_pad_set_formats_function (GstPad *pad, GstPadFormatsFunction formats)
766 g_return_if_fail (pad != NULL);
767 g_return_if_fail (GST_IS_REAL_PAD (pad));
769 GST_RPAD_FORMATSFUNC (pad) = formats;
770 GST_CAT_DEBUG (GST_CAT_PADS, "formats function for %s:%s set to %s",
771 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (formats));
775 * gst_pad_set_link_function:
776 * @pad: a #GstPad to set the link function for.
777 * @link: the #GstPadLinkFunction to set.
779 * Sets the given link function for the pad. It will be called
780 * when the pad is linked or relinked with caps.
783 gst_pad_set_link_function (GstPad *pad,
784 GstPadLinkFunction link)
786 g_return_if_fail (pad != NULL);
787 g_return_if_fail (GST_IS_REAL_PAD (pad));
789 GST_RPAD_LINKFUNC (pad) = link;
790 GST_CAT_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
791 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
795 * gst_pad_set_unlink_function:
796 * @pad: a #GstPad to set the unlink function for.
797 * @unlink: the #GstPadUnlinkFunction to set.
799 * Sets the given unlink function for the pad. It will be called
800 * when the pad is unlinked.
803 gst_pad_set_unlink_function (GstPad *pad,
804 GstPadUnlinkFunction unlink)
806 g_return_if_fail (pad != NULL);
807 g_return_if_fail (GST_IS_REAL_PAD (pad));
809 GST_RPAD_UNLINKFUNC (pad) = unlink;
810 GST_CAT_DEBUG (GST_CAT_PADS, "unlinkfunc for %s:%s set to %s",
811 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (unlink));
815 * gst_pad_set_fixate_function:
816 * @pad: a #GstPad to set the fixate function for.
817 * @getcaps: the #GstPadFixateFunction to set.
819 * Sets the given fixate function for the pad.
822 gst_pad_set_fixate_function (GstPad *pad, GstPadFixateFunction fixate)
824 g_return_if_fail (pad != NULL);
825 g_return_if_fail (GST_IS_REAL_PAD (pad));
827 GST_RPAD_FIXATEFUNC (pad) = fixate;
828 GST_CAT_DEBUG (GST_CAT_PADS, "fixatefunc for %s:%s set to %s",
829 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (fixate));
833 * gst_pad_set_getcaps_function:
834 * @pad: a #GstPad to set the getcaps function for.
835 * @getcaps: the #GstPadGetCapsFunction to set.
837 * Sets the given getcaps function for the pad.
840 gst_pad_set_getcaps_function (GstPad *pad,
841 GstPadGetCapsFunction getcaps)
843 g_return_if_fail (pad != NULL);
844 g_return_if_fail (GST_IS_REAL_PAD (pad));
846 GST_RPAD_GETCAPSFUNC (pad) = getcaps;
847 GST_CAT_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
848 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
852 * gst_pad_set_bufferalloc_function:
853 * @pad: a #GstPad to set the bufferalloc function for.
854 * @bufalloc: the #GstPadBufferAllocFunction to set.
856 * Sets the given bufferalloc function for the pad. Note that the
857 * bufferalloc function can only be set on sinkpads.
860 gst_pad_set_bufferalloc_function (GstPad *pad,
861 GstPadBufferAllocFunction bufalloc)
863 g_return_if_fail (pad != NULL);
864 g_return_if_fail (GST_IS_REAL_PAD (pad));
865 g_return_if_fail (GST_PAD_IS_SINK (pad));
867 GST_RPAD_BUFFERALLOCFUNC (pad) = bufalloc;
868 GST_CAT_DEBUG (GST_CAT_PADS, "bufferallocfunc for %s:%s set to %s",
869 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufalloc));
874 * @srcpad: the source #GstPad to unlink.
875 * @sinkpad: the sink #GstPad to unlink.
877 * Unlinks the source pad from the sink pad.
880 gst_pad_unlink (GstPad *srcpad,
883 GstRealPad *realsrc, *realsink;
884 GstScheduler *src_sched, *sink_sched;
887 g_return_if_fail (srcpad != NULL);
888 g_return_if_fail (GST_IS_PAD (srcpad));
889 g_return_if_fail (sinkpad != NULL);
890 g_return_if_fail (GST_IS_PAD (sinkpad));
892 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
893 GST_DEBUG_PAD_NAME (srcpad), srcpad,
894 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
896 /* now we need to deal with the real/ghost stuff */
897 realsrc = GST_PAD_REALIZE (srcpad);
898 realsink = GST_PAD_REALIZE (sinkpad);
900 g_return_if_fail (GST_RPAD_PEER (realsrc) != NULL);
901 g_return_if_fail (GST_RPAD_PEER (realsink) == realsrc);
903 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
904 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
911 g_return_if_fail ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
912 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK));
914 if (GST_RPAD_UNLINKFUNC (realsrc)) {
915 GST_RPAD_UNLINKFUNC (realsrc) (GST_PAD (realsrc));
917 if (GST_RPAD_UNLINKFUNC (realsink)) {
918 GST_RPAD_UNLINKFUNC (realsink) (GST_PAD (realsink));
921 /* get the schedulers before we unlink */
922 src_sched = gst_pad_get_scheduler (GST_PAD (realsrc));
923 sink_sched = gst_pad_get_scheduler (GST_PAD (realsink));
925 if (GST_RPAD_LINK (realsrc)) gst_pad_link_free (GST_RPAD_LINK (realsrc));
927 /* first clear peers */
928 GST_RPAD_PEER (realsrc) = NULL;
929 GST_RPAD_PEER (realsink) = NULL;
930 GST_RPAD_LINK (realsrc) = NULL;
931 GST_RPAD_LINK (realsink) = NULL;
933 /* now tell the scheduler */
934 if (src_sched && src_sched == sink_sched) {
935 gst_scheduler_pad_unlink (src_sched,
940 /* hold a reference, as they can go away in the signal handlers */
941 gst_object_ref (GST_OBJECT (realsrc));
942 gst_object_ref (GST_OBJECT (realsink));
944 /* fire off a signal to each of the pads telling them
945 * that they've been unlinked */
946 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_UNLINKED],
948 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_UNLINKED],
951 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
952 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
954 gst_object_unref (GST_OBJECT (realsrc));
955 gst_object_unref (GST_OBJECT (realsink));
962 * Checks if a given pad is linked to another pad or not.
964 * Returns: TRUE if the pad is linked.
967 gst_pad_is_linked (GstPad *pad)
969 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
971 return GST_PAD_PEER (pad) != NULL;
989 GstPadFixateFunction app_fixate;
993 gst_pad_check_schedulers (GstRealPad *realsrc, GstRealPad *realsink)
995 GstScheduler *src_sched, *sink_sched;
996 gint num_decoupled = 0;
998 src_sched = gst_pad_get_scheduler (GST_PAD (realsrc));
999 sink_sched = gst_pad_get_scheduler (GST_PAD (realsink));
1001 if (src_sched && sink_sched) {
1002 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsrc), GST_ELEMENT_DECOUPLED))
1004 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsink), GST_ELEMENT_DECOUPLED))
1007 if (src_sched != sink_sched && num_decoupled != 1) {
1014 #define GST_PAD_LINK_SRC(pad) ((GST_PAD_IS_SRC (pad)) ? (pad) : GST_PAD_PEER (pad))
1015 #define GST_PAD_LINK_SINK(pad) ((GST_PAD_IS_SINK (pad)) ? (pad) : GST_PAD_PEER (pad))
1018 gst_pad_link_new (void)
1021 link = g_new0 (GstPadLink, 1);
1022 link->sinknotify = TRUE;
1023 link->srcnotify = TRUE;
1028 gst_pad_link_free (GstPadLink *link)
1030 if (link->srccaps) gst_caps_free (link->srccaps);
1031 if (link->sinkcaps) gst_caps_free (link->sinkcaps);
1032 if (link->filtercaps) gst_caps_free (link->filtercaps);
1033 if (link->caps) gst_caps_free (link->caps);
1034 #ifdef USE_POISONING
1035 memset(link,0xff, sizeof(*link));
1040 static void gst_pad_link_intersect (GstPadLink *link)
1042 GstCaps *pad_intersection;
1044 if (link->caps) gst_caps_free (link->caps);
1046 GST_DEBUG ("intersecting link from %s:%s to %s:%s",
1047 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1048 GST_DEBUG_CAPS ("srccaps", link->srccaps);
1049 GST_DEBUG_CAPS ("sinkcaps", link->sinkcaps);
1050 GST_DEBUG_CAPS ("filtercaps", link->filtercaps);
1052 pad_intersection = gst_caps_intersect (link->srccaps, link->sinkcaps);
1054 if (link->filtercaps) {
1055 GST_DEBUG_CAPS ("unfiltered intersection", pad_intersection);
1056 link->caps = gst_caps_intersect (pad_intersection, link->filtercaps);
1057 gst_caps_free (pad_intersection);
1059 link->caps = pad_intersection;
1062 GST_DEBUG_CAPS ("intersection", link->caps);
1066 gst_pad_link_ready_for_negotiation (GstPadLink *link)
1070 parent = GST_PAD_PARENT (link->srcpad);
1071 if (!parent || GST_STATE (parent) < GST_STATE_READY) {
1072 GST_DEBUG ("parent %s of pad %s:%s is not READY",
1073 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (link->srcpad));
1076 parent = GST_PAD_PARENT (link->sinkpad);
1077 if (!parent || GST_STATE (parent) < GST_STATE_READY) {
1078 GST_DEBUG ("parent %s of pad %s:%s is not READY",
1079 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (link->sinkpad));
1087 gst_pad_link_fixate (GstPadLink *link)
1094 g_return_if_fail (caps != NULL);
1095 g_return_if_fail (!gst_caps_is_empty(caps));
1097 GST_DEBUG_CAPS ("trying to fixate caps", caps);
1099 while (!gst_caps_is_fixed (caps)) {
1106 g_signal_emit (G_OBJECT (link->srcpad),
1107 gst_real_pad_signals[REAL_FIXATE], 0, caps, &newcaps);
1108 GST_DEBUG_CAPS ("app srcpad signal fixated to", newcaps);
1111 g_signal_emit (G_OBJECT (link->sinkpad),
1112 gst_real_pad_signals[REAL_FIXATE], 0, caps, &newcaps);
1113 GST_DEBUG_CAPS ("app sinkpad signal fixated to", newcaps);
1116 if (GST_RPAD_FIXATEFUNC(link->srcpad)) {
1117 newcaps = GST_RPAD_FIXATEFUNC(link->srcpad) (
1118 GST_PAD (link->srcpad), caps);
1119 GST_DEBUG_CAPS ("srcpad fixated to", newcaps);
1123 if (GST_RPAD_FIXATEFUNC(link->sinkpad)) {
1124 newcaps = GST_RPAD_FIXATEFUNC(link->sinkpad) (
1125 GST_PAD (link->sinkpad), caps);
1126 GST_DEBUG_CAPS ("sinkpad fixated to", newcaps);
1130 newcaps = _gst_pad_default_fixate_func (
1131 GST_PAD(link->srcpad), caps);
1132 GST_DEBUG_CAPS ("core fixated to", newcaps);
1136 gst_caps_free (caps);
1146 static GstPadLinkReturn
1147 gst_pad_link_call_link_functions (GstPadLink *link)
1149 gboolean negotiating;
1150 GstPadLinkReturn res;
1152 if (link->srcnotify && GST_RPAD_LINKFUNC (link->srcpad)){
1153 GST_DEBUG ("calling link function on pad %s:%s",
1154 GST_DEBUG_PAD_NAME (link->srcpad));
1156 negotiating = GST_FLAG_IS_SET (link->srcpad, GST_PAD_NEGOTIATING);
1158 /* set the NEGOTIATING flag if not already done */
1159 if (!negotiating) GST_FLAG_SET (link->srcpad, GST_PAD_NEGOTIATING);
1161 /* call the link function */
1162 res = GST_RPAD_LINKFUNC (link->srcpad) (GST_PAD (link->srcpad),
1165 /* unset again after negotiating only if we set it */
1166 if (!negotiating) GST_FLAG_UNSET (link->srcpad, GST_PAD_NEGOTIATING);
1168 GST_DEBUG ("got reply %d from link function on pad %s:%s",
1169 res, GST_DEBUG_PAD_NAME (link->srcpad));
1171 if (GST_PAD_LINK_FAILED (res)) {
1172 GST_CAT_INFO (GST_CAT_CAPS, "pad %s:%s doesn't accept caps",
1173 GST_DEBUG_PAD_NAME (link->srcpad));
1178 if (link->sinknotify && GST_RPAD_LINKFUNC (link->sinkpad)){
1179 GST_DEBUG ("calling link function on pad %s:%s",
1180 GST_DEBUG_PAD_NAME (link->sinkpad));
1182 negotiating = GST_FLAG_IS_SET (link->sinkpad, GST_PAD_NEGOTIATING);
1184 /* set the NEGOTIATING flag if not already done */
1185 if (!negotiating) GST_FLAG_SET (link->sinkpad, GST_PAD_NEGOTIATING);
1187 /* call the link function */
1188 res = GST_RPAD_LINKFUNC (link->sinkpad) (GST_PAD (link->sinkpad),
1191 /* unset again after negotiating only if we set it */
1192 if (!negotiating) GST_FLAG_UNSET (link->sinkpad, GST_PAD_NEGOTIATING);
1194 GST_DEBUG ("got reply %d from link function on pad %s:%s",
1195 res, GST_DEBUG_PAD_NAME (link->sinkpad));
1197 if (GST_PAD_LINK_FAILED (res)) {
1198 GST_CAT_INFO (GST_CAT_CAPS, "pad %s:%s doesn't accept caps",
1199 GST_DEBUG_PAD_NAME (link->sinkpad));
1204 return GST_PAD_LINK_OK;
1207 static GstPadLinkReturn
1208 gst_pad_link_negotiate (GstPadLink *link)
1210 GST_DEBUG ("negotiating link from pad %s:%s to pad %s:%s",
1211 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1213 if (!gst_pad_link_ready_for_negotiation (link)) {
1214 return GST_PAD_LINK_DELAYED;
1217 gst_pad_link_intersect (link);
1218 if (gst_caps_is_empty (link->caps))
1219 return GST_PAD_LINK_REFUSED;
1221 gst_pad_link_fixate (link);
1222 if (gst_caps_is_empty (link->caps))
1223 return GST_PAD_LINK_REFUSED;
1225 return gst_pad_link_call_link_functions (link);
1230 * @link: link to try
1232 * Tries to (re)link the pads with the given link. The function takes ownership
1233 * of the supplied link. If the function returns FALSE and an old link existed,
1234 * that link can be assumed to work unchanged.
1236 * Returns: TRUE if the link succeeded, FALSE if not.
1239 gst_pad_link_try (GstPadLink *link)
1241 GstPad *srcpad, *sinkpad;
1242 GstPadLink *oldlink;
1243 GstPadLinkReturn ret;
1245 /* we use assertions here, because this function is static */
1247 srcpad = link->srcpad;
1249 sinkpad = link->sinkpad;
1251 oldlink = GST_RPAD_LINK (srcpad);
1252 g_assert (oldlink == GST_RPAD_LINK (sinkpad));
1254 ret = gst_pad_link_negotiate (link);
1255 if (GST_PAD_LINK_FAILED (ret) && oldlink && oldlink->caps) {
1256 oldlink->srcnotify = link->srcnotify;
1257 oldlink->sinknotify = link->sinknotify;
1258 if (GST_PAD_LINK_FAILED (gst_pad_link_call_link_functions (oldlink))) {
1259 g_warning ("pads don't accept old caps. We assume they did though");
1262 if (ret == GST_PAD_LINK_REFUSED) {
1263 gst_pad_link_free (link);
1266 if (ret == GST_PAD_LINK_DELAYED) {
1267 gst_caps_replace (&link->caps, NULL);
1270 GST_RPAD_PEER (srcpad) = GST_REAL_PAD(link->sinkpad);
1271 GST_RPAD_PEER (sinkpad) = GST_REAL_PAD(link->srcpad);
1273 gst_pad_link_free (oldlink);
1274 GST_RPAD_LINK (srcpad) = link;
1275 GST_RPAD_LINK (sinkpad) = link;
1276 if (ret == GST_PAD_LINK_OK) {
1277 g_object_notify (G_OBJECT (srcpad), "caps");
1278 g_object_notify (G_OBJECT (sinkpad), "caps");
1285 gst_pad_renegotiate (GstPad *pad)
1289 g_return_val_if_fail (pad != NULL, GST_PAD_LINK_REFUSED);
1290 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
1292 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1293 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1295 link = gst_pad_link_new ();
1297 link->srcpad = GST_PAD_LINK_SRC (pad);
1298 link->sinkpad = GST_PAD_LINK_SINK (pad);
1300 if (!gst_pad_link_ready_for_negotiation (link)) {
1301 gst_pad_link_free (link);
1302 return GST_PAD_LINK_DELAYED;
1305 if (GST_REAL_PAD(pad)->link->filtercaps) {
1306 link->filtercaps = gst_caps_copy (GST_REAL_PAD(pad)->link->filtercaps);
1308 link->srccaps = gst_pad_get_caps (link->srcpad);
1309 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1311 return gst_pad_link_try (link);
1315 gst_pad_try_set_caps (GstPad *pad, const GstCaps *caps)
1318 GstPadLink *oldlink;
1319 GstPadLinkReturn ret;
1321 g_return_val_if_fail (pad != NULL, GST_PAD_LINK_REFUSED);
1322 g_return_val_if_fail (GST_IS_REAL_PAD (pad), GST_PAD_LINK_REFUSED);
1323 g_return_val_if_fail (!GST_FLAG_IS_SET (pad, GST_PAD_NEGOTIATING),
1324 GST_PAD_LINK_REFUSED);
1326 /* setting non-fixed caps on a pad is not allowed */
1327 if (!gst_caps_is_fixed (caps)) {
1328 GST_CAT_INFO (GST_CAT_CAPS,
1329 "trying to set unfixed caps on pad %s:%s, not allowed",
1330 GST_DEBUG_PAD_NAME (pad));
1331 g_warning ("trying to set non fixed caps on pad %s:%s, not allowed",
1332 GST_DEBUG_PAD_NAME (pad));
1334 gst_caps_debug (caps, "unfixed caps");
1335 return GST_PAD_LINK_REFUSED;
1338 /* we allow setting caps on non-linked pads. It's ignored */
1339 if (!GST_PAD_PEER (pad)) {
1340 return GST_PAD_LINK_OK;
1343 /* if the desired caps are already there, it's trivially ok */
1344 if (GST_PAD_CAPS (pad) && gst_caps_is_equal_fixed (caps,
1345 GST_PAD_CAPS (pad))) {
1346 return GST_PAD_LINK_OK;
1349 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1350 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1352 link = gst_pad_link_new ();
1354 link->srcpad = GST_PAD_LINK_SRC (pad);
1355 link->sinkpad = GST_PAD_LINK_SINK (pad);
1357 if (!gst_pad_link_ready_for_negotiation (link)) {
1358 gst_pad_link_free (link);
1359 return GST_PAD_LINK_DELAYED;
1362 oldlink = GST_REAL_PAD(pad)->link;
1363 if (oldlink && oldlink->filtercaps) {
1364 link->filtercaps = gst_caps_copy (oldlink->filtercaps);
1366 if (link->srcpad == pad) {
1367 link->srccaps = gst_caps_copy(caps);
1368 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1369 link->srcnotify = FALSE;
1371 link->srccaps = gst_pad_get_caps (link->srcpad);
1372 link->sinkcaps = gst_caps_copy(caps);
1373 link->sinknotify = FALSE;
1376 ret = gst_pad_link_try (link);
1390 * gst_pad_can_link_filtered:
1391 * @srcpad: the source #GstPad to link.
1392 * @sinkpad: the sink #GstPad to link.
1393 * @filtercaps: the filter #GstCaps.
1395 * Checks if the source pad and the sink pad can be linked when constrained
1396 * by the given filter caps.
1398 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1401 gst_pad_can_link_filtered (GstPad *srcpad, GstPad *sinkpad,
1402 const GstCaps *filtercaps)
1404 GstRealPad *realsrc, *realsink;
1407 /* FIXME This function is gross. It's almost a direct copy of
1408 * gst_pad_link_filtered(). Any decent programmer would attempt
1409 * to merge the two functions, which I will do some day. --ds
1412 /* generic checks */
1413 g_return_val_if_fail (srcpad != NULL, FALSE);
1414 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1415 g_return_val_if_fail (sinkpad != NULL, FALSE);
1416 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1418 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1419 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1421 /* now we need to deal with the real/ghost stuff */
1422 realsrc = GST_PAD_REALIZE (srcpad);
1423 realsink = GST_PAD_REALIZE (sinkpad);
1425 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1426 GST_CAT_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
1427 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1429 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1430 if (GST_RPAD_PEER (realsrc) != NULL) {
1431 GST_CAT_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1432 GST_DEBUG_PAD_NAME (realsrc));
1435 if (GST_RPAD_PEER (realsink) != NULL) {
1436 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1437 GST_DEBUG_PAD_NAME (realsink));
1440 if (GST_PAD_PARENT (realsrc) == NULL) {
1441 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1442 GST_DEBUG_PAD_NAME (realsrc));
1445 if (GST_PAD_PARENT (realsink) == NULL) {
1446 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has no parent, failed",
1447 GST_DEBUG_PAD_NAME (realsrc));
1451 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1452 g_warning ("linking pads with different scheds requires "
1453 "exactly one decoupled element (such as queue)");
1457 g_return_val_if_fail (realsrc != NULL, GST_PAD_LINK_REFUSED);
1458 g_return_val_if_fail (realsink != NULL, GST_PAD_LINK_REFUSED);
1460 link = gst_pad_link_new ();
1462 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
1463 link->srcpad = GST_PAD (realsrc);
1464 link->sinkpad = GST_PAD (realsink);
1466 link->srcpad = GST_PAD (realsink);
1467 link->sinkpad = GST_PAD (realsrc);
1470 if (GST_RPAD_DIRECTION (link->srcpad) != GST_PAD_SRC) {
1471 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s is not a source pad, failed",
1472 GST_DEBUG_PAD_NAME (link->srcpad));
1473 gst_pad_link_free (link);
1476 if (GST_RPAD_DIRECTION (link->sinkpad) != GST_PAD_SINK) {
1477 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1478 GST_DEBUG_PAD_NAME (link->sinkpad));
1479 gst_pad_link_free (link);
1483 link->srccaps = gst_pad_get_caps (link->srcpad);
1484 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1485 if (filtercaps) link->filtercaps = gst_caps_copy (filtercaps);
1487 gst_pad_link_intersect (link);
1488 if (gst_caps_is_empty (link->caps))
1496 * @srcpad: the source #GstPad to link.
1497 * @sinkpad: the sink #GstPad to link.
1499 * Checks if the source pad and the sink pad can be link.
1501 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1504 gst_pad_can_link (GstPad *srcpad, GstPad *sinkpad)
1506 return gst_pad_can_link_filtered (srcpad, sinkpad, NULL);
1510 * gst_pad_link_filtered:
1511 * @srcpad: the source #GstPad to link.
1512 * @sinkpad: the sink #GstPad to link.
1513 * @filtercaps: the filter #GstCaps.
1515 * Links the source pad and the sink pad, constrained
1516 * by the given filter caps. This function sinks the caps.
1518 * Returns: TRUE if the pads have been linked, FALSE otherwise.
1521 gst_pad_link_filtered (GstPad *srcpad, GstPad *sinkpad,
1522 const GstCaps *filtercaps)
1524 GstRealPad *realsrc, *realsink;
1525 GstScheduler *src_sched, *sink_sched;
1528 /* generic checks */
1529 g_return_val_if_fail (srcpad != NULL, FALSE);
1530 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1531 g_return_val_if_fail (sinkpad != NULL, FALSE);
1532 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1534 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1535 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1537 /* now we need to deal with the real/ghost stuff */
1538 realsrc = GST_PAD_REALIZE (srcpad);
1539 realsink = GST_PAD_REALIZE (sinkpad);
1541 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1542 GST_CAT_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
1543 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1545 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1546 if (GST_RPAD_PEER (realsrc) != NULL) {
1547 GST_CAT_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1548 GST_DEBUG_PAD_NAME (realsrc));
1551 if (GST_RPAD_PEER (realsink) != NULL) {
1552 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1553 GST_DEBUG_PAD_NAME (realsink));
1556 if (GST_PAD_PARENT (realsrc) == NULL) {
1557 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1558 GST_DEBUG_PAD_NAME (realsrc));
1561 if (GST_PAD_PARENT (realsink) == NULL) {
1562 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has no parent, failed",
1563 GST_DEBUG_PAD_NAME (realsrc));
1567 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1568 g_warning ("linking pads with different scheds requires "
1569 "exactly one decoupled element (such as queue)");
1573 g_return_val_if_fail (realsrc != NULL, GST_PAD_LINK_REFUSED);
1574 g_return_val_if_fail (realsink != NULL, GST_PAD_LINK_REFUSED);
1576 link = gst_pad_link_new ();
1578 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
1579 link->srcpad = GST_PAD (realsrc);
1580 link->sinkpad = GST_PAD (realsink);
1582 link->srcpad = GST_PAD (realsink);
1583 link->sinkpad = GST_PAD (realsrc);
1586 if (GST_RPAD_DIRECTION (link->srcpad) != GST_PAD_SRC) {
1587 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s is not a source pad, failed",
1588 GST_DEBUG_PAD_NAME (link->srcpad));
1589 gst_pad_link_free (link);
1592 if (GST_RPAD_DIRECTION (link->sinkpad) != GST_PAD_SINK) {
1593 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1594 GST_DEBUG_PAD_NAME (link->sinkpad));
1595 gst_pad_link_free (link);
1599 link->srccaps = gst_pad_get_caps (link->srcpad);
1600 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1601 if (filtercaps) link->filtercaps = gst_caps_copy (filtercaps);
1602 if (gst_pad_link_try (link) == GST_PAD_LINK_REFUSED)
1605 /* fire off a signal to each of the pads telling them
1606 * that they've been linked */
1607 g_signal_emit (G_OBJECT (link->srcpad), gst_real_pad_signals[REAL_LINKED],
1609 g_signal_emit (G_OBJECT (link->sinkpad), gst_real_pad_signals[REAL_LINKED],
1612 src_sched = gst_pad_get_scheduler (GST_PAD (link->srcpad));
1613 sink_sched = gst_pad_get_scheduler (GST_PAD (link->sinkpad));
1615 /* now tell the scheduler */
1616 if (src_sched && src_sched == sink_sched) {
1617 gst_scheduler_pad_link (src_sched,
1618 GST_PAD (link->srcpad), GST_PAD (link->sinkpad));
1621 GST_CAT_INFO (GST_CAT_PADS, "not telling link to scheduler %s:%s and %s:%s, %p %p",
1622 GST_DEBUG_PAD_NAME (link->srcpad),
1623 GST_DEBUG_PAD_NAME (link->sinkpad),
1624 src_sched, sink_sched);
1627 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1628 GST_DEBUG_PAD_NAME (link->srcpad),
1629 GST_DEBUG_PAD_NAME (link->sinkpad));
1636 * @srcpad: the source #GstPad to link.
1637 * @sinkpad: the sink #GstPad to link.
1639 * Links the source pad to the sink pad.
1641 * Returns: TRUE if the pad could be linked, FALSE otherwise.
1644 gst_pad_link (GstPad *srcpad, GstPad *sinkpad)
1646 return gst_pad_link_filtered (srcpad, sinkpad, NULL);
1650 * gst_pad_set_parent:
1651 * @pad: a #GstPad to set the parent of.
1652 * @parent: the new parent #GstElement.
1654 * Sets the parent object of a pad.
1657 gst_pad_set_parent (GstPad *pad, GstElement *parent)
1659 g_return_if_fail (pad != NULL);
1660 g_return_if_fail (GST_IS_PAD (pad));
1661 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
1662 g_return_if_fail (parent != NULL);
1663 g_return_if_fail (GST_IS_OBJECT (parent));
1664 g_return_if_fail ((gpointer) pad != (gpointer) parent);
1666 gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (parent));
1670 * gst_pad_get_parent:
1671 * @pad: the #GstPad to get the parent of.
1673 * Gets the parent object of this pad.
1675 * Returns: the parent #GstElement.
1678 gst_pad_get_parent (GstPad *pad)
1680 g_return_val_if_fail (pad != NULL, NULL);
1681 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1683 return GST_PAD_PARENT (pad);
1687 gst_pad_set_pad_template (GstPad *pad, GstPadTemplate *templ)
1689 /* this function would need checks if it weren't static */
1691 gst_object_replace ((GstObject **) &pad->padtemplate, (GstObject *) templ);
1694 g_signal_emit (G_OBJECT (templ), gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
1697 * gst_pad_get_pad_template:
1698 * @pad: a #GstPad to get the pad template of.
1700 * Gets the pad template object of this pad.
1702 * Returns: the #GstPadTemplate from which this pad was instantiated.
1705 gst_pad_get_pad_template (GstPad *pad)
1707 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1709 return GST_PAD_PAD_TEMPLATE (pad);
1714 * gst_pad_get_scheduler:
1715 * @pad: a #GstPad to get the scheduler of.
1717 * Gets the scheduler of the pad. Since the pad does not
1718 * have a scheduler of its own, the scheduler of the parent
1719 * is taken. For decoupled pads, the scheduler of the peer
1722 * Returns: the #GstScheduler of the pad.
1725 gst_pad_get_scheduler (GstPad *pad)
1727 GstScheduler *scheduler = NULL;
1730 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1732 parent = gst_pad_get_parent (pad);
1734 if (GST_FLAG_IS_SET (parent, GST_ELEMENT_DECOUPLED)) {
1735 GstRealPad *peer = GST_RPAD_PEER (pad);
1738 scheduler = gst_element_get_scheduler (gst_pad_get_parent (GST_PAD (peer)));
1742 scheduler = gst_element_get_scheduler (parent);
1750 * gst_pad_get_real_parent:
1751 * @pad: a #GstPad to get the real parent of.
1753 * Gets the real parent object of this pad. If the pad
1754 * is a ghost pad, the actual owner of the real pad is
1755 * returned, as opposed to #gst_pad_get_parent().
1757 * Returns: the parent #GstElement.
1760 gst_pad_get_real_parent (GstPad *pad)
1762 g_return_val_if_fail (pad != NULL, NULL);
1763 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1765 return GST_PAD_PARENT (GST_PAD (GST_PAD_REALIZE (pad)));
1769 * gst_pad_add_ghost_pad:
1770 * @pad: a #GstPad to attach the ghost pad to.
1771 * @ghostpad: the ghost #GstPad to to the pad.
1773 * Adds a ghost pad to a pad.
1776 gst_pad_add_ghost_pad (GstPad *pad,
1779 GstRealPad *realpad;
1781 g_return_if_fail (pad != NULL);
1782 g_return_if_fail (GST_IS_PAD (pad));
1783 g_return_if_fail (ghostpad != NULL);
1784 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1786 realpad = GST_PAD_REALIZE (pad);
1788 realpad->ghostpads = g_list_prepend (realpad->ghostpads, ghostpad);
1793 * gst_pad_remove_ghost_pad:
1794 * @pad: a #GstPad to remove the ghost pad from.
1795 * @ghostpad: the ghost #GstPad to remove from the pad.
1797 * Removes a ghost pad from a pad.
1800 gst_pad_remove_ghost_pad (GstPad *pad,
1803 GstRealPad *realpad;
1805 g_return_if_fail (GST_IS_PAD (pad));
1806 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1807 realpad = GST_PAD_REALIZE (pad);
1808 g_return_if_fail (GST_GPAD_REALPAD (ghostpad) == realpad);
1810 realpad->ghostpads = g_list_remove (realpad->ghostpads, ghostpad);
1811 GST_GPAD_REALPAD (ghostpad) = NULL;
1815 * gst_pad_get_ghost_pad_list:
1816 * @pad: a #GstPad to get the ghost pads of.
1818 * Gets the ghost pads of this pad.
1820 * Returns: a #GList of ghost pads.
1823 gst_pad_get_ghost_pad_list (GstPad *pad)
1825 g_return_val_if_fail (pad != NULL, NULL);
1826 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1828 return GST_PAD_REALIZE(pad)->ghostpads;
1832 _gst_pad_default_fixate_foreach (GQuark field_id, GValue *value,
1835 GstStructure *structure = (GstStructure *)s;
1836 GType type = G_VALUE_TYPE (value);
1838 if (G_TYPE_IS_FUNDAMENTAL (type) || type == GST_TYPE_FOURCC) return TRUE;
1840 if (type == GST_TYPE_INT_RANGE) {
1841 gst_structure_set (structure, g_quark_to_string (field_id),
1842 G_TYPE_INT, gst_value_get_int_range_min (value), NULL);
1845 if (type == GST_TYPE_DOUBLE_RANGE) {
1846 gst_structure_set (structure, g_quark_to_string (field_id),
1847 G_TYPE_DOUBLE, gst_value_get_double_range_min (value), NULL);
1850 if (type == GST_TYPE_LIST) {
1851 gst_structure_set_value (structure, g_quark_to_string (field_id),
1852 gst_value_list_get_value (value, 0));
1856 g_critical ("don't know how to fixate type %s", g_type_name(type));
1861 _gst_pad_default_fixate_func (GstPad *pad, const GstCaps *caps)
1863 static GstStaticCaps octetcaps = GST_STATIC_CAPS (
1864 "application/octet-stream");
1865 GstStructure *structure;
1868 g_return_val_if_fail (pad != NULL, NULL);
1869 g_return_val_if_fail (caps != NULL, NULL);
1870 g_return_val_if_fail (!gst_caps_is_empty (caps), NULL);
1872 if (gst_caps_is_any (caps)) {
1873 return gst_caps_copy (gst_static_caps_get (&octetcaps));
1876 if (caps->structs->len > 1) {
1877 return gst_caps_new_full (gst_caps_get_structure (caps, 0), NULL);
1880 newcaps = gst_caps_copy (caps);
1881 structure = gst_caps_get_structure (newcaps, 0);
1882 gst_structure_foreach (structure, _gst_pad_default_fixate_foreach,
1889 * gst_pad_perform_negotiate:
1890 * @srcpad: the source #GstPad.
1891 * @sinkpad: the sink #GstPad.
1893 * Tries to negotiate the pads.
1895 * Returns: TRUE if the pads were succesfully negotiated, FALSE otherwise.
1898 gst_pad_perform_negotiate (GstPad *srcpad, GstPad *sinkpad)
1900 return GST_PAD_LINK_SUCCESSFUL (gst_pad_renegotiate (srcpad));
1904 gst_pad_link_unnegotiate (GstPadLink *link)
1906 g_return_if_fail (link != NULL);
1909 gst_caps_free (link->caps);
1911 if (GST_RPAD_LINK (link->srcpad) != link) {
1912 g_warning ("unnegotiating unset link");
1914 g_object_notify (G_OBJECT (link->srcpad), "caps");
1916 if (GST_RPAD_LINK (link->sinkpad) != link) {
1917 g_warning ("unnegotiating unset link");
1919 g_object_notify (G_OBJECT (link->sinkpad), "caps");
1925 * gst_pad_unnegotiate:
1926 * @pad: pad to unnegotiate
1928 * "Unnegotiates" a pad. The currently negotiated caps are cleared and the pad
1929 * needs renegotiation.
1932 gst_pad_unnegotiate (GstPad *pad)
1936 g_return_if_fail (GST_IS_PAD (pad));
1938 link = GST_RPAD_LINK (GST_PAD_REALIZE (pad));
1940 gst_pad_link_unnegotiate (link);
1944 * gst_pad_try_relink_filtered:
1945 * @srcpad: the source #GstPad to relink.
1946 * @sinkpad: the sink #GstPad to relink.
1947 * @filtercaps: the #GstPad to use as a filter in the relink.
1949 * Tries to relink the given source and sink pad, constrained by the given
1952 * Returns: TRUE if the pads were succesfully renegotiated, FALSE otherwise.
1955 gst_pad_try_relink_filtered (GstPad *srcpad, GstPad *sinkpad,
1956 const GstCaps *filtercaps)
1958 GstRealPad *realsrc, *realsink;
1962 /* generic checks */
1963 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1964 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1966 str = filtercaps ? gst_caps_to_string (filtercaps) : g_strdup ("");
1967 GST_CAT_INFO (GST_CAT_PADS, "trying to relink %s:%s and %s:%s with filtercaps %s",
1968 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad), str);
1971 /* now we need to deal with the real/ghost stuff */
1972 realsrc = GST_PAD_REALIZE (srcpad);
1973 realsink = GST_PAD_REALIZE (sinkpad);
1975 g_return_val_if_fail (realsrc != NULL, FALSE);
1976 g_return_val_if_fail (realsink != NULL, FALSE);
1977 g_return_val_if_fail (GST_RPAD_PEER (realsrc) == realsink, FALSE);
1978 g_assert (realsrc == GST_RPAD_PEER (realsink));
1979 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1980 GST_CAT_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
1981 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1984 link = gst_pad_link_new ();
1986 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
1987 link->srcpad = GST_PAD (realsrc);
1988 link->sinkpad = GST_PAD (realsink);
1990 link->srcpad = GST_PAD (realsink);
1991 link->sinkpad = GST_PAD (realsrc);
1994 if (GST_RPAD_DIRECTION (link->srcpad) != GST_PAD_SRC) {
1995 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s is not a source pad, failed",
1996 GST_DEBUG_PAD_NAME (link->srcpad));
1997 gst_pad_link_free (link);
2000 if (GST_RPAD_DIRECTION (link->sinkpad) != GST_PAD_SINK) {
2001 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
2002 GST_DEBUG_PAD_NAME (link->sinkpad));
2003 gst_pad_link_free (link);
2007 link->srccaps = gst_pad_get_caps (link->srcpad);
2008 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
2009 if (filtercaps) link->filtercaps = gst_caps_copy (filtercaps);
2010 if (GST_PAD_LINK_FAILED (gst_pad_link_try (link)))
2017 * gst_pad_relink_filtered:
2018 * @srcpad: the source #GstPad to relink.
2019 * @sinkpad: the sink #GstPad to relink.
2020 * @filtercaps: the #GstPad to use as a filter in the relink.
2022 * Relinks the given source and sink pad, constrained by the given
2023 * capabilities. If the relink fails, the pads are unlinked
2024 * and FALSE is returned.
2026 * Returns: TRUE if the pads were succesfully relinked, FALSE otherwise.
2029 gst_pad_relink_filtered (GstPad *srcpad, GstPad *sinkpad,
2030 const GstCaps *filtercaps)
2032 if (gst_pad_try_relink_filtered (srcpad, sinkpad, filtercaps))
2035 gst_pad_unlink (srcpad, sinkpad);
2040 * gst_pad_proxy_getcaps:
2041 * @pad: a #GstPad to proxy.
2043 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
2044 * same element as @pad, and returns the intersection of the results.
2046 * This function is useful as a default getcaps function for an element
2047 * that can handle any stream format, but requires all its pads to have
2048 * the same caps. Two such elements are tee and aggregator.
2050 * Returns: the intersection of the other pads' allowed caps.
2053 gst_pad_proxy_getcaps (GstPad *pad)
2055 GstElement *element;
2059 GST_DEBUG ("proxying getcaps for %s:%s\n", GST_DEBUG_PAD_NAME (pad));
2061 element = gst_pad_get_parent (pad);
2063 pads = gst_element_get_pad_list (element);
2065 caps = gst_caps_new_any ();
2067 GstPad *otherpad = GST_PAD (pads->data);
2070 if (otherpad != pad) {
2071 temp = gst_caps_intersect (caps, gst_pad_get_allowed_caps (otherpad));
2072 gst_caps_free (caps);
2076 pads = g_list_next (pads);
2083 * gst_pad_proxy_pad_link:
2084 * @pad: a #GstPad to proxy.
2086 * Calls gst_pad_try_set_caps() for every other pad belonging to the
2087 * same element as @pad. If gst_pad_try_set_caps() fails on any pad,
2088 * the proxy link fails.
2090 * Returns: GST_PAD_LINK_OK if sucessful
2093 gst_pad_proxy_pad_link (GstPad *pad, const GstCaps *caps)
2095 GstElement *element;
2097 GstPadLinkReturn ret;
2099 GST_DEBUG ("proxying pad link for %s:%s\n", GST_DEBUG_PAD_NAME (pad));
2101 element = gst_pad_get_parent (pad);
2103 pads = gst_element_get_pad_list (element);
2106 GstPad *otherpad = GST_PAD (pads->data);
2108 if (otherpad != pad) {
2109 ret = gst_pad_try_set_caps (otherpad, caps);
2110 if (GST_PAD_LINK_FAILED (ret)) {
2114 pads = g_list_next (pads);
2117 return GST_PAD_LINK_OK;
2121 * gst_pad_proxy_fixate:
2122 * @pad: a #GstPad to proxy.
2124 * Implements a default fixate function based on the caps set on the other
2125 * pads in the element. This function should only be used if every pad
2126 * has the same pad template caps.
2128 * Returns: a fixated caps, or NULL if caps cannot be fixed
2131 gst_pad_proxy_fixate (GstPad *pad, const GstCaps *caps)
2133 GstElement *element;
2135 const GstCaps *othercaps;
2137 GST_DEBUG ("proxying fixate for %s:%s\n", GST_DEBUG_PAD_NAME (pad));
2139 element = gst_pad_get_parent (pad);
2141 pads = gst_element_get_pad_list (element);
2144 GstPad *otherpad = GST_PAD (pads->data);
2146 /* FIXME check that each pad has the same pad template caps */
2148 if (otherpad != pad) {
2149 othercaps = gst_pad_get_negotiated_caps (otherpad);
2153 icaps = gst_caps_intersect (othercaps, caps);
2154 if (!gst_caps_is_empty (icaps)) {
2157 gst_caps_free (icaps);
2161 pads = g_list_next (pads);
2168 * gst_pad_set_explicit_caps:
2169 * @pad: a #GstPad to set the explicit caps of
2170 * @caps: the #GstCaps to set
2172 * If a pad has been told to use explicit caps, this function is used
2173 * to set the explicit caps. If @caps is NULL, the explicit caps are
2176 * This function calls gst_pad_try_set_caps() on the pad. If that
2177 * call fails, GST_ELEMENT_ERROR() is called to indicate a negotiation
2180 * Returns: TRUE if the caps were set correctly, otherwise FALSE
2183 gst_pad_set_explicit_caps (GstPad *pad, const GstCaps *caps)
2185 GstPadLinkReturn link_ret;
2187 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2189 GST_CAT_DEBUG (GST_CAT_PADS, "setting explicit caps to %s",
2190 gst_caps_to_string (caps));
2193 GST_CAT_DEBUG (GST_CAT_PADS, "caps is NULL");
2194 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2198 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), gst_caps_copy(caps));
2200 if (!GST_PAD_IS_LINKED (pad)) {
2201 GST_CAT_DEBUG (GST_CAT_PADS, "pad is not linked");
2204 link_ret = gst_pad_try_set_caps (pad, caps);
2205 if (link_ret == GST_PAD_LINK_REFUSED) {
2206 gst_element_error (gst_pad_get_parent (pad), CORE, PAD,
2208 ("failed to negotiate (try_set_caps returned REFUSED)"));
2216 gst_pad_explicit_getcaps (GstPad *pad)
2218 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2220 if (GST_RPAD_EXPLICIT_CAPS (pad) == NULL) {
2221 const GstCaps *caps = gst_pad_get_pad_template_caps (pad);
2223 return gst_caps_copy (caps);
2225 return gst_caps_copy (GST_RPAD_EXPLICIT_CAPS (pad));
2228 static GstPadLinkReturn
2229 gst_pad_explicit_link (GstPad *pad, const GstCaps *caps)
2231 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
2232 g_return_val_if_fail (caps != NULL, GST_PAD_LINK_REFUSED);
2234 if (GST_RPAD_EXPLICIT_CAPS (pad) == NULL) {
2235 return GST_PAD_LINK_DELAYED;
2238 return GST_PAD_LINK_OK;
2242 * gst_pad_use_explicit_caps:
2243 * @pad: a #GstPad to set to use explicit caps
2245 * This function handles negotiation for pads that need to be set
2246 * to particular caps under complete control of the element, based
2247 * on some state in the element. This is often the case with
2248 * decoders and other elements whose caps is determined by the data
2251 * WARNING: This function is a hack and will be replaced with something
2252 * better in gstreamer-0.9.
2255 gst_pad_use_explicit_caps (GstPad *pad)
2257 g_return_if_fail (GST_IS_PAD (pad));
2259 gst_pad_set_getcaps_function (pad, gst_pad_explicit_getcaps);
2260 gst_pad_set_link_function (pad, gst_pad_explicit_link);
2261 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2265 * gst_pad_proxy_link:
2266 * @pad: a #GstPad to proxy to.
2267 * @caps: the #GstCaps to use in proxying.
2269 * Proxies the link function to the specified pad.
2271 * Returns: TRUE if the peer pad accepted the caps, FALSE otherwise.
2274 gst_pad_proxy_link (GstPad *pad, const GstCaps *caps)
2276 return gst_pad_try_set_caps (pad, caps);
2280 * gst_pad_is_negotiated:
2281 * @pad: a #GstPad to get the negotiation status of
2283 * Returns: TRUE if the pad has successfully negotiated caps.
2286 gst_pad_is_negotiated (GstPad *pad)
2288 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2290 if (!GST_PAD_REALIZE (pad))
2292 if (!GST_RPAD_LINK (pad))
2295 return (GST_RPAD_LINK (pad)->caps != NULL);
2299 * gst_pad_get_negotiated_caps:
2300 * @pad: a #GstPad to get the negotiated capabilites of
2302 * Gets the currently negotiated caps of a pad or NULL if the pad isn't
2305 * Returns: the currently negotiated caps of a pad or NULL if the pad isn't
2308 G_CONST_RETURN GstCaps *
2309 gst_pad_get_negotiated_caps (GstPad *pad)
2311 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2313 if (!GST_PAD_REALIZE (pad))
2315 if (!GST_RPAD_LINK (pad))
2318 return GST_RPAD_LINK (pad)->caps;
2323 * @pad: a #GstPad to get the capabilities of.
2325 * Gets the capabilities of this pad.
2327 * Returns: the #GstCaps of this pad. This function returns a new caps, so use
2328 * gst_caps_free to get rid of it.
2331 gst_pad_get_caps (GstPad *pad)
2333 GstRealPad *realpad;
2335 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2337 realpad = GST_PAD_REALIZE (pad);
2339 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
2340 GST_DEBUG_PAD_NAME (realpad), realpad);
2342 if (GST_RPAD_GETCAPSFUNC (realpad)) {
2345 GST_CAT_DEBUG (GST_CAT_CAPS, "using pad get function");
2346 caps = GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD (realpad));
2349 g_critical ("pad %s:%s returned NULL caps from getcaps function\n",
2350 GST_ELEMENT_NAME(GST_PAD_PARENT(GST_PAD (realpad))),
2351 GST_PAD_NAME(realpad));
2352 caps = gst_caps_new_any ();
2356 } else if (GST_PAD_PAD_TEMPLATE (realpad)) {
2357 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (realpad);
2358 const GstCaps *caps;
2360 GST_CAT_DEBUG (GST_CAT_CAPS, "using pad template %p with caps %p",
2361 templ, GST_PAD_TEMPLATE_CAPS (templ));
2363 caps = GST_PAD_TEMPLATE_CAPS (templ);
2365 /* FIXME we should enable something like this someday, but this is
2367 if (!gst_caps_is_fixed (caps)) {
2368 g_warning("pad %s:%s (%p) has no getcaps function and the pad template returns non-fixed caps. Element is probably broken.\n",
2369 GST_DEBUG_PAD_NAME (realpad), realpad);
2373 return gst_caps_copy (GST_PAD_TEMPLATE_CAPS (templ));
2375 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
2379 g_warning("pad %s:%s (%p) has no pad template\n",
2380 GST_DEBUG_PAD_NAME (realpad), realpad);
2383 return gst_caps_new_any();
2387 * gst_pad_get_pad_template_caps:
2388 * @pad: a #GstPad to get the template capabilities from.
2390 * Gets the template capabilities of this pad.
2392 * Returns: the template #GstCaps of this pad, unref the caps
2393 * if you no longer need it.
2396 gst_pad_get_pad_template_caps (GstPad *pad)
2398 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2399 g_return_val_if_fail (pad != NULL, NULL);
2400 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2402 if (GST_PAD_PAD_TEMPLATE (pad))
2403 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2406 /* FIXME this should be enabled some day */
2407 g_warning("pad %s:%s (%p) has no pad template\n",
2408 GST_DEBUG_PAD_NAME (realpad), realpad);
2411 return gst_static_caps_get(&anycaps);
2415 * gst_pad_template_get_caps_by_name:
2416 * @templ: a #GstPadTemplate to get the capabilities of.
2417 * @name: the name of the capability to get.
2419 * Gets the capability with the given name from this pad template.
2421 * Returns: the #GstCaps, or NULL if not found or in case of an error. unref
2422 * the caps if you no longer need it.
2425 gst_pad_template_get_caps_by_name (GstPadTemplate *templ, const gchar *name)
2429 g_return_val_if_fail (templ != NULL, NULL);
2431 caps = GST_PAD_TEMPLATE_CAPS (templ);
2436 //return gst_caps_copy (gst_caps_get_by_name (caps, name));
2441 * gst_pad_check_compatibility:
2442 * @srcpad: the source #GstPad to check.
2443 * @sinkpad: the sink #GstPad to check against.
2445 * Checks if two pads have compatible capabilities.
2447 * Returns: TRUE if they are compatible or if the capabilities
2448 * could not be checked
2451 gst_pad_check_compatibility (GstPad *srcpad, GstPad *sinkpad)
2453 g_return_val_if_fail (srcpad != NULL, FALSE);
2454 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2455 g_return_val_if_fail (sinkpad != NULL, FALSE);
2456 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2458 if (GST_PAD_CAPS (srcpad) && GST_PAD_CAPS (sinkpad)) {
2459 if (!gst_caps_is_always_compatible (GST_PAD_CAPS (srcpad),
2460 GST_PAD_CAPS (sinkpad))) {
2468 GST_CAT_DEBUG (GST_CAT_PADS,
2469 "could not check capabilities of pads (%s:%s) and (%s:%s) %p %p",
2470 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2471 GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad));
2478 * @pad: a #GstPad to get the peer of.
2480 * Gets the peer pad of this pad.
2482 * Returns: the peer #GstPad.
2485 gst_pad_get_peer (GstPad *pad)
2487 g_return_val_if_fail (pad != NULL, NULL);
2488 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2490 return GST_PAD (GST_PAD_PEER (pad));
2494 * gst_pad_get_allowed_caps:
2495 * @pad: a #GstPad to get the allowed caps of.
2497 * Gets the capabilities of the allowed media types that can
2498 * flow through this pad. The caller must free the resulting caps.
2500 * Returns: the allowed #GstCaps of the pad link. Free the caps when
2501 * you no longer need it.
2504 gst_pad_get_allowed_caps (GstPad *pad)
2506 const GstCaps *mycaps;
2512 g_return_val_if_fail (pad != NULL, NULL);
2513 g_return_val_if_fail (GST_IS_REAL_PAD (pad), NULL);
2515 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "get allowed caps of %s:%s",
2516 GST_DEBUG_PAD_NAME (pad));
2518 mycaps = gst_pad_get_pad_template_caps (pad);
2519 if (GST_RPAD_PEER (pad) == NULL) {
2520 return gst_caps_copy (mycaps);
2523 peercaps = gst_pad_get_caps (GST_PAD_PEER (pad));
2524 caps = gst_caps_intersect (mycaps, peercaps);
2525 gst_caps_free (peercaps);
2527 link = GST_RPAD_LINK (pad);
2528 if (link->filtercaps) {
2529 icaps = gst_caps_intersect (caps, link->filtercaps);
2530 gst_caps_free (caps);
2538 gst_pad_caps_change_notify (GstPad *pad)
2540 /* call this to indicate that the return value of getcaps may have
2541 * changed, and a renegotiation is suggested */
2545 * gst_pad_recover_caps_error:
2546 * @pad: a #GstPad that had a failed capsnego
2547 * @allowed: possible caps for the link
2549 * Attempt to recover from a failed caps negotiation. This function
2550 * is typically called by a plugin that exhausted its list of caps
2551 * and wants the application to resolve the issue. The application
2552 * should connect to the pad's caps_nego_failed signal and should
2553 * resolve the issue by connecting another element for example.
2555 * Returns: TRUE when the issue was resolved, dumps detailed information
2556 * on the console and returns FALSE otherwise.
2559 gst_pad_recover_caps_error (GstPad *pad, const GstCaps *allowed)
2565 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2567 /* see if someone can resolve this */
2568 if (g_signal_has_handler_pending (G_OBJECT (pad),
2569 gst_real_pad_signals[REAL_CAPS_NEGO_FAILED], 0, FALSE))
2571 /* clear pad caps first */
2572 gst_caps_replace (&GST_PAD_CAPS (pad), NULL);
2574 /* lets hope some signal manages to set the caps again */
2575 g_signal_emit (G_OBJECT (pad), gst_real_pad_signals[REAL_CAPS_NEGO_FAILED], 0, allowed);
2577 /* if the pad has caps now or is disabled, it's ok */
2578 if (GST_PAD_CAPS (pad) != NULL || !GST_PAD_IS_ACTIVE (pad))
2583 parent = gst_pad_get_parent (pad);
2584 gst_element_error (parent, CORE, PAD,
2586 ("negotiation failed on pad %s:%s", GST_DEBUG_PAD_NAME (pad)));
2592 * gst_pad_alloc_buffer:
2593 * @pad: a #GstPad to get the buffer from.
2595 * Allocates a new, empty buffer optimized to push to pad #pad. This
2596 * function only works if #pad is a src pad.
2598 * Returns: a new, empty #GstBuffer, or NULL if there is an error
2601 gst_pad_alloc_buffer (GstPad *pad, guint64 offset, gint size)
2605 g_return_val_if_fail (pad != NULL, NULL);
2606 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2607 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
2609 peer = GST_RPAD_PEER (pad);
2612 return gst_buffer_new_and_alloc(size);
2614 GST_CAT_DEBUG (GST_CAT_BUFFER, "(%s:%s): getting buffer",
2615 GST_DEBUG_PAD_NAME (pad));
2617 if (peer->bufferallocfunc) {
2618 GST_CAT_DEBUG (GST_CAT_PADS,
2619 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s",
2620 GST_DEBUG_FUNCPTR_NAME (peer->bufferallocfunc),
2621 &peer->bufferallocfunc, GST_DEBUG_PAD_NAME (((GstPad*) peer)));
2622 return (peer->bufferallocfunc) (GST_PAD (peer), offset, size);
2624 return gst_buffer_new_and_alloc(size);
2629 gst_real_pad_dispose (GObject *object)
2631 GstPad *pad = GST_PAD (object);
2633 /* No linked pad can ever be disposed.
2634 * It has to have a parent to be linked
2635 * and a parent would hold a reference */
2636 g_assert (GST_PAD_PEER (pad) == NULL);
2638 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s", GST_DEBUG_PAD_NAME(pad));
2640 /* we destroy the ghostpads, because they are nothing without the real pad */
2641 if (GST_REAL_PAD (pad)->ghostpads) {
2642 GList *orig, *ghostpads;
2644 orig = ghostpads = g_list_copy (GST_REAL_PAD (pad)->ghostpads);
2647 GstPad *ghostpad = GST_PAD (ghostpads->data);
2649 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))){
2650 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "removing ghost pad from element '%s'",
2651 GST_OBJECT_NAME (GST_OBJECT_PARENT (ghostpad)));
2653 gst_element_remove_ghost_pad (GST_ELEMENT (GST_OBJECT_PARENT (ghostpad)), GST_PAD (ghostpad));
2655 ghostpads = g_list_next (ghostpads);
2658 g_list_free (GST_REAL_PAD(pad)->ghostpads);
2661 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
2662 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
2663 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
2665 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
2668 G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
2672 #ifndef GST_DISABLE_LOADSAVE
2673 /* FIXME: why isn't this on a GstElement ? */
2675 * gst_pad_load_and_link:
2676 * @self: an #xmlNodePtr to read the description from.
2677 * @parent: the #GstObject element that owns the pad.
2679 * Reads the pad definition from the XML node and links the given pad
2680 * in the element to a pad of an element up in the hierarchy.
2683 gst_pad_load_and_link (xmlNodePtr self, GstObject *parent)
2685 xmlNodePtr field = self->xmlChildrenNode;
2686 GstPad *pad = NULL, *targetpad;
2690 GstObject *grandparent;
2693 if (!strcmp (field->name, "name")) {
2694 pad = gst_element_get_pad (GST_ELEMENT (parent),
2695 xmlNodeGetContent (field));
2697 else if (!strcmp(field->name, "peer")) {
2698 peer = xmlNodeGetContent (field);
2700 field = field->next;
2702 g_return_if_fail (pad != NULL);
2704 if (peer == NULL) return;
2706 split = g_strsplit (peer, ".", 2);
2708 if (split[0] == NULL || split[1] == NULL) {
2709 GST_CAT_DEBUG (GST_CAT_XML,
2710 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
2711 peer, GST_DEBUG_PAD_NAME (pad));
2715 g_return_if_fail (split[0] != NULL);
2716 g_return_if_fail (split[1] != NULL);
2718 grandparent = gst_object_get_parent (parent);
2720 if (grandparent && GST_IS_BIN (grandparent)) {
2721 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2726 if (target == NULL) goto cleanup;
2728 targetpad = gst_element_get_pad (target, split[1]);
2730 if (targetpad == NULL) goto cleanup;
2732 gst_pad_link (pad, targetpad);
2739 * gst_pad_save_thyself:
2740 * @pad: a #GstPad to save.
2741 * @parent: the parent #xmlNodePtr to save the description in.
2743 * Saves the pad into an xml representation.
2745 * Returns: the #xmlNodePtr representation of the pad.
2748 gst_pad_save_thyself (GstObject *object, xmlNodePtr parent)
2750 GstRealPad *realpad;
2753 g_return_val_if_fail (GST_IS_REAL_PAD (object), NULL);
2755 realpad = GST_REAL_PAD (object);
2757 xmlNewChild (parent, NULL, "name", GST_PAD_NAME (realpad));
2758 if (GST_RPAD_PEER (realpad) != NULL) {
2761 peer = GST_PAD (GST_RPAD_PEER (realpad));
2762 /* first check to see if the peer's parent's parent is the same */
2763 /* we just save it off */
2764 content = g_strdup_printf ("%s.%s",
2765 GST_OBJECT_NAME (GST_PAD_PARENT (peer)),
2766 GST_PAD_NAME (peer));
2767 xmlNewChild (parent, NULL, "peer", content);
2770 xmlNewChild (parent, NULL, "peer", "");
2775 /* FIXME: shouldn't pad and ghost be switched ?
2778 * gst_ghost_pad_save_thyself:
2779 * @pad: a ghost #GstPad to save.
2780 * @parent: the parent #xmlNodePtr to save the description in.
2782 * Saves the ghost pad into an xml representation.
2784 * Returns: the #xmlNodePtr representation of the pad.
2787 gst_ghost_pad_save_thyself (GstPad *pad, xmlNodePtr parent)
2791 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2793 self = xmlNewChild (parent, NULL, "ghostpad", NULL);
2794 xmlNewChild (self, NULL, "name", GST_PAD_NAME (pad));
2795 xmlNewChild (self, NULL, "parent", GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
2797 /* FIXME FIXME FIXME! */
2801 #endif /* GST_DISABLE_LOADSAVE */
2805 * @pad: a #GstPad to push the buffer out of.
2806 * @data: the #GstData to push.
2808 * Pushes a buffer or an event to the peer of the pad.
2811 gst_pad_push (GstPad *pad, GstData *data)
2815 g_return_if_fail (GST_IS_PAD (pad));
2816 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
2817 g_return_if_fail (data != NULL);
2819 if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), &data))
2822 if (!GST_PAD_IS_LINKED (pad)) {
2823 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad, "not pushing data %p as pad is unconnected", data);
2824 gst_data_unref (data);
2828 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad, "pushing");
2829 peer = GST_RPAD_PEER (pad);
2832 g_warning ("push on pad %s:%s but it is unlinked",
2833 GST_DEBUG_PAD_NAME (pad));
2836 if (!GST_IS_EVENT (data) && !GST_PAD_IS_ACTIVE (peer)) {
2837 g_warning ("push on peer of pad %s:%s but peer is not active",
2838 GST_DEBUG_PAD_NAME (pad));
2842 if (peer->chainhandler) {
2844 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad,
2845 "calling chainhandler &%s of peer pad %s:%s",
2846 GST_DEBUG_FUNCPTR_NAME (peer->chainhandler),
2847 GST_DEBUG_PAD_NAME (GST_PAD (peer)));
2848 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
2851 (peer->chainhandler) (GST_PAD (peer), data);
2855 g_warning ("trying to push a NULL buffer on pad %s:%s",
2856 GST_DEBUG_PAD_NAME (peer));
2861 g_warning ("internal error: push on pad %s:%s but it has no chainhandler",
2862 GST_DEBUG_PAD_NAME (peer));
2865 /* clean up the mess here */
2866 if (data != NULL) gst_data_unref (data);
2871 * @pad: a #GstPad to pull a buffer from.
2873 * Pulls an event or a buffer from the peer pad.
2875 * Returns: a new #GstData from the peer pad.
2878 gst_pad_pull (GstPad *pad)
2882 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad, "pulling");
2884 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
2885 GST_DATA (gst_event_new (GST_EVENT_INTERRUPT)));
2887 peer = GST_RPAD_PEER (pad);
2890 gst_element_error (GST_PAD_PARENT (pad), CORE, PAD, NULL,
2891 ("pull on pad %s:%s but it was unlinked", GST_DEBUG_PAD_NAME (pad)));
2895 if (peer->gethandler) {
2898 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad,
2899 "calling gethandler %s of peer pad %s:%s",
2900 GST_DEBUG_FUNCPTR_NAME (peer->gethandler),
2901 GST_DEBUG_PAD_NAME (peer));
2903 data = (peer->gethandler) (GST_PAD (peer));
2906 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
2911 /* no null buffers allowed */
2912 gst_element_error (GST_PAD_PARENT (pad), CORE, PAD, NULL,
2913 ("NULL buffer during pull on %s:%s", GST_DEBUG_PAD_NAME (pad)));
2915 gst_element_error (GST_PAD_PARENT (pad), CORE, PAD, NULL,
2916 ("pull on pad %s:%s but the peer pad %s:%s has no gethandler",
2917 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer)));
2920 return GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
2925 * @padlist: a #GList of pads.
2927 * Waits for a buffer on any of the list of pads.
2929 * Returns: the #GstPad that has a buffer available.
2930 * Use #gst_pad_pull() to get the buffer.
2933 gst_pad_selectv (GList *padlist)
2937 pad = gst_scheduler_pad_select (GST_PAD_PARENT (padlist->data)->sched,
2944 * @pad: a first #GstPad to perform the select on.
2945 * @...: A NULL-terminated list of more pads to select on.
2947 * Waits for a buffer on the given set of pads.
2949 * Returns: the #GstPad that has a buffer available.
2950 * Use #gst_pad_pull() to get the buffer.
2953 gst_pad_select (GstPad *pad, ...)
2961 va_start (var_args, pad);
2963 result = gst_pad_select_valist (pad, var_args);
2971 * gst_pad_select_valist:
2972 * @pad: a first #GstPad to perform the select on.
2973 * @varargs: A va_list of more pads to select on.
2975 * Waits for a buffer on the given set of pads.
2977 * Returns: the #GstPad that has a buffer available.
2978 * Use #gst_pad_pull() to get the buffer.
2981 gst_pad_select_valist (GstPad *pad, va_list var_args)
2984 GList *padlist = NULL;
2990 padlist = g_list_prepend (padlist, pad);
2991 pad = va_arg (var_args, GstPad *);
2993 result = gst_pad_selectv (padlist);
2994 g_list_free (padlist);
2999 /************************************************************************
3004 static void gst_pad_template_class_init (GstPadTemplateClass *klass);
3005 static void gst_pad_template_init (GstPadTemplate *templ);
3006 static void gst_pad_template_dispose (GObject *object);
3009 gst_pad_template_get_type (void)
3011 static GType padtemplate_type = 0;
3013 if (!padtemplate_type) {
3014 static const GTypeInfo padtemplate_info = {
3015 sizeof (GstPadTemplateClass), NULL, NULL,
3016 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
3017 sizeof (GstPadTemplate),
3019 (GInstanceInitFunc) gst_pad_template_init, NULL
3021 padtemplate_type = g_type_register_static(GST_TYPE_OBJECT, "GstPadTemplate",
3022 &padtemplate_info, 0);
3024 return padtemplate_type;
3028 gst_pad_template_class_init (GstPadTemplateClass *klass)
3030 GObjectClass *gobject_class;
3031 GstObjectClass *gstobject_class;
3033 gobject_class = (GObjectClass*) klass;
3034 gstobject_class = (GstObjectClass*) klass;
3036 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
3038 gst_pad_template_signals[TEMPL_PAD_CREATED] =
3039 g_signal_new ("pad_created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
3040 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
3041 NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
3044 gobject_class->dispose = gst_pad_template_dispose;
3046 gstobject_class->path_string_separator = "*";
3050 gst_pad_template_init (GstPadTemplate *templ)
3055 gst_pad_template_dispose (GObject *object)
3057 GstPadTemplate *templ = GST_PAD_TEMPLATE (object);
3059 g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
3060 if (GST_PAD_TEMPLATE_CAPS (templ)) {
3061 gst_caps_free (GST_PAD_TEMPLATE_CAPS (templ));
3064 G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object);
3067 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
3069 * SOMETIMES padtemplates can do whatever they want, they are provided by the
3071 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
3072 * 'sink%d' template is automatically selected), so we need to restrict their
3076 name_is_valid (const gchar *name, GstPadPresence presence)
3080 if (presence == GST_PAD_ALWAYS) {
3081 if (strchr (name, '%')) {
3082 g_warning ("invalid name template %s: conversion specifications are not"
3083 " allowed for GST_PAD_ALWAYS padtemplates", name);
3086 } else if (presence == GST_PAD_REQUEST) {
3087 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
3088 g_warning ("invalid name template %s: only one conversion specification"
3089 " allowed in GST_PAD_REQUEST padtemplate", name);
3092 if (str && (*(str+1) != 's' && *(str+1) != 'd')) {
3093 g_warning ("invalid name template %s: conversion specification must be of"
3094 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
3097 if (str && (*(str+2) != '\0')) {
3098 g_warning ("invalid name template %s: conversion specification must"
3099 " appear at the end of the GST_PAD_REQUEST padtemplate name",
3109 * gst_static_pad_template_get:
3110 * @pad_template: the static pad template
3112 * Converts a GstStaticPadTemplate into a GstPadTemplate.
3114 * Returns: a new #GstPadTemplate.
3117 gst_static_pad_template_get (GstStaticPadTemplate *pad_template)
3119 GstPadTemplate *new;
3121 if (!name_is_valid (pad_template->name_template, pad_template->presence))
3124 new = g_object_new (gst_pad_template_get_type (),
3125 "name", pad_template->name_template,
3128 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) =
3129 g_strdup (pad_template->name_template);
3130 GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction;
3131 GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence;
3133 GST_PAD_TEMPLATE_CAPS (new) = gst_caps_copy (
3134 gst_static_caps_get (&pad_template->static_caps));
3140 * gst_pad_template_new:
3141 * @name_template: the name template.
3142 * @direction: the #GstPadDirection of the template.
3143 * @presence: the #GstPadPresence of the pad.
3144 * @caps: a #GstCaps set for the template. The caps are taken ownership of.
3146 * Creates a new pad template with a name according to the given template
3147 * and with the given arguments. This functions takes ownership of the provided
3148 * caps, so be sure to not use them afterwards.
3150 * Returns: a new #GstPadTemplate.
3153 gst_pad_template_new (const gchar *name_template,
3154 GstPadDirection direction, GstPadPresence presence,
3157 GstPadTemplate *new;
3159 g_return_val_if_fail (name_template != NULL, NULL);
3161 if (!name_is_valid (name_template, presence))
3165 #ifdef USE_POISONING
3167 GstCaps *newcaps = gst_caps_copy (caps);
3168 gst_caps_free(caps);
3173 new = g_object_new (gst_pad_template_get_type (),
3174 "name", name_template,
3177 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
3178 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
3179 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
3180 GST_PAD_TEMPLATE_CAPS (new) = caps;
3186 * gst_pad_template_get_caps:
3187 * @templ: a #GstPadTemplate to get capabilities of.
3189 * Gets the capabilities of the pad template.
3191 * Returns: the #GstCaps of the pad template. unref the caps
3195 gst_pad_template_get_caps (GstPadTemplate *templ)
3197 g_return_val_if_fail (templ != NULL, NULL);
3199 return GST_PAD_TEMPLATE_CAPS (templ);
3203 * gst_pad_set_element_private:
3204 * @pad: the #GstPad to set the private data of.
3205 * @priv: The private data to attach to the pad.
3207 * Set the given private data gpointer on the pad.
3208 * This function can only be used by the element that owns the pad.
3211 gst_pad_set_element_private (GstPad *pad, gpointer priv)
3213 pad->element_private = priv;
3217 * gst_pad_get_element_private:
3218 * @pad: the #GstPad to get the private data of.
3220 * Gets the private data of a pad.
3222 * Returns: a #gpointer to the private data.
3225 gst_pad_get_element_private (GstPad *pad)
3227 return pad->element_private;
3231 /***** ghost pads *****/
3232 GType _gst_ghost_pad_type = 0;
3234 static void gst_ghost_pad_class_init (GstGhostPadClass *klass);
3235 static void gst_ghost_pad_init (GstGhostPad *pad);
3236 static void gst_ghost_pad_dispose (GObject *object);
3238 static GstPad *ghost_pad_parent_class = NULL;
3239 /* static guint gst_ghost_pad_signals[LAST_SIGNAL] = { 0 }; */
3242 gst_ghost_pad_get_type (void)
3244 if (!_gst_ghost_pad_type) {
3245 static const GTypeInfo pad_info = {
3246 sizeof (GstGhostPadClass), NULL, NULL,
3247 (GClassInitFunc) gst_ghost_pad_class_init, NULL, NULL,
3248 sizeof (GstGhostPad),
3250 (GInstanceInitFunc) gst_ghost_pad_init,
3253 _gst_ghost_pad_type = g_type_register_static (GST_TYPE_PAD, "GstGhostPad",
3256 return _gst_ghost_pad_type;
3260 gst_ghost_pad_class_init (GstGhostPadClass *klass)
3262 GObjectClass *gobject_class;
3264 gobject_class = (GObjectClass*) klass;
3266 ghost_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
3268 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_ghost_pad_dispose);
3272 gst_ghost_pad_init (GstGhostPad *pad)
3274 /* zeroed by glib */
3277 gst_ghost_pad_dispose (GObject *object)
3279 GstGhostPad *pad = GST_GHOST_PAD (object);
3282 gst_pad_remove_ghost_pad((GstPad *) pad->realpad, (GstPad *) pad);
3284 G_OBJECT_CLASS (ghost_pad_parent_class)->dispose (object);
3288 * gst_ghost_pad_new:
3289 * @name: the name of the new ghost pad.
3290 * @pad: the #GstPad to create a ghost pad for.
3292 * Creates a new ghost pad associated with the given pad, and names it with
3293 * the given name. If name is NULL, a guaranteed unique name (across all
3294 * ghost pads) will be assigned (most likely of the form ghostpad%d).
3296 * Returns: a new ghost #GstPad, or NULL in case of an error.
3300 gst_ghost_pad_new (const gchar *name,
3303 GstGhostPad *ghostpad;
3304 GstRealPad *realpad;
3306 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3308 ghostpad = g_object_new (gst_ghost_pad_get_type () ,NULL);
3309 gst_pad_set_name (GST_PAD (ghostpad), name);
3311 realpad = (GstRealPad *) pad;
3313 while (!GST_IS_REAL_PAD (realpad)) {
3314 realpad = GST_PAD_REALIZE (realpad);
3316 GST_GPAD_REALPAD (ghostpad) = realpad;
3317 gst_pad_set_pad_template (GST_PAD (ghostpad), GST_PAD_PAD_TEMPLATE (pad));
3319 /* add ourselves to the real pad's list of ghostpads */
3320 gst_pad_add_ghost_pad (pad, GST_PAD (ghostpad));
3322 /* FIXME need to ref the real pad here... ? */
3324 GST_CAT_DEBUG (GST_CAT_PADS, "created ghost pad \"%s\"",
3325 gst_pad_get_name (GST_PAD (ghostpad)));
3327 return GST_PAD (ghostpad);
3331 * gst_pad_get_internal_links_default:
3332 * @pad: the #GstPad to get the internal links of.
3334 * Gets a list of pads to which the given pad is linked to
3335 * inside of the parent element.
3336 * This is the default handler, and thus returns a list of all of the
3337 * pads inside the parent element with opposite direction.
3338 * The caller must free this list after use.
3340 * Returns: a newly allocated #GList of pads.
3343 gst_pad_get_internal_links_default (GstPad *pad)
3348 GstPadDirection direction;
3351 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3353 rpad = GST_PAD_REALIZE (pad);
3354 direction = rpad->direction;
3356 parent = GST_PAD_PARENT (rpad);
3357 parent_pads = parent->pads;
3359 while (parent_pads) {
3360 GstRealPad *parent_pad = GST_PAD_REALIZE (parent_pads->data);
3362 if (parent_pad->direction != direction) {
3363 res = g_list_prepend (res, parent_pad);
3366 parent_pads = g_list_next (parent_pads);
3373 * gst_pad_get_internal_links:
3374 * @pad: the #GstPad to get the internal links of.
3376 * Gets a list of pads to which the given pad is linked to
3377 * inside of the parent element.
3378 * The caller must free this list after use.
3380 * Returns: a newly allocated #GList of pads.
3383 gst_pad_get_internal_links (GstPad *pad)
3388 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3390 rpad = GST_PAD_REALIZE (pad);
3392 if (GST_RPAD_INTLINKFUNC (rpad))
3393 res = GST_RPAD_INTLINKFUNC (rpad) (GST_PAD (rpad));
3400 gst_pad_event_default_dispatch (GstPad *pad, GstElement *element,
3405 orig = pads = gst_pad_get_internal_links (pad);
3408 GstPad *eventpad = GST_PAD (pads->data);
3409 pads = g_list_next (pads);
3411 /* for all pads in the opposite direction that are linked */
3412 if (GST_PAD_IS_LINKED (eventpad)) {
3413 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
3414 /* increase the refcount */
3415 gst_event_ref (event);
3416 gst_pad_push (eventpad, GST_DATA (event));
3419 GstPad *peerpad = GST_PAD (GST_RPAD_PEER (eventpad));
3421 /* we only send the event on one pad, multi-sinkpad elements
3422 * should implement a handler */
3424 return gst_pad_send_event (peerpad, event);
3428 gst_event_unref (event);
3430 return (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
3434 * gst_pad_event_default:
3435 * @pad: a #GstPad to call the default event handler on.
3436 * @event: the #GstEvent to handle.
3438 * Invokes the default event handler for the given pad.
3440 * Returns: TRUE if the event was sent succesfully.
3443 gst_pad_event_default (GstPad *pad, GstEvent *event)
3445 GstElement *element;
3447 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3448 g_return_val_if_fail (event, FALSE);
3450 element = GST_PAD_PARENT (pad);
3452 switch (GST_EVENT_TYPE (event)) {
3454 gst_pad_event_default_dispatch (pad, element, event);
3455 gst_element_set_eos (element);
3457 case GST_EVENT_DISCONTINUOUS:
3461 if (gst_event_discont_get_value (event, GST_FORMAT_TIME, &time)) {
3462 if (gst_element_requires_clock (element) && element->clock) {
3463 gst_element_set_time (element, time);
3467 case GST_EVENT_FLUSH:
3469 return gst_pad_event_default_dispatch (pad, element, event);
3475 * gst_pad_dispatcher:
3476 * @pad: a #GstPad to dispatch.
3477 * @dispatch: the #GstDispatcherFunction to call.
3478 * @data: gpointer user data passed to the dispatcher function.
3480 * Invokes the given dispatcher function on all pads that are
3481 * internally linked to the given pad.
3482 * The GstPadDispatcherFunction should return TRUE when no further pads
3483 * need to be processed.
3485 * Returns: TRUE if one of the dispatcher functions returned TRUE.
3488 gst_pad_dispatcher (GstPad *pad, GstPadDispatcherFunction dispatch,
3491 gboolean res = FALSE;
3492 GList *int_pads, *orig;
3494 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3495 g_return_val_if_fail (data, FALSE);
3497 orig = int_pads = gst_pad_get_internal_links (pad);
3500 GstRealPad *int_rpad = GST_PAD_REALIZE (int_pads->data);
3501 GstRealPad *int_peer = GST_RPAD_PEER (int_rpad);
3504 res = dispatch (GST_PAD (int_peer), data);
3508 int_pads = g_list_next (int_pads);
3517 * gst_pad_send_event:
3518 * @pad: a #GstPad to send the event to.
3519 * @event: the #GstEvent to send to the pad.
3521 * Sends the event to the pad.
3523 * Returns: TRUE if the event was handled.
3526 gst_pad_send_event (GstPad *pad, GstEvent *event)
3528 gboolean success = FALSE;
3531 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3532 g_return_val_if_fail (event, FALSE);
3534 rpad = GST_PAD_REALIZE (pad);
3536 if (GST_EVENT_SRC (event) == NULL)
3537 GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (rpad));
3539 GST_CAT_DEBUG (GST_CAT_EVENT, "have event %d on pad %s:%s",
3540 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (rpad));
3542 if (GST_RPAD_EVENTHANDLER (rpad))
3543 success = GST_RPAD_EVENTHANDLER (rpad) (GST_PAD (rpad), event);
3545 g_warning ("pad %s:%s has no event handler", GST_DEBUG_PAD_NAME (rpad));
3546 gst_event_unref (event);
3554 GstFormat src_format;
3556 GstFormat *dest_format;
3558 } GstPadConvertData;
3561 gst_pad_convert_dispatcher (GstPad *pad, GstPadConvertData *data)
3563 return gst_pad_convert (pad, data->src_format, data->src_value,
3564 data->dest_format, data->dest_value);
3568 * gst_pad_convert_default:
3569 * @pad: a #GstPad to invoke the default converter on.
3570 * @src_format: the source #GstFormat.
3571 * @src_value: the source value.
3572 * @dest_format: a pointer to the destination #GstFormat.
3573 * @dest_value: a pointer to the destination value.
3575 * Invokes the default converter on a pad.
3576 * This will forward the call to the pad obtained
3577 * using the internal link of
3580 * Returns: TRUE if the conversion could be performed.
3583 gst_pad_convert_default (GstPad *pad,
3584 GstFormat src_format, gint64 src_value,
3585 GstFormat *dest_format, gint64 *dest_value)
3587 GstPadConvertData data;
3589 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3590 g_return_val_if_fail (dest_format, FALSE);
3591 g_return_val_if_fail (dest_value, FALSE);
3593 data.src_format = src_format;
3594 data.src_value = src_value;
3595 data.dest_format = dest_format;
3596 data.dest_value = dest_value;
3598 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3599 gst_pad_convert_dispatcher, &data);
3604 * @pad: a #GstPad to invoke the default converter on.
3605 * @src_format: the source #GstFormat.
3606 * @src_value: the source value.
3607 * @dest_format: a pointer to the destination #GstFormat.
3608 * @dest_value: a pointer to the destination value.
3610 * Invokes a conversion on the pad.
3612 * Returns: TRUE if the conversion could be performed.
3615 gst_pad_convert (GstPad *pad,
3616 GstFormat src_format, gint64 src_value,
3617 GstFormat *dest_format, gint64 *dest_value)
3621 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3622 g_return_val_if_fail (dest_format, FALSE);
3623 g_return_val_if_fail (dest_value, FALSE);
3625 if (src_format == *dest_format) {
3626 *dest_value = src_value;
3630 rpad = GST_PAD_REALIZE (pad);
3632 if (GST_RPAD_CONVERTFUNC (rpad)) {
3633 return GST_RPAD_CONVERTFUNC (rpad) (GST_PAD (rpad), src_format,
3634 src_value, dest_format, dest_value);
3648 gst_pad_query_dispatcher (GstPad *pad, GstPadQueryData *data)
3650 return gst_pad_query (pad, data->type, data->format, data->value);
3654 * gst_pad_query_default:
3655 * @pad: a #GstPad to invoke the default query on.
3656 * @type: the #GstQueryType of the query to perform.
3657 * @format: a pointer to the #GstFormat of the result.
3658 * @value: a pointer to the result.
3660 * Invokes the default query function on a pad.
3662 * Returns: TRUE if the query could be performed.
3665 gst_pad_query_default (GstPad *pad, GstQueryType type,
3666 GstFormat *format, gint64 *value)
3668 GstPadQueryData data;
3670 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3671 g_return_val_if_fail (format, FALSE);
3672 g_return_val_if_fail (value, FALSE);
3675 data.format = format;
3678 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3679 gst_pad_query_dispatcher, &data);
3684 * @pad: a #GstPad to invoke the default query on.
3685 * @type: the #GstQueryType of the query to perform.
3686 * @format: a pointer to the #GstFormat asked for.
3687 * On return contains the #GstFormat used.
3688 * @value: a pointer to the result.
3690 * Queries a pad for one of the available properties. The format will be
3691 * adjusted to the actual format used when specifying formats such as
3692 * GST_FORMAT_DEFAULT.
3693 * FIXME: Tell if the format can be adjusted when specifying a definite format.
3695 * Returns: TRUE if the query could be performed.
3698 gst_pad_query (GstPad *pad, GstQueryType type,
3699 GstFormat *format, gint64 *value)
3703 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3704 g_return_val_if_fail (format, FALSE);
3705 g_return_val_if_fail (value, FALSE);
3707 rpad = GST_PAD_REALIZE (pad);
3709 g_return_val_if_fail (rpad, FALSE);
3711 if (GST_RPAD_QUERYFUNC (rpad))
3712 return GST_RPAD_QUERYFUNC (rpad) (GST_PAD (pad), type, format, value);
3718 gst_pad_get_formats_dispatcher (GstPad *pad, const GstFormat **data)
3720 *data = gst_pad_get_formats (pad);
3726 * gst_pad_get_formats_default:
3727 * @pad: a #GstPad to query
3729 * Invoke the default format dispatcher for the pad.
3731 * Returns: An array of GstFormats ended with a 0 value.
3734 gst_pad_get_formats_default (GstPad *pad)
3736 GstFormat *result = NULL;
3738 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3739 gst_pad_get_formats_dispatcher, &result);
3745 * gst_pad_get_formats:
3746 * @pad: a #GstPad to query
3748 * Gets the list of supported formats from the pad.
3750 * Returns: An array of GstFormats ended with a 0 value.
3753 gst_pad_get_formats (GstPad *pad)
3757 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3759 rpad = GST_PAD_REALIZE (pad);
3761 if (GST_RPAD_FORMATSFUNC (rpad))
3762 return GST_RPAD_FORMATSFUNC (rpad) (GST_PAD (pad));