2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include "gst_private.h"
26 #include "gstmarshal.h"
28 #include "gstelement.h"
30 #include "gstscheduler.h"
36 #define GST_CAT_DEFAULT GST_CAT_PADS
46 static GstObject *padtemplate_parent_class = NULL;
47 static guint gst_pad_template_signals[TEMPL_LAST_SIGNAL] = { 0 };
49 GType _gst_pad_type = 0;
51 /***** Start with the base GstPad class *****/
52 static void gst_pad_class_init (GstPadClass * klass);
53 static void gst_pad_init (GstPad * pad);
54 static void gst_pad_dispose (GObject * object);
56 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
57 static GstCaps *_gst_pad_default_fixate_func (GstPad * pad,
58 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
81 _gst_pad_type = g_type_register_static (GST_TYPE_OBJECT, "GstPad",
88 gst_pad_class_init (GstPadClass * klass)
90 GObjectClass *gobject_class;
92 gobject_class = (GObjectClass *) klass;
94 pad_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
96 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_pad_dispose);
100 gst_pad_init (GstPad * pad)
102 /* all structs are initialized to NULL by glib */
105 gst_pad_dispose (GObject * object)
107 GstPad *pad = GST_PAD (object);
109 gst_pad_set_pad_template (pad, NULL);
111 G_OBJECT_CLASS (pad_parent_class)->dispose (object);
116 /***** Then do the Real Pad *****/
117 /* Pad signals and args */
135 static void gst_real_pad_class_init (GstRealPadClass * klass);
136 static void gst_real_pad_init (GstRealPad * pad);
137 static void gst_real_pad_dispose (GObject * object);
139 static gboolean _gst_real_pad_fixate_accumulator (GSignalInvocationHint * ihint,
140 GValue * return_accu, const GValue * handler_return, gpointer dummy);
141 static void gst_real_pad_set_property (GObject * object, guint prop_id,
142 const GValue * value, GParamSpec * pspec);
143 static void gst_real_pad_get_property (GObject * object, guint prop_id,
144 GValue * value, GParamSpec * pspec);
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)
154 if (!_gst_real_pad_type) {
155 static const GTypeInfo pad_info = {
156 sizeof (GstRealPadClass), NULL, NULL,
157 (GClassInitFunc) gst_real_pad_class_init, NULL, NULL,
160 (GInstanceInitFunc) gst_real_pad_init, NULL
163 _gst_real_pad_type = g_type_register_static (GST_TYPE_PAD, "GstRealPad",
166 return _gst_real_pad_type;
170 gst_real_pad_class_init (GstRealPadClass * klass)
172 GObjectClass *gobject_class;
173 GstObjectClass *gstobject_class;
175 gobject_class = (GObjectClass *) klass;
176 gstobject_class = (GstObjectClass *) klass;
178 real_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
180 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_real_pad_dispose);
181 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_real_pad_set_property);
182 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_real_pad_get_property);
184 gst_real_pad_signals[REAL_LINKED] =
185 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
186 G_STRUCT_OFFSET (GstRealPadClass, linked), NULL, NULL,
187 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
188 gst_real_pad_signals[REAL_UNLINKED] =
189 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
190 G_STRUCT_OFFSET (GstRealPadClass, unlinked), NULL, NULL,
191 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
192 gst_real_pad_signals[REAL_FIXATE] =
193 g_signal_new ("fixate", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
194 G_STRUCT_OFFSET (GstRealPadClass, appfixatefunc),
195 _gst_real_pad_fixate_accumulator, NULL,
196 gst_marshal_BOXED__BOXED, GST_TYPE_CAPS, 1,
197 GST_TYPE_CAPS | G_SIGNAL_TYPE_STATIC_SCOPE);
199 /* gtk_object_add_arg_type ("GstRealPad::active", G_TYPE_BOOLEAN, */
200 /* GTK_ARG_READWRITE, REAL_ARG_ACTIVE); */
201 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_ACTIVE,
202 g_param_spec_boolean ("active", "Active", "Whether the pad is active.",
203 TRUE, G_PARAM_READWRITE));
204 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_CAPS,
205 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
206 GST_TYPE_CAPS, G_PARAM_READABLE));
208 #ifndef GST_DISABLE_LOADSAVE
209 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
211 gstobject_class->path_string_separator = ".";
215 _gst_real_pad_fixate_accumulator (GSignalInvocationHint * ihint,
216 GValue * return_accu, const GValue * handler_return, gpointer dummy)
218 if (gst_value_get_caps (handler_return)) {
219 g_value_copy (handler_return, return_accu);
220 /* stop emission if something was returned */
227 gst_real_pad_init (GstRealPad * pad)
229 pad->direction = GST_PAD_UNKNOWN;
232 pad->chainfunc = NULL;
235 pad->chainhandler = NULL;
236 pad->gethandler = NULL;
238 pad->ghostpads = NULL;
241 pad->linkfunc = NULL;
242 pad->getcapsfunc = NULL;
244 pad->eventfunc = gst_pad_event_default;
245 pad->convertfunc = gst_pad_convert_default;
246 pad->queryfunc = gst_pad_query_default;
247 pad->intlinkfunc = gst_pad_get_internal_links_default;
249 pad->eventmaskfunc = gst_pad_get_event_masks_default;
250 pad->formatsfunc = gst_pad_get_formats_default;
251 pad->querytypefunc = gst_pad_get_query_types_default;
253 GST_FLAG_SET (pad, GST_PAD_DISABLED);
254 GST_FLAG_UNSET (pad, GST_PAD_NEGOTIATING);
256 gst_probe_dispatcher_init (&pad->probedisp);
260 gst_real_pad_set_property (GObject * object, guint prop_id,
261 const GValue * value, GParamSpec * pspec)
263 g_return_if_fail (GST_IS_PAD (object));
266 case REAL_ARG_ACTIVE:
267 gst_pad_set_active (GST_PAD (object), g_value_get_boolean (value));
270 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
276 gst_real_pad_get_property (GObject * object, guint prop_id,
277 GValue * value, GParamSpec * pspec)
279 g_return_if_fail (GST_IS_PAD (object));
282 case REAL_ARG_ACTIVE:
283 g_value_set_boolean (value, !GST_FLAG_IS_SET (object, GST_PAD_DISABLED));
286 g_value_set_boxed (value, GST_PAD_CAPS (GST_REAL_PAD (object)));
289 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
294 /* FIXME-0.9: Replace these custom functions with proper inheritance via _init
295 functions and object properties */
297 * gst_pad_custom_new:
298 * @type: the #Gtype of the pad.
299 * @name: the name of the new pad.
300 * @direction: the #GstPadDirection of the pad.
302 * Creates a new pad with the given name and type in the given direction.
303 * If name is NULL, a guaranteed unique name (across all pads)
306 * Returns: a new #GstPad, or NULL in case of an error.
309 gst_pad_custom_new (GType type, const gchar * name, GstPadDirection direction)
313 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
315 pad = g_object_new (type, NULL);
316 gst_object_set_name (GST_OBJECT (pad), name);
317 GST_RPAD_DIRECTION (pad) = direction;
319 return GST_PAD (pad);
324 * @name: the name of the new pad.
325 * @direction: the #GstPadDirection of the pad.
327 * Creates a new real pad with the given name in the given direction.
328 * If name is NULL, a guaranteed unique name (across all pads)
331 * Returns: a new #GstPad, or NULL in case of an error.
334 gst_pad_new (const gchar * name, GstPadDirection direction)
336 return gst_pad_custom_new (gst_real_pad_get_type (), name, direction);
340 * gst_pad_custom_new_from_template:
341 * @type: the custom #GType of the pad.
342 * @templ: the #GstPadTemplate to instantiate from.
343 * @name: the name of the new pad.
345 * Creates a new custom pad with the given name from the given template.
346 * If name is NULL, a guaranteed unique name (across all pads)
349 * Returns: a new #GstPad, or NULL in case of an error.
352 gst_pad_custom_new_from_template (GType type, GstPadTemplate * templ,
357 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
359 pad = gst_pad_custom_new (type, name, templ->direction);
360 gst_pad_set_pad_template (pad, templ);
366 * gst_pad_new_from_template:
367 * @templ: the pad template to use
368 * @name: the name of the element
370 * Creates a new real pad with the given name from the given template.
371 * If name is NULL, a guaranteed unique name (across all pads)
374 * Returns: a new #GstPad, or NULL in case of an error.
377 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
379 return gst_pad_custom_new_from_template (gst_real_pad_get_type (),
383 /* FIXME 0.9: GST_PAD_UNKNOWN needs to die! */
385 * gst_pad_get_direction:
386 * @pad: a #GstPad to get the direction of.
388 * Gets the direction of the pad.
390 * Returns: the #GstPadDirection of the pad.
393 gst_pad_get_direction (GstPad * pad)
395 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
397 if (GST_IS_REAL_PAD (pad))
398 return GST_PAD_DIRECTION (pad);
400 return GST_PAD_UNKNOWN;
404 * gst_pad_set_active:
405 * @pad: the #GstPad to activate or deactivate.
406 * @active: TRUE to activate the pad.
408 * Activates or deactivates the given pad.
411 gst_pad_set_active (GstPad * pad, gboolean active)
416 g_return_if_fail (GST_IS_PAD (pad));
418 old = GST_PAD_IS_ACTIVE (pad);
423 realpad = GST_PAD_REALIZE (pad);
426 GST_CAT_DEBUG (GST_CAT_PADS, "activating pad %s:%s",
427 GST_DEBUG_PAD_NAME (realpad));
428 GST_FLAG_UNSET (realpad, GST_PAD_DISABLED);
430 GST_CAT_DEBUG (GST_CAT_PADS, "de-activating pad %s:%s",
431 GST_DEBUG_PAD_NAME (realpad));
432 GST_FLAG_SET (realpad, GST_PAD_DISABLED);
435 g_object_notify (G_OBJECT (realpad), "active");
440 * @pad: the #GstPad to query
442 * Query if a pad is active
444 * Returns: TRUE if the pad is active.
447 gst_pad_is_active (GstPad * pad)
449 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
451 return !GST_FLAG_IS_SET (pad, GST_PAD_DISABLED);
456 * @pad: a #GstPad to set the name of.
457 * @name: the name of the pad.
459 * Sets the name of a pad. If name is NULL, then a guaranteed unique
460 * name will be assigned.
463 gst_pad_set_name (GstPad * pad, const gchar * name)
465 g_return_if_fail (GST_IS_PAD (pad));
467 gst_object_set_name (GST_OBJECT (pad), name);
470 /* FIXME 0.9: This function must die */
473 * @pad: a #GstPad to get the name of.
475 * Gets the name of a pad.
477 * Returns: the name of the pad. This is not a newly allocated pointer
478 * so you must not free it.
481 gst_pad_get_name (GstPad * pad)
483 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
485 return GST_OBJECT_NAME (pad);
489 * gst_pad_set_chain_function:
490 * @pad: a real sink #GstPad.
491 * @chain: the #GstPadChainFunction to set.
493 * Sets the given chain function for the pad. The chain function is called to
494 * process a #GstData input buffer.
497 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
499 g_return_if_fail (GST_IS_REAL_PAD (pad));
500 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SINK);
502 GST_RPAD_CHAINFUNC (pad) = chain;
503 GST_CAT_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
504 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
508 * gst_pad_set_get_function:
509 * @pad: a real source #GstPad.
510 * @get: the #GstPadGetFunction to set.
512 * Sets the given get function for the pad. The get function is called to
513 * produce a new #GstData to start the processing pipeline. Get functions cannot
517 gst_pad_set_get_function (GstPad * pad, GstPadGetFunction get)
519 g_return_if_fail (GST_IS_REAL_PAD (pad));
520 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SRC);
522 GST_RPAD_GETFUNC (pad) = get;
524 GST_CAT_DEBUG (GST_CAT_PADS, "getfunc for %s:%s set to %s",
525 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
529 * gst_pad_set_event_function:
530 * @pad: a real source #GstPad.
531 * @event: the #GstPadEventFunction to set.
533 * Sets the given event handler for the pad.
536 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
538 g_return_if_fail (GST_IS_REAL_PAD (pad));
539 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SRC);
541 GST_RPAD_EVENTFUNC (pad) = event;
543 GST_CAT_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
544 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
548 * gst_pad_set_event_mask_function:
549 * @pad: a real #GstPad of either direction.
550 * @mask_func: the #GstPadEventMaskFunction to set.
552 * Sets the given event mask function for the pad.
555 gst_pad_set_event_mask_function (GstPad * pad,
556 GstPadEventMaskFunction mask_func)
558 g_return_if_fail (GST_IS_REAL_PAD (pad));
560 GST_RPAD_EVENTMASKFUNC (pad) = mask_func;
562 GST_CAT_DEBUG (GST_CAT_PADS, "eventmaskfunc for %s:%s set to %s",
563 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (mask_func));
567 * gst_pad_get_event_masks:
570 * Gets the array of eventmasks from the given pad.
572 * Returns: a zero-terminated array of #GstEventMask, or NULL if the pad does
573 * not have an event mask function.
576 gst_pad_get_event_masks (GstPad * pad)
580 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
582 rpad = GST_PAD_REALIZE (pad);
584 g_return_val_if_fail (rpad, FALSE);
586 if (GST_RPAD_EVENTMASKFUNC (rpad))
587 return GST_RPAD_EVENTMASKFUNC (rpad) (GST_PAD (pad));
593 gst_pad_get_event_masks_dispatcher (GstPad * pad, const GstEventMask ** data)
595 *data = gst_pad_get_event_masks (pad);
601 * gst_pad_get_event_masks_default:
604 * Invokes the default event masks dispatcher on the pad.
606 * Returns: a zero-terminated array of #GstEventMask, or NULL if none of the
607 * internally-linked pads have an event mask function.
610 gst_pad_get_event_masks_default (GstPad * pad)
612 GstEventMask *result = NULL;
614 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
616 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
617 gst_pad_get_event_masks_dispatcher, &result);
623 * gst_pad_set_convert_function:
624 * @pad: a real #GstPad of either direction.
625 * @convert: the #GstPadConvertFunction to set.
627 * Sets the given convert function for the pad.
630 gst_pad_set_convert_function (GstPad * pad, GstPadConvertFunction convert)
632 g_return_if_fail (GST_IS_REAL_PAD (pad));
634 GST_RPAD_CONVERTFUNC (pad) = convert;
636 GST_CAT_DEBUG (GST_CAT_PADS, "convertfunc for %s:%s set to %s",
637 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (convert));
641 * gst_pad_set_query_function:
642 * @pad: a real #GstPad of either direction.
643 * @query: the #GstPadQueryFunction to set.
645 * Set the given query function for the pad.
648 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
650 g_return_if_fail (GST_IS_REAL_PAD (pad));
652 GST_RPAD_QUERYFUNC (pad) = query;
654 GST_CAT_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
655 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
659 * gst_pad_set_query_type_function:
660 * @pad: a real #GstPad of either direction.
661 * @type_func: the #GstPadQueryTypeFunction to set.
663 * Set the given query type function for the pad.
666 gst_pad_set_query_type_function (GstPad * pad,
667 GstPadQueryTypeFunction type_func)
669 g_return_if_fail (GST_IS_REAL_PAD (pad));
671 GST_RPAD_QUERYTYPEFUNC (pad) = type_func;
673 GST_CAT_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
674 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
678 * gst_pad_get_query_types:
681 * Get an array of supported queries that can be performed
684 * Returns: a zero-terminated array of #GstQueryType.
687 gst_pad_get_query_types (GstPad * pad)
691 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
693 rpad = GST_PAD_REALIZE (pad);
695 g_return_val_if_fail (rpad, NULL);
697 if (GST_RPAD_QUERYTYPEFUNC (rpad))
698 return GST_RPAD_QUERYTYPEFUNC (rpad) (GST_PAD (pad));
704 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
706 *data = gst_pad_get_query_types (pad);
712 * gst_pad_get_query_types_default:
715 * Invoke the default dispatcher for the query types on
718 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
719 * internally-linked pads has a query types function.
722 gst_pad_get_query_types_default (GstPad * pad)
724 GstQueryType *result = NULL;
726 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
728 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
729 gst_pad_get_query_types_dispatcher, &result);
735 * gst_pad_set_internal_link_function:
736 * @pad: a real #GstPad of either direction.
737 * @intlink: the #GstPadIntLinkFunction to set.
739 * Sets the given internal link function for the pad.
742 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
744 g_return_if_fail (GST_IS_REAL_PAD (pad));
746 GST_RPAD_INTLINKFUNC (pad) = intlink;
747 GST_CAT_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
748 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
752 * gst_pad_set_formats_function:
753 * @pad: a real #GstPad of either direction.
754 * @formats: the #GstPadFormatsFunction to set.
756 * Sets the given formats function for the pad.
759 gst_pad_set_formats_function (GstPad * pad, GstPadFormatsFunction formats)
761 g_return_if_fail (GST_IS_REAL_PAD (pad));
763 GST_RPAD_FORMATSFUNC (pad) = formats;
764 GST_CAT_DEBUG (GST_CAT_PADS, "formats function for %s:%s set to %s",
765 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (formats));
769 * gst_pad_set_link_function:
770 * @pad: a real #GstPad.
771 * @link: the #GstPadLinkFunction to set.
773 * Sets the given link function for the pad. It will be called when the pad is
774 * linked or relinked with caps. The caps passed to the link function are
775 * guaranteed to be fixed. This means that you can assume that the caps is not
776 * ANY or EMPTY, and that there is exactly one structure in the caps, and that
777 * all the fields in the structure are fixed.
779 * The return value GST_PAD_LINK_OK should be used when the caps are acceptable,
780 * and you've extracted all the necessary information from the caps and set the
781 * element's internal state appropriately.
783 * The return value GST_PAD_LINK_REFUSED should be used when the caps are
784 * unacceptable for whatever reason.
786 * The return value GST_PAD_LINK_DELAYED should be used when the element is in a
787 * state where it can't determine whether the caps are acceptable or not. This
788 * is often used if the element needs to open a device or process data before
789 * determining acceptable caps.
791 * @link must not call gst_caps_try_set_caps() on the pad that was specified as
792 * a parameter, although it may (and often should) call gst_caps_try_set_caps()
796 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
798 g_return_if_fail (GST_IS_REAL_PAD (pad));
800 GST_RPAD_LINKFUNC (pad) = link;
801 GST_CAT_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
802 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
806 * gst_pad_set_unlink_function:
807 * @pad: a real #GstPad.
808 * @unlink: the #GstPadUnlinkFunction to set.
810 * Sets the given unlink function for the pad. It will be called
811 * when the pad is unlinked.
814 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
816 g_return_if_fail (GST_IS_REAL_PAD (pad));
818 GST_RPAD_UNLINKFUNC (pad) = unlink;
819 GST_CAT_DEBUG (GST_CAT_PADS, "unlinkfunc for %s:%s set to %s",
820 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (unlink));
824 * gst_pad_set_fixate_function:
825 * @pad: a real #GstPad.
826 * @fixate: the #GstPadFixateFunction to set.
828 * Sets the given fixate function for the pad. Its job is to narrow down the
829 * possible caps for a connection. Fixate functions are called with a const
830 * caps, and should return a caps that is a strict subset of the given caps.
831 * That is, @fixate should create a caps that is "more fixed" than previously,
832 * but it does not have to return fixed caps. If @fixate can't provide more
833 * fixed caps, it should return %NULL.
835 * Note that @fixate will only be called after the "fixate" signal is emitted,
836 * and only if the caps are still non-fixed.
839 gst_pad_set_fixate_function (GstPad * pad, GstPadFixateFunction fixate)
841 g_return_if_fail (GST_IS_REAL_PAD (pad));
843 GST_RPAD_FIXATEFUNC (pad) = fixate;
844 GST_CAT_DEBUG (GST_CAT_PADS, "fixatefunc for %s:%s set to %s",
845 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (fixate));
849 * gst_pad_set_getcaps_function:
850 * @pad: a real #GstPad.
851 * @getcaps: the #GstPadGetCapsFunction to set.
853 * Sets the given getcaps function for the pad. @getcaps should return the
854 * allowable caps for a pad in the context of the element's state, its link to
855 * other elements, and the devices or files it has opened. These caps must be a
856 * subset of the pad template caps. In the NULL state with no links, @getcaps
857 * should ideally return the same caps as the pad template. In rare
858 * circumstances, an object property can affect the caps returned by @getcaps,
859 * but this is discouraged.
861 * You do not need to call this function if @pad's allowed caps are always the
862 * same as the pad template caps.
864 * For most filters, the caps returned by @getcaps is directly affected by the
865 * allowed caps on other pads. For demuxers and decoders, the caps returned by
866 * the srcpad's getcaps function is directly related to the stream data. Again,
867 * @getcaps should return the most specific caps it reasonably can, since this
868 * helps with autoplugging. However, the returned caps should not depend on the
869 * stream type currently negotiated for @pad.
871 * Note that the return value from @getcaps is owned by the caller.
874 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
876 g_return_if_fail (GST_IS_REAL_PAD (pad));
878 GST_RPAD_GETCAPSFUNC (pad) = getcaps;
879 GST_CAT_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
880 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
884 * gst_pad_set_bufferalloc_function:
885 * @pad: a real sink #GstPad.
886 * @bufalloc: the #GstPadBufferAllocFunction to set.
888 * Sets the given bufferalloc function for the pad. Note that the
889 * bufferalloc function can only be set on sinkpads.
892 gst_pad_set_bufferalloc_function (GstPad * pad,
893 GstPadBufferAllocFunction bufalloc)
895 g_return_if_fail (GST_IS_REAL_PAD (pad));
896 g_return_if_fail (GST_PAD_IS_SINK (pad));
898 GST_RPAD_BUFFERALLOCFUNC (pad) = bufalloc;
899 GST_CAT_DEBUG (GST_CAT_PADS, "bufferallocfunc for %s:%s set to %s",
900 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufalloc));
903 /* FIXME 0.9: Do we actually want to allow the case where src and sink are
907 * @srcpad: the source #GstPad to unlink.
908 * @sinkpad: the sink #GstPad to unlink.
910 * Unlinks the source pad from the sink pad. Will emit the "unlinked" signal on
914 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
916 GstRealPad *realsrc, *realsink;
917 GstScheduler *src_sched, *sink_sched;
919 g_return_if_fail (GST_IS_PAD (srcpad));
920 g_return_if_fail (GST_IS_PAD (sinkpad));
922 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
923 GST_DEBUG_PAD_NAME (srcpad), srcpad,
924 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
926 realsrc = GST_PAD_REALIZE (srcpad);
927 realsink = GST_PAD_REALIZE (sinkpad);
929 g_return_if_fail (GST_RPAD_PEER (realsrc) != NULL);
930 g_return_if_fail (GST_RPAD_PEER (realsink) == realsrc);
932 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
933 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
940 g_return_if_fail ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
941 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK));
943 if (GST_RPAD_UNLINKFUNC (realsrc)) {
944 GST_RPAD_UNLINKFUNC (realsrc) (GST_PAD (realsrc));
946 if (GST_RPAD_UNLINKFUNC (realsink)) {
947 GST_RPAD_UNLINKFUNC (realsink) (GST_PAD (realsink));
950 /* get the schedulers before we unlink */
951 src_sched = gst_pad_get_scheduler (GST_PAD (realsrc));
952 sink_sched = gst_pad_get_scheduler (GST_PAD (realsink));
954 if (GST_RPAD_LINK (realsrc))
955 gst_pad_link_free (GST_RPAD_LINK (realsrc));
957 /* first clear peers */
958 GST_RPAD_PEER (realsrc) = NULL;
959 GST_RPAD_PEER (realsink) = NULL;
960 GST_RPAD_LINK (realsrc) = NULL;
961 GST_RPAD_LINK (realsink) = NULL;
963 /* now tell the scheduler */
964 if (src_sched && src_sched == sink_sched) {
965 gst_scheduler_pad_unlink (src_sched, GST_PAD (realsrc), GST_PAD (realsink));
968 /* hold a reference, as they can go away in the signal handlers */
969 gst_object_ref (GST_OBJECT (realsrc));
970 gst_object_ref (GST_OBJECT (realsink));
972 /* fire off a signal to each of the pads telling them
973 * that they've been unlinked */
974 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_UNLINKED],
976 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_UNLINKED],
979 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
980 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
982 gst_object_unref (GST_OBJECT (realsrc));
983 gst_object_unref (GST_OBJECT (realsink));
990 * Checks if a @pad is linked to another pad or not.
992 * Returns: TRUE if the pad is linked, FALSE otherwise.
995 gst_pad_is_linked (GstPad * pad)
997 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
999 return GST_PAD_PEER (pad) != NULL;
1008 gboolean sinknotify;
1015 GstCaps *filtercaps;
1018 GstPadFixateFunction app_fixate;
1022 gst_pad_check_schedulers (GstRealPad * realsrc, GstRealPad * realsink)
1024 GstScheduler *src_sched, *sink_sched;
1025 gint num_decoupled = 0;
1027 src_sched = gst_pad_get_scheduler (GST_PAD (realsrc));
1028 sink_sched = gst_pad_get_scheduler (GST_PAD (realsink));
1030 if (src_sched && sink_sched) {
1031 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsrc), GST_ELEMENT_DECOUPLED))
1033 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsink), GST_ELEMENT_DECOUPLED))
1036 if (src_sched != sink_sched && num_decoupled != 1) {
1043 #define GST_PAD_LINK_SRC(pad) ((GST_PAD_IS_SRC (pad)) ? (pad) : GST_PAD_PEER (pad))
1044 #define GST_PAD_LINK_SINK(pad) ((GST_PAD_IS_SINK (pad)) ? (pad) : GST_PAD_PEER (pad))
1047 gst_pad_link_new (void)
1051 link = g_new0 (GstPadLink, 1);
1052 link->sinknotify = TRUE;
1053 link->srcnotify = TRUE;
1058 gst_pad_link_free (GstPadLink * link)
1061 gst_caps_free (link->srccaps);
1063 gst_caps_free (link->sinkcaps);
1064 if (link->filtercaps)
1065 gst_caps_free (link->filtercaps);
1067 gst_caps_free (link->caps);
1068 #ifdef USE_POISONING
1069 memset (link, 0xff, sizeof (*link));
1075 gst_pad_link_intersect (GstPadLink * link)
1077 GstCaps *pad_intersection;
1080 gst_caps_free (link->caps);
1082 GST_DEBUG ("intersecting link from %s:%s to %s:%s",
1083 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1084 GST_DEBUG ("... srccaps %" GST_PTR_FORMAT, link->srccaps);
1085 GST_DEBUG ("... sinkcaps %" GST_PTR_FORMAT, link->sinkcaps);
1086 GST_DEBUG ("... filtercaps %" GST_PTR_FORMAT, link->filtercaps);
1088 pad_intersection = gst_caps_intersect (link->srccaps, link->sinkcaps);
1090 if (link->filtercaps) {
1091 GST_DEBUG ("unfiltered intersection %" GST_PTR_FORMAT, pad_intersection);
1092 link->caps = gst_caps_intersect (pad_intersection, link->filtercaps);
1093 gst_caps_free (pad_intersection);
1095 link->caps = pad_intersection;
1098 GST_DEBUG ("intersection %" GST_PTR_FORMAT, link->caps);
1102 gst_pad_link_ready_for_negotiation (GstPadLink * link)
1106 parent = GST_PAD_PARENT (link->srcpad);
1107 if (!parent || GST_STATE (parent) < GST_STATE_READY) {
1108 GST_DEBUG ("parent %s of pad %s:%s is not READY",
1109 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (link->srcpad));
1112 parent = GST_PAD_PARENT (link->sinkpad);
1113 if (!parent || GST_STATE (parent) < GST_STATE_READY) {
1114 GST_DEBUG ("parent %s of pad %s:%s is not READY",
1115 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (link->sinkpad));
1123 gst_pad_link_fixate (GstPadLink * link)
1130 g_return_if_fail (caps != NULL);
1131 g_return_if_fail (!gst_caps_is_empty (caps));
1133 GST_DEBUG ("trying to fixate caps %" GST_PTR_FORMAT, caps);
1135 while (!gst_caps_is_fixed (caps)) {
1138 for (i = 0; i < 5; i++) {
1142 g_signal_emit (G_OBJECT (link->srcpad),
1143 gst_real_pad_signals[REAL_FIXATE], 0, caps, &newcaps);
1144 GST_DEBUG ("app srcpad signal fixated to %" GST_PTR_FORMAT, newcaps);
1147 g_signal_emit (G_OBJECT (link->sinkpad),
1148 gst_real_pad_signals[REAL_FIXATE], 0, caps, &newcaps);
1149 GST_DEBUG ("app sinkpad signal fixated to %" GST_PTR_FORMAT, newcaps);
1152 if (GST_RPAD_FIXATEFUNC (link->srcpad)) {
1154 GST_RPAD_FIXATEFUNC (link->srcpad) (GST_PAD (link->srcpad),
1156 GST_DEBUG ("srcpad %s:%s fixated to %" GST_PTR_FORMAT,
1157 GST_DEBUG_PAD_NAME (link->srcpad), newcaps);
1159 GST_DEBUG ("srcpad %s:%s doesn't have a fixate function",
1160 GST_DEBUG_PAD_NAME (link->srcpad));
1164 if (GST_RPAD_FIXATEFUNC (link->sinkpad)) {
1166 GST_RPAD_FIXATEFUNC (link->sinkpad) (GST_PAD (link->sinkpad),
1168 GST_DEBUG ("sinkpad %s:%s fixated to %" GST_PTR_FORMAT,
1169 GST_DEBUG_PAD_NAME (link->sinkpad), newcaps);
1171 GST_DEBUG ("sinkpad %s:%s doesn't have a fixate function",
1172 GST_DEBUG_PAD_NAME (link->sinkpad));
1175 newcaps = _gst_pad_default_fixate_func (GST_PAD (link->srcpad), caps);
1176 GST_DEBUG ("core fixated to %" GST_PTR_FORMAT, newcaps);
1180 gst_caps_free (caps);
1190 static GstPadLinkReturn
1191 gst_pad_link_call_link_functions (GstPadLink * link)
1193 gboolean negotiating;
1194 GstPadLinkReturn res;
1196 if (link->srcnotify && GST_RPAD_LINKFUNC (link->srcpad)) {
1197 GST_DEBUG ("calling link function on pad %s:%s",
1198 GST_DEBUG_PAD_NAME (link->srcpad));
1200 negotiating = GST_FLAG_IS_SET (link->srcpad, GST_PAD_NEGOTIATING);
1202 /* set the NEGOTIATING flag if not already done */
1204 GST_FLAG_SET (link->srcpad, GST_PAD_NEGOTIATING);
1206 /* call the link function */
1207 res = GST_RPAD_LINKFUNC (link->srcpad) (GST_PAD (link->srcpad), link->caps);
1209 /* unset again after negotiating only if we set it */
1211 GST_FLAG_UNSET (link->srcpad, GST_PAD_NEGOTIATING);
1213 GST_DEBUG ("got reply %d from link function on pad %s:%s",
1214 res, GST_DEBUG_PAD_NAME (link->srcpad));
1216 if (GST_PAD_LINK_FAILED (res)) {
1217 GST_CAT_INFO (GST_CAT_CAPS, "pad %s:%s doesn't accept caps",
1218 GST_DEBUG_PAD_NAME (link->srcpad));
1223 if (link->sinknotify && GST_RPAD_LINKFUNC (link->sinkpad)) {
1224 GST_DEBUG ("calling link function on pad %s:%s",
1225 GST_DEBUG_PAD_NAME (link->sinkpad));
1227 negotiating = GST_FLAG_IS_SET (link->sinkpad, GST_PAD_NEGOTIATING);
1229 /* set the NEGOTIATING flag if not already done */
1231 GST_FLAG_SET (link->sinkpad, GST_PAD_NEGOTIATING);
1233 /* call the link function */
1234 res = GST_RPAD_LINKFUNC (link->sinkpad) (GST_PAD (link->sinkpad),
1237 /* unset again after negotiating only if we set it */
1239 GST_FLAG_UNSET (link->sinkpad, GST_PAD_NEGOTIATING);
1241 GST_DEBUG ("got reply %d from link function on pad %s:%s",
1242 res, GST_DEBUG_PAD_NAME (link->sinkpad));
1244 if (GST_PAD_LINK_FAILED (res)) {
1245 GST_CAT_INFO (GST_CAT_CAPS, "pad %s:%s doesn't accept caps",
1246 GST_DEBUG_PAD_NAME (link->sinkpad));
1251 return GST_PAD_LINK_OK;
1254 static GstPadLinkReturn
1255 gst_pad_link_negotiate (GstPadLink * link)
1257 GST_DEBUG ("negotiating link from pad %s:%s to pad %s:%s",
1258 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1260 if (!gst_pad_link_ready_for_negotiation (link)) {
1261 return GST_PAD_LINK_DELAYED;
1264 gst_pad_link_intersect (link);
1265 if (gst_caps_is_empty (link->caps))
1266 return GST_PAD_LINK_REFUSED;
1268 gst_pad_link_fixate (link);
1269 if (gst_caps_is_empty (link->caps))
1270 return GST_PAD_LINK_REFUSED;
1272 return gst_pad_link_call_link_functions (link);
1277 * @link: link to try
1279 * Tries to (re)link the pads with the given link. The function takes ownership
1280 * of the supplied link. If the function returns FALSE and an old link existed,
1281 * that link can be assumed to work unchanged.
1283 * Returns: TRUE if the link succeeded, FALSE if not.
1286 gst_pad_link_try (GstPadLink * link)
1288 GstPad *srcpad, *sinkpad;
1289 GstPadLink *oldlink;
1290 GstPadLinkReturn ret;
1292 /* we use assertions here, because this function is static */
1294 srcpad = link->srcpad;
1296 sinkpad = link->sinkpad;
1298 oldlink = GST_RPAD_LINK (srcpad);
1299 g_assert (oldlink == GST_RPAD_LINK (sinkpad));
1301 ret = gst_pad_link_negotiate (link);
1302 if (GST_PAD_LINK_FAILED (ret) && oldlink && oldlink->caps) {
1303 oldlink->srcnotify = link->srcnotify;
1304 oldlink->sinknotify = link->sinknotify;
1305 if (GST_PAD_LINK_FAILED (gst_pad_link_call_link_functions (oldlink))) {
1306 g_warning ("pads don't accept old caps. We assume they did though");
1309 if (ret == GST_PAD_LINK_REFUSED) {
1310 gst_pad_link_free (link);
1313 if (ret == GST_PAD_LINK_DELAYED) {
1314 gst_caps_replace (&link->caps, NULL);
1317 GST_RPAD_PEER (srcpad) = GST_REAL_PAD (link->sinkpad);
1318 GST_RPAD_PEER (sinkpad) = GST_REAL_PAD (link->srcpad);
1320 gst_pad_link_free (oldlink);
1321 GST_RPAD_LINK (srcpad) = link;
1322 GST_RPAD_LINK (sinkpad) = link;
1323 if (ret == GST_PAD_LINK_OK) {
1324 g_object_notify (G_OBJECT (srcpad), "caps");
1325 g_object_notify (G_OBJECT (sinkpad), "caps");
1332 * gst_pad_renegotiate:
1335 * Initiate caps negotiation on @pad. @pad must be linked.
1337 * If @pad's parent is not at least in #GST_STATE_READY, returns
1338 * #GST_PAD_LINK_DELAYED.
1340 * Otherwise caps are retrieved from both @pad and its peer by calling their
1341 * getcaps functions. They are then intersected, returning #GST_PAD_LINK_FAIL if
1342 * there is no intersection.
1344 * The intersection is fixated if necessary, and then the link functions of @pad
1345 * and its peer are called.
1347 * Returns: The return value of @pad's link function (see
1348 * gst_pad_set_link_function()), or #GST_PAD_LINK_OK if there is no link
1351 * The macros GST_PAD_LINK_SUCCESSFUL() and GST_PAD_LINK_FAILED() should be used
1352 * when you just need success/failure information.
1355 gst_pad_renegotiate (GstPad * pad)
1359 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
1360 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1361 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1363 link = gst_pad_link_new ();
1365 link->srcpad = GST_PAD_LINK_SRC (pad);
1366 link->sinkpad = GST_PAD_LINK_SINK (pad);
1368 if (!gst_pad_link_ready_for_negotiation (link)) {
1369 gst_pad_link_free (link);
1370 return GST_PAD_LINK_DELAYED;
1373 if (GST_REAL_PAD (pad)->link->filtercaps) {
1374 link->filtercaps = gst_caps_copy (GST_REAL_PAD (pad)->link->filtercaps);
1376 link->srccaps = gst_pad_get_caps (link->srcpad);
1377 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1379 return gst_pad_link_try (link);
1383 * gst_pad_try_set_caps:
1385 * @caps: #GstCaps to set on @pad
1387 * Try to set the caps on @pad. @caps must be fixed. If @pad is unlinked,
1388 * returns #GST_PAD_LINK_OK without doing anything. Otherwise, start caps
1389 * negotiation on @pad.
1391 * Returns: The return value of @pad's link function (see
1392 * gst_pad_set_link_function()), or #GST_PAD_LINK_OK if there is no link
1395 * The macros GST_PAD_LINK_SUCCESSFUL() and GST_PAD_LINK_FAILED() should be used
1396 * when you just need success/failure information.
1399 gst_pad_try_set_caps (GstPad * pad, const GstCaps * caps)
1402 GstPadLink *oldlink;
1403 GstPadLinkReturn ret;
1405 g_return_val_if_fail (GST_IS_REAL_PAD (pad), GST_PAD_LINK_REFUSED);
1406 g_return_val_if_fail (!GST_PAD_IS_NEGOTIATING (pad), GST_PAD_LINK_REFUSED);
1408 /* setting non-fixed caps on a pad is not allowed */
1409 if (!gst_caps_is_fixed (caps)) {
1410 GST_CAT_INFO (GST_CAT_CAPS,
1411 "trying to set unfixed caps on pad %s:%s, not allowed",
1412 GST_DEBUG_PAD_NAME (pad));
1413 g_warning ("trying to set non fixed caps on pad %s:%s, not allowed",
1414 GST_DEBUG_PAD_NAME (pad));
1416 GST_DEBUG ("unfixed caps %" GST_PTR_FORMAT, caps);
1417 return GST_PAD_LINK_REFUSED;
1420 /* we allow setting caps on non-linked pads. It's ignored */
1421 if (!GST_PAD_PEER (pad)) {
1422 return GST_PAD_LINK_OK;
1425 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1426 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1428 /* if the desired caps are already there, it's trivially ok */
1429 if (GST_PAD_CAPS (pad) && gst_caps_is_equal_fixed (caps, GST_PAD_CAPS (pad))) {
1430 return GST_PAD_LINK_OK;
1433 link = gst_pad_link_new ();
1435 link->srcpad = GST_PAD_LINK_SRC (pad);
1436 link->sinkpad = GST_PAD_LINK_SINK (pad);
1438 if (!gst_pad_link_ready_for_negotiation (link)) {
1439 gst_pad_link_free (link);
1440 return GST_PAD_LINK_DELAYED;
1443 oldlink = GST_REAL_PAD (pad)->link;
1444 if (oldlink && oldlink->filtercaps) {
1445 link->filtercaps = gst_caps_copy (oldlink->filtercaps);
1447 if (link->srcpad == pad) {
1448 link->srccaps = gst_caps_copy (caps);
1449 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1450 link->srcnotify = FALSE;
1452 link->srccaps = gst_pad_get_caps (link->srcpad);
1453 link->sinkcaps = gst_caps_copy (caps);
1454 link->sinknotify = FALSE;
1457 ret = gst_pad_link_try (link);
1463 * gst_pad_try_set_caps_nonfixed:
1464 * @pad: a real #GstPad
1465 * @caps: #GstCaps to set on @pad
1467 * Like gst_pad_try_set_caps(), but allows non-fixed caps.
1469 * Returns: a #GstPadLinkReturn, like gst_pad_try_set_caps().
1472 gst_pad_try_set_caps_nonfixed (GstPad * pad, const GstCaps * caps)
1475 GstPadLink *oldlink;
1476 GstPadLinkReturn ret;
1478 g_return_val_if_fail (GST_IS_REAL_PAD (pad), GST_PAD_LINK_REFUSED);
1479 g_return_val_if_fail (!GST_PAD_IS_NEGOTIATING (pad), GST_PAD_LINK_REFUSED);
1481 /* we allow setting caps on non-linked pads. It's ignored */
1482 if (!GST_PAD_PEER (pad)) {
1483 return GST_PAD_LINK_OK;
1486 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1487 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1489 /* if the link is already negotiated and the caps are compatible
1490 * with what we're setting, it's trivially OK. */
1491 if (GST_PAD_CAPS (pad)) {
1492 GstCaps *intersection;
1494 intersection = gst_caps_intersect (caps, GST_PAD_CAPS (pad));
1495 if (!gst_caps_is_empty (intersection)) {
1496 gst_caps_free (intersection);
1497 return GST_PAD_LINK_OK;
1499 gst_caps_free (intersection);
1502 link = gst_pad_link_new ();
1504 link->srcpad = GST_PAD_LINK_SRC (pad);
1505 link->sinkpad = GST_PAD_LINK_SINK (pad);
1507 if (!gst_pad_link_ready_for_negotiation (link)) {
1508 gst_pad_link_free (link);
1509 return GST_PAD_LINK_DELAYED;
1512 oldlink = GST_REAL_PAD (pad)->link;
1513 if (oldlink && oldlink->filtercaps) {
1514 link->filtercaps = gst_caps_copy (oldlink->filtercaps);
1516 if (link->srcpad == pad) {
1517 link->srccaps = gst_caps_copy (caps);
1518 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1519 link->srcnotify = FALSE;
1521 link->srccaps = gst_pad_get_caps (link->srcpad);
1522 link->sinkcaps = gst_caps_copy (caps);
1523 link->sinknotify = FALSE;
1526 ret = gst_pad_link_try (link);
1532 * gst_pad_can_link_filtered:
1533 * @srcpad: the source #GstPad to link.
1534 * @sinkpad: the sink #GstPad to link.
1535 * @filtercaps: the filter #GstCaps.
1537 * Checks if the source pad and the sink pad can be linked when constrained
1538 * by the given filter caps. Both @srcpad and @sinkpad must be unlinked.
1540 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1543 gst_pad_can_link_filtered (GstPad * srcpad, GstPad * sinkpad,
1544 const GstCaps * filtercaps)
1546 GstRealPad *realsrc, *realsink;
1549 /* FIXME This function is gross. It's almost a direct copy of
1550 * gst_pad_link_filtered(). Any decent programmer would attempt
1551 * to merge the two functions, which I will do some day. --ds
1554 /* generic checks */
1555 g_return_val_if_fail (srcpad != NULL, FALSE);
1556 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1557 g_return_val_if_fail (sinkpad != NULL, FALSE);
1558 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1560 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1561 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1563 /* now we need to deal with the real/ghost stuff */
1564 realsrc = GST_PAD_REALIZE (srcpad);
1565 realsink = GST_PAD_REALIZE (sinkpad);
1567 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1568 GST_CAT_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
1569 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1571 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1572 if (GST_RPAD_PEER (realsrc) != NULL) {
1573 GST_CAT_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1574 GST_DEBUG_PAD_NAME (realsrc));
1577 if (GST_RPAD_PEER (realsink) != NULL) {
1578 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1579 GST_DEBUG_PAD_NAME (realsink));
1582 if (GST_PAD_PARENT (realsrc) == NULL) {
1583 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1584 GST_DEBUG_PAD_NAME (realsrc));
1587 if (GST_PAD_PARENT (realsink) == NULL) {
1588 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has no parent, failed",
1589 GST_DEBUG_PAD_NAME (realsrc));
1593 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1594 g_warning ("linking pads with different scheds requires "
1595 "exactly one decoupled element (such as queue)");
1599 g_return_val_if_fail (realsrc != NULL, GST_PAD_LINK_REFUSED);
1600 g_return_val_if_fail (realsink != NULL, GST_PAD_LINK_REFUSED);
1602 link = gst_pad_link_new ();
1604 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
1605 link->srcpad = GST_PAD (realsrc);
1606 link->sinkpad = GST_PAD (realsink);
1608 link->srcpad = GST_PAD (realsink);
1609 link->sinkpad = GST_PAD (realsrc);
1612 if (GST_RPAD_DIRECTION (link->srcpad) != GST_PAD_SRC) {
1613 GST_CAT_INFO (GST_CAT_PADS,
1614 "Real src pad %s:%s is not a source pad, failed",
1615 GST_DEBUG_PAD_NAME (link->srcpad));
1616 gst_pad_link_free (link);
1619 if (GST_RPAD_DIRECTION (link->sinkpad) != GST_PAD_SINK) {
1620 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1621 GST_DEBUG_PAD_NAME (link->sinkpad));
1622 gst_pad_link_free (link);
1626 link->srccaps = gst_pad_get_caps (link->srcpad);
1627 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1629 link->filtercaps = gst_caps_copy (filtercaps);
1631 gst_pad_link_intersect (link);
1632 if (gst_caps_is_empty (link->caps)) {
1633 gst_pad_link_free (link);
1637 gst_pad_link_free (link);
1643 * @srcpad: the source #GstPad to link.
1644 * @sinkpad: the sink #GstPad to link.
1646 * Checks if the source pad and the sink pad can be linked.
1648 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1651 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1653 return gst_pad_can_link_filtered (srcpad, sinkpad, NULL);
1657 * gst_pad_link_filtered:
1658 * @srcpad: the source #GstPad to link.
1659 * @sinkpad: the sink #GstPad to link.
1660 * @filtercaps: the filter #GstCaps.
1662 * Links the source pad and the sink pad, constrained
1663 * by the given filter caps.
1665 * Returns: TRUE if the pads have been linked, FALSE otherwise.
1668 gst_pad_link_filtered (GstPad * srcpad, GstPad * sinkpad,
1669 const GstCaps * filtercaps)
1671 GstRealPad *realsrc, *realsink;
1672 GstScheduler *src_sched, *sink_sched;
1675 /* generic checks */
1676 g_return_val_if_fail (srcpad != NULL, FALSE);
1677 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1678 g_return_val_if_fail (sinkpad != NULL, FALSE);
1679 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1681 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1682 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1684 /* now we need to deal with the real/ghost stuff */
1685 realsrc = GST_PAD_REALIZE (srcpad);
1686 realsink = GST_PAD_REALIZE (sinkpad);
1688 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1689 GST_CAT_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
1690 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1692 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1693 if (GST_RPAD_PEER (realsrc) != NULL) {
1694 GST_CAT_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1695 GST_DEBUG_PAD_NAME (realsrc));
1698 if (GST_RPAD_PEER (realsink) != NULL) {
1699 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1700 GST_DEBUG_PAD_NAME (realsink));
1703 if (GST_PAD_PARENT (realsrc) == NULL) {
1704 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1705 GST_DEBUG_PAD_NAME (realsrc));
1708 if (GST_PAD_PARENT (realsink) == NULL) {
1709 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has no parent, failed",
1710 GST_DEBUG_PAD_NAME (realsrc));
1714 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1715 g_warning ("linking pads with different scheds requires "
1716 "exactly one decoupled element (such as queue)");
1720 g_return_val_if_fail (realsrc != NULL, GST_PAD_LINK_REFUSED);
1721 g_return_val_if_fail (realsink != NULL, GST_PAD_LINK_REFUSED);
1723 link = gst_pad_link_new ();
1725 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
1726 link->srcpad = GST_PAD (realsrc);
1727 link->sinkpad = GST_PAD (realsink);
1729 link->srcpad = GST_PAD (realsink);
1730 link->sinkpad = GST_PAD (realsrc);
1733 if (GST_RPAD_DIRECTION (link->srcpad) != GST_PAD_SRC) {
1734 GST_CAT_INFO (GST_CAT_PADS,
1735 "Real src pad %s:%s is not a source pad, failed",
1736 GST_DEBUG_PAD_NAME (link->srcpad));
1737 gst_pad_link_free (link);
1740 if (GST_RPAD_DIRECTION (link->sinkpad) != GST_PAD_SINK) {
1741 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1742 GST_DEBUG_PAD_NAME (link->sinkpad));
1743 gst_pad_link_free (link);
1747 link->srccaps = gst_pad_get_caps (link->srcpad);
1748 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1750 link->filtercaps = gst_caps_copy (filtercaps);
1751 if (gst_pad_link_try (link) == GST_PAD_LINK_REFUSED)
1754 /* fire off a signal to each of the pads telling them
1755 * that they've been linked */
1756 g_signal_emit (G_OBJECT (link->srcpad), gst_real_pad_signals[REAL_LINKED],
1758 g_signal_emit (G_OBJECT (link->sinkpad), gst_real_pad_signals[REAL_LINKED],
1761 src_sched = gst_pad_get_scheduler (GST_PAD (link->srcpad));
1762 sink_sched = gst_pad_get_scheduler (GST_PAD (link->sinkpad));
1764 /* now tell the scheduler */
1765 if (src_sched && src_sched == sink_sched) {
1766 gst_scheduler_pad_link (src_sched,
1767 GST_PAD (link->srcpad), GST_PAD (link->sinkpad));
1769 GST_CAT_INFO (GST_CAT_PADS,
1770 "not telling link to scheduler %s:%s and %s:%s, %p %p",
1771 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad),
1772 src_sched, sink_sched);
1775 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1776 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1783 * @srcpad: the source #GstPad to link.
1784 * @sinkpad: the sink #GstPad to link.
1786 * Links the source pad to the sink pad.
1788 * Returns: TRUE if the pad could be linked, FALSE otherwise.
1791 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
1793 return gst_pad_link_filtered (srcpad, sinkpad, NULL);
1796 /* FIXME 0.9: Remove this */
1798 * gst_pad_set_parent:
1799 * @pad: a #GstPad to set the parent of.
1800 * @parent: the new parent #GstElement.
1802 * Sets the parent object of a pad. Deprecated, use gst_object_set_parent()
1806 gst_pad_set_parent (GstPad * pad, GstElement * parent)
1808 g_return_if_fail (GST_IS_PAD (pad));
1809 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
1810 g_return_if_fail (GST_IS_ELEMENT (parent));
1812 gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (parent));
1815 /* FIXME 0.9: Remove this */
1817 * gst_pad_get_parent:
1818 * @pad: the #GstPad to get the parent of.
1820 * Gets the parent object of this pad. Deprecated, use gst_object_get_parent()
1823 * Returns: the parent #GstElement.
1826 gst_pad_get_parent (GstPad * pad)
1828 g_return_val_if_fail (pad != NULL, NULL);
1829 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1831 return GST_PAD_PARENT (pad);
1835 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
1837 /* this function would need checks if it weren't static */
1839 gst_object_replace ((GstObject **) & pad->padtemplate, (GstObject *) templ);
1842 g_signal_emit (G_OBJECT (templ),
1843 gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
1847 * gst_pad_get_pad_template:
1850 * Gets the template for @pad.
1852 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
1853 * if this pad has no template.
1856 gst_pad_get_pad_template (GstPad * pad)
1858 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1860 return GST_PAD_PAD_TEMPLATE (pad);
1865 * gst_pad_get_scheduler:
1866 * @pad: a #GstPad to get the scheduler of.
1868 * Gets the scheduler of the pad. Since the pad does not
1869 * have a scheduler of its own, the scheduler of the parent
1870 * is taken. For decoupled pads, the scheduler of the peer
1873 * Returns: the #GstScheduler of the pad, or %NULL if there is no parent or the
1874 * parent is not yet in a managing bin.
1877 gst_pad_get_scheduler (GstPad * pad)
1879 GstScheduler *scheduler = NULL;
1882 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1884 parent = gst_pad_get_parent (pad);
1886 if (GST_FLAG_IS_SET (parent, GST_ELEMENT_DECOUPLED)) {
1887 GstRealPad *peer = GST_RPAD_PEER (pad);
1891 gst_element_get_scheduler (gst_pad_get_parent (GST_PAD (peer)));
1894 scheduler = gst_element_get_scheduler (parent);
1902 * gst_pad_get_real_parent:
1903 * @pad: a #GstPad to get the real parent of.
1905 * Gets the real parent object of this pad. If the pad
1906 * is a ghost pad, the actual owner of the real pad is
1907 * returned, as opposed to #gst_pad_get_parent().
1909 * Returns: the parent #GstElement.
1912 gst_pad_get_real_parent (GstPad * pad)
1914 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1916 return GST_PAD_PARENT (GST_PAD (GST_PAD_REALIZE (pad)));
1919 /* FIXME 0.9: Make static. */
1921 * gst_pad_add_ghost_pad:
1922 * @pad: a #GstPad to attach the ghost pad to.
1923 * @ghostpad: the ghost #GstPad to to the pad.
1925 * Adds a ghost pad to a pad. Private function, will be removed from the API in
1929 gst_pad_add_ghost_pad (GstPad * pad, GstPad * ghostpad)
1931 GstRealPad *realpad;
1933 g_return_if_fail (GST_IS_PAD (pad));
1934 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1936 /* if we're ghosting a ghost pad, drill down to find the real pad */
1937 realpad = (GstRealPad *) pad;
1938 while (GST_IS_GHOST_PAD (realpad))
1939 realpad = GST_GPAD_REALPAD (realpad);
1940 g_return_if_fail (GST_IS_REAL_PAD (realpad));
1942 /* will ref the pad template */
1943 GST_GPAD_REALPAD (ghostpad) = realpad;
1944 realpad->ghostpads = g_list_prepend (realpad->ghostpads, ghostpad);
1945 gst_pad_set_pad_template (GST_PAD (ghostpad), GST_PAD_PAD_TEMPLATE (pad));
1948 /* FIXME 0.9: Make static. */
1950 * gst_pad_remove_ghost_pad:
1951 * @pad: a #GstPad to remove the ghost pad from.
1952 * @ghostpad: the ghost #GstPad to remove from the pad.
1954 * Removes a ghost pad from a pad. Private, will be removed from the API in 0.9.
1957 gst_pad_remove_ghost_pad (GstPad * pad, GstPad * ghostpad)
1959 GstRealPad *realpad;
1961 g_return_if_fail (GST_IS_PAD (pad));
1962 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1963 realpad = GST_PAD_REALIZE (pad);
1964 g_return_if_fail (GST_GPAD_REALPAD (ghostpad) == realpad);
1966 gst_pad_set_pad_template (GST_PAD (ghostpad), NULL);
1967 realpad->ghostpads = g_list_remove (realpad->ghostpads, ghostpad);
1968 GST_GPAD_REALPAD (ghostpad) = NULL;
1972 * gst_pad_get_ghost_pad_list:
1973 * @pad: a #GstPad to get the ghost pads of.
1975 * Gets the ghost pads of this pad.
1977 * Returns: a #GList of ghost pads.
1980 gst_pad_get_ghost_pad_list (GstPad * pad)
1982 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1984 return GST_PAD_REALIZE (pad)->ghostpads;
1988 _gst_pad_default_fixate_foreach (GQuark field_id, GValue * value, gpointer s)
1990 GstStructure *structure = (GstStructure *) s;
1991 GType type = G_VALUE_TYPE (value);
1993 if (G_TYPE_IS_FUNDAMENTAL (type) || type == GST_TYPE_FOURCC)
1996 if (type == GST_TYPE_INT_RANGE) {
1997 gst_structure_set (structure, g_quark_to_string (field_id),
1998 G_TYPE_INT, gst_value_get_int_range_min (value), NULL);
2001 if (type == GST_TYPE_DOUBLE_RANGE) {
2002 gst_structure_set (structure, g_quark_to_string (field_id),
2003 G_TYPE_DOUBLE, gst_value_get_double_range_min (value), NULL);
2006 if (type == GST_TYPE_LIST) {
2007 gst_structure_set_value (structure, g_quark_to_string (field_id),
2008 gst_value_list_get_value (value, 0));
2012 g_critical ("don't know how to fixate type %s", g_type_name (type));
2017 _gst_pad_default_fixate_func (GstPad * pad, const GstCaps * caps)
2019 static GstStaticCaps octetcaps = GST_STATIC_CAPS ("application/octet-stream");
2020 GstStructure *structure;
2023 g_return_val_if_fail (pad != NULL, NULL);
2024 g_return_val_if_fail (caps != NULL, NULL);
2025 g_return_val_if_fail (!gst_caps_is_empty (caps), NULL);
2027 if (gst_caps_is_any (caps)) {
2028 return gst_caps_copy (gst_static_caps_get (&octetcaps));
2031 if (caps->structs->len > 1) {
2032 return gst_caps_new_full (gst_structure_copy (gst_caps_get_structure (caps,
2036 newcaps = gst_caps_copy (caps);
2037 structure = gst_caps_get_structure (newcaps, 0);
2038 gst_structure_foreach (structure, _gst_pad_default_fixate_foreach, structure);
2044 * gst_pad_perform_negotiate:
2045 * @srcpad: the source #GstPad.
2046 * @sinkpad: the sink #GstPad.
2048 * Tries to negotiate the pads. See gst_pad_renegotiate() for a brief
2049 * description of caps negotiation.
2051 * Returns: TRUE if the pads were succesfully negotiated, FALSE otherwise.
2054 gst_pad_perform_negotiate (GstPad * srcpad, GstPad * sinkpad)
2056 return GST_PAD_LINK_SUCCESSFUL (gst_pad_renegotiate (srcpad));
2060 gst_pad_link_unnegotiate (GstPadLink * link)
2062 g_return_if_fail (link != NULL);
2065 gst_caps_free (link->caps);
2067 if (GST_RPAD_LINK (link->srcpad) != link) {
2068 g_warning ("unnegotiating unset link");
2070 g_object_notify (G_OBJECT (link->srcpad), "caps");
2072 if (GST_RPAD_LINK (link->sinkpad) != link) {
2073 g_warning ("unnegotiating unset link");
2075 g_object_notify (G_OBJECT (link->sinkpad), "caps");
2081 * gst_pad_unnegotiate:
2082 * @pad: pad to unnegotiate
2084 * "Unnegotiates" a pad. The currently negotiated caps are cleared and the pad
2085 * needs renegotiation.
2088 gst_pad_unnegotiate (GstPad * pad)
2092 g_return_if_fail (GST_IS_PAD (pad));
2094 link = GST_RPAD_LINK (GST_PAD_REALIZE (pad));
2096 gst_pad_link_unnegotiate (link);
2099 /* returning NULL indicates that the arguments are invalid */
2101 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad,
2102 const GstCaps * filtercaps)
2104 GstRealPad *realsrc, *realsink;
2107 g_return_val_if_fail (GST_IS_PAD (srcpad), NULL);
2108 g_return_val_if_fail (GST_IS_PAD (sinkpad), NULL);
2110 realsrc = GST_PAD_REALIZE (srcpad);
2111 realsink = GST_PAD_REALIZE (sinkpad);
2113 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
2114 GST_CAT_DEBUG (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
2115 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
2118 g_return_val_if_fail (GST_RPAD_PEER (realsrc) == NULL, NULL);
2119 g_return_val_if_fail (GST_RPAD_PEER (realsink) == NULL, NULL);
2120 g_return_val_if_fail (GST_PAD_PARENT (realsrc) != NULL, NULL);
2121 g_return_val_if_fail (GST_PAD_PARENT (realsink) != NULL, NULL);
2123 if (!gst_pad_check_schedulers (realsrc, realsink)) {
2124 g_warning ("linking pads with different scheds requires "
2125 "exactly one decoupled element (such as queue)");
2129 if (GST_RPAD_DIRECTION (realsrc) == GST_RPAD_DIRECTION (realsink)) {
2130 g_warning ("%s:%s and %s:%s are both %s pads, failed",
2131 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink),
2132 GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC ? "src" : "sink");
2136 link = gst_pad_link_new ();
2138 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
2139 link->srcpad = GST_PAD (realsrc);
2140 link->sinkpad = GST_PAD (realsink);
2142 link->srcpad = GST_PAD (realsink);
2143 link->sinkpad = GST_PAD (realsrc);
2146 link->srccaps = gst_pad_get_caps (link->srcpad);
2147 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
2149 link->filtercaps = gst_caps_copy (filtercaps);
2155 * gst_pad_try_relink_filtered:
2156 * @srcpad: the source #GstPad to relink.
2157 * @sinkpad: the sink #GstPad to relink.
2158 * @filtercaps: the #GstPad to use as a filter in the relink.
2160 * Tries to relink the given source and sink pad, constrained by the given
2163 * Returns: TRUE if the pads were succesfully renegotiated, FALSE otherwise.
2166 gst_pad_try_relink_filtered (GstPad * srcpad, GstPad * sinkpad,
2167 const GstCaps * filtercaps)
2171 GST_INFO ("trying to relink %" GST_PTR_FORMAT " and %" GST_PTR_FORMAT
2172 " with filtercaps %" GST_PTR_FORMAT, srcpad, sinkpad);
2174 link = gst_pad_link_prepare (srcpad, sinkpad, filtercaps);
2178 if (GST_RPAD_PEER (link->srcpad) != (GstRealPad *) link->sinkpad) {
2179 g_warning ("Pads %s:%s and %s:%s were never linked",
2180 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2181 gst_pad_link_free (link);
2185 if (GST_PAD_LINK_FAILED (gst_pad_link_try (link)))
2192 * gst_pad_relink_filtered:
2193 * @srcpad: the source #GstPad to relink.
2194 * @sinkpad: the sink #GstPad to relink.
2195 * @filtercaps: the #GstPad to use as a filter in the relink.
2197 * Relinks the given source and sink pad, constrained by the given
2198 * capabilities. If the relink fails, the pads are unlinked
2199 * and FALSE is returned.
2201 * Returns: TRUE if the pads were succesfully relinked, FALSE otherwise.
2204 gst_pad_relink_filtered (GstPad * srcpad, GstPad * sinkpad,
2205 const GstCaps * filtercaps)
2207 if (gst_pad_try_relink_filtered (srcpad, sinkpad, filtercaps))
2210 gst_pad_unlink (srcpad, sinkpad);
2215 * gst_pad_proxy_getcaps:
2216 * @pad: a #GstPad to proxy.
2218 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
2219 * same element as @pad, and returns the intersection of the results.
2221 * This function is useful as a default getcaps function for an element
2222 * that can handle any stream format, but requires all its pads to have
2223 * the same caps. Two such elements are tee and aggregator.
2225 * Returns: the intersection of the other pads' allowed caps.
2228 gst_pad_proxy_getcaps (GstPad * pad)
2230 GstElement *element;
2234 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2236 GST_DEBUG ("proxying getcaps for %s:%s", GST_DEBUG_PAD_NAME (pad));
2238 element = gst_pad_get_parent (pad);
2240 pads = gst_element_get_pad_list (element);
2242 caps = gst_caps_new_any ();
2244 GstPad *otherpad = GST_PAD (pads->data);
2247 if (otherpad != pad) {
2248 GstCaps *allowed = gst_pad_get_allowed_caps (otherpad);
2250 temp = gst_caps_intersect (caps, allowed);
2251 gst_caps_free (caps);
2252 gst_caps_free (allowed);
2256 pads = g_list_next (pads);
2263 * gst_pad_proxy_pad_link:
2264 * @pad: a #GstPad to proxy.
2265 * @caps: the #GstCaps to link with
2267 * Calls gst_pad_try_set_caps() for every other pad belonging to the
2268 * same element as @pad. If gst_pad_try_set_caps() fails on any pad,
2269 * the proxy link fails. May be used only during negotiation.
2271 * Returns: GST_PAD_LINK_OK if sucessful
2274 gst_pad_proxy_pad_link (GstPad * pad, const GstCaps * caps)
2276 GstElement *element;
2278 GstPadLinkReturn ret;
2280 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
2281 g_return_val_if_fail (caps != NULL, GST_PAD_LINK_REFUSED);
2283 GST_DEBUG ("proxying pad link for %s:%s", GST_DEBUG_PAD_NAME (pad));
2285 element = gst_pad_get_parent (pad);
2287 pads = gst_element_get_pad_list (element);
2290 GstPad *otherpad = GST_PAD (pads->data);
2292 if (otherpad != pad) {
2293 ret = gst_pad_try_set_caps (otherpad, caps);
2294 if (GST_PAD_LINK_FAILED (ret)) {
2298 pads = g_list_next (pads);
2301 return GST_PAD_LINK_OK;
2305 * gst_pad_proxy_fixate:
2306 * @pad: a #GstPad to proxy.
2307 * @caps: the #GstCaps to fixate
2309 * Implements a default fixate function based on the caps set on the other
2310 * pads in the element. This function should only be used if every pad
2311 * has the same pad template caps.
2313 * Returns: a fixated caps, or NULL if caps cannot be fixed
2316 gst_pad_proxy_fixate (GstPad * pad, const GstCaps * caps)
2318 GstElement *element;
2320 const GstCaps *othercaps;
2322 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2323 g_return_val_if_fail (caps != NULL, NULL);
2325 GST_DEBUG ("proxying fixate for %s:%s\n", GST_DEBUG_PAD_NAME (pad));
2327 element = gst_pad_get_parent (pad);
2329 pads = gst_element_get_pad_list (element);
2332 GstPad *otherpad = GST_PAD (pads->data);
2334 /* FIXME check that each pad has the same pad template caps */
2336 if (otherpad != pad) {
2337 othercaps = gst_pad_get_negotiated_caps (otherpad);
2342 icaps = gst_caps_intersect (othercaps, caps);
2343 if (!gst_caps_is_empty (icaps)) {
2346 gst_caps_free (icaps);
2350 pads = g_list_next (pads);
2357 * gst_pad_set_explicit_caps:
2358 * @pad: a #GstPad to set the explicit caps of
2359 * @caps: the #GstCaps to set
2361 * If a pad has been told to use explicit caps, this function is used
2362 * to set the explicit caps. If @caps is NULL, the explicit caps are
2365 * This function calls gst_pad_try_set_caps() on the pad. If that
2366 * call fails, GST_ELEMENT_ERROR() is called to indicate a negotiation
2369 * Returns: TRUE if the caps were set correctly, otherwise FALSE
2372 gst_pad_set_explicit_caps (GstPad * pad, const GstCaps * caps)
2374 GstPadLinkReturn link_ret;
2376 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2378 GST_CAT_DEBUG (GST_CAT_PADS, "setting explicit caps to %" GST_PTR_FORMAT,
2382 GST_CAT_DEBUG (GST_CAT_PADS, "caps is NULL");
2383 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2387 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), gst_caps_copy (caps));
2389 if (!GST_PAD_IS_LINKED (pad)) {
2390 GST_CAT_DEBUG (GST_CAT_PADS, "pad is not linked");
2393 link_ret = gst_pad_try_set_caps (pad, caps);
2394 if (link_ret == GST_PAD_LINK_REFUSED) {
2395 gchar *caps_str = gst_caps_to_string (caps);
2397 GST_ELEMENT_ERROR (gst_pad_get_parent (pad), CORE, PAD, (NULL),
2398 ("failed to negotiate (try_set_caps with \"%s\" returned REFUSED)",
2408 gst_pad_explicit_getcaps (GstPad * pad)
2410 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2412 if (GST_RPAD_EXPLICIT_CAPS (pad) == NULL) {
2413 const GstCaps *caps = gst_pad_get_pad_template_caps (pad);
2415 return gst_caps_copy (caps);
2417 return gst_caps_copy (GST_RPAD_EXPLICIT_CAPS (pad));
2420 static GstPadLinkReturn
2421 gst_pad_explicit_link (GstPad * pad, const GstCaps * caps)
2423 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
2424 g_return_val_if_fail (caps != NULL, GST_PAD_LINK_REFUSED);
2426 if (GST_RPAD_EXPLICIT_CAPS (pad) == NULL) {
2427 return GST_PAD_LINK_DELAYED;
2430 return GST_PAD_LINK_OK;
2434 * gst_pad_use_explicit_caps:
2435 * @pad: a #GstPad to set to use explicit caps
2437 * This function handles negotiation for pads that need to be set
2438 * to particular caps under complete control of the element, based
2439 * on some state in the element. This is often the case with
2440 * decoders and other elements whose caps is determined by the data
2443 * WARNING: This function is a hack and will be replaced with something
2444 * better in gstreamer-0.9.
2447 gst_pad_use_explicit_caps (GstPad * pad)
2449 g_return_if_fail (GST_IS_PAD (pad));
2451 gst_pad_set_getcaps_function (pad, gst_pad_explicit_getcaps);
2452 gst_pad_set_link_function (pad, gst_pad_explicit_link);
2453 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2457 * gst_pad_proxy_link:
2458 * @pad: a #GstPad to proxy to.
2459 * @caps: the #GstCaps to use in proxying.
2461 * Proxies the link function to the specified pad.
2463 * Returns: TRUE if the peer pad accepted the caps, FALSE otherwise.
2466 gst_pad_proxy_link (GstPad * pad, const GstCaps * caps)
2468 return gst_pad_try_set_caps (pad, caps);
2472 * gst_pad_is_negotiated:
2473 * @pad: a #GstPad to get the negotiation status of
2475 * Returns: TRUE if the pad has successfully negotiated caps.
2478 gst_pad_is_negotiated (GstPad * pad)
2480 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2482 if (!GST_PAD_REALIZE (pad))
2484 if (!GST_RPAD_LINK (pad))
2487 return (GST_RPAD_LINK (pad)->caps != NULL);
2491 * gst_pad_get_negotiated_caps:
2492 * @pad: a #GstPad to get the negotiated capabilites of
2494 * Gets the currently negotiated caps of a pad.
2496 * Returns: the currently negotiated caps of a pad, or NULL if the pad isn't
2499 G_CONST_RETURN GstCaps *
2500 gst_pad_get_negotiated_caps (GstPad * pad)
2502 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2504 if (!GST_PAD_REALIZE (pad))
2506 if (!GST_RPAD_LINK (pad))
2509 return GST_RPAD_LINK (pad)->caps;
2514 * @pad: a #GstPad to get the capabilities of.
2516 * Gets the capabilities of this pad.
2518 * Returns: the #GstCaps of this pad. This function returns a new caps, so use
2519 * gst_caps_free to get rid of it.
2522 gst_pad_get_caps (GstPad * pad)
2524 GstRealPad *realpad;
2526 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2528 realpad = GST_PAD_REALIZE (pad);
2530 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
2531 GST_DEBUG_PAD_NAME (realpad), realpad);
2533 if (GST_RPAD_GETCAPSFUNC (realpad)) {
2536 GST_CAT_DEBUG (GST_CAT_CAPS, "using pad getcaps function");
2537 caps = GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD (realpad));
2540 g_critical ("pad %s:%s returned NULL caps from getcaps function\n",
2541 GST_ELEMENT_NAME (GST_PAD_PARENT (GST_PAD (realpad))),
2542 GST_PAD_NAME (realpad));
2543 caps = gst_caps_new_any ();
2547 } else if (GST_PAD_PAD_TEMPLATE (realpad)) {
2548 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (realpad);
2549 const GstCaps *caps;
2551 caps = GST_PAD_TEMPLATE_CAPS (templ);
2552 GST_CAT_DEBUG (GST_CAT_CAPS,
2553 "using pad template %p with caps %" GST_PTR_FORMAT, templ, caps);
2556 /* FIXME we should enable something like this someday, but this is
2558 if (!gst_caps_is_fixed (caps)) {
2560 ("pad %s:%s (%p) has no getcaps function and the pad template returns non-fixed caps. Element is probably broken.\n",
2561 GST_DEBUG_PAD_NAME (realpad), realpad);
2565 return gst_caps_copy (GST_PAD_TEMPLATE_CAPS (templ));
2567 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
2571 g_warning ("pad %s:%s (%p) has no pad template\n",
2572 GST_DEBUG_PAD_NAME (realpad), realpad);
2575 return gst_caps_new_any ();
2579 * gst_pad_get_pad_template_caps:
2580 * @pad: a #GstPad to get the template capabilities from.
2582 * Gets the capabilities for @pad's template.
2584 * Returns: the #GstCaps of this pad template. If you intend to keep a reference
2585 * on the caps, make a copy (see gst_caps_copy ()).
2588 gst_pad_get_pad_template_caps (GstPad * pad)
2590 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2592 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2594 if (GST_PAD_PAD_TEMPLATE (pad))
2595 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2598 /* FIXME this should be enabled some day */
2599 /* wingo: why? mail the list during 0.9 when you find this :) */
2600 g_warning ("pad %s:%s (%p) has no pad template\n",
2601 GST_DEBUG_PAD_NAME (realpad), realpad);
2604 return gst_static_caps_get (&anycaps);
2607 /* FIXME 0.9: This function should probably die, or at least be renamed to
2608 * get_caps_by_format. */
2610 * gst_pad_template_get_caps_by_name:
2611 * @templ: a #GstPadTemplate to get the capabilities of.
2612 * @name: the name of the capability to get.
2614 * Gets the capability with the given name from @templ.
2616 * Returns: the #GstCaps of this pad template, or NULL if not found. If you
2617 * intend to keep a reference on the caps, make a copy (see gst_caps_copy ()).
2620 gst_pad_template_get_caps_by_name (GstPadTemplate * templ, const gchar * name)
2624 g_return_val_if_fail (templ != NULL, NULL);
2626 caps = GST_PAD_TEMPLATE_CAPS (templ);
2631 //return gst_caps_copy (gst_caps_get_by_name (caps, name));
2635 /* FIXME 0.9: What good is this if it only works for already-negotiated pads? */
2637 * gst_pad_check_compatibility:
2638 * @srcpad: the source #GstPad to check.
2639 * @sinkpad: the sink #GstPad to check against.
2641 * Checks if two pads have compatible capabilities. If neither one has yet been
2642 * negotiated, returns TRUE for no good reason.
2644 * Returns: TRUE if they are compatible or if the capabilities could not be
2645 * checked, FALSE if the capabilities are not compatible.
2648 gst_pad_check_compatibility (GstPad * srcpad, GstPad * sinkpad)
2650 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2651 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2653 if (GST_PAD_CAPS (srcpad) && GST_PAD_CAPS (sinkpad)) {
2654 if (!gst_caps_is_always_compatible (GST_PAD_CAPS (srcpad),
2655 GST_PAD_CAPS (sinkpad))) {
2661 GST_CAT_DEBUG (GST_CAT_PADS,
2662 "could not check capabilities of pads (%s:%s) and (%s:%s) %p %p",
2663 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2664 GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad));
2671 * @pad: a #GstPad to get the peer of.
2673 * Gets the peer of @pad.
2675 * Returns: the peer #GstPad.
2678 gst_pad_get_peer (GstPad * pad)
2680 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2682 return GST_PAD (GST_PAD_PEER (pad));
2686 * gst_pad_get_allowed_caps:
2687 * @pad: a real #GstPad.
2689 * Gets the capabilities of the allowed media types that can flow through @pad.
2690 * The caller must free the resulting caps.
2692 * Returns: the allowed #GstCaps of the pad link. Free the caps when
2693 * you no longer need it.
2696 gst_pad_get_allowed_caps (GstPad * pad)
2698 const GstCaps *mycaps;
2704 g_return_val_if_fail (GST_IS_REAL_PAD (pad), NULL);
2706 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "get allowed caps of %s:%s",
2707 GST_DEBUG_PAD_NAME (pad));
2709 mycaps = gst_pad_get_pad_template_caps (pad);
2710 if (GST_RPAD_PEER (pad) == NULL) {
2711 return gst_caps_copy (mycaps);
2714 peercaps = gst_pad_get_caps (GST_PAD_PEER (pad));
2715 caps = gst_caps_intersect (mycaps, peercaps);
2716 gst_caps_free (peercaps);
2718 link = GST_RPAD_LINK (pad);
2719 if (link->filtercaps) {
2720 icaps = gst_caps_intersect (caps, link->filtercaps);
2721 gst_caps_free (caps);
2729 * gst_pad_caps_change_notify:
2732 * Called to indicate that the return value of @pad's getcaps function may have
2733 * changed, and that a renegotiation is suggested.
2736 gst_pad_caps_change_notify (GstPad * pad)
2741 * gst_pad_recover_caps_error:
2742 * @pad: a #GstPad that had a failed capsnego
2743 * @allowed: possible caps for the link
2745 * Attempt to recover from a failed caps negotiation. This function
2746 * is typically called by a plugin that exhausted its list of caps
2747 * and wants the application to resolve the issue. The application
2748 * should connect to the pad's caps_nego_failed signal and should
2749 * resolve the issue by connecting another element for example.
2751 * Returns: TRUE when the issue was resolved, dumps detailed information
2752 * on the console and returns FALSE otherwise.
2755 gst_pad_recover_caps_error (GstPad * pad, const GstCaps * allowed)
2762 * gst_pad_alloc_buffer:
2763 * @pad: a source #GstPad.
2764 * @offset: the offset of the new buffer in the stream
2765 * @size: the size of the new buffer
2767 * Allocates a new, empty buffer optimized to push to pad @pad. This
2768 * function only works if @pad is a source pad.
2770 * Returns: a new, empty #GstBuffer, or NULL if there is an error
2773 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size)
2777 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2778 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
2780 peer = GST_RPAD_PEER (pad);
2783 return gst_buffer_new_and_alloc (size);
2785 GST_CAT_DEBUG (GST_CAT_BUFFER, "(%s:%s): getting buffer",
2786 GST_DEBUG_PAD_NAME (pad));
2788 if (peer->bufferallocfunc) {
2789 GST_CAT_DEBUG (GST_CAT_PADS,
2790 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s",
2791 GST_DEBUG_FUNCPTR_NAME (peer->bufferallocfunc),
2792 &peer->bufferallocfunc, GST_DEBUG_PAD_NAME (((GstPad *) peer)));
2793 return (peer->bufferallocfunc) (GST_PAD (peer), offset, size);
2795 return gst_buffer_new_and_alloc (size);
2800 gst_real_pad_dispose (GObject * object)
2802 GstPad *pad = GST_PAD (object);
2804 /* No linked pad can ever be disposed.
2805 * It has to have a parent to be linked
2806 * and a parent would hold a reference */
2807 /* FIXME: what about if g_object_dispose is explicitly called on the pad? Is
2808 that legal? otherwise we could assert GST_OBJECT_PARENT (pad) == NULL as
2810 g_assert (GST_PAD_PEER (pad) == NULL);
2812 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s",
2813 GST_DEBUG_PAD_NAME (pad));
2815 /* we destroy the ghostpads, because they are nothing without the real pad */
2816 if (GST_REAL_PAD (pad)->ghostpads) {
2817 GList *orig, *ghostpads;
2819 orig = ghostpads = g_list_copy (GST_REAL_PAD (pad)->ghostpads);
2822 GstPad *ghostpad = GST_PAD (ghostpads->data);
2824 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))) {
2825 GstElement *parent = GST_ELEMENT (GST_OBJECT_PARENT (ghostpad));
2827 GST_CAT_DEBUG (GST_CAT_REFCOUNTING,
2828 "removing ghost pad from element '%s'", GST_OBJECT_NAME (parent));
2829 gst_element_remove_pad (parent, ghostpad);
2831 /* handle the case where we have some floating ghost pad that was never
2832 added to an element */
2833 g_object_set (ghostpad, "real-pad", NULL, NULL);
2835 ghostpads = g_list_next (ghostpads);
2838 /* as the ghost pads are removed, they remove themselves from ->ghostpads.
2839 So it should be empty now. Let's assert that. */
2840 g_assert (GST_REAL_PAD (pad)->ghostpads == NULL);
2843 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
2844 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
2845 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
2847 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
2850 if (GST_RPAD_EXPLICIT_CAPS (pad)) {
2851 GST_ERROR_OBJECT (pad, "still explicit caps %" GST_PTR_FORMAT " set",
2852 GST_RPAD_EXPLICIT_CAPS (pad));
2853 g_warning ("pad %p has still explicit caps set", pad);
2854 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2856 G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
2860 #ifndef GST_DISABLE_LOADSAVE
2861 /* FIXME: why isn't this on a GstElement ? */
2863 * gst_pad_load_and_link:
2864 * @self: an #xmlNodePtr to read the description from.
2865 * @parent: the #GstObject element that owns the pad.
2867 * Reads the pad definition from the XML node and links the given pad
2868 * in the element to a pad of an element up in the hierarchy.
2871 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
2873 xmlNodePtr field = self->xmlChildrenNode;
2874 GstPad *pad = NULL, *targetpad;
2878 GstObject *grandparent;
2881 if (!strcmp (field->name, "name")) {
2882 pad = gst_element_get_pad (GST_ELEMENT (parent),
2883 xmlNodeGetContent (field));
2884 } else if (!strcmp (field->name, "peer")) {
2885 peer = xmlNodeGetContent (field);
2887 field = field->next;
2889 g_return_if_fail (pad != NULL);
2894 split = g_strsplit (peer, ".", 2);
2896 if (split[0] == NULL || split[1] == NULL) {
2897 GST_CAT_DEBUG (GST_CAT_XML,
2898 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
2899 peer, GST_DEBUG_PAD_NAME (pad));
2903 g_return_if_fail (split[0] != NULL);
2904 g_return_if_fail (split[1] != NULL);
2906 grandparent = gst_object_get_parent (parent);
2908 if (grandparent && GST_IS_BIN (grandparent)) {
2909 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2916 targetpad = gst_element_get_pad (target, split[1]);
2918 if (targetpad == NULL)
2921 gst_pad_link (pad, targetpad);
2928 * gst_pad_save_thyself:
2929 * @pad: a #GstPad to save.
2930 * @parent: the parent #xmlNodePtr to save the description in.
2932 * Saves the pad into an xml representation.
2934 * Returns: the #xmlNodePtr representation of the pad.
2937 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
2939 GstRealPad *realpad;
2942 g_return_val_if_fail (GST_IS_REAL_PAD (object), NULL);
2944 realpad = GST_REAL_PAD (object);
2946 xmlNewChild (parent, NULL, "name", GST_PAD_NAME (realpad));
2947 if (GST_RPAD_PEER (realpad) != NULL) {
2950 peer = GST_PAD (GST_RPAD_PEER (realpad));
2951 /* first check to see if the peer's parent's parent is the same */
2952 /* we just save it off */
2953 content = g_strdup_printf ("%s.%s",
2954 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
2955 xmlNewChild (parent, NULL, "peer", content);
2958 xmlNewChild (parent, NULL, "peer", "");
2963 /* FIXME: shouldn't it be gst_pad_ghost_* ?
2964 * dunno -- wingo 7 feb 2004
2967 * gst_ghost_pad_save_thyself:
2968 * @pad: a ghost #GstPad to save.
2969 * @parent: the parent #xmlNodePtr to save the description in.
2971 * Saves the ghost pad into an xml representation.
2973 * Returns: the #xmlNodePtr representation of the pad.
2976 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
2980 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2982 self = xmlNewChild (parent, NULL, "ghostpad", NULL);
2983 xmlNewChild (self, NULL, "name", GST_PAD_NAME (pad));
2984 xmlNewChild (self, NULL, "parent", GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
2986 /* FIXME FIXME FIXME! */
2990 #endif /* GST_DISABLE_LOADSAVE */
2994 * @pad: a source #GstPad.
2995 * @data: the #GstData to push.
2997 * Pushes a buffer or an event to the peer of @pad. @pad must be linked. May
2998 * only be called by @pad's parent.
3001 gst_pad_push (GstPad * pad, GstData * data)
3005 g_return_if_fail (GST_IS_PAD (pad));
3006 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
3007 g_return_if_fail (data != NULL);
3009 if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), &data))
3012 if (!GST_PAD_IS_LINKED (pad)) {
3013 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad,
3014 "not pushing data %p as pad is unconnected", data);
3015 gst_data_unref (data);
3019 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad, "pushing");
3020 peer = GST_RPAD_PEER (pad);
3023 g_warning ("push on pad %s:%s but it is unlinked",
3024 GST_DEBUG_PAD_NAME (pad));
3026 if (!GST_IS_EVENT (data) && !GST_PAD_IS_ACTIVE (peer)) {
3027 g_warning ("push on peer of pad %s:%s but peer is not active",
3028 GST_DEBUG_PAD_NAME (pad));
3032 if (peer->chainhandler) {
3034 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad,
3035 "calling chainhandler &%s of peer pad %s:%s",
3036 GST_DEBUG_FUNCPTR_NAME (peer->chainhandler),
3037 GST_DEBUG_PAD_NAME (GST_PAD (peer)));
3038 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
3041 (peer->chainhandler) (GST_PAD (peer), data);
3044 g_warning ("trying to push a NULL buffer on pad %s:%s",
3045 GST_DEBUG_PAD_NAME (peer));
3049 g_warning ("internal error: push on pad %s:%s but it has no chainhandler",
3050 GST_DEBUG_PAD_NAME (peer));
3053 /* clean up the mess here */
3055 gst_data_unref (data);
3060 * @pad: a sink #GstPad.
3062 * Pulls an event or a buffer from the peer pad. May only be called by @pad's
3065 * Returns: a new #GstData from the peer pad.
3068 gst_pad_pull (GstPad * pad)
3072 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad, "pulling");
3074 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
3075 GST_DATA (gst_event_new (GST_EVENT_INTERRUPT)));
3077 peer = GST_RPAD_PEER (pad);
3080 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3081 ("pull on pad %s:%s but it was unlinked", GST_DEBUG_PAD_NAME (pad)));
3084 if (peer->gethandler) {
3087 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad,
3088 "calling gethandler %s of peer pad %s:%s",
3089 GST_DEBUG_FUNCPTR_NAME (peer->gethandler), GST_DEBUG_PAD_NAME (peer));
3091 data = (peer->gethandler) (GST_PAD (peer));
3094 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
3099 /* no null buffers allowed */
3100 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3101 ("NULL buffer during pull on %s:%s", GST_DEBUG_PAD_NAME (pad)));
3103 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3104 ("pull on pad %s:%s but the peer pad %s:%s has no gethandler",
3105 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer)));
3108 return GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
3113 * @padlist: a #GList of sink pads.
3115 * Waits for a buffer on any of the list of pads. Each #GstPad in @padlist must
3116 * be owned by the calling code.
3118 * Returns: the #GstPad that has a buffer available.
3119 * Use #gst_pad_pull() to get the buffer.
3122 gst_pad_selectv (GList * padlist)
3126 pad = gst_scheduler_pad_select (GST_PAD_PARENT (padlist->data)->sched,
3131 /* FIXME 0.9: Don't allow the first pad to be NULL */
3134 * @pad: a first sink #GstPad to perform the select on.
3135 * @...: A NULL-terminated list of more pads to select on.
3137 * Waits for a buffer on the given set of pads.
3139 * Returns: the #GstPad that has a buffer available.
3140 * Use #gst_pad_pull() to get the buffer.
3143 gst_pad_select (GstPad * pad, ...)
3151 va_start (var_args, pad);
3153 result = gst_pad_select_valist (pad, var_args);
3161 * gst_pad_select_valist:
3162 * @pad: a first #GstPad to perform the select on.
3163 * @varargs: A va_list of more pads to select on.
3165 * Waits for a buffer on the given set of pads.
3167 * Returns: the #GstPad that has a buffer available.
3168 * Use #gst_pad_pull() to get the buffer.
3171 gst_pad_select_valist (GstPad * pad, va_list var_args)
3174 GList *padlist = NULL;
3180 padlist = g_list_prepend (padlist, pad);
3181 pad = va_arg (var_args, GstPad *);
3183 result = gst_pad_selectv (padlist);
3184 g_list_free (padlist);
3189 /************************************************************************
3194 static void gst_pad_template_class_init (GstPadTemplateClass * klass);
3195 static void gst_pad_template_init (GstPadTemplate * templ);
3196 static void gst_pad_template_dispose (GObject * object);
3199 gst_pad_template_get_type (void)
3201 static GType padtemplate_type = 0;
3203 if (!padtemplate_type) {
3204 static const GTypeInfo padtemplate_info = {
3205 sizeof (GstPadTemplateClass), NULL, NULL,
3206 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
3207 sizeof (GstPadTemplate),
3209 (GInstanceInitFunc) gst_pad_template_init, NULL
3213 g_type_register_static (GST_TYPE_OBJECT, "GstPadTemplate",
3214 &padtemplate_info, 0);
3216 return padtemplate_type;
3220 gst_pad_template_class_init (GstPadTemplateClass * klass)
3222 GObjectClass *gobject_class;
3223 GstObjectClass *gstobject_class;
3225 gobject_class = (GObjectClass *) klass;
3226 gstobject_class = (GstObjectClass *) klass;
3228 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
3230 gst_pad_template_signals[TEMPL_PAD_CREATED] =
3231 g_signal_new ("pad-created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
3232 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
3233 NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
3235 gobject_class->dispose = gst_pad_template_dispose;
3237 gstobject_class->path_string_separator = "*";
3241 gst_pad_template_init (GstPadTemplate * templ)
3246 gst_pad_template_dispose (GObject * object)
3248 GstPadTemplate *templ = GST_PAD_TEMPLATE (object);
3250 g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
3251 if (GST_PAD_TEMPLATE_CAPS (templ)) {
3252 gst_caps_free (GST_PAD_TEMPLATE_CAPS (templ));
3255 G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object);
3258 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
3260 * SOMETIMES padtemplates can do whatever they want, they are provided by the
3262 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
3263 * 'sink%d' template is automatically selected), so we need to restrict their
3267 name_is_valid (const gchar * name, GstPadPresence presence)
3271 if (presence == GST_PAD_ALWAYS) {
3272 if (strchr (name, '%')) {
3273 g_warning ("invalid name template %s: conversion specifications are not"
3274 " allowed for GST_PAD_ALWAYS padtemplates", name);
3277 } else if (presence == GST_PAD_REQUEST) {
3278 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
3279 g_warning ("invalid name template %s: only one conversion specification"
3280 " allowed in GST_PAD_REQUEST padtemplate", name);
3283 if (str && (*(str + 1) != 's' && *(str + 1) != 'd')) {
3284 g_warning ("invalid name template %s: conversion specification must be of"
3285 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
3288 if (str && (*(str + 2) != '\0')) {
3289 g_warning ("invalid name template %s: conversion specification must"
3290 " appear at the end of the GST_PAD_REQUEST padtemplate name", name);
3299 * gst_static_pad_template_get:
3300 * @pad_template: the static pad template
3302 * Converts a #GstStaticPadTemplate into a #GstPadTemplate.
3304 * Returns: a new #GstPadTemplate.
3307 gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
3309 GstPadTemplate *new;
3311 if (!name_is_valid (pad_template->name_template, pad_template->presence))
3314 new = g_object_new (gst_pad_template_get_type (),
3315 "name", pad_template->name_template, NULL);
3317 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (pad_template->name_template);
3318 GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction;
3319 GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence;
3321 GST_PAD_TEMPLATE_CAPS (new) =
3322 gst_caps_copy (gst_static_caps_get (&pad_template->static_caps));
3328 * gst_pad_template_new:
3329 * @name_template: the name template.
3330 * @direction: the #GstPadDirection of the template.
3331 * @presence: the #GstPadPresence of the pad.
3332 * @caps: a #GstCaps set for the template. The caps are taken ownership of.
3334 * Creates a new pad template with a name according to the given template
3335 * and with the given arguments. This functions takes ownership of the provided
3336 * caps, so be sure to not use them afterwards.
3338 * Returns: a new #GstPadTemplate.
3341 gst_pad_template_new (const gchar * name_template,
3342 GstPadDirection direction, GstPadPresence presence, GstCaps * caps)
3344 GstPadTemplate *new;
3346 g_return_val_if_fail (name_template != NULL, NULL);
3348 if (!name_is_valid (name_template, presence))
3352 #ifdef USE_POISONING
3354 GstCaps *newcaps = gst_caps_copy (caps);
3356 gst_caps_free (caps);
3361 new = g_object_new (gst_pad_template_get_type (),
3362 "name", name_template, NULL);
3364 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
3365 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
3366 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
3367 GST_PAD_TEMPLATE_CAPS (new) = caps;
3373 * gst_pad_template_get_caps:
3374 * @templ: a #GstPadTemplate to get capabilities of.
3376 * Gets the capabilities of the pad template.
3378 * Returns: the #GstCaps of the pad template. If you need to keep a reference to
3379 * the caps, make a copy (see gst_caps_copy ()).
3382 gst_pad_template_get_caps (GstPadTemplate * templ)
3384 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
3386 return GST_PAD_TEMPLATE_CAPS (templ);
3390 * gst_pad_set_element_private:
3391 * @pad: the #GstPad to set the private data of.
3392 * @priv: The private data to attach to the pad.
3394 * Set the given private data gpointer on the pad.
3395 * This function can only be used by the element that owns the pad.
3398 gst_pad_set_element_private (GstPad * pad, gpointer priv)
3400 pad->element_private = priv;
3404 * gst_pad_get_element_private:
3405 * @pad: the #GstPad to get the private data of.
3407 * Gets the private data of a pad.
3409 * Returns: a #gpointer to the private data.
3412 gst_pad_get_element_private (GstPad * pad)
3414 return pad->element_private;
3418 /***** ghost pads *****/
3419 GType _gst_ghost_pad_type = 0;
3421 static void gst_ghost_pad_class_init (GstGhostPadClass * klass);
3422 static void gst_ghost_pad_init (GstGhostPad * pad);
3423 static void gst_ghost_pad_dispose (GObject * object);
3424 static void gst_ghost_pad_get_property (GObject * object, guint prop_id,
3425 GValue * value, GParamSpec * pspec);
3426 static void gst_ghost_pad_set_property (GObject * object, guint prop_id,
3427 const GValue * value, GParamSpec * pspec);
3429 static GstPad *ghost_pad_parent_class = NULL;
3431 /* static guint gst_ghost_pad_signals[LAST_SIGNAL] = { 0 }; */
3440 gst_ghost_pad_get_type (void)
3442 if (!_gst_ghost_pad_type) {
3443 static const GTypeInfo pad_info = {
3444 sizeof (GstGhostPadClass), NULL, NULL,
3445 (GClassInitFunc) gst_ghost_pad_class_init, NULL, NULL,
3446 sizeof (GstGhostPad),
3448 (GInstanceInitFunc) gst_ghost_pad_init,
3452 _gst_ghost_pad_type = g_type_register_static (GST_TYPE_PAD, "GstGhostPad",
3455 return _gst_ghost_pad_type;
3459 gst_ghost_pad_class_init (GstGhostPadClass * klass)
3461 GObjectClass *gobject_class;
3463 gobject_class = (GObjectClass *) klass;
3465 ghost_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
3467 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_ghost_pad_dispose);
3468 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_ghost_pad_set_property);
3469 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_ghost_pad_get_property);
3471 g_object_class_install_property (gobject_class, GPAD_ARG_REAL_PAD,
3472 g_param_spec_object ("real-pad", "Real pad",
3473 "The real pad for the ghost pad", GST_TYPE_PAD, G_PARAM_READWRITE));
3477 gst_ghost_pad_init (GstGhostPad * pad)
3479 /* zeroed by glib */
3483 gst_ghost_pad_dispose (GObject * object)
3485 g_object_set (object, "real-pad", NULL, NULL);
3487 G_OBJECT_CLASS (ghost_pad_parent_class)->dispose (object);
3491 gst_ghost_pad_set_property (GObject * object, guint prop_id,
3492 const GValue * value, GParamSpec * pspec)
3494 GstPad *ghostpad = (GstPad *) object;
3495 GstPad *oldrealpad = (GstPad *) GST_GPAD_REALPAD (ghostpad);
3496 GstPad *realpad = NULL;
3499 case GPAD_ARG_REAL_PAD:
3500 realpad = g_value_get_object (value);
3503 if (realpad == oldrealpad)
3506 gst_pad_remove_ghost_pad (oldrealpad, ghostpad);
3510 gst_pad_add_ghost_pad (realpad, ghostpad);
3514 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3520 gst_ghost_pad_get_property (GObject * object, guint prop_id,
3521 GValue * value, GParamSpec * pspec)
3524 case GPAD_ARG_REAL_PAD:
3525 g_value_set_object (value, GST_GPAD_REALPAD (object));
3529 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3535 * gst_ghost_pad_new:
3536 * @name: the name of the new ghost pad.
3537 * @pad: the #GstPad to create a ghost pad for.
3539 * Creates a new ghost pad associated with @pad, and named @name. If @name is
3540 * %NULL, a guaranteed unique name (across all ghost pads) will be assigned.
3542 * Returns: a new ghost #GstPad, or %NULL in case of an error.
3545 gst_ghost_pad_new (const gchar * name, GstPad * pad)
3549 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3551 gpad = g_object_new (GST_TYPE_GHOST_PAD, "name", name, "real-pad", pad, NULL);
3553 GST_CAT_DEBUG (GST_CAT_PADS, "created ghost pad \"%s\" for pad %s:%s",
3554 GST_OBJECT_NAME (gpad), GST_DEBUG_PAD_NAME (pad));
3560 * gst_pad_get_internal_links_default:
3561 * @pad: the #GstPad to get the internal links of.
3563 * Gets a list of pads to which the given pad is linked to
3564 * inside of the parent element.
3565 * This is the default handler, and thus returns a list of all of the
3566 * pads inside the parent element with opposite direction.
3567 * The caller must free this list after use.
3569 * Returns: a newly allocated #GList of pads.
3572 gst_pad_get_internal_links_default (GstPad * pad)
3577 GstPadDirection direction;
3580 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3582 rpad = GST_PAD_REALIZE (pad);
3583 direction = rpad->direction;
3585 parent = GST_PAD_PARENT (rpad);
3586 parent_pads = parent->pads;
3588 while (parent_pads) {
3589 GstRealPad *parent_pad = GST_PAD_REALIZE (parent_pads->data);
3591 if (parent_pad->direction != direction) {
3592 res = g_list_prepend (res, parent_pad);
3595 parent_pads = g_list_next (parent_pads);
3602 * gst_pad_get_internal_links:
3603 * @pad: the #GstPad to get the internal links of.
3605 * Gets a list of pads to which the given pad is linked to
3606 * inside of the parent element.
3607 * The caller must free this list after use.
3609 * Returns: a newly allocated #GList of pads.
3612 gst_pad_get_internal_links (GstPad * pad)
3617 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3619 rpad = GST_PAD_REALIZE (pad);
3621 if (GST_RPAD_INTLINKFUNC (rpad))
3622 res = GST_RPAD_INTLINKFUNC (rpad) (GST_PAD (rpad));
3629 gst_pad_event_default_dispatch (GstPad * pad, GstElement * element,
3634 GST_INFO_OBJECT (pad, "Sending event %p to all internally linked pads",
3637 orig = pads = gst_pad_get_internal_links (pad);
3640 GstPad *eventpad = GST_PAD (pads->data);
3642 pads = g_list_next (pads);
3644 /* for all of the internally-linked pads that are actually linked */
3645 if (GST_PAD_IS_LINKED (eventpad)) {
3646 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
3647 /* increase the refcount */
3648 gst_event_ref (event);
3649 gst_pad_push (eventpad, GST_DATA (event));
3651 GstPad *peerpad = GST_PAD (GST_RPAD_PEER (eventpad));
3653 /* we only send the event on one pad, multi-sinkpad elements
3654 * should implement a handler */
3656 return gst_pad_send_event (peerpad, event);
3660 gst_event_unref (event);
3662 return (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
3666 * gst_pad_event_default:
3667 * @pad: a #GstPad to call the default event handler on.
3668 * @event: the #GstEvent to handle.
3670 * Invokes the default event handler for the given pad. End-of-stream and
3671 * discontinuity events are handled specially, and then the event is sent to all
3672 * pads internally linked to @pad. Note that if there are many possible sink
3673 * pads that are internally linked to @pad, only one will be sent an event.
3674 * Multi-sinkpad elements should implement custom event handlers.
3676 * Returns: TRUE if the event was sent succesfully.
3679 gst_pad_event_default (GstPad * pad, GstEvent * event)
3681 GstElement *element;
3683 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3684 g_return_val_if_fail (event != NULL, FALSE);
3686 element = GST_PAD_PARENT (pad);
3688 switch (GST_EVENT_TYPE (event)) {
3690 gst_pad_event_default_dispatch (pad, element, event);
3691 gst_element_set_eos (element);
3693 case GST_EVENT_DISCONTINUOUS:
3697 if (gst_element_requires_clock (element) && element->clock) {
3698 if (gst_event_discont_get_value (event, GST_FORMAT_TIME, &time)) {
3699 gst_element_set_time (element, time);
3701 GstFormat format = GST_FORMAT_TIME;
3704 for (i = 0; i < event->event_data.discont.noffsets; i++) {
3705 if (gst_pad_convert (pad,
3706 event->event_data.discont.offsets[i].format,
3707 event->event_data.discont.offsets[i].value, &format,
3709 gst_element_set_time (element, time);
3710 } else if (i == event->event_data.discont.noffsets) {
3712 ("can't adjust clock to new time when time not provided");
3719 return gst_pad_event_default_dispatch (pad, element, event);
3725 * gst_pad_dispatcher:
3726 * @pad: a #GstPad to dispatch.
3727 * @dispatch: the #GstDispatcherFunction to call.
3728 * @data: gpointer user data passed to the dispatcher function.
3730 * Invokes the given dispatcher function on all pads that are
3731 * internally linked to the given pad.
3732 * The GstPadDispatcherFunction should return TRUE when no further pads
3733 * need to be processed.
3735 * Returns: TRUE if one of the dispatcher functions returned TRUE.
3738 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
3741 gboolean res = FALSE;
3742 GList *int_pads, *orig;
3744 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3745 g_return_val_if_fail (dispatch != NULL, FALSE);
3747 orig = int_pads = gst_pad_get_internal_links (pad);
3750 GstRealPad *int_rpad = GST_PAD_REALIZE (int_pads->data);
3751 GstRealPad *int_peer = GST_RPAD_PEER (int_rpad);
3754 res = dispatch (GST_PAD (int_peer), data);
3758 int_pads = g_list_next (int_pads);
3767 * gst_pad_send_event:
3768 * @pad: a #GstPad to send the event to.
3769 * @event: the #GstEvent to send to the pad.
3771 * Sends the event to the pad.
3773 * Returns: TRUE if the event was handled.
3776 gst_pad_send_event (GstPad * pad, GstEvent * event)
3778 gboolean success = FALSE;
3781 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3782 g_return_val_if_fail (event != NULL, FALSE);
3784 rpad = GST_PAD_REALIZE (pad);
3786 if (GST_EVENT_SRC (event) == NULL)
3787 GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (rpad));
3789 GST_CAT_DEBUG (GST_CAT_EVENT, "have event %d on pad %s:%s",
3790 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (rpad));
3792 if (GST_RPAD_EVENTHANDLER (rpad))
3793 success = GST_RPAD_EVENTHANDLER (rpad) (GST_PAD (rpad), event);
3795 g_warning ("pad %s:%s has no event handler", GST_DEBUG_PAD_NAME (rpad));
3796 gst_event_unref (event);
3804 GstFormat src_format;
3806 GstFormat *dest_format;
3812 gst_pad_convert_dispatcher (GstPad * pad, GstPadConvertData * data)
3814 return gst_pad_convert (pad, data->src_format, data->src_value,
3815 data->dest_format, data->dest_value);
3819 * gst_pad_convert_default:
3820 * @pad: a #GstPad to invoke the default converter on.
3821 * @src_format: the source #GstFormat.
3822 * @src_value: the source value.
3823 * @dest_format: a pointer to the destination #GstFormat.
3824 * @dest_value: a pointer to the destination value.
3826 * Invokes the default converter on a pad.
3827 * This will forward the call to the pad obtained
3828 * using the internal link of
3831 * Returns: TRUE if the conversion could be performed.
3834 gst_pad_convert_default (GstPad * pad,
3835 GstFormat src_format, gint64 src_value,
3836 GstFormat * dest_format, gint64 * dest_value)
3838 GstPadConvertData data;
3840 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3841 g_return_val_if_fail (dest_format != NULL, FALSE);
3842 g_return_val_if_fail (dest_value != NULL, FALSE);
3844 data.src_format = src_format;
3845 data.src_value = src_value;
3846 data.dest_format = dest_format;
3847 data.dest_value = dest_value;
3849 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3850 gst_pad_convert_dispatcher, &data);
3855 * @pad: a #GstPad to invoke the default converter on.
3856 * @src_format: the source #GstFormat.
3857 * @src_value: the source value.
3858 * @dest_format: a pointer to the destination #GstFormat.
3859 * @dest_value: a pointer to the destination value.
3861 * Invokes a conversion on the pad.
3863 * Returns: TRUE if the conversion could be performed.
3866 gst_pad_convert (GstPad * pad,
3867 GstFormat src_format, gint64 src_value,
3868 GstFormat * dest_format, gint64 * dest_value)
3872 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3873 g_return_val_if_fail (dest_format != NULL, FALSE);
3874 g_return_val_if_fail (dest_value != NULL, FALSE);
3876 if (src_format == *dest_format) {
3877 *dest_value = src_value;
3881 rpad = GST_PAD_REALIZE (pad);
3883 if (GST_RPAD_CONVERTFUNC (rpad)) {
3884 return GST_RPAD_CONVERTFUNC (rpad) (GST_PAD (rpad), src_format,
3885 src_value, dest_format, dest_value);
3900 gst_pad_query_dispatcher (GstPad * pad, GstPadQueryData * data)
3902 return gst_pad_query (pad, data->type, data->format, data->value);
3906 * gst_pad_query_default:
3907 * @pad: a #GstPad to invoke the default query on.
3908 * @type: the #GstQueryType of the query to perform.
3909 * @format: a pointer to the #GstFormat of the result.
3910 * @value: a pointer to the result.
3912 * Invokes the default query function on a pad.
3914 * Returns: TRUE if the query could be performed.
3917 gst_pad_query_default (GstPad * pad, GstQueryType type,
3918 GstFormat * format, gint64 * value)
3920 GstPadQueryData data;
3922 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3923 g_return_val_if_fail (format != NULL, FALSE);
3924 g_return_val_if_fail (value != NULL, FALSE);
3927 data.format = format;
3930 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3931 gst_pad_query_dispatcher, &data);
3936 * @pad: a #GstPad to invoke the default query on.
3937 * @type: the #GstQueryType of the query to perform.
3938 * @format: a pointer to the #GstFormat asked for.
3939 * On return contains the #GstFormat used.
3940 * @value: a pointer to the result.
3942 * Queries a pad for one of the available properties. The format will be
3943 * adjusted to the actual format used when specifying formats such as
3944 * GST_FORMAT_DEFAULT.
3945 * FIXME: Tell if the format can be adjusted when specifying a definite format.
3947 * Returns: TRUE if the query could be performed.
3950 gst_pad_query (GstPad * pad, GstQueryType type,
3951 GstFormat * format, gint64 * value)
3955 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3956 g_return_val_if_fail (format != NULL, FALSE);
3957 g_return_val_if_fail (value != NULL, FALSE);
3959 rpad = GST_PAD_REALIZE (pad);
3961 g_return_val_if_fail (rpad, FALSE);
3963 if (GST_RPAD_QUERYFUNC (rpad))
3964 return GST_RPAD_QUERYFUNC (rpad) (GST_PAD (pad), type, format, value);
3970 gst_pad_get_formats_dispatcher (GstPad * pad, const GstFormat ** data)
3972 *data = gst_pad_get_formats (pad);
3978 * gst_pad_get_formats_default:
3979 * @pad: a #GstPad to query
3981 * Invoke the default format dispatcher for the pad.
3983 * Returns: An array of GstFormats ended with a 0 value.
3986 gst_pad_get_formats_default (GstPad * pad)
3988 GstFormat *result = NULL;
3990 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3992 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3993 gst_pad_get_formats_dispatcher, &result);
3999 * gst_pad_get_formats:
4000 * @pad: a #GstPad to query
4002 * Gets the list of supported formats from the pad.
4004 * Returns: An array of GstFormats ended with a 0 value.
4007 gst_pad_get_formats (GstPad * pad)
4011 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4013 rpad = GST_PAD_REALIZE (pad);
4015 if (GST_RPAD_FORMATSFUNC (rpad))
4016 return GST_RPAD_FORMATSFUNC (rpad) (GST_PAD (pad));