2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for linking elements together
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include "gst_private.h"
26 #include "gstmarshal.h"
28 #include "gstelement.h"
30 #include "gstscheduler.h"
36 GST_DEBUG_CATEGORY_STATIC (debug_dataflow);
37 #define DEBUG_DATA(obj,data,notice) G_STMT_START{\
38 if (GST_IS_EVENT (data)) { \
39 GST_CAT_DEBUG_OBJECT (debug_dataflow, obj, "%s event %p (type %d, refcount %d)", notice, data, \
40 GST_EVENT_TYPE (data), GST_DATA_REFCOUNT_VALUE (data)); \
42 GST_CAT_LOG_OBJECT (debug_dataflow, obj, "%s buffer %p (size %u, refcount %d)", notice, data, \
43 GST_BUFFER_SIZE (data), GST_BUFFER_REFCOUNT_VALUE (data)); \
46 #define GST_CAT_DEFAULT GST_CAT_PADS
64 GstPadFixateFunction app_fixate;
67 GstData *temp_store; /* used only when we invented a DISCONT */
77 static GstObject *padtemplate_parent_class = NULL;
78 static guint gst_pad_template_signals[TEMPL_LAST_SIGNAL] = { 0 };
80 GType _gst_pad_type = 0;
82 /***** Start with the base GstPad class *****/
83 static void gst_pad_class_init (GstPadClass * klass);
84 static void gst_pad_init (GstPad * pad);
85 static void gst_pad_dispose (GObject * object);
87 static void gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ);
88 static GstCaps *_gst_pad_default_fixate_func (GstPad * pad,
89 const GstCaps * caps);
91 static gboolean gst_pad_link_try (GstPadLink * link);
92 static void gst_pad_link_free (GstPadLink * link);
94 #ifndef GST_DISABLE_LOADSAVE
95 static xmlNodePtr gst_pad_save_thyself (GstObject * object, xmlNodePtr parent);
98 static GstObject *pad_parent_class = NULL;
101 gst_pad_get_type (void)
103 if (!_gst_pad_type) {
104 static const GTypeInfo pad_info = {
105 sizeof (GstPadClass), NULL, NULL,
106 (GClassInitFunc) gst_pad_class_init, NULL, NULL,
109 (GInstanceInitFunc) gst_pad_init, NULL
112 _gst_pad_type = g_type_register_static (GST_TYPE_OBJECT, "GstPad",
115 GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW",
116 GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads");
118 return _gst_pad_type;
122 gst_pad_class_init (GstPadClass * klass)
124 GObjectClass *gobject_class;
126 gobject_class = (GObjectClass *) klass;
128 pad_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
130 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_pad_dispose);
134 gst_pad_init (GstPad * pad)
136 /* all structs are initialized to NULL by glib */
139 gst_pad_dispose (GObject * object)
141 GstPad *pad = GST_PAD (object);
143 gst_pad_set_pad_template (pad, NULL);
145 G_OBJECT_CLASS (pad_parent_class)->dispose (object);
150 /***** Then do the Real Pad *****/
151 /* Pad signals and args */
169 static void gst_real_pad_class_init (GstRealPadClass * klass);
170 static void gst_real_pad_init (GstRealPad * pad);
171 static void gst_real_pad_dispose (GObject * object);
173 static gboolean _gst_real_pad_fixate_accumulator (GSignalInvocationHint * ihint,
174 GValue * return_accu, const GValue * handler_return, gpointer dummy);
175 static void gst_real_pad_set_property (GObject * object, guint prop_id,
176 const GValue * value, GParamSpec * pspec);
177 static void gst_real_pad_get_property (GObject * object, guint prop_id,
178 GValue * value, GParamSpec * pspec);
180 GType _gst_real_pad_type = 0;
182 static GstPad *real_pad_parent_class = NULL;
183 static guint gst_real_pad_signals[REAL_LAST_SIGNAL] = { 0 };
186 gst_real_pad_get_type (void)
188 if (!_gst_real_pad_type) {
189 static const GTypeInfo pad_info = {
190 sizeof (GstRealPadClass), NULL, NULL,
191 (GClassInitFunc) gst_real_pad_class_init, NULL, NULL,
194 (GInstanceInitFunc) gst_real_pad_init, NULL
197 _gst_real_pad_type = g_type_register_static (GST_TYPE_PAD, "GstRealPad",
200 return _gst_real_pad_type;
204 gst_real_pad_class_init (GstRealPadClass * klass)
206 GObjectClass *gobject_class;
207 GstObjectClass *gstobject_class;
209 gobject_class = (GObjectClass *) klass;
210 gstobject_class = (GstObjectClass *) klass;
212 real_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
214 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_real_pad_dispose);
215 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_real_pad_set_property);
216 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_real_pad_get_property);
218 gst_real_pad_signals[REAL_LINKED] =
219 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
220 G_STRUCT_OFFSET (GstRealPadClass, linked), NULL, NULL,
221 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
222 gst_real_pad_signals[REAL_UNLINKED] =
223 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
224 G_STRUCT_OFFSET (GstRealPadClass, unlinked), NULL, NULL,
225 gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
226 gst_real_pad_signals[REAL_FIXATE] =
227 g_signal_new ("fixate", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
228 G_STRUCT_OFFSET (GstRealPadClass, appfixatefunc),
229 _gst_real_pad_fixate_accumulator, NULL,
230 gst_marshal_BOXED__BOXED, GST_TYPE_CAPS, 1,
231 GST_TYPE_CAPS | G_SIGNAL_TYPE_STATIC_SCOPE);
233 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_ACTIVE,
234 g_param_spec_boolean ("active", "Active", "Whether the pad is active.",
235 TRUE, G_PARAM_READWRITE));
236 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_CAPS,
237 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
238 GST_TYPE_CAPS, G_PARAM_READABLE));
240 #ifndef GST_DISABLE_LOADSAVE
241 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
243 gstobject_class->path_string_separator = ".";
247 _gst_real_pad_fixate_accumulator (GSignalInvocationHint * ihint,
248 GValue * return_accu, const GValue * handler_return, gpointer dummy)
250 if (gst_value_get_caps (handler_return)) {
251 g_value_copy (handler_return, return_accu);
252 /* stop emission if something was returned */
259 gst_real_pad_init (GstRealPad * pad)
261 pad->direction = GST_PAD_UNKNOWN;
264 pad->chainfunc = NULL;
267 pad->chainhandler = NULL;
268 pad->gethandler = NULL;
270 pad->ghostpads = NULL;
273 pad->linkfunc = NULL;
274 pad->getcapsfunc = NULL;
276 pad->eventfunc = gst_pad_event_default;
277 pad->convertfunc = gst_pad_convert_default;
278 pad->queryfunc = gst_pad_query_default;
279 pad->intlinkfunc = gst_pad_get_internal_links_default;
281 pad->eventmaskfunc = gst_pad_get_event_masks_default;
282 pad->formatsfunc = gst_pad_get_formats_default;
283 pad->querytypefunc = gst_pad_get_query_types_default;
285 GST_FLAG_SET (pad, GST_PAD_DISABLED);
286 GST_FLAG_UNSET (pad, GST_PAD_NEGOTIATING);
288 gst_probe_dispatcher_init (&pad->probedisp);
292 gst_real_pad_set_property (GObject * object, guint prop_id,
293 const GValue * value, GParamSpec * pspec)
295 g_return_if_fail (GST_IS_PAD (object));
298 case REAL_ARG_ACTIVE:
299 gst_pad_set_active (GST_PAD (object), g_value_get_boolean (value));
302 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
308 gst_real_pad_get_property (GObject * object, guint prop_id,
309 GValue * value, GParamSpec * pspec)
311 g_return_if_fail (GST_IS_PAD (object));
314 case REAL_ARG_ACTIVE:
315 g_value_set_boolean (value, !GST_FLAG_IS_SET (object, GST_PAD_DISABLED));
318 g_value_set_boxed (value, GST_PAD_CAPS (GST_REAL_PAD (object)));
321 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
326 /* FIXME-0.9: Replace these custom functions with proper inheritance via _init
327 functions and object properties */
329 * gst_pad_custom_new:
330 * @type: the #Gtype of the pad.
331 * @name: the name of the new pad.
332 * @direction: the #GstPadDirection of the pad.
334 * Creates a new pad with the given name and type in the given direction.
335 * If name is NULL, a guaranteed unique name (across all pads)
338 * Returns: a new #GstPad, or NULL in case of an error.
341 gst_pad_custom_new (GType type, const gchar * name, GstPadDirection direction)
345 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
347 pad = g_object_new (type, NULL);
348 gst_object_set_name (GST_OBJECT (pad), name);
349 GST_RPAD_DIRECTION (pad) = direction;
351 return GST_PAD (pad);
356 * @name: the name of the new pad.
357 * @direction: the #GstPadDirection of the pad.
359 * Creates a new real pad with the given name in the given direction.
360 * If name is NULL, a guaranteed unique name (across all pads)
363 * Returns: a new #GstPad, or NULL in case of an error.
366 gst_pad_new (const gchar * name, GstPadDirection direction)
368 return gst_pad_custom_new (gst_real_pad_get_type (), name, direction);
372 * gst_pad_custom_new_from_template:
373 * @type: the custom #GType of the pad.
374 * @templ: the #GstPadTemplate to instantiate from.
375 * @name: the name of the new pad.
377 * Creates a new custom pad with the given name from the given template.
378 * If name is NULL, a guaranteed unique name (across all pads)
381 * Returns: a new #GstPad, or NULL in case of an error.
384 gst_pad_custom_new_from_template (GType type, GstPadTemplate * templ,
389 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
391 pad = gst_pad_custom_new (type, name, templ->direction);
392 gst_pad_set_pad_template (pad, templ);
398 * gst_pad_new_from_template:
399 * @templ: the pad template to use
400 * @name: the name of the element
402 * Creates a new real pad with the given name from the given template.
403 * If name is NULL, a guaranteed unique name (across all pads)
406 * Returns: a new #GstPad, or NULL in case of an error.
409 gst_pad_new_from_template (GstPadTemplate * templ, const gchar * name)
411 return gst_pad_custom_new_from_template (gst_real_pad_get_type (),
415 /* FIXME 0.9: GST_PAD_UNKNOWN needs to die! */
417 * gst_pad_get_direction:
418 * @pad: a #GstPad to get the direction of.
420 * Gets the direction of the pad.
422 * Returns: the #GstPadDirection of the pad.
425 gst_pad_get_direction (GstPad * pad)
427 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
429 if (GST_IS_REAL_PAD (pad))
430 return GST_PAD_DIRECTION (pad);
432 return GST_PAD_UNKNOWN;
436 * gst_pad_set_active:
437 * @pad: the #GstPad to activate or deactivate.
438 * @active: TRUE to activate the pad.
440 * Activates or deactivates the given pad.
443 gst_pad_set_active (GstPad * pad, gboolean active)
449 g_return_if_fail (GST_IS_PAD (pad));
451 old = GST_PAD_IS_ACTIVE (pad);
456 realpad = GST_PAD_REALIZE (pad);
459 GST_CAT_DEBUG (GST_CAT_PADS, "activating pad %s:%s",
460 GST_DEBUG_PAD_NAME (realpad));
461 GST_FLAG_UNSET (realpad, GST_PAD_DISABLED);
463 GST_CAT_DEBUG (GST_CAT_PADS, "de-activating pad %s:%s",
464 GST_DEBUG_PAD_NAME (realpad));
465 GST_FLAG_SET (realpad, GST_PAD_DISABLED);
467 link = GST_RPAD_LINK (realpad);
469 if (link->temp_store) {
470 GST_CAT_INFO (GST_CAT_PADS,
471 "deleting cached data %p from bufpen of pad %s:%s", link->temp_store,
472 GST_DEBUG_PAD_NAME (realpad));
473 gst_data_unref (link->temp_store);
474 link->temp_store = NULL;
478 g_object_notify (G_OBJECT (realpad), "active");
483 * @pad: the #GstPad to query
485 * Query if a pad is active
487 * Returns: TRUE if the pad is active.
490 gst_pad_is_active (GstPad * pad)
492 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
494 return !GST_FLAG_IS_SET (pad, GST_PAD_DISABLED);
499 * @pad: a #GstPad to set the name of.
500 * @name: the name of the pad.
502 * Sets the name of a pad. If name is NULL, then a guaranteed unique
503 * name will be assigned.
506 gst_pad_set_name (GstPad * pad, const gchar * name)
508 g_return_if_fail (GST_IS_PAD (pad));
510 gst_object_set_name (GST_OBJECT (pad), name);
513 /* FIXME 0.9: This function must die */
516 * @pad: a #GstPad to get the name of.
518 * Gets the name of a pad.
520 * Returns: the name of the pad. This is not a newly allocated pointer
521 * so you must not free it.
524 gst_pad_get_name (GstPad * pad)
526 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
528 return GST_OBJECT_NAME (pad);
532 * gst_pad_set_chain_function:
533 * @pad: a real sink #GstPad.
534 * @chain: the #GstPadChainFunction to set.
536 * Sets the given chain function for the pad. The chain function is called to
537 * process a #GstData input buffer.
540 gst_pad_set_chain_function (GstPad * pad, GstPadChainFunction chain)
542 g_return_if_fail (GST_IS_REAL_PAD (pad));
543 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SINK);
545 GST_RPAD_CHAINFUNC (pad) = chain;
546 GST_CAT_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
547 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
551 * gst_pad_set_get_function:
552 * @pad: a real source #GstPad.
553 * @get: the #GstPadGetFunction to set.
555 * Sets the given get function for the pad. The get function is called to
556 * produce a new #GstData to start the processing pipeline. Get functions cannot
560 gst_pad_set_get_function (GstPad * pad, GstPadGetFunction get)
562 g_return_if_fail (GST_IS_REAL_PAD (pad));
563 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SRC);
565 GST_RPAD_GETFUNC (pad) = get;
567 GST_CAT_DEBUG (GST_CAT_PADS, "getfunc for %s:%s set to %s",
568 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
572 * gst_pad_set_event_function:
573 * @pad: a real source #GstPad.
574 * @event: the #GstPadEventFunction to set.
576 * Sets the given event handler for the pad.
579 gst_pad_set_event_function (GstPad * pad, GstPadEventFunction event)
581 g_return_if_fail (GST_IS_REAL_PAD (pad));
582 g_return_if_fail (GST_RPAD_DIRECTION (pad) == GST_PAD_SRC);
584 GST_RPAD_EVENTFUNC (pad) = event;
586 GST_CAT_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
587 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
591 * gst_pad_set_event_mask_function:
592 * @pad: a real #GstPad of either direction.
593 * @mask_func: the #GstPadEventMaskFunction to set.
595 * Sets the given event mask function for the pad.
598 gst_pad_set_event_mask_function (GstPad * pad,
599 GstPadEventMaskFunction mask_func)
601 g_return_if_fail (GST_IS_REAL_PAD (pad));
603 GST_RPAD_EVENTMASKFUNC (pad) = mask_func;
605 GST_CAT_DEBUG (GST_CAT_PADS, "eventmaskfunc for %s:%s set to %s",
606 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (mask_func));
610 * gst_pad_get_event_masks:
613 * Gets the array of eventmasks from the given pad.
615 * Returns: a zero-terminated array of #GstEventMask, or NULL if the pad does
616 * not have an event mask function.
619 gst_pad_get_event_masks (GstPad * pad)
623 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
625 rpad = GST_PAD_REALIZE (pad);
627 g_return_val_if_fail (rpad, FALSE);
629 if (GST_RPAD_EVENTMASKFUNC (rpad))
630 return GST_RPAD_EVENTMASKFUNC (rpad) (GST_PAD (pad));
636 gst_pad_get_event_masks_dispatcher (GstPad * pad, const GstEventMask ** data)
638 *data = gst_pad_get_event_masks (pad);
644 * gst_pad_get_event_masks_default:
647 * Invokes the default event masks dispatcher on the pad.
649 * Returns: a zero-terminated array of #GstEventMask, or NULL if none of the
650 * internally-linked pads have an event mask function.
653 gst_pad_get_event_masks_default (GstPad * pad)
655 GstEventMask *result = NULL;
657 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
659 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
660 gst_pad_get_event_masks_dispatcher, &result);
666 * gst_pad_set_convert_function:
667 * @pad: a real #GstPad of either direction.
668 * @convert: the #GstPadConvertFunction to set.
670 * Sets the given convert function for the pad.
673 gst_pad_set_convert_function (GstPad * pad, GstPadConvertFunction convert)
675 g_return_if_fail (GST_IS_REAL_PAD (pad));
677 GST_RPAD_CONVERTFUNC (pad) = convert;
679 GST_CAT_DEBUG (GST_CAT_PADS, "convertfunc for %s:%s set to %s",
680 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (convert));
684 * gst_pad_set_query_function:
685 * @pad: a real #GstPad of either direction.
686 * @query: the #GstPadQueryFunction to set.
688 * Set the given query function for the pad.
691 gst_pad_set_query_function (GstPad * pad, GstPadQueryFunction query)
693 g_return_if_fail (GST_IS_REAL_PAD (pad));
695 GST_RPAD_QUERYFUNC (pad) = query;
697 GST_CAT_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
698 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
702 * gst_pad_set_query_type_function:
703 * @pad: a real #GstPad of either direction.
704 * @type_func: the #GstPadQueryTypeFunction to set.
706 * Set the given query type function for the pad.
709 gst_pad_set_query_type_function (GstPad * pad,
710 GstPadQueryTypeFunction type_func)
712 g_return_if_fail (GST_IS_REAL_PAD (pad));
714 GST_RPAD_QUERYTYPEFUNC (pad) = type_func;
716 GST_CAT_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
717 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
721 * gst_pad_get_query_types:
724 * Get an array of supported queries that can be performed
727 * Returns: a zero-terminated array of #GstQueryType.
730 gst_pad_get_query_types (GstPad * pad)
734 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
736 rpad = GST_PAD_REALIZE (pad);
738 g_return_val_if_fail (rpad, NULL);
740 if (GST_RPAD_QUERYTYPEFUNC (rpad))
741 return GST_RPAD_QUERYTYPEFUNC (rpad) (GST_PAD (pad));
747 gst_pad_get_query_types_dispatcher (GstPad * pad, const GstQueryType ** data)
749 *data = gst_pad_get_query_types (pad);
755 * gst_pad_get_query_types_default:
758 * Invoke the default dispatcher for the query types on
761 * Returns: an zero-terminated array of #GstQueryType, or NULL if none of the
762 * internally-linked pads has a query types function.
765 gst_pad_get_query_types_default (GstPad * pad)
767 GstQueryType *result = NULL;
769 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
771 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
772 gst_pad_get_query_types_dispatcher, &result);
778 * gst_pad_set_internal_link_function:
779 * @pad: a real #GstPad of either direction.
780 * @intlink: the #GstPadIntLinkFunction to set.
782 * Sets the given internal link function for the pad.
785 gst_pad_set_internal_link_function (GstPad * pad, GstPadIntLinkFunction intlink)
787 g_return_if_fail (GST_IS_REAL_PAD (pad));
789 GST_RPAD_INTLINKFUNC (pad) = intlink;
790 GST_CAT_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
791 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
795 * gst_pad_set_formats_function:
796 * @pad: a real #GstPad of either direction.
797 * @formats: the #GstPadFormatsFunction to set.
799 * Sets the given formats function for the pad.
802 gst_pad_set_formats_function (GstPad * pad, GstPadFormatsFunction formats)
804 g_return_if_fail (GST_IS_REAL_PAD (pad));
806 GST_RPAD_FORMATSFUNC (pad) = formats;
807 GST_CAT_DEBUG (GST_CAT_PADS, "formats function for %s:%s set to %s",
808 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (formats));
812 * gst_pad_set_link_function:
813 * @pad: a real #GstPad.
814 * @link: the #GstPadLinkFunction to set.
816 * Sets the given link function for the pad. It will be called when the pad is
817 * linked or relinked with caps. The caps passed to the link function are
818 * guaranteed to be fixed. This means that you can assume that the caps is not
819 * ANY or EMPTY, and that there is exactly one structure in the caps, and that
820 * all the fields in the structure are fixed.
822 * The return value GST_PAD_LINK_OK should be used when the caps are acceptable,
823 * and you've extracted all the necessary information from the caps and set the
824 * element's internal state appropriately.
826 * The return value GST_PAD_LINK_REFUSED should be used when the caps are
827 * unacceptable for whatever reason.
829 * The return value GST_PAD_LINK_DELAYED should be used when the element is in a
830 * state where it can't determine whether the caps are acceptable or not. This
831 * is often used if the element needs to open a device or process data before
832 * determining acceptable caps.
834 * @link must not call gst_caps_try_set_caps() on the pad that was specified as
835 * a parameter, although it may (and often should) call gst_caps_try_set_caps()
839 gst_pad_set_link_function (GstPad * pad, GstPadLinkFunction link)
841 g_return_if_fail (GST_IS_REAL_PAD (pad));
843 GST_RPAD_LINKFUNC (pad) = link;
844 GST_CAT_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
845 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
849 * gst_pad_set_unlink_function:
850 * @pad: a real #GstPad.
851 * @unlink: the #GstPadUnlinkFunction to set.
853 * Sets the given unlink function for the pad. It will be called
854 * when the pad is unlinked.
857 gst_pad_set_unlink_function (GstPad * pad, GstPadUnlinkFunction unlink)
859 g_return_if_fail (GST_IS_REAL_PAD (pad));
861 GST_RPAD_UNLINKFUNC (pad) = unlink;
862 GST_CAT_DEBUG (GST_CAT_PADS, "unlinkfunc for %s:%s set to %s",
863 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (unlink));
867 * gst_pad_set_fixate_function:
868 * @pad: a real #GstPad.
869 * @fixate: the #GstPadFixateFunction to set.
871 * Sets the given fixate function for the pad. Its job is to narrow down the
872 * possible caps for a connection. Fixate functions are called with a const
873 * caps, and should return a caps that is a strict subset of the given caps.
874 * That is, @fixate should create a caps that is "more fixed" than previously,
875 * but it does not have to return fixed caps. If @fixate can't provide more
876 * fixed caps, it should return %NULL.
878 * Note that @fixate will only be called after the "fixate" signal is emitted,
879 * and only if the caps are still non-fixed.
882 gst_pad_set_fixate_function (GstPad * pad, GstPadFixateFunction fixate)
884 g_return_if_fail (GST_IS_REAL_PAD (pad));
886 GST_RPAD_FIXATEFUNC (pad) = fixate;
887 GST_CAT_DEBUG (GST_CAT_PADS, "fixatefunc for %s:%s set to %s",
888 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (fixate));
892 * gst_pad_set_getcaps_function:
893 * @pad: a real #GstPad.
894 * @getcaps: the #GstPadGetCapsFunction to set.
896 * Sets the given getcaps function for the pad. @getcaps should return the
897 * allowable caps for a pad in the context of the element's state, its link to
898 * other elements, and the devices or files it has opened. These caps must be a
899 * subset of the pad template caps. In the NULL state with no links, @getcaps
900 * should ideally return the same caps as the pad template. In rare
901 * circumstances, an object property can affect the caps returned by @getcaps,
902 * but this is discouraged.
904 * You do not need to call this function if @pad's allowed caps are always the
905 * same as the pad template caps.
907 * For most filters, the caps returned by @getcaps is directly affected by the
908 * allowed caps on other pads. For demuxers and decoders, the caps returned by
909 * the srcpad's getcaps function is directly related to the stream data. Again,
910 * @getcaps should return the most specific caps it reasonably can, since this
911 * helps with autoplugging. However, the returned caps should not depend on the
912 * stream type currently negotiated for @pad.
914 * Note that the return value from @getcaps is owned by the caller.
917 gst_pad_set_getcaps_function (GstPad * pad, GstPadGetCapsFunction getcaps)
919 g_return_if_fail (GST_IS_REAL_PAD (pad));
921 GST_RPAD_GETCAPSFUNC (pad) = getcaps;
922 GST_CAT_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
923 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
927 * gst_pad_set_bufferalloc_function:
928 * @pad: a real sink #GstPad.
929 * @bufalloc: the #GstPadBufferAllocFunction to set.
931 * Sets the given bufferalloc function for the pad. Note that the
932 * bufferalloc function can only be set on sinkpads.
935 gst_pad_set_bufferalloc_function (GstPad * pad,
936 GstPadBufferAllocFunction bufalloc)
938 g_return_if_fail (GST_IS_REAL_PAD (pad));
939 g_return_if_fail (GST_PAD_IS_SINK (pad));
941 GST_RPAD_BUFFERALLOCFUNC (pad) = bufalloc;
942 GST_CAT_DEBUG (GST_CAT_PADS, "bufferallocfunc for %s:%s set to %s",
943 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufalloc));
946 /* FIXME 0.9: Do we actually want to allow the case where src and sink are
950 * @srcpad: the source #GstPad to unlink.
951 * @sinkpad: the sink #GstPad to unlink.
953 * Unlinks the source pad from the sink pad. Will emit the "unlinked" signal on
957 gst_pad_unlink (GstPad * srcpad, GstPad * sinkpad)
959 GstRealPad *realsrc, *realsink;
960 GstScheduler *src_sched, *sink_sched;
962 g_return_if_fail (GST_IS_PAD (srcpad));
963 g_return_if_fail (GST_IS_PAD (sinkpad));
965 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
966 GST_DEBUG_PAD_NAME (srcpad), srcpad,
967 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
969 realsrc = GST_PAD_REALIZE (srcpad);
970 realsink = GST_PAD_REALIZE (sinkpad);
972 g_return_if_fail (GST_RPAD_PEER (realsrc) != NULL);
973 g_return_if_fail (GST_RPAD_PEER (realsink) == realsrc);
975 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
976 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
983 g_return_if_fail ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
984 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK));
986 if (GST_RPAD_UNLINKFUNC (realsrc)) {
987 GST_RPAD_UNLINKFUNC (realsrc) (GST_PAD (realsrc));
989 if (GST_RPAD_UNLINKFUNC (realsink)) {
990 GST_RPAD_UNLINKFUNC (realsink) (GST_PAD (realsink));
993 /* get the schedulers before we unlink */
994 src_sched = gst_pad_get_scheduler (GST_PAD (realsrc));
995 sink_sched = gst_pad_get_scheduler (GST_PAD (realsink));
997 if (GST_RPAD_LINK (realsrc))
998 gst_pad_link_free (GST_RPAD_LINK (realsrc));
1000 /* first clear peers */
1001 GST_RPAD_PEER (realsrc) = NULL;
1002 GST_RPAD_PEER (realsink) = NULL;
1003 GST_RPAD_LINK (realsrc) = NULL;
1004 GST_RPAD_LINK (realsink) = NULL;
1006 /* now tell the scheduler */
1007 if (src_sched && src_sched == sink_sched) {
1008 gst_scheduler_pad_unlink (src_sched, GST_PAD (realsrc), GST_PAD (realsink));
1011 /* hold a reference, as they can go away in the signal handlers */
1012 gst_object_ref (GST_OBJECT (realsrc));
1013 gst_object_ref (GST_OBJECT (realsink));
1015 /* fire off a signal to each of the pads telling them
1016 * that they've been unlinked */
1017 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_UNLINKED],
1019 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_UNLINKED],
1022 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
1023 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1025 gst_object_unref (GST_OBJECT (realsrc));
1026 gst_object_unref (GST_OBJECT (realsink));
1030 * gst_pad_is_linked:
1031 * @pad: pad to check
1033 * Checks if a @pad is linked to another pad or not.
1035 * Returns: TRUE if the pad is linked, FALSE otherwise.
1038 gst_pad_is_linked (GstPad * pad)
1040 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1042 return GST_PAD_PEER (pad) != NULL;
1046 gst_pad_check_schedulers (GstRealPad * realsrc, GstRealPad * realsink)
1048 GstScheduler *src_sched, *sink_sched;
1049 gint num_decoupled = 0;
1051 src_sched = gst_pad_get_scheduler (GST_PAD (realsrc));
1052 sink_sched = gst_pad_get_scheduler (GST_PAD (realsink));
1054 if (src_sched && sink_sched) {
1055 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsrc), GST_ELEMENT_DECOUPLED))
1057 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsink), GST_ELEMENT_DECOUPLED))
1060 if (src_sched != sink_sched && num_decoupled != 1) {
1067 #define GST_PAD_LINK_SRC(pad) ((GST_PAD_IS_SRC (pad)) ? (pad) : GST_PAD_PEER (pad))
1068 #define GST_PAD_LINK_SINK(pad) ((GST_PAD_IS_SINK (pad)) ? (pad) : GST_PAD_PEER (pad))
1071 gst_pad_link_new (void)
1075 link = g_new0 (GstPadLink, 1);
1076 link->sinknotify = TRUE;
1077 link->srcnotify = TRUE;
1079 link->engaged = FALSE;
1084 gst_pad_link_free (GstPadLink * link)
1087 gst_caps_free (link->srccaps);
1089 gst_caps_free (link->sinkcaps);
1090 if (link->filtercaps)
1091 gst_caps_free (link->filtercaps);
1093 gst_caps_free (link->caps);
1094 if (link->temp_store)
1095 gst_data_unref (link->temp_store);
1096 #ifdef USE_POISONING
1097 memset (link, 0xff, sizeof (*link));
1103 gst_pad_link_intersect (GstPadLink * link)
1105 GstCaps *pad_intersection;
1108 gst_caps_free (link->caps);
1110 GST_DEBUG ("intersecting link from %s:%s to %s:%s",
1111 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1112 GST_DEBUG ("... srccaps %" GST_PTR_FORMAT, link->srccaps);
1113 GST_DEBUG ("... sinkcaps %" GST_PTR_FORMAT, link->sinkcaps);
1114 GST_DEBUG ("... filtercaps %" GST_PTR_FORMAT, link->filtercaps);
1116 pad_intersection = gst_caps_intersect (link->srccaps, link->sinkcaps);
1118 if (link->filtercaps) {
1119 GST_DEBUG ("unfiltered intersection %" GST_PTR_FORMAT, pad_intersection);
1120 link->caps = gst_caps_intersect (pad_intersection, link->filtercaps);
1121 gst_caps_free (pad_intersection);
1123 link->caps = pad_intersection;
1126 GST_DEBUG ("intersection %" GST_PTR_FORMAT, link->caps);
1130 gst_pad_link_ready_for_negotiation (GstPadLink * link)
1134 parent = GST_PAD_PARENT (link->srcpad);
1135 if (!parent || GST_STATE (parent) < GST_STATE_READY) {
1136 GST_DEBUG ("parent %s of pad %s:%s is not READY",
1137 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (link->srcpad));
1140 parent = GST_PAD_PARENT (link->sinkpad);
1141 if (!parent || GST_STATE (parent) < GST_STATE_READY) {
1142 GST_DEBUG ("parent %s of pad %s:%s is not READY",
1143 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (link->sinkpad));
1151 gst_pad_link_fixate (GstPadLink * link)
1158 g_return_if_fail (caps != NULL);
1159 g_return_if_fail (!gst_caps_is_empty (caps));
1161 GST_DEBUG ("trying to fixate caps %" GST_PTR_FORMAT, caps);
1163 gst_caps_do_simplify (caps);
1164 while (!gst_caps_is_fixed (caps)) {
1167 for (i = 0; i < 5; i++) {
1171 g_signal_emit (G_OBJECT (link->srcpad),
1172 gst_real_pad_signals[REAL_FIXATE], 0, caps, &newcaps);
1173 GST_DEBUG ("app srcpad signal fixated to %" GST_PTR_FORMAT, newcaps);
1176 g_signal_emit (G_OBJECT (link->sinkpad),
1177 gst_real_pad_signals[REAL_FIXATE], 0, caps, &newcaps);
1178 GST_DEBUG ("app sinkpad signal fixated to %" GST_PTR_FORMAT, newcaps);
1181 if (GST_RPAD_FIXATEFUNC (link->srcpad)) {
1183 GST_RPAD_FIXATEFUNC (link->srcpad) (GST_PAD (link->srcpad),
1185 GST_DEBUG ("srcpad %s:%s fixated to %" GST_PTR_FORMAT,
1186 GST_DEBUG_PAD_NAME (link->srcpad), newcaps);
1188 GST_DEBUG ("srcpad %s:%s doesn't have a fixate function",
1189 GST_DEBUG_PAD_NAME (link->srcpad));
1193 if (GST_RPAD_FIXATEFUNC (link->sinkpad)) {
1195 GST_RPAD_FIXATEFUNC (link->sinkpad) (GST_PAD (link->sinkpad),
1197 GST_DEBUG ("sinkpad %s:%s fixated to %" GST_PTR_FORMAT,
1198 GST_DEBUG_PAD_NAME (link->sinkpad), newcaps);
1200 GST_DEBUG ("sinkpad %s:%s doesn't have a fixate function",
1201 GST_DEBUG_PAD_NAME (link->sinkpad));
1204 newcaps = _gst_pad_default_fixate_func (GST_PAD (link->srcpad), caps);
1205 GST_DEBUG ("core fixated to %" GST_PTR_FORMAT, newcaps);
1209 G_GNUC_UNUSED gboolean bad;
1211 gst_caps_do_simplify (newcaps);
1212 #ifndef G_DISABLE_CHECKS
1213 /* some mad checking for correctly working fixation functions */
1216 /* we trust the default fixation function unconditionally */
1218 } else if (gst_caps_is_any (caps)) {
1219 bad = gst_caps_is_any (newcaps);
1221 GstCaps *test = gst_caps_subtract (caps, newcaps);
1223 bad = gst_caps_is_empty (test);
1224 gst_caps_free (test);
1225 /* simplifying is ok, too */
1227 bad = (gst_caps_get_size (newcaps) >= gst_caps_get_size (caps));
1230 gchar *newcaps_str = gst_caps_to_string (newcaps);
1231 gchar *caps_str = gst_caps_to_string (caps);
1234 ("a fixation function did not fixate correctly, the returned caps %s are no true subset of %s.",
1235 newcaps_str, caps_str);
1236 g_free (newcaps_str);
1238 gst_caps_free (newcaps);
1242 gst_caps_free (caps);
1253 static GstPadLinkReturn
1254 gst_pad_link_call_link_functions (GstPadLink * link)
1256 GstPadLinkReturn res = GST_PAD_LINK_OK;
1258 /* Detect recursion. */
1259 if (GST_PAD_IS_NEGOTIATING (link->srcpad) ||
1260 GST_PAD_IS_NEGOTIATING (link->sinkpad)) {
1261 GST_ERROR ("The link functions have recursed, please file a bug!");
1262 return GST_PAD_LINK_REFUSED;
1265 /* Both of the pads are in negotiation, so we set the NEGOTIATING flag on both
1266 * of them now to avoid recursion from either pad. */
1267 GST_FLAG_SET (link->srcpad, GST_PAD_NEGOTIATING);
1268 GST_FLAG_SET (link->sinkpad, GST_PAD_NEGOTIATING);
1270 /* If this doesn't run, the status is left to the default OK value. */
1271 if (link->srcnotify && GST_RPAD_LINKFUNC (link->srcpad)) {
1272 GST_DEBUG ("calling link function on pad %s:%s",
1273 GST_DEBUG_PAD_NAME (link->srcpad));
1275 /* call the link function */
1276 res = GST_RPAD_LINKFUNC (link->srcpad) (GST_PAD (link->srcpad), link->caps);
1278 GST_DEBUG ("got reply %d from link function on pad %s:%s",
1279 res, GST_DEBUG_PAD_NAME (link->srcpad));
1281 if (GST_PAD_LINK_FAILED (res)) {
1282 GST_CAT_INFO (GST_CAT_CAPS,
1283 "pad %s:%s doesn't accept caps %" GST_PTR_FORMAT,
1284 GST_DEBUG_PAD_NAME (link->srcpad), link->caps);
1288 if (GST_PAD_LINK_SUCCESSFUL (res) &&
1289 link->sinknotify && GST_RPAD_LINKFUNC (link->sinkpad)) {
1290 GST_DEBUG ("calling link function on pad %s:%s",
1291 GST_DEBUG_PAD_NAME (link->sinkpad));
1293 /* call the link function */
1294 res = GST_RPAD_LINKFUNC (link->sinkpad) (GST_PAD (link->sinkpad),
1297 GST_DEBUG ("got reply %d from link function on pad %s:%s",
1298 res, GST_DEBUG_PAD_NAME (link->sinkpad));
1300 if (GST_PAD_LINK_FAILED (res)) {
1301 GST_CAT_INFO (GST_CAT_CAPS,
1302 "pad %s:%s doesn't accept caps %" GST_PTR_FORMAT,
1303 GST_DEBUG_PAD_NAME (link->sinkpad), link->caps);
1307 GST_FLAG_UNSET (link->srcpad, GST_PAD_NEGOTIATING);
1308 GST_FLAG_UNSET (link->sinkpad, GST_PAD_NEGOTIATING);
1312 static GstPadLinkReturn
1313 gst_pad_link_negotiate (GstPadLink * link)
1315 GST_DEBUG ("negotiating link from pad %s:%s to pad %s:%s",
1316 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1318 gst_pad_link_intersect (link);
1319 if (gst_caps_is_empty (link->caps))
1320 return GST_PAD_LINK_REFUSED;
1322 gst_pad_link_fixate (link);
1323 if (gst_caps_is_empty (link->caps))
1324 return GST_PAD_LINK_REFUSED;
1326 if (!gst_pad_link_ready_for_negotiation (link)) {
1327 return GST_PAD_LINK_DELAYED;
1329 GST_DEBUG ("trying to call link function on caps %" GST_PTR_FORMAT,
1332 return gst_pad_link_call_link_functions (link);
1337 * @link: link to try
1339 * Tries to (re)link the pads with the given link. The function takes ownership
1340 * of the supplied link. If the function returns FALSE and an old link existed,
1341 * that link can be assumed to work unchanged.
1343 * Returns: TRUE if the link succeeded, FALSE if not.
1346 gst_pad_link_try (GstPadLink * link)
1348 GstPad *srcpad, *sinkpad;
1349 GstPadLink *oldlink;
1350 GstPadLinkReturn ret;
1352 /* we use assertions here, because this function is static */
1354 srcpad = link->srcpad;
1356 sinkpad = link->sinkpad;
1358 oldlink = GST_RPAD_LINK (srcpad);
1359 g_assert (oldlink == GST_RPAD_LINK (sinkpad));
1361 GST_DEBUG ("negotiating given link");
1362 ret = gst_pad_link_negotiate (link);
1363 if (GST_PAD_LINK_FAILED (ret) && oldlink && oldlink->caps) {
1364 GST_DEBUG ("negotiating failed, but there was a valid old link");
1365 oldlink->srcnotify = link->srcnotify;
1366 oldlink->sinknotify = link->sinknotify;
1367 if (GST_PAD_LINK_FAILED (gst_pad_link_call_link_functions (oldlink))) {
1368 g_warning ("pads don't accept old caps. We assume they did though");
1371 if (ret == GST_PAD_LINK_REFUSED) {
1372 GST_DEBUG ("link refused, returning");
1373 gst_pad_link_free (link);
1376 if (ret == GST_PAD_LINK_DELAYED) {
1377 GST_DEBUG ("link delayed, replacing link caps and returning");
1378 gst_caps_replace (&link->caps, NULL);
1381 GST_RPAD_PEER (srcpad) = GST_REAL_PAD (link->sinkpad);
1382 GST_RPAD_PEER (sinkpad) = GST_REAL_PAD (link->srcpad);
1384 GST_DEBUG ("copying stuff from oldlink");
1385 link->temp_store = oldlink->temp_store;
1386 GST_DEBUG ("moving old data temp store %p", link->temp_store);
1387 link->engaged = oldlink->engaged;
1388 oldlink->temp_store = NULL;
1389 gst_pad_link_free (oldlink);
1391 GST_RPAD_LINK (srcpad) = link;
1392 GST_RPAD_LINK (sinkpad) = link;
1393 if (ret == GST_PAD_LINK_OK) {
1394 GST_DEBUG ("notifying caps after successful link");
1395 g_object_notify (G_OBJECT (srcpad), "caps");
1396 g_object_notify (G_OBJECT (sinkpad), "caps");
1403 * gst_pad_renegotiate:
1406 * Initiate caps negotiation on @pad. @pad must be linked.
1408 * If @pad's parent is not at least in #GST_STATE_READY, returns
1409 * #GST_PAD_LINK_DELAYED.
1411 * Otherwise caps are retrieved from both @pad and its peer by calling their
1412 * getcaps functions. They are then intersected, returning #GST_PAD_LINK_FAIL if
1413 * there is no intersection.
1415 * The intersection is fixated if necessary, and then the link functions of @pad
1416 * and its peer are called.
1418 * Returns: The return value of @pad's link function (see
1419 * gst_pad_set_link_function()), or #GST_PAD_LINK_OK if there is no link
1422 * The macros GST_PAD_LINK_SUCCESSFUL() and GST_PAD_LINK_FAILED() should be used
1423 * when you just need success/failure information.
1426 gst_pad_renegotiate (GstPad * pad)
1430 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
1431 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1432 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1434 link = gst_pad_link_new ();
1436 link->srcpad = GST_PAD_LINK_SRC (pad);
1437 link->sinkpad = GST_PAD_LINK_SINK (pad);
1439 if (!gst_pad_link_ready_for_negotiation (link)) {
1440 gst_pad_link_free (link);
1441 return GST_PAD_LINK_DELAYED;
1444 if (GST_REAL_PAD (pad)->link->filtercaps) {
1445 link->filtercaps = gst_caps_copy (GST_REAL_PAD (pad)->link->filtercaps);
1447 link->srccaps = gst_pad_get_caps (link->srcpad);
1448 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1450 return gst_pad_link_try (link);
1454 * gst_pad_try_set_caps:
1456 * @caps: #GstCaps to set on @pad
1458 * Try to set the caps on @pad. @caps must be fixed. If @pad is unlinked,
1459 * returns #GST_PAD_LINK_OK without doing anything. Otherwise, start caps
1460 * negotiation on @pad.
1462 * Returns: The return value of @pad's link function (see
1463 * gst_pad_set_link_function()), or #GST_PAD_LINK_OK if there is no link
1466 * The macros GST_PAD_LINK_SUCCESSFUL() and GST_PAD_LINK_FAILED() should be used
1467 * when you just need success/failure information.
1470 gst_pad_try_set_caps (GstPad * pad, const GstCaps * caps)
1473 GstPadLink *oldlink;
1474 GstPadLinkReturn ret;
1476 g_return_val_if_fail (GST_IS_REAL_PAD (pad), GST_PAD_LINK_REFUSED);
1478 GST_LOG_OBJECT (pad, "Trying to set %" GST_PTR_FORMAT, caps);
1480 if (GST_PAD_IS_NEGOTIATING (pad)) {
1481 GST_DEBUG_OBJECT (pad, "Detected a recursion, just returning OK");
1482 return GST_PAD_LINK_OK;
1485 GST_CAT_INFO_OBJECT (GST_CAT_CAPS, pad, "caps %" GST_PTR_FORMAT, caps);
1486 /* setting non-fixed caps on a pad is not allowed */
1487 if (!gst_caps_is_fixed (caps)) {
1488 GST_CAT_INFO (GST_CAT_CAPS,
1489 "trying to set unfixed caps on pad %s:%s, not allowed",
1490 GST_DEBUG_PAD_NAME (pad));
1491 g_warning ("trying to set non fixed caps on pad %s:%s, not allowed",
1492 GST_DEBUG_PAD_NAME (pad));
1494 GST_DEBUG ("unfixed caps %" GST_PTR_FORMAT, caps);
1495 return GST_PAD_LINK_REFUSED;
1498 /* we allow setting caps on non-linked pads. It's ignored */
1499 if (!GST_PAD_PEER (pad)) {
1500 GST_DEBUG ("unlinked pad %s:%s, returning OK", GST_DEBUG_PAD_NAME (pad));
1501 return GST_PAD_LINK_OK;
1504 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1505 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1507 /* if the desired caps are already there, it's trivially ok */
1508 if (GST_PAD_CAPS (pad) && gst_caps_is_equal (caps, GST_PAD_CAPS (pad))) {
1509 GST_DEBUG ("pad %s:%s already has these caps", GST_DEBUG_PAD_NAME (pad));
1510 return GST_PAD_LINK_OK;
1513 link = gst_pad_link_new ();
1515 link->srcpad = GST_PAD_LINK_SRC (pad);
1516 link->sinkpad = GST_PAD_LINK_SINK (pad);
1518 if (!gst_pad_link_ready_for_negotiation (link)) {
1519 GST_DEBUG ("link not ready for negotiating, delaying");
1520 gst_pad_link_free (link);
1521 return GST_PAD_LINK_DELAYED;
1524 oldlink = GST_REAL_PAD (pad)->link;
1525 if (oldlink && oldlink->filtercaps) {
1526 link->filtercaps = gst_caps_copy (oldlink->filtercaps);
1528 if (link->srcpad == pad) {
1529 link->srccaps = gst_caps_copy (caps);
1530 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1531 link->srcnotify = FALSE;
1533 link->srccaps = gst_pad_get_caps (link->srcpad);
1534 link->sinkcaps = gst_caps_copy (caps);
1535 link->sinknotify = FALSE;
1538 GST_DEBUG ("trying to link");
1539 ret = gst_pad_link_try (link);
1545 * gst_pad_try_set_caps_nonfixed:
1546 * @pad: a real #GstPad
1547 * @caps: #GstCaps to set on @pad
1549 * Like gst_pad_try_set_caps(), but allows non-fixed caps.
1551 * Returns: a #GstPadLinkReturn, like gst_pad_try_set_caps().
1554 gst_pad_try_set_caps_nonfixed (GstPad * pad, const GstCaps * caps)
1557 GstPadLink *oldlink;
1558 GstPadLinkReturn ret;
1560 g_return_val_if_fail (GST_IS_REAL_PAD (pad), GST_PAD_LINK_REFUSED);
1561 g_return_val_if_fail (!GST_PAD_IS_NEGOTIATING (pad), GST_PAD_LINK_REFUSED);
1563 /* we allow setting caps on non-linked pads. It's ignored */
1564 if (!GST_PAD_PEER (pad)) {
1565 return GST_PAD_LINK_OK;
1568 g_return_val_if_fail (GST_PAD_LINK_SRC (pad), GST_PAD_LINK_REFUSED);
1569 g_return_val_if_fail (GST_PAD_LINK_SINK (pad), GST_PAD_LINK_REFUSED);
1571 /* if the link is already negotiated and the caps are compatible
1572 * with what we're setting, it's trivially OK. */
1573 if (GST_PAD_CAPS (pad)) {
1574 GstCaps *intersection;
1576 intersection = gst_caps_intersect (caps, GST_PAD_CAPS (pad));
1577 if (!gst_caps_is_empty (intersection)) {
1578 gst_caps_free (intersection);
1579 return GST_PAD_LINK_OK;
1581 gst_caps_free (intersection);
1584 link = gst_pad_link_new ();
1586 link->srcpad = GST_PAD_LINK_SRC (pad);
1587 link->sinkpad = GST_PAD_LINK_SINK (pad);
1589 if (!gst_pad_link_ready_for_negotiation (link)) {
1590 gst_pad_link_free (link);
1591 return GST_PAD_LINK_DELAYED;
1594 oldlink = GST_REAL_PAD (pad)->link;
1595 if (oldlink && oldlink->filtercaps) {
1596 link->filtercaps = gst_caps_copy (oldlink->filtercaps);
1598 if (link->srcpad == pad) {
1599 link->srccaps = gst_caps_copy (caps);
1600 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1601 link->srcnotify = FALSE;
1603 link->srccaps = gst_pad_get_caps (link->srcpad);
1604 link->sinkcaps = gst_caps_copy (caps);
1605 link->sinknotify = FALSE;
1608 ret = gst_pad_link_try (link);
1614 * gst_pad_can_link_filtered:
1615 * @srcpad: the source #GstPad to link.
1616 * @sinkpad: the sink #GstPad to link.
1617 * @filtercaps: the filter #GstCaps.
1619 * Checks if the source pad and the sink pad can be linked when constrained
1620 * by the given filter caps. Both @srcpad and @sinkpad must be unlinked.
1622 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1625 gst_pad_can_link_filtered (GstPad * srcpad, GstPad * sinkpad,
1626 const GstCaps * filtercaps)
1628 GstRealPad *realsrc, *realsink;
1631 /* FIXME This function is gross. It's almost a direct copy of
1632 * gst_pad_link_filtered(). Any decent programmer would attempt
1633 * to merge the two functions, which I will do some day. --ds
1636 /* generic checks */
1637 g_return_val_if_fail (srcpad != NULL, FALSE);
1638 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1639 g_return_val_if_fail (sinkpad != NULL, FALSE);
1640 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1642 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1643 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1645 /* now we need to deal with the real/ghost stuff */
1646 realsrc = GST_PAD_REALIZE (srcpad);
1647 realsink = GST_PAD_REALIZE (sinkpad);
1649 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1650 GST_CAT_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
1651 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1653 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1654 if (GST_RPAD_PEER (realsrc) != NULL) {
1655 GST_CAT_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1656 GST_DEBUG_PAD_NAME (realsrc));
1659 if (GST_RPAD_PEER (realsink) != NULL) {
1660 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1661 GST_DEBUG_PAD_NAME (realsink));
1664 if (GST_PAD_PARENT (realsrc) == NULL) {
1665 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1666 GST_DEBUG_PAD_NAME (realsrc));
1669 if (GST_PAD_PARENT (realsink) == NULL) {
1670 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has no parent, failed",
1671 GST_DEBUG_PAD_NAME (realsrc));
1675 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1676 g_warning ("linking pads with different scheds requires "
1677 "exactly one decoupled element (such as queue)");
1681 g_return_val_if_fail (realsrc != NULL, GST_PAD_LINK_REFUSED);
1682 g_return_val_if_fail (realsink != NULL, GST_PAD_LINK_REFUSED);
1684 link = gst_pad_link_new ();
1686 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
1687 link->srcpad = GST_PAD (realsrc);
1688 link->sinkpad = GST_PAD (realsink);
1690 link->srcpad = GST_PAD (realsink);
1691 link->sinkpad = GST_PAD (realsrc);
1694 if (GST_RPAD_DIRECTION (link->srcpad) != GST_PAD_SRC) {
1695 GST_CAT_INFO (GST_CAT_PADS,
1696 "Real src pad %s:%s is not a source pad, failed",
1697 GST_DEBUG_PAD_NAME (link->srcpad));
1698 gst_pad_link_free (link);
1701 if (GST_RPAD_DIRECTION (link->sinkpad) != GST_PAD_SINK) {
1702 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1703 GST_DEBUG_PAD_NAME (link->sinkpad));
1704 gst_pad_link_free (link);
1708 link->srccaps = gst_pad_get_caps (link->srcpad);
1709 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1711 link->filtercaps = gst_caps_copy (filtercaps);
1713 gst_pad_link_intersect (link);
1714 if (gst_caps_is_empty (link->caps)) {
1715 gst_pad_link_free (link);
1719 gst_pad_link_free (link);
1725 * @srcpad: the source #GstPad to link.
1726 * @sinkpad: the sink #GstPad to link.
1728 * Checks if the source pad and the sink pad can be linked.
1730 * Returns: TRUE if the pads can be linked, FALSE otherwise.
1733 gst_pad_can_link (GstPad * srcpad, GstPad * sinkpad)
1735 return gst_pad_can_link_filtered (srcpad, sinkpad, NULL);
1739 * gst_pad_link_filtered:
1740 * @srcpad: the source #GstPad to link.
1741 * @sinkpad: the sink #GstPad to link.
1742 * @filtercaps: the filter #GstCaps.
1744 * Links the source pad and the sink pad, constrained
1745 * by the given filter caps.
1747 * Returns: TRUE if the pads have been linked, FALSE otherwise.
1750 gst_pad_link_filtered (GstPad * srcpad, GstPad * sinkpad,
1751 const GstCaps * filtercaps)
1753 GstRealPad *realsrc, *realsink;
1754 GstScheduler *src_sched, *sink_sched;
1757 /* generic checks */
1758 g_return_val_if_fail (srcpad != NULL, FALSE);
1759 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1760 g_return_val_if_fail (sinkpad != NULL, FALSE);
1761 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1763 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
1764 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1766 /* now we need to deal with the real/ghost stuff */
1767 realsrc = GST_PAD_REALIZE (srcpad);
1768 realsink = GST_PAD_REALIZE (sinkpad);
1770 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1771 GST_CAT_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
1772 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1774 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1775 if (GST_RPAD_PEER (realsrc) != NULL) {
1776 GST_CAT_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1777 GST_DEBUG_PAD_NAME (realsrc));
1780 if (GST_RPAD_PEER (realsink) != NULL) {
1781 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1782 GST_DEBUG_PAD_NAME (realsink));
1785 if (GST_PAD_PARENT (realsrc) == NULL) {
1786 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1787 GST_DEBUG_PAD_NAME (realsrc));
1790 if (GST_PAD_PARENT (realsink) == NULL) {
1791 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has no parent, failed",
1792 GST_DEBUG_PAD_NAME (realsrc));
1796 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1797 g_warning ("linking pads with different scheds requires "
1798 "exactly one decoupled element (such as queue)");
1802 g_return_val_if_fail (realsrc != NULL, GST_PAD_LINK_REFUSED);
1803 g_return_val_if_fail (realsink != NULL, GST_PAD_LINK_REFUSED);
1805 link = gst_pad_link_new ();
1807 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
1808 link->srcpad = GST_PAD (realsrc);
1809 link->sinkpad = GST_PAD (realsink);
1811 link->srcpad = GST_PAD (realsink);
1812 link->sinkpad = GST_PAD (realsrc);
1815 if (GST_RPAD_DIRECTION (link->srcpad) != GST_PAD_SRC) {
1816 GST_CAT_INFO (GST_CAT_PADS,
1817 "Real src pad %s:%s is not a source pad, failed",
1818 GST_DEBUG_PAD_NAME (link->srcpad));
1819 gst_pad_link_free (link);
1822 if (GST_RPAD_DIRECTION (link->sinkpad) != GST_PAD_SINK) {
1823 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1824 GST_DEBUG_PAD_NAME (link->sinkpad));
1825 gst_pad_link_free (link);
1829 link->srccaps = gst_pad_get_caps (link->srcpad);
1830 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
1832 link->filtercaps = gst_caps_copy (filtercaps);
1833 if (gst_pad_link_try (link) == GST_PAD_LINK_REFUSED)
1836 /* fire off a signal to each of the pads telling them
1837 * that they've been linked */
1838 g_signal_emit (G_OBJECT (link->srcpad), gst_real_pad_signals[REAL_LINKED],
1840 g_signal_emit (G_OBJECT (link->sinkpad), gst_real_pad_signals[REAL_LINKED],
1843 src_sched = gst_pad_get_scheduler (GST_PAD (link->srcpad));
1844 sink_sched = gst_pad_get_scheduler (GST_PAD (link->sinkpad));
1846 /* now tell the scheduler */
1847 if (src_sched && src_sched == sink_sched) {
1848 gst_scheduler_pad_link (src_sched,
1849 GST_PAD (link->srcpad), GST_PAD (link->sinkpad));
1851 GST_CAT_INFO (GST_CAT_PADS,
1852 "not telling link to scheduler %s:%s and %s:%s, %p %p",
1853 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad),
1854 src_sched, sink_sched);
1857 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1858 GST_DEBUG_PAD_NAME (link->srcpad), GST_DEBUG_PAD_NAME (link->sinkpad));
1865 * @srcpad: the source #GstPad to link.
1866 * @sinkpad: the sink #GstPad to link.
1868 * Links the source pad to the sink pad.
1870 * Returns: TRUE if the pad could be linked, FALSE otherwise.
1873 gst_pad_link (GstPad * srcpad, GstPad * sinkpad)
1875 return gst_pad_link_filtered (srcpad, sinkpad, NULL);
1878 /* FIXME 0.9: Remove this */
1880 * gst_pad_set_parent:
1881 * @pad: a #GstPad to set the parent of.
1882 * @parent: the new parent #GstElement.
1884 * Sets the parent object of a pad. Deprecated, use gst_object_set_parent()
1888 gst_pad_set_parent (GstPad * pad, GstElement * parent)
1890 g_return_if_fail (GST_IS_PAD (pad));
1891 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
1892 g_return_if_fail (GST_IS_ELEMENT (parent));
1894 gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (parent));
1897 /* FIXME 0.9: Remove this */
1899 * gst_pad_get_parent:
1900 * @pad: the #GstPad to get the parent of.
1902 * Gets the parent object of this pad. Deprecated, use gst_object_get_parent()
1905 * Returns: the parent #GstElement.
1908 gst_pad_get_parent (GstPad * pad)
1910 g_return_val_if_fail (pad != NULL, NULL);
1911 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1913 return GST_PAD_PARENT (pad);
1917 gst_pad_set_pad_template (GstPad * pad, GstPadTemplate * templ)
1919 /* this function would need checks if it weren't static */
1921 gst_object_replace ((GstObject **) & pad->padtemplate, (GstObject *) templ);
1924 gst_object_sink (GST_OBJECT (templ));
1925 g_signal_emit (G_OBJECT (templ),
1926 gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
1931 * gst_pad_get_pad_template:
1934 * Gets the template for @pad.
1936 * Returns: the #GstPadTemplate from which this pad was instantiated, or %NULL
1937 * if this pad has no template.
1940 gst_pad_get_pad_template (GstPad * pad)
1942 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1944 return GST_PAD_PAD_TEMPLATE (pad);
1949 * gst_pad_get_scheduler:
1950 * @pad: a #GstPad to get the scheduler of.
1952 * Gets the scheduler of the pad. Since the pad does not
1953 * have a scheduler of its own, the scheduler of the parent
1954 * is taken. For decoupled pads, the scheduler of the peer
1957 * Returns: the #GstScheduler of the pad, or %NULL if there is no parent or the
1958 * parent is not yet in a managing bin.
1961 gst_pad_get_scheduler (GstPad * pad)
1963 GstScheduler *scheduler = NULL;
1966 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1968 parent = gst_pad_get_parent (pad);
1970 if (GST_FLAG_IS_SET (parent, GST_ELEMENT_DECOUPLED)) {
1971 GstRealPad *peer = GST_RPAD_PEER (pad);
1975 gst_element_get_scheduler (gst_pad_get_parent (GST_PAD (peer)));
1978 scheduler = gst_element_get_scheduler (parent);
1986 * gst_pad_get_real_parent:
1987 * @pad: a #GstPad to get the real parent of.
1989 * Gets the real parent object of this pad. If the pad
1990 * is a ghost pad, the actual owner of the real pad is
1991 * returned, as opposed to #gst_pad_get_parent().
1993 * Returns: the parent #GstElement.
1996 gst_pad_get_real_parent (GstPad * pad)
1998 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2000 return GST_PAD_PARENT (GST_PAD (GST_PAD_REALIZE (pad)));
2003 /* FIXME 0.9: Make static. */
2005 * gst_pad_add_ghost_pad:
2006 * @pad: a #GstPad to attach the ghost pad to.
2007 * @ghostpad: the ghost #GstPad to to the pad.
2009 * Adds a ghost pad to a pad. Private function, will be removed from the API in
2013 gst_pad_add_ghost_pad (GstPad * pad, GstPad * ghostpad)
2015 GstRealPad *realpad;
2017 g_return_if_fail (GST_IS_PAD (pad));
2018 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
2020 /* if we're ghosting a ghost pad, drill down to find the real pad */
2021 realpad = (GstRealPad *) pad;
2022 while (GST_IS_GHOST_PAD (realpad))
2023 realpad = GST_GPAD_REALPAD (realpad);
2024 g_return_if_fail (GST_IS_REAL_PAD (realpad));
2026 /* will ref the pad template */
2027 GST_GPAD_REALPAD (ghostpad) = realpad;
2028 realpad->ghostpads = g_list_prepend (realpad->ghostpads, ghostpad);
2029 gst_pad_set_pad_template (GST_PAD (ghostpad), GST_PAD_PAD_TEMPLATE (pad));
2032 /* FIXME 0.9: Make static. */
2034 * gst_pad_remove_ghost_pad:
2035 * @pad: a #GstPad to remove the ghost pad from.
2036 * @ghostpad: the ghost #GstPad to remove from the pad.
2038 * Removes a ghost pad from a pad. Private, will be removed from the API in 0.9.
2041 gst_pad_remove_ghost_pad (GstPad * pad, GstPad * ghostpad)
2043 GstRealPad *realpad;
2045 g_return_if_fail (GST_IS_PAD (pad));
2046 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
2047 realpad = GST_PAD_REALIZE (pad);
2048 g_return_if_fail (GST_GPAD_REALPAD (ghostpad) == realpad);
2050 gst_pad_set_pad_template (GST_PAD (ghostpad), NULL);
2051 realpad->ghostpads = g_list_remove (realpad->ghostpads, ghostpad);
2052 GST_GPAD_REALPAD (ghostpad) = NULL;
2056 * gst_pad_get_ghost_pad_list:
2057 * @pad: a #GstPad to get the ghost pads of.
2059 * Gets the ghost pads of this pad.
2061 * Returns: a #GList of ghost pads.
2064 gst_pad_get_ghost_pad_list (GstPad * pad)
2066 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2068 return GST_PAD_REALIZE (pad)->ghostpads;
2072 _gst_pad_default_fixate_foreach (GQuark field_id, GValue * value, gpointer s)
2074 GstStructure *structure = (GstStructure *) s;
2075 GType type = G_VALUE_TYPE (value);
2077 if (gst_type_is_fixed (type))
2080 if (type == GST_TYPE_INT_RANGE) {
2081 gst_structure_set (structure, g_quark_to_string (field_id),
2082 G_TYPE_INT, gst_value_get_int_range_min (value), NULL);
2085 if (type == GST_TYPE_DOUBLE_RANGE) {
2086 gst_structure_set (structure, g_quark_to_string (field_id),
2087 G_TYPE_DOUBLE, gst_value_get_double_range_min (value), NULL);
2090 if (type == GST_TYPE_LIST) {
2091 gst_structure_set_value (structure, g_quark_to_string (field_id),
2092 gst_value_list_get_value (value, 0));
2096 g_critical ("don't know how to fixate type %s", g_type_name (type));
2101 _gst_pad_default_fixate_func (GstPad * pad, const GstCaps * caps)
2103 static GstStaticCaps octetcaps = GST_STATIC_CAPS ("application/octet-stream");
2104 GstStructure *structure;
2107 g_return_val_if_fail (pad != NULL, NULL);
2108 g_return_val_if_fail (caps != NULL, NULL);
2109 g_return_val_if_fail (!gst_caps_is_empty (caps), NULL);
2111 if (gst_caps_is_any (caps)) {
2112 return gst_caps_copy (gst_static_caps_get (&octetcaps));
2115 if (caps->structs->len > 1) {
2116 return gst_caps_new_full (gst_structure_copy (gst_caps_get_structure (caps,
2120 newcaps = gst_caps_copy (caps);
2121 structure = gst_caps_get_structure (newcaps, 0);
2122 gst_structure_foreach (structure, _gst_pad_default_fixate_foreach, structure);
2128 * gst_pad_perform_negotiate:
2129 * @srcpad: the source #GstPad.
2130 * @sinkpad: the sink #GstPad.
2132 * Tries to negotiate the pads. See gst_pad_renegotiate() for a brief
2133 * description of caps negotiation.
2135 * Returns: TRUE if the pads were succesfully negotiated, FALSE otherwise.
2138 gst_pad_perform_negotiate (GstPad * srcpad, GstPad * sinkpad)
2140 return GST_PAD_LINK_SUCCESSFUL (gst_pad_renegotiate (srcpad));
2144 gst_pad_link_unnegotiate (GstPadLink * link)
2146 g_return_if_fail (link != NULL);
2149 gst_caps_free (link->caps);
2151 link->engaged = FALSE;
2152 if (GST_RPAD_LINK (link->srcpad) != link) {
2153 g_warning ("unnegotiating unset link");
2155 g_object_notify (G_OBJECT (link->srcpad), "caps");
2157 if (GST_RPAD_LINK (link->sinkpad) != link) {
2158 g_warning ("unnegotiating unset link");
2160 g_object_notify (G_OBJECT (link->sinkpad), "caps");
2166 * gst_pad_unnegotiate:
2167 * @pad: pad to unnegotiate
2169 * "Unnegotiates" a pad. The currently negotiated caps are cleared and the pad
2170 * needs renegotiation.
2173 gst_pad_unnegotiate (GstPad * pad)
2177 g_return_if_fail (GST_IS_PAD (pad));
2179 link = GST_RPAD_LINK (GST_PAD_REALIZE (pad));
2181 gst_pad_link_unnegotiate (link);
2184 /* returning NULL indicates that the arguments are invalid */
2186 gst_pad_link_prepare (GstPad * srcpad, GstPad * sinkpad,
2187 const GstCaps * filtercaps)
2189 GstRealPad *realsrc, *realsink;
2192 g_return_val_if_fail (GST_IS_PAD (srcpad), NULL);
2193 g_return_val_if_fail (GST_IS_PAD (sinkpad), NULL);
2195 realsrc = GST_PAD_REALIZE (srcpad);
2196 realsink = GST_PAD_REALIZE (sinkpad);
2198 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
2199 GST_CAT_DEBUG (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
2200 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
2203 g_return_val_if_fail (GST_RPAD_PEER (realsrc) == NULL, NULL);
2204 g_return_val_if_fail (GST_RPAD_PEER (realsink) == NULL, NULL);
2205 g_return_val_if_fail (GST_PAD_PARENT (realsrc) != NULL, NULL);
2206 g_return_val_if_fail (GST_PAD_PARENT (realsink) != NULL, NULL);
2208 if (!gst_pad_check_schedulers (realsrc, realsink)) {
2209 g_warning ("linking pads with different scheds requires "
2210 "exactly one decoupled element (such as queue)");
2214 if (GST_RPAD_DIRECTION (realsrc) == GST_RPAD_DIRECTION (realsink)) {
2215 g_warning ("%s:%s and %s:%s are both %s pads, failed",
2216 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink),
2217 GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC ? "src" : "sink");
2221 link = gst_pad_link_new ();
2223 if (GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) {
2224 link->srcpad = GST_PAD (realsrc);
2225 link->sinkpad = GST_PAD (realsink);
2227 link->srcpad = GST_PAD (realsink);
2228 link->sinkpad = GST_PAD (realsrc);
2231 link->srccaps = gst_pad_get_caps (link->srcpad);
2232 link->sinkcaps = gst_pad_get_caps (link->sinkpad);
2234 link->filtercaps = gst_caps_copy (filtercaps);
2240 * gst_pad_try_relink_filtered:
2241 * @srcpad: the source #GstPad to relink.
2242 * @sinkpad: the sink #GstPad to relink.
2243 * @filtercaps: the #GstPad to use as a filter in the relink.
2245 * Tries to relink the given source and sink pad, constrained by the given
2248 * Returns: TRUE if the pads were succesfully renegotiated, FALSE otherwise.
2251 gst_pad_try_relink_filtered (GstPad * srcpad, GstPad * sinkpad,
2252 const GstCaps * filtercaps)
2256 GST_INFO ("trying to relink %" GST_PTR_FORMAT " and %" GST_PTR_FORMAT
2257 " with filtercaps %" GST_PTR_FORMAT, srcpad, sinkpad);
2259 link = gst_pad_link_prepare (srcpad, sinkpad, filtercaps);
2263 if (GST_RPAD_PEER (link->srcpad) != (GstRealPad *) link->sinkpad) {
2264 g_warning ("Pads %s:%s and %s:%s were never linked",
2265 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
2266 gst_pad_link_free (link);
2270 if (GST_PAD_LINK_FAILED (gst_pad_link_try (link)))
2277 * gst_pad_relink_filtered:
2278 * @srcpad: the source #GstPad to relink.
2279 * @sinkpad: the sink #GstPad to relink.
2280 * @filtercaps: the #GstPad to use as a filter in the relink.
2282 * Relinks the given source and sink pad, constrained by the given
2283 * capabilities. If the relink fails, the pads are unlinked
2284 * and FALSE is returned.
2286 * Returns: TRUE if the pads were succesfully relinked, FALSE otherwise.
2289 gst_pad_relink_filtered (GstPad * srcpad, GstPad * sinkpad,
2290 const GstCaps * filtercaps)
2292 if (gst_pad_try_relink_filtered (srcpad, sinkpad, filtercaps))
2295 gst_pad_unlink (srcpad, sinkpad);
2300 * gst_pad_proxy_getcaps:
2301 * @pad: a #GstPad to proxy.
2303 * Calls gst_pad_get_allowed_caps() for every other pad belonging to the
2304 * same element as @pad, and returns the intersection of the results.
2306 * This function is useful as a default getcaps function for an element
2307 * that can handle any stream format, but requires all its pads to have
2308 * the same caps. Two such elements are tee and aggregator.
2310 * Returns: the intersection of the other pads' allowed caps.
2313 gst_pad_proxy_getcaps (GstPad * pad)
2315 GstElement *element;
2317 GstCaps *caps, *intersected;
2319 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2321 GST_DEBUG ("proxying getcaps for %s:%s", GST_DEBUG_PAD_NAME (pad));
2323 element = gst_pad_get_parent (pad);
2325 pads = gst_element_get_pad_list (element);
2327 caps = gst_caps_new_any ();
2329 GstPad *otherpad = GST_PAD (pads->data);
2332 if (otherpad != pad) {
2333 GstCaps *allowed = gst_pad_get_allowed_caps (otherpad);
2335 temp = gst_caps_intersect (caps, allowed);
2336 gst_caps_free (caps);
2337 gst_caps_free (allowed);
2341 pads = g_list_next (pads);
2344 intersected = gst_caps_intersect (caps, gst_pad_get_pad_template_caps (pad));
2345 gst_caps_free (caps);
2350 * gst_pad_proxy_pad_link:
2351 * @pad: a #GstPad to proxy from
2352 * @caps: the #GstCaps to link with
2354 * Calls gst_pad_try_set_caps() for every other pad belonging to the
2355 * same element as @pad. If gst_pad_try_set_caps() fails on any pad,
2356 * the proxy link fails. May be used only during negotiation.
2358 * Returns: GST_PAD_LINK_OK if sucessful
2361 gst_pad_proxy_pad_link (GstPad * pad, const GstCaps * caps)
2363 GstElement *element;
2365 GstPadLinkReturn ret;
2367 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
2368 g_return_val_if_fail (caps != NULL, GST_PAD_LINK_REFUSED);
2370 GST_DEBUG ("proxying pad link for %s:%s", GST_DEBUG_PAD_NAME (pad));
2372 element = gst_pad_get_parent (pad);
2374 pads = gst_element_get_pad_list (element);
2377 GstPad *otherpad = GST_PAD (pads->data);
2379 if (otherpad != pad) {
2380 ret = gst_pad_try_set_caps (otherpad, caps);
2381 if (GST_PAD_LINK_FAILED (ret)) {
2385 pads = g_list_next (pads);
2388 return GST_PAD_LINK_OK;
2392 * gst_pad_proxy_fixate:
2393 * @pad: a #GstPad to proxy.
2394 * @caps: the #GstCaps to fixate
2396 * Implements a default fixate function based on the caps set on the other
2397 * pads in the element. This function should only be used if every pad
2398 * has the same pad template caps.
2400 * Returns: a fixated caps, or NULL if caps cannot be fixed
2403 gst_pad_proxy_fixate (GstPad * pad, const GstCaps * caps)
2405 GstElement *element;
2407 const GstCaps *othercaps;
2409 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2410 g_return_val_if_fail (caps != NULL, NULL);
2412 GST_DEBUG ("proxying fixate for %s:%s\n", GST_DEBUG_PAD_NAME (pad));
2414 element = gst_pad_get_parent (pad);
2416 pads = gst_element_get_pad_list (element);
2419 GstPad *otherpad = GST_PAD (pads->data);
2421 /* FIXME check that each pad has the same pad template caps */
2423 if (otherpad != pad) {
2424 othercaps = gst_pad_get_negotiated_caps (otherpad);
2426 if (othercaps && !gst_caps_is_subset (caps, othercaps)) {
2429 icaps = gst_caps_intersect (othercaps, caps);
2430 if (!gst_caps_is_empty (icaps)) {
2433 gst_caps_free (icaps);
2437 pads = g_list_next (pads);
2444 * gst_pad_set_explicit_caps:
2445 * @pad: a #GstPad to set the explicit caps of
2446 * @caps: the #GstCaps to set
2448 * If a pad has been told to use explicit caps, this function is used
2449 * to set the explicit caps. If @caps is NULL, the explicit caps are
2452 * This function calls gst_pad_try_set_caps() on the pad. If that
2453 * call fails, GST_ELEMENT_ERROR() is called to indicate a negotiation
2456 * Returns: TRUE if the caps were set correctly, otherwise FALSE
2459 gst_pad_set_explicit_caps (GstPad * pad, const GstCaps * caps)
2461 GstPadLinkReturn link_ret;
2463 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2465 GST_CAT_DEBUG (GST_CAT_PADS,
2466 "setting explicit caps on %s:%s to %" GST_PTR_FORMAT,
2467 GST_DEBUG_PAD_NAME (pad), caps);
2470 GST_CAT_DEBUG (GST_CAT_PADS, "caps is NULL");
2471 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2475 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), gst_caps_copy (caps));
2477 if (!GST_PAD_IS_LINKED (pad)) {
2478 GST_CAT_DEBUG (GST_CAT_PADS, "pad is not linked");
2481 link_ret = gst_pad_try_set_caps (pad, caps);
2482 if (link_ret == GST_PAD_LINK_REFUSED) {
2483 gchar *caps_str = gst_caps_to_string (caps);
2485 GST_ELEMENT_ERROR (gst_pad_get_parent (pad), CORE, PAD, (NULL),
2486 ("failed to negotiate (try_set_caps with \"%s\" returned REFUSED)",
2496 gst_pad_explicit_getcaps (GstPad * pad)
2498 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2500 if (GST_RPAD_EXPLICIT_CAPS (pad) == NULL) {
2501 const GstCaps *caps = gst_pad_get_pad_template_caps (pad);
2503 return gst_caps_copy (caps);
2505 return gst_caps_copy (GST_RPAD_EXPLICIT_CAPS (pad));
2508 static GstPadLinkReturn
2509 gst_pad_explicit_link (GstPad * pad, const GstCaps * caps)
2511 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
2512 g_return_val_if_fail (caps != NULL, GST_PAD_LINK_REFUSED);
2514 if (GST_RPAD_EXPLICIT_CAPS (pad) == NULL) {
2515 return GST_PAD_LINK_DELAYED;
2518 return GST_PAD_LINK_OK;
2522 * gst_pad_use_explicit_caps:
2523 * @pad: a #GstPad to set to use explicit caps
2525 * This function handles negotiation for pads that need to be set
2526 * to particular caps under complete control of the element, based
2527 * on some state in the element. This is often the case with
2528 * decoders and other elements whose caps is determined by the data
2531 * WARNING: This function is a hack and will be replaced with something
2532 * better in gstreamer-0.9.
2535 gst_pad_use_explicit_caps (GstPad * pad)
2537 g_return_if_fail (GST_IS_PAD (pad));
2539 gst_pad_set_getcaps_function (pad, gst_pad_explicit_getcaps);
2540 gst_pad_set_link_function (pad, gst_pad_explicit_link);
2541 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2545 * gst_pad_proxy_link:
2546 * @pad: a #GstPad to proxy to.
2547 * @caps: the #GstCaps to use in proxying.
2549 * Proxies the link function to the specified pad.
2551 * Returns: TRUE if the peer pad accepted the caps, FALSE otherwise.
2554 gst_pad_proxy_link (GstPad * pad, const GstCaps * caps)
2556 return gst_pad_try_set_caps (pad, caps);
2560 * gst_pad_is_negotiated:
2561 * @pad: a #GstPad to get the negotiation status of
2563 * Returns: TRUE if the pad has successfully negotiated caps.
2566 gst_pad_is_negotiated (GstPad * pad)
2568 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2570 if (!GST_PAD_REALIZE (pad))
2572 if (!GST_RPAD_LINK (pad))
2575 return (GST_RPAD_LINK (pad)->caps != NULL);
2579 * gst_pad_get_negotiated_caps:
2580 * @pad: a #GstPad to get the negotiated capabilites of
2582 * Gets the currently negotiated caps of a pad.
2584 * Returns: the currently negotiated caps of a pad, or NULL if the pad isn't
2587 G_CONST_RETURN GstCaps *
2588 gst_pad_get_negotiated_caps (GstPad * pad)
2590 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2592 if (!GST_PAD_REALIZE (pad))
2594 if (!GST_RPAD_LINK (pad))
2597 return GST_RPAD_LINK (pad)->caps;
2602 * @pad: a #GstPad to get the capabilities of.
2604 * Gets the capabilities of this pad.
2606 * Returns: the #GstCaps of this pad. This function returns a new caps, so use
2607 * gst_caps_free to get rid of it.
2610 gst_pad_get_caps (GstPad * pad)
2612 GstRealPad *realpad;
2614 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2616 realpad = GST_PAD_REALIZE (pad);
2618 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
2619 GST_DEBUG_PAD_NAME (realpad), realpad);
2621 if (GST_PAD_IS_DISPATCHING (realpad))
2622 GST_CAT_DEBUG (GST_CAT_CAPS,
2623 "pad %s:%s is already dispatching -- looking for a template",
2624 GST_DEBUG_PAD_NAME (realpad));
2626 if (GST_RPAD_GETCAPSFUNC (realpad) && !GST_PAD_IS_DISPATCHING (realpad)) {
2629 GST_CAT_DEBUG (GST_CAT_CAPS, "dispatching to pad getcaps function");
2631 GST_FLAG_SET (realpad, GST_PAD_DISPATCHING);
2632 caps = GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD (realpad));
2633 GST_FLAG_UNSET (realpad, GST_PAD_DISPATCHING);
2636 g_critical ("pad %s:%s returned NULL caps from getcaps function\n",
2637 GST_DEBUG_PAD_NAME (realpad));
2639 #ifndef G_DISABLE_ASSERT
2640 /* check that the returned caps are a real subset of the template caps */
2641 if (GST_PAD_PAD_TEMPLATE (realpad)) {
2642 const GstCaps *templ_caps =
2643 GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (realpad));
2644 if (!gst_caps_is_subset (caps, templ_caps)) {
2647 GST_CAT_ERROR_OBJECT (GST_CAT_CAPS, pad,
2648 "pad returned caps %" GST_PTR_FORMAT
2649 " which are not a real subset of its template caps %"
2650 GST_PTR_FORMAT, caps, templ_caps);
2652 ("pad %s:%s returned caps that are not a real subset of its template caps",
2653 GST_DEBUG_PAD_NAME (realpad));
2654 temp = gst_caps_intersect (templ_caps, caps);
2655 gst_caps_free (caps);
2663 if (GST_PAD_PAD_TEMPLATE (realpad)) {
2664 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (realpad);
2665 const GstCaps *caps;
2667 caps = GST_PAD_TEMPLATE_CAPS (templ);
2668 GST_CAT_DEBUG (GST_CAT_CAPS,
2669 "using pad template %p with caps %" GST_PTR_FORMAT, templ, caps);
2672 /* FIXME we should enable something like this someday, but this is
2674 if (!gst_caps_is_fixed (caps)) {
2676 ("pad %s:%s (%p) has no getcaps function and the pad template returns non-fixed caps. Element is probably broken.\n",
2677 GST_DEBUG_PAD_NAME (realpad), realpad);
2681 return gst_caps_copy (GST_PAD_TEMPLATE_CAPS (templ));
2683 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
2687 g_warning ("pad %s:%s (%p) has no pad template\n",
2688 GST_DEBUG_PAD_NAME (realpad), realpad);
2691 return gst_caps_new_any ();
2695 * gst_pad_get_pad_template_caps:
2696 * @pad: a #GstPad to get the template capabilities from.
2698 * Gets the capabilities for @pad's template.
2700 * Returns: the #GstCaps of this pad template. If you intend to keep a reference
2701 * on the caps, make a copy (see gst_caps_copy ()).
2704 gst_pad_get_pad_template_caps (GstPad * pad)
2706 static GstStaticCaps anycaps = GST_STATIC_CAPS ("ANY");
2708 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2710 if (GST_PAD_PAD_TEMPLATE (pad))
2711 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
2714 /* FIXME this should be enabled some day */
2715 /* wingo: why? mail the list during 0.9 when you find this :) */
2716 g_warning ("pad %s:%s (%p) has no pad template\n",
2717 GST_DEBUG_PAD_NAME (realpad), realpad);
2720 return gst_static_caps_get (&anycaps);
2723 /* FIXME 0.9: This function should probably die, or at least be renamed to
2724 * get_caps_by_format. */
2726 * gst_pad_template_get_caps_by_name:
2727 * @templ: a #GstPadTemplate to get the capabilities of.
2728 * @name: the name of the capability to get.
2730 * Gets the capability with the given name from @templ.
2732 * Returns: the #GstCaps of this pad template, or NULL if not found. If you
2733 * intend to keep a reference on the caps, make a copy (see gst_caps_copy ()).
2736 gst_pad_template_get_caps_by_name (GstPadTemplate * templ, const gchar * name)
2740 g_return_val_if_fail (templ != NULL, NULL);
2742 caps = GST_PAD_TEMPLATE_CAPS (templ);
2750 /* FIXME 0.9: What good is this if it only works for already-negotiated pads? */
2752 * gst_pad_check_compatibility:
2753 * @srcpad: the source #GstPad to check.
2754 * @sinkpad: the sink #GstPad to check against.
2756 * Checks if two pads have compatible capabilities. If neither one has yet been
2757 * negotiated, returns TRUE for no good reason.
2759 * Returns: TRUE if they are compatible or if the capabilities could not be
2760 * checked, FALSE if the capabilities are not compatible.
2763 gst_pad_check_compatibility (GstPad * srcpad, GstPad * sinkpad)
2765 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
2766 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
2768 if (GST_PAD_CAPS (srcpad) && GST_PAD_CAPS (sinkpad)) {
2769 if (!gst_caps_is_always_compatible (GST_PAD_CAPS (srcpad),
2770 GST_PAD_CAPS (sinkpad))) {
2776 GST_CAT_DEBUG (GST_CAT_PADS,
2777 "could not check capabilities of pads (%s:%s) and (%s:%s) %p %p",
2778 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
2779 GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad));
2786 * @pad: a #GstPad to get the peer of.
2788 * Gets the peer of @pad.
2790 * Returns: the peer #GstPad.
2793 gst_pad_get_peer (GstPad * pad)
2795 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2797 return GST_PAD (GST_PAD_PEER (pad));
2801 * gst_pad_get_allowed_caps:
2802 * @pad: a real #GstPad.
2804 * Gets the capabilities of the allowed media types that can flow through @pad.
2805 * The caller must free the resulting caps.
2807 * Returns: the allowed #GstCaps of the pad link. Free the caps when
2808 * you no longer need it.
2811 gst_pad_get_allowed_caps (GstPad * pad)
2813 const GstCaps *mycaps;
2819 g_return_val_if_fail (GST_IS_REAL_PAD (pad), NULL);
2821 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: getting allowed caps",
2822 GST_DEBUG_PAD_NAME (pad));
2824 mycaps = gst_pad_get_pad_template_caps (pad);
2825 if (GST_RPAD_PEER (pad) == NULL) {
2826 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "%s:%s: no peer, returning template",
2827 GST_DEBUG_PAD_NAME (pad));
2828 return gst_caps_copy (mycaps);
2831 peercaps = gst_pad_get_caps (GST_PAD_PEER (pad));
2832 caps = gst_caps_intersect (mycaps, peercaps);
2833 gst_caps_free (peercaps);
2835 link = GST_RPAD_LINK (pad);
2836 if (link->filtercaps) {
2837 icaps = gst_caps_intersect (caps, link->filtercaps);
2838 gst_caps_free (caps);
2839 GST_CAT_DEBUG (GST_CAT_PROPERTIES,
2840 "%s:%s: returning filtered intersection with peer",
2841 GST_DEBUG_PAD_NAME (pad));
2844 GST_CAT_DEBUG (GST_CAT_PROPERTIES,
2845 "%s:%s: returning unfiltered intersection with peer",
2846 GST_DEBUG_PAD_NAME (pad));
2852 * gst_pad_caps_change_notify:
2855 * Called to indicate that the return value of @pad's getcaps function may have
2856 * changed, and that a renegotiation is suggested.
2859 gst_pad_caps_change_notify (GstPad * pad)
2864 * gst_pad_recover_caps_error:
2865 * @pad: a #GstPad that had a failed capsnego
2866 * @allowed: possible caps for the link
2868 * Attempt to recover from a failed caps negotiation. This function
2869 * is typically called by a plugin that exhausted its list of caps
2870 * and wants the application to resolve the issue. The application
2871 * should connect to the pad's caps_nego_failed signal and should
2872 * resolve the issue by connecting another element for example.
2874 * Returns: TRUE when the issue was resolved, dumps detailed information
2875 * on the console and returns FALSE otherwise.
2878 gst_pad_recover_caps_error (GstPad * pad, const GstCaps * allowed)
2885 * gst_pad_alloc_buffer:
2886 * @pad: a source #GstPad
2887 * @offset: the offset of the new buffer in the stream
2888 * @size: the size of the new buffer
2890 * Allocates a new, empty buffer optimized to push to pad @pad. This
2891 * function only works if @pad is a source pad.
2893 * Returns: a new, empty #GstBuffer, or NULL if there is an error
2896 gst_pad_alloc_buffer (GstPad * pad, guint64 offset, gint size)
2900 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2901 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
2903 peer = GST_RPAD_PEER (pad);
2905 if (peer && peer->bufferallocfunc) {
2908 GST_CAT_DEBUG (GST_CAT_BUFFER, "(%s:%s): getting buffer",
2909 GST_DEBUG_PAD_NAME (pad));
2910 GST_CAT_DEBUG (GST_CAT_PADS,
2911 "calling bufferallocfunc &%s (@%p) of peer pad %s:%s",
2912 GST_DEBUG_FUNCPTR_NAME (peer->bufferallocfunc),
2913 &peer->bufferallocfunc, GST_DEBUG_PAD_NAME (((GstPad *) peer)));
2915 ret = (peer->bufferallocfunc) (GST_PAD (peer), offset, size);
2919 return gst_buffer_new_and_alloc (size);
2923 gst_real_pad_dispose (GObject * object)
2925 GstPad *pad = GST_PAD (object);
2927 /* No linked pad can ever be disposed.
2928 * It has to have a parent to be linked
2929 * and a parent would hold a reference */
2930 /* FIXME: what about if g_object_dispose is explicitly called on the pad? Is
2931 that legal? otherwise we could assert GST_OBJECT_PARENT (pad) == NULL as
2933 g_assert (GST_PAD_PEER (pad) == NULL);
2935 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s",
2936 GST_DEBUG_PAD_NAME (pad));
2938 /* we destroy the ghostpads, because they are nothing without the real pad */
2939 if (GST_REAL_PAD (pad)->ghostpads) {
2940 GList *orig, *ghostpads;
2942 orig = ghostpads = g_list_copy (GST_REAL_PAD (pad)->ghostpads);
2945 GstPad *ghostpad = GST_PAD (ghostpads->data);
2947 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))) {
2948 GstElement *parent = GST_ELEMENT (GST_OBJECT_PARENT (ghostpad));
2950 GST_CAT_DEBUG (GST_CAT_REFCOUNTING,
2951 "removing ghost pad from element '%s'", GST_OBJECT_NAME (parent));
2952 gst_element_remove_pad (parent, ghostpad);
2954 /* handle the case where we have some floating ghost pad that was never
2955 added to an element */
2956 g_object_set (ghostpad, "real-pad", NULL, NULL);
2958 ghostpads = g_list_next (ghostpads);
2961 /* as the ghost pads are removed, they remove themselves from ->ghostpads.
2962 So it should be empty now. Let's assert that. */
2963 g_assert (GST_REAL_PAD (pad)->ghostpads == NULL);
2966 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
2967 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
2968 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
2970 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
2973 if (GST_RPAD_EXPLICIT_CAPS (pad)) {
2974 GST_ERROR_OBJECT (pad, "still explicit caps %" GST_PTR_FORMAT " set",
2975 GST_RPAD_EXPLICIT_CAPS (pad));
2976 g_warning ("pad %p has still explicit caps set", pad);
2977 gst_caps_replace (&GST_RPAD_EXPLICIT_CAPS (pad), NULL);
2979 G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
2983 #ifndef GST_DISABLE_LOADSAVE
2984 /* FIXME: why isn't this on a GstElement ? */
2986 * gst_pad_load_and_link:
2987 * @self: an #xmlNodePtr to read the description from.
2988 * @parent: the #GstObject element that owns the pad.
2990 * Reads the pad definition from the XML node and links the given pad
2991 * in the element to a pad of an element up in the hierarchy.
2994 gst_pad_load_and_link (xmlNodePtr self, GstObject * parent)
2996 xmlNodePtr field = self->xmlChildrenNode;
2997 GstPad *pad = NULL, *targetpad;
3001 GstObject *grandparent;
3004 if (!strcmp (field->name, "name")) {
3005 pad = gst_element_get_pad (GST_ELEMENT (parent),
3006 xmlNodeGetContent (field));
3007 } else if (!strcmp (field->name, "peer")) {
3008 peer = xmlNodeGetContent (field);
3010 field = field->next;
3012 g_return_if_fail (pad != NULL);
3017 split = g_strsplit (peer, ".", 2);
3019 if (split[0] == NULL || split[1] == NULL) {
3020 GST_CAT_DEBUG (GST_CAT_XML,
3021 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
3022 peer, GST_DEBUG_PAD_NAME (pad));
3026 g_return_if_fail (split[0] != NULL);
3027 g_return_if_fail (split[1] != NULL);
3029 grandparent = gst_object_get_parent (parent);
3031 if (grandparent && GST_IS_BIN (grandparent)) {
3032 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
3039 targetpad = gst_element_get_pad (target, split[1]);
3041 if (targetpad == NULL)
3044 gst_pad_link (pad, targetpad);
3051 * gst_pad_save_thyself:
3052 * @pad: a #GstPad to save.
3053 * @parent: the parent #xmlNodePtr to save the description in.
3055 * Saves the pad into an xml representation.
3057 * Returns: the #xmlNodePtr representation of the pad.
3060 gst_pad_save_thyself (GstObject * object, xmlNodePtr parent)
3062 GstRealPad *realpad;
3065 g_return_val_if_fail (GST_IS_REAL_PAD (object), NULL);
3067 realpad = GST_REAL_PAD (object);
3069 xmlNewChild (parent, NULL, "name", GST_PAD_NAME (realpad));
3070 if (GST_RPAD_PEER (realpad) != NULL) {
3073 peer = GST_PAD (GST_RPAD_PEER (realpad));
3074 /* first check to see if the peer's parent's parent is the same */
3075 /* we just save it off */
3076 content = g_strdup_printf ("%s.%s",
3077 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
3078 xmlNewChild (parent, NULL, "peer", content);
3081 xmlNewChild (parent, NULL, "peer", "");
3086 /* FIXME: shouldn't it be gst_pad_ghost_* ?
3087 * dunno -- wingo 7 feb 2004
3090 * gst_ghost_pad_save_thyself:
3091 * @pad: a ghost #GstPad to save.
3092 * @parent: the parent #xmlNodePtr to save the description in.
3094 * Saves the ghost pad into an xml representation.
3096 * Returns: the #xmlNodePtr representation of the pad.
3099 gst_ghost_pad_save_thyself (GstPad * pad, xmlNodePtr parent)
3103 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
3105 self = xmlNewChild (parent, NULL, "ghostpad", NULL);
3106 xmlNewChild (self, NULL, "name", GST_PAD_NAME (pad));
3107 xmlNewChild (self, NULL, "parent", GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
3109 /* FIXME FIXME FIXME! */
3113 #endif /* GST_DISABLE_LOADSAVE */
3116 _invent_event (GstPad * pad, GstBuffer * buffer)
3119 GstEventType event_type;
3122 if (GST_BUFFER_OFFSET_IS_VALID (buffer))
3123 event_type = GST_FORMAT_DEFAULT;
3125 event_type = GST_FORMAT_UNDEFINED;
3127 offset = GST_BUFFER_OFFSET (buffer);
3129 if (GST_BUFFER_TIMESTAMP_IS_VALID (buffer)) {
3130 GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer);
3132 event = gst_event_new_discontinuous (TRUE,
3133 GST_FORMAT_TIME, timestamp, event_type, offset, GST_FORMAT_UNDEFINED);
3134 GST_CAT_WARNING (GST_CAT_SCHEDULING,
3135 "needed to invent a DISCONT %p (time %" G_GUINT64_FORMAT
3136 ") for %s:%s => %s:%s", event, timestamp,
3137 GST_DEBUG_PAD_NAME (GST_PAD_PEER (pad)), GST_DEBUG_PAD_NAME (pad));
3139 event = gst_event_new_discontinuous (TRUE,
3140 event_type, offset, GST_FORMAT_UNDEFINED);
3141 GST_CAT_WARNING (GST_CAT_SCHEDULING,
3142 "needed to invent a DISCONT %p (no time) for %s:%s => %s:%s", event,
3143 GST_DEBUG_PAD_NAME (GST_PAD_PEER (pad)), GST_DEBUG_PAD_NAME (pad));
3146 return GST_DATA (event);
3151 * @pad: a source #GstPad.
3152 * @data: the #GstData to push.
3154 * Pushes a buffer or an event to the peer of @pad. @pad must be linked. May
3155 * only be called by @pad's parent.
3158 gst_pad_push (GstPad * pad, GstData * data)
3162 g_return_if_fail (GST_IS_PAD (pad));
3163 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
3164 g_return_if_fail (data != NULL);
3166 DEBUG_DATA (pad, data, "gst_pad_push");
3167 if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), &data))
3170 if (!GST_PAD_IS_LINKED (pad)) {
3171 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3172 "not pushing data %p as pad is unconnected", data);
3173 gst_data_unref (data);
3177 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad, "pushing");
3178 peer = GST_RPAD_PEER (pad);
3181 g_warning ("push on pad %s:%s but it is unlinked",
3182 GST_DEBUG_PAD_NAME (pad));
3184 if (!GST_IS_EVENT (data) && !GST_PAD_IS_ACTIVE (peer)) {
3185 g_warning ("push on peer of pad %s:%s but peer is not active",
3186 GST_DEBUG_PAD_NAME (pad));
3190 if (peer->chainhandler) {
3192 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3193 "calling chainhandler &%s of peer pad %s:%s",
3194 GST_DEBUG_FUNCPTR_NAME (peer->chainhandler),
3195 GST_DEBUG_PAD_NAME (GST_PAD (peer)));
3196 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
3199 (peer->chainhandler) (GST_PAD (peer), data);
3202 g_warning ("trying to push a NULL buffer on pad %s:%s",
3203 GST_DEBUG_PAD_NAME (peer));
3207 g_warning ("internal error: push on pad %s:%s but it has no chainhandler",
3208 GST_DEBUG_PAD_NAME (peer));
3211 /* clean up the mess here */
3213 gst_data_unref (data);
3218 * @pad: a sink #GstPad.
3220 * Pulls an event or a buffer from the peer pad. May only be called by @pad's
3223 * Returns: a new #GstData from the peer pad.
3226 gst_pad_pull (GstPad * pad)
3231 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
3232 GST_DATA (gst_event_new (GST_EVENT_INTERRUPT)));
3234 peer = GST_RPAD_PEER (pad);
3237 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3238 ("pull on pad %s:%s but it was unlinked", GST_DEBUG_PAD_NAME (pad)));
3241 if (peer->gethandler) {
3242 GstPadLink *link = GST_RPAD_LINK (pad);
3244 GST_CAT_LOG_OBJECT (GST_CAT_SCHEDULING, pad,
3245 "calling gethandler %s of peer pad %s:%s",
3246 GST_DEBUG_FUNCPTR_NAME (peer->gethandler), GST_DEBUG_PAD_NAME (peer));
3248 if (link->temp_store) {
3249 g_assert (link->engaged);
3250 GST_DEBUG ("moving temp_store %p to data", link->temp_store);
3251 data = link->temp_store;
3252 link->temp_store = NULL;
3254 data = (peer->gethandler) (GST_PAD (peer));
3255 /* refetch - we might have been relinked */
3256 link = GST_RPAD_LINK (pad);
3257 peer = GST_RPAD_PEER (pad);
3261 if (!link->engaged) {
3262 g_assert (link->temp_store == NULL);
3263 if (GST_IS_BUFFER (data)) {
3264 GST_DEBUG ("moving data buffer %p back to temp_store", data);
3265 link->temp_store = data;
3266 link->engaged = TRUE;
3267 data = _invent_event (pad, GST_BUFFER (data));
3268 } else if (GST_IS_EVENT (data) &&
3269 GST_EVENT_TYPE (data) == GST_EVENT_DISCONTINUOUS &&
3270 GST_EVENT_DISCONT_NEW_MEDIA (data)) {
3271 link->engaged = TRUE;
3272 GST_CAT_LOG (GST_CAT_SCHEDULING,
3273 "link engaged by discont event %p for pad %s:%s", data,
3274 GST_DEBUG_PAD_NAME (pad));
3277 GST_DEBUG ("calling gst_probe_dispatcher_dispatch on data %p", data);
3278 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
3280 DEBUG_DATA (pad, data, "gst_pad_pull returned");
3284 /* no null buffers allowed */
3285 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3286 ("NULL buffer during pull on %s:%s", GST_DEBUG_PAD_NAME (pad)));
3288 GST_ELEMENT_ERROR (GST_PAD_PARENT (pad), CORE, PAD, (NULL),
3289 ("pull on pad %s:%s but the peer pad %s:%s has no gethandler",
3290 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer)));
3293 data = GST_DATA (gst_event_new (GST_EVENT_INTERRUPT));
3294 DEBUG_DATA (pad, data, "gst_pad_pull returned created");
3299 gst_pad_collect_array (GstScheduler * scheduler, GstPad ** selected,
3302 GstSchedulerClass *klass = GST_SCHEDULER_GET_CLASS (scheduler);
3304 if (!GST_FLAG_IS_SET (scheduler, GST_SCHEDULER_FLAG_NEW_API) ||
3305 !klass->pad_select) {
3306 /* better randomness? */
3308 *selected = padlist[0];
3309 return gst_pad_pull (padlist[0]);
3313 return klass->pad_select (scheduler, selected ? selected : &select,
3320 * @selected: set to the pad the buffer comes from if not NULL
3321 * @padlist: a #GList of sink pads.
3323 * Waits for a buffer on any of the list of pads. Each #GstPad in @padlist must
3324 * belong to the same element and be owned by the caller.
3326 * Returns: the #GstData that was available
3329 gst_pad_collectv (GstPad ** selected, const GList * padlist)
3331 /* need to use alloca here because we must not leak data */
3334 GstElement *element = NULL;
3337 g_return_val_if_fail (padlist != NULL, NULL);
3338 pads = g_alloca (sizeof (gpointer) * (g_list_length ((GList *) padlist) + 1));
3339 for (; padlist; padlist = g_list_next (padlist)) {
3340 test = GST_PAD (padlist->data);
3341 g_return_val_if_fail (GST_IS_PAD (test), NULL);
3342 g_return_val_if_fail (GST_PAD_IS_SINK (test), NULL);
3344 g_return_val_if_fail (element == gst_pad_get_parent (test), NULL);
3346 element = gst_pad_get_parent (test);
3352 return gst_pad_collect_array (GST_SCHEDULER (element), selected, pads);
3357 * @selected: set to the pad the buffer comes from if not NULL
3359 * @...: more sink pads.
3361 * Waits for a buffer on the given set of pads.
3363 * Returns: the #GstData that was available.
3366 gst_pad_collect (GstPad ** selected, GstPad * pad, ...)
3371 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3373 va_start (var_args, pad);
3375 result = gst_pad_collect_valist (selected, pad, var_args);
3383 * gst_pad_collect_valist:
3384 * @selected: set to the pad the buffer comes from if not NULL
3386 * @...: more sink pads.
3388 * Waits for a buffer on the given set of pads.
3390 * Returns: the #GstData that was available.
3393 gst_pad_collect_valist (GstPad ** selected, GstPad * pad, va_list var_args)
3396 GstElement *element = NULL;
3397 gint i = 0, maxlength;
3399 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3401 element = gst_pad_get_parent (pad);
3402 maxlength = element->numsinkpads;
3403 /* can we make this list a bit smaller than this upper limit? */
3404 padlist = g_alloca (sizeof (gpointer) * (maxlength + 1));
3406 g_return_val_if_fail (i < maxlength, NULL);
3407 g_return_val_if_fail (element == gst_pad_get_parent (pad), NULL);
3409 pad = va_arg (var_args, GstPad *);
3411 return gst_pad_collect_array (GST_SCHEDULER (element), selected, padlist);
3416 * @padlist: a #GList of sink pads.
3418 * Waits for a buffer on any of the list of pads. Each #GstPad in @padlist must
3419 * be owned by the calling code.
3421 * Returns: the #GstPad that has a buffer available.
3422 * Use #gst_pad_pull() to get the buffer.
3425 gst_pad_selectv (GList * padlist)
3431 * gst_pad_select_valist:
3432 * @pad: a first #GstPad to perform the select on.
3433 * @varargs: A va_list of more pads to select on.
3435 * Waits for a buffer on the given set of pads.
3437 * Returns: the #GstPad that has a buffer available.
3438 * Use #gst_pad_pull() to get the buffer.
3441 gst_pad_select_valist (GstPad * pad, va_list var_args)
3444 GList *padlist = NULL;
3450 padlist = g_list_prepend (padlist, pad);
3451 pad = va_arg (var_args, GstPad *);
3453 result = gst_pad_selectv (padlist);
3454 g_list_free (padlist);
3461 * @pad: a first sink #GstPad to perform the select on.
3462 * @...: A NULL-terminated list of more pads to select on.
3464 * Waits for a buffer on the given set of pads.
3466 * Returns: the #GstPad that has a buffer available.
3467 * Use #gst_pad_pull() to get the buffer.
3470 gst_pad_select (GstPad * pad, ...)
3478 va_start (var_args, pad);
3480 result = gst_pad_select_valist (pad, var_args);
3487 /************************************************************************
3492 static void gst_pad_template_class_init (GstPadTemplateClass * klass);
3493 static void gst_pad_template_init (GstPadTemplate * templ);
3494 static void gst_pad_template_dispose (GObject * object);
3497 gst_pad_template_get_type (void)
3499 static GType padtemplate_type = 0;
3501 if (!padtemplate_type) {
3502 static const GTypeInfo padtemplate_info = {
3503 sizeof (GstPadTemplateClass), NULL, NULL,
3504 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
3505 sizeof (GstPadTemplate),
3507 (GInstanceInitFunc) gst_pad_template_init, NULL
3511 g_type_register_static (GST_TYPE_OBJECT, "GstPadTemplate",
3512 &padtemplate_info, 0);
3514 return padtemplate_type;
3518 gst_pad_template_class_init (GstPadTemplateClass * klass)
3520 GObjectClass *gobject_class;
3521 GstObjectClass *gstobject_class;
3523 gobject_class = (GObjectClass *) klass;
3524 gstobject_class = (GstObjectClass *) klass;
3526 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
3528 gst_pad_template_signals[TEMPL_PAD_CREATED] =
3529 g_signal_new ("pad-created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
3530 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
3531 NULL, NULL, gst_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GST_TYPE_PAD);
3533 gobject_class->dispose = gst_pad_template_dispose;
3535 gstobject_class->path_string_separator = "*";
3539 gst_pad_template_init (GstPadTemplate * templ)
3544 gst_pad_template_dispose (GObject * object)
3546 GstPadTemplate *templ = GST_PAD_TEMPLATE (object);
3548 g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
3549 if (GST_PAD_TEMPLATE_CAPS (templ)) {
3550 gst_caps_free (GST_PAD_TEMPLATE_CAPS (templ));
3553 G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object);
3556 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
3558 * SOMETIMES padtemplates can do whatever they want, they are provided by the
3560 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
3561 * 'sink%d' template is automatically selected), so we need to restrict their
3565 name_is_valid (const gchar * name, GstPadPresence presence)
3569 if (presence == GST_PAD_ALWAYS) {
3570 if (strchr (name, '%')) {
3571 g_warning ("invalid name template %s: conversion specifications are not"
3572 " allowed for GST_PAD_ALWAYS padtemplates", name);
3575 } else if (presence == GST_PAD_REQUEST) {
3576 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
3577 g_warning ("invalid name template %s: only one conversion specification"
3578 " allowed in GST_PAD_REQUEST padtemplate", name);
3581 if (str && (*(str + 1) != 's' && *(str + 1) != 'd')) {
3582 g_warning ("invalid name template %s: conversion specification must be of"
3583 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
3586 if (str && (*(str + 2) != '\0')) {
3587 g_warning ("invalid name template %s: conversion specification must"
3588 " appear at the end of the GST_PAD_REQUEST padtemplate name", name);
3597 * gst_static_pad_template_get:
3598 * @pad_template: the static pad template
3600 * Converts a #GstStaticPadTemplate into a #GstPadTemplate.
3602 * Returns: a new #GstPadTemplate.
3605 gst_static_pad_template_get (GstStaticPadTemplate * pad_template)
3607 GstPadTemplate *new;
3609 if (!name_is_valid (pad_template->name_template, pad_template->presence))
3612 new = g_object_new (gst_pad_template_get_type (),
3613 "name", pad_template->name_template, NULL);
3615 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (pad_template->name_template);
3616 GST_PAD_TEMPLATE_DIRECTION (new) = pad_template->direction;
3617 GST_PAD_TEMPLATE_PRESENCE (new) = pad_template->presence;
3619 GST_PAD_TEMPLATE_CAPS (new) =
3620 gst_caps_copy (gst_static_caps_get (&pad_template->static_caps));
3626 * gst_pad_template_new:
3627 * @name_template: the name template.
3628 * @direction: the #GstPadDirection of the template.
3629 * @presence: the #GstPadPresence of the pad.
3630 * @caps: a #GstCaps set for the template. The caps are taken ownership of.
3632 * Creates a new pad template with a name according to the given template
3633 * and with the given arguments. This functions takes ownership of the provided
3634 * caps, so be sure to not use them afterwards.
3636 * Returns: a new #GstPadTemplate.
3639 gst_pad_template_new (const gchar * name_template,
3640 GstPadDirection direction, GstPadPresence presence, GstCaps * caps)
3642 GstPadTemplate *new;
3644 g_return_val_if_fail (name_template != NULL, NULL);
3645 g_return_val_if_fail (caps != NULL, NULL);
3647 if (!name_is_valid (name_template, presence))
3651 #ifdef USE_POISONING
3653 GstCaps *newcaps = gst_caps_copy (caps);
3655 gst_caps_free (caps);
3660 new = g_object_new (gst_pad_template_get_type (),
3661 "name", name_template, NULL);
3663 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
3664 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
3665 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
3666 gst_caps_do_simplify (caps);
3667 GST_PAD_TEMPLATE_CAPS (new) = caps;
3673 * gst_pad_template_get_caps:
3674 * @templ: a #GstPadTemplate to get capabilities of.
3676 * Gets the capabilities of the pad template.
3678 * Returns: the #GstCaps of the pad template. If you need to keep a reference to
3679 * the caps, make a copy (see gst_caps_copy ()).
3682 gst_pad_template_get_caps (GstPadTemplate * templ)
3684 g_return_val_if_fail (GST_IS_PAD_TEMPLATE (templ), NULL);
3686 return GST_PAD_TEMPLATE_CAPS (templ);
3690 * gst_pad_set_element_private:
3691 * @pad: the #GstPad to set the private data of.
3692 * @priv: The private data to attach to the pad.
3694 * Set the given private data gpointer on the pad.
3695 * This function can only be used by the element that owns the pad.
3698 gst_pad_set_element_private (GstPad * pad, gpointer priv)
3700 pad->element_private = priv;
3704 * gst_pad_get_element_private:
3705 * @pad: the #GstPad to get the private data of.
3707 * Gets the private data of a pad.
3709 * Returns: a #gpointer to the private data.
3712 gst_pad_get_element_private (GstPad * pad)
3714 return pad->element_private;
3718 /***** ghost pads *****/
3719 GType _gst_ghost_pad_type = 0;
3721 static void gst_ghost_pad_class_init (GstGhostPadClass * klass);
3722 static void gst_ghost_pad_init (GstGhostPad * pad);
3723 static void gst_ghost_pad_dispose (GObject * object);
3724 static void gst_ghost_pad_get_property (GObject * object, guint prop_id,
3725 GValue * value, GParamSpec * pspec);
3726 static void gst_ghost_pad_set_property (GObject * object, guint prop_id,
3727 const GValue * value, GParamSpec * pspec);
3729 static GstPad *ghost_pad_parent_class = NULL;
3731 /* static guint gst_ghost_pad_signals[LAST_SIGNAL] = { 0 }; */
3740 gst_ghost_pad_get_type (void)
3742 if (!_gst_ghost_pad_type) {
3743 static const GTypeInfo pad_info = {
3744 sizeof (GstGhostPadClass), NULL, NULL,
3745 (GClassInitFunc) gst_ghost_pad_class_init, NULL, NULL,
3746 sizeof (GstGhostPad),
3748 (GInstanceInitFunc) gst_ghost_pad_init,
3752 _gst_ghost_pad_type = g_type_register_static (GST_TYPE_PAD, "GstGhostPad",
3755 return _gst_ghost_pad_type;
3759 gst_ghost_pad_class_init (GstGhostPadClass * klass)
3761 GObjectClass *gobject_class;
3763 gobject_class = (GObjectClass *) klass;
3765 ghost_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
3767 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_ghost_pad_dispose);
3768 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_ghost_pad_set_property);
3769 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_ghost_pad_get_property);
3771 g_object_class_install_property (gobject_class, GPAD_ARG_REAL_PAD,
3772 g_param_spec_object ("real-pad", "Real pad",
3773 "The real pad for the ghost pad", GST_TYPE_PAD, G_PARAM_READWRITE));
3777 gst_ghost_pad_init (GstGhostPad * pad)
3779 /* zeroed by glib */
3783 gst_ghost_pad_dispose (GObject * object)
3785 g_object_set (object, "real-pad", NULL, NULL);
3787 G_OBJECT_CLASS (ghost_pad_parent_class)->dispose (object);
3791 gst_ghost_pad_set_property (GObject * object, guint prop_id,
3792 const GValue * value, GParamSpec * pspec)
3794 GstPad *ghostpad = (GstPad *) object;
3795 GstPad *oldrealpad = (GstPad *) GST_GPAD_REALPAD (ghostpad);
3796 GstPad *realpad = NULL;
3799 case GPAD_ARG_REAL_PAD:
3800 realpad = g_value_get_object (value);
3803 if (realpad == oldrealpad)
3806 gst_pad_remove_ghost_pad (oldrealpad, ghostpad);
3810 gst_pad_add_ghost_pad (realpad, ghostpad);
3814 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3820 gst_ghost_pad_get_property (GObject * object, guint prop_id,
3821 GValue * value, GParamSpec * pspec)
3824 case GPAD_ARG_REAL_PAD:
3825 g_value_set_object (value, GST_GPAD_REALPAD (object));
3829 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
3835 * gst_ghost_pad_new:
3836 * @name: the name of the new ghost pad.
3837 * @pad: the #GstPad to create a ghost pad for.
3839 * Creates a new ghost pad associated with @pad, and named @name. If @name is
3840 * %NULL, a guaranteed unique name (across all ghost pads) will be assigned.
3842 * Returns: a new ghost #GstPad, or %NULL in case of an error.
3845 gst_ghost_pad_new (const gchar * name, GstPad * pad)
3849 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3851 gpad = g_object_new (GST_TYPE_GHOST_PAD, "name", name, "real-pad", pad, NULL);
3853 GST_CAT_DEBUG (GST_CAT_PADS, "created ghost pad \"%s\" for pad %s:%s",
3854 GST_OBJECT_NAME (gpad), GST_DEBUG_PAD_NAME (pad));
3860 * gst_pad_get_internal_links_default:
3861 * @pad: the #GstPad to get the internal links of.
3863 * Gets a list of pads to which the given pad is linked to
3864 * inside of the parent element.
3865 * This is the default handler, and thus returns a list of all of the
3866 * pads inside the parent element with opposite direction.
3867 * The caller must free this list after use.
3869 * Returns: a newly allocated #GList of pads.
3872 gst_pad_get_internal_links_default (GstPad * pad)
3877 GstPadDirection direction;
3880 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3882 rpad = GST_PAD_REALIZE (pad);
3883 direction = rpad->direction;
3885 parent = GST_PAD_PARENT (rpad);
3886 parent_pads = parent->pads;
3888 while (parent_pads) {
3889 GstRealPad *parent_pad = GST_PAD_REALIZE (parent_pads->data);
3891 if (parent_pad->direction != direction) {
3892 res = g_list_prepend (res, parent_pad);
3895 parent_pads = g_list_next (parent_pads);
3902 * gst_pad_get_internal_links:
3903 * @pad: the #GstPad to get the internal links of.
3905 * Gets a list of pads to which the given pad is linked to
3906 * inside of the parent element.
3907 * The caller must free this list after use.
3909 * Returns: a newly allocated #GList of pads.
3912 gst_pad_get_internal_links (GstPad * pad)
3917 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
3919 rpad = GST_PAD_REALIZE (pad);
3921 if (GST_RPAD_INTLINKFUNC (rpad))
3922 res = GST_RPAD_INTLINKFUNC (rpad) (GST_PAD (rpad));
3929 gst_pad_event_default_dispatch (GstPad * pad, GstElement * element,
3934 GST_INFO_OBJECT (pad, "Sending event %p to all internally linked pads",
3937 orig = pads = gst_pad_get_internal_links (pad);
3940 GstPad *eventpad = GST_PAD (pads->data);
3942 pads = g_list_next (pads);
3944 /* for all of the internally-linked pads that are actually linked */
3945 if (GST_PAD_IS_LINKED (eventpad)) {
3946 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
3947 /* for each pad we send to, we should ref the event; it's up
3948 * to downstream to unref again when handled. */
3949 GST_LOG_OBJECT (pad, "Reffing and sending event %p to %s:%s", event,
3950 GST_DEBUG_PAD_NAME (eventpad));
3951 gst_event_ref (event);
3952 gst_pad_push (eventpad, GST_DATA (event));
3954 GstPad *peerpad = GST_PAD (GST_RPAD_PEER (eventpad));
3956 /* we only send the event on one pad, multi-sinkpad elements
3957 * should implement a handler */
3959 GST_LOG_OBJECT (pad, "sending event %p to one sink pad %s:%s", event,
3960 GST_DEBUG_PAD_NAME (eventpad));
3961 return gst_pad_send_event (peerpad, event);
3965 /* we handled the incoming event so we unref once */
3966 GST_LOG_OBJECT (pad, "handled event %p, unreffing", event);
3967 gst_event_unref (event);
3969 return (GST_PAD_DIRECTION (pad) == GST_PAD_SINK);
3973 * gst_pad_event_default:
3974 * @pad: a #GstPad to call the default event handler on.
3975 * @event: the #GstEvent to handle.
3977 * Invokes the default event handler for the given pad. End-of-stream and
3978 * discontinuity events are handled specially, and then the event is sent to all
3979 * pads internally linked to @pad. Note that if there are many possible sink
3980 * pads that are internally linked to @pad, only one will be sent an event.
3981 * Multi-sinkpad elements should implement custom event handlers.
3983 * Returns: TRUE if the event was sent succesfully.
3986 gst_pad_event_default (GstPad * pad, GstEvent * event)
3988 GstElement *element;
3990 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3991 g_return_val_if_fail (event != NULL, FALSE);
3993 element = GST_PAD_PARENT (pad);
3995 switch (GST_EVENT_TYPE (event)) {
3997 gst_pad_event_default_dispatch (pad, element, event);
3998 gst_element_set_eos (element);
4000 case GST_EVENT_DISCONTINUOUS:
4004 if (gst_element_requires_clock (element) && element->clock) {
4005 if (gst_event_discont_get_value (event, GST_FORMAT_TIME, &time)) {
4006 gst_element_set_time (element, time);
4008 GstFormat format = GST_FORMAT_TIME;
4011 for (i = 0; i < event->event_data.discont.noffsets; i++) {
4012 if (gst_pad_convert (pad,
4013 event->event_data.discont.offsets[i].format,
4014 event->event_data.discont.offsets[i].value, &format,
4016 gst_element_set_time (element, time);
4017 } else if (i == event->event_data.discont.noffsets) {
4019 ("can't adjust clock to new time when time not provided");
4026 return gst_pad_event_default_dispatch (pad, element, event);
4032 * gst_pad_dispatcher:
4033 * @pad: a #GstPad to dispatch.
4034 * @dispatch: the #GstDispatcherFunction to call.
4035 * @data: gpointer user data passed to the dispatcher function.
4037 * Invokes the given dispatcher function on all pads that are
4038 * internally linked to the given pad.
4039 * The GstPadDispatcherFunction should return TRUE when no further pads
4040 * need to be processed.
4042 * Returns: TRUE if one of the dispatcher functions returned TRUE.
4045 gst_pad_dispatcher (GstPad * pad, GstPadDispatcherFunction dispatch,
4048 gboolean res = FALSE;
4049 GList *int_pads, *orig;
4051 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4052 g_return_val_if_fail (dispatch != NULL, FALSE);
4054 orig = int_pads = gst_pad_get_internal_links (pad);
4057 GstRealPad *int_rpad = GST_PAD_REALIZE (int_pads->data);
4058 GstRealPad *int_peer = GST_RPAD_PEER (int_rpad);
4061 res = dispatch (GST_PAD (int_peer), data);
4065 int_pads = g_list_next (int_pads);
4074 * gst_pad_send_event:
4075 * @pad: a #GstPad to send the event to.
4076 * @event: the #GstEvent to send to the pad.
4078 * Sends the event to the pad.
4080 * Returns: TRUE if the event was handled.
4083 gst_pad_send_event (GstPad * pad, GstEvent * event)
4085 gboolean success = FALSE;
4089 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4090 g_return_val_if_fail (event != NULL, FALSE);
4091 parent = gst_pad_get_parent (pad);
4092 g_return_val_if_fail (GST_STATE (parent) >= GST_STATE_PAUSED, FALSE);
4094 rpad = GST_PAD_REALIZE (pad);
4097 if (GST_EVENT_SRC (event) == NULL)
4098 GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (rpad));
4100 GST_CAT_DEBUG (GST_CAT_EVENT, "have event type %d on pad %s:%s",
4101 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (rpad));
4103 if (GST_RPAD_EVENTHANDLER (rpad))
4104 success = GST_RPAD_EVENTHANDLER (rpad) (GST_PAD (rpad), event);
4106 g_warning ("pad %s:%s has no event handler", GST_DEBUG_PAD_NAME (rpad));
4107 gst_event_unref (event);
4115 GstFormat src_format;
4117 GstFormat *dest_format;
4123 gst_pad_convert_dispatcher (GstPad * pad, GstPadConvertData * data)
4125 return gst_pad_convert (pad, data->src_format, data->src_value,
4126 data->dest_format, data->dest_value);
4130 * gst_pad_convert_default:
4131 * @pad: a #GstPad to invoke the default converter on.
4132 * @src_format: the source #GstFormat.
4133 * @src_value: the source value.
4134 * @dest_format: a pointer to the destination #GstFormat.
4135 * @dest_value: a pointer to the destination value.
4137 * Invokes the default converter on a pad.
4138 * This will forward the call to the pad obtained
4139 * using the internal link of
4142 * Returns: TRUE if the conversion could be performed.
4145 gst_pad_convert_default (GstPad * pad,
4146 GstFormat src_format, gint64 src_value,
4147 GstFormat * dest_format, gint64 * dest_value)
4149 GstPadConvertData data;
4151 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4152 g_return_val_if_fail (dest_format != NULL, FALSE);
4153 g_return_val_if_fail (dest_value != NULL, FALSE);
4155 data.src_format = src_format;
4156 data.src_value = src_value;
4157 data.dest_format = dest_format;
4158 data.dest_value = dest_value;
4160 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
4161 gst_pad_convert_dispatcher, &data);
4166 * @pad: a #GstPad to invoke the default converter on.
4167 * @src_format: the source #GstFormat.
4168 * @src_value: the source value.
4169 * @dest_format: a pointer to the destination #GstFormat.
4170 * @dest_value: a pointer to the destination value.
4172 * Invokes a conversion on the pad.
4174 * Returns: TRUE if the conversion could be performed.
4177 gst_pad_convert (GstPad * pad,
4178 GstFormat src_format, gint64 src_value,
4179 GstFormat * dest_format, gint64 * dest_value)
4183 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4184 g_return_val_if_fail (dest_format != NULL, FALSE);
4185 g_return_val_if_fail (dest_value != NULL, FALSE);
4187 if (src_format == *dest_format) {
4188 *dest_value = src_value;
4192 rpad = GST_PAD_REALIZE (pad);
4194 if (GST_RPAD_CONVERTFUNC (rpad)) {
4195 return GST_RPAD_CONVERTFUNC (rpad) (GST_PAD (rpad), src_format,
4196 src_value, dest_format, dest_value);
4211 gst_pad_query_dispatcher (GstPad * pad, GstPadQueryData * data)
4213 return gst_pad_query (pad, data->type, data->format, data->value);
4217 * gst_pad_query_default:
4218 * @pad: a #GstPad to invoke the default query on.
4219 * @type: the #GstQueryType of the query to perform.
4220 * @format: a pointer to the #GstFormat of the result.
4221 * @value: a pointer to the result.
4223 * Invokes the default query function on a pad.
4225 * Returns: TRUE if the query could be performed.
4228 gst_pad_query_default (GstPad * pad, GstQueryType type,
4229 GstFormat * format, gint64 * value)
4231 GstPadQueryData data;
4233 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4234 g_return_val_if_fail (format != NULL, FALSE);
4235 g_return_val_if_fail (value != NULL, FALSE);
4238 data.format = format;
4241 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
4242 gst_pad_query_dispatcher, &data);
4247 * @pad: a #GstPad to invoke the default query on.
4248 * @type: the #GstQueryType of the query to perform.
4249 * @format: a pointer to the #GstFormat asked for.
4250 * On return contains the #GstFormat used.
4251 * @value: a pointer to the result.
4253 * Queries a pad for one of the available properties. The format will be
4254 * adjusted to the actual format used when specifying formats such as
4255 * GST_FORMAT_DEFAULT.
4256 * FIXME: Tell if the format can be adjusted when specifying a definite format.
4258 * Returns: TRUE if the query could be performed.
4261 gst_pad_query (GstPad * pad, GstQueryType type,
4262 GstFormat * format, gint64 * value)
4266 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
4267 g_return_val_if_fail (format != NULL, FALSE);
4268 g_return_val_if_fail (value != NULL, FALSE);
4270 rpad = GST_PAD_REALIZE (pad);
4272 g_return_val_if_fail (rpad, FALSE);
4274 if (GST_RPAD_QUERYFUNC (rpad))
4275 return GST_RPAD_QUERYFUNC (rpad) (GST_PAD (pad), type, format, value);
4281 gst_pad_get_formats_dispatcher (GstPad * pad, const GstFormat ** data)
4283 *data = gst_pad_get_formats (pad);
4289 * gst_pad_get_formats_default:
4290 * @pad: a #GstPad to query
4292 * Invoke the default format dispatcher for the pad.
4294 * Returns: An array of GstFormats ended with a 0 value.
4297 gst_pad_get_formats_default (GstPad * pad)
4299 GstFormat *result = NULL;
4301 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4303 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
4304 gst_pad_get_formats_dispatcher, &result);
4310 * gst_pad_get_formats:
4311 * @pad: a #GstPad to query
4313 * Gets the list of supported formats from the pad.
4315 * Returns: An array of GstFormats ended with a 0 value.
4318 gst_pad_get_formats (GstPad * pad)
4322 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
4324 rpad = GST_PAD_REALIZE (pad);
4326 if (GST_RPAD_FORMATSFUNC (rpad))
4327 return GST_RPAD_FORMATSFUNC (rpad) (GST_PAD (pad));
4332 #define CALL_CHAINFUNC(pad, data) G_STMT_START {\
4333 GstData *__temp = (data); \
4334 DEBUG_DATA (pad, __temp, "calling chain function with "); \
4335 if (GST_IS_EVENT (__temp) && \
4336 !GST_FLAG_IS_SET (gst_pad_get_parent (pad), GST_ELEMENT_EVENT_AWARE)) { \
4337 gst_pad_send_event (pad, GST_EVENT (__temp)); \
4339 GST_RPAD_CHAINFUNC (pad) (pad, __temp); \
4343 * gst_pad_call_chain_function:
4344 * @pad: sink pad to call chain function on
4345 * @data: data to call the chain function with
4347 * Calls the chain function of the given pad while making sure the internal
4348 * consistency is kept. Use this function inside schedulers instead of calling
4349 * the chain function yourself.
4352 gst_pad_call_chain_function (GstPad * pad, GstData * data)
4356 g_return_if_fail (GST_IS_REAL_PAD (pad));
4357 g_return_if_fail (GST_PAD_IS_SINK (pad));
4358 g_return_if_fail (data != NULL);
4359 g_return_if_fail (GST_RPAD_CHAINFUNC (pad) != NULL);
4360 g_return_if_fail (GST_RPAD_LINK (pad) != NULL);
4362 link = GST_RPAD_LINK (pad);
4363 if (!link->engaged) {
4364 g_assert (link->temp_store == NULL);
4365 if (GST_IS_BUFFER (data)) {
4366 GST_DEBUG ("moving data buffer %p back to temp_store", data);
4367 link->temp_store = data;
4368 link->engaged = TRUE;
4369 CALL_CHAINFUNC (pad, _invent_event (pad, GST_BUFFER (data)));
4370 link = GST_RPAD_LINK (pad);
4371 if (link->temp_store == NULL) /* happens after relinking in chainfunc */
4373 g_assert (link->temp_store == data);
4374 link->temp_store = NULL;
4375 } else if (GST_IS_EVENT (data) &&
4376 GST_EVENT_TYPE (data) == GST_EVENT_DISCONTINUOUS &&
4377 GST_EVENT_DISCONT_NEW_MEDIA (data)) {
4378 link->engaged = TRUE;
4379 GST_CAT_LOG (GST_CAT_SCHEDULING,
4380 "link engaged by discont event %p for pad %s:%s", data,
4381 GST_DEBUG_PAD_NAME (pad));
4384 CALL_CHAINFUNC (pad, data);
4388 * gst_pad_call_get_function:
4389 * @pad: sink pad to call chain function on
4391 * Calls the get function of the given pad while making sure the internal
4392 * consistency is kept. Use this function inside schedulers instead of calling
4393 * the get function yourself.
4395 * Returns: the data provided by the pad or NULL if no data was available.
4398 gst_pad_call_get_function (GstPad * pad)
4402 g_return_val_if_fail (GST_IS_REAL_PAD (pad), NULL);
4403 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
4404 g_return_val_if_fail (GST_RPAD_GETFUNC (pad) != NULL, NULL);
4406 data = GST_RPAD_GETFUNC (pad) (pad);
4407 DEBUG_DATA (pad, data, "getfunction returned");