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)", notice, data, \
40 GST_EVENT_TYPE (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 /* gtk_object_add_arg_type ("GstRealPad::active", G_TYPE_BOOLEAN, */
234 /* GTK_ARG_READWRITE, REAL_ARG_ACTIVE); */
235 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_ACTIVE,
236 g_param_spec_boolean ("active", "Active", "Whether the pad is active.",
237 TRUE, G_PARAM_READWRITE));
238 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_CAPS,
239 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
240 GST_TYPE_CAPS, G_PARAM_READABLE));
242 #ifndef GST_DISABLE_LOADSAVE
243 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
245 gstobject_class->path_string_separator = ".";
249 _gst_real_pad_fixate_accumulator (GSignalInvocationHint * ihint,
250 GValue * return_accu, const GValue * handler_return, gpointer dummy)
252 if (gst_value_get_caps (handler_return)) {
253 g_value_copy (handler_return, return_accu);
254 /* stop emission if something was returned */
261 gst_real_pad_init (GstRealPad * pad)
263 pad->direction = GST_PAD_UNKNOWN;
266 pad->chainfunc = NULL;
269 pad->chainhandler = NULL;
270 pad->gethandler = NULL;
272 pad->ghostpads = NULL;
275 pad->linkfunc = NULL;
276 pad->getcapsfunc = NULL;
278 pad->eventfunc = gst_pad_event_default;
279 pad->convertfunc = gst_pad_convert_default;
280 pad->queryfunc = gst_pad_query_default;
281 pad->intlinkfunc = gst_pad_get_internal_links_default;
283 pad->eventmaskfunc = gst_pad_get_event_masks_default;
284 pad->formatsfunc = gst_pad_get_formats_default;
285 pad->querytypefunc = gst_pad_get_query_types_default;
287 GST_FLAG_SET (pad, GST_PAD_DISABLED);
288 GST_FLAG_UNSET (pad, GST_PAD_NEGOTIATING);
290 gst_probe_dispatcher_init (&pad->probedisp);
294 gst_real_pad_set_property (GObject * object, guint prop_id,
295 const GValue * value, GParamSpec * pspec)
297 g_return_if_fail (GST_IS_PAD (object));
300 case REAL_ARG_ACTIVE:
301 gst_pad_set_active (GST_PAD (object), g_value_get_boolean (value));
304 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
310 gst_real_pad_get_property (GObject * object, guint prop_id,
311 GValue * value, GParamSpec * pspec)
313 g_return_if_fail (GST_IS_PAD (object));
316 case REAL_ARG_ACTIVE:
317 g_value_set_boolean (value, !GST_FLAG_IS_SET (object, GST_PAD_DISABLED));
320 g_value_set_boxed (value, GST_PAD_CAPS (GST_REAL_PAD (object)));
323 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
328 /* FIXME-0.9: Replace these custom functions with proper inheritance via _init
329 functions and object properties */
331 * gst_pad_custom_new:
332 * @type: the #Gtype of the pad.
333 * @name: the name of the new pad.
334 * @direction: the #GstPadDirection of the pad.
336 * Creates a new pad with the given name and type in the given direction.
337 * If name is NULL, a guaranteed unique name (across all pads)
340 * Returns: a new #GstPad, or NULL in case of an error.
343 gst_pad_custom_new (GType type, const gchar * name, GstPadDirection direction)
347 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
349 pad = g_object_new (type, NULL);
350 gst_object_set_name (GST_OBJECT (pad), name);
351 GST_RPAD_DIRECTION (pad) = direction;
353 return GST_PAD (pad);
358 * @name: the name of the new pad.
359 * @direction: the #GstPadDirection of the pad.
361 * Creates a new real pad with the given name in the given direction.
362 * If name is NULL, a guaranteed unique name (across all pads)
365 * Returns: a new #GstPad, or NULL in case of an error.
368 gst_pad_new (const gchar * name, GstPadDirection direction)
370 return gst_pad_custom_new (gst_real_pad_get_type (), name, direction);
374 * gst_pad_custom_new_from_template:
375 * @type: the custom #GType of the pad.
376 * @templ: the #GstPadTemplate to instantiate from.
377 * @name: the name of the new pad.
379 * Creates a new custom pad with the given name from the given template.
380 * If name is NULL, a guaranteed unique name (across all pads)
383 * Returns: a new #GstPad, or NULL in case of an error.
386 gst_pad_custom_new_from_template (GType type, GstPadTemplate * templ,
391 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
393 pad = gst_pad_custom_new (type, name, templ->direction);
394 gst_pad_set_pad_template (pad, templ);
400 * gst_pad_new_from_template:
401 * @templ: the pad template to use
402 * @name: the name of the element
404 * Creates a new real pad with the given name from the given template.
405 * If name is NULL, a guaranteed unique name (across all pads)
408 * Returns: a new #GstPad, or NULL in case of an error.
411 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
413 return gst_pad_custom_new_from_template (gst_real_pad_get_type (),
417 /* FIXME 0.9: GST_PAD_UNKNOWN needs to die! */
419 * gst_pad_get_direction:
420 * @pad: a #GstPad to get the direction of.
422 * Gets the direction of the pad.
424 * Returns: the #GstPadDirection of the pad.
427 gst_pad_get_direction (GstPad * pad)
429 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
431 if (GST_IS_REAL_PAD (pad))
432 return GST_PAD_DIRECTION (pad);
434 return GST_PAD_UNKNOWN;
438 * gst_pad_set_active:
439 * @pad: the #GstPad to activate or deactivate.
440 * @active: TRUE to activate the pad.
442 * Activates or deactivates the given pad.
445 gst_pad_set_active (GstPad * pad, gboolean active)
451 g_return_if_fail (GST_IS_PAD (pad));
453 old = GST_PAD_IS_ACTIVE (pad);
458 realpad = GST_PAD_REALIZE (pad);
461 GST_CAT_DEBUG (GST_CAT_PADS, "activating pad %s:%s",
462 GST_DEBUG_PAD_NAME (realpad));
463 GST_FLAG_UNSET (realpad, GST_PAD_DISABLED);
465 GST_CAT_DEBUG (GST_CAT_PADS, "de-activating pad %s:%s",
466 GST_DEBUG_PAD_NAME (realpad));
467 GST_FLAG_SET (realpad, GST_PAD_DISABLED);
469 link = GST_RPAD_LINK (realpad);
471 if (link->temp_store) {
472 GST_CAT_INFO (GST_CAT_PADS,
473 "deleting cached buffer from bufpen of pad %s:%s",
474 GST_DEBUG_PAD_NAME (realpad));
475 gst_data_unref (link->temp_store);
476 link->temp_store = NULL;
480 g_object_notify (G_OBJECT (realpad), "active");
485 * @pad: the #GstPad to query
487 * Query if a pad is active
489 * Returns: TRUE if the pad is active.
492 gst_pad_is_active (GstPad * pad)
494 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
496 return !GST_FLAG_IS_SET (pad, GST_PAD_DISABLED);
501 * @pad: a #GstPad to set the name of.
502 * @name: the name of the pad.
504 * Sets the name of a pad. If name is NULL, then a guaranteed unique
505 * name will be assigned.
508 gst_pad_set_name (GstPad * pad, const gchar * name)
510 g_return_if_fail (GST_IS_PAD (pad));
512 gst_object_set_name (GST_OBJECT (pad), name);
515 /* FIXME 0.9: This function must die */
518 * @pad: a #GstPad to get the name of.
520 * Gets the name of a pad.
522 * Returns: the name of the pad. This is not a newly allocated pointer
523 * so you must not free it.
526 gst_pad_get_name (GstPad * pad)
528 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
530 return GST_OBJECT_NAME (pad);
534 * gst_pad_set_chain_function:
535 * @pad: a real sink #GstPad.
536 * @chain: the #GstPadChainFunction to set.
538 * Sets the given chain function for the pad. The chain function is called to
539 * process a #GstData input buffer.
542 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
544 g_return_if_fail (GST_IS_REAL_PAD (pad));
545 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SINK);
547 GST_RPAD_CHAINFUNC (pad) = chain;
548 GST_CAT_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
549 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
553 * gst_pad_set_get_function:
554 * @pad: a real source #GstPad.
555 * @get: the #GstPadGetFunction to set.
557 * Sets the given get function for the pad. The get function is called to
558 * produce a new #GstData to start the processing pipeline. Get functions cannot
562 gst_pad_set_get_function (GstPad * pad, GstPadGetFunction get)
564 g_return_if_fail (GST_IS_REAL_PAD (pad));
565 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SRC);
567 GST_RPAD_GETFUNC (pad) = get;
569 GST_CAT_DEBUG (GST_CAT_PADS, "getfunc for %s:%s set to %s",
570 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
574 * gst_pad_set_event_function:
575 * @pad: a real source #GstPad.
576 * @event: the #GstPadEventFunction to set.
578 * Sets the given event handler for the pad.
581 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
583 g_return_if_fail (GST_IS_REAL_PAD (pad));
584 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SRC);
586 GST_RPAD_EVENTFUNC (pad) = event;
588 GST_CAT_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
589 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
593 * gst_pad_set_event_mask_function:
594 * @pad: a real #GstPad of either direction.
595 * @mask_func: the #GstPadEventMaskFunction to set.
597 * Sets the given event mask function for the pad.
600 gst_pad_set_event_mask_function (GstPad * pad,
601 GstPadEventMaskFunction mask_func)
603 g_return_if_fail (GST_IS_REAL_PAD (pad));
605 GST_RPAD_EVENTMASKFUNC (pad) = mask_func;
607 GST_CAT_DEBUG (GST_CAT_PADS, "eventmaskfunc for %s:%s set to %s",
608 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (mask_func));
612 * gst_pad_get_event_masks:
615 * Gets the array of eventmasks from the given pad.
617 * Returns: a zero-terminated array of #GstEventMask, or NULL if the pad does
618 * not have an event mask function.
621 gst_pad_get_event_masks (GstPad * pad)
625 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
627 rpad = GST_PAD_REALIZE (pad);
629 g_return_val_if_fail (rpad, FALSE);
631 if (GST_RPAD_EVENTMASKFUNC (rpad))
632 return GST_RPAD_EVENTMASKFUNC (rpad) (GST_PAD (pad));
638 gst_pad_get_event_masks_dispatcher (GstPad * pad, const GstEventMask ** data)
640 *data = gst_pad_get_event_masks (pad);
646 * gst_pad_get_event_masks_default:
649 * Invokes the default event masks dispatcher on the pad.
651 * Returns: a zero-terminated array of #GstEventMask, or NULL if none of the
652 * internally-linked pads have an event mask function.
655 gst_pad_get_event_masks_default (GstPad * pad)
657 GstEventMask *result = NULL;
659 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
661 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
662 gst_pad_get_event_masks_dispatcher, &result);
668 * gst_pad_set_convert_function:
669 * @pad: a real #GstPad of either direction.
670 * @convert: the #GstPadConvertFunction to set.
672 * Sets the given convert function for the pad.
675 gst_pad_set_convert_function (GstPad * pad, GstPadConvertFunction convert)
677 g_return_if_fail (GST_IS_REAL_PAD (pad));
679 GST_RPAD_CONVERTFUNC (pad) = convert;
681 GST_CAT_DEBUG (GST_CAT_PADS, "convertfunc for %s:%s set to %s",
682 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (convert));
686 * gst_pad_set_query_function:
687 * @pad: a real #GstPad of either direction.
688 * @query: the #GstPadQueryFunction to set.
690 * Set the given query function for the pad.
693 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
695 g_return_if_fail (GST_IS_REAL_PAD (pad));
697 GST_RPAD_QUERYFUNC (pad) = query;
699 GST_CAT_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
700 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
704 * gst_pad_set_query_type_function:
705 * @pad: a real #GstPad of either direction.
706 * @type_func: the #GstPadQueryTypeFunction to set.
708 * Set the given query type function for the pad.
711 gst_pad_set_query_type_function (GstPad * pad,
712 GstPadQueryTypeFunction type_func)
714 g_return_if_fail (GST_IS_REAL_PAD (pad));
716 GST_RPAD_QUERYTYPEFUNC (pad) = type_func;
718 GST_CAT_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
719 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
723 * gst_pad_get_query_types:
726 * Get an array of supported queries that can be performed
729 * Returns: a zero-terminated array of #GstQueryType.
732 gst_pad_get_query_types (GstPad * pad)
736 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
738 rpad = GST_PAD_REALIZE (pad);
740 g_return_val_if_fail (rpad, NULL);
742 if (GST_RPAD_QUERYTYPEFUNC (rpad))
743 return GST_RPAD_QUERYTYPEFUNC (rpad) (GST_PAD (pad));
749 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
751 *data = gst_pad_get_query_types (pad);
757 * gst_pad_get_query_types_default:
760 * Invoke the default dispatcher for the query types on
763 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
764 * internally-linked pads has a query types function.
767 gst_pad_get_query_types_default (GstPad * pad)
769 GstQueryType *result = NULL;
771 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
773 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
774 gst_pad_get_query_types_dispatcher, &result);
780 * gst_pad_set_internal_link_function:
781 * @pad: a real #GstPad of either direction.
782 * @intlink: the #GstPadIntLinkFunction to set.
784 * Sets the given internal link function for the pad.
787 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
789 g_return_if_fail (GST_IS_REAL_PAD (pad));
791 GST_RPAD_INTLINKFUNC (pad) = intlink;
792 GST_CAT_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
793 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
797 * gst_pad_set_formats_function:
798 * @pad: a real #GstPad of either direction.
799 * @formats: the #GstPadFormatsFunction to set.
801 * Sets the given formats function for the pad.
804 gst_pad_set_formats_function (GstPad * pad, GstPadFormatsFunction formats)
806 g_return_if_fail (GST_IS_REAL_PAD (pad));
808 GST_RPAD_FORMATSFUNC (pad) = formats;
809 GST_CAT_DEBUG (GST_CAT_PADS, "formats function for %s:%s set to %s",
810 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (formats));
814 * gst_pad_set_link_function:
815 * @pad: a real #GstPad.
816 * @link: the #GstPadLinkFunction to set.
818 * Sets the given link function for the pad. It will be called when the pad is
819 * linked or relinked with caps. The caps passed to the link function are
820 * guaranteed to be fixed. This means that you can assume that the caps is not
821 * ANY or EMPTY, and that there is exactly one structure in the caps, and that
822 * all the fields in the structure are fixed.
824 * The return value GST_PAD_LINK_OK should be used when the caps are acceptable,
825 * and you've extracted all the necessary information from the caps and set the
826 * element's internal state appropriately.
828 * The return value GST_PAD_LINK_REFUSED should be used when the caps are
829 * unacceptable for whatever reason.
831 * The return value GST_PAD_LINK_DELAYED should be used when the element is in a
832 * state where it can't determine whether the caps are acceptable or not. This
833 * is often used if the element needs to open a device or process data before
834 * determining acceptable caps.
836 * @link must not call gst_caps_try_set_caps() on the pad that was specified as
837 * a parameter, although it may (and often should) call gst_caps_try_set_caps()
841 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
843 g_return_if_fail (GST_IS_REAL_PAD (pad));
845 GST_RPAD_LINKFUNC (pad) = link;
846 GST_CAT_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
847 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
851 * gst_pad_set_unlink_function:
852 * @pad: a real #GstPad.
853 * @unlink: the #GstPadUnlinkFunction to set.
855 * Sets the given unlink function for the pad. It will be called
856 * when the pad is unlinked.
859 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
861 g_return_if_fail (GST_IS_REAL_PAD (pad));
863 GST_RPAD_UNLINKFUNC (pad) = unlink;
864 GST_CAT_DEBUG (GST_CAT_PADS, "unlinkfunc for %s:%s set to %s",
865 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (unlink));
869 * gst_pad_set_fixate_function:
870 * @pad: a real #GstPad.
871 * @fixate: the #GstPadFixateFunction to set.
873 * Sets the given fixate function for the pad. Its job is to narrow down the
874 * possible caps for a connection. Fixate functions are called with a const
875 * caps, and should return a caps that is a strict subset of the given caps.
876 * That is, @fixate should create a caps that is "more fixed" than previously,
877 * but it does not have to return fixed caps. If @fixate can't provide more
878 * fixed caps, it should return %NULL.
880 * Note that @fixate will only be called after the "fixate" signal is emitted,
881 * and only if the caps are still non-fixed.
884 gst_pad_set_fixate_function (GstPad * pad, GstPadFixateFunction fixate)
886 g_return_if_fail (GST_IS_REAL_PAD (pad));
888 GST_RPAD_FIXATEFUNC (pad) = fixate;
889 GST_CAT_DEBUG (GST_CAT_PADS, "fixatefunc for %s:%s set to %s",
890 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (fixate));
894 * gst_pad_set_getcaps_function:
895 * @pad: a real #GstPad.
896 * @getcaps: the #GstPadGetCapsFunction to set.
898 * Sets the given getcaps function for the pad. @getcaps should return the
899 * allowable caps for a pad in the context of the element's state, its link to
900 * other elements, and the devices or files it has opened. These caps must be a
901 * subset of the pad template caps. In the NULL state with no links, @getcaps
902 * should ideally return the same caps as the pad template. In rare
903 * circumstances, an object property can affect the caps returned by @getcaps,
904 * but this is discouraged.
906 * You do not need to call this function if @pad's allowed caps are always the
907 * same as the pad template caps.
909 * For most filters, the caps returned by @getcaps is directly affected by the
910 * allowed caps on other pads. For demuxers and decoders, the caps returned by
911 * the srcpad's getcaps function is directly related to the stream data. Again,
912 * @getcaps should return the most specific caps it reasonably can, since this
913 * helps with autoplugging. However, the returned caps should not depend on the
914 * stream type currently negotiated for @pad.
916 * Note that the return value from @getcaps is owned by the caller.
919 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
921 g_return_if_fail (GST_IS_REAL_PAD (pad));
923 GST_RPAD_GETCAPSFUNC (pad) = getcaps;
924 GST_CAT_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
925 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
929 * gst_pad_set_bufferalloc_function:
930 * @pad: a real sink #GstPad.
931 * @bufalloc: the #GstPadBufferAllocFunction to set.
933 * Sets the given bufferalloc function for the pad. Note that the
934 * bufferalloc function can only be set on sinkpads.
937 gst_pad_set_bufferalloc_function (GstPad * pad,
938 GstPadBufferAllocFunction bufalloc)
940 g_return_if_fail (GST_IS_REAL_PAD (pad));
941 g_return_if_fail (GST_PAD_IS_SINK (pad));
943 GST_RPAD_BUFFERALLOCFUNC (pad) = bufalloc;
944 GST_CAT_DEBUG (GST_CAT_PADS, "bufferallocfunc for %s:%s set to %s",
945 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufalloc));
948 /* FIXME 0.9: Do we actually want to allow the case where src and sink are
952 * @srcpad: the source #GstPad to unlink.
953 * @sinkpad: the sink #GstPad to unlink.
955 * Unlinks the source pad from the sink pad. Will emit the "unlinked" signal on
959 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
961 GstRealPad *realsrc, *realsink;
962 GstScheduler *src_sched, *sink_sched;
964 g_return_if_fail (GST_IS_PAD (srcpad));
965 g_return_if_fail (GST_IS_PAD (sinkpad));
967 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
968 GST_DEBUG_PAD_NAME (srcpad), srcpad,
969 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
971 realsrc = GST_PAD_REALIZE (srcpad);
972 realsink = GST_PAD_REALIZE (sinkpad);
974 g_return_if_fail (GST_RPAD_PEER (realsrc) != NULL);
975 g_return_if_fail (GST_RPAD_PEER (realsink) == realsrc);
977 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
978 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
985 g_return_if_fail ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
986 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK));
988 if (GST_RPAD_UNLINKFUNC (realsrc)) {
989 GST_RPAD_UNLINKFUNC (realsrc) (GST_PAD (realsrc));
991 if (GST_RPAD_UNLINKFUNC (realsink)) {
992 GST_RPAD_UNLINKFUNC (realsink) (GST_PAD (realsink));
995 /* get the schedulers before we unlink */
996 src_sched = gst_pad_get_scheduler (GST_PAD (realsrc));
997 sink_sched = gst_pad_get_scheduler (GST_PAD (realsink));
999 if (GST_RPAD_LINK (realsrc))
1000 gst_pad_link_free (GST_RPAD_LINK (realsrc));
1002 /* first clear peers */
1003 GST_RPAD_PEER (realsrc) = NULL;
1004 GST_RPAD_PEER (realsink) = NULL;
1005 GST_RPAD_LINK (realsrc) = NULL;
1006 GST_RPAD_LINK (realsink) = NULL;
1008 /* now tell the scheduler */
1009 if (src_sched && src_sched == sink_sched) {
1010 gst_scheduler_pad_unlink (src_sched, GST_PAD (realsrc), GST_PAD (realsink));
1013 /* hold a reference, as they can go away in the signal handlers */
1014 gst_object_ref (GST_OBJECT (realsrc));
1015 gst_object_ref (GST_OBJECT (realsink));
1017 /* fire off a signal to each of the pads telling them
1018 * that they've been unlinked */
1019 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_UNLINKED],
1021 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_UNLINKED],
1024 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1025 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1027 gst_object_unref (GST_OBJECT (realsrc));
1028 gst_object_unref (GST_OBJECT (realsink));
1032 * gst_pad_is_linked:
1033 * @pad: pad to check
1035 * Checks if a @pad is linked to another pad or not.
1037 * Returns: TRUE if the pad is linked, FALSE otherwise.
1040 gst_pad_is_linked (GstPad * pad)
1042 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1044 return GST_PAD_PEER (pad) != NULL;
1048 gst_pad_check_schedulers (GstRealPad * realsrc, GstRealPad * realsink)
1050 GstScheduler *src_sched, *sink_sched;
1051 gint num_decoupled = 0;
1053 src_sched = gst_pad_get_scheduler (GST_PAD (realsrc));
1054 sink_sched = gst_pad_get_scheduler (GST_PAD (realsink));
1056 if (src_sched && sink_sched) {
1057 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsrc), GST_ELEMENT_DECOUPLED))
1059 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsink), GST_ELEMENT_DECOUPLED))
1062 if (src_sched != sink_sched && num_decoupled != 1) {
1069 #define GST_PAD_LINK_SRC(pad) ((GST_PAD_IS_SRC (pad)) ? (pad) : GST_PAD_PEER (pad))
1070 #define GST_PAD_LINK_SINK(pad) ((GST_PAD_IS_SINK (pad)) ? (pad) : GST_PAD_PEER (pad))
1073 gst_pad_link_new (void)
1077 link = g_new0 (GstPadLink, 1);
1078 link->sinknotify = TRUE;
1079 link->srcnotify = TRUE;
1081 link->engaged = FALSE;
1086 gst_pad_link_free (GstPadLink * link)
1089 gst_caps_free (link->srccaps);
1091 gst_caps_free (link->sinkcaps);
1092 if (link->filtercaps)
1093 gst_caps_free (link->filtercaps);
1095 gst_caps_free (link->caps);
1096 if (link->temp_store)
1097 gst_data_unref (link->temp_store);
1098 #ifdef USE_POISONING
1099 memset (link, 0xff, sizeof (*link));
1105 gst_pad_link_intersect (GstPadLink * link)
1107 GstCaps *pad_intersection;
1110 gst_caps_free (link->caps);
1112 GST_DEBUG ("intersecting link from %s:%s to %s:%s",
1113 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1114 GST_DEBUG ("... srccaps %" GST_PTR_FORMAT, link->srccaps);
1115 GST_DEBUG ("... sinkcaps %" GST_PTR_FORMAT, link->sinkcaps);
1116 GST_DEBUG ("... filtercaps %" GST_PTR_FORMAT, link->filtercaps);
1118 pad_intersection = gst_caps_intersect (link->srccaps, link->sinkcaps);
1120 if (link->filtercaps) {
1121 GST_DEBUG ("unfiltered intersection %" GST_PTR_FORMAT, pad_intersection);
1122 link->caps = gst_caps_intersect (pad_intersection, link->filtercaps);
1123 gst_caps_free (pad_intersection);
1125 link->caps = pad_intersection;
1128 GST_DEBUG ("intersection %" GST_PTR_FORMAT, link->caps);
1132 gst_pad_link_ready_for_negotiation (GstPadLink * link)
1136 parent = GST_PAD_PARENT (link->srcpad);
1137 if (!parent || GST_STATE (parent) < GST_STATE_READY) {
1138 GST_DEBUG ("parent %s of pad %s:%s is not READY",
1139 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (link->srcpad));
1142 parent = GST_PAD_PARENT (link->sinkpad);
1143 if (!parent || GST_STATE (parent) < GST_STATE_READY) {
1144 GST_DEBUG ("parent %s of pad %s:%s is not READY",
1145 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (link->sinkpad));
1153 gst_pad_link_fixate (GstPadLink * link)
1160 g_return_if_fail (caps != NULL);
1161 g_return_if_fail (!gst_caps_is_empty (caps));
1163 GST_DEBUG ("trying to fixate caps %" GST_PTR_FORMAT, caps);
1165 gst_caps_do_simplify (caps);
1166 while (!gst_caps_is_fixed (caps)) {
1169 for (i = 0; i < 5; i++) {
1173 g_signal_emit (G_OBJECT (link->srcpad),
1174 gst_real_pad_signals[REAL_FIXATE], 0, caps, &newcaps);
1175 GST_DEBUG ("app srcpad signal fixated to %" GST_PTR_FORMAT, newcaps);
1178 g_signal_emit (G_OBJECT (link->sinkpad),
1179 gst_real_pad_signals[REAL_FIXATE], 0, caps, &newcaps);
1180 GST_DEBUG ("app sinkpad signal fixated to %" GST_PTR_FORMAT, newcaps);
1183 if (GST_RPAD_FIXATEFUNC (link->srcpad)) {
1185 GST_RPAD_FIXATEFUNC (link->srcpad) (GST_PAD (link->srcpad),
1187 GST_DEBUG ("srcpad %s:%s fixated to %" GST_PTR_FORMAT,
1188 GST_DEBUG_PAD_NAME (link->srcpad), newcaps);
1190 GST_DEBUG ("srcpad %s:%s doesn't have a fixate function",
1191 GST_DEBUG_PAD_NAME (link->srcpad));
1195 if (GST_RPAD_FIXATEFUNC (link->sinkpad)) {
1197 GST_RPAD_FIXATEFUNC (link->sinkpad) (GST_PAD (link->sinkpad),
1199 GST_DEBUG ("sinkpad %s:%s fixated to %" GST_PTR_FORMAT,
1200 GST_DEBUG_PAD_NAME (link->sinkpad), newcaps);
1202 GST_DEBUG ("sinkpad %s:%s doesn't have a fixate function",
1203 GST_DEBUG_PAD_NAME (link->sinkpad));
1206 newcaps = _gst_pad_default_fixate_func (GST_PAD (link->srcpad), caps);
1207 GST_DEBUG ("core fixated to %" GST_PTR_FORMAT, newcaps);
1211 G_GNUC_UNUSED gboolean bad;
1213 gst_caps_do_simplify (newcaps);
1214 #ifndef G_DISABLE_CHECKS
1215 /* some mad checking for correctly working fixation functions */
1218 /* we trust the default fixation function unconditionally */
1220 } else if (gst_caps_is_any (caps)) {
1221 bad = gst_caps_is_any (newcaps);
1223 GstCaps *test = gst_caps_subtract (caps, newcaps);
1225 bad = gst_caps_is_empty (test);
1226 gst_caps_free (test);
1227 /* simplifying is ok, too */
1229 bad = (gst_caps_get_size (newcaps) >= gst_caps_get_size (caps));
1232 gchar *newcaps_str = gst_caps_to_string (newcaps);
1233 gchar *caps_str = gst_caps_to_string (caps);
1236 ("a fixation function did not fixate correctly, the returned caps %s are no true subset of %s.",
1237 newcaps_str, caps_str);
1238 g_free (newcaps_str);
1240 gst_caps_free (newcaps);
1244 gst_caps_free (caps);
1255 static GstPadLinkReturn
1256 gst_pad_link_call_link_functions (GstPadLink * link)
1258 gboolean negotiating;
1259 GstPadLinkReturn res;
1261 if (link->srcnotify && GST_RPAD_LINKFUNC (link->srcpad)) {
1262 GST_DEBUG ("calling link function on pad %s:%s",
1263 GST_DEBUG_PAD_NAME (link->srcpad));
1265 negotiating = GST_FLAG_IS_SET (link->srcpad, GST_PAD_NEGOTIATING);
1267 /* set the NEGOTIATING flag if not already done */
1269 GST_FLAG_SET (link->srcpad, GST_PAD_NEGOTIATING);
1271 /* call the link function */
1272 res = GST_RPAD_LINKFUNC (link->srcpad) (GST_PAD (link->srcpad), link->caps);
1274 /* unset again after negotiating only if we set it */
1276 GST_FLAG_UNSET (link->srcpad, GST_PAD_NEGOTIATING);
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);
1289 if (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 negotiating = GST_FLAG_IS_SET (link->sinkpad, GST_PAD_NEGOTIATING);
1295 /* set the NEGOTIATING flag if not already done */
1297 GST_FLAG_SET (link->sinkpad, GST_PAD_NEGOTIATING);
1299 /* call the link function */
1300 res = GST_RPAD_LINKFUNC (link->sinkpad) (GST_PAD (link->sinkpad),
1303 /* unset again after negotiating only if we set it */
1305 GST_FLAG_UNSET (link->sinkpad, GST_PAD_NEGOTIATING);
1307 GST_DEBUG ("got reply %d from link function on pad %s:%s",
1308 res, GST_DEBUG_PAD_NAME (link->sinkpad));
1310 if (GST_PAD_LINK_FAILED (res)) {
1311 GST_CAT_INFO (GST_CAT_CAPS,
1312 "pad %s:%s doesn't accept caps %" GST_PTR_FORMAT,
1313 GST_DEBUG_PAD_NAME (link->sinkpad), link->caps);
1318 return GST_PAD_LINK_OK;
1321 static GstPadLinkReturn
1322 gst_pad_link_negotiate (GstPadLink * link)
1324 GST_DEBUG ("negotiating link from pad %s:%s to pad %s:%s",
1325 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1327 gst_pad_link_intersect (link);
1328 if (gst_caps_is_empty (link->caps))
1329 return GST_PAD_LINK_REFUSED;
1331 gst_pad_link_fixate (link);
1332 if (gst_caps_is_empty (link->caps))
1333 return GST_PAD_LINK_REFUSED;
1335 if (!gst_pad_link_ready_for_negotiation (link)) {
1336 return GST_PAD_LINK_DELAYED;
1338 GST_DEBUG ("trying to call link function on caps %" GST_PTR_FORMAT,
1341 return gst_pad_link_call_link_functions (link);
1346 * @link: link to try
1348 * Tries to (re)link the pads with the given link. The function takes ownership
1349 * of the supplied link. If the function returns FALSE and an old link existed,
1350 * that link can be assumed to work unchanged.
1352 * Returns: TRUE if the link succeeded, FALSE if not.
1355 gst_pad_link_try (GstPadLink * link)
1357 GstPad *srcpad, *sinkpad;
1358 GstPadLink *oldlink;
1359 GstPadLinkReturn ret;
1361 /* we use assertions here, because this function is static */
1363 srcpad = link->srcpad;
1365 sinkpad = link->sinkpad;
1367 oldlink = GST_RPAD_LINK (srcpad);
1368 g_assert (oldlink == GST_RPAD_LINK (sinkpad));
1370 GST_DEBUG ("negotiating given link");
1371 ret = gst_pad_link_negotiate (link);
1372 if (GST_PAD_LINK_FAILED (ret) && oldlink && oldlink->caps) {
1373 GST_DEBUG ("negotiating failed, but there was a valid old link");
1374 oldlink->srcnotify = link->srcnotify;
1375 oldlink->sinknotify = link->sinknotify;
1376 if (GST_PAD_LINK_FAILED (gst_pad_link_call_link_functions (oldlink))) {
1377 g_warning ("pads don't accept old caps. We assume they did though");
1380 if (ret == GST_PAD_LINK_REFUSED) {
1381 GST_DEBUG ("link refused, returning");
1382 gst_pad_link_free (link);
1385 if (ret == GST_PAD_LINK_DELAYED) {
1386 GST_DEBUG ("link delayed, replacing link caps and returning");
1387 gst_caps_replace (&link->caps, NULL);
1390 GST_RPAD_PEER (srcpad) = GST_REAL_PAD (link->sinkpad);
1391 GST_RPAD_PEER (sinkpad) = GST_REAL_PAD (link->srcpad);
1393 GST_DEBUG ("copying stuff from oldlink");
1394 link->temp_store = oldlink->temp_store;
1395 link->engaged = oldlink->engaged;
1396 oldlink->temp_store = NULL;
1397 gst_pad_link_free (oldlink);
1399 GST_RPAD_LINK (srcpad) = link;
1400 GST_RPAD_LINK (sinkpad) = link;
1401 if (ret == GST_PAD_LINK_OK) {
1402 GST_DEBUG ("notifying caps after successful link");
1403 g_object_notify (G_OBJECT (srcpad), "caps");
1404 g_object_notify (G_OBJECT (sinkpad), "caps");
1411 * gst_pad_renegotiate:
1414 * Initiate caps negotiation on @pad. @pad must be linked.
1416 * If @pad's parent is not at least in #GST_STATE_READY, returns
1417 * #GST_PAD_LINK_DELAYED.
1419 * Otherwise caps are retrieved from both @pad and its peer by calling their
1420 * getcaps functions. They are then intersected, returning #GST_PAD_LINK_FAIL if
1421 * there is no intersection.
1423 * The intersection is fixated if necessary, and then the link functions of @pad
1424 * and its peer are called.
1426 * Returns: The return value of @pad's link function (see
1427 * gst_pad_set_link_function()), or #GST_PAD_LINK_OK if there is no link
1430 * The macros GST_PAD_LINK_SUCCESSFUL() and GST_PAD_LINK_FAILED() should be used
1431 * when you just need success/failure information.
1434 gst_pad_renegotiate (GstPad * pad)
1438 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
1439 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1440 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1442 link = gst_pad_link_new ();
1444 link->srcpad = GST_PAD_LINK_SRC (pad);
1445 link->sinkpad = GST_PAD_LINK_SINK (pad);
1447 if (!gst_pad_link_ready_for_negotiation (link)) {
1448 gst_pad_link_free (link);
1449 return GST_PAD_LINK_DELAYED;
1452 if (GST_REAL_PAD (pad)->link->filtercaps) {
1453 link->filtercaps = gst_caps_copy (GST_REAL_PAD (pad)->link->filtercaps);
1455 link->srccaps = gst_pad_get_caps (link->srcpad);
1456 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1458 return gst_pad_link_try (link);
1462 * gst_pad_try_set_caps:
1464 * @caps: #GstCaps to set on @pad
1466 * Try to set the caps on @pad. @caps must be fixed. If @pad is unlinked,
1467 * returns #GST_PAD_LINK_OK without doing anything. Otherwise, start caps
1468 * negotiation on @pad.
1470 * Returns: The return value of @pad's link function (see
1471 * gst_pad_set_link_function()), or #GST_PAD_LINK_OK if there is no link
1474 * The macros GST_PAD_LINK_SUCCESSFUL() and GST_PAD_LINK_FAILED() should be used
1475 * when you just need success/failure information.
1478 gst_pad_try_set_caps (GstPad * pad, const GstCaps * caps)
1481 GstPadLink *oldlink;
1482 GstPadLinkReturn ret;
1484 g_return_val_if_fail (GST_IS_REAL_PAD (pad), GST_PAD_LINK_REFUSED);
1485 g_return_val_if_fail (!GST_PAD_IS_NEGOTIATING (pad), GST_PAD_LINK_REFUSED);
1487 /* setting non-fixed caps on a pad is not allowed */
1488 if (!gst_caps_is_fixed (caps)) {
1489 GST_CAT_INFO (GST_CAT_CAPS,
1490 "trying to set unfixed caps on pad %s:%s, not allowed",
1491 GST_DEBUG_PAD_NAME (pad));
1492 g_warning ("trying to set non fixed caps on pad %s:%s, not allowed",
1493 GST_DEBUG_PAD_NAME (pad));
1495 GST_DEBUG ("unfixed caps %" GST_PTR_FORMAT, caps);
1496 return GST_PAD_LINK_REFUSED;
1499 /* we allow setting caps on non-linked pads. It's ignored */
1500 if (!GST_PAD_PEER (pad)) {
1501 GST_DEBUG ("unlinked pad %s:%s, returning OK", GST_DEBUG_PAD_NAME (pad));
1502 return GST_PAD_LINK_OK;
1505 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1506 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1508 /* if the desired caps are already there, it's trivially ok */
1509 if (GST_PAD_CAPS (pad) && gst_caps_is_equal (caps, GST_PAD_CAPS (pad))) {
1510 GST_DEBUG ("pad %s:%s already has these caps", GST_DEBUG_PAD_NAME (pad));
1511 return GST_PAD_LINK_OK;
1514 link = gst_pad_link_new ();
1516 link->srcpad = GST_PAD_LINK_SRC (pad);
1517 link->sinkpad = GST_PAD_LINK_SINK (pad);
1519 if (!gst_pad_link_ready_for_negotiation (link)) {
1520 GST_DEBUG ("link not ready for negotiating, delaying");
1521 gst_pad_link_free (link);
1522 return GST_PAD_LINK_DELAYED;
1525 oldlink = GST_REAL_PAD (pad)->link;
1526 if (oldlink && oldlink->filtercaps) {
1527 link->filtercaps = gst_caps_copy (oldlink->filtercaps);
1529 if (link->srcpad == pad) {
1530 link->srccaps = gst_caps_copy (caps);
1531 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1532 link->srcnotify = FALSE;
1534 link->srccaps = gst_pad_get_caps (link->srcpad);
1535 link->sinkcaps = gst_caps_copy (caps);
1536 link->sinknotify = FALSE;
1539 GST_DEBUG ("trying to link");
1540 ret = gst_pad_link_try (link);
1546 * gst_pad_try_set_caps_nonfixed:
1547 * @pad: a real #GstPad
1548 * @caps: #GstCaps to set on @pad
1550 * Like gst_pad_try_set_caps(), but allows non-fixed caps.
1552 * Returns: a #GstPadLinkReturn, like gst_pad_try_set_caps().
1555 gst_pad_try_set_caps_nonfixed (GstPad * pad, const GstCaps * caps)
1558 GstPadLink *oldlink;
1559 GstPadLinkReturn ret;
1561 g_return_val_if_fail (GST_IS_REAL_PAD (pad), GST_PAD_LINK_REFUSED);
1562 g_return_val_if_fail (!GST_PAD_IS_NEGOTIATING (pad), GST_PAD_LINK_REFUSED);
1564 /* we allow setting caps on non-linked pads. It's ignored */
1565 if (!GST_PAD_PEER (pad)) {
1566 return GST_PAD_LINK_OK;
1569 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1570 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1572 /* if the link is already negotiated and the caps are compatible
1573 * with what we're setting, it's trivially OK. */
1574 if (GST_PAD_CAPS (pad)) {
1575 GstCaps *intersection;
1577 intersection = gst_caps_intersect (caps, GST_PAD_CAPS (pad));
1578 if (!gst_caps_is_empty (intersection)) {
1579 gst_caps_free (intersection);
1580 return GST_PAD_LINK_OK;
1582 gst_caps_free (intersection);
1585 link = gst_pad_link_new ();
1587 link->srcpad = GST_PAD_LINK_SRC (pad);
1588 link->sinkpad = GST_PAD_LINK_SINK (pad);
1590 if (!gst_pad_link_ready_for_negotiation (link)) {
1591 gst_pad_link_free (link);
1592 return GST_PAD_LINK_DELAYED;
1595 oldlink = GST_REAL_PAD (pad)->link;
1596 if (oldlink && oldlink->filtercaps) {
1597 link->filtercaps = gst_caps_copy (oldlink->filtercaps);
1599 if (link->srcpad == pad) {
1600 link->srccaps = gst_caps_copy (caps);
1601 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1602 link->srcnotify = FALSE;
1604 link->srccaps = gst_pad_get_caps (link->srcpad);
1605 link->sinkcaps = gst_caps_copy (caps);
1606 link->sinknotify = FALSE;
1609 ret = gst_pad_link_try (link);
1615 * gst_pad_can_link_filtered:
1616 * @srcpad: the source #GstPad to link.
1617 * @sinkpad: the sink #GstPad to link.
1618 * @filtercaps: the filter #GstCaps.
1620 * Checks if the source pad and the sink pad can be linked when constrained
1621 * by the given filter caps. Both @srcpad and @sinkpad must be unlinked.
1623 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1626 gst_pad_can_link_filtered (GstPad * srcpad, GstPad * sinkpad,
1627 const GstCaps * filtercaps)
1629 GstRealPad *realsrc, *realsink;
1632 /* FIXME This function is gross. It's almost a direct copy of
1633 * gst_pad_link_filtered(). Any decent programmer would attempt
1634 * to merge the two functions, which I will do some day. --ds
1637 /* generic checks */
1638 g_return_val_if_fail (srcpad != NULL, FALSE);
1639 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1640 g_return_val_if_fail (sinkpad != NULL, FALSE);
1641 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1643 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1644 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1646 /* now we need to deal with the real/ghost stuff */
1647 realsrc = GST_PAD_REALIZE (srcpad);
1648 realsink = GST_PAD_REALIZE (sinkpad);
1650 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1651 GST_CAT_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
1652 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1654 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1655 if (GST_RPAD_PEER (realsrc) != NULL) {
1656 GST_CAT_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1657 GST_DEBUG_PAD_NAME (realsrc));
1660 if (GST_RPAD_PEER (realsink) != NULL) {
1661 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1662 GST_DEBUG_PAD_NAME (realsink));
1665 if (GST_PAD_PARENT (realsrc) == NULL) {
1666 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1667 GST_DEBUG_PAD_NAME (realsrc));
1670 if (GST_PAD_PARENT (realsink) == NULL) {
1671 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has no parent, failed",
1672 GST_DEBUG_PAD_NAME (realsrc));
1676 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1677 g_warning ("linking pads with different scheds requires "
1678 "exactly one decoupled element (such as queue)");
1682 g_return_val_if_fail (realsrc != NULL, GST_PAD_LINK_REFUSED);
1683 g_return_val_if_fail (realsink != NULL, GST_PAD_LINK_REFUSED);
1685 link = gst_pad_link_new ();
1687 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
1688 link->srcpad = GST_PAD (realsrc);
1689 link->sinkpad = GST_PAD (realsink);
1691 link->srcpad = GST_PAD (realsink);
1692 link->sinkpad = GST_PAD (realsrc);
1695 if (GST_RPAD_DIRECTION (link->srcpad) != GST_PAD_SRC) {
1696 GST_CAT_INFO (GST_CAT_PADS,
1697 "Real src pad %s:%s is not a source pad, failed",
1698 GST_DEBUG_PAD_NAME (link->srcpad));
1699 gst_pad_link_free (link);
1702 if (GST_RPAD_DIRECTION (link->sinkpad) != GST_PAD_SINK) {
1703 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1704 GST_DEBUG_PAD_NAME (link->sinkpad));
1705 gst_pad_link_free (link);
1709 link->srccaps = gst_pad_get_caps (link->srcpad);
1710 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1712 link->filtercaps = gst_caps_copy (filtercaps);
1714 gst_pad_link_intersect (link);
1715 if (gst_caps_is_empty (link->caps)) {
1716 gst_pad_link_free (link);
1720 gst_pad_link_free (link);
1726 * @srcpad: the source #GstPad to link.
1727 * @sinkpad: the sink #GstPad to link.
1729 * Checks if the source pad and the sink pad can be linked.
1731 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1734 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1736 return gst_pad_can_link_filtered (srcpad, sinkpad, NULL);
1740 * gst_pad_link_filtered:
1741 * @srcpad: the source #GstPad to link.
1742 * @sinkpad: the sink #GstPad to link.
1743 * @filtercaps: the filter #GstCaps.
1745 * Links the source pad and the sink pad, constrained
1746 * by the given filter caps.
1748 * Returns: TRUE if the pads have been linked, FALSE otherwise.
1751 gst_pad_link_filtered (GstPad * srcpad, GstPad * sinkpad,
1752 const GstCaps * filtercaps)
1754 GstRealPad *realsrc, *realsink;
1755 GstScheduler *src_sched, *sink_sched;
1758 /* generic checks */
1759 g_return_val_if_fail (srcpad != NULL, FALSE);
1760 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1761 g_return_val_if_fail (sinkpad != NULL, FALSE);
1762 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1764 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1765 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1767 /* now we need to deal with the real/ghost stuff */
1768 realsrc = GST_PAD_REALIZE (srcpad);
1769 realsink = GST_PAD_REALIZE (sinkpad);
1771 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1772 GST_CAT_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
1773 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1775 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1776 if (GST_RPAD_PEER (realsrc) != NULL) {
1777 GST_CAT_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1778 GST_DEBUG_PAD_NAME (realsrc));
1781 if (GST_RPAD_PEER (realsink) != NULL) {
1782 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1783 GST_DEBUG_PAD_NAME (realsink));
1786 if (GST_PAD_PARENT (realsrc) == NULL) {
1787 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1788 GST_DEBUG_PAD_NAME (realsrc));
1791 if (GST_PAD_PARENT (realsink) == NULL) {
1792 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has no parent, failed",
1793 GST_DEBUG_PAD_NAME (realsrc));
1797 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1798 g_warning ("linking pads with different scheds requires "
1799 "exactly one decoupled element (such as queue)");
1803 g_return_val_if_fail (realsrc != NULL, GST_PAD_LINK_REFUSED);
1804 g_return_val_if_fail (realsink != NULL, GST_PAD_LINK_REFUSED);
1806 link = gst_pad_link_new ();
1808 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
1809 link->srcpad = GST_PAD (realsrc);
1810 link->sinkpad = GST_PAD (realsink);
1812 link->srcpad = GST_PAD (realsink);
1813 link->sinkpad = GST_PAD (realsrc);
1816 if (GST_RPAD_DIRECTION (link->srcpad) != GST_PAD_SRC) {
1817 GST_CAT_INFO (GST_CAT_PADS,
1818 "Real src pad %s:%s is not a source pad, failed",
1819 GST_DEBUG_PAD_NAME (link->srcpad));
1820 gst_pad_link_free (link);
1823 if (GST_RPAD_DIRECTION (link->sinkpad) != GST_PAD_SINK) {
1824 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1825 GST_DEBUG_PAD_NAME (link->sinkpad));
1826 gst_pad_link_free (link);
1830 link->srccaps = gst_pad_get_caps (link->srcpad);
1831 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1833 link->filtercaps = gst_caps_copy (filtercaps);
1834 if (gst_pad_link_try (link) == GST_PAD_LINK_REFUSED)
1837 /* fire off a signal to each of the pads telling them
1838 * that they've been linked */
1839 g_signal_emit (G_OBJECT (link->srcpad), gst_real_pad_signals[REAL_LINKED],
1841 g_signal_emit (G_OBJECT (link->sinkpad), gst_real_pad_signals[REAL_LINKED],
1844 src_sched = gst_pad_get_scheduler (GST_PAD (link->srcpad));
1845 sink_sched = gst_pad_get_scheduler (GST_PAD (link->sinkpad));
1847 /* now tell the scheduler */
1848 if (src_sched && src_sched == sink_sched) {
1849 gst_scheduler_pad_link (src_sched,
1850 GST_PAD (link->srcpad), GST_PAD (link->sinkpad));
1852 GST_CAT_INFO (GST_CAT_PADS,
1853 "not telling link to scheduler %s:%s and %s:%s, %p %p",
1854 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad),
1855 src_sched, sink_sched);
1858 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1859 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1866 * @srcpad: the source #GstPad to link.
1867 * @sinkpad: the sink #GstPad to link.
1869 * Links the source pad to the sink pad.
1871 * Returns: TRUE if the pad could be linked, FALSE otherwise.
1874 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
1876 return gst_pad_link_filtered (srcpad, sinkpad, NULL);
1879 /* FIXME 0.9: Remove this */
1881 * gst_pad_set_parent:
1882 * @pad: a #GstPad to set the parent of.
1883 * @parent: the new parent #GstElement.
1885 * Sets the parent object of a pad. Deprecated, use gst_object_set_parent()
1889 gst_pad_set_parent (GstPad * pad, GstElement * parent)
1891 g_return_if_fail (GST_IS_PAD (pad));
1892 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
1893 g_return_if_fail (GST_IS_ELEMENT (parent));
1895 gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (parent));
1898 /* FIXME 0.9: Remove this */
1900 * gst_pad_get_parent:
1901 * @pad: the #GstPad to get the parent of.
1903 * Gets the parent object of this pad. Deprecated, use gst_object_get_parent()
1906 * Returns: the parent #GstElement.
1909 gst_pad_get_parent (GstPad * pad)
1911 g_return_val_if_fail (pad != NULL, NULL);
1912 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1914 return GST_PAD_PARENT (pad);
1918 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
1920 /* this function would need checks if it weren't static */
1922 gst_object_replace ((GstObject **) & pad->padtemplate, (GstObject *) templ);
1925 gst_object_sink (GST_OBJECT (templ));
1926 g_signal_emit (G_OBJECT (templ),
1927 gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
1932 * gst_pad_get_pad_template:
1935 * Gets the template for @pad.
1937 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
1938 * if this pad has no template.
1941 gst_pad_get_pad_template (GstPad * pad)
1943 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1945 return GST_PAD_PAD_TEMPLATE (pad);
1950 * gst_pad_get_scheduler:
1951 * @pad: a #GstPad to get the scheduler of.
1953 * Gets the scheduler of the pad. Since the pad does not
1954 * have a scheduler of its own, the scheduler of the parent
1955 * is taken. For decoupled pads, the scheduler of the peer
1958 * Returns: the #GstScheduler of the pad, or %NULL if there is no parent or the
1959 * parent is not yet in a managing bin.
1962 gst_pad_get_scheduler (GstPad * pad)
1964 GstScheduler *scheduler = NULL;
1967 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1969 parent = gst_pad_get_parent (pad);
1971 if (GST_FLAG_IS_SET (parent, GST_ELEMENT_DECOUPLED)) {
1972 GstRealPad *peer = GST_RPAD_PEER (pad);
1976 gst_element_get_scheduler (gst_pad_get_parent (GST_PAD (peer)));
1979 scheduler = gst_element_get_scheduler (parent);
1987 * gst_pad_get_real_parent:
1988 * @pad: a #GstPad to get the real parent of.
1990 * Gets the real parent object of this pad. If the pad
1991 * is a ghost pad, the actual owner of the real pad is
1992 * returned, as opposed to #gst_pad_get_parent().
1994 * Returns: the parent #GstElement.
1997 gst_pad_get_real_parent (GstPad * pad)
1999 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2001 return GST_PAD_PARENT (GST_PAD (GST_PAD_REALIZE (pad)));
2004 /* FIXME 0.9: Make static. */
2006 * gst_pad_add_ghost_pad:
2007 * @pad: a #GstPad to attach the ghost pad to.
2008 * @ghostpad: the ghost #GstPad to to the pad.
2010 * Adds a ghost pad to a pad. Private function, will be removed from the API in
2014 gst_pad_add_ghost_pad (GstPad * pad, GstPad * ghostpad)
2016 GstRealPad *realpad;
2018 g_return_if_fail (GST_IS_PAD (pad));
2019 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
2021 /* if we're ghosting a ghost pad, drill down to find the real pad */
2022 realpad = (GstRealPad *) pad;
2023 while (GST_IS_GHOST_PAD (realpad))
2024 realpad = GST_GPAD_REALPAD (realpad);
2025 g_return_if_fail (GST_IS_REAL_PAD (realpad));
2027 /* will ref the pad template */
2028 GST_GPAD_REALPAD (ghostpad) = realpad;
2029 realpad->ghostpads = g_list_prepend (realpad->ghostpads, ghostpad);
2030 gst_pad_set_pad_template (GST_PAD (ghostpad), GST_PAD_PAD_TEMPLATE (pad));
2033 /* FIXME 0.9: Make static. */
2035 * gst_pad_remove_ghost_pad:
2036 * @pad: a #GstPad to remove the ghost pad from.
2037 * @ghostpad: the ghost #GstPad to remove from the pad.
2039 * Removes a ghost pad from a pad. Private, will be removed from the API in 0.9.
2042 gst_pad_remove_ghost_pad (GstPad * pad, GstPad * ghostpad)
2044 GstRealPad *realpad;
2046 g_return_if_fail (GST_IS_PAD (pad));
2047 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
2048 realpad = GST_PAD_REALIZE (pad);
2049 g_return_if_fail (GST_GPAD_REALPAD (ghostpad) == realpad);
2051 gst_pad_set_pad_template (GST_PAD (ghostpad), NULL);
2052 realpad->ghostpads = g_list_remove (realpad->ghostpads, ghostpad);
2053 GST_GPAD_REALPAD (ghostpad) = NULL;
2057 * gst_pad_get_ghost_pad_list:
2058 * @pad: a #GstPad to get the ghost pads of.
2060 * Gets the ghost pads of this pad.
2062 * Returns: a #GList of ghost pads.
2065 gst_pad_get_ghost_pad_list (GstPad * pad)
2067 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2069 return GST_PAD_REALIZE (pad)->ghostpads;
2073 _gst_pad_default_fixate_foreach (GQuark field_id, GValue * value, gpointer s)
2075 GstStructure *structure = (GstStructure *) s;
2076 GType type = G_VALUE_TYPE (value);
2078 if (gst_type_is_fixed (type))
2081 if (type == GST_TYPE_INT_RANGE) {
2082 gst_structure_set (structure, g_quark_to_string (field_id),
2083 G_TYPE_INT, gst_value_get_int_range_min (value), NULL);
2086 if (type == GST_TYPE_DOUBLE_RANGE) {
2087 gst_structure_set (structure, g_quark_to_string (field_id),
2088 G_TYPE_DOUBLE, gst_value_get_double_range_min (value), NULL);
2091 if (type == GST_TYPE_LIST) {
2092 gst_structure_set_value (structure, g_quark_to_string (field_id),
2093 gst_value_list_get_value (value, 0));
2097 g_critical ("don't know how to fixate type %s", g_type_name (type));
2102 _gst_pad_default_fixate_func (GstPad * pad, const GstCaps * caps)
2104 static GstStaticCaps octetcaps = GST_STATIC_CAPS ("application/octet-stream");
2105 GstStructure *structure;
2108 g_return_val_if_fail (pad != NULL, NULL);
2109 g_return_val_if_fail (caps != NULL, NULL);
2110 g_return_val_if_fail (!gst_caps_is_empty (caps), NULL);
2112 if (gst_caps_is_any (caps)) {
2113 return gst_caps_copy (gst_static_caps_get (&octetcaps));
2116 if (caps->structs->len > 1) {
2117 return gst_caps_new_full (gst_structure_copy (gst_caps_get_structure (caps,
2121 newcaps = gst_caps_copy (caps);
2122 structure = gst_caps_get_structure (newcaps, 0);
2123 gst_structure_foreach (structure, _gst_pad_default_fixate_foreach, structure);
2129 * gst_pad_perform_negotiate:
2130 * @srcpad: the source #GstPad.
2131 * @sinkpad: the sink #GstPad.
2133 * Tries to negotiate the pads. See gst_pad_renegotiate() for a brief
2134 * description of caps negotiation.
2136 * Returns: TRUE if the pads were succesfully negotiated, FALSE otherwise.
2139 gst_pad_perform_negotiate (GstPad * srcpad, GstPad * sinkpad)
2141 return GST_PAD_LINK_SUCCESSFUL (gst_pad_renegotiate (srcpad));
2145 gst_pad_link_unnegotiate (GstPadLink * link)
2147 g_return_if_fail (link != NULL);
2150 gst_caps_free (link->caps);
2152 link->engaged = FALSE;
2153 if (GST_RPAD_LINK (link->srcpad) != link) {
2154 g_warning ("unnegotiating unset link");
2156 g_object_notify (G_OBJECT (link->srcpad), "caps");
2158 if (GST_RPAD_LINK (link->sinkpad) != link) {
2159 g_warning ("unnegotiating unset link");
2161 g_object_notify (G_OBJECT (link->sinkpad), "caps");
2167 * gst_pad_unnegotiate:
2168 * @pad: pad to unnegotiate
2170 * "Unnegotiates" a pad. The currently negotiated caps are cleared and the pad
2171 * needs renegotiation.
2174 gst_pad_unnegotiate (GstPad * pad)
2178 g_return_if_fail (GST_IS_PAD (pad));
2180 link = GST_RPAD_LINK (GST_PAD_REALIZE (pad));
2182 gst_pad_link_unnegotiate (link);
2185 /* returning NULL indicates that the arguments are invalid */
2187 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad,
2188 const GstCaps * filtercaps)
2190 GstRealPad *realsrc, *realsink;
2193 g_return_val_if_fail (GST_IS_PAD (srcpad), NULL);
2194 g_return_val_if_fail (GST_IS_PAD (sinkpad), NULL);
2196 realsrc = GST_PAD_REALIZE (srcpad);
2197 realsink = GST_PAD_REALIZE (sinkpad);
2199 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
2200 GST_CAT_DEBUG (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
2201 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
2204 g_return_val_if_fail (GST_RPAD_PEER (realsrc) == NULL, NULL);
2205 g_return_val_if_fail (GST_RPAD_PEER (realsink) == NULL, NULL);
2206 g_return_val_if_fail (GST_PAD_PARENT (realsrc) != NULL, NULL);
2207 g_return_val_if_fail (GST_PAD_PARENT (realsink) != NULL, NULL);
2209 if (!gst_pad_check_schedulers (realsrc, realsink)) {
2210 g_warning ("linking pads with different scheds requires "
2211 "exactly one decoupled element (such as queue)");
2215 if (GST_RPAD_DIRECTION (realsrc) == GST_RPAD_DIRECTION (realsink)) {
2216 g_warning ("%s:%s and %s:%s are both %s pads, failed",
2217 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink),
2218 GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC ? "src" : "sink");
2222 link = gst_pad_link_new ();
2224 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
2225 link->srcpad = GST_PAD (realsrc);
2226 link->sinkpad = GST_PAD (realsink);
2228 link->srcpad = GST_PAD (realsink);
2229 link->sinkpad = GST_PAD (realsrc);
2232 link->srccaps = gst_pad_get_caps (link->srcpad);
2233 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
2235 link->filtercaps = gst_caps_copy (filtercaps);
2241 * gst_pad_try_relink_filtered:
2242 * @srcpad: the source #GstPad to relink.
2243 * @sinkpad: the sink #GstPad to relink.
2244 * @filtercaps: the #GstPad to use as a filter in the relink.
2246 * Tries to relink the given source and sink pad, constrained by the given
2249 * Returns: TRUE if the pads were succesfully renegotiated, FALSE otherwise.
2252 gst_pad_try_relink_filtered (GstPad * srcpad, GstPad * sinkpad,
2253 const GstCaps * filtercaps)
2257 GST_INFO ("trying to relink %" GST_PTR_FORMAT " and %" GST_PTR_FORMAT
2258 " with filtercaps %" GST_PTR_FORMAT, srcpad, sinkpad);
2260 link = gst_pad_link_prepare (srcpad, sinkpad, filtercaps);
2264 if (GST_RPAD_PEER (link->srcpad) != (GstRealPad *) link->sinkpad) {
2265 g_warning ("Pads %s:%s and %s:%s were never linked",
2266 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2267 gst_pad_link_free (link);
2271 if (GST_PAD_LINK_FAILED (gst_pad_link_try (link)))
2278 * gst_pad_relink_filtered:
2279 * @srcpad: the source #GstPad to relink.
2280 * @sinkpad: the sink #GstPad to relink.
2281 * @filtercaps: the #GstPad to use as a filter in the relink.
2283 * Relinks the given source and sink pad, constrained by the given
2284 * capabilities. If the relink fails, the pads are unlinked
2285 * and FALSE is returned.
2287 * Returns: TRUE if the pads were succesfully relinked, FALSE otherwise.
2290 gst_pad_relink_filtered (GstPad * srcpad, GstPad * sinkpad,
2291 const GstCaps * filtercaps)
2293 if (gst_pad_try_relink_filtered (srcpad, sinkpad, filtercaps))
2296 gst_pad_unlink (srcpad, sinkpad);
2301 * gst_pad_proxy_getcaps:
2302 * @pad: a #GstPad to proxy.
2304 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
2305 * same element as @pad, and returns the intersection of the results.
2307 * This function is useful as a default getcaps function for an element
2308 * that can handle any stream format, but requires all its pads to have
2309 * the same caps. Two such elements are tee and aggregator.
2311 * Returns: the intersection of the other pads' allowed caps.
2314 gst_pad_proxy_getcaps (GstPad * pad)
2316 GstElement *element;
2320 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2322 GST_DEBUG ("proxying getcaps for %s:%s", GST_DEBUG_PAD_NAME (pad));
2324 element = gst_pad_get_parent (pad);
2326 pads = gst_element_get_pad_list (element);
2328 caps = gst_caps_new_any ();
2330 GstPad *otherpad = GST_PAD (pads->data);
2333 if (otherpad != pad) {
2334 GstCaps *allowed = gst_pad_get_allowed_caps (otherpad);
2336 temp = gst_caps_intersect (caps, allowed);
2337 gst_caps_free (caps);
2338 gst_caps_free (allowed);
2342 pads = g_list_next (pads);
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_RPAD_GETCAPSFUNC (realpad)) {
2623 GST_CAT_DEBUG (GST_CAT_CAPS, "using pad getcaps function");
2624 caps = GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD (realpad));
2627 g_critical ("pad %s:%s returned NULL caps from getcaps function\n",
2628 GST_DEBUG_PAD_NAME (realpad));
2630 #ifndef G_DISABLE_ASSERT
2631 /* check that the returned caps are a real subset of the template caps */
2632 if (GST_PAD_PAD_TEMPLATE (realpad)) {
2633 const GstCaps *templ_caps =
2634 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (realpad));
2635 if (!gst_caps_is_subset (caps, templ_caps)) {
2638 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
2639 "pad returned caps %" GST_PTR_FORMAT
2640 " which are not a real subset of its template caps %"
2641 GST_PTR_FORMAT, caps, templ_caps);
2643 ("pad %s:%s returned caps that are not a real subset of its template caps",
2644 GST_DEBUG_PAD_NAME (realpad));
2645 temp = gst_caps_intersect (templ_caps, caps);
2646 gst_caps_free (caps);
2654 if (GST_PAD_PAD_TEMPLATE (realpad)) {
2655 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (realpad);
2656 const GstCaps *caps;
2658 caps = GST_PAD_TEMPLATE_CAPS (templ);
2659 GST_CAT_DEBUG (GST_CAT_CAPS,
2660 "using pad template %p with caps %" GST_PTR_FORMAT, templ, caps);
2663 /* FIXME we should enable something like this someday, but this is
2665 if (!gst_caps_is_fixed (caps)) {
2667 ("pad %s:%s (%p) has no getcaps function and the pad template returns non-fixed caps. Element is probably broken.\n",
2668 GST_DEBUG_PAD_NAME (realpad), realpad);
2672 return gst_caps_copy (GST_PAD_TEMPLATE_CAPS (templ));
2674 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
2678 g_warning ("pad %s:%s (%p) has no pad template\n",
2679 GST_DEBUG_PAD_NAME (realpad), realpad);
2682 return gst_caps_new_any ();
2686 * gst_pad_get_pad_template_caps:
2687 * @pad: a #GstPad to get the template capabilities from.
2689 * Gets the capabilities for @pad's template.
2691 * Returns: the #GstCaps of this pad template. If you intend to keep a reference
2692 * on the caps, make a copy (see gst_caps_copy ()).
2695 gst_pad_get_pad_template_caps (GstPad * pad)
2697 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2699 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2701 if (GST_PAD_PAD_TEMPLATE (pad))
2702 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2705 /* FIXME this should be enabled some day */
2706 /* wingo: why? mail the list during 0.9 when you find this :) */
2707 g_warning ("pad %s:%s (%p) has no pad template\n",
2708 GST_DEBUG_PAD_NAME (realpad), realpad);
2711 return gst_static_caps_get (&anycaps);
2714 /* FIXME 0.9: This function should probably die, or at least be renamed to
2715 * get_caps_by_format. */
2717 * gst_pad_template_get_caps_by_name:
2718 * @templ: a #GstPadTemplate to get the capabilities of.
2719 * @name: the name of the capability to get.
2721 * Gets the capability with the given name from @templ.
2723 * Returns: the #GstCaps of this pad template, or NULL if not found. If you
2724 * intend to keep a reference on the caps, make a copy (see gst_caps_copy ()).
2727 gst_pad_template_get_caps_by_name (GstPadTemplate * templ, const gchar * name)
2731 g_return_val_if_fail (templ != NULL, NULL);
2733 caps = GST_PAD_TEMPLATE_CAPS (templ);
2741 /* FIXME 0.9: What good is this if it only works for already-negotiated pads? */
2743 * gst_pad_check_compatibility:
2744 * @srcpad: the source #GstPad to check.
2745 * @sinkpad: the sink #GstPad to check against.
2747 * Checks if two pads have compatible capabilities. If neither one has yet been
2748 * negotiated, returns TRUE for no good reason.
2750 * Returns: TRUE if they are compatible or if the capabilities could not be
2751 * checked, FALSE if the capabilities are not compatible.
2754 gst_pad_check_compatibility (GstPad * srcpad, GstPad * sinkpad)
2756 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2757 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2759 if (GST_PAD_CAPS (srcpad) && GST_PAD_CAPS (sinkpad)) {
2760 if (!gst_caps_is_always_compatible (GST_PAD_CAPS (srcpad),
2761 GST_PAD_CAPS (sinkpad))) {
2767 GST_CAT_DEBUG (GST_CAT_PADS,
2768 "could not check capabilities of pads (%s:%s) and (%s:%s) %p %p",
2769 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2770 GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad));
2777 * @pad: a #GstPad to get the peer of.
2779 * Gets the peer of @pad.
2781 * Returns: the peer #GstPad.
2784 gst_pad_get_peer (GstPad * pad)
2786 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2788 return GST_PAD (GST_PAD_PEER (pad));
2792 * gst_pad_get_allowed_caps:
2793 * @pad: a real #GstPad.
2795 * Gets the capabilities of the allowed media types that can flow through @pad.
2796 * The caller must free the resulting caps.
2798 * Returns: the allowed #GstCaps of the pad link. Free the caps when
2799 * you no longer need it.
2802 gst_pad_get_allowed_caps (GstPad * pad)
2804 const GstCaps *mycaps;
2810 g_return_val_if_fail (GST_IS_REAL_PAD (pad), NULL);
2812 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting allowed caps",
2813 GST_DEBUG_PAD_NAME (pad));
2815 mycaps = gst_pad_get_pad_template_caps (pad);
2816 if (GST_RPAD_PEER (pad) == NULL) {
2817 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer, returning template",
2818 GST_DEBUG_PAD_NAME (pad));
2819 return gst_caps_copy (mycaps);
2822 peercaps = gst_pad_get_caps (GST_PAD_PEER (pad));
2823 caps = gst_caps_intersect (mycaps, peercaps);
2824 gst_caps_free (peercaps);
2826 link = GST_RPAD_LINK (pad);
2827 if (link->filtercaps) {
2828 icaps = gst_caps_intersect (caps, link->filtercaps);
2829 gst_caps_free (caps);
2830 GST_CAT_DEBUG (GST_CAT_PROPERTIES,
2831 "%s:%s: returning filtered intersection with peer",
2832 GST_DEBUG_PAD_NAME (pad));
2835 GST_CAT_DEBUG (GST_CAT_PROPERTIES,
2836 "%s:%s: returning unfiltered intersection with peer",
2837 GST_DEBUG_PAD_NAME (pad));
2843 * gst_pad_caps_change_notify:
2846 * Called to indicate that the return value of @pad's getcaps function may have
2847 * changed, and that a renegotiation is suggested.
2850 gst_pad_caps_change_notify (GstPad * pad)
2855 * gst_pad_recover_caps_error:
2856 * @pad: a #GstPad that had a failed capsnego
2857 * @allowed: possible caps for the link
2859 * Attempt to recover from a failed caps negotiation. This function
2860 * is typically called by a plugin that exhausted its list of caps
2861 * and wants the application to resolve the issue. The application
2862 * should connect to the pad's caps_nego_failed signal and should
2863 * resolve the issue by connecting another element for example.
2865 * Returns: TRUE when the issue was resolved, dumps detailed information
2866 * on the console and returns FALSE otherwise.
2869 gst_pad_recover_caps_error (GstPad * pad, const GstCaps * allowed)
2876 * gst_pad_alloc_buffer:
2877 * @pad: a source #GstPad
2878 * @offset: the offset of the new buffer in the stream
2879 * @size: the size of the new buffer
2881 * Allocates a new, empty buffer optimized to push to pad @pad. This
2882 * function only works if @pad is a source pad.
2884 * Returns: a new, empty #GstBuffer, or NULL if there is an error
2887 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size)
2891 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2892 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
2894 peer = GST_RPAD_PEER (pad);
2897 return gst_buffer_new_and_alloc (size);
2899 GST_CAT_DEBUG (GST_CAT_BUFFER, "(%s:%s): getting buffer",
2900 GST_DEBUG_PAD_NAME (pad));
2902 if (peer->bufferallocfunc) {
2903 GST_CAT_DEBUG (GST_CAT_PADS,
2904 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s",
2905 GST_DEBUG_FUNCPTR_NAME (peer->bufferallocfunc),
2906 &peer->bufferallocfunc, GST_DEBUG_PAD_NAME (((GstPad *) peer)));
2907 return (peer->bufferallocfunc) (GST_PAD (peer), offset, size);
2909 return gst_buffer_new_and_alloc (size);
2914 gst_real_pad_dispose (GObject * object)
2916 GstPad *pad = GST_PAD (object);
2918 /* No linked pad can ever be disposed.
2919 * It has to have a parent to be linked
2920 * and a parent would hold a reference */
2921 /* FIXME: what about if g_object_dispose is explicitly called on the pad? Is
2922 that legal? otherwise we could assert GST_OBJECT_PARENT (pad) == NULL as
2924 g_assert (GST_PAD_PEER (pad) == NULL);
2926 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s",
2927 GST_DEBUG_PAD_NAME (pad));
2929 /* we destroy the ghostpads, because they are nothing without the real pad */
2930 if (GST_REAL_PAD (pad)->ghostpads) {
2931 GList *orig, *ghostpads;
2933 orig = ghostpads = g_list_copy (GST_REAL_PAD (pad)->ghostpads);
2936 GstPad *ghostpad = GST_PAD (ghostpads->data);
2938 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))) {
2939 GstElement *parent = GST_ELEMENT (GST_OBJECT_PARENT (ghostpad));
2941 GST_CAT_DEBUG (GST_CAT_REFCOUNTING,
2942 "removing ghost pad from element '%s'", GST_OBJECT_NAME (parent));
2943 gst_element_remove_pad (parent, ghostpad);
2945 /* handle the case where we have some floating ghost pad that was never
2946 added to an element */
2947 g_object_set (ghostpad, "real-pad", NULL, NULL);
2949 ghostpads = g_list_next (ghostpads);
2952 /* as the ghost pads are removed, they remove themselves from ->ghostpads.
2953 So it should be empty now. Let's assert that. */
2954 g_assert (GST_REAL_PAD (pad)->ghostpads == NULL);
2957 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
2958 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
2959 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
2961 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
2964 if (GST_RPAD_EXPLICIT_CAPS (pad)) {
2965 GST_ERROR_OBJECT (pad, "still explicit caps %" GST_PTR_FORMAT " set",
2966 GST_RPAD_EXPLICIT_CAPS (pad));
2967 g_warning ("pad %p has still explicit caps set", pad);
2968 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2970 G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
2974 #ifndef GST_DISABLE_LOADSAVE
2975 /* FIXME: why isn't this on a GstElement ? */
2977 * gst_pad_load_and_link:
2978 * @self: an #xmlNodePtr to read the description from.
2979 * @parent: the #GstObject element that owns the pad.
2981 * Reads the pad definition from the XML node and links the given pad
2982 * in the element to a pad of an element up in the hierarchy.
2985 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
2987 xmlNodePtr field = self->xmlChildrenNode;
2988 GstPad *pad = NULL, *targetpad;
2992 GstObject *grandparent;
2995 if (!strcmp (field->name, "name")) {
2996 pad = gst_element_get_pad (GST_ELEMENT (parent),
2997 xmlNodeGetContent (field));
2998 } else if (!strcmp (field->name, "peer")) {
2999 peer = xmlNodeGetContent (field);
3001 field = field->next;
3003 g_return_if_fail (pad != NULL);
3008 split = g_strsplit (peer, ".", 2);
3010 if (split[0] == NULL || split[1] == NULL) {
3011 GST_CAT_DEBUG (GST_CAT_XML,
3012 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
3013 peer, GST_DEBUG_PAD_NAME (pad));
3017 g_return_if_fail (split[0] != NULL);
3018 g_return_if_fail (split[1] != NULL);
3020 grandparent = gst_object_get_parent (parent);
3022 if (grandparent && GST_IS_BIN (grandparent)) {
3023 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
3030 targetpad = gst_element_get_pad (target, split[1]);
3032 if (targetpad == NULL)
3035 gst_pad_link (pad, targetpad);
3042 * gst_pad_save_thyself:
3043 * @pad: a #GstPad to save.
3044 * @parent: the parent #xmlNodePtr to save the description in.
3046 * Saves the pad into an xml representation.
3048 * Returns: the #xmlNodePtr representation of the pad.
3051 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
3053 GstRealPad *realpad;
3056 g_return_val_if_fail (GST_IS_REAL_PAD (object), NULL);
3058 realpad = GST_REAL_PAD (object);
3060 xmlNewChild (parent, NULL, "name", GST_PAD_NAME (realpad));
3061 if (GST_RPAD_PEER (realpad) != NULL) {
3064 peer = GST_PAD (GST_RPAD_PEER (realpad));
3065 /* first check to see if the peer's parent's parent is the same */
3066 /* we just save it off */
3067 content = g_strdup_printf ("%s.%s",
3068 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
3069 xmlNewChild (parent, NULL, "peer", content);
3072 xmlNewChild (parent, NULL, "peer", "");
3077 /* FIXME: shouldn't it be gst_pad_ghost_* ?
3078 * dunno -- wingo 7 feb 2004
3081 * gst_ghost_pad_save_thyself:
3082 * @pad: a ghost #GstPad to save.
3083 * @parent: the parent #xmlNodePtr to save the description in.
3085 * Saves the ghost pad into an xml representation.
3087 * Returns: the #xmlNodePtr representation of the pad.
3090 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
3094 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
3096 self = xmlNewChild (parent, NULL, "ghostpad", NULL);
3097 xmlNewChild (self, NULL, "name", GST_PAD_NAME (pad));
3098 xmlNewChild (self, NULL, "parent", GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
3100 /* FIXME FIXME FIXME! */
3104 #endif /* GST_DISABLE_LOADSAVE */
3107 _invent_event (GstPad * pad, GstBuffer * buffer)
3110 GstEventType event_type;
3113 if (GST_BUFFER_OFFSET_IS_VALID (buffer))
3114 event_type = GST_FORMAT_DEFAULT;
3116 event_type = GST_FORMAT_UNDEFINED;
3118 offset = GST_BUFFER_OFFSET (buffer);
3120 if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) {
3121 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
3123 event = gst_event_new_discontinuous (TRUE,
3124 GST_FORMAT_TIME, timestamp, event_type, offset, GST_FORMAT_UNDEFINED);
3125 GST_CAT_WARNING (GST_CAT_SCHEDULING,
3126 "needed to invent a DISCONT (time %" G_GUINT64_FORMAT
3127 ") for %s:%s => %s:%s", timestamp,
3128 GST_DEBUG_PAD_NAME (GST_PAD_PEER (pad)), GST_DEBUG_PAD_NAME (pad));
3130 event = gst_event_new_discontinuous (TRUE,
3131 event_type, offset, GST_FORMAT_UNDEFINED);
3132 GST_CAT_WARNING (GST_CAT_SCHEDULING,
3133 "needed to invent a DISCONT (no time) for %s:%s => %s:%s",
3134 GST_DEBUG_PAD_NAME (GST_PAD_PEER (pad)), GST_DEBUG_PAD_NAME (pad));
3137 return GST_DATA (event);
3142 * @pad: a source #GstPad.
3143 * @data: the #GstData to push.
3145 * Pushes a buffer or an event to the peer of @pad. @pad must be linked. May
3146 * only be called by @pad's parent.
3149 gst_pad_push (GstPad * pad, GstData * data)
3153 g_return_if_fail (GST_IS_PAD (pad));
3154 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
3155 g_return_if_fail (data != NULL);
3157 DEBUG_DATA (pad, data, "gst_pad_push");
3158 if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), &data))
3161 if (!GST_PAD_IS_LINKED (pad)) {
3162 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3163 "not pushing data %p as pad is unconnected", data);
3164 gst_data_unref (data);
3168 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing");
3169 peer = GST_RPAD_PEER (pad);
3172 g_warning ("push on pad %s:%s but it is unlinked",
3173 GST_DEBUG_PAD_NAME (pad));
3175 if (!GST_IS_EVENT (data) && !GST_PAD_IS_ACTIVE (peer)) {
3176 g_warning ("push on peer of pad %s:%s but peer is not active",
3177 GST_DEBUG_PAD_NAME (pad));
3181 if (peer->chainhandler) {
3183 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3184 "calling chainhandler &%s of peer pad %s:%s",
3185 GST_DEBUG_FUNCPTR_NAME (peer->chainhandler),
3186 GST_DEBUG_PAD_NAME (GST_PAD (peer)));
3187 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
3190 (peer->chainhandler) (GST_PAD (peer), data);
3193 g_warning ("trying to push a NULL buffer on pad %s:%s",
3194 GST_DEBUG_PAD_NAME (peer));
3198 g_warning ("internal error: push on pad %s:%s but it has no chainhandler",
3199 GST_DEBUG_PAD_NAME (peer));
3202 /* clean up the mess here */
3204 gst_data_unref (data);
3209 * @pad: a sink #GstPad.
3211 * Pulls an event or a buffer from the peer pad. May only be called by @pad's
3214 * Returns: a new #GstData from the peer pad.
3217 gst_pad_pull (GstPad * pad)
3222 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
3223 GST_DATA (gst_event_new (GST_EVENT_INTERRUPT)));
3225 peer = GST_RPAD_PEER (pad);
3228 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3229 ("pull on pad %s:%s but it was unlinked", GST_DEBUG_PAD_NAME (pad)));
3232 if (peer->gethandler) {
3233 GstPadLink *link = GST_RPAD_LINK (pad);
3235 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3236 "calling gethandler %s of peer pad %s:%s",
3237 GST_DEBUG_FUNCPTR_NAME (peer->gethandler), GST_DEBUG_PAD_NAME (peer));
3239 if (link->temp_store) {
3240 g_assert (link->engaged);
3241 data = link->temp_store;
3242 link->temp_store = NULL;
3244 data = (peer->gethandler) (GST_PAD (peer));
3245 /* refetch - we might have been relinked */
3246 link = GST_RPAD_LINK (pad);
3247 peer = GST_RPAD_PEER (pad);
3251 if (!link->engaged) {
3252 g_assert (link->temp_store == NULL);
3253 if (GST_IS_BUFFER (data)) {
3254 link->temp_store = data;
3255 link->engaged = TRUE;
3256 data = _invent_event (pad, GST_BUFFER (data));
3257 } else if (GST_IS_EVENT (data) &&
3258 GST_EVENT_TYPE (data) == GST_EVENT_DISCONTINUOUS &&
3259 GST_EVENT_DISCONT_NEW_MEDIA (data)) {
3260 link->engaged = TRUE;
3261 GST_CAT_LOG (GST_CAT_SCHEDULING,
3262 "link engaged by discont event for pad %s:%s",
3263 GST_DEBUG_PAD_NAME (pad));
3266 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
3268 DEBUG_DATA (pad, data, "gst_pad_pull returned");
3272 /* no null buffers allowed */
3273 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3274 ("NULL buffer during pull on %s:%s", GST_DEBUG_PAD_NAME (pad)));
3276 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3277 ("pull on pad %s:%s but the peer pad %s:%s has no gethandler",
3278 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer)));
3281 data = GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
3282 DEBUG_DATA (pad, data, "gst_pad_pull returned created");
3287 gst_pad_collect_array (GstScheduler * scheduler, GstPad ** selected,
3290 GstSchedulerClass *klass = GST_SCHEDULER_GET_CLASS (scheduler);
3292 if (!GST_FLAG_IS_SET (scheduler, GST_SCHEDULER_FLAG_NEW_API) ||
3293 !klass->pad_select) {
3294 /* better randomness? */
3296 *selected = padlist[0];
3297 return gst_pad_pull (padlist[0]);
3301 return klass->pad_select (scheduler, selected ? selected : &select,
3308 * @selected: set to the pad the buffer comes from if not NULL
3309 * @padlist: a #GList of sink pads.
3311 * Waits for a buffer on any of the list of pads. Each #GstPad in @padlist must
3312 * belong to the same element and be owned by the caller.
3314 * Returns: the #GstData that was available
3317 gst_pad_collectv (GstPad ** selected, const GList * padlist)
3319 /* need to use alloca here because we must not leak data */
3322 GstElement *element = NULL;
3325 g_return_val_if_fail (padlist != NULL, NULL);
3326 pads = g_alloca (sizeof (gpointer) * (g_list_length ((GList *) padlist) + 1));
3327 for (; padlist; padlist = g_list_next (padlist)) {
3328 test = GST_PAD (padlist->data);
3329 g_return_val_if_fail (GST_IS_PAD (test), NULL);
3330 g_return_val_if_fail (GST_PAD_IS_SINK (test), NULL);
3332 g_return_val_if_fail (element == gst_pad_get_parent (test), NULL);
3334 element = gst_pad_get_parent (test);
3340 return gst_pad_collect_array (GST_SCHEDULER (element), selected, pads);
3345 * @selected: set to the pad the buffer comes from if not NULL
3347 * @...: more sink pads.
3349 * Waits for a buffer on the given set of pads.
3351 * Returns: the #GstData that was available.
3354 gst_pad_collect (GstPad ** selected, GstPad * pad, ...)
3359 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3361 va_start (var_args, pad);
3363 result = gst_pad_collect_valist (selected, pad, var_args);
3371 * gst_pad_collect_valist:
3372 * @selected: set to the pad the buffer comes from if not NULL
3374 * @...: more sink pads.
3376 * Waits for a buffer on the given set of pads.
3378 * Returns: the #GstData that was available.
3381 gst_pad_collect_valist (GstPad ** selected, GstPad * pad, va_list var_args)
3384 GstElement *element = NULL;
3385 gint i = 0, maxlength;
3387 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3389 element = gst_pad_get_parent (pad);
3390 maxlength = element->numsinkpads;
3391 /* can we make this list a bit smaller than this upper limit? */
3392 padlist = g_alloca (sizeof (gpointer) * (maxlength + 1));
3394 g_return_val_if_fail (i < maxlength, NULL);
3395 g_return_val_if_fail (element == gst_pad_get_parent (pad), NULL);
3397 pad = va_arg (var_args, GstPad *);
3399 return gst_pad_collect_array (GST_SCHEDULER (element), selected, padlist);
3404 * @padlist: a #GList of sink pads.
3406 * Waits for a buffer on any of the list of pads. Each #GstPad in @padlist must
3407 * be owned by the calling code.
3409 * Returns: the #GstPad that has a buffer available.
3410 * Use #gst_pad_pull() to get the buffer.
3413 gst_pad_selectv (GList * padlist)
3419 * gst_pad_select_valist:
3420 * @pad: a first #GstPad to perform the select on.
3421 * @varargs: A va_list of more pads to select on.
3423 * Waits for a buffer on the given set of pads.
3425 * Returns: the #GstPad that has a buffer available.
3426 * Use #gst_pad_pull() to get the buffer.
3429 gst_pad_select_valist (GstPad * pad, va_list var_args)
3432 GList *padlist = NULL;
3438 padlist = g_list_prepend (padlist, pad);
3439 pad = va_arg (var_args, GstPad *);
3441 result = gst_pad_selectv (padlist);
3442 g_list_free (padlist);
3449 * @pad: a first sink #GstPad to perform the select on.
3450 * @...: A NULL-terminated list of more pads to select on.
3452 * Waits for a buffer on the given set of pads.
3454 * Returns: the #GstPad that has a buffer available.
3455 * Use #gst_pad_pull() to get the buffer.
3458 gst_pad_select (GstPad * pad, ...)
3466 va_start (var_args, pad);
3468 result = gst_pad_select_valist (pad, var_args);
3475 /************************************************************************
3480 static void gst_pad_template_class_init (GstPadTemplateClass * klass);
3481 static void gst_pad_template_init (GstPadTemplate * templ);
3482 static void gst_pad_template_dispose (GObject * object);
3485 gst_pad_template_get_type (void)
3487 static GType padtemplate_type = 0;
3489 if (!padtemplate_type) {
3490 static const GTypeInfo padtemplate_info = {
3491 sizeof (GstPadTemplateClass), NULL, NULL,
3492 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
3493 sizeof (GstPadTemplate),
3495 (GInstanceInitFunc) gst_pad_template_init, NULL
3499 g_type_register_static (GST_TYPE_OBJECT, "GstPadTemplate",
3500 &padtemplate_info, 0);
3502 return padtemplate_type;
3506 gst_pad_template_class_init (GstPadTemplateClass * klass)
3508 GObjectClass *gobject_class;
3509 GstObjectClass *gstobject_class;
3511 gobject_class = (GObjectClass *) klass;
3512 gstobject_class = (GstObjectClass *) klass;
3514 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
3516 gst_pad_template_signals[TEMPL_PAD_CREATED] =
3517 g_signal_new ("pad-created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
3518 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
3519 NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
3521 gobject_class->dispose = gst_pad_template_dispose;
3523 gstobject_class->path_string_separator = "*";
3527 gst_pad_template_init (GstPadTemplate * templ)
3532 gst_pad_template_dispose (GObject * object)
3534 GstPadTemplate *templ = GST_PAD_TEMPLATE (object);
3536 g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
3537 if (GST_PAD_TEMPLATE_CAPS (templ)) {
3538 gst_caps_free (GST_PAD_TEMPLATE_CAPS (templ));
3541 G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object);
3544 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
3546 * SOMETIMES padtemplates can do whatever they want, they are provided by the
3548 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
3549 * 'sink%d' template is automatically selected), so we need to restrict their
3553 name_is_valid (const gchar * name, GstPadPresence presence)
3557 if (presence == GST_PAD_ALWAYS) {
3558 if (strchr (name, '%')) {
3559 g_warning ("invalid name template %s: conversion specifications are not"
3560 " allowed for GST_PAD_ALWAYS padtemplates", name);
3563 } else if (presence == GST_PAD_REQUEST) {
3564 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
3565 g_warning ("invalid name template %s: only one conversion specification"
3566 " allowed in GST_PAD_REQUEST padtemplate", name);
3569 if (str && (*(str + 1) != 's' && *(str + 1) != 'd')) {
3570 g_warning ("invalid name template %s: conversion specification must be of"
3571 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
3574 if (str && (*(str + 2) != '\0')) {
3575 g_warning ("invalid name template %s: conversion specification must"
3576 " appear at the end of the GST_PAD_REQUEST padtemplate name", name);
3585 * gst_static_pad_template_get:
3586 * @pad_template: the static pad template
3588 * Converts a #GstStaticPadTemplate into a #GstPadTemplate.
3590 * Returns: a new #GstPadTemplate.
3593 gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
3595 GstPadTemplate *new;
3597 if (!name_is_valid (pad_template->name_template, pad_template->presence))
3600 new = g_object_new (gst_pad_template_get_type (),
3601 "name", pad_template->name_template, NULL);
3603 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (pad_template->name_template);
3604 GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction;
3605 GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence;
3607 GST_PAD_TEMPLATE_CAPS (new) =
3608 gst_caps_copy (gst_static_caps_get (&pad_template->static_caps));
3614 * gst_pad_template_new:
3615 * @name_template: the name template.
3616 * @direction: the #GstPadDirection of the template.
3617 * @presence: the #GstPadPresence of the pad.
3618 * @caps: a #GstCaps set for the template. The caps are taken ownership of.
3620 * Creates a new pad template with a name according to the given template
3621 * and with the given arguments. This functions takes ownership of the provided
3622 * caps, so be sure to not use them afterwards.
3624 * Returns: a new #GstPadTemplate.
3627 gst_pad_template_new (const gchar * name_template,
3628 GstPadDirection direction, GstPadPresence presence, GstCaps * caps)
3630 GstPadTemplate *new;
3632 g_return_val_if_fail (name_template != NULL, NULL);
3633 g_return_val_if_fail (caps != NULL, NULL);
3635 if (!name_is_valid (name_template, presence))
3639 #ifdef USE_POISONING
3641 GstCaps *newcaps = gst_caps_copy (caps);
3643 gst_caps_free (caps);
3648 new = g_object_new (gst_pad_template_get_type (),
3649 "name", name_template, NULL);
3651 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
3652 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
3653 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
3654 gst_caps_do_simplify (caps);
3655 GST_PAD_TEMPLATE_CAPS (new) = caps;
3661 * gst_pad_template_get_caps:
3662 * @templ: a #GstPadTemplate to get capabilities of.
3664 * Gets the capabilities of the pad template.
3666 * Returns: the #GstCaps of the pad template. If you need to keep a reference to
3667 * the caps, make a copy (see gst_caps_copy ()).
3670 gst_pad_template_get_caps (GstPadTemplate * templ)
3672 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
3674 return GST_PAD_TEMPLATE_CAPS (templ);
3678 * gst_pad_set_element_private:
3679 * @pad: the #GstPad to set the private data of.
3680 * @priv: The private data to attach to the pad.
3682 * Set the given private data gpointer on the pad.
3683 * This function can only be used by the element that owns the pad.
3686 gst_pad_set_element_private (GstPad * pad, gpointer priv)
3688 pad->element_private = priv;
3692 * gst_pad_get_element_private:
3693 * @pad: the #GstPad to get the private data of.
3695 * Gets the private data of a pad.
3697 * Returns: a #gpointer to the private data.
3700 gst_pad_get_element_private (GstPad * pad)
3702 return pad->element_private;
3706 /***** ghost pads *****/
3707 GType _gst_ghost_pad_type = 0;
3709 static void gst_ghost_pad_class_init (GstGhostPadClass * klass);
3710 static void gst_ghost_pad_init (GstGhostPad * pad);
3711 static void gst_ghost_pad_dispose (GObject * object);
3712 static void gst_ghost_pad_get_property (GObject * object, guint prop_id,
3713 GValue * value, GParamSpec * pspec);
3714 static void gst_ghost_pad_set_property (GObject * object, guint prop_id,
3715 const GValue * value, GParamSpec * pspec);
3717 static GstPad *ghost_pad_parent_class = NULL;
3719 /* static guint gst_ghost_pad_signals[LAST_SIGNAL] = { 0 }; */
3728 gst_ghost_pad_get_type (void)
3730 if (!_gst_ghost_pad_type) {
3731 static const GTypeInfo pad_info = {
3732 sizeof (GstGhostPadClass), NULL, NULL,
3733 (GClassInitFunc) gst_ghost_pad_class_init, NULL, NULL,
3734 sizeof (GstGhostPad),
3736 (GInstanceInitFunc) gst_ghost_pad_init,
3740 _gst_ghost_pad_type = g_type_register_static (GST_TYPE_PAD, "GstGhostPad",
3743 return _gst_ghost_pad_type;
3747 gst_ghost_pad_class_init (GstGhostPadClass * klass)
3749 GObjectClass *gobject_class;
3751 gobject_class = (GObjectClass *) klass;
3753 ghost_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
3755 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_ghost_pad_dispose);
3756 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_ghost_pad_set_property);
3757 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_ghost_pad_get_property);
3759 g_object_class_install_property (gobject_class, GPAD_ARG_REAL_PAD,
3760 g_param_spec_object ("real-pad", "Real pad",
3761 "The real pad for the ghost pad", GST_TYPE_PAD, G_PARAM_READWRITE));
3765 gst_ghost_pad_init (GstGhostPad * pad)
3767 /* zeroed by glib */
3771 gst_ghost_pad_dispose (GObject * object)
3773 g_object_set (object, "real-pad", NULL, NULL);
3775 G_OBJECT_CLASS (ghost_pad_parent_class)->dispose (object);
3779 gst_ghost_pad_set_property (GObject * object, guint prop_id,
3780 const GValue * value, GParamSpec * pspec)
3782 GstPad *ghostpad = (GstPad *) object;
3783 GstPad *oldrealpad = (GstPad *) GST_GPAD_REALPAD (ghostpad);
3784 GstPad *realpad = NULL;
3787 case GPAD_ARG_REAL_PAD:
3788 realpad = g_value_get_object (value);
3791 if (realpad == oldrealpad)
3794 gst_pad_remove_ghost_pad (oldrealpad, ghostpad);
3798 gst_pad_add_ghost_pad (realpad, ghostpad);
3802 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3808 gst_ghost_pad_get_property (GObject * object, guint prop_id,
3809 GValue * value, GParamSpec * pspec)
3812 case GPAD_ARG_REAL_PAD:
3813 g_value_set_object (value, GST_GPAD_REALPAD (object));
3817 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3823 * gst_ghost_pad_new:
3824 * @name: the name of the new ghost pad.
3825 * @pad: the #GstPad to create a ghost pad for.
3827 * Creates a new ghost pad associated with @pad, and named @name. If @name is
3828 * %NULL, a guaranteed unique name (across all ghost pads) will be assigned.
3830 * Returns: a new ghost #GstPad, or %NULL in case of an error.
3833 gst_ghost_pad_new (const gchar * name, GstPad * pad)
3837 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3839 gpad = g_object_new (GST_TYPE_GHOST_PAD, "name", name, "real-pad", pad, NULL);
3841 GST_CAT_DEBUG (GST_CAT_PADS, "created ghost pad \"%s\" for pad %s:%s",
3842 GST_OBJECT_NAME (gpad), GST_DEBUG_PAD_NAME (pad));
3848 * gst_pad_get_internal_links_default:
3849 * @pad: the #GstPad to get the internal links of.
3851 * Gets a list of pads to which the given pad is linked to
3852 * inside of the parent element.
3853 * This is the default handler, and thus returns a list of all of the
3854 * pads inside the parent element with opposite direction.
3855 * The caller must free this list after use.
3857 * Returns: a newly allocated #GList of pads.
3860 gst_pad_get_internal_links_default (GstPad * pad)
3865 GstPadDirection direction;
3868 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3870 rpad = GST_PAD_REALIZE (pad);
3871 direction = rpad->direction;
3873 parent = GST_PAD_PARENT (rpad);
3874 parent_pads = parent->pads;
3876 while (parent_pads) {
3877 GstRealPad *parent_pad = GST_PAD_REALIZE (parent_pads->data);
3879 if (parent_pad->direction != direction) {
3880 res = g_list_prepend (res, parent_pad);
3883 parent_pads = g_list_next (parent_pads);
3890 * gst_pad_get_internal_links:
3891 * @pad: the #GstPad to get the internal links of.
3893 * Gets a list of pads to which the given pad is linked to
3894 * inside of the parent element.
3895 * The caller must free this list after use.
3897 * Returns: a newly allocated #GList of pads.
3900 gst_pad_get_internal_links (GstPad * pad)
3905 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3907 rpad = GST_PAD_REALIZE (pad);
3909 if (GST_RPAD_INTLINKFUNC (rpad))
3910 res = GST_RPAD_INTLINKFUNC (rpad) (GST_PAD (rpad));
3917 gst_pad_event_default_dispatch (GstPad * pad, GstElement * element,
3922 GST_INFO_OBJECT (pad, "Sending event %p to all internally linked pads",
3925 orig = pads = gst_pad_get_internal_links (pad);
3928 GstPad *eventpad = GST_PAD (pads->data);
3930 pads = g_list_next (pads);
3932 /* for all of the internally-linked pads that are actually linked */
3933 if (GST_PAD_IS_LINKED (eventpad)) {
3934 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
3935 /* increase the refcount */
3936 gst_event_ref (event);
3937 gst_pad_push (eventpad, GST_DATA (event));
3939 GstPad *peerpad = GST_PAD (GST_RPAD_PEER (eventpad));
3941 /* we only send the event on one pad, multi-sinkpad elements
3942 * should implement a handler */
3944 return gst_pad_send_event (peerpad, event);
3948 gst_event_unref (event);
3950 return (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
3954 * gst_pad_event_default:
3955 * @pad: a #GstPad to call the default event handler on.
3956 * @event: the #GstEvent to handle.
3958 * Invokes the default event handler for the given pad. End-of-stream and
3959 * discontinuity events are handled specially, and then the event is sent to all
3960 * pads internally linked to @pad. Note that if there are many possible sink
3961 * pads that are internally linked to @pad, only one will be sent an event.
3962 * Multi-sinkpad elements should implement custom event handlers.
3964 * Returns: TRUE if the event was sent succesfully.
3967 gst_pad_event_default (GstPad * pad, GstEvent * event)
3969 GstElement *element;
3971 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3972 g_return_val_if_fail (event != NULL, FALSE);
3974 element = GST_PAD_PARENT (pad);
3976 switch (GST_EVENT_TYPE (event)) {
3978 gst_pad_event_default_dispatch (pad, element, event);
3979 gst_element_set_eos (element);
3981 case GST_EVENT_DISCONTINUOUS:
3985 if (gst_element_requires_clock (element) && element->clock) {
3986 if (gst_event_discont_get_value (event, GST_FORMAT_TIME, &time)) {
3987 gst_element_set_time (element, time);
3989 GstFormat format = GST_FORMAT_TIME;
3992 for (i = 0; i < event->event_data.discont.noffsets; i++) {
3993 if (gst_pad_convert (pad,
3994 event->event_data.discont.offsets[i].format,
3995 event->event_data.discont.offsets[i].value, &format,
3997 gst_element_set_time (element, time);
3998 } else if (i == event->event_data.discont.noffsets) {
4000 ("can't adjust clock to new time when time not provided");
4007 return gst_pad_event_default_dispatch (pad, element, event);
4013 * gst_pad_dispatcher:
4014 * @pad: a #GstPad to dispatch.
4015 * @dispatch: the #GstDispatcherFunction to call.
4016 * @data: gpointer user data passed to the dispatcher function.
4018 * Invokes the given dispatcher function on all pads that are
4019 * internally linked to the given pad.
4020 * The GstPadDispatcherFunction should return TRUE when no further pads
4021 * need to be processed.
4023 * Returns: TRUE if one of the dispatcher functions returned TRUE.
4026 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
4029 gboolean res = FALSE;
4030 GList *int_pads, *orig;
4032 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4033 g_return_val_if_fail (dispatch != NULL, FALSE);
4035 orig = int_pads = gst_pad_get_internal_links (pad);
4038 GstRealPad *int_rpad = GST_PAD_REALIZE (int_pads->data);
4039 GstRealPad *int_peer = GST_RPAD_PEER (int_rpad);
4042 res = dispatch (GST_PAD (int_peer), data);
4046 int_pads = g_list_next (int_pads);
4055 * gst_pad_send_event:
4056 * @pad: a #GstPad to send the event to.
4057 * @event: the #GstEvent to send to the pad.
4059 * Sends the event to the pad.
4061 * Returns: TRUE if the event was handled.
4064 gst_pad_send_event (GstPad * pad, GstEvent * event)
4066 gboolean success = FALSE;
4069 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4070 g_return_val_if_fail (event != NULL, FALSE);
4072 rpad = GST_PAD_REALIZE (pad);
4074 if (GST_EVENT_SRC (event) == NULL)
4075 GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (rpad));
4077 GST_CAT_DEBUG (GST_CAT_EVENT, "have event %d on pad %s:%s",
4078 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (rpad));
4080 if (GST_RPAD_EVENTHANDLER (rpad))
4081 success = GST_RPAD_EVENTHANDLER (rpad) (GST_PAD (rpad), event);
4083 g_warning ("pad %s:%s has no event handler", GST_DEBUG_PAD_NAME (rpad));
4084 gst_event_unref (event);
4092 GstFormat src_format;
4094 GstFormat *dest_format;
4100 gst_pad_convert_dispatcher (GstPad * pad, GstPadConvertData * data)
4102 return gst_pad_convert (pad, data->src_format, data->src_value,
4103 data->dest_format, data->dest_value);
4107 * gst_pad_convert_default:
4108 * @pad: a #GstPad to invoke the default converter on.
4109 * @src_format: the source #GstFormat.
4110 * @src_value: the source value.
4111 * @dest_format: a pointer to the destination #GstFormat.
4112 * @dest_value: a pointer to the destination value.
4114 * Invokes the default converter on a pad.
4115 * This will forward the call to the pad obtained
4116 * using the internal link of
4119 * Returns: TRUE if the conversion could be performed.
4122 gst_pad_convert_default (GstPad * pad,
4123 GstFormat src_format, gint64 src_value,
4124 GstFormat * dest_format, gint64 * dest_value)
4126 GstPadConvertData data;
4128 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4129 g_return_val_if_fail (dest_format != NULL, FALSE);
4130 g_return_val_if_fail (dest_value != NULL, FALSE);
4132 data.src_format = src_format;
4133 data.src_value = src_value;
4134 data.dest_format = dest_format;
4135 data.dest_value = dest_value;
4137 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
4138 gst_pad_convert_dispatcher, &data);
4143 * @pad: a #GstPad to invoke the default converter on.
4144 * @src_format: the source #GstFormat.
4145 * @src_value: the source value.
4146 * @dest_format: a pointer to the destination #GstFormat.
4147 * @dest_value: a pointer to the destination value.
4149 * Invokes a conversion on the pad.
4151 * Returns: TRUE if the conversion could be performed.
4154 gst_pad_convert (GstPad * pad,
4155 GstFormat src_format, gint64 src_value,
4156 GstFormat * dest_format, gint64 * dest_value)
4160 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4161 g_return_val_if_fail (dest_format != NULL, FALSE);
4162 g_return_val_if_fail (dest_value != NULL, FALSE);
4164 if (src_format == *dest_format) {
4165 *dest_value = src_value;
4169 rpad = GST_PAD_REALIZE (pad);
4171 if (GST_RPAD_CONVERTFUNC (rpad)) {
4172 return GST_RPAD_CONVERTFUNC (rpad) (GST_PAD (rpad), src_format,
4173 src_value, dest_format, dest_value);
4188 gst_pad_query_dispatcher (GstPad * pad, GstPadQueryData * data)
4190 return gst_pad_query (pad, data->type, data->format, data->value);
4194 * gst_pad_query_default:
4195 * @pad: a #GstPad to invoke the default query on.
4196 * @type: the #GstQueryType of the query to perform.
4197 * @format: a pointer to the #GstFormat of the result.
4198 * @value: a pointer to the result.
4200 * Invokes the default query function on a pad.
4202 * Returns: TRUE if the query could be performed.
4205 gst_pad_query_default (GstPad * pad, GstQueryType type,
4206 GstFormat * format, gint64 * value)
4208 GstPadQueryData data;
4210 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4211 g_return_val_if_fail (format != NULL, FALSE);
4212 g_return_val_if_fail (value != NULL, FALSE);
4215 data.format = format;
4218 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
4219 gst_pad_query_dispatcher, &data);
4224 * @pad: a #GstPad to invoke the default query on.
4225 * @type: the #GstQueryType of the query to perform.
4226 * @format: a pointer to the #GstFormat asked for.
4227 * On return contains the #GstFormat used.
4228 * @value: a pointer to the result.
4230 * Queries a pad for one of the available properties. The format will be
4231 * adjusted to the actual format used when specifying formats such as
4232 * GST_FORMAT_DEFAULT.
4233 * FIXME: Tell if the format can be adjusted when specifying a definite format.
4235 * Returns: TRUE if the query could be performed.
4238 gst_pad_query (GstPad * pad, GstQueryType type,
4239 GstFormat * format, gint64 * value)
4243 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4244 g_return_val_if_fail (format != NULL, FALSE);
4245 g_return_val_if_fail (value != NULL, FALSE);
4247 rpad = GST_PAD_REALIZE (pad);
4249 g_return_val_if_fail (rpad, FALSE);
4251 if (GST_RPAD_QUERYFUNC (rpad))
4252 return GST_RPAD_QUERYFUNC (rpad) (GST_PAD (pad), type, format, value);
4258 gst_pad_get_formats_dispatcher (GstPad * pad, const GstFormat ** data)
4260 *data = gst_pad_get_formats (pad);
4266 * gst_pad_get_formats_default:
4267 * @pad: a #GstPad to query
4269 * Invoke the default format dispatcher for the pad.
4271 * Returns: An array of GstFormats ended with a 0 value.
4274 gst_pad_get_formats_default (GstPad * pad)
4276 GstFormat *result = NULL;
4278 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4280 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
4281 gst_pad_get_formats_dispatcher, &result);
4287 * gst_pad_get_formats:
4288 * @pad: a #GstPad to query
4290 * Gets the list of supported formats from the pad.
4292 * Returns: An array of GstFormats ended with a 0 value.
4295 gst_pad_get_formats (GstPad * pad)
4299 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4301 rpad = GST_PAD_REALIZE (pad);
4303 if (GST_RPAD_FORMATSFUNC (rpad))
4304 return GST_RPAD_FORMATSFUNC (rpad) (GST_PAD (pad));
4309 #define CALL_CHAINFUNC(pad, data) G_STMT_START {\
4310 GstData *__temp = (data); \
4311 DEBUG_DATA (pad, __temp, "calling chain function with "); \
4312 if (GST_IS_EVENT (__temp) && \
4313 !GST_FLAG_IS_SET (gst_pad_get_parent (pad), GST_ELEMENT_EVENT_AWARE)) { \
4314 gst_pad_send_event (pad, GST_EVENT (__temp)); \
4316 GST_RPAD_CHAINFUNC (pad) (pad, __temp); \
4320 * gst_pad_call_chain_function:
4321 * @pad: sink pad to call chain function on
4322 * @data: data to call the chain function with
4324 * Calls the chain function of the given pad while making sure the internal
4325 * consistency is kept. Use this function inside schedulers instead of calling
4326 * the chain function yourself.
4329 gst_pad_call_chain_function (GstPad * pad, GstData * data)
4333 g_return_if_fail (GST_IS_REAL_PAD (pad));
4334 g_return_if_fail (GST_PAD_IS_SINK (pad));
4335 g_return_if_fail (data != NULL);
4336 g_return_if_fail (GST_RPAD_CHAINFUNC (pad) != NULL);
4337 g_return_if_fail (GST_RPAD_LINK (pad) != NULL);
4339 link = GST_RPAD_LINK (pad);
4340 if (!link->engaged) {
4341 g_assert (link->temp_store == NULL);
4342 if (GST_IS_BUFFER (data)) {
4343 link->temp_store = data;
4344 link->engaged = TRUE;
4345 CALL_CHAINFUNC (pad, _invent_event (pad, GST_BUFFER (data)));
4346 link = GST_RPAD_LINK (pad);
4347 if (link->temp_store == NULL) /* happens after relinking in chainfunc */
4349 g_assert (link->temp_store == data);
4350 link->temp_store = NULL;
4351 } else if (GST_IS_EVENT (data) &&
4352 GST_EVENT_TYPE (data) == GST_EVENT_DISCONTINUOUS &&
4353 GST_EVENT_DISCONT_NEW_MEDIA (data)) {
4354 link->engaged = TRUE;
4355 GST_CAT_LOG (GST_CAT_SCHEDULING,
4356 "link engaged by discont event for pad %s:%s",
4357 GST_DEBUG_PAD_NAME (pad));
4360 CALL_CHAINFUNC (pad, data);
4364 * gst_pad_call_get_function:
4365 * @pad: sink pad to call chain function on
4367 * Calls the get function of the given pad while making sure the internal
4368 * consistency is kept. Use this function inside schedulers instead of calling
4369 * the get function yourself.
4371 * Returns: the data provided by the pad or NULL if no data was available.
4374 gst_pad_call_get_function (GstPad * pad)
4378 g_return_val_if_fail (GST_IS_REAL_PAD (pad), NULL);
4379 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
4380 g_return_val_if_fail (GST_RPAD_GETFUNC (pad) != NULL, NULL);
4382 data = GST_RPAD_GETFUNC (pad) (pad);
4383 DEBUG_DATA (pad, data, "getfunction returned");