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.
2266 * Calls gst_pad_try_set_caps() for every other pad belonging to the
2267 * same element as @pad. If gst_pad_try_set_caps() fails on any pad,
2268 * the proxy link fails. May be used only during negotiation.
2270 * Returns: GST_PAD_LINK_OK if sucessful
2273 gst_pad_proxy_pad_link (GstPad * pad, const GstCaps * caps)
2275 GstElement *element;
2277 GstPadLinkReturn ret;
2279 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
2280 g_return_val_if_fail (caps != NULL, GST_PAD_LINK_REFUSED);
2282 GST_DEBUG ("proxying pad link for %s:%s", GST_DEBUG_PAD_NAME (pad));
2284 element = gst_pad_get_parent (pad);
2286 pads = gst_element_get_pad_list (element);
2289 GstPad *otherpad = GST_PAD (pads->data);
2291 if (otherpad != pad) {
2292 ret = gst_pad_try_set_caps (otherpad, caps);
2293 if (GST_PAD_LINK_FAILED (ret)) {
2297 pads = g_list_next (pads);
2300 return GST_PAD_LINK_OK;
2304 * gst_pad_proxy_fixate:
2305 * @pad: a #GstPad to proxy.
2307 * Implements a default fixate function based on the caps set on the other
2308 * pads in the element. This function should only be used if every pad
2309 * has the same pad template caps.
2311 * Returns: a fixated caps, or NULL if caps cannot be fixed
2314 gst_pad_proxy_fixate (GstPad * pad, const GstCaps * caps)
2316 GstElement *element;
2318 const GstCaps *othercaps;
2320 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2321 g_return_val_if_fail (caps != NULL, NULL);
2323 GST_DEBUG ("proxying fixate for %s:%s\n", GST_DEBUG_PAD_NAME (pad));
2325 element = gst_pad_get_parent (pad);
2327 pads = gst_element_get_pad_list (element);
2330 GstPad *otherpad = GST_PAD (pads->data);
2332 /* FIXME check that each pad has the same pad template caps */
2334 if (otherpad != pad) {
2335 othercaps = gst_pad_get_negotiated_caps (otherpad);
2340 icaps = gst_caps_intersect (othercaps, caps);
2341 if (!gst_caps_is_empty (icaps)) {
2344 gst_caps_free (icaps);
2348 pads = g_list_next (pads);
2355 * gst_pad_set_explicit_caps:
2356 * @pad: a #GstPad to set the explicit caps of
2357 * @caps: the #GstCaps to set
2359 * If a pad has been told to use explicit caps, this function is used
2360 * to set the explicit caps. If @caps is NULL, the explicit caps are
2363 * This function calls gst_pad_try_set_caps() on the pad. If that
2364 * call fails, GST_ELEMENT_ERROR() is called to indicate a negotiation
2367 * Returns: TRUE if the caps were set correctly, otherwise FALSE
2370 gst_pad_set_explicit_caps (GstPad * pad, const GstCaps * caps)
2372 GstPadLinkReturn link_ret;
2374 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2376 GST_CAT_DEBUG (GST_CAT_PADS, "setting explicit caps to %" GST_PTR_FORMAT,
2380 GST_CAT_DEBUG (GST_CAT_PADS, "caps is NULL");
2381 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2385 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), gst_caps_copy (caps));
2387 if (!GST_PAD_IS_LINKED (pad)) {
2388 GST_CAT_DEBUG (GST_CAT_PADS, "pad is not linked");
2391 link_ret = gst_pad_try_set_caps (pad, caps);
2392 if (link_ret == GST_PAD_LINK_REFUSED) {
2393 gchar *caps_str = gst_caps_to_string (caps);
2395 GST_ELEMENT_ERROR (gst_pad_get_parent (pad), CORE, PAD, (NULL),
2396 ("failed to negotiate (try_set_caps with \"%s\" returned REFUSED)",
2406 gst_pad_explicit_getcaps (GstPad * pad)
2408 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2410 if (GST_RPAD_EXPLICIT_CAPS (pad) == NULL) {
2411 const GstCaps *caps = gst_pad_get_pad_template_caps (pad);
2413 return gst_caps_copy (caps);
2415 return gst_caps_copy (GST_RPAD_EXPLICIT_CAPS (pad));
2418 static GstPadLinkReturn
2419 gst_pad_explicit_link (GstPad * pad, const GstCaps * caps)
2421 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
2422 g_return_val_if_fail (caps != NULL, GST_PAD_LINK_REFUSED);
2424 if (GST_RPAD_EXPLICIT_CAPS (pad) == NULL) {
2425 return GST_PAD_LINK_DELAYED;
2428 return GST_PAD_LINK_OK;
2432 * gst_pad_use_explicit_caps:
2433 * @pad: a #GstPad to set to use explicit caps
2435 * This function handles negotiation for pads that need to be set
2436 * to particular caps under complete control of the element, based
2437 * on some state in the element. This is often the case with
2438 * decoders and other elements whose caps is determined by the data
2441 * WARNING: This function is a hack and will be replaced with something
2442 * better in gstreamer-0.9.
2445 gst_pad_use_explicit_caps (GstPad * pad)
2447 g_return_if_fail (GST_IS_PAD (pad));
2449 gst_pad_set_getcaps_function (pad, gst_pad_explicit_getcaps);
2450 gst_pad_set_link_function (pad, gst_pad_explicit_link);
2451 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2455 * gst_pad_proxy_link:
2456 * @pad: a #GstPad to proxy to.
2457 * @caps: the #GstCaps to use in proxying.
2459 * Proxies the link function to the specified pad.
2461 * Returns: TRUE if the peer pad accepted the caps, FALSE otherwise.
2464 gst_pad_proxy_link (GstPad * pad, const GstCaps * caps)
2466 return gst_pad_try_set_caps (pad, caps);
2470 * gst_pad_is_negotiated:
2471 * @pad: a #GstPad to get the negotiation status of
2473 * Returns: TRUE if the pad has successfully negotiated caps.
2476 gst_pad_is_negotiated (GstPad * pad)
2478 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2480 if (!GST_PAD_REALIZE (pad))
2482 if (!GST_RPAD_LINK (pad))
2485 return (GST_RPAD_LINK (pad)->caps != NULL);
2489 * gst_pad_get_negotiated_caps:
2490 * @pad: a #GstPad to get the negotiated capabilites of
2492 * Gets the currently negotiated caps of a pad.
2494 * Returns: the currently negotiated caps of a pad, or NULL if the pad isn't
2497 G_CONST_RETURN GstCaps *
2498 gst_pad_get_negotiated_caps (GstPad * pad)
2500 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2502 if (!GST_PAD_REALIZE (pad))
2504 if (!GST_RPAD_LINK (pad))
2507 return GST_RPAD_LINK (pad)->caps;
2512 * @pad: a #GstPad to get the capabilities of.
2514 * Gets the capabilities of this pad.
2516 * Returns: the #GstCaps of this pad. This function returns a new caps, so use
2517 * gst_caps_free to get rid of it.
2520 gst_pad_get_caps (GstPad * pad)
2522 GstRealPad *realpad;
2524 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2526 realpad = GST_PAD_REALIZE (pad);
2528 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
2529 GST_DEBUG_PAD_NAME (realpad), realpad);
2531 if (GST_RPAD_GETCAPSFUNC (realpad)) {
2534 GST_CAT_DEBUG (GST_CAT_CAPS, "using pad getcaps function");
2535 caps = GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD (realpad));
2538 g_critical ("pad %s:%s returned NULL caps from getcaps function\n",
2539 GST_ELEMENT_NAME (GST_PAD_PARENT (GST_PAD (realpad))),
2540 GST_PAD_NAME (realpad));
2541 caps = gst_caps_new_any ();
2545 } else if (GST_PAD_PAD_TEMPLATE (realpad)) {
2546 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (realpad);
2547 const GstCaps *caps;
2549 caps = GST_PAD_TEMPLATE_CAPS (templ);
2550 GST_CAT_DEBUG (GST_CAT_CAPS,
2551 "using pad template %p with caps %" GST_PTR_FORMAT, templ, caps);
2554 /* FIXME we should enable something like this someday, but this is
2556 if (!gst_caps_is_fixed (caps)) {
2558 ("pad %s:%s (%p) has no getcaps function and the pad template returns non-fixed caps. Element is probably broken.\n",
2559 GST_DEBUG_PAD_NAME (realpad), realpad);
2563 return gst_caps_copy (GST_PAD_TEMPLATE_CAPS (templ));
2565 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
2569 g_warning ("pad %s:%s (%p) has no pad template\n",
2570 GST_DEBUG_PAD_NAME (realpad), realpad);
2573 return gst_caps_new_any ();
2577 * gst_pad_get_pad_template_caps:
2578 * @pad: a #GstPad to get the template capabilities from.
2580 * Gets the capabilities for @pad's template.
2582 * Returns: the #GstCaps of this pad template. If you intend to keep a reference
2583 * on the caps, make a copy (see gst_caps_copy ()).
2586 gst_pad_get_pad_template_caps (GstPad * pad)
2588 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2590 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2592 if (GST_PAD_PAD_TEMPLATE (pad))
2593 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2596 /* FIXME this should be enabled some day */
2597 /* wingo: why? mail the list during 0.9 when you find this :) */
2598 g_warning ("pad %s:%s (%p) has no pad template\n",
2599 GST_DEBUG_PAD_NAME (realpad), realpad);
2602 return gst_static_caps_get (&anycaps);
2605 /* FIXME 0.9: This function should probably die, or at least be renamed to
2606 * get_caps_by_format. */
2608 * gst_pad_template_get_caps_by_name:
2609 * @templ: a #GstPadTemplate to get the capabilities of.
2610 * @name: the name of the capability to get.
2612 * Gets the capability with the given name from @templ.
2614 * Returns: the #GstCaps of this pad template, or NULL if not found. If you
2615 * intend to keep a reference on the caps, make a copy (see gst_caps_copy ()).
2618 gst_pad_template_get_caps_by_name (GstPadTemplate * templ, const gchar * name)
2622 g_return_val_if_fail (templ != NULL, NULL);
2624 caps = GST_PAD_TEMPLATE_CAPS (templ);
2629 //return gst_caps_copy (gst_caps_get_by_name (caps, name));
2633 /* FIXME 0.9: What good is this if it only works for already-negotiated pads? */
2635 * gst_pad_check_compatibility:
2636 * @srcpad: the source #GstPad to check.
2637 * @sinkpad: the sink #GstPad to check against.
2639 * Checks if two pads have compatible capabilities. If neither one has yet been
2640 * negotiated, returns TRUE for no good reason.
2642 * Returns: TRUE if they are compatible or if the capabilities could not be
2643 * checked, FALSE if the capabilities are not compatible.
2646 gst_pad_check_compatibility (GstPad * srcpad, GstPad * sinkpad)
2648 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2649 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2651 if (GST_PAD_CAPS (srcpad) && GST_PAD_CAPS (sinkpad)) {
2652 if (!gst_caps_is_always_compatible (GST_PAD_CAPS (srcpad),
2653 GST_PAD_CAPS (sinkpad))) {
2659 GST_CAT_DEBUG (GST_CAT_PADS,
2660 "could not check capabilities of pads (%s:%s) and (%s:%s) %p %p",
2661 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2662 GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad));
2669 * @pad: a #GstPad to get the peer of.
2671 * Gets the peer of @pad.
2673 * Returns: the peer #GstPad.
2676 gst_pad_get_peer (GstPad * pad)
2678 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2680 return GST_PAD (GST_PAD_PEER (pad));
2684 * gst_pad_get_allowed_caps:
2685 * @pad: a real #GstPad.
2687 * Gets the capabilities of the allowed media types that can flow through @pad.
2688 * The caller must free the resulting caps.
2690 * Returns: the allowed #GstCaps of the pad link. Free the caps when
2691 * you no longer need it.
2694 gst_pad_get_allowed_caps (GstPad * pad)
2696 const GstCaps *mycaps;
2702 g_return_val_if_fail (GST_IS_REAL_PAD (pad), NULL);
2704 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "get allowed caps of %s:%s",
2705 GST_DEBUG_PAD_NAME (pad));
2707 mycaps = gst_pad_get_pad_template_caps (pad);
2708 if (GST_RPAD_PEER (pad) == NULL) {
2709 return gst_caps_copy (mycaps);
2712 peercaps = gst_pad_get_caps (GST_PAD_PEER (pad));
2713 caps = gst_caps_intersect (mycaps, peercaps);
2714 gst_caps_free (peercaps);
2716 link = GST_RPAD_LINK (pad);
2717 if (link->filtercaps) {
2718 icaps = gst_caps_intersect (caps, link->filtercaps);
2719 gst_caps_free (caps);
2727 * gst_pad_caps_change_notify:
2730 * Called to indicate that the return value of @pad's getcaps function may have
2731 * changed, and that a renegotiation is suggested.
2734 gst_pad_caps_change_notify (GstPad * pad)
2739 * gst_pad_recover_caps_error:
2740 * @pad: a #GstPad that had a failed capsnego
2741 * @allowed: possible caps for the link
2743 * Attempt to recover from a failed caps negotiation. This function
2744 * is typically called by a plugin that exhausted its list of caps
2745 * and wants the application to resolve the issue. The application
2746 * should connect to the pad's caps_nego_failed signal and should
2747 * resolve the issue by connecting another element for example.
2749 * Returns: TRUE when the issue was resolved, dumps detailed information
2750 * on the console and returns FALSE otherwise.
2753 gst_pad_recover_caps_error (GstPad * pad, const GstCaps * allowed)
2759 /* FIXME 0.9: Is it so difficult to write SOURCE? */
2761 * gst_pad_alloc_buffer:
2762 * @pad: a source #GstPad.
2764 * Allocates a new, empty buffer optimized to push to pad @pad. This
2765 * function only works if @pad is a src pad.
2767 * Returns: a new, empty #GstBuffer, or NULL if there is an error
2770 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size)
2774 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2775 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
2777 peer = GST_RPAD_PEER (pad);
2780 return gst_buffer_new_and_alloc (size);
2782 GST_CAT_DEBUG (GST_CAT_BUFFER, "(%s:%s): getting buffer",
2783 GST_DEBUG_PAD_NAME (pad));
2785 if (peer->bufferallocfunc) {
2786 GST_CAT_DEBUG (GST_CAT_PADS,
2787 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s",
2788 GST_DEBUG_FUNCPTR_NAME (peer->bufferallocfunc),
2789 &peer->bufferallocfunc, GST_DEBUG_PAD_NAME (((GstPad *) peer)));
2790 return (peer->bufferallocfunc) (GST_PAD (peer), offset, size);
2792 return gst_buffer_new_and_alloc (size);
2797 gst_real_pad_dispose (GObject * object)
2799 GstPad *pad = GST_PAD (object);
2801 /* No linked pad can ever be disposed.
2802 * It has to have a parent to be linked
2803 * and a parent would hold a reference */
2804 /* FIXME: what about if g_object_dispose is explicitly called on the pad? Is
2805 that legal? otherwise we could assert GST_OBJECT_PARENT (pad) == NULL as
2807 g_assert (GST_PAD_PEER (pad) == NULL);
2809 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s",
2810 GST_DEBUG_PAD_NAME (pad));
2812 /* we destroy the ghostpads, because they are nothing without the real pad */
2813 if (GST_REAL_PAD (pad)->ghostpads) {
2814 GList *orig, *ghostpads;
2816 orig = ghostpads = g_list_copy (GST_REAL_PAD (pad)->ghostpads);
2819 GstPad *ghostpad = GST_PAD (ghostpads->data);
2821 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))) {
2822 GstElement *parent = GST_ELEMENT (GST_OBJECT_PARENT (ghostpad));
2824 GST_CAT_DEBUG (GST_CAT_REFCOUNTING,
2825 "removing ghost pad from element '%s'", GST_OBJECT_NAME (parent));
2826 gst_element_remove_pad (parent, ghostpad);
2828 /* handle the case where we have some floating ghost pad that was never
2829 added to an element */
2830 g_object_set (ghostpad, "real-pad", NULL, NULL);
2832 ghostpads = g_list_next (ghostpads);
2835 /* as the ghost pads are removed, they remove themselves from ->ghostpads.
2836 So it should be empty now. Let's assert that. */
2837 g_assert (GST_REAL_PAD (pad)->ghostpads == NULL);
2840 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
2841 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
2842 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
2844 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
2847 if (GST_RPAD_EXPLICIT_CAPS (pad)) {
2848 GST_ERROR_OBJECT (pad, "still explicit caps %" GST_PTR_FORMAT " set",
2849 GST_RPAD_EXPLICIT_CAPS (pad));
2850 g_warning ("pad %p has still explicit caps set", pad);
2851 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2853 G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
2857 #ifndef GST_DISABLE_LOADSAVE
2858 /* FIXME: why isn't this on a GstElement ? */
2860 * gst_pad_load_and_link:
2861 * @self: an #xmlNodePtr to read the description from.
2862 * @parent: the #GstObject element that owns the pad.
2864 * Reads the pad definition from the XML node and links the given pad
2865 * in the element to a pad of an element up in the hierarchy.
2868 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
2870 xmlNodePtr field = self->xmlChildrenNode;
2871 GstPad *pad = NULL, *targetpad;
2875 GstObject *grandparent;
2878 if (!strcmp (field->name, "name")) {
2879 pad = gst_element_get_pad (GST_ELEMENT (parent),
2880 xmlNodeGetContent (field));
2881 } else if (!strcmp (field->name, "peer")) {
2882 peer = xmlNodeGetContent (field);
2884 field = field->next;
2886 g_return_if_fail (pad != NULL);
2891 split = g_strsplit (peer, ".", 2);
2893 if (split[0] == NULL || split[1] == NULL) {
2894 GST_CAT_DEBUG (GST_CAT_XML,
2895 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
2896 peer, GST_DEBUG_PAD_NAME (pad));
2900 g_return_if_fail (split[0] != NULL);
2901 g_return_if_fail (split[1] != NULL);
2903 grandparent = gst_object_get_parent (parent);
2905 if (grandparent && GST_IS_BIN (grandparent)) {
2906 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2913 targetpad = gst_element_get_pad (target, split[1]);
2915 if (targetpad == NULL)
2918 gst_pad_link (pad, targetpad);
2925 * gst_pad_save_thyself:
2926 * @pad: a #GstPad to save.
2927 * @parent: the parent #xmlNodePtr to save the description in.
2929 * Saves the pad into an xml representation.
2931 * Returns: the #xmlNodePtr representation of the pad.
2934 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
2936 GstRealPad *realpad;
2939 g_return_val_if_fail (GST_IS_REAL_PAD (object), NULL);
2941 realpad = GST_REAL_PAD (object);
2943 xmlNewChild (parent, NULL, "name", GST_PAD_NAME (realpad));
2944 if (GST_RPAD_PEER (realpad) != NULL) {
2947 peer = GST_PAD (GST_RPAD_PEER (realpad));
2948 /* first check to see if the peer's parent's parent is the same */
2949 /* we just save it off */
2950 content = g_strdup_printf ("%s.%s",
2951 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
2952 xmlNewChild (parent, NULL, "peer", content);
2955 xmlNewChild (parent, NULL, "peer", "");
2960 /* FIXME: shouldn't it be gst_pad_ghost_* ?
2961 * dunno -- wingo 7 feb 2004
2964 * gst_ghost_pad_save_thyself:
2965 * @pad: a ghost #GstPad to save.
2966 * @parent: the parent #xmlNodePtr to save the description in.
2968 * Saves the ghost pad into an xml representation.
2970 * Returns: the #xmlNodePtr representation of the pad.
2973 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
2977 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2979 self = xmlNewChild (parent, NULL, "ghostpad", NULL);
2980 xmlNewChild (self, NULL, "name", GST_PAD_NAME (pad));
2981 xmlNewChild (self, NULL, "parent", GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
2983 /* FIXME FIXME FIXME! */
2987 #endif /* GST_DISABLE_LOADSAVE */
2991 * @pad: a source #GstPad.
2992 * @data: the #GstData to push.
2994 * Pushes a buffer or an event to the peer of @pad. @pad must be linked. May
2995 * only be called by @pad's parent.
2998 gst_pad_push (GstPad * pad, GstData * data)
3002 g_return_if_fail (GST_IS_PAD (pad));
3003 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
3004 g_return_if_fail (data != NULL);
3006 if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), &data))
3009 if (!GST_PAD_IS_LINKED (pad)) {
3010 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad,
3011 "not pushing data %p as pad is unconnected", data);
3012 gst_data_unref (data);
3016 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad, "pushing");
3017 peer = GST_RPAD_PEER (pad);
3020 g_warning ("push on pad %s:%s but it is unlinked",
3021 GST_DEBUG_PAD_NAME (pad));
3023 if (!GST_IS_EVENT (data) && !GST_PAD_IS_ACTIVE (peer)) {
3024 g_warning ("push on peer of pad %s:%s but peer is not active",
3025 GST_DEBUG_PAD_NAME (pad));
3029 if (peer->chainhandler) {
3031 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad,
3032 "calling chainhandler &%s of peer pad %s:%s",
3033 GST_DEBUG_FUNCPTR_NAME (peer->chainhandler),
3034 GST_DEBUG_PAD_NAME (GST_PAD (peer)));
3035 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
3038 (peer->chainhandler) (GST_PAD (peer), data);
3041 g_warning ("trying to push a NULL buffer on pad %s:%s",
3042 GST_DEBUG_PAD_NAME (peer));
3046 g_warning ("internal error: push on pad %s:%s but it has no chainhandler",
3047 GST_DEBUG_PAD_NAME (peer));
3050 /* clean up the mess here */
3052 gst_data_unref (data);
3057 * @pad: a sink #GstPad.
3059 * Pulls an event or a buffer from the peer pad. May only be called by @pad's
3062 * Returns: a new #GstData from the peer pad.
3065 gst_pad_pull (GstPad * pad)
3069 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad, "pulling");
3071 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
3072 GST_DATA (gst_event_new (GST_EVENT_INTERRUPT)));
3074 peer = GST_RPAD_PEER (pad);
3077 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3078 ("pull on pad %s:%s but it was unlinked", GST_DEBUG_PAD_NAME (pad)));
3081 if (peer->gethandler) {
3084 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad,
3085 "calling gethandler %s of peer pad %s:%s",
3086 GST_DEBUG_FUNCPTR_NAME (peer->gethandler), GST_DEBUG_PAD_NAME (peer));
3088 data = (peer->gethandler) (GST_PAD (peer));
3091 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
3096 /* no null buffers allowed */
3097 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3098 ("NULL buffer during pull on %s:%s", GST_DEBUG_PAD_NAME (pad)));
3100 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3101 ("pull on pad %s:%s but the peer pad %s:%s has no gethandler",
3102 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer)));
3105 return GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
3110 * @padlist: a #GList of sink pads.
3112 * Waits for a buffer on any of the list of pads. Each #GstPad in @padlist must
3113 * be owned by the calling code.
3115 * Returns: the #GstPad that has a buffer available.
3116 * Use #gst_pad_pull() to get the buffer.
3119 gst_pad_selectv (GList * padlist)
3123 pad = gst_scheduler_pad_select (GST_PAD_PARENT (padlist->data)->sched,
3128 /* FIXME 0.9: Don't allow the first pad to be NULL */
3131 * @pad: a first sink #GstPad to perform the select on.
3132 * @...: A NULL-terminated list of more pads to select on.
3134 * Waits for a buffer on the given set of pads.
3136 * Returns: the #GstPad that has a buffer available.
3137 * Use #gst_pad_pull() to get the buffer.
3140 gst_pad_select (GstPad * pad, ...)
3148 va_start (var_args, pad);
3150 result = gst_pad_select_valist (pad, var_args);
3158 * gst_pad_select_valist:
3159 * @pad: a first #GstPad to perform the select on.
3160 * @varargs: A va_list of more pads to select on.
3162 * Waits for a buffer on the given set of pads.
3164 * Returns: the #GstPad that has a buffer available.
3165 * Use #gst_pad_pull() to get the buffer.
3168 gst_pad_select_valist (GstPad * pad, va_list var_args)
3171 GList *padlist = NULL;
3177 padlist = g_list_prepend (padlist, pad);
3178 pad = va_arg (var_args, GstPad *);
3180 result = gst_pad_selectv (padlist);
3181 g_list_free (padlist);
3186 /************************************************************************
3191 static void gst_pad_template_class_init (GstPadTemplateClass * klass);
3192 static void gst_pad_template_init (GstPadTemplate * templ);
3193 static void gst_pad_template_dispose (GObject * object);
3196 gst_pad_template_get_type (void)
3198 static GType padtemplate_type = 0;
3200 if (!padtemplate_type) {
3201 static const GTypeInfo padtemplate_info = {
3202 sizeof (GstPadTemplateClass), NULL, NULL,
3203 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
3204 sizeof (GstPadTemplate),
3206 (GInstanceInitFunc) gst_pad_template_init, NULL
3210 g_type_register_static (GST_TYPE_OBJECT, "GstPadTemplate",
3211 &padtemplate_info, 0);
3213 return padtemplate_type;
3217 gst_pad_template_class_init (GstPadTemplateClass * klass)
3219 GObjectClass *gobject_class;
3220 GstObjectClass *gstobject_class;
3222 gobject_class = (GObjectClass *) klass;
3223 gstobject_class = (GstObjectClass *) klass;
3225 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
3227 gst_pad_template_signals[TEMPL_PAD_CREATED] =
3228 g_signal_new ("pad-created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
3229 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
3230 NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
3232 gobject_class->dispose = gst_pad_template_dispose;
3234 gstobject_class->path_string_separator = "*";
3238 gst_pad_template_init (GstPadTemplate * templ)
3243 gst_pad_template_dispose (GObject * object)
3245 GstPadTemplate *templ = GST_PAD_TEMPLATE (object);
3247 g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
3248 if (GST_PAD_TEMPLATE_CAPS (templ)) {
3249 gst_caps_free (GST_PAD_TEMPLATE_CAPS (templ));
3252 G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object);
3255 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
3257 * SOMETIMES padtemplates can do whatever they want, they are provided by the
3259 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
3260 * 'sink%d' template is automatically selected), so we need to restrict their
3264 name_is_valid (const gchar * name, GstPadPresence presence)
3268 if (presence == GST_PAD_ALWAYS) {
3269 if (strchr (name, '%')) {
3270 g_warning ("invalid name template %s: conversion specifications are not"
3271 " allowed for GST_PAD_ALWAYS padtemplates", name);
3274 } else if (presence == GST_PAD_REQUEST) {
3275 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
3276 g_warning ("invalid name template %s: only one conversion specification"
3277 " allowed in GST_PAD_REQUEST padtemplate", name);
3280 if (str && (*(str + 1) != 's' && *(str + 1) != 'd')) {
3281 g_warning ("invalid name template %s: conversion specification must be of"
3282 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
3285 if (str && (*(str + 2) != '\0')) {
3286 g_warning ("invalid name template %s: conversion specification must"
3287 " appear at the end of the GST_PAD_REQUEST padtemplate name", name);
3296 * gst_static_pad_template_get:
3297 * @pad_template: the static pad template
3299 * Converts a #GstStaticPadTemplate into a #GstPadTemplate.
3301 * Returns: a new #GstPadTemplate.
3304 gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
3306 GstPadTemplate *new;
3308 if (!name_is_valid (pad_template->name_template, pad_template->presence))
3311 new = g_object_new (gst_pad_template_get_type (),
3312 "name", pad_template->name_template, NULL);
3314 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (pad_template->name_template);
3315 GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction;
3316 GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence;
3318 GST_PAD_TEMPLATE_CAPS (new) =
3319 gst_caps_copy (gst_static_caps_get (&pad_template->static_caps));
3325 * gst_pad_template_new:
3326 * @name_template: the name template.
3327 * @direction: the #GstPadDirection of the template.
3328 * @presence: the #GstPadPresence of the pad.
3329 * @caps: a #GstCaps set for the template. The caps are taken ownership of.
3331 * Creates a new pad template with a name according to the given template
3332 * and with the given arguments. This functions takes ownership of the provided
3333 * caps, so be sure to not use them afterwards.
3335 * Returns: a new #GstPadTemplate.
3338 gst_pad_template_new (const gchar * name_template,
3339 GstPadDirection direction, GstPadPresence presence, GstCaps * caps)
3341 GstPadTemplate *new;
3343 g_return_val_if_fail (name_template != NULL, NULL);
3345 if (!name_is_valid (name_template, presence))
3349 #ifdef USE_POISONING
3351 GstCaps *newcaps = gst_caps_copy (caps);
3353 gst_caps_free (caps);
3358 new = g_object_new (gst_pad_template_get_type (),
3359 "name", name_template, NULL);
3361 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
3362 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
3363 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
3364 GST_PAD_TEMPLATE_CAPS (new) = caps;
3370 * gst_pad_template_get_caps:
3371 * @templ: a #GstPadTemplate to get capabilities of.
3373 * Gets the capabilities of the pad template.
3375 * Returns: the #GstCaps of the pad template. If you need to keep a reference to
3376 * the caps, make a copy (see gst_caps_copy ()).
3379 gst_pad_template_get_caps (GstPadTemplate * templ)
3381 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
3383 return GST_PAD_TEMPLATE_CAPS (templ);
3387 * gst_pad_set_element_private:
3388 * @pad: the #GstPad to set the private data of.
3389 * @priv: The private data to attach to the pad.
3391 * Set the given private data gpointer on the pad.
3392 * This function can only be used by the element that owns the pad.
3395 gst_pad_set_element_private (GstPad * pad, gpointer priv)
3397 pad->element_private = priv;
3401 * gst_pad_get_element_private:
3402 * @pad: the #GstPad to get the private data of.
3404 * Gets the private data of a pad.
3406 * Returns: a #gpointer to the private data.
3409 gst_pad_get_element_private (GstPad * pad)
3411 return pad->element_private;
3415 /***** ghost pads *****/
3416 GType _gst_ghost_pad_type = 0;
3418 static void gst_ghost_pad_class_init (GstGhostPadClass * klass);
3419 static void gst_ghost_pad_init (GstGhostPad * pad);
3420 static void gst_ghost_pad_dispose (GObject * object);
3421 static void gst_ghost_pad_get_property (GObject * object, guint prop_id,
3422 GValue * value, GParamSpec * pspec);
3423 static void gst_ghost_pad_set_property (GObject * object, guint prop_id,
3424 const GValue * value, GParamSpec * pspec);
3426 static GstPad *ghost_pad_parent_class = NULL;
3428 /* static guint gst_ghost_pad_signals[LAST_SIGNAL] = { 0 }; */
3437 gst_ghost_pad_get_type (void)
3439 if (!_gst_ghost_pad_type) {
3440 static const GTypeInfo pad_info = {
3441 sizeof (GstGhostPadClass), NULL, NULL,
3442 (GClassInitFunc) gst_ghost_pad_class_init, NULL, NULL,
3443 sizeof (GstGhostPad),
3445 (GInstanceInitFunc) gst_ghost_pad_init,
3449 _gst_ghost_pad_type = g_type_register_static (GST_TYPE_PAD, "GstGhostPad",
3452 return _gst_ghost_pad_type;
3456 gst_ghost_pad_class_init (GstGhostPadClass * klass)
3458 GObjectClass *gobject_class;
3460 gobject_class = (GObjectClass *) klass;
3462 ghost_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
3464 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_ghost_pad_dispose);
3465 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_ghost_pad_set_property);
3466 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_ghost_pad_get_property);
3468 g_object_class_install_property (gobject_class, GPAD_ARG_REAL_PAD,
3469 g_param_spec_object ("real-pad", "Real pad",
3470 "The real pad for the ghost pad", GST_TYPE_PAD, G_PARAM_READWRITE));
3474 gst_ghost_pad_init (GstGhostPad * pad)
3476 /* zeroed by glib */
3480 gst_ghost_pad_dispose (GObject * object)
3482 g_object_set (object, "real-pad", NULL, NULL);
3484 G_OBJECT_CLASS (ghost_pad_parent_class)->dispose (object);
3488 gst_ghost_pad_set_property (GObject * object, guint prop_id,
3489 const GValue * value, GParamSpec * pspec)
3491 GstPad *ghostpad = (GstPad *) object;
3492 GstPad *oldrealpad = (GstPad *) GST_GPAD_REALPAD (ghostpad);
3493 GstPad *realpad = NULL;
3496 case GPAD_ARG_REAL_PAD:
3497 realpad = g_value_get_object (value);
3500 if (realpad == oldrealpad)
3503 gst_pad_remove_ghost_pad (oldrealpad, ghostpad);
3507 gst_pad_add_ghost_pad (realpad, ghostpad);
3511 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3517 gst_ghost_pad_get_property (GObject * object, guint prop_id,
3518 GValue * value, GParamSpec * pspec)
3521 case GPAD_ARG_REAL_PAD:
3522 g_value_set_object (value, GST_GPAD_REALPAD (object));
3526 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3532 * gst_ghost_pad_new:
3533 * @name: the name of the new ghost pad.
3534 * @pad: the #GstPad to create a ghost pad for.
3536 * Creates a new ghost pad associated with @pad, and named @name. If @name is
3537 * %NULL, a guaranteed unique name (across all ghost pads) will be assigned.
3539 * Returns: a new ghost #GstPad, or %NULL in case of an error.
3542 gst_ghost_pad_new (const gchar * name, GstPad * pad)
3546 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3548 gpad = g_object_new (GST_TYPE_GHOST_PAD, "name", name, "real-pad", pad, NULL);
3550 GST_CAT_DEBUG (GST_CAT_PADS, "created ghost pad \"%s\" for pad %s:%s",
3551 GST_OBJECT_NAME (gpad), GST_DEBUG_PAD_NAME (pad));
3557 * gst_pad_get_internal_links_default:
3558 * @pad: the #GstPad to get the internal links of.
3560 * Gets a list of pads to which the given pad is linked to
3561 * inside of the parent element.
3562 * This is the default handler, and thus returns a list of all of the
3563 * pads inside the parent element with opposite direction.
3564 * The caller must free this list after use.
3566 * Returns: a newly allocated #GList of pads.
3569 gst_pad_get_internal_links_default (GstPad * pad)
3574 GstPadDirection direction;
3577 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3579 rpad = GST_PAD_REALIZE (pad);
3580 direction = rpad->direction;
3582 parent = GST_PAD_PARENT (rpad);
3583 parent_pads = parent->pads;
3585 while (parent_pads) {
3586 GstRealPad *parent_pad = GST_PAD_REALIZE (parent_pads->data);
3588 if (parent_pad->direction != direction) {
3589 res = g_list_prepend (res, parent_pad);
3592 parent_pads = g_list_next (parent_pads);
3599 * gst_pad_get_internal_links:
3600 * @pad: the #GstPad to get the internal links of.
3602 * Gets a list of pads to which the given pad is linked to
3603 * inside of the parent element.
3604 * The caller must free this list after use.
3606 * Returns: a newly allocated #GList of pads.
3609 gst_pad_get_internal_links (GstPad * pad)
3614 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3616 rpad = GST_PAD_REALIZE (pad);
3618 if (GST_RPAD_INTLINKFUNC (rpad))
3619 res = GST_RPAD_INTLINKFUNC (rpad) (GST_PAD (rpad));
3626 gst_pad_event_default_dispatch (GstPad * pad, GstElement * element,
3631 GST_INFO_OBJECT (pad, "Sending event %p to all internally linked pads",
3634 orig = pads = gst_pad_get_internal_links (pad);
3637 GstPad *eventpad = GST_PAD (pads->data);
3639 pads = g_list_next (pads);
3641 /* for all of the internally-linked pads that are actually linked */
3642 if (GST_PAD_IS_LINKED (eventpad)) {
3643 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
3644 /* increase the refcount */
3645 gst_event_ref (event);
3646 gst_pad_push (eventpad, GST_DATA (event));
3648 GstPad *peerpad = GST_PAD (GST_RPAD_PEER (eventpad));
3650 /* we only send the event on one pad, multi-sinkpad elements
3651 * should implement a handler */
3653 return gst_pad_send_event (peerpad, event);
3657 gst_event_unref (event);
3659 return (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
3663 * gst_pad_event_default:
3664 * @pad: a #GstPad to call the default event handler on.
3665 * @event: the #GstEvent to handle.
3667 * Invokes the default event handler for the given pad. End-of-stream and
3668 * discontinuity events are handled specially, and then the event is sent to all
3669 * pads internally linked to @pad. Note that if there are many possible sink
3670 * pads that are internally linked to @pad, only one will be sent an event.
3671 * Multi-sinkpad elements should implement custom event handlers.
3673 * Returns: TRUE if the event was sent succesfully.
3676 gst_pad_event_default (GstPad * pad, GstEvent * event)
3678 GstElement *element;
3680 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3681 g_return_val_if_fail (event != NULL, FALSE);
3683 element = GST_PAD_PARENT (pad);
3685 switch (GST_EVENT_TYPE (event)) {
3687 gst_pad_event_default_dispatch (pad, element, event);
3688 gst_element_set_eos (element);
3690 case GST_EVENT_DISCONTINUOUS:
3694 if (gst_element_requires_clock (element) && element->clock) {
3695 if (gst_event_discont_get_value (event, GST_FORMAT_TIME, &time)) {
3696 gst_element_set_time (element, time);
3698 GstFormat format = GST_FORMAT_TIME;
3701 for (i = 0; i < event->event_data.discont.noffsets; i++) {
3702 if (gst_pad_convert (pad,
3703 event->event_data.discont.offsets[i].format,
3704 event->event_data.discont.offsets[i].value, &format,
3706 gst_element_set_time (element, time);
3707 } else if (i == event->event_data.discont.noffsets) {
3709 ("can't adjust clock to new time when time not provided");
3716 return gst_pad_event_default_dispatch (pad, element, event);
3722 * gst_pad_dispatcher:
3723 * @pad: a #GstPad to dispatch.
3724 * @dispatch: the #GstDispatcherFunction to call.
3725 * @data: gpointer user data passed to the dispatcher function.
3727 * Invokes the given dispatcher function on all pads that are
3728 * internally linked to the given pad.
3729 * The GstPadDispatcherFunction should return TRUE when no further pads
3730 * need to be processed.
3732 * Returns: TRUE if one of the dispatcher functions returned TRUE.
3735 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
3738 gboolean res = FALSE;
3739 GList *int_pads, *orig;
3741 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3742 g_return_val_if_fail (dispatch != NULL, FALSE);
3744 orig = int_pads = gst_pad_get_internal_links (pad);
3747 GstRealPad *int_rpad = GST_PAD_REALIZE (int_pads->data);
3748 GstRealPad *int_peer = GST_RPAD_PEER (int_rpad);
3751 res = dispatch (GST_PAD (int_peer), data);
3755 int_pads = g_list_next (int_pads);
3764 * gst_pad_send_event:
3765 * @pad: a #GstPad to send the event to.
3766 * @event: the #GstEvent to send to the pad.
3768 * Sends the event to the pad.
3770 * Returns: TRUE if the event was handled.
3773 gst_pad_send_event (GstPad * pad, GstEvent * event)
3775 gboolean success = FALSE;
3778 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3779 g_return_val_if_fail (event != NULL, FALSE);
3781 rpad = GST_PAD_REALIZE (pad);
3783 if (GST_EVENT_SRC (event) == NULL)
3784 GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (rpad));
3786 GST_CAT_DEBUG (GST_CAT_EVENT, "have event %d on pad %s:%s",
3787 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (rpad));
3789 if (GST_RPAD_EVENTHANDLER (rpad))
3790 success = GST_RPAD_EVENTHANDLER (rpad) (GST_PAD (rpad), event);
3792 g_warning ("pad %s:%s has no event handler", GST_DEBUG_PAD_NAME (rpad));
3793 gst_event_unref (event);
3801 GstFormat src_format;
3803 GstFormat *dest_format;
3809 gst_pad_convert_dispatcher (GstPad * pad, GstPadConvertData * data)
3811 return gst_pad_convert (pad, data->src_format, data->src_value,
3812 data->dest_format, data->dest_value);
3816 * gst_pad_convert_default:
3817 * @pad: a #GstPad to invoke the default converter on.
3818 * @src_format: the source #GstFormat.
3819 * @src_value: the source value.
3820 * @dest_format: a pointer to the destination #GstFormat.
3821 * @dest_value: a pointer to the destination value.
3823 * Invokes the default converter on a pad.
3824 * This will forward the call to the pad obtained
3825 * using the internal link of
3828 * Returns: TRUE if the conversion could be performed.
3831 gst_pad_convert_default (GstPad * pad,
3832 GstFormat src_format, gint64 src_value,
3833 GstFormat * dest_format, gint64 * dest_value)
3835 GstPadConvertData data;
3837 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3838 g_return_val_if_fail (dest_format != NULL, FALSE);
3839 g_return_val_if_fail (dest_value != NULL, FALSE);
3841 data.src_format = src_format;
3842 data.src_value = src_value;
3843 data.dest_format = dest_format;
3844 data.dest_value = dest_value;
3846 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3847 gst_pad_convert_dispatcher, &data);
3852 * @pad: a #GstPad to invoke the default converter on.
3853 * @src_format: the source #GstFormat.
3854 * @src_value: the source value.
3855 * @dest_format: a pointer to the destination #GstFormat.
3856 * @dest_value: a pointer to the destination value.
3858 * Invokes a conversion on the pad.
3860 * Returns: TRUE if the conversion could be performed.
3863 gst_pad_convert (GstPad * pad,
3864 GstFormat src_format, gint64 src_value,
3865 GstFormat * dest_format, gint64 * dest_value)
3869 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3870 g_return_val_if_fail (dest_format != NULL, FALSE);
3871 g_return_val_if_fail (dest_value != NULL, FALSE);
3873 if (src_format == *dest_format) {
3874 *dest_value = src_value;
3878 rpad = GST_PAD_REALIZE (pad);
3880 if (GST_RPAD_CONVERTFUNC (rpad)) {
3881 return GST_RPAD_CONVERTFUNC (rpad) (GST_PAD (rpad), src_format,
3882 src_value, dest_format, dest_value);
3897 gst_pad_query_dispatcher (GstPad * pad, GstPadQueryData * data)
3899 return gst_pad_query (pad, data->type, data->format, data->value);
3903 * gst_pad_query_default:
3904 * @pad: a #GstPad to invoke the default query on.
3905 * @type: the #GstQueryType of the query to perform.
3906 * @format: a pointer to the #GstFormat of the result.
3907 * @value: a pointer to the result.
3909 * Invokes the default query function on a pad.
3911 * Returns: TRUE if the query could be performed.
3914 gst_pad_query_default (GstPad * pad, GstQueryType type,
3915 GstFormat * format, gint64 * value)
3917 GstPadQueryData data;
3919 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3920 g_return_val_if_fail (format != NULL, FALSE);
3921 g_return_val_if_fail (value != NULL, FALSE);
3924 data.format = format;
3927 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3928 gst_pad_query_dispatcher, &data);
3933 * @pad: a #GstPad to invoke the default query on.
3934 * @type: the #GstQueryType of the query to perform.
3935 * @format: a pointer to the #GstFormat asked for.
3936 * On return contains the #GstFormat used.
3937 * @value: a pointer to the result.
3939 * Queries a pad for one of the available properties. The format will be
3940 * adjusted to the actual format used when specifying formats such as
3941 * GST_FORMAT_DEFAULT.
3942 * FIXME: Tell if the format can be adjusted when specifying a definite format.
3944 * Returns: TRUE if the query could be performed.
3947 gst_pad_query (GstPad * pad, GstQueryType type,
3948 GstFormat * format, gint64 * value)
3952 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3953 g_return_val_if_fail (format != NULL, FALSE);
3954 g_return_val_if_fail (value != NULL, FALSE);
3956 rpad = GST_PAD_REALIZE (pad);
3958 g_return_val_if_fail (rpad, FALSE);
3960 if (GST_RPAD_QUERYFUNC (rpad))
3961 return GST_RPAD_QUERYFUNC (rpad) (GST_PAD (pad), type, format, value);
3967 gst_pad_get_formats_dispatcher (GstPad * pad, const GstFormat ** data)
3969 *data = gst_pad_get_formats (pad);
3975 * gst_pad_get_formats_default:
3976 * @pad: a #GstPad to query
3978 * Invoke the default format dispatcher for the pad.
3980 * Returns: An array of GstFormats ended with a 0 value.
3983 gst_pad_get_formats_default (GstPad * pad)
3985 GstFormat *result = NULL;
3987 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3989 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3990 gst_pad_get_formats_dispatcher, &result);
3996 * gst_pad_get_formats:
3997 * @pad: a #GstPad to query
3999 * Gets the list of supported formats from the pad.
4001 * Returns: An array of GstFormats ended with a 0 value.
4004 gst_pad_get_formats (GstPad * pad)
4008 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4010 rpad = GST_PAD_REALIZE (pad);
4012 if (GST_RPAD_FORMATSFUNC (rpad))
4013 return GST_RPAD_FORMATSFUNC (rpad) (GST_PAD (pad));