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 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
37 #define DEBUG_DATA(obj,data,notice) G_STMT_START{\
38 if (GST_IS_EVENT (data)) { \
39 GST_CAT_DEBUG_OBJECT (debug_dataflow, obj, "%s event %p (type %d, refcount %d)", notice, data, \
40 GST_EVENT_TYPE (data), GST_DATA_REFCOUNT_VALUE (data)); \
42 GST_CAT_LOG_OBJECT (debug_dataflow, obj, "%s buffer %p (size %u, refcount %d)", notice, data, \
43 GST_BUFFER_SIZE (data), GST_BUFFER_REFCOUNT_VALUE (data)); \
46 #define GST_CAT_DEFAULT GST_CAT_PADS
64 GstPadFixateFunction app_fixate;
67 GstData *temp_store; /* used only when we invented a DISCONT */
77 static GstObject *padtemplate_parent_class = NULL;
78 static guint gst_pad_template_signals[TEMPL_LAST_SIGNAL] = { 0 };
80 GType _gst_pad_type = 0;
82 /***** Start with the base GstPad class *****/
83 static void gst_pad_class_init (GstPadClass * klass);
84 static void gst_pad_init (GstPad * pad);
85 static void gst_pad_dispose (GObject * object);
87 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
88 static GstCaps *_gst_pad_default_fixate_func (GstPad * pad,
89 const GstCaps * caps);
91 static gboolean gst_pad_link_try (GstPadLink * link);
92 static void gst_pad_link_free (GstPadLink * link);
94 #ifndef GST_DISABLE_LOADSAVE
95 static xmlNodePtr gst_pad_save_thyself (GstObject * object, xmlNodePtr parent);
98 static GstObject *pad_parent_class = NULL;
101 gst_pad_get_type (void)
103 if (!_gst_pad_type) {
104 static const GTypeInfo pad_info = {
105 sizeof (GstPadClass), NULL, NULL,
106 (GClassInitFunc) gst_pad_class_init, NULL, NULL,
109 (GInstanceInitFunc) gst_pad_init, NULL
112 _gst_pad_type = g_type_register_static (GST_TYPE_OBJECT, "GstPad",
115 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW",
116 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads");
118 return _gst_pad_type;
122 gst_pad_class_init (GstPadClass * klass)
124 GObjectClass *gobject_class;
126 gobject_class = (GObjectClass *) klass;
128 pad_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
130 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_pad_dispose);
134 gst_pad_init (GstPad * pad)
136 /* all structs are initialized to NULL by glib */
139 gst_pad_dispose (GObject * object)
141 GstPad *pad = GST_PAD (object);
143 gst_pad_set_pad_template (pad, NULL);
145 G_OBJECT_CLASS (pad_parent_class)->dispose (object);
150 /***** Then do the Real Pad *****/
151 /* Pad signals and args */
169 static void gst_real_pad_class_init (GstRealPadClass * klass);
170 static void gst_real_pad_init (GstRealPad * pad);
171 static void gst_real_pad_dispose (GObject * object);
173 static gboolean _gst_real_pad_fixate_accumulator (GSignalInvocationHint * ihint,
174 GValue * return_accu, const GValue * handler_return, gpointer dummy);
175 static void gst_real_pad_set_property (GObject * object, guint prop_id,
176 const GValue * value, GParamSpec * pspec);
177 static void gst_real_pad_get_property (GObject * object, guint prop_id,
178 GValue * value, GParamSpec * pspec);
180 GType _gst_real_pad_type = 0;
182 static GstPad *real_pad_parent_class = NULL;
183 static guint gst_real_pad_signals[REAL_LAST_SIGNAL] = { 0 };
186 gst_real_pad_get_type (void)
188 if (!_gst_real_pad_type) {
189 static const GTypeInfo pad_info = {
190 sizeof (GstRealPadClass), NULL, NULL,
191 (GClassInitFunc) gst_real_pad_class_init, NULL, NULL,
194 (GInstanceInitFunc) gst_real_pad_init, NULL
197 _gst_real_pad_type = g_type_register_static (GST_TYPE_PAD, "GstRealPad",
200 return _gst_real_pad_type;
204 gst_real_pad_class_init (GstRealPadClass * klass)
206 GObjectClass *gobject_class;
207 GstObjectClass *gstobject_class;
209 gobject_class = (GObjectClass *) klass;
210 gstobject_class = (GstObjectClass *) klass;
212 real_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
214 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_real_pad_dispose);
215 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_real_pad_set_property);
216 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_real_pad_get_property);
218 gst_real_pad_signals[REAL_LINKED] =
219 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
220 G_STRUCT_OFFSET (GstRealPadClass, linked), NULL, NULL,
221 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
222 gst_real_pad_signals[REAL_UNLINKED] =
223 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
224 G_STRUCT_OFFSET (GstRealPadClass, unlinked), NULL, NULL,
225 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
226 gst_real_pad_signals[REAL_FIXATE] =
227 g_signal_new ("fixate", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
228 G_STRUCT_OFFSET (GstRealPadClass, appfixatefunc),
229 _gst_real_pad_fixate_accumulator, NULL,
230 gst_marshal_BOXED__BOXED, GST_TYPE_CAPS, 1,
231 GST_TYPE_CAPS | G_SIGNAL_TYPE_STATIC_SCOPE);
233 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_ACTIVE,
234 g_param_spec_boolean ("active", "Active", "Whether the pad is active.",
235 TRUE, G_PARAM_READWRITE));
236 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_CAPS,
237 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
238 GST_TYPE_CAPS, G_PARAM_READABLE));
240 #ifndef GST_DISABLE_LOADSAVE
241 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
243 gstobject_class->path_string_separator = ".";
247 _gst_real_pad_fixate_accumulator (GSignalInvocationHint * ihint,
248 GValue * return_accu, const GValue * handler_return, gpointer dummy)
250 if (gst_value_get_caps (handler_return)) {
251 g_value_copy (handler_return, return_accu);
252 /* stop emission if something was returned */
259 gst_real_pad_init (GstRealPad * pad)
261 pad->direction = GST_PAD_UNKNOWN;
264 pad->chainfunc = NULL;
267 pad->chainhandler = NULL;
268 pad->gethandler = NULL;
270 pad->ghostpads = NULL;
273 pad->linkfunc = NULL;
274 pad->getcapsfunc = NULL;
276 pad->eventfunc = gst_pad_event_default;
277 pad->convertfunc = gst_pad_convert_default;
278 pad->queryfunc = gst_pad_query_default;
279 pad->intlinkfunc = gst_pad_get_internal_links_default;
281 pad->eventmaskfunc = gst_pad_get_event_masks_default;
282 pad->formatsfunc = gst_pad_get_formats_default;
283 pad->querytypefunc = gst_pad_get_query_types_default;
285 GST_FLAG_SET (pad, GST_PAD_DISABLED);
286 GST_FLAG_UNSET (pad, GST_PAD_NEGOTIATING);
288 gst_probe_dispatcher_init (&pad->probedisp);
292 gst_real_pad_set_property (GObject * object, guint prop_id,
293 const GValue * value, GParamSpec * pspec)
295 g_return_if_fail (GST_IS_PAD (object));
298 case REAL_ARG_ACTIVE:
299 gst_pad_set_active (GST_PAD (object), g_value_get_boolean (value));
302 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
308 gst_real_pad_get_property (GObject * object, guint prop_id,
309 GValue * value, GParamSpec * pspec)
311 g_return_if_fail (GST_IS_PAD (object));
314 case REAL_ARG_ACTIVE:
315 g_value_set_boolean (value, !GST_FLAG_IS_SET (object, GST_PAD_DISABLED));
318 g_value_set_boxed (value, GST_PAD_CAPS (GST_REAL_PAD (object)));
321 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
326 /* FIXME-0.9: Replace these custom functions with proper inheritance via _init
327 functions and object properties */
329 * gst_pad_custom_new:
330 * @type: the #Gtype of the pad.
331 * @name: the name of the new pad.
332 * @direction: the #GstPadDirection of the pad.
334 * Creates a new pad with the given name and type in the given direction.
335 * If name is NULL, a guaranteed unique name (across all pads)
338 * Returns: a new #GstPad, or NULL in case of an error.
341 gst_pad_custom_new (GType type, const gchar * name, GstPadDirection direction)
345 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
347 pad = g_object_new (type, NULL);
348 gst_object_set_name (GST_OBJECT (pad), name);
349 GST_RPAD_DIRECTION (pad) = direction;
351 return GST_PAD (pad);
356 * @name: the name of the new pad.
357 * @direction: the #GstPadDirection of the pad.
359 * Creates a new real pad with the given name in the given direction.
360 * If name is NULL, a guaranteed unique name (across all pads)
363 * Returns: a new #GstPad, or NULL in case of an error.
366 gst_pad_new (const gchar * name, GstPadDirection direction)
368 return gst_pad_custom_new (gst_real_pad_get_type (), name, direction);
372 * gst_pad_custom_new_from_template:
373 * @type: the custom #GType of the pad.
374 * @templ: the #GstPadTemplate to instantiate from.
375 * @name: the name of the new pad.
377 * Creates a new custom pad with the given name from the given template.
378 * If name is NULL, a guaranteed unique name (across all pads)
381 * Returns: a new #GstPad, or NULL in case of an error.
384 gst_pad_custom_new_from_template (GType type, GstPadTemplate * templ,
389 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
391 pad = gst_pad_custom_new (type, name, templ->direction);
392 gst_pad_set_pad_template (pad, templ);
398 * gst_pad_new_from_template:
399 * @templ: the pad template to use
400 * @name: the name of the element
402 * Creates a new real pad with the given name from the given template.
403 * If name is NULL, a guaranteed unique name (across all pads)
406 * Returns: a new #GstPad, or NULL in case of an error.
409 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
411 return gst_pad_custom_new_from_template (gst_real_pad_get_type (),
415 /* FIXME 0.9: GST_PAD_UNKNOWN needs to die! */
417 * gst_pad_get_direction:
418 * @pad: a #GstPad to get the direction of.
420 * Gets the direction of the pad.
422 * Returns: the #GstPadDirection of the pad.
425 gst_pad_get_direction (GstPad * pad)
427 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
429 if (GST_IS_REAL_PAD (pad))
430 return GST_PAD_DIRECTION (pad);
432 return GST_PAD_UNKNOWN;
436 * gst_pad_set_active:
437 * @pad: the #GstPad to activate or deactivate.
438 * @active: TRUE to activate the pad.
440 * Activates or deactivates the given pad.
443 gst_pad_set_active (GstPad * pad, gboolean active)
449 g_return_if_fail (GST_IS_PAD (pad));
451 old = GST_PAD_IS_ACTIVE (pad);
456 realpad = GST_PAD_REALIZE (pad);
459 GST_CAT_DEBUG (GST_CAT_PADS, "activating pad %s:%s",
460 GST_DEBUG_PAD_NAME (realpad));
461 GST_FLAG_UNSET (realpad, GST_PAD_DISABLED);
463 GST_CAT_DEBUG (GST_CAT_PADS, "de-activating pad %s:%s",
464 GST_DEBUG_PAD_NAME (realpad));
465 GST_FLAG_SET (realpad, GST_PAD_DISABLED);
467 link = GST_RPAD_LINK (realpad);
469 if (link->temp_store) {
470 GST_CAT_INFO (GST_CAT_PADS,
471 "deleting cached data %p from bufpen of pad %s:%s", link->temp_store,
472 GST_DEBUG_PAD_NAME (realpad));
473 gst_data_unref (link->temp_store);
474 link->temp_store = NULL;
478 g_object_notify (G_OBJECT (realpad), "active");
483 * @pad: the #GstPad to query
485 * Query if a pad is active
487 * Returns: TRUE if the pad is active.
490 gst_pad_is_active (GstPad * pad)
492 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
494 return !GST_FLAG_IS_SET (pad, GST_PAD_DISABLED);
499 * @pad: a #GstPad to set the name of.
500 * @name: the name of the pad.
502 * Sets the name of a pad. If name is NULL, then a guaranteed unique
503 * name will be assigned.
506 gst_pad_set_name (GstPad * pad, const gchar * name)
508 g_return_if_fail (GST_IS_PAD (pad));
510 gst_object_set_name (GST_OBJECT (pad), name);
513 /* FIXME 0.9: This function must die */
516 * @pad: a #GstPad to get the name of.
518 * Gets the name of a pad.
520 * Returns: the name of the pad. This is not a newly allocated pointer
521 * so you must not free it.
524 gst_pad_get_name (GstPad * pad)
526 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
528 return GST_OBJECT_NAME (pad);
532 * gst_pad_set_chain_function:
533 * @pad: a real sink #GstPad.
534 * @chain: the #GstPadChainFunction to set.
536 * Sets the given chain function for the pad. The chain function is called to
537 * process a #GstData input buffer.
540 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
542 g_return_if_fail (GST_IS_REAL_PAD (pad));
543 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SINK);
545 GST_RPAD_CHAINFUNC (pad) = chain;
546 GST_CAT_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
547 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
551 * gst_pad_set_get_function:
552 * @pad: a real source #GstPad.
553 * @get: the #GstPadGetFunction to set.
555 * Sets the given get function for the pad. The get function is called to
556 * produce a new #GstData to start the processing pipeline. Get functions cannot
560 gst_pad_set_get_function (GstPad * pad, GstPadGetFunction get)
562 g_return_if_fail (GST_IS_REAL_PAD (pad));
563 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SRC);
565 GST_RPAD_GETFUNC (pad) = get;
567 GST_CAT_DEBUG (GST_CAT_PADS, "getfunc for %s:%s set to %s",
568 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
572 * gst_pad_set_event_function:
573 * @pad: a real source #GstPad.
574 * @event: the #GstPadEventFunction to set.
576 * Sets the given event handler for the pad.
579 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
581 g_return_if_fail (GST_IS_REAL_PAD (pad));
582 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SRC);
584 GST_RPAD_EVENTFUNC (pad) = event;
586 GST_CAT_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
587 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
591 * gst_pad_set_event_mask_function:
592 * @pad: a real #GstPad of either direction.
593 * @mask_func: the #GstPadEventMaskFunction to set.
595 * Sets the given event mask function for the pad.
598 gst_pad_set_event_mask_function (GstPad * pad,
599 GstPadEventMaskFunction mask_func)
601 g_return_if_fail (GST_IS_REAL_PAD (pad));
603 GST_RPAD_EVENTMASKFUNC (pad) = mask_func;
605 GST_CAT_DEBUG (GST_CAT_PADS, "eventmaskfunc for %s:%s set to %s",
606 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (mask_func));
610 * gst_pad_get_event_masks:
613 * Gets the array of eventmasks from the given pad.
615 * Returns: a zero-terminated array of #GstEventMask, or NULL if the pad does
616 * not have an event mask function.
619 gst_pad_get_event_masks (GstPad * pad)
623 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
625 rpad = GST_PAD_REALIZE (pad);
627 g_return_val_if_fail (rpad, FALSE);
629 if (GST_RPAD_EVENTMASKFUNC (rpad))
630 return GST_RPAD_EVENTMASKFUNC (rpad) (GST_PAD (pad));
636 gst_pad_get_event_masks_dispatcher (GstPad * pad, const GstEventMask ** data)
638 *data = gst_pad_get_event_masks (pad);
644 * gst_pad_get_event_masks_default:
647 * Invokes the default event masks dispatcher on the pad.
649 * Returns: a zero-terminated array of #GstEventMask, or NULL if none of the
650 * internally-linked pads have an event mask function.
653 gst_pad_get_event_masks_default (GstPad * pad)
655 GstEventMask *result = NULL;
657 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
659 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
660 gst_pad_get_event_masks_dispatcher, &result);
666 * gst_pad_set_convert_function:
667 * @pad: a real #GstPad of either direction.
668 * @convert: the #GstPadConvertFunction to set.
670 * Sets the given convert function for the pad.
673 gst_pad_set_convert_function (GstPad * pad, GstPadConvertFunction convert)
675 g_return_if_fail (GST_IS_REAL_PAD (pad));
677 GST_RPAD_CONVERTFUNC (pad) = convert;
679 GST_CAT_DEBUG (GST_CAT_PADS, "convertfunc for %s:%s set to %s",
680 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (convert));
684 * gst_pad_set_query_function:
685 * @pad: a real #GstPad of either direction.
686 * @query: the #GstPadQueryFunction to set.
688 * Set the given query function for the pad.
691 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
693 g_return_if_fail (GST_IS_REAL_PAD (pad));
695 GST_RPAD_QUERYFUNC (pad) = query;
697 GST_CAT_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
698 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
702 * gst_pad_set_query_type_function:
703 * @pad: a real #GstPad of either direction.
704 * @type_func: the #GstPadQueryTypeFunction to set.
706 * Set the given query type function for the pad.
709 gst_pad_set_query_type_function (GstPad * pad,
710 GstPadQueryTypeFunction type_func)
712 g_return_if_fail (GST_IS_REAL_PAD (pad));
714 GST_RPAD_QUERYTYPEFUNC (pad) = type_func;
716 GST_CAT_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
717 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
721 * gst_pad_get_query_types:
724 * Get an array of supported queries that can be performed
727 * Returns: a zero-terminated array of #GstQueryType.
730 gst_pad_get_query_types (GstPad * pad)
734 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
736 rpad = GST_PAD_REALIZE (pad);
738 g_return_val_if_fail (rpad, NULL);
740 if (GST_RPAD_QUERYTYPEFUNC (rpad))
741 return GST_RPAD_QUERYTYPEFUNC (rpad) (GST_PAD (pad));
747 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
749 *data = gst_pad_get_query_types (pad);
755 * gst_pad_get_query_types_default:
758 * Invoke the default dispatcher for the query types on
761 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
762 * internally-linked pads has a query types function.
765 gst_pad_get_query_types_default (GstPad * pad)
767 GstQueryType *result = NULL;
769 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
771 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
772 gst_pad_get_query_types_dispatcher, &result);
778 * gst_pad_set_internal_link_function:
779 * @pad: a real #GstPad of either direction.
780 * @intlink: the #GstPadIntLinkFunction to set.
782 * Sets the given internal link function for the pad.
785 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
787 g_return_if_fail (GST_IS_REAL_PAD (pad));
789 GST_RPAD_INTLINKFUNC (pad) = intlink;
790 GST_CAT_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
791 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
795 * gst_pad_set_formats_function:
796 * @pad: a real #GstPad of either direction.
797 * @formats: the #GstPadFormatsFunction to set.
799 * Sets the given formats function for the pad.
802 gst_pad_set_formats_function (GstPad * pad, GstPadFormatsFunction formats)
804 g_return_if_fail (GST_IS_REAL_PAD (pad));
806 GST_RPAD_FORMATSFUNC (pad) = formats;
807 GST_CAT_DEBUG (GST_CAT_PADS, "formats function for %s:%s set to %s",
808 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (formats));
812 * gst_pad_set_link_function:
813 * @pad: a real #GstPad.
814 * @link: the #GstPadLinkFunction to set.
816 * Sets the given link function for the pad. It will be called when the pad is
817 * linked or relinked with caps. The caps passed to the link function are
818 * guaranteed to be fixed. This means that you can assume that the caps is not
819 * ANY or EMPTY, and that there is exactly one structure in the caps, and that
820 * all the fields in the structure are fixed.
822 * The return value GST_PAD_LINK_OK should be used when the caps are acceptable,
823 * and you've extracted all the necessary information from the caps and set the
824 * element's internal state appropriately.
826 * The return value GST_PAD_LINK_REFUSED should be used when the caps are
827 * unacceptable for whatever reason.
829 * The return value GST_PAD_LINK_DELAYED should be used when the element is in a
830 * state where it can't determine whether the caps are acceptable or not. This
831 * is often used if the element needs to open a device or process data before
832 * determining acceptable caps.
834 * @link must not call gst_caps_try_set_caps() on the pad that was specified as
835 * a parameter, although it may (and often should) call gst_caps_try_set_caps()
839 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
841 g_return_if_fail (GST_IS_REAL_PAD (pad));
843 GST_RPAD_LINKFUNC (pad) = link;
844 GST_CAT_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
845 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
849 * gst_pad_set_unlink_function:
850 * @pad: a real #GstPad.
851 * @unlink: the #GstPadUnlinkFunction to set.
853 * Sets the given unlink function for the pad. It will be called
854 * when the pad is unlinked.
857 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
859 g_return_if_fail (GST_IS_REAL_PAD (pad));
861 GST_RPAD_UNLINKFUNC (pad) = unlink;
862 GST_CAT_DEBUG (GST_CAT_PADS, "unlinkfunc for %s:%s set to %s",
863 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (unlink));
867 * gst_pad_set_fixate_function:
868 * @pad: a real #GstPad.
869 * @fixate: the #GstPadFixateFunction to set.
871 * Sets the given fixate function for the pad. Its job is to narrow down the
872 * possible caps for a connection. Fixate functions are called with a const
873 * caps, and should return a caps that is a strict subset of the given caps.
874 * That is, @fixate should create a caps that is "more fixed" than previously,
875 * but it does not have to return fixed caps. If @fixate can't provide more
876 * fixed caps, it should return %NULL.
878 * Note that @fixate will only be called after the "fixate" signal is emitted,
879 * and only if the caps are still non-fixed.
882 gst_pad_set_fixate_function (GstPad * pad, GstPadFixateFunction fixate)
884 g_return_if_fail (GST_IS_REAL_PAD (pad));
886 GST_RPAD_FIXATEFUNC (pad) = fixate;
887 GST_CAT_DEBUG (GST_CAT_PADS, "fixatefunc for %s:%s set to %s",
888 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (fixate));
892 * gst_pad_set_getcaps_function:
893 * @pad: a real #GstPad.
894 * @getcaps: the #GstPadGetCapsFunction to set.
896 * Sets the given getcaps function for the pad. @getcaps should return the
897 * allowable caps for a pad in the context of the element's state, its link to
898 * other elements, and the devices or files it has opened. These caps must be a
899 * subset of the pad template caps. In the NULL state with no links, @getcaps
900 * should ideally return the same caps as the pad template. In rare
901 * circumstances, an object property can affect the caps returned by @getcaps,
902 * but this is discouraged.
904 * You do not need to call this function if @pad's allowed caps are always the
905 * same as the pad template caps.
907 * For most filters, the caps returned by @getcaps is directly affected by the
908 * allowed caps on other pads. For demuxers and decoders, the caps returned by
909 * the srcpad's getcaps function is directly related to the stream data. Again,
910 * @getcaps should return the most specific caps it reasonably can, since this
911 * helps with autoplugging. However, the returned caps should not depend on the
912 * stream type currently negotiated for @pad.
914 * Note that the return value from @getcaps is owned by the caller.
917 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
919 g_return_if_fail (GST_IS_REAL_PAD (pad));
921 GST_RPAD_GETCAPSFUNC (pad) = getcaps;
922 GST_CAT_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
923 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
927 * gst_pad_set_bufferalloc_function:
928 * @pad: a real sink #GstPad.
929 * @bufalloc: the #GstPadBufferAllocFunction to set.
931 * Sets the given bufferalloc function for the pad. Note that the
932 * bufferalloc function can only be set on sinkpads.
935 gst_pad_set_bufferalloc_function (GstPad * pad,
936 GstPadBufferAllocFunction bufalloc)
938 g_return_if_fail (GST_IS_REAL_PAD (pad));
939 g_return_if_fail (GST_PAD_IS_SINK (pad));
941 GST_RPAD_BUFFERALLOCFUNC (pad) = bufalloc;
942 GST_CAT_DEBUG (GST_CAT_PADS, "bufferallocfunc for %s:%s set to %s",
943 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufalloc));
946 /* FIXME 0.9: Do we actually want to allow the case where src and sink are
950 * @srcpad: the source #GstPad to unlink.
951 * @sinkpad: the sink #GstPad to unlink.
953 * Unlinks the source pad from the sink pad. Will emit the "unlinked" signal on
957 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
959 GstRealPad *realsrc, *realsink;
960 GstScheduler *src_sched, *sink_sched;
962 g_return_if_fail (GST_IS_PAD (srcpad));
963 g_return_if_fail (GST_IS_PAD (sinkpad));
965 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
966 GST_DEBUG_PAD_NAME (srcpad), srcpad,
967 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
969 realsrc = GST_PAD_REALIZE (srcpad);
970 realsink = GST_PAD_REALIZE (sinkpad);
972 g_return_if_fail (GST_RPAD_PEER (realsrc) != NULL);
973 g_return_if_fail (GST_RPAD_PEER (realsink) == realsrc);
975 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
976 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
983 g_return_if_fail ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
984 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK));
986 if (GST_RPAD_UNLINKFUNC (realsrc)) {
987 GST_RPAD_UNLINKFUNC (realsrc) (GST_PAD (realsrc));
989 if (GST_RPAD_UNLINKFUNC (realsink)) {
990 GST_RPAD_UNLINKFUNC (realsink) (GST_PAD (realsink));
993 /* get the schedulers before we unlink */
994 src_sched = gst_pad_get_scheduler (GST_PAD (realsrc));
995 sink_sched = gst_pad_get_scheduler (GST_PAD (realsink));
997 if (GST_RPAD_LINK (realsrc))
998 gst_pad_link_free (GST_RPAD_LINK (realsrc));
1000 /* first clear peers */
1001 GST_RPAD_PEER (realsrc) = NULL;
1002 GST_RPAD_PEER (realsink) = NULL;
1003 GST_RPAD_LINK (realsrc) = NULL;
1004 GST_RPAD_LINK (realsink) = NULL;
1006 /* now tell the scheduler */
1007 if (src_sched && src_sched == sink_sched) {
1008 gst_scheduler_pad_unlink (src_sched, GST_PAD (realsrc), GST_PAD (realsink));
1011 /* hold a reference, as they can go away in the signal handlers */
1012 gst_object_ref (GST_OBJECT (realsrc));
1013 gst_object_ref (GST_OBJECT (realsink));
1015 /* fire off a signal to each of the pads telling them
1016 * that they've been unlinked */
1017 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_UNLINKED],
1019 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_UNLINKED],
1022 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1023 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1025 gst_object_unref (GST_OBJECT (realsrc));
1026 gst_object_unref (GST_OBJECT (realsink));
1030 * gst_pad_is_linked:
1031 * @pad: pad to check
1033 * Checks if a @pad is linked to another pad or not.
1035 * Returns: TRUE if the pad is linked, FALSE otherwise.
1038 gst_pad_is_linked (GstPad * pad)
1040 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1042 return GST_PAD_PEER (pad) != NULL;
1046 gst_pad_check_schedulers (GstRealPad * realsrc, GstRealPad * realsink)
1048 GstScheduler *src_sched, *sink_sched;
1049 gint num_decoupled = 0;
1051 src_sched = gst_pad_get_scheduler (GST_PAD (realsrc));
1052 sink_sched = gst_pad_get_scheduler (GST_PAD (realsink));
1054 if (src_sched && sink_sched) {
1055 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsrc), GST_ELEMENT_DECOUPLED))
1057 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsink), GST_ELEMENT_DECOUPLED))
1060 if (src_sched != sink_sched && num_decoupled != 1) {
1067 #define GST_PAD_LINK_SRC(pad) ((GST_PAD_IS_SRC (pad)) ? (pad) : GST_PAD_PEER (pad))
1068 #define GST_PAD_LINK_SINK(pad) ((GST_PAD_IS_SINK (pad)) ? (pad) : GST_PAD_PEER (pad))
1071 gst_pad_link_new (void)
1075 link = g_new0 (GstPadLink, 1);
1076 link->sinknotify = TRUE;
1077 link->srcnotify = TRUE;
1079 link->engaged = FALSE;
1084 gst_pad_link_free (GstPadLink * link)
1087 gst_caps_free (link->srccaps);
1089 gst_caps_free (link->sinkcaps);
1090 if (link->filtercaps)
1091 gst_caps_free (link->filtercaps);
1093 gst_caps_free (link->caps);
1094 if (link->temp_store)
1095 gst_data_unref (link->temp_store);
1096 #ifdef USE_POISONING
1097 memset (link, 0xff, sizeof (*link));
1103 gst_pad_link_intersect (GstPadLink * link)
1105 GstCaps *pad_intersection;
1108 gst_caps_free (link->caps);
1110 GST_DEBUG ("intersecting link from %s:%s to %s:%s",
1111 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1112 GST_DEBUG ("... srccaps %" GST_PTR_FORMAT, link->srccaps);
1113 GST_DEBUG ("... sinkcaps %" GST_PTR_FORMAT, link->sinkcaps);
1114 GST_DEBUG ("... filtercaps %" GST_PTR_FORMAT, link->filtercaps);
1116 pad_intersection = gst_caps_intersect (link->srccaps, link->sinkcaps);
1118 if (link->filtercaps) {
1119 GST_DEBUG ("unfiltered intersection %" GST_PTR_FORMAT, pad_intersection);
1120 link->caps = gst_caps_intersect (pad_intersection, link->filtercaps);
1121 gst_caps_free (pad_intersection);
1123 link->caps = pad_intersection;
1126 GST_DEBUG ("intersection %" GST_PTR_FORMAT, link->caps);
1130 gst_pad_link_ready_for_negotiation (GstPadLink * link)
1134 parent = GST_PAD_PARENT (link->srcpad);
1135 if (!parent || GST_STATE (parent) < GST_STATE_READY) {
1136 GST_DEBUG ("parent %s of pad %s:%s is not READY",
1137 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (link->srcpad));
1140 parent = GST_PAD_PARENT (link->sinkpad);
1141 if (!parent || GST_STATE (parent) < GST_STATE_READY) {
1142 GST_DEBUG ("parent %s of pad %s:%s is not READY",
1143 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (link->sinkpad));
1151 gst_pad_link_fixate (GstPadLink * link)
1158 g_return_if_fail (caps != NULL);
1159 g_return_if_fail (!gst_caps_is_empty (caps));
1161 GST_DEBUG ("trying to fixate caps %" GST_PTR_FORMAT, caps);
1163 gst_caps_do_simplify (caps);
1164 while (!gst_caps_is_fixed (caps)) {
1167 for (i = 0; i < 5; i++) {
1171 g_signal_emit (G_OBJECT (link->srcpad),
1172 gst_real_pad_signals[REAL_FIXATE], 0, caps, &newcaps);
1173 GST_DEBUG ("app srcpad signal fixated to %" GST_PTR_FORMAT, newcaps);
1176 g_signal_emit (G_OBJECT (link->sinkpad),
1177 gst_real_pad_signals[REAL_FIXATE], 0, caps, &newcaps);
1178 GST_DEBUG ("app sinkpad signal fixated to %" GST_PTR_FORMAT, newcaps);
1181 if (GST_RPAD_FIXATEFUNC (link->srcpad)) {
1183 GST_RPAD_FIXATEFUNC (link->srcpad) (GST_PAD (link->srcpad),
1185 GST_DEBUG ("srcpad %s:%s fixated to %" GST_PTR_FORMAT,
1186 GST_DEBUG_PAD_NAME (link->srcpad), newcaps);
1188 GST_DEBUG ("srcpad %s:%s doesn't have a fixate function",
1189 GST_DEBUG_PAD_NAME (link->srcpad));
1193 if (GST_RPAD_FIXATEFUNC (link->sinkpad)) {
1195 GST_RPAD_FIXATEFUNC (link->sinkpad) (GST_PAD (link->sinkpad),
1197 GST_DEBUG ("sinkpad %s:%s fixated to %" GST_PTR_FORMAT,
1198 GST_DEBUG_PAD_NAME (link->sinkpad), newcaps);
1200 GST_DEBUG ("sinkpad %s:%s doesn't have a fixate function",
1201 GST_DEBUG_PAD_NAME (link->sinkpad));
1204 newcaps = _gst_pad_default_fixate_func (GST_PAD (link->srcpad), caps);
1205 GST_DEBUG ("core fixated to %" GST_PTR_FORMAT, newcaps);
1209 G_GNUC_UNUSED gboolean bad;
1211 gst_caps_do_simplify (newcaps);
1212 #ifndef G_DISABLE_CHECKS
1213 /* some mad checking for correctly working fixation functions */
1216 /* we trust the default fixation function unconditionally */
1218 } else if (gst_caps_is_any (caps)) {
1219 bad = gst_caps_is_any (newcaps);
1221 GstCaps *test = gst_caps_subtract (caps, newcaps);
1223 bad = gst_caps_is_empty (test);
1224 gst_caps_free (test);
1225 /* simplifying is ok, too */
1227 bad = (gst_caps_get_size (newcaps) >= gst_caps_get_size (caps));
1230 gchar *newcaps_str = gst_caps_to_string (newcaps);
1231 gchar *caps_str = gst_caps_to_string (caps);
1234 ("a fixation function did not fixate correctly, the returned caps %s are no true subset of %s.",
1235 newcaps_str, caps_str);
1236 g_free (newcaps_str);
1238 gst_caps_free (newcaps);
1242 gst_caps_free (caps);
1253 static GstPadLinkReturn
1254 gst_pad_link_call_link_functions (GstPadLink * link)
1256 GstPadLinkReturn res = GST_PAD_LINK_OK;
1258 /* Detect recursion. */
1259 if (GST_PAD_IS_NEGOTIATING (link->srcpad) ||
1260 GST_PAD_IS_NEGOTIATING (link->sinkpad)) {
1261 GST_ERROR ("The link functions have recursed, please file a bug!");
1262 return GST_PAD_LINK_REFUSED;
1265 /* Both of the pads are in negotiation, so we set the NEGOTIATING flag on both
1266 * of them now to avoid recursion from either pad. */
1267 GST_FLAG_SET (link->srcpad, GST_PAD_NEGOTIATING);
1268 GST_FLAG_SET (link->sinkpad, GST_PAD_NEGOTIATING);
1270 /* If this doesn't run, the status is left to the default OK value. */
1271 if (link->srcnotify && GST_RPAD_LINKFUNC (link->srcpad)) {
1272 GST_DEBUG ("calling link function on pad %s:%s",
1273 GST_DEBUG_PAD_NAME (link->srcpad));
1275 /* call the link function */
1276 res = GST_RPAD_LINKFUNC (link->srcpad) (GST_PAD (link->srcpad), link->caps);
1278 GST_DEBUG ("got reply %d from link function on pad %s:%s",
1279 res, GST_DEBUG_PAD_NAME (link->srcpad));
1281 if (GST_PAD_LINK_FAILED (res)) {
1282 GST_CAT_INFO (GST_CAT_CAPS,
1283 "pad %s:%s doesn't accept caps %" GST_PTR_FORMAT,
1284 GST_DEBUG_PAD_NAME (link->srcpad), link->caps);
1288 if (GST_PAD_LINK_SUCCESSFUL (res) &&
1289 link->sinknotify && GST_RPAD_LINKFUNC (link->sinkpad)) {
1290 GST_DEBUG ("calling link function on pad %s:%s",
1291 GST_DEBUG_PAD_NAME (link->sinkpad));
1293 /* call the link function */
1294 res = GST_RPAD_LINKFUNC (link->sinkpad) (GST_PAD (link->sinkpad),
1297 GST_DEBUG ("got reply %d from link function on pad %s:%s",
1298 res, GST_DEBUG_PAD_NAME (link->sinkpad));
1300 if (GST_PAD_LINK_FAILED (res)) {
1301 GST_CAT_INFO (GST_CAT_CAPS,
1302 "pad %s:%s doesn't accept caps %" GST_PTR_FORMAT,
1303 GST_DEBUG_PAD_NAME (link->sinkpad), link->caps);
1307 GST_FLAG_UNSET (link->srcpad, GST_PAD_NEGOTIATING);
1308 GST_FLAG_UNSET (link->sinkpad, GST_PAD_NEGOTIATING);
1312 static GstPadLinkReturn
1313 gst_pad_link_negotiate (GstPadLink * link)
1315 GST_DEBUG ("negotiating link from pad %s:%s to pad %s:%s",
1316 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1318 gst_pad_link_intersect (link);
1319 if (gst_caps_is_empty (link->caps))
1320 return GST_PAD_LINK_REFUSED;
1322 gst_pad_link_fixate (link);
1323 if (gst_caps_is_empty (link->caps))
1324 return GST_PAD_LINK_REFUSED;
1326 if (!gst_pad_link_ready_for_negotiation (link)) {
1327 return GST_PAD_LINK_DELAYED;
1329 GST_DEBUG ("trying to call link function on caps %" GST_PTR_FORMAT,
1332 return gst_pad_link_call_link_functions (link);
1337 * @link: link to try
1339 * Tries to (re)link the pads with the given link. The function takes ownership
1340 * of the supplied link. If the function returns FALSE and an old link existed,
1341 * that link can be assumed to work unchanged.
1343 * Returns: TRUE if the link succeeded, FALSE if not.
1346 gst_pad_link_try (GstPadLink * link)
1348 GstPad *srcpad, *sinkpad;
1349 GstPadLink *oldlink;
1350 GstPadLinkReturn ret;
1352 /* we use assertions here, because this function is static */
1354 srcpad = link->srcpad;
1356 sinkpad = link->sinkpad;
1358 oldlink = GST_RPAD_LINK (srcpad);
1359 g_assert (oldlink == GST_RPAD_LINK (sinkpad));
1361 GST_DEBUG ("negotiating given link");
1362 ret = gst_pad_link_negotiate (link);
1363 if (GST_PAD_LINK_FAILED (ret) && oldlink && oldlink->caps) {
1364 GST_DEBUG ("negotiating failed, but there was a valid old link");
1365 oldlink->srcnotify = link->srcnotify;
1366 oldlink->sinknotify = link->sinknotify;
1367 if (GST_PAD_LINK_FAILED (gst_pad_link_call_link_functions (oldlink))) {
1368 g_warning ("pads don't accept old caps. We assume they did though");
1371 if (ret == GST_PAD_LINK_REFUSED) {
1372 GST_DEBUG ("link refused, returning");
1373 gst_pad_link_free (link);
1376 if (ret == GST_PAD_LINK_DELAYED) {
1377 GST_DEBUG ("link delayed, replacing link caps and returning");
1378 gst_caps_replace (&link->caps, NULL);
1381 GST_RPAD_PEER (srcpad) = GST_REAL_PAD (link->sinkpad);
1382 GST_RPAD_PEER (sinkpad) = GST_REAL_PAD (link->srcpad);
1384 GST_DEBUG ("copying stuff from oldlink");
1385 link->temp_store = oldlink->temp_store;
1386 GST_DEBUG ("moving old data temp store %p", link->temp_store);
1387 link->engaged = oldlink->engaged;
1388 oldlink->temp_store = NULL;
1389 gst_pad_link_free (oldlink);
1391 GST_RPAD_LINK (srcpad) = link;
1392 GST_RPAD_LINK (sinkpad) = link;
1393 if (ret == GST_PAD_LINK_OK) {
1394 GST_DEBUG ("notifying caps after successful link");
1395 g_object_notify (G_OBJECT (srcpad), "caps");
1396 g_object_notify (G_OBJECT (sinkpad), "caps");
1403 * gst_pad_renegotiate:
1406 * Initiate caps negotiation on @pad. @pad must be linked.
1408 * If @pad's parent is not at least in #GST_STATE_READY, returns
1409 * #GST_PAD_LINK_DELAYED.
1411 * Otherwise caps are retrieved from both @pad and its peer by calling their
1412 * getcaps functions. They are then intersected, returning #GST_PAD_LINK_FAIL if
1413 * there is no intersection.
1415 * The intersection is fixated if necessary, and then the link functions of @pad
1416 * and its peer are called.
1418 * Returns: The return value of @pad's link function (see
1419 * gst_pad_set_link_function()), or #GST_PAD_LINK_OK if there is no link
1422 * The macros GST_PAD_LINK_SUCCESSFUL() and GST_PAD_LINK_FAILED() should be used
1423 * when you just need success/failure information.
1426 gst_pad_renegotiate (GstPad * pad)
1430 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
1431 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1432 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1434 link = gst_pad_link_new ();
1436 link->srcpad = GST_PAD_LINK_SRC (pad);
1437 link->sinkpad = GST_PAD_LINK_SINK (pad);
1439 if (!gst_pad_link_ready_for_negotiation (link)) {
1440 gst_pad_link_free (link);
1441 return GST_PAD_LINK_DELAYED;
1444 if (GST_REAL_PAD (pad)->link->filtercaps) {
1445 link->filtercaps = gst_caps_copy (GST_REAL_PAD (pad)->link->filtercaps);
1447 link->srccaps = gst_pad_get_caps (link->srcpad);
1448 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1450 return gst_pad_link_try (link);
1454 * gst_pad_try_set_caps:
1456 * @caps: #GstCaps to set on @pad
1458 * Try to set the caps on @pad. @caps must be fixed. If @pad is unlinked,
1459 * returns #GST_PAD_LINK_OK without doing anything. Otherwise, start caps
1460 * negotiation on @pad.
1462 * Returns: The return value of @pad's link function (see
1463 * gst_pad_set_link_function()), or #GST_PAD_LINK_OK if there is no link
1466 * The macros GST_PAD_LINK_SUCCESSFUL() and GST_PAD_LINK_FAILED() should be used
1467 * when you just need success/failure information.
1470 gst_pad_try_set_caps (GstPad * pad, const GstCaps * caps)
1473 GstPadLink *oldlink;
1474 GstPadLinkReturn ret;
1476 g_return_val_if_fail (GST_IS_REAL_PAD (pad), GST_PAD_LINK_REFUSED);
1478 GST_LOG_OBJECT (pad, "Trying to set %" GST_PTR_FORMAT, caps);
1480 if (GST_PAD_IS_NEGOTIATING (pad)) {
1481 GST_DEBUG_OBJECT (pad, "Detected a recursion, just returning OK");
1482 return GST_PAD_LINK_OK;
1485 /* setting non-fixed caps on a pad is not allowed */
1486 if (!gst_caps_is_fixed (caps)) {
1487 GST_CAT_INFO (GST_CAT_CAPS,
1488 "trying to set unfixed caps on pad %s:%s, not allowed",
1489 GST_DEBUG_PAD_NAME (pad));
1490 g_warning ("trying to set non fixed caps on pad %s:%s, not allowed",
1491 GST_DEBUG_PAD_NAME (pad));
1493 GST_DEBUG ("unfixed caps %" GST_PTR_FORMAT, caps);
1494 return GST_PAD_LINK_REFUSED;
1497 /* we allow setting caps on non-linked pads. It's ignored */
1498 if (!GST_PAD_PEER (pad)) {
1499 GST_DEBUG ("unlinked pad %s:%s, returning OK", GST_DEBUG_PAD_NAME (pad));
1500 return GST_PAD_LINK_OK;
1503 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1504 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1506 /* if the desired caps are already there, it's trivially ok */
1507 if (GST_PAD_CAPS (pad) && gst_caps_is_equal (caps, GST_PAD_CAPS (pad))) {
1508 GST_DEBUG ("pad %s:%s already has these caps", GST_DEBUG_PAD_NAME (pad));
1509 return GST_PAD_LINK_OK;
1512 link = gst_pad_link_new ();
1514 link->srcpad = GST_PAD_LINK_SRC (pad);
1515 link->sinkpad = GST_PAD_LINK_SINK (pad);
1517 if (!gst_pad_link_ready_for_negotiation (link)) {
1518 GST_DEBUG ("link not ready for negotiating, delaying");
1519 gst_pad_link_free (link);
1520 return GST_PAD_LINK_DELAYED;
1523 oldlink = GST_REAL_PAD (pad)->link;
1524 if (oldlink && oldlink->filtercaps) {
1525 link->filtercaps = gst_caps_copy (oldlink->filtercaps);
1527 if (link->srcpad == pad) {
1528 link->srccaps = gst_caps_copy (caps);
1529 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1530 link->srcnotify = FALSE;
1532 link->srccaps = gst_pad_get_caps (link->srcpad);
1533 link->sinkcaps = gst_caps_copy (caps);
1534 link->sinknotify = FALSE;
1537 GST_DEBUG ("trying to link");
1538 ret = gst_pad_link_try (link);
1544 * gst_pad_try_set_caps_nonfixed:
1545 * @pad: a real #GstPad
1546 * @caps: #GstCaps to set on @pad
1548 * Like gst_pad_try_set_caps(), but allows non-fixed caps.
1550 * Returns: a #GstPadLinkReturn, like gst_pad_try_set_caps().
1553 gst_pad_try_set_caps_nonfixed (GstPad * pad, const GstCaps * caps)
1556 GstPadLink *oldlink;
1557 GstPadLinkReturn ret;
1559 g_return_val_if_fail (GST_IS_REAL_PAD (pad), GST_PAD_LINK_REFUSED);
1560 g_return_val_if_fail (!GST_PAD_IS_NEGOTIATING (pad), GST_PAD_LINK_REFUSED);
1562 /* we allow setting caps on non-linked pads. It's ignored */
1563 if (!GST_PAD_PEER (pad)) {
1564 return GST_PAD_LINK_OK;
1567 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1568 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1570 /* if the link is already negotiated and the caps are compatible
1571 * with what we're setting, it's trivially OK. */
1572 if (GST_PAD_CAPS (pad)) {
1573 GstCaps *intersection;
1575 intersection = gst_caps_intersect (caps, GST_PAD_CAPS (pad));
1576 if (!gst_caps_is_empty (intersection)) {
1577 gst_caps_free (intersection);
1578 return GST_PAD_LINK_OK;
1580 gst_caps_free (intersection);
1583 link = gst_pad_link_new ();
1585 link->srcpad = GST_PAD_LINK_SRC (pad);
1586 link->sinkpad = GST_PAD_LINK_SINK (pad);
1588 if (!gst_pad_link_ready_for_negotiation (link)) {
1589 gst_pad_link_free (link);
1590 return GST_PAD_LINK_DELAYED;
1593 oldlink = GST_REAL_PAD (pad)->link;
1594 if (oldlink && oldlink->filtercaps) {
1595 link->filtercaps = gst_caps_copy (oldlink->filtercaps);
1597 if (link->srcpad == pad) {
1598 link->srccaps = gst_caps_copy (caps);
1599 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1600 link->srcnotify = FALSE;
1602 link->srccaps = gst_pad_get_caps (link->srcpad);
1603 link->sinkcaps = gst_caps_copy (caps);
1604 link->sinknotify = FALSE;
1607 ret = gst_pad_link_try (link);
1613 * gst_pad_can_link_filtered:
1614 * @srcpad: the source #GstPad to link.
1615 * @sinkpad: the sink #GstPad to link.
1616 * @filtercaps: the filter #GstCaps.
1618 * Checks if the source pad and the sink pad can be linked when constrained
1619 * by the given filter caps. Both @srcpad and @sinkpad must be unlinked.
1621 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1624 gst_pad_can_link_filtered (GstPad * srcpad, GstPad * sinkpad,
1625 const GstCaps * filtercaps)
1627 GstRealPad *realsrc, *realsink;
1630 /* FIXME This function is gross. It's almost a direct copy of
1631 * gst_pad_link_filtered(). Any decent programmer would attempt
1632 * to merge the two functions, which I will do some day. --ds
1635 /* generic checks */
1636 g_return_val_if_fail (srcpad != NULL, FALSE);
1637 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1638 g_return_val_if_fail (sinkpad != NULL, FALSE);
1639 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1641 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1642 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1644 /* now we need to deal with the real/ghost stuff */
1645 realsrc = GST_PAD_REALIZE (srcpad);
1646 realsink = GST_PAD_REALIZE (sinkpad);
1648 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1649 GST_CAT_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
1650 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1652 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1653 if (GST_RPAD_PEER (realsrc) != NULL) {
1654 GST_CAT_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1655 GST_DEBUG_PAD_NAME (realsrc));
1658 if (GST_RPAD_PEER (realsink) != NULL) {
1659 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1660 GST_DEBUG_PAD_NAME (realsink));
1663 if (GST_PAD_PARENT (realsrc) == NULL) {
1664 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1665 GST_DEBUG_PAD_NAME (realsrc));
1668 if (GST_PAD_PARENT (realsink) == NULL) {
1669 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has no parent, failed",
1670 GST_DEBUG_PAD_NAME (realsrc));
1674 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1675 g_warning ("linking pads with different scheds requires "
1676 "exactly one decoupled element (such as queue)");
1680 g_return_val_if_fail (realsrc != NULL, GST_PAD_LINK_REFUSED);
1681 g_return_val_if_fail (realsink != NULL, GST_PAD_LINK_REFUSED);
1683 link = gst_pad_link_new ();
1685 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
1686 link->srcpad = GST_PAD (realsrc);
1687 link->sinkpad = GST_PAD (realsink);
1689 link->srcpad = GST_PAD (realsink);
1690 link->sinkpad = GST_PAD (realsrc);
1693 if (GST_RPAD_DIRECTION (link->srcpad) != GST_PAD_SRC) {
1694 GST_CAT_INFO (GST_CAT_PADS,
1695 "Real src pad %s:%s is not a source pad, failed",
1696 GST_DEBUG_PAD_NAME (link->srcpad));
1697 gst_pad_link_free (link);
1700 if (GST_RPAD_DIRECTION (link->sinkpad) != GST_PAD_SINK) {
1701 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1702 GST_DEBUG_PAD_NAME (link->sinkpad));
1703 gst_pad_link_free (link);
1707 link->srccaps = gst_pad_get_caps (link->srcpad);
1708 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1710 link->filtercaps = gst_caps_copy (filtercaps);
1712 gst_pad_link_intersect (link);
1713 if (gst_caps_is_empty (link->caps)) {
1714 gst_pad_link_free (link);
1718 gst_pad_link_free (link);
1724 * @srcpad: the source #GstPad to link.
1725 * @sinkpad: the sink #GstPad to link.
1727 * Checks if the source pad and the sink pad can be linked.
1729 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1732 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1734 return gst_pad_can_link_filtered (srcpad, sinkpad, NULL);
1738 * gst_pad_link_filtered:
1739 * @srcpad: the source #GstPad to link.
1740 * @sinkpad: the sink #GstPad to link.
1741 * @filtercaps: the filter #GstCaps.
1743 * Links the source pad and the sink pad, constrained
1744 * by the given filter caps.
1746 * Returns: TRUE if the pads have been linked, FALSE otherwise.
1749 gst_pad_link_filtered (GstPad * srcpad, GstPad * sinkpad,
1750 const GstCaps * filtercaps)
1752 GstRealPad *realsrc, *realsink;
1753 GstScheduler *src_sched, *sink_sched;
1756 /* generic checks */
1757 g_return_val_if_fail (srcpad != NULL, FALSE);
1758 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1759 g_return_val_if_fail (sinkpad != NULL, FALSE);
1760 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1762 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1763 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1765 /* now we need to deal with the real/ghost stuff */
1766 realsrc = GST_PAD_REALIZE (srcpad);
1767 realsink = GST_PAD_REALIZE (sinkpad);
1769 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1770 GST_CAT_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
1771 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1773 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1774 if (GST_RPAD_PEER (realsrc) != NULL) {
1775 GST_CAT_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1776 GST_DEBUG_PAD_NAME (realsrc));
1779 if (GST_RPAD_PEER (realsink) != NULL) {
1780 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1781 GST_DEBUG_PAD_NAME (realsink));
1784 if (GST_PAD_PARENT (realsrc) == NULL) {
1785 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1786 GST_DEBUG_PAD_NAME (realsrc));
1789 if (GST_PAD_PARENT (realsink) == NULL) {
1790 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has no parent, failed",
1791 GST_DEBUG_PAD_NAME (realsrc));
1795 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1796 g_warning ("linking pads with different scheds requires "
1797 "exactly one decoupled element (such as queue)");
1801 g_return_val_if_fail (realsrc != NULL, GST_PAD_LINK_REFUSED);
1802 g_return_val_if_fail (realsink != NULL, GST_PAD_LINK_REFUSED);
1804 link = gst_pad_link_new ();
1806 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
1807 link->srcpad = GST_PAD (realsrc);
1808 link->sinkpad = GST_PAD (realsink);
1810 link->srcpad = GST_PAD (realsink);
1811 link->sinkpad = GST_PAD (realsrc);
1814 if (GST_RPAD_DIRECTION (link->srcpad) != GST_PAD_SRC) {
1815 GST_CAT_INFO (GST_CAT_PADS,
1816 "Real src pad %s:%s is not a source pad, failed",
1817 GST_DEBUG_PAD_NAME (link->srcpad));
1818 gst_pad_link_free (link);
1821 if (GST_RPAD_DIRECTION (link->sinkpad) != GST_PAD_SINK) {
1822 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1823 GST_DEBUG_PAD_NAME (link->sinkpad));
1824 gst_pad_link_free (link);
1828 link->srccaps = gst_pad_get_caps (link->srcpad);
1829 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1831 link->filtercaps = gst_caps_copy (filtercaps);
1832 if (gst_pad_link_try (link) == GST_PAD_LINK_REFUSED)
1835 /* fire off a signal to each of the pads telling them
1836 * that they've been linked */
1837 g_signal_emit (G_OBJECT (link->srcpad), gst_real_pad_signals[REAL_LINKED],
1839 g_signal_emit (G_OBJECT (link->sinkpad), gst_real_pad_signals[REAL_LINKED],
1842 src_sched = gst_pad_get_scheduler (GST_PAD (link->srcpad));
1843 sink_sched = gst_pad_get_scheduler (GST_PAD (link->sinkpad));
1845 /* now tell the scheduler */
1846 if (src_sched && src_sched == sink_sched) {
1847 gst_scheduler_pad_link (src_sched,
1848 GST_PAD (link->srcpad), GST_PAD (link->sinkpad));
1850 GST_CAT_INFO (GST_CAT_PADS,
1851 "not telling link to scheduler %s:%s and %s:%s, %p %p",
1852 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad),
1853 src_sched, sink_sched);
1856 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1857 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1864 * @srcpad: the source #GstPad to link.
1865 * @sinkpad: the sink #GstPad to link.
1867 * Links the source pad to the sink pad.
1869 * Returns: TRUE if the pad could be linked, FALSE otherwise.
1872 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
1874 return gst_pad_link_filtered (srcpad, sinkpad, NULL);
1877 /* FIXME 0.9: Remove this */
1879 * gst_pad_set_parent:
1880 * @pad: a #GstPad to set the parent of.
1881 * @parent: the new parent #GstElement.
1883 * Sets the parent object of a pad. Deprecated, use gst_object_set_parent()
1887 gst_pad_set_parent (GstPad * pad, GstElement * parent)
1889 g_return_if_fail (GST_IS_PAD (pad));
1890 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
1891 g_return_if_fail (GST_IS_ELEMENT (parent));
1893 gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (parent));
1896 /* FIXME 0.9: Remove this */
1898 * gst_pad_get_parent:
1899 * @pad: the #GstPad to get the parent of.
1901 * Gets the parent object of this pad. Deprecated, use gst_object_get_parent()
1904 * Returns: the parent #GstElement.
1907 gst_pad_get_parent (GstPad * pad)
1909 g_return_val_if_fail (pad != NULL, NULL);
1910 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1912 return GST_PAD_PARENT (pad);
1916 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
1918 /* this function would need checks if it weren't static */
1920 gst_object_replace ((GstObject **) & pad->padtemplate, (GstObject *) templ);
1923 gst_object_sink (GST_OBJECT (templ));
1924 g_signal_emit (G_OBJECT (templ),
1925 gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
1930 * gst_pad_get_pad_template:
1933 * Gets the template for @pad.
1935 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
1936 * if this pad has no template.
1939 gst_pad_get_pad_template (GstPad * pad)
1941 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1943 return GST_PAD_PAD_TEMPLATE (pad);
1948 * gst_pad_get_scheduler:
1949 * @pad: a #GstPad to get the scheduler of.
1951 * Gets the scheduler of the pad. Since the pad does not
1952 * have a scheduler of its own, the scheduler of the parent
1953 * is taken. For decoupled pads, the scheduler of the peer
1956 * Returns: the #GstScheduler of the pad, or %NULL if there is no parent or the
1957 * parent is not yet in a managing bin.
1960 gst_pad_get_scheduler (GstPad * pad)
1962 GstScheduler *scheduler = NULL;
1965 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1967 parent = gst_pad_get_parent (pad);
1969 if (GST_FLAG_IS_SET (parent, GST_ELEMENT_DECOUPLED)) {
1970 GstRealPad *peer = GST_RPAD_PEER (pad);
1974 gst_element_get_scheduler (gst_pad_get_parent (GST_PAD (peer)));
1977 scheduler = gst_element_get_scheduler (parent);
1985 * gst_pad_get_real_parent:
1986 * @pad: a #GstPad to get the real parent of.
1988 * Gets the real parent object of this pad. If the pad
1989 * is a ghost pad, the actual owner of the real pad is
1990 * returned, as opposed to #gst_pad_get_parent().
1992 * Returns: the parent #GstElement.
1995 gst_pad_get_real_parent (GstPad * pad)
1997 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1999 return GST_PAD_PARENT (GST_PAD (GST_PAD_REALIZE (pad)));
2002 /* FIXME 0.9: Make static. */
2004 * gst_pad_add_ghost_pad:
2005 * @pad: a #GstPad to attach the ghost pad to.
2006 * @ghostpad: the ghost #GstPad to to the pad.
2008 * Adds a ghost pad to a pad. Private function, will be removed from the API in
2012 gst_pad_add_ghost_pad (GstPad * pad, GstPad * ghostpad)
2014 GstRealPad *realpad;
2016 g_return_if_fail (GST_IS_PAD (pad));
2017 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
2019 /* if we're ghosting a ghost pad, drill down to find the real pad */
2020 realpad = (GstRealPad *) pad;
2021 while (GST_IS_GHOST_PAD (realpad))
2022 realpad = GST_GPAD_REALPAD (realpad);
2023 g_return_if_fail (GST_IS_REAL_PAD (realpad));
2025 /* will ref the pad template */
2026 GST_GPAD_REALPAD (ghostpad) = realpad;
2027 realpad->ghostpads = g_list_prepend (realpad->ghostpads, ghostpad);
2028 gst_pad_set_pad_template (GST_PAD (ghostpad), GST_PAD_PAD_TEMPLATE (pad));
2031 /* FIXME 0.9: Make static. */
2033 * gst_pad_remove_ghost_pad:
2034 * @pad: a #GstPad to remove the ghost pad from.
2035 * @ghostpad: the ghost #GstPad to remove from the pad.
2037 * Removes a ghost pad from a pad. Private, will be removed from the API in 0.9.
2040 gst_pad_remove_ghost_pad (GstPad * pad, GstPad * ghostpad)
2042 GstRealPad *realpad;
2044 g_return_if_fail (GST_IS_PAD (pad));
2045 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
2046 realpad = GST_PAD_REALIZE (pad);
2047 g_return_if_fail (GST_GPAD_REALPAD (ghostpad) == realpad);
2049 gst_pad_set_pad_template (GST_PAD (ghostpad), NULL);
2050 realpad->ghostpads = g_list_remove (realpad->ghostpads, ghostpad);
2051 GST_GPAD_REALPAD (ghostpad) = NULL;
2055 * gst_pad_get_ghost_pad_list:
2056 * @pad: a #GstPad to get the ghost pads of.
2058 * Gets the ghost pads of this pad.
2060 * Returns: a #GList of ghost pads.
2063 gst_pad_get_ghost_pad_list (GstPad * pad)
2065 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2067 return GST_PAD_REALIZE (pad)->ghostpads;
2071 _gst_pad_default_fixate_foreach (GQuark field_id, GValue * value, gpointer s)
2073 GstStructure *structure = (GstStructure *) s;
2074 GType type = G_VALUE_TYPE (value);
2076 if (gst_type_is_fixed (type))
2079 if (type == GST_TYPE_INT_RANGE) {
2080 gst_structure_set (structure, g_quark_to_string (field_id),
2081 G_TYPE_INT, gst_value_get_int_range_min (value), NULL);
2084 if (type == GST_TYPE_DOUBLE_RANGE) {
2085 gst_structure_set (structure, g_quark_to_string (field_id),
2086 G_TYPE_DOUBLE, gst_value_get_double_range_min (value), NULL);
2089 if (type == GST_TYPE_LIST) {
2090 gst_structure_set_value (structure, g_quark_to_string (field_id),
2091 gst_value_list_get_value (value, 0));
2095 g_critical ("don't know how to fixate type %s", g_type_name (type));
2100 _gst_pad_default_fixate_func (GstPad * pad, const GstCaps * caps)
2102 static GstStaticCaps octetcaps = GST_STATIC_CAPS ("application/octet-stream");
2103 GstStructure *structure;
2106 g_return_val_if_fail (pad != NULL, NULL);
2107 g_return_val_if_fail (caps != NULL, NULL);
2108 g_return_val_if_fail (!gst_caps_is_empty (caps), NULL);
2110 if (gst_caps_is_any (caps)) {
2111 return gst_caps_copy (gst_static_caps_get (&octetcaps));
2114 if (caps->structs->len > 1) {
2115 return gst_caps_new_full (gst_structure_copy (gst_caps_get_structure (caps,
2119 newcaps = gst_caps_copy (caps);
2120 structure = gst_caps_get_structure (newcaps, 0);
2121 gst_structure_foreach (structure, _gst_pad_default_fixate_foreach, structure);
2127 * gst_pad_perform_negotiate:
2128 * @srcpad: the source #GstPad.
2129 * @sinkpad: the sink #GstPad.
2131 * Tries to negotiate the pads. See gst_pad_renegotiate() for a brief
2132 * description of caps negotiation.
2134 * Returns: TRUE if the pads were succesfully negotiated, FALSE otherwise.
2137 gst_pad_perform_negotiate (GstPad * srcpad, GstPad * sinkpad)
2139 return GST_PAD_LINK_SUCCESSFUL (gst_pad_renegotiate (srcpad));
2143 gst_pad_link_unnegotiate (GstPadLink * link)
2145 g_return_if_fail (link != NULL);
2148 gst_caps_free (link->caps);
2150 link->engaged = FALSE;
2151 if (GST_RPAD_LINK (link->srcpad) != link) {
2152 g_warning ("unnegotiating unset link");
2154 g_object_notify (G_OBJECT (link->srcpad), "caps");
2156 if (GST_RPAD_LINK (link->sinkpad) != link) {
2157 g_warning ("unnegotiating unset link");
2159 g_object_notify (G_OBJECT (link->sinkpad), "caps");
2165 * gst_pad_unnegotiate:
2166 * @pad: pad to unnegotiate
2168 * "Unnegotiates" a pad. The currently negotiated caps are cleared and the pad
2169 * needs renegotiation.
2172 gst_pad_unnegotiate (GstPad * pad)
2176 g_return_if_fail (GST_IS_PAD (pad));
2178 link = GST_RPAD_LINK (GST_PAD_REALIZE (pad));
2180 gst_pad_link_unnegotiate (link);
2183 /* returning NULL indicates that the arguments are invalid */
2185 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad,
2186 const GstCaps * filtercaps)
2188 GstRealPad *realsrc, *realsink;
2191 g_return_val_if_fail (GST_IS_PAD (srcpad), NULL);
2192 g_return_val_if_fail (GST_IS_PAD (sinkpad), NULL);
2194 realsrc = GST_PAD_REALIZE (srcpad);
2195 realsink = GST_PAD_REALIZE (sinkpad);
2197 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
2198 GST_CAT_DEBUG (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
2199 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
2202 g_return_val_if_fail (GST_RPAD_PEER (realsrc) == NULL, NULL);
2203 g_return_val_if_fail (GST_RPAD_PEER (realsink) == NULL, NULL);
2204 g_return_val_if_fail (GST_PAD_PARENT (realsrc) != NULL, NULL);
2205 g_return_val_if_fail (GST_PAD_PARENT (realsink) != NULL, NULL);
2207 if (!gst_pad_check_schedulers (realsrc, realsink)) {
2208 g_warning ("linking pads with different scheds requires "
2209 "exactly one decoupled element (such as queue)");
2213 if (GST_RPAD_DIRECTION (realsrc) == GST_RPAD_DIRECTION (realsink)) {
2214 g_warning ("%s:%s and %s:%s are both %s pads, failed",
2215 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink),
2216 GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC ? "src" : "sink");
2220 link = gst_pad_link_new ();
2222 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
2223 link->srcpad = GST_PAD (realsrc);
2224 link->sinkpad = GST_PAD (realsink);
2226 link->srcpad = GST_PAD (realsink);
2227 link->sinkpad = GST_PAD (realsrc);
2230 link->srccaps = gst_pad_get_caps (link->srcpad);
2231 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
2233 link->filtercaps = gst_caps_copy (filtercaps);
2239 * gst_pad_try_relink_filtered:
2240 * @srcpad: the source #GstPad to relink.
2241 * @sinkpad: the sink #GstPad to relink.
2242 * @filtercaps: the #GstPad to use as a filter in the relink.
2244 * Tries to relink the given source and sink pad, constrained by the given
2247 * Returns: TRUE if the pads were succesfully renegotiated, FALSE otherwise.
2250 gst_pad_try_relink_filtered (GstPad * srcpad, GstPad * sinkpad,
2251 const GstCaps * filtercaps)
2255 GST_INFO ("trying to relink %" GST_PTR_FORMAT " and %" GST_PTR_FORMAT
2256 " with filtercaps %" GST_PTR_FORMAT, srcpad, sinkpad);
2258 link = gst_pad_link_prepare (srcpad, sinkpad, filtercaps);
2262 if (GST_RPAD_PEER (link->srcpad) != (GstRealPad *) link->sinkpad) {
2263 g_warning ("Pads %s:%s and %s:%s were never linked",
2264 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2265 gst_pad_link_free (link);
2269 if (GST_PAD_LINK_FAILED (gst_pad_link_try (link)))
2276 * gst_pad_relink_filtered:
2277 * @srcpad: the source #GstPad to relink.
2278 * @sinkpad: the sink #GstPad to relink.
2279 * @filtercaps: the #GstPad to use as a filter in the relink.
2281 * Relinks the given source and sink pad, constrained by the given
2282 * capabilities. If the relink fails, the pads are unlinked
2283 * and FALSE is returned.
2285 * Returns: TRUE if the pads were succesfully relinked, FALSE otherwise.
2288 gst_pad_relink_filtered (GstPad * srcpad, GstPad * sinkpad,
2289 const GstCaps * filtercaps)
2291 if (gst_pad_try_relink_filtered (srcpad, sinkpad, filtercaps))
2294 gst_pad_unlink (srcpad, sinkpad);
2299 * gst_pad_proxy_getcaps:
2300 * @pad: a #GstPad to proxy.
2302 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
2303 * same element as @pad, and returns the intersection of the results.
2305 * This function is useful as a default getcaps function for an element
2306 * that can handle any stream format, but requires all its pads to have
2307 * the same caps. Two such elements are tee and aggregator.
2309 * Returns: the intersection of the other pads' allowed caps.
2312 gst_pad_proxy_getcaps (GstPad * pad)
2314 GstElement *element;
2316 GstCaps *caps, *intersected;
2318 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2320 GST_DEBUG ("proxying getcaps for %s:%s", GST_DEBUG_PAD_NAME (pad));
2322 element = gst_pad_get_parent (pad);
2324 pads = gst_element_get_pad_list (element);
2326 caps = gst_caps_new_any ();
2328 GstPad *otherpad = GST_PAD (pads->data);
2331 if (otherpad != pad) {
2332 GstCaps *allowed = gst_pad_get_allowed_caps (otherpad);
2334 temp = gst_caps_intersect (caps, allowed);
2335 gst_caps_free (caps);
2336 gst_caps_free (allowed);
2340 pads = g_list_next (pads);
2343 intersected = gst_caps_intersect (caps, gst_pad_get_pad_template_caps (pad));
2344 gst_caps_free (caps);
2349 * gst_pad_proxy_pad_link:
2350 * @pad: a #GstPad to proxy from
2351 * @caps: the #GstCaps to link with
2353 * Calls gst_pad_try_set_caps() for every other pad belonging to the
2354 * same element as @pad. If gst_pad_try_set_caps() fails on any pad,
2355 * the proxy link fails. May be used only during negotiation.
2357 * Returns: GST_PAD_LINK_OK if sucessful
2360 gst_pad_proxy_pad_link (GstPad * pad, const GstCaps * caps)
2362 GstElement *element;
2364 GstPadLinkReturn ret;
2366 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
2367 g_return_val_if_fail (caps != NULL, GST_PAD_LINK_REFUSED);
2369 GST_DEBUG ("proxying pad link for %s:%s", GST_DEBUG_PAD_NAME (pad));
2371 element = gst_pad_get_parent (pad);
2373 pads = gst_element_get_pad_list (element);
2376 GstPad *otherpad = GST_PAD (pads->data);
2378 if (otherpad != pad) {
2379 ret = gst_pad_try_set_caps (otherpad, caps);
2380 if (GST_PAD_LINK_FAILED (ret)) {
2384 pads = g_list_next (pads);
2387 return GST_PAD_LINK_OK;
2391 * gst_pad_proxy_fixate:
2392 * @pad: a #GstPad to proxy.
2393 * @caps: the #GstCaps to fixate
2395 * Implements a default fixate function based on the caps set on the other
2396 * pads in the element. This function should only be used if every pad
2397 * has the same pad template caps.
2399 * Returns: a fixated caps, or NULL if caps cannot be fixed
2402 gst_pad_proxy_fixate (GstPad * pad, const GstCaps * caps)
2404 GstElement *element;
2406 const GstCaps *othercaps;
2408 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2409 g_return_val_if_fail (caps != NULL, NULL);
2411 GST_DEBUG ("proxying fixate for %s:%s\n", GST_DEBUG_PAD_NAME (pad));
2413 element = gst_pad_get_parent (pad);
2415 pads = gst_element_get_pad_list (element);
2418 GstPad *otherpad = GST_PAD (pads->data);
2420 /* FIXME check that each pad has the same pad template caps */
2422 if (otherpad != pad) {
2423 othercaps = gst_pad_get_negotiated_caps (otherpad);
2425 if (othercaps && !gst_caps_is_subset (caps, othercaps)) {
2428 icaps = gst_caps_intersect (othercaps, caps);
2429 if (!gst_caps_is_empty (icaps)) {
2432 gst_caps_free (icaps);
2436 pads = g_list_next (pads);
2443 * gst_pad_set_explicit_caps:
2444 * @pad: a #GstPad to set the explicit caps of
2445 * @caps: the #GstCaps to set
2447 * If a pad has been told to use explicit caps, this function is used
2448 * to set the explicit caps. If @caps is NULL, the explicit caps are
2451 * This function calls gst_pad_try_set_caps() on the pad. If that
2452 * call fails, GST_ELEMENT_ERROR() is called to indicate a negotiation
2455 * Returns: TRUE if the caps were set correctly, otherwise FALSE
2458 gst_pad_set_explicit_caps (GstPad * pad, const GstCaps * caps)
2460 GstPadLinkReturn link_ret;
2462 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2464 GST_CAT_DEBUG (GST_CAT_PADS,
2465 "setting explicit caps on %s:%s to %" GST_PTR_FORMAT,
2466 GST_DEBUG_PAD_NAME (pad), caps);
2469 GST_CAT_DEBUG (GST_CAT_PADS, "caps is NULL");
2470 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2474 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), gst_caps_copy (caps));
2476 if (!GST_PAD_IS_LINKED (pad)) {
2477 GST_CAT_DEBUG (GST_CAT_PADS, "pad is not linked");
2480 link_ret = gst_pad_try_set_caps (pad, caps);
2481 if (link_ret == GST_PAD_LINK_REFUSED) {
2482 gchar *caps_str = gst_caps_to_string (caps);
2484 GST_ELEMENT_ERROR (gst_pad_get_parent (pad), CORE, PAD, (NULL),
2485 ("failed to negotiate (try_set_caps with \"%s\" returned REFUSED)",
2495 gst_pad_explicit_getcaps (GstPad * pad)
2497 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2499 if (GST_RPAD_EXPLICIT_CAPS (pad) == NULL) {
2500 const GstCaps *caps = gst_pad_get_pad_template_caps (pad);
2502 return gst_caps_copy (caps);
2504 return gst_caps_copy (GST_RPAD_EXPLICIT_CAPS (pad));
2507 static GstPadLinkReturn
2508 gst_pad_explicit_link (GstPad * pad, const GstCaps * caps)
2510 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
2511 g_return_val_if_fail (caps != NULL, GST_PAD_LINK_REFUSED);
2513 if (GST_RPAD_EXPLICIT_CAPS (pad) == NULL) {
2514 return GST_PAD_LINK_DELAYED;
2517 return GST_PAD_LINK_OK;
2521 * gst_pad_use_explicit_caps:
2522 * @pad: a #GstPad to set to use explicit caps
2524 * This function handles negotiation for pads that need to be set
2525 * to particular caps under complete control of the element, based
2526 * on some state in the element. This is often the case with
2527 * decoders and other elements whose caps is determined by the data
2530 * WARNING: This function is a hack and will be replaced with something
2531 * better in gstreamer-0.9.
2534 gst_pad_use_explicit_caps (GstPad * pad)
2536 g_return_if_fail (GST_IS_PAD (pad));
2538 gst_pad_set_getcaps_function (pad, gst_pad_explicit_getcaps);
2539 gst_pad_set_link_function (pad, gst_pad_explicit_link);
2540 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2544 * gst_pad_proxy_link:
2545 * @pad: a #GstPad to proxy to.
2546 * @caps: the #GstCaps to use in proxying.
2548 * Proxies the link function to the specified pad.
2550 * Returns: TRUE if the peer pad accepted the caps, FALSE otherwise.
2553 gst_pad_proxy_link (GstPad * pad, const GstCaps * caps)
2555 return gst_pad_try_set_caps (pad, caps);
2559 * gst_pad_is_negotiated:
2560 * @pad: a #GstPad to get the negotiation status of
2562 * Returns: TRUE if the pad has successfully negotiated caps.
2565 gst_pad_is_negotiated (GstPad * pad)
2567 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2569 if (!GST_PAD_REALIZE (pad))
2571 if (!GST_RPAD_LINK (pad))
2574 return (GST_RPAD_LINK (pad)->caps != NULL);
2578 * gst_pad_get_negotiated_caps:
2579 * @pad: a #GstPad to get the negotiated capabilites of
2581 * Gets the currently negotiated caps of a pad.
2583 * Returns: the currently negotiated caps of a pad, or NULL if the pad isn't
2586 G_CONST_RETURN GstCaps *
2587 gst_pad_get_negotiated_caps (GstPad * pad)
2589 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2591 if (!GST_PAD_REALIZE (pad))
2593 if (!GST_RPAD_LINK (pad))
2596 return GST_RPAD_LINK (pad)->caps;
2601 * @pad: a #GstPad to get the capabilities of.
2603 * Gets the capabilities of this pad.
2605 * Returns: the #GstCaps of this pad. This function returns a new caps, so use
2606 * gst_caps_free to get rid of it.
2609 gst_pad_get_caps (GstPad * pad)
2611 GstRealPad *realpad;
2613 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2615 realpad = GST_PAD_REALIZE (pad);
2617 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
2618 GST_DEBUG_PAD_NAME (realpad), realpad);
2620 if (GST_PAD_IS_DISPATCHING (realpad))
2621 GST_CAT_DEBUG (GST_CAT_CAPS,
2622 "pad %s:%s is already dispatching -- looking for a template",
2623 GST_DEBUG_PAD_NAME (realpad));
2625 if (GST_RPAD_GETCAPSFUNC (realpad) && !GST_PAD_IS_DISPATCHING (realpad)) {
2628 GST_CAT_DEBUG (GST_CAT_CAPS, "dispatching to pad getcaps function");
2630 GST_FLAG_SET (realpad, GST_PAD_DISPATCHING);
2631 caps = GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD (realpad));
2632 GST_FLAG_UNSET (realpad, GST_PAD_DISPATCHING);
2635 g_critical ("pad %s:%s returned NULL caps from getcaps function\n",
2636 GST_DEBUG_PAD_NAME (realpad));
2638 #ifndef G_DISABLE_ASSERT
2639 /* check that the returned caps are a real subset of the template caps */
2640 if (GST_PAD_PAD_TEMPLATE (realpad)) {
2641 const GstCaps *templ_caps =
2642 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (realpad));
2643 if (!gst_caps_is_subset (caps, templ_caps)) {
2646 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
2647 "pad returned caps %" GST_PTR_FORMAT
2648 " which are not a real subset of its template caps %"
2649 GST_PTR_FORMAT, caps, templ_caps);
2651 ("pad %s:%s returned caps that are not a real subset of its template caps",
2652 GST_DEBUG_PAD_NAME (realpad));
2653 temp = gst_caps_intersect (templ_caps, caps);
2654 gst_caps_free (caps);
2662 if (GST_PAD_PAD_TEMPLATE (realpad)) {
2663 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (realpad);
2664 const GstCaps *caps;
2666 caps = GST_PAD_TEMPLATE_CAPS (templ);
2667 GST_CAT_DEBUG (GST_CAT_CAPS,
2668 "using pad template %p with caps %" GST_PTR_FORMAT, templ, caps);
2671 /* FIXME we should enable something like this someday, but this is
2673 if (!gst_caps_is_fixed (caps)) {
2675 ("pad %s:%s (%p) has no getcaps function and the pad template returns non-fixed caps. Element is probably broken.\n",
2676 GST_DEBUG_PAD_NAME (realpad), realpad);
2680 return gst_caps_copy (GST_PAD_TEMPLATE_CAPS (templ));
2682 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
2686 g_warning ("pad %s:%s (%p) has no pad template\n",
2687 GST_DEBUG_PAD_NAME (realpad), realpad);
2690 return gst_caps_new_any ();
2694 * gst_pad_get_pad_template_caps:
2695 * @pad: a #GstPad to get the template capabilities from.
2697 * Gets the capabilities for @pad's template.
2699 * Returns: the #GstCaps of this pad template. If you intend to keep a reference
2700 * on the caps, make a copy (see gst_caps_copy ()).
2703 gst_pad_get_pad_template_caps (GstPad * pad)
2705 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2707 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2709 if (GST_PAD_PAD_TEMPLATE (pad))
2710 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2713 /* FIXME this should be enabled some day */
2714 /* wingo: why? mail the list during 0.9 when you find this :) */
2715 g_warning ("pad %s:%s (%p) has no pad template\n",
2716 GST_DEBUG_PAD_NAME (realpad), realpad);
2719 return gst_static_caps_get (&anycaps);
2722 /* FIXME 0.9: This function should probably die, or at least be renamed to
2723 * get_caps_by_format. */
2725 * gst_pad_template_get_caps_by_name:
2726 * @templ: a #GstPadTemplate to get the capabilities of.
2727 * @name: the name of the capability to get.
2729 * Gets the capability with the given name from @templ.
2731 * Returns: the #GstCaps of this pad template, or NULL if not found. If you
2732 * intend to keep a reference on the caps, make a copy (see gst_caps_copy ()).
2735 gst_pad_template_get_caps_by_name (GstPadTemplate * templ, const gchar * name)
2739 g_return_val_if_fail (templ != NULL, NULL);
2741 caps = GST_PAD_TEMPLATE_CAPS (templ);
2749 /* FIXME 0.9: What good is this if it only works for already-negotiated pads? */
2751 * gst_pad_check_compatibility:
2752 * @srcpad: the source #GstPad to check.
2753 * @sinkpad: the sink #GstPad to check against.
2755 * Checks if two pads have compatible capabilities. If neither one has yet been
2756 * negotiated, returns TRUE for no good reason.
2758 * Returns: TRUE if they are compatible or if the capabilities could not be
2759 * checked, FALSE if the capabilities are not compatible.
2762 gst_pad_check_compatibility (GstPad * srcpad, GstPad * sinkpad)
2764 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2765 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2767 if (GST_PAD_CAPS (srcpad) && GST_PAD_CAPS (sinkpad)) {
2768 if (!gst_caps_is_always_compatible (GST_PAD_CAPS (srcpad),
2769 GST_PAD_CAPS (sinkpad))) {
2775 GST_CAT_DEBUG (GST_CAT_PADS,
2776 "could not check capabilities of pads (%s:%s) and (%s:%s) %p %p",
2777 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2778 GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad));
2785 * @pad: a #GstPad to get the peer of.
2787 * Gets the peer of @pad.
2789 * Returns: the peer #GstPad.
2792 gst_pad_get_peer (GstPad * pad)
2794 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2796 return GST_PAD (GST_PAD_PEER (pad));
2800 * gst_pad_get_allowed_caps:
2801 * @pad: a real #GstPad.
2803 * Gets the capabilities of the allowed media types that can flow through @pad.
2804 * The caller must free the resulting caps.
2806 * Returns: the allowed #GstCaps of the pad link. Free the caps when
2807 * you no longer need it.
2810 gst_pad_get_allowed_caps (GstPad * pad)
2812 const GstCaps *mycaps;
2818 g_return_val_if_fail (GST_IS_REAL_PAD (pad), NULL);
2820 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting allowed caps",
2821 GST_DEBUG_PAD_NAME (pad));
2823 mycaps = gst_pad_get_pad_template_caps (pad);
2824 if (GST_RPAD_PEER (pad) == NULL) {
2825 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer, returning template",
2826 GST_DEBUG_PAD_NAME (pad));
2827 return gst_caps_copy (mycaps);
2830 peercaps = gst_pad_get_caps (GST_PAD_PEER (pad));
2831 caps = gst_caps_intersect (mycaps, peercaps);
2832 gst_caps_free (peercaps);
2834 link = GST_RPAD_LINK (pad);
2835 if (link->filtercaps) {
2836 icaps = gst_caps_intersect (caps, link->filtercaps);
2837 gst_caps_free (caps);
2838 GST_CAT_DEBUG (GST_CAT_PROPERTIES,
2839 "%s:%s: returning filtered intersection with peer",
2840 GST_DEBUG_PAD_NAME (pad));
2843 GST_CAT_DEBUG (GST_CAT_PROPERTIES,
2844 "%s:%s: returning unfiltered intersection with peer",
2845 GST_DEBUG_PAD_NAME (pad));
2851 * gst_pad_caps_change_notify:
2854 * Called to indicate that the return value of @pad's getcaps function may have
2855 * changed, and that a renegotiation is suggested.
2858 gst_pad_caps_change_notify (GstPad * pad)
2863 * gst_pad_recover_caps_error:
2864 * @pad: a #GstPad that had a failed capsnego
2865 * @allowed: possible caps for the link
2867 * Attempt to recover from a failed caps negotiation. This function
2868 * is typically called by a plugin that exhausted its list of caps
2869 * and wants the application to resolve the issue. The application
2870 * should connect to the pad's caps_nego_failed signal and should
2871 * resolve the issue by connecting another element for example.
2873 * Returns: TRUE when the issue was resolved, dumps detailed information
2874 * on the console and returns FALSE otherwise.
2877 gst_pad_recover_caps_error (GstPad * pad, const GstCaps * allowed)
2884 * gst_pad_alloc_buffer:
2885 * @pad: a source #GstPad
2886 * @offset: the offset of the new buffer in the stream
2887 * @size: the size of the new buffer
2889 * Allocates a new, empty buffer optimized to push to pad @pad. This
2890 * function only works if @pad is a source pad.
2892 * Returns: a new, empty #GstBuffer, or NULL if there is an error
2895 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size)
2899 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2900 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
2902 peer = GST_RPAD_PEER (pad);
2904 if (peer && peer->bufferallocfunc) {
2907 GST_CAT_DEBUG (GST_CAT_BUFFER, "(%s:%s): getting buffer",
2908 GST_DEBUG_PAD_NAME (pad));
2909 GST_CAT_DEBUG (GST_CAT_PADS,
2910 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s",
2911 GST_DEBUG_FUNCPTR_NAME (peer->bufferallocfunc),
2912 &peer->bufferallocfunc, GST_DEBUG_PAD_NAME (((GstPad *) peer)));
2914 ret = (peer->bufferallocfunc) (GST_PAD (peer), offset, size);
2918 return gst_buffer_new_and_alloc (size);
2922 gst_real_pad_dispose (GObject * object)
2924 GstPad *pad = GST_PAD (object);
2926 /* No linked pad can ever be disposed.
2927 * It has to have a parent to be linked
2928 * and a parent would hold a reference */
2929 /* FIXME: what about if g_object_dispose is explicitly called on the pad? Is
2930 that legal? otherwise we could assert GST_OBJECT_PARENT (pad) == NULL as
2932 g_assert (GST_PAD_PEER (pad) == NULL);
2934 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s",
2935 GST_DEBUG_PAD_NAME (pad));
2937 /* we destroy the ghostpads, because they are nothing without the real pad */
2938 if (GST_REAL_PAD (pad)->ghostpads) {
2939 GList *orig, *ghostpads;
2941 orig = ghostpads = g_list_copy (GST_REAL_PAD (pad)->ghostpads);
2944 GstPad *ghostpad = GST_PAD (ghostpads->data);
2946 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))) {
2947 GstElement *parent = GST_ELEMENT (GST_OBJECT_PARENT (ghostpad));
2949 GST_CAT_DEBUG (GST_CAT_REFCOUNTING,
2950 "removing ghost pad from element '%s'", GST_OBJECT_NAME (parent));
2951 gst_element_remove_pad (parent, ghostpad);
2953 /* handle the case where we have some floating ghost pad that was never
2954 added to an element */
2955 g_object_set (ghostpad, "real-pad", NULL, NULL);
2957 ghostpads = g_list_next (ghostpads);
2960 /* as the ghost pads are removed, they remove themselves from ->ghostpads.
2961 So it should be empty now. Let's assert that. */
2962 g_assert (GST_REAL_PAD (pad)->ghostpads == NULL);
2965 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
2966 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
2967 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
2969 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
2972 if (GST_RPAD_EXPLICIT_CAPS (pad)) {
2973 GST_ERROR_OBJECT (pad, "still explicit caps %" GST_PTR_FORMAT " set",
2974 GST_RPAD_EXPLICIT_CAPS (pad));
2975 g_warning ("pad %p has still explicit caps set", pad);
2976 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2978 G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
2982 #ifndef GST_DISABLE_LOADSAVE
2983 /* FIXME: why isn't this on a GstElement ? */
2985 * gst_pad_load_and_link:
2986 * @self: an #xmlNodePtr to read the description from.
2987 * @parent: the #GstObject element that owns the pad.
2989 * Reads the pad definition from the XML node and links the given pad
2990 * in the element to a pad of an element up in the hierarchy.
2993 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
2995 xmlNodePtr field = self->xmlChildrenNode;
2996 GstPad *pad = NULL, *targetpad;
3000 GstObject *grandparent;
3003 if (!strcmp (field->name, "name")) {
3004 pad = gst_element_get_pad (GST_ELEMENT (parent),
3005 xmlNodeGetContent (field));
3006 } else if (!strcmp (field->name, "peer")) {
3007 peer = xmlNodeGetContent (field);
3009 field = field->next;
3011 g_return_if_fail (pad != NULL);
3016 split = g_strsplit (peer, ".", 2);
3018 if (split[0] == NULL || split[1] == NULL) {
3019 GST_CAT_DEBUG (GST_CAT_XML,
3020 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
3021 peer, GST_DEBUG_PAD_NAME (pad));
3025 g_return_if_fail (split[0] != NULL);
3026 g_return_if_fail (split[1] != NULL);
3028 grandparent = gst_object_get_parent (parent);
3030 if (grandparent && GST_IS_BIN (grandparent)) {
3031 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
3038 targetpad = gst_element_get_pad (target, split[1]);
3040 if (targetpad == NULL)
3043 gst_pad_link (pad, targetpad);
3050 * gst_pad_save_thyself:
3051 * @pad: a #GstPad to save.
3052 * @parent: the parent #xmlNodePtr to save the description in.
3054 * Saves the pad into an xml representation.
3056 * Returns: the #xmlNodePtr representation of the pad.
3059 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
3061 GstRealPad *realpad;
3064 g_return_val_if_fail (GST_IS_REAL_PAD (object), NULL);
3066 realpad = GST_REAL_PAD (object);
3068 xmlNewChild (parent, NULL, "name", GST_PAD_NAME (realpad));
3069 if (GST_RPAD_PEER (realpad) != NULL) {
3072 peer = GST_PAD (GST_RPAD_PEER (realpad));
3073 /* first check to see if the peer's parent's parent is the same */
3074 /* we just save it off */
3075 content = g_strdup_printf ("%s.%s",
3076 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
3077 xmlNewChild (parent, NULL, "peer", content);
3080 xmlNewChild (parent, NULL, "peer", "");
3085 /* FIXME: shouldn't it be gst_pad_ghost_* ?
3086 * dunno -- wingo 7 feb 2004
3089 * gst_ghost_pad_save_thyself:
3090 * @pad: a ghost #GstPad to save.
3091 * @parent: the parent #xmlNodePtr to save the description in.
3093 * Saves the ghost pad into an xml representation.
3095 * Returns: the #xmlNodePtr representation of the pad.
3098 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
3102 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
3104 self = xmlNewChild (parent, NULL, "ghostpad", NULL);
3105 xmlNewChild (self, NULL, "name", GST_PAD_NAME (pad));
3106 xmlNewChild (self, NULL, "parent", GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
3108 /* FIXME FIXME FIXME! */
3112 #endif /* GST_DISABLE_LOADSAVE */
3115 _invent_event (GstPad * pad, GstBuffer * buffer)
3118 GstEventType event_type;
3121 if (GST_BUFFER_OFFSET_IS_VALID (buffer))
3122 event_type = GST_FORMAT_DEFAULT;
3124 event_type = GST_FORMAT_UNDEFINED;
3126 offset = GST_BUFFER_OFFSET (buffer);
3128 if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) {
3129 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
3131 event = gst_event_new_discontinuous (TRUE,
3132 GST_FORMAT_TIME, timestamp, event_type, offset, GST_FORMAT_UNDEFINED);
3133 GST_CAT_WARNING (GST_CAT_SCHEDULING,
3134 "needed to invent a DISCONT %p (time %" G_GUINT64_FORMAT
3135 ") for %s:%s => %s:%s", event, timestamp,
3136 GST_DEBUG_PAD_NAME (GST_PAD_PEER (pad)), GST_DEBUG_PAD_NAME (pad));
3138 event = gst_event_new_discontinuous (TRUE,
3139 event_type, offset, GST_FORMAT_UNDEFINED);
3140 GST_CAT_WARNING (GST_CAT_SCHEDULING,
3141 "needed to invent a DISCONT %p (no time) for %s:%s => %s:%s", event,
3142 GST_DEBUG_PAD_NAME (GST_PAD_PEER (pad)), GST_DEBUG_PAD_NAME (pad));
3145 return GST_DATA (event);
3150 * @pad: a source #GstPad.
3151 * @data: the #GstData to push.
3153 * Pushes a buffer or an event to the peer of @pad. @pad must be linked. May
3154 * only be called by @pad's parent.
3157 gst_pad_push (GstPad * pad, GstData * data)
3161 g_return_if_fail (GST_IS_PAD (pad));
3162 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
3163 g_return_if_fail (data != NULL);
3165 DEBUG_DATA (pad, data, "gst_pad_push");
3166 if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), &data))
3169 if (!GST_PAD_IS_LINKED (pad)) {
3170 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3171 "not pushing data %p as pad is unconnected", data);
3172 gst_data_unref (data);
3176 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing");
3177 peer = GST_RPAD_PEER (pad);
3180 g_warning ("push on pad %s:%s but it is unlinked",
3181 GST_DEBUG_PAD_NAME (pad));
3183 if (!GST_IS_EVENT (data) && !GST_PAD_IS_ACTIVE (peer)) {
3184 g_warning ("push on peer of pad %s:%s but peer is not active",
3185 GST_DEBUG_PAD_NAME (pad));
3189 if (peer->chainhandler) {
3191 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3192 "calling chainhandler &%s of peer pad %s:%s",
3193 GST_DEBUG_FUNCPTR_NAME (peer->chainhandler),
3194 GST_DEBUG_PAD_NAME (GST_PAD (peer)));
3195 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
3198 (peer->chainhandler) (GST_PAD (peer), data);
3201 g_warning ("trying to push a NULL buffer on pad %s:%s",
3202 GST_DEBUG_PAD_NAME (peer));
3206 g_warning ("internal error: push on pad %s:%s but it has no chainhandler",
3207 GST_DEBUG_PAD_NAME (peer));
3210 /* clean up the mess here */
3212 gst_data_unref (data);
3217 * @pad: a sink #GstPad.
3219 * Pulls an event or a buffer from the peer pad. May only be called by @pad's
3222 * Returns: a new #GstData from the peer pad.
3225 gst_pad_pull (GstPad * pad)
3230 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
3231 GST_DATA (gst_event_new (GST_EVENT_INTERRUPT)));
3233 peer = GST_RPAD_PEER (pad);
3236 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3237 ("pull on pad %s:%s but it was unlinked", GST_DEBUG_PAD_NAME (pad)));
3240 if (peer->gethandler) {
3241 GstPadLink *link = GST_RPAD_LINK (pad);
3243 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3244 "calling gethandler %s of peer pad %s:%s",
3245 GST_DEBUG_FUNCPTR_NAME (peer->gethandler), GST_DEBUG_PAD_NAME (peer));
3247 if (link->temp_store) {
3248 g_assert (link->engaged);
3249 GST_DEBUG ("moving temp_store %p to data", link->temp_store);
3250 data = link->temp_store;
3251 link->temp_store = NULL;
3253 data = (peer->gethandler) (GST_PAD (peer));
3254 /* refetch - we might have been relinked */
3255 link = GST_RPAD_LINK (pad);
3256 peer = GST_RPAD_PEER (pad);
3260 if (!link->engaged) {
3261 g_assert (link->temp_store == NULL);
3262 if (GST_IS_BUFFER (data)) {
3263 GST_DEBUG ("moving data buffer %p back to temp_store", data);
3264 link->temp_store = data;
3265 link->engaged = TRUE;
3266 data = _invent_event (pad, GST_BUFFER (data));
3267 } else if (GST_IS_EVENT (data) &&
3268 GST_EVENT_TYPE (data) == GST_EVENT_DISCONTINUOUS &&
3269 GST_EVENT_DISCONT_NEW_MEDIA (data)) {
3270 link->engaged = TRUE;
3271 GST_CAT_LOG (GST_CAT_SCHEDULING,
3272 "link engaged by discont event %p for pad %s:%s", data,
3273 GST_DEBUG_PAD_NAME (pad));
3276 GST_DEBUG ("calling gst_probe_dispatcher_dispatch on data %p", data);
3277 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
3279 DEBUG_DATA (pad, data, "gst_pad_pull returned");
3283 /* no null buffers allowed */
3284 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3285 ("NULL buffer during pull on %s:%s", GST_DEBUG_PAD_NAME (pad)));
3287 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3288 ("pull on pad %s:%s but the peer pad %s:%s has no gethandler",
3289 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer)));
3292 data = GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
3293 DEBUG_DATA (pad, data, "gst_pad_pull returned created");
3298 gst_pad_collect_array (GstScheduler * scheduler, GstPad ** selected,
3301 GstSchedulerClass *klass = GST_SCHEDULER_GET_CLASS (scheduler);
3303 if (!GST_FLAG_IS_SET (scheduler, GST_SCHEDULER_FLAG_NEW_API) ||
3304 !klass->pad_select) {
3305 /* better randomness? */
3307 *selected = padlist[0];
3308 return gst_pad_pull (padlist[0]);
3312 return klass->pad_select (scheduler, selected ? selected : &select,
3319 * @selected: set to the pad the buffer comes from if not NULL
3320 * @padlist: a #GList of sink pads.
3322 * Waits for a buffer on any of the list of pads. Each #GstPad in @padlist must
3323 * belong to the same element and be owned by the caller.
3325 * Returns: the #GstData that was available
3328 gst_pad_collectv (GstPad ** selected, const GList * padlist)
3330 /* need to use alloca here because we must not leak data */
3333 GstElement *element = NULL;
3336 g_return_val_if_fail (padlist != NULL, NULL);
3337 pads = g_alloca (sizeof (gpointer) * (g_list_length ((GList *) padlist) + 1));
3338 for (; padlist; padlist = g_list_next (padlist)) {
3339 test = GST_PAD (padlist->data);
3340 g_return_val_if_fail (GST_IS_PAD (test), NULL);
3341 g_return_val_if_fail (GST_PAD_IS_SINK (test), NULL);
3343 g_return_val_if_fail (element == gst_pad_get_parent (test), NULL);
3345 element = gst_pad_get_parent (test);
3351 return gst_pad_collect_array (GST_SCHEDULER (element), selected, pads);
3356 * @selected: set to the pad the buffer comes from if not NULL
3358 * @...: more sink pads.
3360 * Waits for a buffer on the given set of pads.
3362 * Returns: the #GstData that was available.
3365 gst_pad_collect (GstPad ** selected, GstPad * pad, ...)
3370 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3372 va_start (var_args, pad);
3374 result = gst_pad_collect_valist (selected, pad, var_args);
3382 * gst_pad_collect_valist:
3383 * @selected: set to the pad the buffer comes from if not NULL
3385 * @...: more sink pads.
3387 * Waits for a buffer on the given set of pads.
3389 * Returns: the #GstData that was available.
3392 gst_pad_collect_valist (GstPad ** selected, GstPad * pad, va_list var_args)
3395 GstElement *element = NULL;
3396 gint i = 0, maxlength;
3398 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3400 element = gst_pad_get_parent (pad);
3401 maxlength = element->numsinkpads;
3402 /* can we make this list a bit smaller than this upper limit? */
3403 padlist = g_alloca (sizeof (gpointer) * (maxlength + 1));
3405 g_return_val_if_fail (i < maxlength, NULL);
3406 g_return_val_if_fail (element == gst_pad_get_parent (pad), NULL);
3408 pad = va_arg (var_args, GstPad *);
3410 return gst_pad_collect_array (GST_SCHEDULER (element), selected, padlist);
3415 * @padlist: a #GList of sink pads.
3417 * Waits for a buffer on any of the list of pads. Each #GstPad in @padlist must
3418 * be owned by the calling code.
3420 * Returns: the #GstPad that has a buffer available.
3421 * Use #gst_pad_pull() to get the buffer.
3424 gst_pad_selectv (GList * padlist)
3430 * gst_pad_select_valist:
3431 * @pad: a first #GstPad to perform the select on.
3432 * @varargs: A va_list of more pads to select on.
3434 * Waits for a buffer on the given set of pads.
3436 * Returns: the #GstPad that has a buffer available.
3437 * Use #gst_pad_pull() to get the buffer.
3440 gst_pad_select_valist (GstPad * pad, va_list var_args)
3443 GList *padlist = NULL;
3449 padlist = g_list_prepend (padlist, pad);
3450 pad = va_arg (var_args, GstPad *);
3452 result = gst_pad_selectv (padlist);
3453 g_list_free (padlist);
3460 * @pad: a first sink #GstPad to perform the select on.
3461 * @...: A NULL-terminated list of more pads to select on.
3463 * Waits for a buffer on the given set of pads.
3465 * Returns: the #GstPad that has a buffer available.
3466 * Use #gst_pad_pull() to get the buffer.
3469 gst_pad_select (GstPad * pad, ...)
3477 va_start (var_args, pad);
3479 result = gst_pad_select_valist (pad, var_args);
3486 /************************************************************************
3491 static void gst_pad_template_class_init (GstPadTemplateClass * klass);
3492 static void gst_pad_template_init (GstPadTemplate * templ);
3493 static void gst_pad_template_dispose (GObject * object);
3496 gst_pad_template_get_type (void)
3498 static GType padtemplate_type = 0;
3500 if (!padtemplate_type) {
3501 static const GTypeInfo padtemplate_info = {
3502 sizeof (GstPadTemplateClass), NULL, NULL,
3503 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
3504 sizeof (GstPadTemplate),
3506 (GInstanceInitFunc) gst_pad_template_init, NULL
3510 g_type_register_static (GST_TYPE_OBJECT, "GstPadTemplate",
3511 &padtemplate_info, 0);
3513 return padtemplate_type;
3517 gst_pad_template_class_init (GstPadTemplateClass * klass)
3519 GObjectClass *gobject_class;
3520 GstObjectClass *gstobject_class;
3522 gobject_class = (GObjectClass *) klass;
3523 gstobject_class = (GstObjectClass *) klass;
3525 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
3527 gst_pad_template_signals[TEMPL_PAD_CREATED] =
3528 g_signal_new ("pad-created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
3529 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
3530 NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
3532 gobject_class->dispose = gst_pad_template_dispose;
3534 gstobject_class->path_string_separator = "*";
3538 gst_pad_template_init (GstPadTemplate * templ)
3543 gst_pad_template_dispose (GObject * object)
3545 GstPadTemplate *templ = GST_PAD_TEMPLATE (object);
3547 g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
3548 if (GST_PAD_TEMPLATE_CAPS (templ)) {
3549 gst_caps_free (GST_PAD_TEMPLATE_CAPS (templ));
3552 G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object);
3555 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
3557 * SOMETIMES padtemplates can do whatever they want, they are provided by the
3559 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
3560 * 'sink%d' template is automatically selected), so we need to restrict their
3564 name_is_valid (const gchar * name, GstPadPresence presence)
3568 if (presence == GST_PAD_ALWAYS) {
3569 if (strchr (name, '%')) {
3570 g_warning ("invalid name template %s: conversion specifications are not"
3571 " allowed for GST_PAD_ALWAYS padtemplates", name);
3574 } else if (presence == GST_PAD_REQUEST) {
3575 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
3576 g_warning ("invalid name template %s: only one conversion specification"
3577 " allowed in GST_PAD_REQUEST padtemplate", name);
3580 if (str && (*(str + 1) != 's' && *(str + 1) != 'd')) {
3581 g_warning ("invalid name template %s: conversion specification must be of"
3582 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
3585 if (str && (*(str + 2) != '\0')) {
3586 g_warning ("invalid name template %s: conversion specification must"
3587 " appear at the end of the GST_PAD_REQUEST padtemplate name", name);
3596 * gst_static_pad_template_get:
3597 * @pad_template: the static pad template
3599 * Converts a #GstStaticPadTemplate into a #GstPadTemplate.
3601 * Returns: a new #GstPadTemplate.
3604 gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
3606 GstPadTemplate *new;
3608 if (!name_is_valid (pad_template->name_template, pad_template->presence))
3611 new = g_object_new (gst_pad_template_get_type (),
3612 "name", pad_template->name_template, NULL);
3614 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (pad_template->name_template);
3615 GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction;
3616 GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence;
3618 GST_PAD_TEMPLATE_CAPS (new) =
3619 gst_caps_copy (gst_static_caps_get (&pad_template->static_caps));
3625 * gst_pad_template_new:
3626 * @name_template: the name template.
3627 * @direction: the #GstPadDirection of the template.
3628 * @presence: the #GstPadPresence of the pad.
3629 * @caps: a #GstCaps set for the template. The caps are taken ownership of.
3631 * Creates a new pad template with a name according to the given template
3632 * and with the given arguments. This functions takes ownership of the provided
3633 * caps, so be sure to not use them afterwards.
3635 * Returns: a new #GstPadTemplate.
3638 gst_pad_template_new (const gchar * name_template,
3639 GstPadDirection direction, GstPadPresence presence, GstCaps * caps)
3641 GstPadTemplate *new;
3643 g_return_val_if_fail (name_template != NULL, NULL);
3644 g_return_val_if_fail (caps != NULL, NULL);
3646 if (!name_is_valid (name_template, presence))
3650 #ifdef USE_POISONING
3652 GstCaps *newcaps = gst_caps_copy (caps);
3654 gst_caps_free (caps);
3659 new = g_object_new (gst_pad_template_get_type (),
3660 "name", name_template, NULL);
3662 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
3663 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
3664 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
3665 gst_caps_do_simplify (caps);
3666 GST_PAD_TEMPLATE_CAPS (new) = caps;
3672 * gst_pad_template_get_caps:
3673 * @templ: a #GstPadTemplate to get capabilities of.
3675 * Gets the capabilities of the pad template.
3677 * Returns: the #GstCaps of the pad template. If you need to keep a reference to
3678 * the caps, make a copy (see gst_caps_copy ()).
3681 gst_pad_template_get_caps (GstPadTemplate * templ)
3683 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
3685 return GST_PAD_TEMPLATE_CAPS (templ);
3689 * gst_pad_set_element_private:
3690 * @pad: the #GstPad to set the private data of.
3691 * @priv: The private data to attach to the pad.
3693 * Set the given private data gpointer on the pad.
3694 * This function can only be used by the element that owns the pad.
3697 gst_pad_set_element_private (GstPad * pad, gpointer priv)
3699 pad->element_private = priv;
3703 * gst_pad_get_element_private:
3704 * @pad: the #GstPad to get the private data of.
3706 * Gets the private data of a pad.
3708 * Returns: a #gpointer to the private data.
3711 gst_pad_get_element_private (GstPad * pad)
3713 return pad->element_private;
3717 /***** ghost pads *****/
3718 GType _gst_ghost_pad_type = 0;
3720 static void gst_ghost_pad_class_init (GstGhostPadClass * klass);
3721 static void gst_ghost_pad_init (GstGhostPad * pad);
3722 static void gst_ghost_pad_dispose (GObject * object);
3723 static void gst_ghost_pad_get_property (GObject * object, guint prop_id,
3724 GValue * value, GParamSpec * pspec);
3725 static void gst_ghost_pad_set_property (GObject * object, guint prop_id,
3726 const GValue * value, GParamSpec * pspec);
3728 static GstPad *ghost_pad_parent_class = NULL;
3730 /* static guint gst_ghost_pad_signals[LAST_SIGNAL] = { 0 }; */
3739 gst_ghost_pad_get_type (void)
3741 if (!_gst_ghost_pad_type) {
3742 static const GTypeInfo pad_info = {
3743 sizeof (GstGhostPadClass), NULL, NULL,
3744 (GClassInitFunc) gst_ghost_pad_class_init, NULL, NULL,
3745 sizeof (GstGhostPad),
3747 (GInstanceInitFunc) gst_ghost_pad_init,
3751 _gst_ghost_pad_type = g_type_register_static (GST_TYPE_PAD, "GstGhostPad",
3754 return _gst_ghost_pad_type;
3758 gst_ghost_pad_class_init (GstGhostPadClass * klass)
3760 GObjectClass *gobject_class;
3762 gobject_class = (GObjectClass *) klass;
3764 ghost_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
3766 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_ghost_pad_dispose);
3767 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_ghost_pad_set_property);
3768 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_ghost_pad_get_property);
3770 g_object_class_install_property (gobject_class, GPAD_ARG_REAL_PAD,
3771 g_param_spec_object ("real-pad", "Real pad",
3772 "The real pad for the ghost pad", GST_TYPE_PAD, G_PARAM_READWRITE));
3776 gst_ghost_pad_init (GstGhostPad * pad)
3778 /* zeroed by glib */
3782 gst_ghost_pad_dispose (GObject * object)
3784 g_object_set (object, "real-pad", NULL, NULL);
3786 G_OBJECT_CLASS (ghost_pad_parent_class)->dispose (object);
3790 gst_ghost_pad_set_property (GObject * object, guint prop_id,
3791 const GValue * value, GParamSpec * pspec)
3793 GstPad *ghostpad = (GstPad *) object;
3794 GstPad *oldrealpad = (GstPad *) GST_GPAD_REALPAD (ghostpad);
3795 GstPad *realpad = NULL;
3798 case GPAD_ARG_REAL_PAD:
3799 realpad = g_value_get_object (value);
3802 if (realpad == oldrealpad)
3805 gst_pad_remove_ghost_pad (oldrealpad, ghostpad);
3809 gst_pad_add_ghost_pad (realpad, ghostpad);
3813 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3819 gst_ghost_pad_get_property (GObject * object, guint prop_id,
3820 GValue * value, GParamSpec * pspec)
3823 case GPAD_ARG_REAL_PAD:
3824 g_value_set_object (value, GST_GPAD_REALPAD (object));
3828 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3834 * gst_ghost_pad_new:
3835 * @name: the name of the new ghost pad.
3836 * @pad: the #GstPad to create a ghost pad for.
3838 * Creates a new ghost pad associated with @pad, and named @name. If @name is
3839 * %NULL, a guaranteed unique name (across all ghost pads) will be assigned.
3841 * Returns: a new ghost #GstPad, or %NULL in case of an error.
3844 gst_ghost_pad_new (const gchar * name, GstPad * pad)
3848 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3850 gpad = g_object_new (GST_TYPE_GHOST_PAD, "name", name, "real-pad", pad, NULL);
3852 GST_CAT_DEBUG (GST_CAT_PADS, "created ghost pad \"%s\" for pad %s:%s",
3853 GST_OBJECT_NAME (gpad), GST_DEBUG_PAD_NAME (pad));
3859 * gst_pad_get_internal_links_default:
3860 * @pad: the #GstPad to get the internal links of.
3862 * Gets a list of pads to which the given pad is linked to
3863 * inside of the parent element.
3864 * This is the default handler, and thus returns a list of all of the
3865 * pads inside the parent element with opposite direction.
3866 * The caller must free this list after use.
3868 * Returns: a newly allocated #GList of pads.
3871 gst_pad_get_internal_links_default (GstPad * pad)
3876 GstPadDirection direction;
3879 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3881 rpad = GST_PAD_REALIZE (pad);
3882 direction = rpad->direction;
3884 parent = GST_PAD_PARENT (rpad);
3885 parent_pads = parent->pads;
3887 while (parent_pads) {
3888 GstRealPad *parent_pad = GST_PAD_REALIZE (parent_pads->data);
3890 if (parent_pad->direction != direction) {
3891 res = g_list_prepend (res, parent_pad);
3894 parent_pads = g_list_next (parent_pads);
3901 * gst_pad_get_internal_links:
3902 * @pad: the #GstPad to get the internal links of.
3904 * Gets a list of pads to which the given pad is linked to
3905 * inside of the parent element.
3906 * The caller must free this list after use.
3908 * Returns: a newly allocated #GList of pads.
3911 gst_pad_get_internal_links (GstPad * pad)
3916 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3918 rpad = GST_PAD_REALIZE (pad);
3920 if (GST_RPAD_INTLINKFUNC (rpad))
3921 res = GST_RPAD_INTLINKFUNC (rpad) (GST_PAD (rpad));
3928 gst_pad_event_default_dispatch (GstPad * pad, GstElement * element,
3933 GST_INFO_OBJECT (pad, "Sending event %p to all internally linked pads",
3936 orig = pads = gst_pad_get_internal_links (pad);
3939 GstPad *eventpad = GST_PAD (pads->data);
3941 pads = g_list_next (pads);
3943 /* for all of the internally-linked pads that are actually linked */
3944 if (GST_PAD_IS_LINKED (eventpad)) {
3945 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
3946 /* for each pad we send to, we should ref the event; it's up
3947 * to downstream to unref again when handled. */
3948 GST_LOG_OBJECT (pad, "Reffing and sending event %p to %s:%s", event,
3949 GST_DEBUG_PAD_NAME (eventpad));
3950 gst_event_ref (event);
3951 gst_pad_push (eventpad, GST_DATA (event));
3953 GstPad *peerpad = GST_PAD (GST_RPAD_PEER (eventpad));
3955 /* we only send the event on one pad, multi-sinkpad elements
3956 * should implement a handler */
3958 GST_LOG_OBJECT (pad, "sending event %p to one sink pad %s:%s", event,
3959 GST_DEBUG_PAD_NAME (eventpad));
3960 return gst_pad_send_event (peerpad, event);
3964 /* we handled the incoming event so we unref once */
3965 GST_LOG_OBJECT (pad, "handled event %p, unreffing", event);
3966 gst_event_unref (event);
3968 return (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
3972 * gst_pad_event_default:
3973 * @pad: a #GstPad to call the default event handler on.
3974 * @event: the #GstEvent to handle.
3976 * Invokes the default event handler for the given pad. End-of-stream and
3977 * discontinuity events are handled specially, and then the event is sent to all
3978 * pads internally linked to @pad. Note that if there are many possible sink
3979 * pads that are internally linked to @pad, only one will be sent an event.
3980 * Multi-sinkpad elements should implement custom event handlers.
3982 * Returns: TRUE if the event was sent succesfully.
3985 gst_pad_event_default (GstPad * pad, GstEvent * event)
3987 GstElement *element;
3989 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3990 g_return_val_if_fail (event != NULL, FALSE);
3992 element = GST_PAD_PARENT (pad);
3994 switch (GST_EVENT_TYPE (event)) {
3996 gst_pad_event_default_dispatch (pad, element, event);
3997 gst_element_set_eos (element);
3999 case GST_EVENT_DISCONTINUOUS:
4003 if (gst_element_requires_clock (element) && element->clock) {
4004 if (gst_event_discont_get_value (event, GST_FORMAT_TIME, &time)) {
4005 gst_element_set_time (element, time);
4007 GstFormat format = GST_FORMAT_TIME;
4010 for (i = 0; i < event->event_data.discont.noffsets; i++) {
4011 if (gst_pad_convert (pad,
4012 event->event_data.discont.offsets[i].format,
4013 event->event_data.discont.offsets[i].value, &format,
4015 gst_element_set_time (element, time);
4016 } else if (i == event->event_data.discont.noffsets) {
4018 ("can't adjust clock to new time when time not provided");
4025 return gst_pad_event_default_dispatch (pad, element, event);
4031 * gst_pad_dispatcher:
4032 * @pad: a #GstPad to dispatch.
4033 * @dispatch: the #GstDispatcherFunction to call.
4034 * @data: gpointer user data passed to the dispatcher function.
4036 * Invokes the given dispatcher function on all pads that are
4037 * internally linked to the given pad.
4038 * The GstPadDispatcherFunction should return TRUE when no further pads
4039 * need to be processed.
4041 * Returns: TRUE if one of the dispatcher functions returned TRUE.
4044 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
4047 gboolean res = FALSE;
4048 GList *int_pads, *orig;
4050 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4051 g_return_val_if_fail (dispatch != NULL, FALSE);
4053 orig = int_pads = gst_pad_get_internal_links (pad);
4056 GstRealPad *int_rpad = GST_PAD_REALIZE (int_pads->data);
4057 GstRealPad *int_peer = GST_RPAD_PEER (int_rpad);
4060 res = dispatch (GST_PAD (int_peer), data);
4064 int_pads = g_list_next (int_pads);
4073 * gst_pad_send_event:
4074 * @pad: a #GstPad to send the event to.
4075 * @event: the #GstEvent to send to the pad.
4077 * Sends the event to the pad.
4079 * Returns: TRUE if the event was handled.
4082 gst_pad_send_event (GstPad * pad, GstEvent * event)
4084 gboolean success = FALSE;
4088 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4089 g_return_val_if_fail (event != NULL, FALSE);
4090 parent = gst_pad_get_parent (pad);
4091 g_return_val_if_fail (GST_STATE (parent) >= GST_STATE_PAUSED, FALSE);
4093 rpad = GST_PAD_REALIZE (pad);
4096 if (GST_EVENT_SRC (event) == NULL)
4097 GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (rpad));
4099 GST_CAT_DEBUG (GST_CAT_EVENT, "have event type %d on pad %s:%s",
4100 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (rpad));
4102 if (GST_RPAD_EVENTHANDLER (rpad))
4103 success = GST_RPAD_EVENTHANDLER (rpad) (GST_PAD (rpad), event);
4105 g_warning ("pad %s:%s has no event handler", GST_DEBUG_PAD_NAME (rpad));
4106 gst_event_unref (event);
4114 GstFormat src_format;
4116 GstFormat *dest_format;
4122 gst_pad_convert_dispatcher (GstPad * pad, GstPadConvertData * data)
4124 return gst_pad_convert (pad, data->src_format, data->src_value,
4125 data->dest_format, data->dest_value);
4129 * gst_pad_convert_default:
4130 * @pad: a #GstPad to invoke the default converter on.
4131 * @src_format: the source #GstFormat.
4132 * @src_value: the source value.
4133 * @dest_format: a pointer to the destination #GstFormat.
4134 * @dest_value: a pointer to the destination value.
4136 * Invokes the default converter on a pad.
4137 * This will forward the call to the pad obtained
4138 * using the internal link of
4141 * Returns: TRUE if the conversion could be performed.
4144 gst_pad_convert_default (GstPad * pad,
4145 GstFormat src_format, gint64 src_value,
4146 GstFormat * dest_format, gint64 * dest_value)
4148 GstPadConvertData data;
4150 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4151 g_return_val_if_fail (dest_format != NULL, FALSE);
4152 g_return_val_if_fail (dest_value != NULL, FALSE);
4154 data.src_format = src_format;
4155 data.src_value = src_value;
4156 data.dest_format = dest_format;
4157 data.dest_value = dest_value;
4159 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
4160 gst_pad_convert_dispatcher, &data);
4165 * @pad: a #GstPad to invoke the default converter on.
4166 * @src_format: the source #GstFormat.
4167 * @src_value: the source value.
4168 * @dest_format: a pointer to the destination #GstFormat.
4169 * @dest_value: a pointer to the destination value.
4171 * Invokes a conversion on the pad.
4173 * Returns: TRUE if the conversion could be performed.
4176 gst_pad_convert (GstPad * pad,
4177 GstFormat src_format, gint64 src_value,
4178 GstFormat * dest_format, gint64 * dest_value)
4182 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4183 g_return_val_if_fail (dest_format != NULL, FALSE);
4184 g_return_val_if_fail (dest_value != NULL, FALSE);
4186 if (src_format == *dest_format) {
4187 *dest_value = src_value;
4191 rpad = GST_PAD_REALIZE (pad);
4193 if (GST_RPAD_CONVERTFUNC (rpad)) {
4194 return GST_RPAD_CONVERTFUNC (rpad) (GST_PAD (rpad), src_format,
4195 src_value, dest_format, dest_value);
4210 gst_pad_query_dispatcher (GstPad * pad, GstPadQueryData * data)
4212 return gst_pad_query (pad, data->type, data->format, data->value);
4216 * gst_pad_query_default:
4217 * @pad: a #GstPad to invoke the default query on.
4218 * @type: the #GstQueryType of the query to perform.
4219 * @format: a pointer to the #GstFormat of the result.
4220 * @value: a pointer to the result.
4222 * Invokes the default query function on a pad.
4224 * Returns: TRUE if the query could be performed.
4227 gst_pad_query_default (GstPad * pad, GstQueryType type,
4228 GstFormat * format, gint64 * value)
4230 GstPadQueryData data;
4232 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4233 g_return_val_if_fail (format != NULL, FALSE);
4234 g_return_val_if_fail (value != NULL, FALSE);
4237 data.format = format;
4240 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
4241 gst_pad_query_dispatcher, &data);
4246 * @pad: a #GstPad to invoke the default query on.
4247 * @type: the #GstQueryType of the query to perform.
4248 * @format: a pointer to the #GstFormat asked for.
4249 * On return contains the #GstFormat used.
4250 * @value: a pointer to the result.
4252 * Queries a pad for one of the available properties. The format will be
4253 * adjusted to the actual format used when specifying formats such as
4254 * GST_FORMAT_DEFAULT.
4255 * FIXME: Tell if the format can be adjusted when specifying a definite format.
4257 * Returns: TRUE if the query could be performed.
4260 gst_pad_query (GstPad * pad, GstQueryType type,
4261 GstFormat * format, gint64 * value)
4265 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4266 g_return_val_if_fail (format != NULL, FALSE);
4267 g_return_val_if_fail (value != NULL, FALSE);
4269 rpad = GST_PAD_REALIZE (pad);
4271 g_return_val_if_fail (rpad, FALSE);
4273 if (GST_RPAD_QUERYFUNC (rpad))
4274 return GST_RPAD_QUERYFUNC (rpad) (GST_PAD (pad), type, format, value);
4280 gst_pad_get_formats_dispatcher (GstPad * pad, const GstFormat ** data)
4282 *data = gst_pad_get_formats (pad);
4288 * gst_pad_get_formats_default:
4289 * @pad: a #GstPad to query
4291 * Invoke the default format dispatcher for the pad.
4293 * Returns: An array of GstFormats ended with a 0 value.
4296 gst_pad_get_formats_default (GstPad * pad)
4298 GstFormat *result = NULL;
4300 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4302 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
4303 gst_pad_get_formats_dispatcher, &result);
4309 * gst_pad_get_formats:
4310 * @pad: a #GstPad to query
4312 * Gets the list of supported formats from the pad.
4314 * Returns: An array of GstFormats ended with a 0 value.
4317 gst_pad_get_formats (GstPad * pad)
4321 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4323 rpad = GST_PAD_REALIZE (pad);
4325 if (GST_RPAD_FORMATSFUNC (rpad))
4326 return GST_RPAD_FORMATSFUNC (rpad) (GST_PAD (pad));
4331 #define CALL_CHAINFUNC(pad, data) G_STMT_START {\
4332 GstData *__temp = (data); \
4333 DEBUG_DATA (pad, __temp, "calling chain function with "); \
4334 if (GST_IS_EVENT (__temp) && \
4335 !GST_FLAG_IS_SET (gst_pad_get_parent (pad), GST_ELEMENT_EVENT_AWARE)) { \
4336 gst_pad_send_event (pad, GST_EVENT (__temp)); \
4338 GST_RPAD_CHAINFUNC (pad) (pad, __temp); \
4342 * gst_pad_call_chain_function:
4343 * @pad: sink pad to call chain function on
4344 * @data: data to call the chain function with
4346 * Calls the chain function of the given pad while making sure the internal
4347 * consistency is kept. Use this function inside schedulers instead of calling
4348 * the chain function yourself.
4351 gst_pad_call_chain_function (GstPad * pad, GstData * data)
4355 g_return_if_fail (GST_IS_REAL_PAD (pad));
4356 g_return_if_fail (GST_PAD_IS_SINK (pad));
4357 g_return_if_fail (data != NULL);
4358 g_return_if_fail (GST_RPAD_CHAINFUNC (pad) != NULL);
4359 g_return_if_fail (GST_RPAD_LINK (pad) != NULL);
4361 link = GST_RPAD_LINK (pad);
4362 if (!link->engaged) {
4363 g_assert (link->temp_store == NULL);
4364 if (GST_IS_BUFFER (data)) {
4365 GST_DEBUG ("moving data buffer %p back to temp_store", data);
4366 link->temp_store = data;
4367 link->engaged = TRUE;
4368 CALL_CHAINFUNC (pad, _invent_event (pad, GST_BUFFER (data)));
4369 link = GST_RPAD_LINK (pad);
4370 if (link->temp_store == NULL) /* happens after relinking in chainfunc */
4372 g_assert (link->temp_store == data);
4373 link->temp_store = NULL;
4374 } else if (GST_IS_EVENT (data) &&
4375 GST_EVENT_TYPE (data) == GST_EVENT_DISCONTINUOUS &&
4376 GST_EVENT_DISCONT_NEW_MEDIA (data)) {
4377 link->engaged = TRUE;
4378 GST_CAT_LOG (GST_CAT_SCHEDULING,
4379 "link engaged by discont event %p for pad %s:%s", data,
4380 GST_DEBUG_PAD_NAME (pad));
4383 CALL_CHAINFUNC (pad, data);
4387 * gst_pad_call_get_function:
4388 * @pad: sink pad to call chain function on
4390 * Calls the get function of the given pad while making sure the internal
4391 * consistency is kept. Use this function inside schedulers instead of calling
4392 * the get function yourself.
4394 * Returns: the data provided by the pad or NULL if no data was available.
4397 gst_pad_call_get_function (GstPad * pad)
4401 g_return_val_if_fail (GST_IS_REAL_PAD (pad), NULL);
4402 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
4403 g_return_val_if_fail (GST_RPAD_GETFUNC (pad) != NULL, NULL);
4405 data = GST_RPAD_GETFUNC (pad) (pad);
4406 DEBUG_DATA (pad, data, "getfunction returned");