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
55 GstPadFixateFunction app_fixate;
58 GstData *temp_store; /* used only when we invented a DISCONT */
68 static GstObject *padtemplate_parent_class = NULL;
69 static guint gst_pad_template_signals[TEMPL_LAST_SIGNAL] = { 0 };
71 GType _gst_pad_type = 0;
73 /***** Start with the base GstPad class *****/
74 static void gst_pad_class_init (GstPadClass * klass);
75 static void gst_pad_init (GstPad * pad);
76 static void gst_pad_dispose (GObject * object);
78 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
79 static GstCaps *_gst_pad_default_fixate_func (GstPad * pad,
80 const GstCaps * caps);
82 static gboolean gst_pad_link_try (GstPadLink * link);
83 static void gst_pad_link_free (GstPadLink * link);
85 #ifndef GST_DISABLE_LOADSAVE
86 static xmlNodePtr gst_pad_save_thyself (GstObject * object, xmlNodePtr parent);
89 static GstObject *pad_parent_class = NULL;
92 gst_pad_get_type (void)
95 static const GTypeInfo pad_info = {
96 sizeof (GstPadClass), NULL, NULL,
97 (GClassInitFunc) gst_pad_class_init, NULL, NULL,
100 (GInstanceInitFunc) gst_pad_init, NULL
103 _gst_pad_type = g_type_register_static (GST_TYPE_OBJECT, "GstPad",
106 return _gst_pad_type;
110 gst_pad_class_init (GstPadClass * klass)
112 GObjectClass *gobject_class;
114 gobject_class = (GObjectClass *) klass;
116 pad_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
118 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_pad_dispose);
122 gst_pad_init (GstPad * pad)
124 /* all structs are initialized to NULL by glib */
127 gst_pad_dispose (GObject * object)
129 GstPad *pad = GST_PAD (object);
131 gst_pad_set_pad_template (pad, NULL);
133 G_OBJECT_CLASS (pad_parent_class)->dispose (object);
138 /***** Then do the Real Pad *****/
139 /* Pad signals and args */
157 static void gst_real_pad_class_init (GstRealPadClass * klass);
158 static void gst_real_pad_init (GstRealPad * pad);
159 static void gst_real_pad_dispose (GObject * object);
161 static gboolean _gst_real_pad_fixate_accumulator (GSignalInvocationHint * ihint,
162 GValue * return_accu, const GValue * handler_return, gpointer dummy);
163 static void gst_real_pad_set_property (GObject * object, guint prop_id,
164 const GValue * value, GParamSpec * pspec);
165 static void gst_real_pad_get_property (GObject * object, guint prop_id,
166 GValue * value, GParamSpec * pspec);
168 GType _gst_real_pad_type = 0;
170 static GstPad *real_pad_parent_class = NULL;
171 static guint gst_real_pad_signals[REAL_LAST_SIGNAL] = { 0 };
174 gst_real_pad_get_type (void)
176 if (!_gst_real_pad_type) {
177 static const GTypeInfo pad_info = {
178 sizeof (GstRealPadClass), NULL, NULL,
179 (GClassInitFunc) gst_real_pad_class_init, NULL, NULL,
182 (GInstanceInitFunc) gst_real_pad_init, NULL
185 _gst_real_pad_type = g_type_register_static (GST_TYPE_PAD, "GstRealPad",
188 return _gst_real_pad_type;
192 gst_real_pad_class_init (GstRealPadClass * klass)
194 GObjectClass *gobject_class;
195 GstObjectClass *gstobject_class;
197 gobject_class = (GObjectClass *) klass;
198 gstobject_class = (GstObjectClass *) klass;
200 real_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
202 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_real_pad_dispose);
203 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_real_pad_set_property);
204 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_real_pad_get_property);
206 gst_real_pad_signals[REAL_LINKED] =
207 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
208 G_STRUCT_OFFSET (GstRealPadClass, linked), NULL, NULL,
209 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
210 gst_real_pad_signals[REAL_UNLINKED] =
211 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
212 G_STRUCT_OFFSET (GstRealPadClass, unlinked), NULL, NULL,
213 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
214 gst_real_pad_signals[REAL_FIXATE] =
215 g_signal_new ("fixate", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
216 G_STRUCT_OFFSET (GstRealPadClass, appfixatefunc),
217 _gst_real_pad_fixate_accumulator, NULL,
218 gst_marshal_BOXED__BOXED, GST_TYPE_CAPS, 1,
219 GST_TYPE_CAPS | G_SIGNAL_TYPE_STATIC_SCOPE);
221 /* gtk_object_add_arg_type ("GstRealPad::active", G_TYPE_BOOLEAN, */
222 /* GTK_ARG_READWRITE, REAL_ARG_ACTIVE); */
223 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_ACTIVE,
224 g_param_spec_boolean ("active", "Active", "Whether the pad is active.",
225 TRUE, G_PARAM_READWRITE));
226 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_CAPS,
227 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
228 GST_TYPE_CAPS, G_PARAM_READABLE));
230 #ifndef GST_DISABLE_LOADSAVE
231 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
233 gstobject_class->path_string_separator = ".";
237 _gst_real_pad_fixate_accumulator (GSignalInvocationHint * ihint,
238 GValue * return_accu, const GValue * handler_return, gpointer dummy)
240 if (gst_value_get_caps (handler_return)) {
241 g_value_copy (handler_return, return_accu);
242 /* stop emission if something was returned */
249 gst_real_pad_init (GstRealPad * pad)
251 pad->direction = GST_PAD_UNKNOWN;
254 pad->chainfunc = NULL;
257 pad->chainhandler = NULL;
258 pad->gethandler = NULL;
260 pad->ghostpads = NULL;
263 pad->linkfunc = NULL;
264 pad->getcapsfunc = NULL;
266 pad->eventfunc = gst_pad_event_default;
267 pad->convertfunc = gst_pad_convert_default;
268 pad->queryfunc = gst_pad_query_default;
269 pad->intlinkfunc = gst_pad_get_internal_links_default;
271 pad->eventmaskfunc = gst_pad_get_event_masks_default;
272 pad->formatsfunc = gst_pad_get_formats_default;
273 pad->querytypefunc = gst_pad_get_query_types_default;
275 GST_FLAG_SET (pad, GST_PAD_DISABLED);
276 GST_FLAG_UNSET (pad, GST_PAD_NEGOTIATING);
278 gst_probe_dispatcher_init (&pad->probedisp);
282 gst_real_pad_set_property (GObject * object, guint prop_id,
283 const GValue * value, GParamSpec * pspec)
285 g_return_if_fail (GST_IS_PAD (object));
288 case REAL_ARG_ACTIVE:
289 gst_pad_set_active (GST_PAD (object), g_value_get_boolean (value));
292 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
298 gst_real_pad_get_property (GObject * object, guint prop_id,
299 GValue * value, GParamSpec * pspec)
301 g_return_if_fail (GST_IS_PAD (object));
304 case REAL_ARG_ACTIVE:
305 g_value_set_boolean (value, !GST_FLAG_IS_SET (object, GST_PAD_DISABLED));
308 g_value_set_boxed (value, GST_PAD_CAPS (GST_REAL_PAD (object)));
311 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
316 /* FIXME-0.9: Replace these custom functions with proper inheritance via _init
317 functions and object properties */
319 * gst_pad_custom_new:
320 * @type: the #Gtype of the pad.
321 * @name: the name of the new pad.
322 * @direction: the #GstPadDirection of the pad.
324 * Creates a new pad with the given name and type in the given direction.
325 * If name is NULL, a guaranteed unique name (across all pads)
328 * Returns: a new #GstPad, or NULL in case of an error.
331 gst_pad_custom_new (GType type, const gchar * name, GstPadDirection direction)
335 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
337 pad = g_object_new (type, NULL);
338 gst_object_set_name (GST_OBJECT (pad), name);
339 GST_RPAD_DIRECTION (pad) = direction;
341 return GST_PAD (pad);
346 * @name: the name of the new pad.
347 * @direction: the #GstPadDirection of the pad.
349 * Creates a new real pad with the given name in the given direction.
350 * If name is NULL, a guaranteed unique name (across all pads)
353 * Returns: a new #GstPad, or NULL in case of an error.
356 gst_pad_new (const gchar * name, GstPadDirection direction)
358 return gst_pad_custom_new (gst_real_pad_get_type (), name, direction);
362 * gst_pad_custom_new_from_template:
363 * @type: the custom #GType of the pad.
364 * @templ: the #GstPadTemplate to instantiate from.
365 * @name: the name of the new pad.
367 * Creates a new custom pad with the given name from the given template.
368 * If name is NULL, a guaranteed unique name (across all pads)
371 * Returns: a new #GstPad, or NULL in case of an error.
374 gst_pad_custom_new_from_template (GType type, GstPadTemplate * templ,
379 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
381 pad = gst_pad_custom_new (type, name, templ->direction);
382 gst_pad_set_pad_template (pad, templ);
388 * gst_pad_new_from_template:
389 * @templ: the pad template to use
390 * @name: the name of the element
392 * Creates a new real pad with the given name from the given template.
393 * If name is NULL, a guaranteed unique name (across all pads)
396 * Returns: a new #GstPad, or NULL in case of an error.
399 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
401 return gst_pad_custom_new_from_template (gst_real_pad_get_type (),
405 /* FIXME 0.9: GST_PAD_UNKNOWN needs to die! */
407 * gst_pad_get_direction:
408 * @pad: a #GstPad to get the direction of.
410 * Gets the direction of the pad.
412 * Returns: the #GstPadDirection of the pad.
415 gst_pad_get_direction (GstPad * pad)
417 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
419 if (GST_IS_REAL_PAD (pad))
420 return GST_PAD_DIRECTION (pad);
422 return GST_PAD_UNKNOWN;
426 * gst_pad_set_active:
427 * @pad: the #GstPad to activate or deactivate.
428 * @active: TRUE to activate the pad.
430 * Activates or deactivates the given pad.
433 gst_pad_set_active (GstPad * pad, gboolean active)
439 g_return_if_fail (GST_IS_PAD (pad));
441 old = GST_PAD_IS_ACTIVE (pad);
446 realpad = GST_PAD_REALIZE (pad);
449 GST_CAT_DEBUG (GST_CAT_PADS, "activating pad %s:%s",
450 GST_DEBUG_PAD_NAME (realpad));
451 GST_FLAG_UNSET (realpad, GST_PAD_DISABLED);
453 GST_CAT_DEBUG (GST_CAT_PADS, "de-activating pad %s:%s",
454 GST_DEBUG_PAD_NAME (realpad));
455 GST_FLAG_SET (realpad, GST_PAD_DISABLED);
457 link = GST_RPAD_LINK (realpad);
459 if (link->temp_store) {
460 GST_CAT_INFO (GST_CAT_PADS,
461 "deleting cached buffer from bufpen of pad %s:%s",
462 GST_DEBUG_PAD_NAME (realpad));
463 gst_data_unref (link->temp_store);
464 link->temp_store = NULL;
468 g_object_notify (G_OBJECT (realpad), "active");
473 * @pad: the #GstPad to query
475 * Query if a pad is active
477 * Returns: TRUE if the pad is active.
480 gst_pad_is_active (GstPad * pad)
482 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
484 return !GST_FLAG_IS_SET (pad, GST_PAD_DISABLED);
489 * @pad: a #GstPad to set the name of.
490 * @name: the name of the pad.
492 * Sets the name of a pad. If name is NULL, then a guaranteed unique
493 * name will be assigned.
496 gst_pad_set_name (GstPad * pad, const gchar * name)
498 g_return_if_fail (GST_IS_PAD (pad));
500 gst_object_set_name (GST_OBJECT (pad), name);
503 /* FIXME 0.9: This function must die */
506 * @pad: a #GstPad to get the name of.
508 * Gets the name of a pad.
510 * Returns: the name of the pad. This is not a newly allocated pointer
511 * so you must not free it.
514 gst_pad_get_name (GstPad * pad)
516 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
518 return GST_OBJECT_NAME (pad);
522 * gst_pad_set_chain_function:
523 * @pad: a real sink #GstPad.
524 * @chain: the #GstPadChainFunction to set.
526 * Sets the given chain function for the pad. The chain function is called to
527 * process a #GstData input buffer.
530 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
532 g_return_if_fail (GST_IS_REAL_PAD (pad));
533 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SINK);
535 GST_RPAD_CHAINFUNC (pad) = chain;
536 GST_CAT_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
537 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
541 * gst_pad_set_get_function:
542 * @pad: a real source #GstPad.
543 * @get: the #GstPadGetFunction to set.
545 * Sets the given get function for the pad. The get function is called to
546 * produce a new #GstData to start the processing pipeline. Get functions cannot
550 gst_pad_set_get_function (GstPad * pad, GstPadGetFunction get)
552 g_return_if_fail (GST_IS_REAL_PAD (pad));
553 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SRC);
555 GST_RPAD_GETFUNC (pad) = get;
557 GST_CAT_DEBUG (GST_CAT_PADS, "getfunc for %s:%s set to %s",
558 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
562 * gst_pad_set_event_function:
563 * @pad: a real source #GstPad.
564 * @event: the #GstPadEventFunction to set.
566 * Sets the given event handler for the pad.
569 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
571 g_return_if_fail (GST_IS_REAL_PAD (pad));
572 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SRC);
574 GST_RPAD_EVENTFUNC (pad) = event;
576 GST_CAT_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
577 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
581 * gst_pad_set_event_mask_function:
582 * @pad: a real #GstPad of either direction.
583 * @mask_func: the #GstPadEventMaskFunction to set.
585 * Sets the given event mask function for the pad.
588 gst_pad_set_event_mask_function (GstPad * pad,
589 GstPadEventMaskFunction mask_func)
591 g_return_if_fail (GST_IS_REAL_PAD (pad));
593 GST_RPAD_EVENTMASKFUNC (pad) = mask_func;
595 GST_CAT_DEBUG (GST_CAT_PADS, "eventmaskfunc for %s:%s set to %s",
596 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (mask_func));
600 * gst_pad_get_event_masks:
603 * Gets the array of eventmasks from the given pad.
605 * Returns: a zero-terminated array of #GstEventMask, or NULL if the pad does
606 * not have an event mask function.
609 gst_pad_get_event_masks (GstPad * pad)
613 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
615 rpad = GST_PAD_REALIZE (pad);
617 g_return_val_if_fail (rpad, FALSE);
619 if (GST_RPAD_EVENTMASKFUNC (rpad))
620 return GST_RPAD_EVENTMASKFUNC (rpad) (GST_PAD (pad));
626 gst_pad_get_event_masks_dispatcher (GstPad * pad, const GstEventMask ** data)
628 *data = gst_pad_get_event_masks (pad);
634 * gst_pad_get_event_masks_default:
637 * Invokes the default event masks dispatcher on the pad.
639 * Returns: a zero-terminated array of #GstEventMask, or NULL if none of the
640 * internally-linked pads have an event mask function.
643 gst_pad_get_event_masks_default (GstPad * pad)
645 GstEventMask *result = NULL;
647 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
649 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
650 gst_pad_get_event_masks_dispatcher, &result);
656 * gst_pad_set_convert_function:
657 * @pad: a real #GstPad of either direction.
658 * @convert: the #GstPadConvertFunction to set.
660 * Sets the given convert function for the pad.
663 gst_pad_set_convert_function (GstPad * pad, GstPadConvertFunction convert)
665 g_return_if_fail (GST_IS_REAL_PAD (pad));
667 GST_RPAD_CONVERTFUNC (pad) = convert;
669 GST_CAT_DEBUG (GST_CAT_PADS, "convertfunc for %s:%s set to %s",
670 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (convert));
674 * gst_pad_set_query_function:
675 * @pad: a real #GstPad of either direction.
676 * @query: the #GstPadQueryFunction to set.
678 * Set the given query function for the pad.
681 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
683 g_return_if_fail (GST_IS_REAL_PAD (pad));
685 GST_RPAD_QUERYFUNC (pad) = query;
687 GST_CAT_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
688 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
692 * gst_pad_set_query_type_function:
693 * @pad: a real #GstPad of either direction.
694 * @type_func: the #GstPadQueryTypeFunction to set.
696 * Set the given query type function for the pad.
699 gst_pad_set_query_type_function (GstPad * pad,
700 GstPadQueryTypeFunction type_func)
702 g_return_if_fail (GST_IS_REAL_PAD (pad));
704 GST_RPAD_QUERYTYPEFUNC (pad) = type_func;
706 GST_CAT_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
707 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
711 * gst_pad_get_query_types:
714 * Get an array of supported queries that can be performed
717 * Returns: a zero-terminated array of #GstQueryType.
720 gst_pad_get_query_types (GstPad * pad)
724 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
726 rpad = GST_PAD_REALIZE (pad);
728 g_return_val_if_fail (rpad, NULL);
730 if (GST_RPAD_QUERYTYPEFUNC (rpad))
731 return GST_RPAD_QUERYTYPEFUNC (rpad) (GST_PAD (pad));
737 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
739 *data = gst_pad_get_query_types (pad);
745 * gst_pad_get_query_types_default:
748 * Invoke the default dispatcher for the query types on
751 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
752 * internally-linked pads has a query types function.
755 gst_pad_get_query_types_default (GstPad * pad)
757 GstQueryType *result = NULL;
759 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
761 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
762 gst_pad_get_query_types_dispatcher, &result);
768 * gst_pad_set_internal_link_function:
769 * @pad: a real #GstPad of either direction.
770 * @intlink: the #GstPadIntLinkFunction to set.
772 * Sets the given internal link function for the pad.
775 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
777 g_return_if_fail (GST_IS_REAL_PAD (pad));
779 GST_RPAD_INTLINKFUNC (pad) = intlink;
780 GST_CAT_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
781 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
785 * gst_pad_set_formats_function:
786 * @pad: a real #GstPad of either direction.
787 * @formats: the #GstPadFormatsFunction to set.
789 * Sets the given formats function for the pad.
792 gst_pad_set_formats_function (GstPad * pad, GstPadFormatsFunction formats)
794 g_return_if_fail (GST_IS_REAL_PAD (pad));
796 GST_RPAD_FORMATSFUNC (pad) = formats;
797 GST_CAT_DEBUG (GST_CAT_PADS, "formats function for %s:%s set to %s",
798 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (formats));
802 * gst_pad_set_link_function:
803 * @pad: a real #GstPad.
804 * @link: the #GstPadLinkFunction to set.
806 * Sets the given link function for the pad. It will be called when the pad is
807 * linked or relinked with caps. The caps passed to the link function are
808 * guaranteed to be fixed. This means that you can assume that the caps is not
809 * ANY or EMPTY, and that there is exactly one structure in the caps, and that
810 * all the fields in the structure are fixed.
812 * The return value GST_PAD_LINK_OK should be used when the caps are acceptable,
813 * and you've extracted all the necessary information from the caps and set the
814 * element's internal state appropriately.
816 * The return value GST_PAD_LINK_REFUSED should be used when the caps are
817 * unacceptable for whatever reason.
819 * The return value GST_PAD_LINK_DELAYED should be used when the element is in a
820 * state where it can't determine whether the caps are acceptable or not. This
821 * is often used if the element needs to open a device or process data before
822 * determining acceptable caps.
824 * @link must not call gst_caps_try_set_caps() on the pad that was specified as
825 * a parameter, although it may (and often should) call gst_caps_try_set_caps()
829 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
831 g_return_if_fail (GST_IS_REAL_PAD (pad));
833 GST_RPAD_LINKFUNC (pad) = link;
834 GST_CAT_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
835 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
839 * gst_pad_set_unlink_function:
840 * @pad: a real #GstPad.
841 * @unlink: the #GstPadUnlinkFunction to set.
843 * Sets the given unlink function for the pad. It will be called
844 * when the pad is unlinked.
847 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
849 g_return_if_fail (GST_IS_REAL_PAD (pad));
851 GST_RPAD_UNLINKFUNC (pad) = unlink;
852 GST_CAT_DEBUG (GST_CAT_PADS, "unlinkfunc for %s:%s set to %s",
853 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (unlink));
857 * gst_pad_set_fixate_function:
858 * @pad: a real #GstPad.
859 * @fixate: the #GstPadFixateFunction to set.
861 * Sets the given fixate function for the pad. Its job is to narrow down the
862 * possible caps for a connection. Fixate functions are called with a const
863 * caps, and should return a caps that is a strict subset of the given caps.
864 * That is, @fixate should create a caps that is "more fixed" than previously,
865 * but it does not have to return fixed caps. If @fixate can't provide more
866 * fixed caps, it should return %NULL.
868 * Note that @fixate will only be called after the "fixate" signal is emitted,
869 * and only if the caps are still non-fixed.
872 gst_pad_set_fixate_function (GstPad * pad, GstPadFixateFunction fixate)
874 g_return_if_fail (GST_IS_REAL_PAD (pad));
876 GST_RPAD_FIXATEFUNC (pad) = fixate;
877 GST_CAT_DEBUG (GST_CAT_PADS, "fixatefunc for %s:%s set to %s",
878 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (fixate));
882 * gst_pad_set_getcaps_function:
883 * @pad: a real #GstPad.
884 * @getcaps: the #GstPadGetCapsFunction to set.
886 * Sets the given getcaps function for the pad. @getcaps should return the
887 * allowable caps for a pad in the context of the element's state, its link to
888 * other elements, and the devices or files it has opened. These caps must be a
889 * subset of the pad template caps. In the NULL state with no links, @getcaps
890 * should ideally return the same caps as the pad template. In rare
891 * circumstances, an object property can affect the caps returned by @getcaps,
892 * but this is discouraged.
894 * You do not need to call this function if @pad's allowed caps are always the
895 * same as the pad template caps.
897 * For most filters, the caps returned by @getcaps is directly affected by the
898 * allowed caps on other pads. For demuxers and decoders, the caps returned by
899 * the srcpad's getcaps function is directly related to the stream data. Again,
900 * @getcaps should return the most specific caps it reasonably can, since this
901 * helps with autoplugging. However, the returned caps should not depend on the
902 * stream type currently negotiated for @pad.
904 * Note that the return value from @getcaps is owned by the caller.
907 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
909 g_return_if_fail (GST_IS_REAL_PAD (pad));
911 GST_RPAD_GETCAPSFUNC (pad) = getcaps;
912 GST_CAT_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
913 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
917 * gst_pad_set_bufferalloc_function:
918 * @pad: a real sink #GstPad.
919 * @bufalloc: the #GstPadBufferAllocFunction to set.
921 * Sets the given bufferalloc function for the pad. Note that the
922 * bufferalloc function can only be set on sinkpads.
925 gst_pad_set_bufferalloc_function (GstPad * pad,
926 GstPadBufferAllocFunction bufalloc)
928 g_return_if_fail (GST_IS_REAL_PAD (pad));
929 g_return_if_fail (GST_PAD_IS_SINK (pad));
931 GST_RPAD_BUFFERALLOCFUNC (pad) = bufalloc;
932 GST_CAT_DEBUG (GST_CAT_PADS, "bufferallocfunc for %s:%s set to %s",
933 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufalloc));
936 /* FIXME 0.9: Do we actually want to allow the case where src and sink are
940 * @srcpad: the source #GstPad to unlink.
941 * @sinkpad: the sink #GstPad to unlink.
943 * Unlinks the source pad from the sink pad. Will emit the "unlinked" signal on
947 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
949 GstRealPad *realsrc, *realsink;
950 GstScheduler *src_sched, *sink_sched;
952 g_return_if_fail (GST_IS_PAD (srcpad));
953 g_return_if_fail (GST_IS_PAD (sinkpad));
955 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
956 GST_DEBUG_PAD_NAME (srcpad), srcpad,
957 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
959 realsrc = GST_PAD_REALIZE (srcpad);
960 realsink = GST_PAD_REALIZE (sinkpad);
962 g_return_if_fail (GST_RPAD_PEER (realsrc) != NULL);
963 g_return_if_fail (GST_RPAD_PEER (realsink) == realsrc);
965 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
966 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
973 g_return_if_fail ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
974 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK));
976 if (GST_RPAD_UNLINKFUNC (realsrc)) {
977 GST_RPAD_UNLINKFUNC (realsrc) (GST_PAD (realsrc));
979 if (GST_RPAD_UNLINKFUNC (realsink)) {
980 GST_RPAD_UNLINKFUNC (realsink) (GST_PAD (realsink));
983 /* get the schedulers before we unlink */
984 src_sched = gst_pad_get_scheduler (GST_PAD (realsrc));
985 sink_sched = gst_pad_get_scheduler (GST_PAD (realsink));
987 if (GST_RPAD_LINK (realsrc))
988 gst_pad_link_free (GST_RPAD_LINK (realsrc));
990 /* first clear peers */
991 GST_RPAD_PEER (realsrc) = NULL;
992 GST_RPAD_PEER (realsink) = NULL;
993 GST_RPAD_LINK (realsrc) = NULL;
994 GST_RPAD_LINK (realsink) = NULL;
996 /* now tell the scheduler */
997 if (src_sched && src_sched == sink_sched) {
998 gst_scheduler_pad_unlink (src_sched, GST_PAD (realsrc), GST_PAD (realsink));
1001 /* hold a reference, as they can go away in the signal handlers */
1002 gst_object_ref (GST_OBJECT (realsrc));
1003 gst_object_ref (GST_OBJECT (realsink));
1005 /* fire off a signal to each of the pads telling them
1006 * that they've been unlinked */
1007 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_UNLINKED],
1009 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_UNLINKED],
1012 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1013 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1015 gst_object_unref (GST_OBJECT (realsrc));
1016 gst_object_unref (GST_OBJECT (realsink));
1020 * gst_pad_is_linked:
1021 * @pad: pad to check
1023 * Checks if a @pad is linked to another pad or not.
1025 * Returns: TRUE if the pad is linked, FALSE otherwise.
1028 gst_pad_is_linked (GstPad * pad)
1030 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1032 return GST_PAD_PEER (pad) != NULL;
1036 gst_pad_check_schedulers (GstRealPad * realsrc, GstRealPad * realsink)
1038 GstScheduler *src_sched, *sink_sched;
1039 gint num_decoupled = 0;
1041 src_sched = gst_pad_get_scheduler (GST_PAD (realsrc));
1042 sink_sched = gst_pad_get_scheduler (GST_PAD (realsink));
1044 if (src_sched && sink_sched) {
1045 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsrc), GST_ELEMENT_DECOUPLED))
1047 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsink), GST_ELEMENT_DECOUPLED))
1050 if (src_sched != sink_sched && num_decoupled != 1) {
1057 #define GST_PAD_LINK_SRC(pad) ((GST_PAD_IS_SRC (pad)) ? (pad) : GST_PAD_PEER (pad))
1058 #define GST_PAD_LINK_SINK(pad) ((GST_PAD_IS_SINK (pad)) ? (pad) : GST_PAD_PEER (pad))
1061 gst_pad_link_new (void)
1065 link = g_new0 (GstPadLink, 1);
1066 link->sinknotify = TRUE;
1067 link->srcnotify = TRUE;
1069 link->engaged = FALSE;
1074 gst_pad_link_free (GstPadLink * link)
1077 gst_caps_free (link->srccaps);
1079 gst_caps_free (link->sinkcaps);
1080 if (link->filtercaps)
1081 gst_caps_free (link->filtercaps);
1083 gst_caps_free (link->caps);
1084 if (link->temp_store)
1085 gst_data_unref (link->temp_store);
1086 #ifdef USE_POISONING
1087 memset (link, 0xff, sizeof (*link));
1093 gst_pad_link_intersect (GstPadLink * link)
1095 GstCaps *pad_intersection;
1098 gst_caps_free (link->caps);
1100 GST_DEBUG ("intersecting link from %s:%s to %s:%s",
1101 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1102 GST_DEBUG ("... srccaps %" GST_PTR_FORMAT, link->srccaps);
1103 GST_DEBUG ("... sinkcaps %" GST_PTR_FORMAT, link->sinkcaps);
1104 GST_DEBUG ("... filtercaps %" GST_PTR_FORMAT, link->filtercaps);
1106 pad_intersection = gst_caps_intersect (link->srccaps, link->sinkcaps);
1108 if (link->filtercaps) {
1109 GST_DEBUG ("unfiltered intersection %" GST_PTR_FORMAT, pad_intersection);
1110 link->caps = gst_caps_intersect (pad_intersection, link->filtercaps);
1111 gst_caps_free (pad_intersection);
1113 link->caps = pad_intersection;
1116 GST_DEBUG ("intersection %" GST_PTR_FORMAT, link->caps);
1120 gst_pad_link_ready_for_negotiation (GstPadLink * link)
1124 parent = GST_PAD_PARENT (link->srcpad);
1125 if (!parent || GST_STATE (parent) < GST_STATE_READY) {
1126 GST_DEBUG ("parent %s of pad %s:%s is not READY",
1127 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (link->srcpad));
1130 parent = GST_PAD_PARENT (link->sinkpad);
1131 if (!parent || GST_STATE (parent) < GST_STATE_READY) {
1132 GST_DEBUG ("parent %s of pad %s:%s is not READY",
1133 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (link->sinkpad));
1141 gst_pad_link_fixate (GstPadLink * link)
1148 g_return_if_fail (caps != NULL);
1149 g_return_if_fail (!gst_caps_is_empty (caps));
1151 GST_DEBUG ("trying to fixate caps %" GST_PTR_FORMAT, caps);
1153 gst_caps_do_simplify (caps);
1154 while (!gst_caps_is_fixed (caps)) {
1157 for (i = 0; i < 5; i++) {
1161 g_signal_emit (G_OBJECT (link->srcpad),
1162 gst_real_pad_signals[REAL_FIXATE], 0, caps, &newcaps);
1163 GST_DEBUG ("app srcpad signal fixated to %" GST_PTR_FORMAT, newcaps);
1166 g_signal_emit (G_OBJECT (link->sinkpad),
1167 gst_real_pad_signals[REAL_FIXATE], 0, caps, &newcaps);
1168 GST_DEBUG ("app sinkpad signal fixated to %" GST_PTR_FORMAT, newcaps);
1171 if (GST_RPAD_FIXATEFUNC (link->srcpad)) {
1173 GST_RPAD_FIXATEFUNC (link->srcpad) (GST_PAD (link->srcpad),
1175 GST_DEBUG ("srcpad %s:%s fixated to %" GST_PTR_FORMAT,
1176 GST_DEBUG_PAD_NAME (link->srcpad), newcaps);
1178 GST_DEBUG ("srcpad %s:%s doesn't have a fixate function",
1179 GST_DEBUG_PAD_NAME (link->srcpad));
1183 if (GST_RPAD_FIXATEFUNC (link->sinkpad)) {
1185 GST_RPAD_FIXATEFUNC (link->sinkpad) (GST_PAD (link->sinkpad),
1187 GST_DEBUG ("sinkpad %s:%s fixated to %" GST_PTR_FORMAT,
1188 GST_DEBUG_PAD_NAME (link->sinkpad), newcaps);
1190 GST_DEBUG ("sinkpad %s:%s doesn't have a fixate function",
1191 GST_DEBUG_PAD_NAME (link->sinkpad));
1194 newcaps = _gst_pad_default_fixate_func (GST_PAD (link->srcpad), caps);
1195 GST_DEBUG ("core fixated to %" GST_PTR_FORMAT, newcaps);
1199 G_GNUC_UNUSED gboolean bad;
1201 gst_caps_do_simplify (newcaps);
1202 #ifndef G_DISABLE_CHECKS
1203 /* some mad checking for correctly working fixation functions */
1206 /* we trust the default fixation function unconditionally */
1208 } else if (gst_caps_is_any (caps)) {
1209 bad = gst_caps_is_any (newcaps);
1211 GstCaps *test = gst_caps_subtract (caps, newcaps);
1213 bad = gst_caps_is_empty (test);
1214 gst_caps_free (test);
1215 /* simplifying is ok, too */
1217 bad = (gst_caps_get_size (newcaps) >= gst_caps_get_size (caps));
1220 gchar *newcaps_str = gst_caps_to_string (newcaps);
1221 gchar *caps_str = gst_caps_to_string (caps);
1224 ("a fixation function did not fixate correctly, the returned caps %s are no true subset of %s.",
1225 newcaps_str, caps_str);
1226 g_free (newcaps_str);
1228 gst_caps_free (newcaps);
1232 gst_caps_free (caps);
1243 static GstPadLinkReturn
1244 gst_pad_link_call_link_functions (GstPadLink * link)
1246 gboolean negotiating;
1247 GstPadLinkReturn res;
1249 if (link->srcnotify && GST_RPAD_LINKFUNC (link->srcpad)) {
1250 GST_DEBUG ("calling link function on pad %s:%s",
1251 GST_DEBUG_PAD_NAME (link->srcpad));
1253 negotiating = GST_FLAG_IS_SET (link->srcpad, GST_PAD_NEGOTIATING);
1255 /* set the NEGOTIATING flag if not already done */
1257 GST_FLAG_SET (link->srcpad, GST_PAD_NEGOTIATING);
1259 /* call the link function */
1260 res = GST_RPAD_LINKFUNC (link->srcpad) (GST_PAD (link->srcpad), link->caps);
1262 /* unset again after negotiating only if we set it */
1264 GST_FLAG_UNSET (link->srcpad, GST_PAD_NEGOTIATING);
1266 GST_DEBUG ("got reply %d from link function on pad %s:%s",
1267 res, GST_DEBUG_PAD_NAME (link->srcpad));
1269 if (GST_PAD_LINK_FAILED (res)) {
1270 GST_CAT_INFO (GST_CAT_CAPS, "pad %s:%s doesn't accept caps",
1271 GST_DEBUG_PAD_NAME (link->srcpad));
1276 if (link->sinknotify && GST_RPAD_LINKFUNC (link->sinkpad)) {
1277 GST_DEBUG ("calling link function on pad %s:%s",
1278 GST_DEBUG_PAD_NAME (link->sinkpad));
1280 negotiating = GST_FLAG_IS_SET (link->sinkpad, GST_PAD_NEGOTIATING);
1282 /* set the NEGOTIATING flag if not already done */
1284 GST_FLAG_SET (link->sinkpad, GST_PAD_NEGOTIATING);
1286 /* call the link function */
1287 res = GST_RPAD_LINKFUNC (link->sinkpad) (GST_PAD (link->sinkpad),
1290 /* unset again after negotiating only if we set it */
1292 GST_FLAG_UNSET (link->sinkpad, GST_PAD_NEGOTIATING);
1294 GST_DEBUG ("got reply %d from link function on pad %s:%s",
1295 res, GST_DEBUG_PAD_NAME (link->sinkpad));
1297 if (GST_PAD_LINK_FAILED (res)) {
1298 GST_CAT_INFO (GST_CAT_CAPS, "pad %s:%s doesn't accept caps",
1299 GST_DEBUG_PAD_NAME (link->sinkpad));
1304 return GST_PAD_LINK_OK;
1307 static GstPadLinkReturn
1308 gst_pad_link_negotiate (GstPadLink * link)
1310 GST_DEBUG ("negotiating link from pad %s:%s to pad %s:%s",
1311 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1313 gst_pad_link_intersect (link);
1314 if (gst_caps_is_empty (link->caps))
1315 return GST_PAD_LINK_REFUSED;
1317 gst_pad_link_fixate (link);
1318 if (gst_caps_is_empty (link->caps))
1319 return GST_PAD_LINK_REFUSED;
1321 if (!gst_pad_link_ready_for_negotiation (link)) {
1322 return GST_PAD_LINK_DELAYED;
1324 GST_DEBUG ("trying to call link function on caps %" GST_PTR_FORMAT,
1327 return gst_pad_link_call_link_functions (link);
1332 * @link: link to try
1334 * Tries to (re)link the pads with the given link. The function takes ownership
1335 * of the supplied link. If the function returns FALSE and an old link existed,
1336 * that link can be assumed to work unchanged.
1338 * Returns: TRUE if the link succeeded, FALSE if not.
1341 gst_pad_link_try (GstPadLink * link)
1343 GstPad *srcpad, *sinkpad;
1344 GstPadLink *oldlink;
1345 GstPadLinkReturn ret;
1347 /* we use assertions here, because this function is static */
1349 srcpad = link->srcpad;
1351 sinkpad = link->sinkpad;
1353 oldlink = GST_RPAD_LINK (srcpad);
1354 g_assert (oldlink == GST_RPAD_LINK (sinkpad));
1356 GST_DEBUG ("negotiating given link");
1357 ret = gst_pad_link_negotiate (link);
1358 if (GST_PAD_LINK_FAILED (ret) && oldlink && oldlink->caps) {
1359 GST_DEBUG ("negotiating failed, but there was a valid old link");
1360 oldlink->srcnotify = link->srcnotify;
1361 oldlink->sinknotify = link->sinknotify;
1362 if (GST_PAD_LINK_FAILED (gst_pad_link_call_link_functions (oldlink))) {
1363 g_warning ("pads don't accept old caps. We assume they did though");
1366 if (ret == GST_PAD_LINK_REFUSED) {
1367 GST_DEBUG ("link refused, returning");
1368 gst_pad_link_free (link);
1371 if (ret == GST_PAD_LINK_DELAYED) {
1372 GST_DEBUG ("link delayed, replacing link caps and returning");
1373 gst_caps_replace (&link->caps, NULL);
1376 GST_RPAD_PEER (srcpad) = GST_REAL_PAD (link->sinkpad);
1377 GST_RPAD_PEER (sinkpad) = GST_REAL_PAD (link->srcpad);
1379 GST_DEBUG ("copying stuff from oldlink");
1380 link->temp_store = oldlink->temp_store;
1381 link->engaged = oldlink->engaged;
1382 oldlink->temp_store = NULL;
1383 gst_pad_link_free (oldlink);
1385 GST_RPAD_LINK (srcpad) = link;
1386 GST_RPAD_LINK (sinkpad) = link;
1387 if (ret == GST_PAD_LINK_OK) {
1388 GST_DEBUG ("notifying caps after successful link");
1389 g_object_notify (G_OBJECT (srcpad), "caps");
1390 g_object_notify (G_OBJECT (sinkpad), "caps");
1397 * gst_pad_renegotiate:
1400 * Initiate caps negotiation on @pad. @pad must be linked.
1402 * If @pad's parent is not at least in #GST_STATE_READY, returns
1403 * #GST_PAD_LINK_DELAYED.
1405 * Otherwise caps are retrieved from both @pad and its peer by calling their
1406 * getcaps functions. They are then intersected, returning #GST_PAD_LINK_FAIL if
1407 * there is no intersection.
1409 * The intersection is fixated if necessary, and then the link functions of @pad
1410 * and its peer are called.
1412 * Returns: The return value of @pad's link function (see
1413 * gst_pad_set_link_function()), or #GST_PAD_LINK_OK if there is no link
1416 * The macros GST_PAD_LINK_SUCCESSFUL() and GST_PAD_LINK_FAILED() should be used
1417 * when you just need success/failure information.
1420 gst_pad_renegotiate (GstPad * pad)
1424 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
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 link = gst_pad_link_new ();
1430 link->srcpad = GST_PAD_LINK_SRC (pad);
1431 link->sinkpad = GST_PAD_LINK_SINK (pad);
1433 if (!gst_pad_link_ready_for_negotiation (link)) {
1434 gst_pad_link_free (link);
1435 return GST_PAD_LINK_DELAYED;
1438 if (GST_REAL_PAD (pad)->link->filtercaps) {
1439 link->filtercaps = gst_caps_copy (GST_REAL_PAD (pad)->link->filtercaps);
1441 link->srccaps = gst_pad_get_caps (link->srcpad);
1442 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1444 return gst_pad_link_try (link);
1448 * gst_pad_try_set_caps:
1450 * @caps: #GstCaps to set on @pad
1452 * Try to set the caps on @pad. @caps must be fixed. If @pad is unlinked,
1453 * returns #GST_PAD_LINK_OK without doing anything. Otherwise, start caps
1454 * negotiation on @pad.
1456 * Returns: The return value of @pad's link function (see
1457 * gst_pad_set_link_function()), or #GST_PAD_LINK_OK if there is no link
1460 * The macros GST_PAD_LINK_SUCCESSFUL() and GST_PAD_LINK_FAILED() should be used
1461 * when you just need success/failure information.
1464 gst_pad_try_set_caps (GstPad * pad, const GstCaps * caps)
1467 GstPadLink *oldlink;
1468 GstPadLinkReturn ret;
1470 g_return_val_if_fail (GST_IS_REAL_PAD (pad), GST_PAD_LINK_REFUSED);
1471 g_return_val_if_fail (!GST_PAD_IS_NEGOTIATING (pad), GST_PAD_LINK_REFUSED);
1473 /* setting non-fixed caps on a pad is not allowed */
1474 if (!gst_caps_is_fixed (caps)) {
1475 GST_CAT_INFO (GST_CAT_CAPS,
1476 "trying to set unfixed caps on pad %s:%s, not allowed",
1477 GST_DEBUG_PAD_NAME (pad));
1478 g_warning ("trying to set non fixed caps on pad %s:%s, not allowed",
1479 GST_DEBUG_PAD_NAME (pad));
1481 GST_DEBUG ("unfixed caps %" GST_PTR_FORMAT, caps);
1482 return GST_PAD_LINK_REFUSED;
1485 /* we allow setting caps on non-linked pads. It's ignored */
1486 if (!GST_PAD_PEER (pad)) {
1487 GST_DEBUG ("unlinked pad %s:%s, returning OK", GST_DEBUG_PAD_NAME (pad));
1488 return GST_PAD_LINK_OK;
1491 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1492 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1494 /* if the desired caps are already there, it's trivially ok */
1495 if (GST_PAD_CAPS (pad) && gst_caps_is_equal (caps, GST_PAD_CAPS (pad))) {
1496 GST_DEBUG ("pad %s:%s already has these caps", GST_DEBUG_PAD_NAME (pad));
1497 return GST_PAD_LINK_OK;
1500 link = gst_pad_link_new ();
1502 link->srcpad = GST_PAD_LINK_SRC (pad);
1503 link->sinkpad = GST_PAD_LINK_SINK (pad);
1505 if (!gst_pad_link_ready_for_negotiation (link)) {
1506 GST_DEBUG ("link not ready for negotiating, delaying");
1507 gst_pad_link_free (link);
1508 return GST_PAD_LINK_DELAYED;
1511 oldlink = GST_REAL_PAD (pad)->link;
1512 if (oldlink && oldlink->filtercaps) {
1513 link->filtercaps = gst_caps_copy (oldlink->filtercaps);
1515 if (link->srcpad == pad) {
1516 link->srccaps = gst_caps_copy (caps);
1517 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1518 link->srcnotify = FALSE;
1520 link->srccaps = gst_pad_get_caps (link->srcpad);
1521 link->sinkcaps = gst_caps_copy (caps);
1522 link->sinknotify = FALSE;
1525 GST_DEBUG ("trying to link");
1526 ret = gst_pad_link_try (link);
1532 * gst_pad_try_set_caps_nonfixed:
1533 * @pad: a real #GstPad
1534 * @caps: #GstCaps to set on @pad
1536 * Like gst_pad_try_set_caps(), but allows non-fixed caps.
1538 * Returns: a #GstPadLinkReturn, like gst_pad_try_set_caps().
1541 gst_pad_try_set_caps_nonfixed (GstPad * pad, const GstCaps * caps)
1544 GstPadLink *oldlink;
1545 GstPadLinkReturn ret;
1547 g_return_val_if_fail (GST_IS_REAL_PAD (pad), GST_PAD_LINK_REFUSED);
1548 g_return_val_if_fail (!GST_PAD_IS_NEGOTIATING (pad), GST_PAD_LINK_REFUSED);
1550 /* we allow setting caps on non-linked pads. It's ignored */
1551 if (!GST_PAD_PEER (pad)) {
1552 return GST_PAD_LINK_OK;
1555 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1556 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1558 /* if the link is already negotiated and the caps are compatible
1559 * with what we're setting, it's trivially OK. */
1560 if (GST_PAD_CAPS (pad)) {
1561 GstCaps *intersection;
1563 intersection = gst_caps_intersect (caps, GST_PAD_CAPS (pad));
1564 if (!gst_caps_is_empty (intersection)) {
1565 gst_caps_free (intersection);
1566 return GST_PAD_LINK_OK;
1568 gst_caps_free (intersection);
1571 link = gst_pad_link_new ();
1573 link->srcpad = GST_PAD_LINK_SRC (pad);
1574 link->sinkpad = GST_PAD_LINK_SINK (pad);
1576 if (!gst_pad_link_ready_for_negotiation (link)) {
1577 gst_pad_link_free (link);
1578 return GST_PAD_LINK_DELAYED;
1581 oldlink = GST_REAL_PAD (pad)->link;
1582 if (oldlink && oldlink->filtercaps) {
1583 link->filtercaps = gst_caps_copy (oldlink->filtercaps);
1585 if (link->srcpad == pad) {
1586 link->srccaps = gst_caps_copy (caps);
1587 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1588 link->srcnotify = FALSE;
1590 link->srccaps = gst_pad_get_caps (link->srcpad);
1591 link->sinkcaps = gst_caps_copy (caps);
1592 link->sinknotify = FALSE;
1595 ret = gst_pad_link_try (link);
1601 * gst_pad_can_link_filtered:
1602 * @srcpad: the source #GstPad to link.
1603 * @sinkpad: the sink #GstPad to link.
1604 * @filtercaps: the filter #GstCaps.
1606 * Checks if the source pad and the sink pad can be linked when constrained
1607 * by the given filter caps. Both @srcpad and @sinkpad must be unlinked.
1609 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1612 gst_pad_can_link_filtered (GstPad * srcpad, GstPad * sinkpad,
1613 const GstCaps * filtercaps)
1615 GstRealPad *realsrc, *realsink;
1618 /* FIXME This function is gross. It's almost a direct copy of
1619 * gst_pad_link_filtered(). Any decent programmer would attempt
1620 * to merge the two functions, which I will do some day. --ds
1623 /* generic checks */
1624 g_return_val_if_fail (srcpad != NULL, FALSE);
1625 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1626 g_return_val_if_fail (sinkpad != NULL, FALSE);
1627 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1629 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1630 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1632 /* now we need to deal with the real/ghost stuff */
1633 realsrc = GST_PAD_REALIZE (srcpad);
1634 realsink = GST_PAD_REALIZE (sinkpad);
1636 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1637 GST_CAT_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
1638 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1640 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1641 if (GST_RPAD_PEER (realsrc) != NULL) {
1642 GST_CAT_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1643 GST_DEBUG_PAD_NAME (realsrc));
1646 if (GST_RPAD_PEER (realsink) != NULL) {
1647 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1648 GST_DEBUG_PAD_NAME (realsink));
1651 if (GST_PAD_PARENT (realsrc) == NULL) {
1652 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1653 GST_DEBUG_PAD_NAME (realsrc));
1656 if (GST_PAD_PARENT (realsink) == NULL) {
1657 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has no parent, failed",
1658 GST_DEBUG_PAD_NAME (realsrc));
1662 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1663 g_warning ("linking pads with different scheds requires "
1664 "exactly one decoupled element (such as queue)");
1668 g_return_val_if_fail (realsrc != NULL, GST_PAD_LINK_REFUSED);
1669 g_return_val_if_fail (realsink != NULL, GST_PAD_LINK_REFUSED);
1671 link = gst_pad_link_new ();
1673 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
1674 link->srcpad = GST_PAD (realsrc);
1675 link->sinkpad = GST_PAD (realsink);
1677 link->srcpad = GST_PAD (realsink);
1678 link->sinkpad = GST_PAD (realsrc);
1681 if (GST_RPAD_DIRECTION (link->srcpad) != GST_PAD_SRC) {
1682 GST_CAT_INFO (GST_CAT_PADS,
1683 "Real src pad %s:%s is not a source pad, failed",
1684 GST_DEBUG_PAD_NAME (link->srcpad));
1685 gst_pad_link_free (link);
1688 if (GST_RPAD_DIRECTION (link->sinkpad) != GST_PAD_SINK) {
1689 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1690 GST_DEBUG_PAD_NAME (link->sinkpad));
1691 gst_pad_link_free (link);
1695 link->srccaps = gst_pad_get_caps (link->srcpad);
1696 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1698 link->filtercaps = gst_caps_copy (filtercaps);
1700 gst_pad_link_intersect (link);
1701 if (gst_caps_is_empty (link->caps)) {
1702 gst_pad_link_free (link);
1706 gst_pad_link_free (link);
1712 * @srcpad: the source #GstPad to link.
1713 * @sinkpad: the sink #GstPad to link.
1715 * Checks if the source pad and the sink pad can be linked.
1717 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1720 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1722 return gst_pad_can_link_filtered (srcpad, sinkpad, NULL);
1726 * gst_pad_link_filtered:
1727 * @srcpad: the source #GstPad to link.
1728 * @sinkpad: the sink #GstPad to link.
1729 * @filtercaps: the filter #GstCaps.
1731 * Links the source pad and the sink pad, constrained
1732 * by the given filter caps.
1734 * Returns: TRUE if the pads have been linked, FALSE otherwise.
1737 gst_pad_link_filtered (GstPad * srcpad, GstPad * sinkpad,
1738 const GstCaps * filtercaps)
1740 GstRealPad *realsrc, *realsink;
1741 GstScheduler *src_sched, *sink_sched;
1744 /* generic checks */
1745 g_return_val_if_fail (srcpad != NULL, FALSE);
1746 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1747 g_return_val_if_fail (sinkpad != NULL, FALSE);
1748 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1750 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1751 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1753 /* now we need to deal with the real/ghost stuff */
1754 realsrc = GST_PAD_REALIZE (srcpad);
1755 realsink = GST_PAD_REALIZE (sinkpad);
1757 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1758 GST_CAT_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
1759 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1761 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1762 if (GST_RPAD_PEER (realsrc) != NULL) {
1763 GST_CAT_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1764 GST_DEBUG_PAD_NAME (realsrc));
1767 if (GST_RPAD_PEER (realsink) != NULL) {
1768 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1769 GST_DEBUG_PAD_NAME (realsink));
1772 if (GST_PAD_PARENT (realsrc) == NULL) {
1773 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1774 GST_DEBUG_PAD_NAME (realsrc));
1777 if (GST_PAD_PARENT (realsink) == NULL) {
1778 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has no parent, failed",
1779 GST_DEBUG_PAD_NAME (realsrc));
1783 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1784 g_warning ("linking pads with different scheds requires "
1785 "exactly one decoupled element (such as queue)");
1789 g_return_val_if_fail (realsrc != NULL, GST_PAD_LINK_REFUSED);
1790 g_return_val_if_fail (realsink != NULL, GST_PAD_LINK_REFUSED);
1792 link = gst_pad_link_new ();
1794 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
1795 link->srcpad = GST_PAD (realsrc);
1796 link->sinkpad = GST_PAD (realsink);
1798 link->srcpad = GST_PAD (realsink);
1799 link->sinkpad = GST_PAD (realsrc);
1802 if (GST_RPAD_DIRECTION (link->srcpad) != GST_PAD_SRC) {
1803 GST_CAT_INFO (GST_CAT_PADS,
1804 "Real src pad %s:%s is not a source pad, failed",
1805 GST_DEBUG_PAD_NAME (link->srcpad));
1806 gst_pad_link_free (link);
1809 if (GST_RPAD_DIRECTION (link->sinkpad) != GST_PAD_SINK) {
1810 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1811 GST_DEBUG_PAD_NAME (link->sinkpad));
1812 gst_pad_link_free (link);
1816 link->srccaps = gst_pad_get_caps (link->srcpad);
1817 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1819 link->filtercaps = gst_caps_copy (filtercaps);
1820 if (gst_pad_link_try (link) == GST_PAD_LINK_REFUSED)
1823 /* fire off a signal to each of the pads telling them
1824 * that they've been linked */
1825 g_signal_emit (G_OBJECT (link->srcpad), gst_real_pad_signals[REAL_LINKED],
1827 g_signal_emit (G_OBJECT (link->sinkpad), gst_real_pad_signals[REAL_LINKED],
1830 src_sched = gst_pad_get_scheduler (GST_PAD (link->srcpad));
1831 sink_sched = gst_pad_get_scheduler (GST_PAD (link->sinkpad));
1833 /* now tell the scheduler */
1834 if (src_sched && src_sched == sink_sched) {
1835 gst_scheduler_pad_link (src_sched,
1836 GST_PAD (link->srcpad), GST_PAD (link->sinkpad));
1838 GST_CAT_INFO (GST_CAT_PADS,
1839 "not telling link to scheduler %s:%s and %s:%s, %p %p",
1840 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad),
1841 src_sched, sink_sched);
1844 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1845 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1852 * @srcpad: the source #GstPad to link.
1853 * @sinkpad: the sink #GstPad to link.
1855 * Links the source pad to the sink pad.
1857 * Returns: TRUE if the pad could be linked, FALSE otherwise.
1860 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
1862 return gst_pad_link_filtered (srcpad, sinkpad, NULL);
1865 /* FIXME 0.9: Remove this */
1867 * gst_pad_set_parent:
1868 * @pad: a #GstPad to set the parent of.
1869 * @parent: the new parent #GstElement.
1871 * Sets the parent object of a pad. Deprecated, use gst_object_set_parent()
1875 gst_pad_set_parent (GstPad * pad, GstElement * parent)
1877 g_return_if_fail (GST_IS_PAD (pad));
1878 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
1879 g_return_if_fail (GST_IS_ELEMENT (parent));
1881 gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (parent));
1884 /* FIXME 0.9: Remove this */
1886 * gst_pad_get_parent:
1887 * @pad: the #GstPad to get the parent of.
1889 * Gets the parent object of this pad. Deprecated, use gst_object_get_parent()
1892 * Returns: the parent #GstElement.
1895 gst_pad_get_parent (GstPad * pad)
1897 g_return_val_if_fail (pad != NULL, NULL);
1898 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1900 return GST_PAD_PARENT (pad);
1904 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
1906 /* this function would need checks if it weren't static */
1908 gst_object_replace ((GstObject **) & pad->padtemplate, (GstObject *) templ);
1911 gst_object_sink (GST_OBJECT (templ));
1912 g_signal_emit (G_OBJECT (templ),
1913 gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
1918 * gst_pad_get_pad_template:
1921 * Gets the template for @pad.
1923 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
1924 * if this pad has no template.
1927 gst_pad_get_pad_template (GstPad * pad)
1929 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1931 return GST_PAD_PAD_TEMPLATE (pad);
1936 * gst_pad_get_scheduler:
1937 * @pad: a #GstPad to get the scheduler of.
1939 * Gets the scheduler of the pad. Since the pad does not
1940 * have a scheduler of its own, the scheduler of the parent
1941 * is taken. For decoupled pads, the scheduler of the peer
1944 * Returns: the #GstScheduler of the pad, or %NULL if there is no parent or the
1945 * parent is not yet in a managing bin.
1948 gst_pad_get_scheduler (GstPad * pad)
1950 GstScheduler *scheduler = NULL;
1953 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1955 parent = gst_pad_get_parent (pad);
1957 if (GST_FLAG_IS_SET (parent, GST_ELEMENT_DECOUPLED)) {
1958 GstRealPad *peer = GST_RPAD_PEER (pad);
1962 gst_element_get_scheduler (gst_pad_get_parent (GST_PAD (peer)));
1965 scheduler = gst_element_get_scheduler (parent);
1973 * gst_pad_get_real_parent:
1974 * @pad: a #GstPad to get the real parent of.
1976 * Gets the real parent object of this pad. If the pad
1977 * is a ghost pad, the actual owner of the real pad is
1978 * returned, as opposed to #gst_pad_get_parent().
1980 * Returns: the parent #GstElement.
1983 gst_pad_get_real_parent (GstPad * pad)
1985 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1987 return GST_PAD_PARENT (GST_PAD (GST_PAD_REALIZE (pad)));
1990 /* FIXME 0.9: Make static. */
1992 * gst_pad_add_ghost_pad:
1993 * @pad: a #GstPad to attach the ghost pad to.
1994 * @ghostpad: the ghost #GstPad to to the pad.
1996 * Adds a ghost pad to a pad. Private function, will be removed from the API in
2000 gst_pad_add_ghost_pad (GstPad * pad, GstPad * ghostpad)
2002 GstRealPad *realpad;
2004 g_return_if_fail (GST_IS_PAD (pad));
2005 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
2007 /* if we're ghosting a ghost pad, drill down to find the real pad */
2008 realpad = (GstRealPad *) pad;
2009 while (GST_IS_GHOST_PAD (realpad))
2010 realpad = GST_GPAD_REALPAD (realpad);
2011 g_return_if_fail (GST_IS_REAL_PAD (realpad));
2013 /* will ref the pad template */
2014 GST_GPAD_REALPAD (ghostpad) = realpad;
2015 realpad->ghostpads = g_list_prepend (realpad->ghostpads, ghostpad);
2016 gst_pad_set_pad_template (GST_PAD (ghostpad), GST_PAD_PAD_TEMPLATE (pad));
2019 /* FIXME 0.9: Make static. */
2021 * gst_pad_remove_ghost_pad:
2022 * @pad: a #GstPad to remove the ghost pad from.
2023 * @ghostpad: the ghost #GstPad to remove from the pad.
2025 * Removes a ghost pad from a pad. Private, will be removed from the API in 0.9.
2028 gst_pad_remove_ghost_pad (GstPad * pad, GstPad * ghostpad)
2030 GstRealPad *realpad;
2032 g_return_if_fail (GST_IS_PAD (pad));
2033 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
2034 realpad = GST_PAD_REALIZE (pad);
2035 g_return_if_fail (GST_GPAD_REALPAD (ghostpad) == realpad);
2037 gst_pad_set_pad_template (GST_PAD (ghostpad), NULL);
2038 realpad->ghostpads = g_list_remove (realpad->ghostpads, ghostpad);
2039 GST_GPAD_REALPAD (ghostpad) = NULL;
2043 * gst_pad_get_ghost_pad_list:
2044 * @pad: a #GstPad to get the ghost pads of.
2046 * Gets the ghost pads of this pad.
2048 * Returns: a #GList of ghost pads.
2051 gst_pad_get_ghost_pad_list (GstPad * pad)
2053 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2055 return GST_PAD_REALIZE (pad)->ghostpads;
2059 _gst_pad_default_fixate_foreach (GQuark field_id, GValue * value, gpointer s)
2061 GstStructure *structure = (GstStructure *) s;
2062 GType type = G_VALUE_TYPE (value);
2064 if (gst_type_is_fixed (type))
2067 if (type == GST_TYPE_INT_RANGE) {
2068 gst_structure_set (structure, g_quark_to_string (field_id),
2069 G_TYPE_INT, gst_value_get_int_range_min (value), NULL);
2072 if (type == GST_TYPE_DOUBLE_RANGE) {
2073 gst_structure_set (structure, g_quark_to_string (field_id),
2074 G_TYPE_DOUBLE, gst_value_get_double_range_min (value), NULL);
2077 if (type == GST_TYPE_LIST) {
2078 gst_structure_set_value (structure, g_quark_to_string (field_id),
2079 gst_value_list_get_value (value, 0));
2083 g_critical ("don't know how to fixate type %s", g_type_name (type));
2088 _gst_pad_default_fixate_func (GstPad * pad, const GstCaps * caps)
2090 static GstStaticCaps octetcaps = GST_STATIC_CAPS ("application/octet-stream");
2091 GstStructure *structure;
2094 g_return_val_if_fail (pad != NULL, NULL);
2095 g_return_val_if_fail (caps != NULL, NULL);
2096 g_return_val_if_fail (!gst_caps_is_empty (caps), NULL);
2098 if (gst_caps_is_any (caps)) {
2099 return gst_caps_copy (gst_static_caps_get (&octetcaps));
2102 if (caps->structs->len > 1) {
2103 return gst_caps_new_full (gst_structure_copy (gst_caps_get_structure (caps,
2107 newcaps = gst_caps_copy (caps);
2108 structure = gst_caps_get_structure (newcaps, 0);
2109 gst_structure_foreach (structure, _gst_pad_default_fixate_foreach, structure);
2115 * gst_pad_perform_negotiate:
2116 * @srcpad: the source #GstPad.
2117 * @sinkpad: the sink #GstPad.
2119 * Tries to negotiate the pads. See gst_pad_renegotiate() for a brief
2120 * description of caps negotiation.
2122 * Returns: TRUE if the pads were succesfully negotiated, FALSE otherwise.
2125 gst_pad_perform_negotiate (GstPad * srcpad, GstPad * sinkpad)
2127 return GST_PAD_LINK_SUCCESSFUL (gst_pad_renegotiate (srcpad));
2131 gst_pad_link_unnegotiate (GstPadLink * link)
2133 g_return_if_fail (link != NULL);
2136 gst_caps_free (link->caps);
2138 link->engaged = FALSE;
2139 if (GST_RPAD_LINK (link->srcpad) != link) {
2140 g_warning ("unnegotiating unset link");
2142 g_object_notify (G_OBJECT (link->srcpad), "caps");
2144 if (GST_RPAD_LINK (link->sinkpad) != link) {
2145 g_warning ("unnegotiating unset link");
2147 g_object_notify (G_OBJECT (link->sinkpad), "caps");
2153 * gst_pad_unnegotiate:
2154 * @pad: pad to unnegotiate
2156 * "Unnegotiates" a pad. The currently negotiated caps are cleared and the pad
2157 * needs renegotiation.
2160 gst_pad_unnegotiate (GstPad * pad)
2164 g_return_if_fail (GST_IS_PAD (pad));
2166 link = GST_RPAD_LINK (GST_PAD_REALIZE (pad));
2168 gst_pad_link_unnegotiate (link);
2171 /* returning NULL indicates that the arguments are invalid */
2173 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad,
2174 const GstCaps * filtercaps)
2176 GstRealPad *realsrc, *realsink;
2179 g_return_val_if_fail (GST_IS_PAD (srcpad), NULL);
2180 g_return_val_if_fail (GST_IS_PAD (sinkpad), NULL);
2182 realsrc = GST_PAD_REALIZE (srcpad);
2183 realsink = GST_PAD_REALIZE (sinkpad);
2185 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
2186 GST_CAT_DEBUG (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
2187 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
2190 g_return_val_if_fail (GST_RPAD_PEER (realsrc) == NULL, NULL);
2191 g_return_val_if_fail (GST_RPAD_PEER (realsink) == NULL, NULL);
2192 g_return_val_if_fail (GST_PAD_PARENT (realsrc) != NULL, NULL);
2193 g_return_val_if_fail (GST_PAD_PARENT (realsink) != NULL, NULL);
2195 if (!gst_pad_check_schedulers (realsrc, realsink)) {
2196 g_warning ("linking pads with different scheds requires "
2197 "exactly one decoupled element (such as queue)");
2201 if (GST_RPAD_DIRECTION (realsrc) == GST_RPAD_DIRECTION (realsink)) {
2202 g_warning ("%s:%s and %s:%s are both %s pads, failed",
2203 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink),
2204 GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC ? "src" : "sink");
2208 link = gst_pad_link_new ();
2210 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
2211 link->srcpad = GST_PAD (realsrc);
2212 link->sinkpad = GST_PAD (realsink);
2214 link->srcpad = GST_PAD (realsink);
2215 link->sinkpad = GST_PAD (realsrc);
2218 link->srccaps = gst_pad_get_caps (link->srcpad);
2219 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
2221 link->filtercaps = gst_caps_copy (filtercaps);
2227 * gst_pad_try_relink_filtered:
2228 * @srcpad: the source #GstPad to relink.
2229 * @sinkpad: the sink #GstPad to relink.
2230 * @filtercaps: the #GstPad to use as a filter in the relink.
2232 * Tries to relink the given source and sink pad, constrained by the given
2235 * Returns: TRUE if the pads were succesfully renegotiated, FALSE otherwise.
2238 gst_pad_try_relink_filtered (GstPad * srcpad, GstPad * sinkpad,
2239 const GstCaps * filtercaps)
2243 GST_INFO ("trying to relink %" GST_PTR_FORMAT " and %" GST_PTR_FORMAT
2244 " with filtercaps %" GST_PTR_FORMAT, srcpad, sinkpad);
2246 link = gst_pad_link_prepare (srcpad, sinkpad, filtercaps);
2250 if (GST_RPAD_PEER (link->srcpad) != (GstRealPad *) link->sinkpad) {
2251 g_warning ("Pads %s:%s and %s:%s were never linked",
2252 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2253 gst_pad_link_free (link);
2257 if (GST_PAD_LINK_FAILED (gst_pad_link_try (link)))
2264 * gst_pad_relink_filtered:
2265 * @srcpad: the source #GstPad to relink.
2266 * @sinkpad: the sink #GstPad to relink.
2267 * @filtercaps: the #GstPad to use as a filter in the relink.
2269 * Relinks the given source and sink pad, constrained by the given
2270 * capabilities. If the relink fails, the pads are unlinked
2271 * and FALSE is returned.
2273 * Returns: TRUE if the pads were succesfully relinked, FALSE otherwise.
2276 gst_pad_relink_filtered (GstPad * srcpad, GstPad * sinkpad,
2277 const GstCaps * filtercaps)
2279 if (gst_pad_try_relink_filtered (srcpad, sinkpad, filtercaps))
2282 gst_pad_unlink (srcpad, sinkpad);
2287 * gst_pad_proxy_getcaps:
2288 * @pad: a #GstPad to proxy.
2290 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
2291 * same element as @pad, and returns the intersection of the results.
2293 * This function is useful as a default getcaps function for an element
2294 * that can handle any stream format, but requires all its pads to have
2295 * the same caps. Two such elements are tee and aggregator.
2297 * Returns: the intersection of the other pads' allowed caps.
2300 gst_pad_proxy_getcaps (GstPad * pad)
2302 GstElement *element;
2306 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2308 GST_DEBUG ("proxying getcaps for %s:%s", GST_DEBUG_PAD_NAME (pad));
2310 element = gst_pad_get_parent (pad);
2312 pads = gst_element_get_pad_list (element);
2314 caps = gst_caps_new_any ();
2316 GstPad *otherpad = GST_PAD (pads->data);
2319 if (otherpad != pad) {
2320 GstCaps *allowed = gst_pad_get_allowed_caps (otherpad);
2322 temp = gst_caps_intersect (caps, allowed);
2323 gst_caps_free (caps);
2324 gst_caps_free (allowed);
2328 pads = g_list_next (pads);
2335 * gst_pad_proxy_pad_link:
2336 * @pad: a #GstPad to proxy from
2337 * @caps: the #GstCaps to link with
2339 * Calls gst_pad_try_set_caps() for every other pad belonging to the
2340 * same element as @pad. If gst_pad_try_set_caps() fails on any pad,
2341 * the proxy link fails. May be used only during negotiation.
2343 * Returns: GST_PAD_LINK_OK if sucessful
2346 gst_pad_proxy_pad_link (GstPad * pad, const GstCaps * caps)
2348 GstElement *element;
2350 GstPadLinkReturn ret;
2352 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
2353 g_return_val_if_fail (caps != NULL, GST_PAD_LINK_REFUSED);
2355 GST_DEBUG ("proxying pad link for %s:%s", GST_DEBUG_PAD_NAME (pad));
2357 element = gst_pad_get_parent (pad);
2359 pads = gst_element_get_pad_list (element);
2362 GstPad *otherpad = GST_PAD (pads->data);
2364 if (otherpad != pad) {
2365 ret = gst_pad_try_set_caps (otherpad, caps);
2366 if (GST_PAD_LINK_FAILED (ret)) {
2370 pads = g_list_next (pads);
2373 return GST_PAD_LINK_OK;
2377 * gst_pad_proxy_fixate:
2378 * @pad: a #GstPad to proxy.
2379 * @caps: the #GstCaps to fixate
2381 * Implements a default fixate function based on the caps set on the other
2382 * pads in the element. This function should only be used if every pad
2383 * has the same pad template caps.
2385 * Returns: a fixated caps, or NULL if caps cannot be fixed
2388 gst_pad_proxy_fixate (GstPad * pad, const GstCaps * caps)
2390 GstElement *element;
2392 const GstCaps *othercaps;
2394 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2395 g_return_val_if_fail (caps != NULL, NULL);
2397 GST_DEBUG ("proxying fixate for %s:%s\n", GST_DEBUG_PAD_NAME (pad));
2399 element = gst_pad_get_parent (pad);
2401 pads = gst_element_get_pad_list (element);
2404 GstPad *otherpad = GST_PAD (pads->data);
2406 /* FIXME check that each pad has the same pad template caps */
2408 if (otherpad != pad) {
2409 othercaps = gst_pad_get_negotiated_caps (otherpad);
2411 if (othercaps && !gst_caps_is_subset (caps, othercaps)) {
2414 icaps = gst_caps_intersect (othercaps, caps);
2415 if (!gst_caps_is_empty (icaps)) {
2418 gst_caps_free (icaps);
2422 pads = g_list_next (pads);
2429 * gst_pad_set_explicit_caps:
2430 * @pad: a #GstPad to set the explicit caps of
2431 * @caps: the #GstCaps to set
2433 * If a pad has been told to use explicit caps, this function is used
2434 * to set the explicit caps. If @caps is NULL, the explicit caps are
2437 * This function calls gst_pad_try_set_caps() on the pad. If that
2438 * call fails, GST_ELEMENT_ERROR() is called to indicate a negotiation
2441 * Returns: TRUE if the caps were set correctly, otherwise FALSE
2444 gst_pad_set_explicit_caps (GstPad * pad, const GstCaps * caps)
2446 GstPadLinkReturn link_ret;
2448 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2450 GST_CAT_DEBUG (GST_CAT_PADS,
2451 "setting explicit caps on %s:%s to %" GST_PTR_FORMAT,
2452 GST_DEBUG_PAD_NAME (pad), caps);
2455 GST_CAT_DEBUG (GST_CAT_PADS, "caps is NULL");
2456 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2460 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), gst_caps_copy (caps));
2462 if (!GST_PAD_IS_LINKED (pad)) {
2463 GST_CAT_DEBUG (GST_CAT_PADS, "pad is not linked");
2466 link_ret = gst_pad_try_set_caps (pad, caps);
2467 if (link_ret == GST_PAD_LINK_REFUSED) {
2468 gchar *caps_str = gst_caps_to_string (caps);
2470 GST_ELEMENT_ERROR (gst_pad_get_parent (pad), CORE, PAD, (NULL),
2471 ("failed to negotiate (try_set_caps with \"%s\" returned REFUSED)",
2481 gst_pad_explicit_getcaps (GstPad * pad)
2483 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2485 if (GST_RPAD_EXPLICIT_CAPS (pad) == NULL) {
2486 const GstCaps *caps = gst_pad_get_pad_template_caps (pad);
2488 return gst_caps_copy (caps);
2490 return gst_caps_copy (GST_RPAD_EXPLICIT_CAPS (pad));
2493 static GstPadLinkReturn
2494 gst_pad_explicit_link (GstPad * pad, const GstCaps * caps)
2496 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
2497 g_return_val_if_fail (caps != NULL, GST_PAD_LINK_REFUSED);
2499 if (GST_RPAD_EXPLICIT_CAPS (pad) == NULL) {
2500 return GST_PAD_LINK_DELAYED;
2503 return GST_PAD_LINK_OK;
2507 * gst_pad_use_explicit_caps:
2508 * @pad: a #GstPad to set to use explicit caps
2510 * This function handles negotiation for pads that need to be set
2511 * to particular caps under complete control of the element, based
2512 * on some state in the element. This is often the case with
2513 * decoders and other elements whose caps is determined by the data
2516 * WARNING: This function is a hack and will be replaced with something
2517 * better in gstreamer-0.9.
2520 gst_pad_use_explicit_caps (GstPad * pad)
2522 g_return_if_fail (GST_IS_PAD (pad));
2524 gst_pad_set_getcaps_function (pad, gst_pad_explicit_getcaps);
2525 gst_pad_set_link_function (pad, gst_pad_explicit_link);
2526 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2530 * gst_pad_proxy_link:
2531 * @pad: a #GstPad to proxy to.
2532 * @caps: the #GstCaps to use in proxying.
2534 * Proxies the link function to the specified pad.
2536 * Returns: TRUE if the peer pad accepted the caps, FALSE otherwise.
2539 gst_pad_proxy_link (GstPad * pad, const GstCaps * caps)
2541 return gst_pad_try_set_caps (pad, caps);
2545 * gst_pad_is_negotiated:
2546 * @pad: a #GstPad to get the negotiation status of
2548 * Returns: TRUE if the pad has successfully negotiated caps.
2551 gst_pad_is_negotiated (GstPad * pad)
2553 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2555 if (!GST_PAD_REALIZE (pad))
2557 if (!GST_RPAD_LINK (pad))
2560 return (GST_RPAD_LINK (pad)->caps != NULL);
2564 * gst_pad_get_negotiated_caps:
2565 * @pad: a #GstPad to get the negotiated capabilites of
2567 * Gets the currently negotiated caps of a pad.
2569 * Returns: the currently negotiated caps of a pad, or NULL if the pad isn't
2572 G_CONST_RETURN GstCaps *
2573 gst_pad_get_negotiated_caps (GstPad * pad)
2575 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2577 if (!GST_PAD_REALIZE (pad))
2579 if (!GST_RPAD_LINK (pad))
2582 return GST_RPAD_LINK (pad)->caps;
2587 * @pad: a #GstPad to get the capabilities of.
2589 * Gets the capabilities of this pad.
2591 * Returns: the #GstCaps of this pad. This function returns a new caps, so use
2592 * gst_caps_free to get rid of it.
2595 gst_pad_get_caps (GstPad * pad)
2597 GstRealPad *realpad;
2599 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2601 realpad = GST_PAD_REALIZE (pad);
2603 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
2604 GST_DEBUG_PAD_NAME (realpad), realpad);
2606 if (GST_RPAD_GETCAPSFUNC (realpad)) {
2609 GST_CAT_DEBUG (GST_CAT_CAPS, "using pad getcaps function");
2610 caps = GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD (realpad));
2613 g_critical ("pad %s:%s returned NULL caps from getcaps function\n",
2614 GST_ELEMENT_NAME (GST_PAD_PARENT (GST_PAD (realpad))),
2615 GST_PAD_NAME (realpad));
2616 caps = gst_caps_new_any ();
2620 } else if (GST_PAD_PAD_TEMPLATE (realpad)) {
2621 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (realpad);
2622 const GstCaps *caps;
2624 caps = GST_PAD_TEMPLATE_CAPS (templ);
2625 GST_CAT_DEBUG (GST_CAT_CAPS,
2626 "using pad template %p with caps %" GST_PTR_FORMAT, templ, caps);
2629 /* FIXME we should enable something like this someday, but this is
2631 if (!gst_caps_is_fixed (caps)) {
2633 ("pad %s:%s (%p) has no getcaps function and the pad template returns non-fixed caps. Element is probably broken.\n",
2634 GST_DEBUG_PAD_NAME (realpad), realpad);
2638 return gst_caps_copy (GST_PAD_TEMPLATE_CAPS (templ));
2640 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
2644 g_warning ("pad %s:%s (%p) has no pad template\n",
2645 GST_DEBUG_PAD_NAME (realpad), realpad);
2648 return gst_caps_new_any ();
2652 * gst_pad_get_pad_template_caps:
2653 * @pad: a #GstPad to get the template capabilities from.
2655 * Gets the capabilities for @pad's template.
2657 * Returns: the #GstCaps of this pad template. If you intend to keep a reference
2658 * on the caps, make a copy (see gst_caps_copy ()).
2661 gst_pad_get_pad_template_caps (GstPad * pad)
2663 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2665 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2667 if (GST_PAD_PAD_TEMPLATE (pad))
2668 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2671 /* FIXME this should be enabled some day */
2672 /* wingo: why? mail the list during 0.9 when you find this :) */
2673 g_warning ("pad %s:%s (%p) has no pad template\n",
2674 GST_DEBUG_PAD_NAME (realpad), realpad);
2677 return gst_static_caps_get (&anycaps);
2680 /* FIXME 0.9: This function should probably die, or at least be renamed to
2681 * get_caps_by_format. */
2683 * gst_pad_template_get_caps_by_name:
2684 * @templ: a #GstPadTemplate to get the capabilities of.
2685 * @name: the name of the capability to get.
2687 * Gets the capability with the given name from @templ.
2689 * Returns: the #GstCaps of this pad template, or NULL if not found. If you
2690 * intend to keep a reference on the caps, make a copy (see gst_caps_copy ()).
2693 gst_pad_template_get_caps_by_name (GstPadTemplate * templ, const gchar * name)
2697 g_return_val_if_fail (templ != NULL, NULL);
2699 caps = GST_PAD_TEMPLATE_CAPS (templ);
2707 /* FIXME 0.9: What good is this if it only works for already-negotiated pads? */
2709 * gst_pad_check_compatibility:
2710 * @srcpad: the source #GstPad to check.
2711 * @sinkpad: the sink #GstPad to check against.
2713 * Checks if two pads have compatible capabilities. If neither one has yet been
2714 * negotiated, returns TRUE for no good reason.
2716 * Returns: TRUE if they are compatible or if the capabilities could not be
2717 * checked, FALSE if the capabilities are not compatible.
2720 gst_pad_check_compatibility (GstPad * srcpad, GstPad * sinkpad)
2722 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2723 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2725 if (GST_PAD_CAPS (srcpad) && GST_PAD_CAPS (sinkpad)) {
2726 if (!gst_caps_is_always_compatible (GST_PAD_CAPS (srcpad),
2727 GST_PAD_CAPS (sinkpad))) {
2733 GST_CAT_DEBUG (GST_CAT_PADS,
2734 "could not check capabilities of pads (%s:%s) and (%s:%s) %p %p",
2735 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2736 GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad));
2743 * @pad: a #GstPad to get the peer of.
2745 * Gets the peer of @pad.
2747 * Returns: the peer #GstPad.
2750 gst_pad_get_peer (GstPad * pad)
2752 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2754 return GST_PAD (GST_PAD_PEER (pad));
2758 * gst_pad_get_allowed_caps:
2759 * @pad: a real #GstPad.
2761 * Gets the capabilities of the allowed media types that can flow through @pad.
2762 * The caller must free the resulting caps.
2764 * Returns: the allowed #GstCaps of the pad link. Free the caps when
2765 * you no longer need it.
2768 gst_pad_get_allowed_caps (GstPad * pad)
2770 const GstCaps *mycaps;
2776 g_return_val_if_fail (GST_IS_REAL_PAD (pad), NULL);
2778 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting allowed caps",
2779 GST_DEBUG_PAD_NAME (pad));
2781 mycaps = gst_pad_get_pad_template_caps (pad);
2782 if (GST_RPAD_PEER (pad) == NULL) {
2783 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer, returning template",
2784 GST_DEBUG_PAD_NAME (pad));
2785 return gst_caps_copy (mycaps);
2788 peercaps = gst_pad_get_caps (GST_PAD_PEER (pad));
2789 caps = gst_caps_intersect (mycaps, peercaps);
2790 gst_caps_free (peercaps);
2792 link = GST_RPAD_LINK (pad);
2793 if (link->filtercaps) {
2794 icaps = gst_caps_intersect (caps, link->filtercaps);
2795 gst_caps_free (caps);
2796 GST_CAT_DEBUG (GST_CAT_PROPERTIES,
2797 "%s:%s: returning filtered intersection with peer",
2798 GST_DEBUG_PAD_NAME (pad));
2801 GST_CAT_DEBUG (GST_CAT_PROPERTIES,
2802 "%s:%s: returning unfiltered intersection with peer",
2803 GST_DEBUG_PAD_NAME (pad));
2809 * gst_pad_caps_change_notify:
2812 * Called to indicate that the return value of @pad's getcaps function may have
2813 * changed, and that a renegotiation is suggested.
2816 gst_pad_caps_change_notify (GstPad * pad)
2821 * gst_pad_recover_caps_error:
2822 * @pad: a #GstPad that had a failed capsnego
2823 * @allowed: possible caps for the link
2825 * Attempt to recover from a failed caps negotiation. This function
2826 * is typically called by a plugin that exhausted its list of caps
2827 * and wants the application to resolve the issue. The application
2828 * should connect to the pad's caps_nego_failed signal and should
2829 * resolve the issue by connecting another element for example.
2831 * Returns: TRUE when the issue was resolved, dumps detailed information
2832 * on the console and returns FALSE otherwise.
2835 gst_pad_recover_caps_error (GstPad * pad, const GstCaps * allowed)
2842 * gst_pad_alloc_buffer:
2843 * @pad: a source #GstPad
2844 * @offset: the offset of the new buffer in the stream
2845 * @size: the size of the new buffer
2847 * Allocates a new, empty buffer optimized to push to pad @pad. This
2848 * function only works if @pad is a source pad.
2850 * Returns: a new, empty #GstBuffer, or NULL if there is an error
2853 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size)
2857 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2858 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
2860 peer = GST_RPAD_PEER (pad);
2863 return gst_buffer_new_and_alloc (size);
2865 GST_CAT_DEBUG (GST_CAT_BUFFER, "(%s:%s): getting buffer",
2866 GST_DEBUG_PAD_NAME (pad));
2868 if (peer->bufferallocfunc) {
2869 GST_CAT_DEBUG (GST_CAT_PADS,
2870 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s",
2871 GST_DEBUG_FUNCPTR_NAME (peer->bufferallocfunc),
2872 &peer->bufferallocfunc, GST_DEBUG_PAD_NAME (((GstPad *) peer)));
2873 return (peer->bufferallocfunc) (GST_PAD (peer), offset, size);
2875 return gst_buffer_new_and_alloc (size);
2880 gst_real_pad_dispose (GObject * object)
2882 GstPad *pad = GST_PAD (object);
2884 /* No linked pad can ever be disposed.
2885 * It has to have a parent to be linked
2886 * and a parent would hold a reference */
2887 /* FIXME: what about if g_object_dispose is explicitly called on the pad? Is
2888 that legal? otherwise we could assert GST_OBJECT_PARENT (pad) == NULL as
2890 g_assert (GST_PAD_PEER (pad) == NULL);
2892 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s",
2893 GST_DEBUG_PAD_NAME (pad));
2895 /* we destroy the ghostpads, because they are nothing without the real pad */
2896 if (GST_REAL_PAD (pad)->ghostpads) {
2897 GList *orig, *ghostpads;
2899 orig = ghostpads = g_list_copy (GST_REAL_PAD (pad)->ghostpads);
2902 GstPad *ghostpad = GST_PAD (ghostpads->data);
2904 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))) {
2905 GstElement *parent = GST_ELEMENT (GST_OBJECT_PARENT (ghostpad));
2907 GST_CAT_DEBUG (GST_CAT_REFCOUNTING,
2908 "removing ghost pad from element '%s'", GST_OBJECT_NAME (parent));
2909 gst_element_remove_pad (parent, ghostpad);
2911 /* handle the case where we have some floating ghost pad that was never
2912 added to an element */
2913 g_object_set (ghostpad, "real-pad", NULL, NULL);
2915 ghostpads = g_list_next (ghostpads);
2918 /* as the ghost pads are removed, they remove themselves from ->ghostpads.
2919 So it should be empty now. Let's assert that. */
2920 g_assert (GST_REAL_PAD (pad)->ghostpads == NULL);
2923 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
2924 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
2925 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
2927 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
2930 if (GST_RPAD_EXPLICIT_CAPS (pad)) {
2931 GST_ERROR_OBJECT (pad, "still explicit caps %" GST_PTR_FORMAT " set",
2932 GST_RPAD_EXPLICIT_CAPS (pad));
2933 g_warning ("pad %p has still explicit caps set", pad);
2934 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2936 G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
2940 #ifndef GST_DISABLE_LOADSAVE
2941 /* FIXME: why isn't this on a GstElement ? */
2943 * gst_pad_load_and_link:
2944 * @self: an #xmlNodePtr to read the description from.
2945 * @parent: the #GstObject element that owns the pad.
2947 * Reads the pad definition from the XML node and links the given pad
2948 * in the element to a pad of an element up in the hierarchy.
2951 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
2953 xmlNodePtr field = self->xmlChildrenNode;
2954 GstPad *pad = NULL, *targetpad;
2958 GstObject *grandparent;
2961 if (!strcmp (field->name, "name")) {
2962 pad = gst_element_get_pad (GST_ELEMENT (parent),
2963 xmlNodeGetContent (field));
2964 } else if (!strcmp (field->name, "peer")) {
2965 peer = xmlNodeGetContent (field);
2967 field = field->next;
2969 g_return_if_fail (pad != NULL);
2974 split = g_strsplit (peer, ".", 2);
2976 if (split[0] == NULL || split[1] == NULL) {
2977 GST_CAT_DEBUG (GST_CAT_XML,
2978 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
2979 peer, GST_DEBUG_PAD_NAME (pad));
2983 g_return_if_fail (split[0] != NULL);
2984 g_return_if_fail (split[1] != NULL);
2986 grandparent = gst_object_get_parent (parent);
2988 if (grandparent && GST_IS_BIN (grandparent)) {
2989 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2996 targetpad = gst_element_get_pad (target, split[1]);
2998 if (targetpad == NULL)
3001 gst_pad_link (pad, targetpad);
3008 * gst_pad_save_thyself:
3009 * @pad: a #GstPad to save.
3010 * @parent: the parent #xmlNodePtr to save the description in.
3012 * Saves the pad into an xml representation.
3014 * Returns: the #xmlNodePtr representation of the pad.
3017 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
3019 GstRealPad *realpad;
3022 g_return_val_if_fail (GST_IS_REAL_PAD (object), NULL);
3024 realpad = GST_REAL_PAD (object);
3026 xmlNewChild (parent, NULL, "name", GST_PAD_NAME (realpad));
3027 if (GST_RPAD_PEER (realpad) != NULL) {
3030 peer = GST_PAD (GST_RPAD_PEER (realpad));
3031 /* first check to see if the peer's parent's parent is the same */
3032 /* we just save it off */
3033 content = g_strdup_printf ("%s.%s",
3034 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
3035 xmlNewChild (parent, NULL, "peer", content);
3038 xmlNewChild (parent, NULL, "peer", "");
3043 /* FIXME: shouldn't it be gst_pad_ghost_* ?
3044 * dunno -- wingo 7 feb 2004
3047 * gst_ghost_pad_save_thyself:
3048 * @pad: a ghost #GstPad to save.
3049 * @parent: the parent #xmlNodePtr to save the description in.
3051 * Saves the ghost pad into an xml representation.
3053 * Returns: the #xmlNodePtr representation of the pad.
3056 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
3060 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
3062 self = xmlNewChild (parent, NULL, "ghostpad", NULL);
3063 xmlNewChild (self, NULL, "name", GST_PAD_NAME (pad));
3064 xmlNewChild (self, NULL, "parent", GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
3066 /* FIXME FIXME FIXME! */
3070 #endif /* GST_DISABLE_LOADSAVE */
3073 _invent_event (GstPad * pad, GstBuffer * buffer)
3076 GstEventType event_type;
3079 if (GST_BUFFER_OFFSET_IS_VALID (buffer))
3080 event_type = GST_FORMAT_DEFAULT;
3082 event_type = GST_FORMAT_UNDEFINED;
3084 offset = GST_BUFFER_OFFSET (buffer);
3086 if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) {
3087 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
3089 event = gst_event_new_discontinuous (TRUE,
3090 GST_FORMAT_TIME, timestamp, event_type, offset, GST_FORMAT_UNDEFINED);
3091 GST_CAT_WARNING (GST_CAT_DATAFLOW,
3092 "needed to invent a DISCONT (time %" G_GUINT64_FORMAT
3093 ") for %s:%s => %s:%s", timestamp,
3094 GST_DEBUG_PAD_NAME (GST_PAD_PEER (pad)), GST_DEBUG_PAD_NAME (pad));
3096 event = gst_event_new_discontinuous (TRUE,
3097 event_type, offset, GST_FORMAT_UNDEFINED);
3098 GST_CAT_WARNING (GST_CAT_DATAFLOW,
3099 "needed to invent a DISCONT (no time) for %s:%s => %s:%s",
3100 GST_DEBUG_PAD_NAME (GST_PAD_PEER (pad)), GST_DEBUG_PAD_NAME (pad));
3103 return GST_DATA (event);
3108 * @pad: a source #GstPad.
3109 * @data: the #GstData to push.
3111 * Pushes a buffer or an event to the peer of @pad. @pad must be linked. May
3112 * only be called by @pad's parent.
3115 gst_pad_push (GstPad * pad, GstData * data)
3119 g_return_if_fail (GST_IS_PAD (pad));
3120 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
3121 g_return_if_fail (data != NULL);
3123 if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), &data))
3126 if (!GST_PAD_IS_LINKED (pad)) {
3127 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad,
3128 "not pushing data %p as pad is unconnected", data);
3129 gst_data_unref (data);
3133 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad, "pushing");
3134 peer = GST_RPAD_PEER (pad);
3137 g_warning ("push on pad %s:%s but it is unlinked",
3138 GST_DEBUG_PAD_NAME (pad));
3140 if (!GST_IS_EVENT (data) && !GST_PAD_IS_ACTIVE (peer)) {
3141 g_warning ("push on peer of pad %s:%s but peer is not active",
3142 GST_DEBUG_PAD_NAME (pad));
3146 if (peer->chainhandler) {
3148 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad,
3149 "calling chainhandler &%s of peer pad %s:%s",
3150 GST_DEBUG_FUNCPTR_NAME (peer->chainhandler),
3151 GST_DEBUG_PAD_NAME (GST_PAD (peer)));
3152 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
3155 (peer->chainhandler) (GST_PAD (peer), data);
3158 g_warning ("trying to push a NULL buffer on pad %s:%s",
3159 GST_DEBUG_PAD_NAME (peer));
3163 g_warning ("internal error: push on pad %s:%s but it has no chainhandler",
3164 GST_DEBUG_PAD_NAME (peer));
3167 /* clean up the mess here */
3169 gst_data_unref (data);
3174 * @pad: a sink #GstPad.
3176 * Pulls an event or a buffer from the peer pad. May only be called by @pad's
3179 * Returns: a new #GstData from the peer pad.
3182 gst_pad_pull (GstPad * pad)
3186 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad, "pulling");
3188 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
3189 GST_DATA (gst_event_new (GST_EVENT_INTERRUPT)));
3191 peer = GST_RPAD_PEER (pad);
3194 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3195 ("pull on pad %s:%s but it was unlinked", GST_DEBUG_PAD_NAME (pad)));
3198 if (peer->gethandler) {
3199 GstPadLink *link = GST_RPAD_LINK (pad);
3202 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad,
3203 "calling gethandler %s of peer pad %s:%s",
3204 GST_DEBUG_FUNCPTR_NAME (peer->gethandler), GST_DEBUG_PAD_NAME (peer));
3206 if (link->temp_store) {
3207 g_assert (link->engaged);
3208 data = link->temp_store;
3209 link->temp_store = NULL;
3211 data = (peer->gethandler) (GST_PAD (peer));
3212 /* refetch - we might have been relinked */
3213 link = GST_RPAD_LINK (pad);
3214 peer = GST_RPAD_PEER (pad);
3218 if (!link->engaged) {
3219 g_assert (link->temp_store == NULL);
3220 if (GST_IS_BUFFER (data)) {
3221 link->temp_store = data;
3222 link->engaged = TRUE;
3223 data = _invent_event (pad, GST_BUFFER (data));
3224 } else if (GST_IS_EVENT (data) &&
3225 GST_EVENT_TYPE (data) == GST_EVENT_DISCONTINUOUS &&
3226 GST_EVENT_DISCONT_NEW_MEDIA (data)) {
3227 link->engaged = TRUE;
3228 GST_CAT_LOG (GST_CAT_DATAFLOW,
3229 "link engaged by discont event for pad %s:%s",
3230 GST_DEBUG_PAD_NAME (pad));
3233 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
3238 /* no null buffers allowed */
3239 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3240 ("NULL buffer during pull on %s:%s", GST_DEBUG_PAD_NAME (pad)));
3242 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3243 ("pull on pad %s:%s but the peer pad %s:%s has no gethandler",
3244 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer)));
3247 return GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
3251 gst_pad_collect_array (GstScheduler * scheduler, GstPad ** selected,
3254 GstSchedulerClass *klass = GST_SCHEDULER_GET_CLASS (scheduler);
3256 if (!GST_FLAG_IS_SET (scheduler, GST_SCHEDULER_FLAG_NEW_API) ||
3257 !klass->pad_select) {
3258 /* better randomness? */
3260 *selected = padlist[0];
3261 return gst_pad_pull (padlist[0]);
3265 return klass->pad_select (scheduler, selected ? selected : &select,
3272 * @selected: set to the pad the buffer comes from if not NULL
3273 * @padlist: a #GList of sink pads.
3275 * Waits for a buffer on any of the list of pads. Each #GstPad in @padlist must
3276 * belong to the same element and be owned by the caller.
3278 * Returns: the #GstData that was available
3281 gst_pad_collectv (GstPad ** selected, const GList * padlist)
3283 /* need to use alloca here because we must not leak data */
3286 GstElement *element = NULL;
3289 g_return_val_if_fail (padlist != NULL, NULL);
3290 pads = g_alloca (sizeof (gpointer) * (g_list_length ((GList *) padlist) + 1));
3291 for (; padlist; padlist = g_list_next (padlist)) {
3292 test = GST_PAD (padlist->data);
3293 g_return_val_if_fail (GST_IS_PAD (test), NULL);
3294 g_return_val_if_fail (GST_PAD_IS_SINK (test), NULL);
3296 g_return_val_if_fail (element == gst_pad_get_parent (test), NULL);
3298 element = gst_pad_get_parent (test);
3304 return gst_pad_collect_array (GST_SCHEDULER (element), selected, pads);
3309 * @selected: set to the pad the buffer comes from if not NULL
3311 * @...: more sink pads.
3313 * Waits for a buffer on the given set of pads.
3315 * Returns: the #GstData that was available.
3318 gst_pad_collect (GstPad ** selected, GstPad * pad, ...)
3323 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3325 va_start (var_args, pad);
3327 result = gst_pad_collect_valist (selected, pad, var_args);
3335 * gst_pad_collect_valist:
3336 * @selected: set to the pad the buffer comes from if not NULL
3338 * @...: more sink pads.
3340 * Waits for a buffer on the given set of pads.
3342 * Returns: the #GstData that was available.
3345 gst_pad_collect_valist (GstPad ** selected, GstPad * pad, va_list var_args)
3348 GstElement *element = NULL;
3349 gint i = 0, maxlength;
3351 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3353 element = gst_pad_get_parent (pad);
3354 maxlength = element->numsinkpads;
3355 /* can we make this list a bit smaller than this upper limit? */
3356 padlist = g_alloca (sizeof (gpointer) * (maxlength + 1));
3358 g_return_val_if_fail (i < maxlength, NULL);
3359 g_return_val_if_fail (element == gst_pad_get_parent (pad), NULL);
3361 pad = va_arg (var_args, GstPad *);
3363 return gst_pad_collect_array (GST_SCHEDULER (element), selected, padlist);
3368 * @padlist: a #GList of sink pads.
3370 * Waits for a buffer on any of the list of pads. Each #GstPad in @padlist must
3371 * be owned by the calling code.
3373 * Returns: the #GstPad that has a buffer available.
3374 * Use #gst_pad_pull() to get the buffer.
3377 gst_pad_selectv (GList * padlist)
3383 * gst_pad_select_valist:
3384 * @pad: a first #GstPad to perform the select on.
3385 * @varargs: A va_list of more pads to select on.
3387 * Waits for a buffer on the given set of pads.
3389 * Returns: the #GstPad that has a buffer available.
3390 * Use #gst_pad_pull() to get the buffer.
3393 gst_pad_select_valist (GstPad * pad, va_list var_args)
3396 GList *padlist = NULL;
3402 padlist = g_list_prepend (padlist, pad);
3403 pad = va_arg (var_args, GstPad *);
3405 result = gst_pad_selectv (padlist);
3406 g_list_free (padlist);
3413 * @pad: a first sink #GstPad to perform the select on.
3414 * @...: A NULL-terminated list of more pads to select on.
3416 * Waits for a buffer on the given set of pads.
3418 * Returns: the #GstPad that has a buffer available.
3419 * Use #gst_pad_pull() to get the buffer.
3422 gst_pad_select (GstPad * pad, ...)
3430 va_start (var_args, pad);
3432 result = gst_pad_select_valist (pad, var_args);
3439 /************************************************************************
3444 static void gst_pad_template_class_init (GstPadTemplateClass * klass);
3445 static void gst_pad_template_init (GstPadTemplate * templ);
3446 static void gst_pad_template_dispose (GObject * object);
3449 gst_pad_template_get_type (void)
3451 static GType padtemplate_type = 0;
3453 if (!padtemplate_type) {
3454 static const GTypeInfo padtemplate_info = {
3455 sizeof (GstPadTemplateClass), NULL, NULL,
3456 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
3457 sizeof (GstPadTemplate),
3459 (GInstanceInitFunc) gst_pad_template_init, NULL
3463 g_type_register_static (GST_TYPE_OBJECT, "GstPadTemplate",
3464 &padtemplate_info, 0);
3466 return padtemplate_type;
3470 gst_pad_template_class_init (GstPadTemplateClass * klass)
3472 GObjectClass *gobject_class;
3473 GstObjectClass *gstobject_class;
3475 gobject_class = (GObjectClass *) klass;
3476 gstobject_class = (GstObjectClass *) klass;
3478 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
3480 gst_pad_template_signals[TEMPL_PAD_CREATED] =
3481 g_signal_new ("pad-created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
3482 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
3483 NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
3485 gobject_class->dispose = gst_pad_template_dispose;
3487 gstobject_class->path_string_separator = "*";
3491 gst_pad_template_init (GstPadTemplate * templ)
3496 gst_pad_template_dispose (GObject * object)
3498 GstPadTemplate *templ = GST_PAD_TEMPLATE (object);
3500 g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
3501 if (GST_PAD_TEMPLATE_CAPS (templ)) {
3502 gst_caps_free (GST_PAD_TEMPLATE_CAPS (templ));
3505 G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object);
3508 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
3510 * SOMETIMES padtemplates can do whatever they want, they are provided by the
3512 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
3513 * 'sink%d' template is automatically selected), so we need to restrict their
3517 name_is_valid (const gchar * name, GstPadPresence presence)
3521 if (presence == GST_PAD_ALWAYS) {
3522 if (strchr (name, '%')) {
3523 g_warning ("invalid name template %s: conversion specifications are not"
3524 " allowed for GST_PAD_ALWAYS padtemplates", name);
3527 } else if (presence == GST_PAD_REQUEST) {
3528 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
3529 g_warning ("invalid name template %s: only one conversion specification"
3530 " allowed in GST_PAD_REQUEST padtemplate", name);
3533 if (str && (*(str + 1) != 's' && *(str + 1) != 'd')) {
3534 g_warning ("invalid name template %s: conversion specification must be of"
3535 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
3538 if (str && (*(str + 2) != '\0')) {
3539 g_warning ("invalid name template %s: conversion specification must"
3540 " appear at the end of the GST_PAD_REQUEST padtemplate name", name);
3549 * gst_static_pad_template_get:
3550 * @pad_template: the static pad template
3552 * Converts a #GstStaticPadTemplate into a #GstPadTemplate.
3554 * Returns: a new #GstPadTemplate.
3557 gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
3559 GstPadTemplate *new;
3561 if (!name_is_valid (pad_template->name_template, pad_template->presence))
3564 new = g_object_new (gst_pad_template_get_type (),
3565 "name", pad_template->name_template, NULL);
3567 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (pad_template->name_template);
3568 GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction;
3569 GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence;
3571 GST_PAD_TEMPLATE_CAPS (new) =
3572 gst_caps_copy (gst_static_caps_get (&pad_template->static_caps));
3578 * gst_pad_template_new:
3579 * @name_template: the name template.
3580 * @direction: the #GstPadDirection of the template.
3581 * @presence: the #GstPadPresence of the pad.
3582 * @caps: a #GstCaps set for the template. The caps are taken ownership of.
3584 * Creates a new pad template with a name according to the given template
3585 * and with the given arguments. This functions takes ownership of the provided
3586 * caps, so be sure to not use them afterwards.
3588 * Returns: a new #GstPadTemplate.
3591 gst_pad_template_new (const gchar * name_template,
3592 GstPadDirection direction, GstPadPresence presence, GstCaps * caps)
3594 GstPadTemplate *new;
3596 g_return_val_if_fail (name_template != NULL, NULL);
3597 g_return_val_if_fail (caps != NULL, NULL);
3599 if (!name_is_valid (name_template, presence))
3603 #ifdef USE_POISONING
3605 GstCaps *newcaps = gst_caps_copy (caps);
3607 gst_caps_free (caps);
3612 new = g_object_new (gst_pad_template_get_type (),
3613 "name", name_template, NULL);
3615 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
3616 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
3617 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
3618 gst_caps_do_simplify (caps);
3619 GST_PAD_TEMPLATE_CAPS (new) = caps;
3625 * gst_pad_template_get_caps:
3626 * @templ: a #GstPadTemplate to get capabilities of.
3628 * Gets the capabilities of the pad template.
3630 * Returns: the #GstCaps of the pad template. If you need to keep a reference to
3631 * the caps, make a copy (see gst_caps_copy ()).
3634 gst_pad_template_get_caps (GstPadTemplate * templ)
3636 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
3638 return GST_PAD_TEMPLATE_CAPS (templ);
3642 * gst_pad_set_element_private:
3643 * @pad: the #GstPad to set the private data of.
3644 * @priv: The private data to attach to the pad.
3646 * Set the given private data gpointer on the pad.
3647 * This function can only be used by the element that owns the pad.
3650 gst_pad_set_element_private (GstPad * pad, gpointer priv)
3652 pad->element_private = priv;
3656 * gst_pad_get_element_private:
3657 * @pad: the #GstPad to get the private data of.
3659 * Gets the private data of a pad.
3661 * Returns: a #gpointer to the private data.
3664 gst_pad_get_element_private (GstPad * pad)
3666 return pad->element_private;
3670 /***** ghost pads *****/
3671 GType _gst_ghost_pad_type = 0;
3673 static void gst_ghost_pad_class_init (GstGhostPadClass * klass);
3674 static void gst_ghost_pad_init (GstGhostPad * pad);
3675 static void gst_ghost_pad_dispose (GObject * object);
3676 static void gst_ghost_pad_get_property (GObject * object, guint prop_id,
3677 GValue * value, GParamSpec * pspec);
3678 static void gst_ghost_pad_set_property (GObject * object, guint prop_id,
3679 const GValue * value, GParamSpec * pspec);
3681 static GstPad *ghost_pad_parent_class = NULL;
3683 /* static guint gst_ghost_pad_signals[LAST_SIGNAL] = { 0 }; */
3692 gst_ghost_pad_get_type (void)
3694 if (!_gst_ghost_pad_type) {
3695 static const GTypeInfo pad_info = {
3696 sizeof (GstGhostPadClass), NULL, NULL,
3697 (GClassInitFunc) gst_ghost_pad_class_init, NULL, NULL,
3698 sizeof (GstGhostPad),
3700 (GInstanceInitFunc) gst_ghost_pad_init,
3704 _gst_ghost_pad_type = g_type_register_static (GST_TYPE_PAD, "GstGhostPad",
3707 return _gst_ghost_pad_type;
3711 gst_ghost_pad_class_init (GstGhostPadClass * klass)
3713 GObjectClass *gobject_class;
3715 gobject_class = (GObjectClass *) klass;
3717 ghost_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
3719 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_ghost_pad_dispose);
3720 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_ghost_pad_set_property);
3721 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_ghost_pad_get_property);
3723 g_object_class_install_property (gobject_class, GPAD_ARG_REAL_PAD,
3724 g_param_spec_object ("real-pad", "Real pad",
3725 "The real pad for the ghost pad", GST_TYPE_PAD, G_PARAM_READWRITE));
3729 gst_ghost_pad_init (GstGhostPad * pad)
3731 /* zeroed by glib */
3735 gst_ghost_pad_dispose (GObject * object)
3737 g_object_set (object, "real-pad", NULL, NULL);
3739 G_OBJECT_CLASS (ghost_pad_parent_class)->dispose (object);
3743 gst_ghost_pad_set_property (GObject * object, guint prop_id,
3744 const GValue * value, GParamSpec * pspec)
3746 GstPad *ghostpad = (GstPad *) object;
3747 GstPad *oldrealpad = (GstPad *) GST_GPAD_REALPAD (ghostpad);
3748 GstPad *realpad = NULL;
3751 case GPAD_ARG_REAL_PAD:
3752 realpad = g_value_get_object (value);
3755 if (realpad == oldrealpad)
3758 gst_pad_remove_ghost_pad (oldrealpad, ghostpad);
3762 gst_pad_add_ghost_pad (realpad, ghostpad);
3766 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3772 gst_ghost_pad_get_property (GObject * object, guint prop_id,
3773 GValue * value, GParamSpec * pspec)
3776 case GPAD_ARG_REAL_PAD:
3777 g_value_set_object (value, GST_GPAD_REALPAD (object));
3781 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3787 * gst_ghost_pad_new:
3788 * @name: the name of the new ghost pad.
3789 * @pad: the #GstPad to create a ghost pad for.
3791 * Creates a new ghost pad associated with @pad, and named @name. If @name is
3792 * %NULL, a guaranteed unique name (across all ghost pads) will be assigned.
3794 * Returns: a new ghost #GstPad, or %NULL in case of an error.
3797 gst_ghost_pad_new (const gchar * name, GstPad * pad)
3801 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3803 gpad = g_object_new (GST_TYPE_GHOST_PAD, "name", name, "real-pad", pad, NULL);
3805 GST_CAT_DEBUG (GST_CAT_PADS, "created ghost pad \"%s\" for pad %s:%s",
3806 GST_OBJECT_NAME (gpad), GST_DEBUG_PAD_NAME (pad));
3812 * gst_pad_get_internal_links_default:
3813 * @pad: the #GstPad to get the internal links of.
3815 * Gets a list of pads to which the given pad is linked to
3816 * inside of the parent element.
3817 * This is the default handler, and thus returns a list of all of the
3818 * pads inside the parent element with opposite direction.
3819 * The caller must free this list after use.
3821 * Returns: a newly allocated #GList of pads.
3824 gst_pad_get_internal_links_default (GstPad * pad)
3829 GstPadDirection direction;
3832 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3834 rpad = GST_PAD_REALIZE (pad);
3835 direction = rpad->direction;
3837 parent = GST_PAD_PARENT (rpad);
3838 parent_pads = parent->pads;
3840 while (parent_pads) {
3841 GstRealPad *parent_pad = GST_PAD_REALIZE (parent_pads->data);
3843 if (parent_pad->direction != direction) {
3844 res = g_list_prepend (res, parent_pad);
3847 parent_pads = g_list_next (parent_pads);
3854 * gst_pad_get_internal_links:
3855 * @pad: the #GstPad to get the internal links of.
3857 * Gets a list of pads to which the given pad is linked to
3858 * inside of the parent element.
3859 * The caller must free this list after use.
3861 * Returns: a newly allocated #GList of pads.
3864 gst_pad_get_internal_links (GstPad * pad)
3869 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3871 rpad = GST_PAD_REALIZE (pad);
3873 if (GST_RPAD_INTLINKFUNC (rpad))
3874 res = GST_RPAD_INTLINKFUNC (rpad) (GST_PAD (rpad));
3881 gst_pad_event_default_dispatch (GstPad * pad, GstElement * element,
3886 GST_INFO_OBJECT (pad, "Sending event %p to all internally linked pads",
3889 orig = pads = gst_pad_get_internal_links (pad);
3892 GstPad *eventpad = GST_PAD (pads->data);
3894 pads = g_list_next (pads);
3896 /* for all of the internally-linked pads that are actually linked */
3897 if (GST_PAD_IS_LINKED (eventpad)) {
3898 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
3899 /* increase the refcount */
3900 gst_event_ref (event);
3901 gst_pad_push (eventpad, GST_DATA (event));
3903 GstPad *peerpad = GST_PAD (GST_RPAD_PEER (eventpad));
3905 /* we only send the event on one pad, multi-sinkpad elements
3906 * should implement a handler */
3908 return gst_pad_send_event (peerpad, event);
3912 gst_event_unref (event);
3914 return (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
3918 * gst_pad_event_default:
3919 * @pad: a #GstPad to call the default event handler on.
3920 * @event: the #GstEvent to handle.
3922 * Invokes the default event handler for the given pad. End-of-stream and
3923 * discontinuity events are handled specially, and then the event is sent to all
3924 * pads internally linked to @pad. Note that if there are many possible sink
3925 * pads that are internally linked to @pad, only one will be sent an event.
3926 * Multi-sinkpad elements should implement custom event handlers.
3928 * Returns: TRUE if the event was sent succesfully.
3931 gst_pad_event_default (GstPad * pad, GstEvent * event)
3933 GstElement *element;
3935 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3936 g_return_val_if_fail (event != NULL, FALSE);
3938 element = GST_PAD_PARENT (pad);
3940 switch (GST_EVENT_TYPE (event)) {
3942 gst_pad_event_default_dispatch (pad, element, event);
3943 gst_element_set_eos (element);
3945 case GST_EVENT_DISCONTINUOUS:
3949 if (gst_element_requires_clock (element) && element->clock) {
3950 if (gst_event_discont_get_value (event, GST_FORMAT_TIME, &time)) {
3951 gst_element_set_time (element, time);
3953 GstFormat format = GST_FORMAT_TIME;
3956 for (i = 0; i < event->event_data.discont.noffsets; i++) {
3957 if (gst_pad_convert (pad,
3958 event->event_data.discont.offsets[i].format,
3959 event->event_data.discont.offsets[i].value, &format,
3961 gst_element_set_time (element, time);
3962 } else if (i == event->event_data.discont.noffsets) {
3964 ("can't adjust clock to new time when time not provided");
3971 return gst_pad_event_default_dispatch (pad, element, event);
3977 * gst_pad_dispatcher:
3978 * @pad: a #GstPad to dispatch.
3979 * @dispatch: the #GstDispatcherFunction to call.
3980 * @data: gpointer user data passed to the dispatcher function.
3982 * Invokes the given dispatcher function on all pads that are
3983 * internally linked to the given pad.
3984 * The GstPadDispatcherFunction should return TRUE when no further pads
3985 * need to be processed.
3987 * Returns: TRUE if one of the dispatcher functions returned TRUE.
3990 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
3993 gboolean res = FALSE;
3994 GList *int_pads, *orig;
3996 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3997 g_return_val_if_fail (dispatch != NULL, FALSE);
3999 orig = int_pads = gst_pad_get_internal_links (pad);
4002 GstRealPad *int_rpad = GST_PAD_REALIZE (int_pads->data);
4003 GstRealPad *int_peer = GST_RPAD_PEER (int_rpad);
4006 res = dispatch (GST_PAD (int_peer), data);
4010 int_pads = g_list_next (int_pads);
4019 * gst_pad_send_event:
4020 * @pad: a #GstPad to send the event to.
4021 * @event: the #GstEvent to send to the pad.
4023 * Sends the event to the pad.
4025 * Returns: TRUE if the event was handled.
4028 gst_pad_send_event (GstPad * pad, GstEvent * event)
4030 gboolean success = FALSE;
4033 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4034 g_return_val_if_fail (event != NULL, FALSE);
4036 rpad = GST_PAD_REALIZE (pad);
4038 if (GST_EVENT_SRC (event) == NULL)
4039 GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (rpad));
4041 GST_CAT_DEBUG (GST_CAT_EVENT, "have event %d on pad %s:%s",
4042 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (rpad));
4044 if (GST_RPAD_EVENTHANDLER (rpad))
4045 success = GST_RPAD_EVENTHANDLER (rpad) (GST_PAD (rpad), event);
4047 g_warning ("pad %s:%s has no event handler", GST_DEBUG_PAD_NAME (rpad));
4048 gst_event_unref (event);
4056 GstFormat src_format;
4058 GstFormat *dest_format;
4064 gst_pad_convert_dispatcher (GstPad * pad, GstPadConvertData * data)
4066 return gst_pad_convert (pad, data->src_format, data->src_value,
4067 data->dest_format, data->dest_value);
4071 * gst_pad_convert_default:
4072 * @pad: a #GstPad to invoke the default converter on.
4073 * @src_format: the source #GstFormat.
4074 * @src_value: the source value.
4075 * @dest_format: a pointer to the destination #GstFormat.
4076 * @dest_value: a pointer to the destination value.
4078 * Invokes the default converter on a pad.
4079 * This will forward the call to the pad obtained
4080 * using the internal link of
4083 * Returns: TRUE if the conversion could be performed.
4086 gst_pad_convert_default (GstPad * pad,
4087 GstFormat src_format, gint64 src_value,
4088 GstFormat * dest_format, gint64 * dest_value)
4090 GstPadConvertData data;
4092 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4093 g_return_val_if_fail (dest_format != NULL, FALSE);
4094 g_return_val_if_fail (dest_value != NULL, FALSE);
4096 data.src_format = src_format;
4097 data.src_value = src_value;
4098 data.dest_format = dest_format;
4099 data.dest_value = dest_value;
4101 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
4102 gst_pad_convert_dispatcher, &data);
4107 * @pad: a #GstPad to invoke the default converter on.
4108 * @src_format: the source #GstFormat.
4109 * @src_value: the source value.
4110 * @dest_format: a pointer to the destination #GstFormat.
4111 * @dest_value: a pointer to the destination value.
4113 * Invokes a conversion on the pad.
4115 * Returns: TRUE if the conversion could be performed.
4118 gst_pad_convert (GstPad * pad,
4119 GstFormat src_format, gint64 src_value,
4120 GstFormat * dest_format, gint64 * dest_value)
4124 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4125 g_return_val_if_fail (dest_format != NULL, FALSE);
4126 g_return_val_if_fail (dest_value != NULL, FALSE);
4128 if (src_format == *dest_format) {
4129 *dest_value = src_value;
4133 rpad = GST_PAD_REALIZE (pad);
4135 if (GST_RPAD_CONVERTFUNC (rpad)) {
4136 return GST_RPAD_CONVERTFUNC (rpad) (GST_PAD (rpad), src_format,
4137 src_value, dest_format, dest_value);
4152 gst_pad_query_dispatcher (GstPad * pad, GstPadQueryData * data)
4154 return gst_pad_query (pad, data->type, data->format, data->value);
4158 * gst_pad_query_default:
4159 * @pad: a #GstPad to invoke the default query on.
4160 * @type: the #GstQueryType of the query to perform.
4161 * @format: a pointer to the #GstFormat of the result.
4162 * @value: a pointer to the result.
4164 * Invokes the default query function on a pad.
4166 * Returns: TRUE if the query could be performed.
4169 gst_pad_query_default (GstPad * pad, GstQueryType type,
4170 GstFormat * format, gint64 * value)
4172 GstPadQueryData data;
4174 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4175 g_return_val_if_fail (format != NULL, FALSE);
4176 g_return_val_if_fail (value != NULL, FALSE);
4179 data.format = format;
4182 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
4183 gst_pad_query_dispatcher, &data);
4188 * @pad: a #GstPad to invoke the default query on.
4189 * @type: the #GstQueryType of the query to perform.
4190 * @format: a pointer to the #GstFormat asked for.
4191 * On return contains the #GstFormat used.
4192 * @value: a pointer to the result.
4194 * Queries a pad for one of the available properties. The format will be
4195 * adjusted to the actual format used when specifying formats such as
4196 * GST_FORMAT_DEFAULT.
4197 * FIXME: Tell if the format can be adjusted when specifying a definite format.
4199 * Returns: TRUE if the query could be performed.
4202 gst_pad_query (GstPad * pad, GstQueryType type,
4203 GstFormat * format, gint64 * value)
4207 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4208 g_return_val_if_fail (format != NULL, FALSE);
4209 g_return_val_if_fail (value != NULL, FALSE);
4211 rpad = GST_PAD_REALIZE (pad);
4213 g_return_val_if_fail (rpad, FALSE);
4215 if (GST_RPAD_QUERYFUNC (rpad))
4216 return GST_RPAD_QUERYFUNC (rpad) (GST_PAD (pad), type, format, value);
4222 gst_pad_get_formats_dispatcher (GstPad * pad, const GstFormat ** data)
4224 *data = gst_pad_get_formats (pad);
4230 * gst_pad_get_formats_default:
4231 * @pad: a #GstPad to query
4233 * Invoke the default format dispatcher for the pad.
4235 * Returns: An array of GstFormats ended with a 0 value.
4238 gst_pad_get_formats_default (GstPad * pad)
4240 GstFormat *result = NULL;
4242 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4244 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
4245 gst_pad_get_formats_dispatcher, &result);
4251 * gst_pad_get_formats:
4252 * @pad: a #GstPad to query
4254 * Gets the list of supported formats from the pad.
4256 * Returns: An array of GstFormats ended with a 0 value.
4259 gst_pad_get_formats (GstPad * pad)
4263 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4265 rpad = GST_PAD_REALIZE (pad);
4267 if (GST_RPAD_FORMATSFUNC (rpad))
4268 return GST_RPAD_FORMATSFUNC (rpad) (GST_PAD (pad));
4273 #define CALL_CHAINFUNC(pad, data) G_STMT_START {\
4274 GstData *__temp = (data); \
4275 if (GST_IS_EVENT (__temp) && \
4276 !GST_FLAG_IS_SET (gst_pad_get_parent (pad), GST_ELEMENT_EVENT_AWARE)) { \
4277 gst_pad_send_event (pad, GST_EVENT (__temp)); \
4279 GST_RPAD_CHAINFUNC (pad) (pad, __temp); \
4283 * gst_pad_call_chain_function:
4284 * @pad: sink pad to call chain function on
4285 * @data: data to call the chain function with
4287 * Calls the chain function of the given pad while making sure the internal
4288 * consistency is kept. Use this function inside schedulers instead of calling
4289 * the chain function yourself.
4292 gst_pad_call_chain_function (GstPad * pad, GstData * data)
4296 g_return_if_fail (GST_IS_REAL_PAD (pad));
4297 g_return_if_fail (GST_PAD_IS_SINK (pad));
4298 g_return_if_fail (data != NULL);
4299 g_return_if_fail (GST_RPAD_CHAINFUNC (pad) != NULL);
4300 g_return_if_fail (GST_RPAD_LINK (pad) != NULL);
4302 link = GST_RPAD_LINK (pad);
4303 if (!link->engaged) {
4304 g_assert (link->temp_store == NULL);
4305 if (GST_IS_BUFFER (data)) {
4306 link->temp_store = data;
4307 link->engaged = TRUE;
4308 CALL_CHAINFUNC (pad, _invent_event (pad, GST_BUFFER (data)));
4309 g_assert (link->temp_store == data);
4310 link->temp_store = NULL;
4311 } else if (GST_IS_EVENT (data) &&
4312 GST_EVENT_TYPE (data) == GST_EVENT_DISCONTINUOUS &&
4313 GST_EVENT_DISCONT_NEW_MEDIA (data)) {
4314 link->engaged = TRUE;
4315 GST_CAT_LOG (GST_CAT_DATAFLOW,
4316 "link engaged by discont event for pad %s:%s",
4317 GST_DEBUG_PAD_NAME (pad));
4320 CALL_CHAINFUNC (pad, data);
4324 * gst_pad_call_get_function:
4325 * @pad: sink pad to call chain function on
4327 * Calls the get function of the given pad while making sure the internal
4328 * consistency is kept. Use this function inside schedulers instead of calling
4329 * the get function yourself.
4331 * Returns: the data provided by the pad or NULL if no data was available.
4334 gst_pad_call_get_function (GstPad * pad)
4336 g_return_val_if_fail (GST_IS_REAL_PAD (pad), NULL);
4337 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
4338 g_return_val_if_fail (GST_RPAD_GETFUNC (pad) != NULL, NULL);
4340 return GST_RPAD_GETFUNC (pad) (pad);