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 /* #define GST_DEBUG_ENABLED */
24 #include "gst_private.h"
28 #include "gstelement.h"
31 #include "gstscheduler.h"
41 static GstObject *padtemplate_parent_class = NULL;
42 static guint gst_pad_template_signals[TEMPL_LAST_SIGNAL] = { 0 };
44 GType _gst_pad_type = 0;
46 /***** Start with the base GstPad class *****/
47 static void gst_pad_class_init (GstPadClass *klass);
48 static void gst_pad_init (GstPad *pad);
49 static void gst_pad_dispose (GObject *object);
51 static gboolean gst_pad_try_relink_filtered_func (GstRealPad *srcpad, GstRealPad *sinkpad,
52 GstCaps *caps, gboolean clear);
53 static void gst_pad_set_pad_template (GstPad *pad, GstPadTemplate *templ);
55 #ifndef GST_DISABLE_LOADSAVE
56 static xmlNodePtr gst_pad_save_thyself (GstObject *object, xmlNodePtr parent);
59 static GstObject *pad_parent_class = NULL;
62 gst_pad_get_type (void)
65 static const GTypeInfo pad_info = {
66 sizeof (GstPadClass), NULL, NULL,
67 (GClassInitFunc) gst_pad_class_init, NULL, NULL,
70 (GInstanceInitFunc) gst_pad_init, NULL
72 _gst_pad_type = g_type_register_static (GST_TYPE_OBJECT, "GstPad",
79 gst_pad_class_init (GstPadClass *klass)
81 GObjectClass *gobject_class;
83 gobject_class = (GObjectClass*) klass;
85 pad_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
87 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_pad_dispose);
91 gst_pad_init (GstPad *pad)
93 /* all structs are initialized to NULL by glib */
96 gst_pad_dispose (GObject *object)
98 GstPad *pad = GST_PAD (object);
100 gst_pad_set_pad_template (pad, NULL);
102 G_OBJECT_CLASS (pad_parent_class)->dispose (object);
107 /***** Then do the Real Pad *****/
108 /* Pad signals and args */
110 REAL_CAPS_NEGO_FAILED,
124 static void gst_real_pad_class_init (GstRealPadClass *klass);
125 static void gst_real_pad_init (GstRealPad *pad);
126 static void gst_real_pad_dispose (GObject *object);
128 static void gst_real_pad_set_property (GObject *object, guint prop_id,
131 static void gst_real_pad_get_property (GObject *object, guint prop_id,
135 GType _gst_real_pad_type = 0;
137 static GstPad *real_pad_parent_class = NULL;
138 static guint gst_real_pad_signals[REAL_LAST_SIGNAL] = { 0 };
141 gst_real_pad_get_type (void) {
142 if (!_gst_real_pad_type) {
143 static const GTypeInfo pad_info = {
144 sizeof (GstRealPadClass), NULL, NULL,
145 (GClassInitFunc) gst_real_pad_class_init, NULL, NULL,
148 (GInstanceInitFunc) gst_real_pad_init, NULL
150 _gst_real_pad_type = g_type_register_static (GST_TYPE_PAD, "GstRealPad",
153 return _gst_real_pad_type;
157 gst_real_pad_class_init (GstRealPadClass *klass)
159 GObjectClass *gobject_class;
160 GstObjectClass *gstobject_class;
162 gobject_class = (GObjectClass*) klass;
163 gstobject_class = (GstObjectClass*) klass;
165 real_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
167 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_real_pad_dispose);
168 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_real_pad_set_property);
169 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_real_pad_get_property);
171 gst_real_pad_signals[REAL_CAPS_NEGO_FAILED] =
172 g_signal_new ("caps_nego_failed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
173 G_STRUCT_OFFSET (GstRealPadClass, caps_nego_failed), NULL, NULL,
174 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
176 gst_real_pad_signals[REAL_LINKED] =
177 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
178 G_STRUCT_OFFSET (GstRealPadClass, linked), NULL, NULL,
179 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
181 gst_real_pad_signals[REAL_UNLINKED] =
182 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
183 G_STRUCT_OFFSET (GstRealPadClass, unlinked), NULL, NULL,
184 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
187 /* gtk_object_add_arg_type ("GstRealPad::active", G_TYPE_BOOLEAN, */
188 /* GTK_ARG_READWRITE, REAL_ARG_ACTIVE); */
189 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_ACTIVE,
190 g_param_spec_boolean ("active", "Active", "Whether the pad is active.",
191 TRUE, G_PARAM_READWRITE));
192 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_CAPS,
193 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
194 GST_TYPE_CAPS, G_PARAM_READABLE));
196 #ifndef GST_DISABLE_LOADSAVE
197 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
199 gstobject_class->path_string_separator = ".";
203 gst_real_pad_init (GstRealPad *pad)
205 pad->direction = GST_PAD_UNKNOWN;
208 pad->chainfunc = NULL;
211 pad->chainhandler = NULL;
212 pad->gethandler = NULL;
214 pad->bufferpoolfunc = NULL;
215 pad->ghostpads = NULL;
218 pad->linkfunc = NULL;
219 pad->getcapsfunc = NULL;
221 pad->convertfunc = gst_pad_convert_default;
222 pad->eventfunc = gst_pad_event_default;
223 pad->convertfunc = gst_pad_convert_default;
224 pad->queryfunc = gst_pad_query_default;
225 pad->intlinkfunc = gst_pad_get_internal_links_default;
227 pad->eventmaskfunc = gst_pad_get_event_masks_default;
228 pad->formatsfunc = gst_pad_get_formats_default;
229 pad->querytypefunc = gst_pad_get_query_types_default;
231 GST_FLAG_SET (pad, GST_PAD_DISABLED);
232 GST_FLAG_UNSET (pad, GST_PAD_NEGOTIATING);
234 gst_probe_dispatcher_init (&pad->probedisp);
238 gst_real_pad_set_property (GObject *object, guint prop_id,
239 const GValue *value, GParamSpec *pspec)
241 g_return_if_fail (GST_IS_PAD (object));
244 case REAL_ARG_ACTIVE:
245 gst_pad_set_active (GST_PAD (object), g_value_get_boolean (value));
248 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
254 gst_real_pad_get_property (GObject *object, guint prop_id,
255 GValue *value, GParamSpec *pspec)
257 g_return_if_fail (GST_IS_PAD (object));
260 case REAL_ARG_ACTIVE:
261 g_value_set_boolean (value, !GST_FLAG_IS_SET (object, GST_PAD_DISABLED));
264 g_value_set_boxed (value, GST_PAD_CAPS (GST_REAL_PAD (object)));
267 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
274 * gst_pad_custom_new:
275 * @type: the #Gtype of the pad.
276 * @name: the name of the new pad.
277 * @direction: the #GstPadDirection of the pad.
279 * Creates a new pad with the given name and type in the given direction.
280 * If name is NULL, a guaranteed unique name (across all pads)
283 * Returns: a new #GstPad, or NULL in case of an error.
286 gst_pad_custom_new (GType type, const gchar *name,
287 GstPadDirection direction)
291 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
293 pad = g_object_new (type, NULL);
294 gst_object_set_name (GST_OBJECT (pad), name);
295 GST_RPAD_DIRECTION (pad) = direction;
297 return GST_PAD (pad);
302 * @name: the name of the new pad.
303 * @direction: the #GstPadDirection of the pad.
305 * Creates a new real pad with the given name in the given direction.
306 * If name is NULL, a guaranteed unique name (across all pads)
309 * Returns: a new #GstPad, or NULL in case of an error.
312 gst_pad_new (const gchar *name,
313 GstPadDirection direction)
315 return gst_pad_custom_new (gst_real_pad_get_type (), name, direction);
319 * gst_pad_custom_new_from_template:
320 * @type: the custom #GType of the pad.
321 * @templ: the #GstPadTemplate to instantiate from.
322 * @name: the name of the new pad.
324 * Creates a new custom pad with the given name from the given template.
325 * If name is NULL, a guaranteed unique name (across all pads)
328 * Returns: a new #GstPad, or NULL in case of an error.
331 gst_pad_custom_new_from_template (GType type, GstPadTemplate *templ,
336 g_return_val_if_fail (templ != NULL, NULL);
338 pad = gst_pad_new (name, templ->direction);
339 gst_pad_set_pad_template (pad, templ);
345 * gst_pad_new_from_template:
346 * @templ: the pad template to use
347 * @name: the name of the element
349 * Creates a new real pad with the given name from the given template.
350 * If name is NULL, a guaranteed unique name (across all pads)
353 * Returns: a new #GstPad, or NULL in case of an error.
356 gst_pad_new_from_template (GstPadTemplate *templ, const gchar *name)
358 return gst_pad_custom_new_from_template (gst_real_pad_get_type (),
363 * gst_pad_get_direction:
364 * @pad: a #GstPad to get the direction of.
366 * Gets the direction of the pad.
368 * Returns: the #GstPadDirection of the pad.
371 gst_pad_get_direction (GstPad *pad)
373 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
375 return GST_PAD_DIRECTION (pad);
379 * gst_pad_set_active:
380 * @pad: the #GstPad to activate or deactivate.
381 * @active: TRUE to activate the pad.
383 * Activates or deactivates the given pad.
386 gst_pad_set_active (GstPad *pad, gboolean active)
391 g_return_if_fail (GST_IS_PAD (pad));
393 old = GST_PAD_IS_ACTIVE (pad);
398 realpad = GST_PAD_REALIZE (pad);
401 GST_DEBUG (GST_CAT_PADS, "activating pad %s:%s",
402 GST_DEBUG_PAD_NAME (realpad));
403 GST_FLAG_UNSET (realpad, GST_PAD_DISABLED);
405 GST_DEBUG (GST_CAT_PADS, "de-activating pad %s:%s",
406 GST_DEBUG_PAD_NAME (realpad));
407 GST_FLAG_SET (realpad, GST_PAD_DISABLED);
410 g_object_notify (G_OBJECT (realpad), "active");
415 * @pad: the #GstPad to query
417 * Query if a pad is active
419 * Returns: TRUE if the pad is active.
422 gst_pad_is_active (GstPad *pad)
424 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
426 return !GST_FLAG_IS_SET (pad, GST_PAD_DISABLED);
431 * @pad: a #GstPad to set the name of.
432 * @name: the name of the pad.
434 * Sets the name of a pad. If name is NULL, then a guaranteed unique
435 * name will be assigned.
438 gst_pad_set_name (GstPad *pad, const gchar *name)
440 g_return_if_fail (GST_IS_PAD (pad));
442 gst_object_set_name (GST_OBJECT (pad), name);
447 * @pad: a #GstPad to get the name of.
449 * Gets the name of a pad.
451 * Returns: the name of the pad. This is not a newly allocated pointer
452 * so you must not free it.
455 gst_pad_get_name (GstPad *pad)
457 g_return_val_if_fail (pad != NULL, NULL);
458 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
460 return GST_OBJECT_NAME (pad);
464 * gst_pad_set_chain_function:
465 * @pad: a #GstPad to set the chain function for.
466 * @chain: the #GstPadChainFunction to set.
468 * Sets the given chain function for the pad.
471 gst_pad_set_chain_function (GstPad *pad, GstPadChainFunction chain)
473 g_return_if_fail (pad != NULL);
474 g_return_if_fail (GST_IS_REAL_PAD (pad));
476 GST_RPAD_CHAINFUNC (pad) = chain;
477 GST_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
478 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
482 * gst_pad_set_get_function:
483 * @pad: a #GstPad to set the get function for.
484 * @get: the #GstPadGetFunction to set.
486 * Sets the given get function for the pad.
489 gst_pad_set_get_function (GstPad *pad,
490 GstPadGetFunction get)
492 g_return_if_fail (pad != NULL);
493 g_return_if_fail (GST_IS_REAL_PAD (pad));
495 GST_RPAD_GETFUNC (pad) = get;
497 GST_DEBUG (GST_CAT_PADS, "getfunc for %s:%s set to %s",
498 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
502 * gst_pad_set_event_function:
503 * @pad: a #GstPad to set the event handler for.
504 * @event: the #GstPadEventFunction to set.
506 * Sets the given event handler for the pad.
509 gst_pad_set_event_function (GstPad *pad,
510 GstPadEventFunction event)
512 g_return_if_fail (GST_IS_REAL_PAD (pad));
514 GST_RPAD_EVENTFUNC (pad) = event;
516 GST_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
517 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
521 * gst_pad_set_event_mask_function:
522 * @pad: a #GstPad to set the event mask function for.
523 * @mask_func: the #GstPadEventMaskFunction to set.
525 * Sets the given event mask function for the pad.
528 gst_pad_set_event_mask_function (GstPad *pad,
529 GstPadEventMaskFunction mask_func)
531 g_return_if_fail (GST_IS_REAL_PAD (pad));
533 GST_RPAD_EVENTMASKFUNC (pad) = mask_func;
535 GST_DEBUG (GST_CAT_PADS, "eventmaskfunc for %s:%s set to %s",
536 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (mask_func));
540 * gst_pad_get_event_masks:
541 * @pad: a #GstPad to get the event mask for.
543 * Gets the array of eventmasks from the given pad.
545 * Returns: an array with eventmasks, the list is ended
549 gst_pad_get_event_masks (GstPad *pad)
556 rpad = GST_PAD_REALIZE (pad);
558 g_return_val_if_fail (rpad, FALSE);
560 if (GST_RPAD_EVENTMASKFUNC (rpad))
561 return GST_RPAD_EVENTMASKFUNC (rpad) (GST_PAD_CAST (pad));
567 gst_pad_get_event_masks_dispatcher (GstPad *pad, const GstEventMask **data)
569 *data = gst_pad_get_event_masks (pad);
575 * gst_pad_get_event_masks_default:
576 * @pad: a #GstPad to get the event mask for.
578 * Invokes the default event masks dispatcher on the pad.
580 * Returns: an array with eventmasks, the list is ended
584 gst_pad_get_event_masks_default (GstPad *pad)
586 GstEventMask *result = NULL;
588 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
589 gst_pad_get_event_masks_dispatcher, &result);
595 * gst_pad_set_convert_function:
596 * @pad: a #GstPad to set the convert function for.
597 * @convert: the #GstPadConvertFunction to set.
599 * Sets the given convert function for the pad.
602 gst_pad_set_convert_function (GstPad *pad,
603 GstPadConvertFunction convert)
605 g_return_if_fail (pad != NULL);
606 g_return_if_fail (GST_IS_REAL_PAD (pad));
608 GST_RPAD_CONVERTFUNC (pad) = convert;
610 GST_DEBUG (GST_CAT_PADS, "convertfunc for %s:%s set to %s",
611 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (convert));
615 * gst_pad_set_query_function:
616 * @pad: the #GstPad to set the query function for.
617 * @query: the #GstPadQueryFunction to set.
619 * Set the given query function for the pad.
622 gst_pad_set_query_function (GstPad *pad, GstPadQueryFunction query)
624 g_return_if_fail (pad != NULL);
625 g_return_if_fail (GST_IS_REAL_PAD (pad));
627 GST_RPAD_QUERYFUNC (pad) = query;
629 GST_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
630 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
634 * gst_pad_set_query_type_function:
635 * @pad: the #GstPad to set the query type function for.
636 * @type_func: the #GstPadQueryTypeFunction to set.
638 * Set the given query type function for the pad.
641 gst_pad_set_query_type_function (GstPad *pad, GstPadQueryTypeFunction type_func)
643 g_return_if_fail (pad != NULL);
644 g_return_if_fail (GST_IS_REAL_PAD (pad));
646 GST_RPAD_QUERYTYPEFUNC (pad) = type_func;
648 GST_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
649 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
653 * gst_pad_get_query_types:
654 * @pad: the #GstPad to query
656 * Get an array of supported queries that can be performed
659 * Returns: an array of querytypes anded with 0.
662 gst_pad_get_query_types (GstPad *pad)
669 rpad = GST_PAD_REALIZE (pad);
671 g_return_val_if_fail (rpad, FALSE);
673 if (GST_RPAD_QUERYTYPEFUNC (rpad))
674 return GST_RPAD_QUERYTYPEFUNC (rpad) (GST_PAD_CAST (pad));
680 gst_pad_get_query_types_dispatcher (GstPad *pad, const GstQueryType **data)
682 *data = gst_pad_get_query_types (pad);
688 * gst_pad_get_query_types_default:
689 * @pad: the #GstPad to query
691 * Invoke the default dispatcher for the query types on
694 * Returns: an array of querytypes anded with 0.
697 gst_pad_get_query_types_default (GstPad *pad)
699 GstQueryType *result = NULL;
701 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
702 gst_pad_get_query_types_dispatcher, &result);
708 * gst_pad_set_internal_link_function:
709 * @pad: a #GstPad to set the internal link function for.
710 * @intlink: the #GstPadIntLinkFunction to set.
712 * Sets the given internal link function for the pad.
715 gst_pad_set_internal_link_function (GstPad *pad,
716 GstPadIntLinkFunction intlink)
718 g_return_if_fail (pad != NULL);
719 g_return_if_fail (GST_IS_REAL_PAD (pad));
721 GST_RPAD_INTLINKFUNC (pad) = intlink;
722 GST_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
723 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
727 * gst_pad_set_formats_function:
728 * @pad: the #GstPad to set the formats function for.
729 * @formats: the #GstPadFormatsFunction to set.
731 * Sets the given formats function for the pad.
734 gst_pad_set_formats_function (GstPad *pad, GstPadFormatsFunction formats)
736 g_return_if_fail (pad != NULL);
737 g_return_if_fail (GST_IS_REAL_PAD (pad));
739 GST_RPAD_FORMATSFUNC (pad) = formats;
740 GST_DEBUG (GST_CAT_PADS, "formats function for %s:%s set to %s",
741 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (formats));
745 * gst_pad_set_link_function:
746 * @pad: a #GstPad to set the link function for.
747 * @link: the #GstPadLinkFunction to set.
749 * Sets the given link function for the pad. It will be called
750 * when the pad is linked or relinked with caps.
753 gst_pad_set_link_function (GstPad *pad,
754 GstPadLinkFunction link)
756 g_return_if_fail (pad != NULL);
757 g_return_if_fail (GST_IS_REAL_PAD (pad));
759 GST_RPAD_LINKFUNC (pad) = link;
760 GST_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
761 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
765 * gst_pad_set_getcaps_function:
766 * @pad: a #GstPad to set the getcaps function for.
767 * @getcaps: the #GstPadGetCapsFunction to set.
769 * Sets the given getcaps function for the pad.
772 gst_pad_set_getcaps_function (GstPad *pad,
773 GstPadGetCapsFunction getcaps)
775 g_return_if_fail (pad != NULL);
776 g_return_if_fail (GST_IS_REAL_PAD (pad));
778 GST_RPAD_GETCAPSFUNC (pad) = getcaps;
779 GST_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
780 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
783 * gst_pad_set_bufferpool_function:
784 * @pad: a #GstPad to set the bufferpool function for.
785 * @bufpool: the #GstPadBufferPoolFunction to set.
787 * Sets the given bufferpool function for the pad. Note that the
788 * bufferpool function can only be set on sinkpads.
791 gst_pad_set_bufferpool_function (GstPad *pad,
792 GstPadBufferPoolFunction bufpool)
794 g_return_if_fail (pad != NULL);
795 g_return_if_fail (GST_IS_REAL_PAD (pad));
796 g_return_if_fail (GST_PAD_IS_SINK (pad));
798 GST_RPAD_BUFFERPOOLFUNC (pad) = bufpool;
799 GST_DEBUG (GST_CAT_PADS, "bufferpoolfunc for %s:%s set to %s",
800 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufpool));
805 * @srcpad: the source #GstPad to unlink.
806 * @sinkpad: the sink #GstPad to unlink.
808 * Unlinks the source pad from the sink pad.
811 gst_pad_unlink (GstPad *srcpad,
814 GstRealPad *realsrc, *realsink;
815 GstScheduler *src_sched, *sink_sched;
818 g_return_if_fail (srcpad != NULL);
819 g_return_if_fail (GST_IS_PAD (srcpad));
820 g_return_if_fail (sinkpad != NULL);
821 g_return_if_fail (GST_IS_PAD (sinkpad));
823 GST_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
824 GST_DEBUG_PAD_NAME (srcpad), srcpad,
825 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
827 /* now we need to deal with the real/ghost stuff */
828 realsrc = GST_PAD_REALIZE (srcpad);
829 realsink = GST_PAD_REALIZE (sinkpad);
831 g_return_if_fail (GST_RPAD_PEER (realsrc) != NULL);
832 g_return_if_fail (GST_RPAD_PEER (realsink) == realsrc);
834 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
835 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
842 g_return_if_fail ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
843 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK));
845 /* get the schedulers before we unlink */
846 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
847 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
849 /* first clear peers */
850 GST_RPAD_PEER (realsrc) = NULL;
851 GST_RPAD_PEER (realsink) = NULL;
853 /* reset the filters, both filters are refcounted once */
854 if (GST_RPAD_FILTER (realsrc)) {
855 gst_caps_replace (&GST_RPAD_FILTER (realsink), NULL);
856 gst_caps_replace (&GST_RPAD_FILTER (realsrc), NULL);
859 /* now tell the scheduler */
860 if (src_sched && src_sched == sink_sched) {
861 gst_scheduler_pad_unlink (src_sched,
862 GST_PAD_CAST (realsrc),
863 GST_PAD_CAST (realsink));
866 /* hold a reference, as they can go away in the signal handlers */
867 gst_object_ref (GST_OBJECT (realsrc));
868 gst_object_ref (GST_OBJECT (realsink));
870 /* fire off a signal to each of the pads telling them
871 * that they've been unlinked */
872 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_UNLINKED],
874 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_UNLINKED],
877 GST_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
878 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
880 gst_object_unref (GST_OBJECT (realsrc));
881 gst_object_unref (GST_OBJECT (realsink));
885 gst_pad_check_schedulers (GstRealPad *realsrc, GstRealPad *realsink)
887 GstScheduler *src_sched, *sink_sched;
888 gint num_decoupled = 0;
890 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
891 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
893 if (src_sched && sink_sched) {
894 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsrc), GST_ELEMENT_DECOUPLED))
896 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsink), GST_ELEMENT_DECOUPLED))
899 if (src_sched != sink_sched && num_decoupled != 1) {
907 * gst_pad_can_link_filtered:
908 * @srcpad: the source #GstPad to link.
909 * @sinkpad: the sink #GstPad to link.
910 * @filtercaps: the filter #GstCaps.
912 * Checks if the source pad and the sink pad can be linked when constrained
913 * by the given filter caps.
915 * Returns: TRUE if the pads can be linked, FALSE otherwise.
918 gst_pad_can_link_filtered (GstPad *srcpad, GstPad *sinkpad,
921 GstRealPad *realsrc, *realsink;
924 g_return_val_if_fail (srcpad != NULL, FALSE);
925 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
926 g_return_val_if_fail (sinkpad != NULL, FALSE);
927 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
929 /* now we need to deal with the real/ghost stuff */
930 realsrc = GST_PAD_REALIZE (srcpad);
931 realsink = GST_PAD_REALIZE (sinkpad);
933 g_return_val_if_fail (GST_RPAD_PEER (realsrc) == NULL, FALSE);
934 g_return_val_if_fail (GST_RPAD_PEER (realsink) == NULL, FALSE);
935 g_return_val_if_fail (GST_PAD_PARENT (realsrc) != NULL, FALSE);
936 g_return_val_if_fail (GST_PAD_PARENT (realsink) != NULL, FALSE);
938 if (!gst_pad_check_schedulers (realsrc, realsink)) {
939 g_warning ("linking pads with different scheds requires "
940 "exactly one decoupled element (queue)");
944 /* check if the directions are compatible */
945 if (!(((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
946 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) ||
947 ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
948 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK))))
955 * @srcpad: the source #GstPad to link.
956 * @sinkpad: the sink #GstPad to link.
958 * Checks if the source pad and the sink pad can be link.
960 * Returns: TRUE if the pads can be linked, FALSE otherwise.
963 gst_pad_can_link (GstPad *srcpad, GstPad *sinkpad)
965 return gst_pad_can_link_filtered (srcpad, sinkpad, NULL);
969 * gst_pad_link_filtered:
970 * @srcpad: the source #GstPad to link.
971 * @sinkpad: the sink #GstPad to link.
972 * @filtercaps: the filter #GstCaps.
974 * Links the source pad and the sink pad, constrained
975 * by the given filter caps. This function sinks the caps.
977 * Returns: TRUE if the pads have been linked, FALSE otherwise.
980 gst_pad_link_filtered (GstPad *srcpad, GstPad *sinkpad, GstCaps *filtercaps)
982 GstRealPad *realsrc, *realsink;
983 GstScheduler *src_sched, *sink_sched;
986 g_return_val_if_fail (srcpad != NULL, FALSE);
987 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
988 g_return_val_if_fail (sinkpad != NULL, FALSE);
989 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
991 GST_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
992 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
994 /* now we need to deal with the real/ghost stuff */
995 realsrc = GST_PAD_REALIZE (srcpad);
996 realsink = GST_PAD_REALIZE (sinkpad);
998 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
999 GST_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
1000 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1002 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1003 if (GST_RPAD_PEER (realsrc) != NULL) {
1004 GST_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1005 GST_DEBUG_PAD_NAME (realsrc));
1008 if (GST_RPAD_PEER (realsink) != NULL) {
1009 GST_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1010 GST_DEBUG_PAD_NAME (realsink));
1013 if (GST_PAD_PARENT (realsrc) == NULL) {
1014 GST_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1015 GST_DEBUG_PAD_NAME (realsrc));
1018 if (GST_PAD_PARENT (realsink) == NULL) {
1019 GST_INFO (GST_CAT_PADS, "Real sink pad %s:%s has no parent, failed",
1020 GST_DEBUG_PAD_NAME (realsrc));
1024 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1025 g_warning ("linking pads with different scheds requires "
1026 "exactly one decoupled element (such as queue)");
1030 /* check for reversed directions and swap if necessary */
1031 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
1032 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
1033 GstRealPad *temppad;
1039 if (GST_RPAD_DIRECTION (realsrc) != GST_PAD_SRC) {
1040 GST_INFO (GST_CAT_PADS, "Real src pad %s:%s is not a source pad, failed",
1041 GST_DEBUG_PAD_NAME (realsrc));
1044 if (GST_RPAD_DIRECTION (realsink) != GST_PAD_SINK) {
1045 GST_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1046 GST_DEBUG_PAD_NAME (realsink));
1049 /* first set peers */
1050 GST_RPAD_PEER (realsrc) = realsink;
1051 GST_RPAD_PEER (realsink) = realsrc;
1053 /* try to negotiate the pads, we don't need to clear the caps here */
1054 if (!gst_pad_try_relink_filtered_func (realsrc, realsink,
1055 filtercaps, FALSE)) {
1056 GST_DEBUG (GST_CAT_CAPS, "relink_filtered_func failed, can't link");
1058 GST_RPAD_PEER (realsrc) = NULL;
1059 GST_RPAD_PEER (realsink) = NULL;
1064 /* fire off a signal to each of the pads telling them
1065 * that they've been linked */
1066 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_LINKED],
1068 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_LINKED],
1071 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
1072 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
1074 /* now tell the scheduler */
1075 if (src_sched && src_sched == sink_sched) {
1076 gst_scheduler_pad_link (src_sched,
1077 GST_PAD_CAST (realsrc), GST_PAD_CAST (realsink));
1080 GST_INFO (GST_CAT_PADS, "not telling link to scheduler %s:%s and %s:%s, %p %p",
1081 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
1082 src_sched, sink_sched);
1085 GST_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1086 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1093 * @srcpad: the source #GstPad to link.
1094 * @sinkpad: the sink #GstPad to link.
1096 * Links the source pad to the sink pad.
1098 * Returns: TRUE if the pad could be linked, FALSE otherwise.
1101 gst_pad_link (GstPad *srcpad, GstPad *sinkpad)
1103 return gst_pad_link_filtered (srcpad, sinkpad, NULL);
1107 * gst_pad_set_parent:
1108 * @pad: a #GstPad to set the parent of.
1109 * @parent: the new parent #GstElement.
1111 * Sets the parent object of a pad.
1114 gst_pad_set_parent (GstPad *pad, GstElement *parent)
1116 g_return_if_fail (pad != NULL);
1117 g_return_if_fail (GST_IS_PAD (pad));
1118 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
1119 g_return_if_fail (parent != NULL);
1120 g_return_if_fail (GST_IS_OBJECT (parent));
1121 g_return_if_fail ((gpointer) pad != (gpointer) parent);
1123 gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (parent));
1127 * gst_pad_get_parent:
1128 * @pad: the #GstPad to get the parent of.
1130 * Gets the parent object of this pad.
1132 * Returns: the parent #GstElement.
1135 gst_pad_get_parent (GstPad *pad)
1137 g_return_val_if_fail (pad != NULL, NULL);
1138 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1140 return GST_PAD_PARENT (pad);
1144 gst_pad_set_pad_template (GstPad *pad, GstPadTemplate *templ)
1146 /* this function would need checks if it weren't static */
1148 gst_object_replace ((GstObject **) &pad->padtemplate, (GstObject *) templ);
1151 g_signal_emit (G_OBJECT (templ), gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
1154 * gst_pad_get_pad_template:
1155 * @pad: a #GstPad to get the pad template of.
1157 * Gets the pad template object of this pad.
1159 * Returns: the #GstPadTemplate from which this pad was instantiated.
1162 gst_pad_get_pad_template (GstPad *pad)
1164 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1166 return GST_PAD_PAD_TEMPLATE (pad);
1171 * gst_pad_get_scheduler:
1172 * @pad: a #GstPad to get the scheduler of.
1174 * Gets the scheduler of the pad. Since the pad does not
1175 * have a scheduler of its own, the scheduler of the parent
1176 * is taken. For decoupled pads, the scheduler of the peer
1179 * Returns: the #GstScheduler of the pad.
1182 gst_pad_get_scheduler (GstPad *pad)
1184 GstScheduler *scheduler = NULL;
1187 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1189 parent = gst_pad_get_parent (pad);
1191 if (GST_FLAG_IS_SET (parent, GST_ELEMENT_DECOUPLED)) {
1192 GstRealPad *peer = GST_RPAD_PEER (pad);
1195 scheduler = gst_element_get_scheduler (gst_pad_get_parent (GST_PAD_CAST (peer)));
1199 scheduler = gst_element_get_scheduler (parent);
1207 * gst_pad_get_real_parent:
1208 * @pad: a #GstPad to get the real parent of.
1210 * Gets the real parent object of this pad. If the pad
1211 * is a ghost pad, the actual owner of the real pad is
1212 * returned, as opposed to #gst_pad_get_parent().
1214 * Returns: the parent #GstElement.
1217 gst_pad_get_real_parent (GstPad *pad)
1219 g_return_val_if_fail (pad != NULL, NULL);
1220 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1222 return GST_PAD_PARENT (GST_PAD (GST_PAD_REALIZE (pad)));
1226 * gst_pad_add_ghost_pad:
1227 * @pad: a #GstPad to attach the ghost pad to.
1228 * @ghostpad: the ghost #GstPad to to the pad.
1230 * Adds a ghost pad to a pad.
1233 gst_pad_add_ghost_pad (GstPad *pad,
1236 GstRealPad *realpad;
1238 g_return_if_fail (pad != NULL);
1239 g_return_if_fail (GST_IS_PAD (pad));
1240 g_return_if_fail (ghostpad != NULL);
1241 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1243 realpad = GST_PAD_REALIZE (pad);
1245 realpad->ghostpads = g_list_prepend (realpad->ghostpads, ghostpad);
1250 * gst_pad_remove_ghost_pad:
1251 * @pad: a #GstPad to remove the ghost pad from.
1252 * @ghostpad: the ghost #GstPad to remove from the pad.
1254 * Removes a ghost pad from a pad.
1257 gst_pad_remove_ghost_pad (GstPad *pad,
1260 GstRealPad *realpad;
1262 g_return_if_fail (GST_IS_PAD (pad));
1263 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1264 realpad = GST_PAD_REALIZE (pad);
1265 g_return_if_fail (GST_GPAD_REALPAD (ghostpad) == realpad);
1267 realpad->ghostpads = g_list_remove (realpad->ghostpads, ghostpad);
1268 GST_GPAD_REALPAD (ghostpad) = NULL;
1272 * gst_pad_get_ghost_pad_list:
1273 * @pad: a #GstPad to get the ghost pads of.
1275 * Gets the ghost pads of this pad.
1277 * Returns: a #GList of ghost pads.
1280 gst_pad_get_ghost_pad_list (GstPad *pad)
1282 g_return_val_if_fail (pad != NULL, NULL);
1283 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1285 return GST_PAD_REALIZE(pad)->ghostpads;
1288 /* an internal caps negotiation helper function:
1290 * 1. optionally calls the pad link function with the provided caps
1291 * 2. deals with the result code of the link function
1292 * 3. sets fixed caps on the pad.
1294 static GstPadLinkReturn
1295 gst_pad_try_set_caps_func (GstRealPad *pad, GstCaps *caps, gboolean notify)
1297 GstCaps *allowed = NULL;
1298 GstPadTemplate *template;
1299 GstElement *parent = GST_PAD_PARENT (pad);
1301 g_return_val_if_fail (pad != NULL, GST_PAD_LINK_REFUSED);
1302 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
1304 /* if this pad has a parent and the parent is not READY, delay the
1306 if (parent && GST_STATE (parent) < GST_STATE_READY)
1308 GST_DEBUG (GST_CAT_CAPS, "parent %s of pad %s:%s is not READY",
1309 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (pad));
1310 return GST_PAD_LINK_DELAYED;
1313 GST_INFO (GST_CAT_CAPS, "trying to set caps %p on pad %s:%s",
1314 caps, GST_DEBUG_PAD_NAME (pad));
1316 /* first see if we have to check against a filter, we ref the caps here as we're
1317 * going to unref it later on */
1318 if (!(allowed = gst_caps_ref (GST_RPAD_FILTER (pad)))) {
1319 /* no filter, make sure we check against the padtemplate then */
1320 if ((template = gst_pad_get_pad_template (GST_PAD_CAST (pad)))) {
1321 allowed = gst_pad_template_get_caps (template);
1325 /* do we have to check the caps against something? */
1327 GstCaps *intersection;
1329 /* check against calculated caps */
1330 intersection = gst_caps_intersect (caps, allowed);
1332 /* oops, empty intersection, caps don"t have anything in common */
1333 if (!intersection) {
1334 GST_INFO (GST_CAT_CAPS, "caps did not intersect with %s:%s's allowed caps",
1335 GST_DEBUG_PAD_NAME (pad));
1336 gst_caps_debug (caps, "caps themselves (attemped to set)");
1337 gst_caps_debug (allowed,
1338 "allowed caps that did not agree with caps");
1339 gst_caps_unref (allowed);
1340 return GST_PAD_LINK_REFUSED;
1342 /* caps checks out fine, we can unref the intersection now */
1343 gst_caps_unref (intersection);
1344 gst_caps_unref (allowed);
1345 /* given that the caps are fixed, we know that their intersection with the
1346 * padtemplate caps is the same as caps itself */
1349 /* we need to notify the link function */
1350 if (notify && GST_RPAD_LINKFUNC (pad)) {
1351 GstPadLinkReturn res;
1352 gchar *debug_string;
1353 gboolean negotiating;
1355 GST_INFO (GST_CAT_CAPS, "calling link function on pad %s:%s",
1356 GST_DEBUG_PAD_NAME (pad));
1358 negotiating = GST_FLAG_IS_SET (pad, GST_PAD_NEGOTIATING);
1360 /* set the NEGOTIATING flag if not already done */
1362 GST_FLAG_SET (pad, GST_PAD_NEGOTIATING);
1364 /* call the link function */
1365 res = GST_RPAD_LINKFUNC (pad) (GST_PAD (pad), caps);
1367 /* unset again after negotiating only if we set it */
1369 GST_FLAG_UNSET (pad, GST_PAD_NEGOTIATING);
1372 case GST_PAD_LINK_REFUSED:
1373 debug_string = "REFUSED";
1375 case GST_PAD_LINK_OK:
1376 debug_string = "OK";
1378 case GST_PAD_LINK_DONE:
1379 debug_string = "DONE";
1381 case GST_PAD_LINK_DELAYED:
1382 debug_string = "DELAYED";
1385 g_warning ("unknown return code from link function of pad %s:%s %d",
1386 GST_DEBUG_PAD_NAME (pad), res);
1387 return GST_PAD_LINK_REFUSED;
1390 GST_INFO (GST_CAT_CAPS,
1391 "got reply %s (%d) from link function on pad %s:%s",
1392 debug_string, res, GST_DEBUG_PAD_NAME (pad));
1394 /* done means the link function called another caps negotiate function
1395 * on this pad that succeeded, we dont need to continue */
1396 if (res == GST_PAD_LINK_DONE) {
1397 GST_INFO (GST_CAT_CAPS, "pad %s:%s is done", GST_DEBUG_PAD_NAME (pad));
1398 return GST_PAD_LINK_DONE;
1400 if (res == GST_PAD_LINK_REFUSED) {
1401 GST_INFO (GST_CAT_CAPS, "pad %s:%s doesn't accept caps",
1402 GST_DEBUG_PAD_NAME (pad));
1403 return GST_PAD_LINK_REFUSED;
1406 /* we can only set caps on the pad if they are fixed */
1407 if (GST_CAPS_IS_FIXED (caps)) {
1409 GST_INFO (GST_CAT_CAPS, "setting caps on pad %s:%s",
1410 GST_DEBUG_PAD_NAME (pad));
1411 /* if we got this far all is ok, remove the old caps, set the new one */
1412 gst_caps_replace_sink (&GST_PAD_CAPS (pad), caps);
1414 g_object_notify (G_OBJECT (pad), "caps");
1417 GST_INFO (GST_CAT_CAPS,
1418 "caps are not fixed on pad %s:%s, not setting them yet",
1419 GST_DEBUG_PAD_NAME (pad));
1421 return GST_PAD_LINK_DELAYED;
1423 return GST_PAD_LINK_OK;
1427 * gst_pad_try_set_caps:
1428 * @pad: a #GstPad to try to set the caps on.
1429 * @caps: the #GstCaps to set.
1431 * Tries to set the caps on the given pad. Ownership is always taken
1432 * of the caps, so you will need to unref non-floating caps.
1434 * Returns: A #GstPadLinkReturn value indicating whether the caps
1438 gst_pad_try_set_caps (GstPad *pad, GstCaps *caps)
1440 GstRealPad *peer, *realpad;
1441 GstPadLinkReturn set_retval;
1443 realpad = GST_PAD_REALIZE (pad);
1444 peer = GST_RPAD_PEER (realpad);
1446 GST_INFO (GST_CAT_CAPS, "trying to set caps %p on pad %s:%s",
1447 caps, GST_DEBUG_PAD_NAME (realpad));
1449 gst_caps_debug (caps, "caps that we are trying to set");
1451 /* try to take ownership */
1452 gst_caps_ref (caps);
1453 gst_caps_sink (caps);
1455 /* setting non fixed caps on a pad is not allowed */
1456 if (!GST_CAPS_IS_FIXED (caps)) {
1457 GST_INFO (GST_CAT_CAPS,
1458 "trying to set unfixed caps on pad %s:%s, not allowed",
1459 GST_DEBUG_PAD_NAME (realpad));
1460 g_warning ("trying to set non fixed caps on pad %s:%s, not allowed",
1461 GST_DEBUG_PAD_NAME (realpad));
1463 gst_caps_debug (caps, "unfixed caps");
1464 set_retval = GST_PAD_LINK_DELAYED;
1468 /* if we have a peer try to set the caps, notifying the peerpad
1469 * if it has a link function */
1470 if (peer && ((set_retval = gst_pad_try_set_caps_func (peer, caps, TRUE)) <= 0))
1472 GST_INFO (GST_CAT_CAPS, "tried to set caps on peerpad %s:%s but couldn't, return value %d",
1473 GST_DEBUG_PAD_NAME (peer), set_retval);
1477 /* then try to set our own caps, we don't need to be notified */
1478 if ((set_retval = gst_pad_try_set_caps_func (realpad, caps, FALSE)) <= 0)
1480 GST_INFO (GST_CAT_CAPS, "tried to set own caps on pad %s:%s but couldn't, return value %d",
1481 GST_DEBUG_PAD_NAME (realpad), set_retval);
1484 GST_INFO (GST_CAT_CAPS, "succeeded setting caps %p on pad %s:%s, return value %d",
1485 caps, GST_DEBUG_PAD_NAME (realpad), set_retval);
1486 g_assert (GST_PAD_CAPS (pad));
1489 /* if we took ownership, the caps will be freed */
1490 gst_caps_unref (caps);
1495 /* this is a caps negotiation convenience routine, it:
1497 * 1. optionally clears any pad caps.
1498 * 2. calculates the intersection between the two pad tamplate/getcaps caps.
1499 * 3. calculates the intersection with the (optional) filtercaps.
1500 * 4. stores the intersection in the pad filter.
1501 * 5. stores the app filtercaps in the pad appfilter.
1502 * 6. starts the caps negotiation.
1505 gst_pad_try_relink_filtered_func (GstRealPad *srcpad, GstRealPad *sinkpad,
1506 GstCaps *filtercaps, gboolean clear)
1508 GstCaps *srccaps, *sinkcaps;
1509 GstCaps *intersection = NULL;
1510 GstRealPad *realsrc, *realsink;
1512 realsrc = GST_PAD_REALIZE (srcpad);
1513 realsink = GST_PAD_REALIZE (sinkpad);
1515 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1516 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1518 /* optinally clear the caps */
1520 GST_INFO (GST_CAT_PADS,
1521 "start relink filtered %s:%s and %s:%s, clearing caps",
1522 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1524 gst_caps_replace (&GST_PAD_CAPS (GST_PAD (realsrc)), NULL);
1525 gst_caps_replace (&GST_PAD_CAPS (GST_PAD (realsink)), NULL);
1526 gst_caps_replace (&GST_RPAD_FILTER (realsrc), NULL);
1527 gst_caps_replace (&GST_RPAD_FILTER (realsink), NULL);
1530 GST_INFO (GST_CAT_PADS, "start relink filtered %s:%s and %s:%s",
1531 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1534 srccaps = gst_pad_get_caps (GST_PAD (realsrc));
1535 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1536 GST_DEBUG_PAD_NAME (realsrc));
1537 gst_caps_debug (srccaps, "caps of src pad (pre-relink)");
1538 sinkcaps = gst_pad_get_caps (GST_PAD (realsink));
1539 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1540 GST_DEBUG_PAD_NAME (realsink));
1541 gst_caps_debug (sinkcaps, "caps of sink pad (pre-relink)");
1543 /* first take the intersection of the pad caps */
1544 intersection = gst_caps_intersect (srccaps, sinkcaps);
1545 gst_caps_debug (intersection, "caps of intersection");
1547 /* if we have no intersection but one of the caps was not NULL.. */
1548 if (!intersection && (srccaps || sinkcaps)) {
1549 /* the intersection is NULL but the pad caps were not both NULL,
1550 * this means they have no common format */
1551 GST_INFO (GST_CAT_PADS, "pads %s:%s and %s:%s have no common type",
1552 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1553 /* make sure any floating caps from gst_pad_get_caps are freed here */
1554 gst_caps_sink (srccaps);
1555 gst_caps_sink (sinkcaps);
1558 GST_INFO (GST_CAT_PADS, "pads %s:%s and %s:%s intersected to %s caps",
1559 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink),
1561 (GST_CAPS_IS_FIXED (intersection) ? "fixed" : "variable") :
1564 /* we don't need those anymore, as the caps can be floating */
1565 gst_caps_sink (srccaps);
1566 gst_caps_sink (sinkcaps);
1568 /* then filter this against the app filter */
1570 GstCaps *filtered_intersection;
1572 filtered_intersection = gst_caps_intersect (intersection,
1575 gst_caps_sink (intersection);
1577 if (!filtered_intersection) {
1578 GST_INFO (GST_CAT_PADS,
1579 "filtered link between pads %s:%s and %s:%s is empty",
1580 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1583 intersection = filtered_intersection;
1585 /* keep a reference to the app caps */
1586 gst_caps_replace_sink (&GST_RPAD_APPFILTER (realsink), filtercaps);
1587 gst_caps_replace_sink (&GST_RPAD_APPFILTER (realsrc), filtercaps);
1590 GST_DEBUG (GST_CAT_CAPS, "setting filter for link to:");
1591 gst_caps_debug (intersection, "filter for link");
1593 /* both the app filter and the filter, while stored on both peer pads,
1594 * are equal to the same thing on both */
1595 gst_caps_replace_sink (&GST_RPAD_FILTER (realsrc), intersection);
1596 gst_caps_replace_sink (&GST_RPAD_FILTER (realsink), intersection);
1597 gst_caps_sink (intersection);
1599 return gst_pad_perform_negotiate (GST_PAD (realsrc), GST_PAD (realsink));
1603 * gst_pad_perform_negotiate:
1604 * @srcpad: the source #GstPad.
1605 * @sinkpad: the sink #GstPad.
1607 * Tries to negotiate the pads.
1609 * Returns: TRUE if the pads were succesfully negotiated, FALSE otherwise.
1612 gst_pad_perform_negotiate (GstPad *srcpad, GstPad *sinkpad)
1614 GstCaps *intersection, *filtered_intersection;
1615 GstRealPad *realsrc, *realsink;
1616 GstCaps *srccaps, *sinkcaps, *filter;
1617 gboolean res = TRUE;
1621 g_return_val_if_fail (srcpad != NULL, FALSE);
1622 g_return_val_if_fail (sinkpad != NULL, FALSE);
1624 realsrc = GST_PAD_REALIZE (srcpad);
1625 realsink = GST_PAD_REALIZE (sinkpad);
1627 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1628 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1630 /* shortcut negotiation */
1631 parent = GST_PAD_PARENT (realsrc);
1632 if (parent && GST_STATE (parent) < GST_STATE_READY) {
1633 GST_DEBUG (GST_CAT_CAPS, "parent %s of pad %s:%s is not READY",
1634 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (realsrc));
1637 parent = GST_PAD_PARENT (realsink);
1638 if (parent && GST_STATE (parent) < GST_STATE_READY) {
1639 GST_DEBUG (GST_CAT_CAPS, "parent %s of pad %s:%s is not READY",
1640 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (realsink));
1644 GST_INFO (GST_CAT_PADS, "perform negotiate for link %s:%s-%s:%s",
1645 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1647 filter = GST_RPAD_APPFILTER (realsrc);
1649 GST_INFO (GST_CAT_PADS, "dumping filter for link %s:%s-%s:%s",
1650 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1651 gst_caps_debug (filter, "link filter caps");
1654 /* calculate the new caps here */
1655 srccaps = gst_pad_get_caps (GST_PAD (realsrc));
1656 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1657 GST_DEBUG_PAD_NAME (realsrc));
1658 gst_caps_debug (srccaps,
1659 "src caps, awaiting negotiation, after applying filter");
1660 sinkcaps = gst_pad_get_caps (GST_PAD (realsink));
1661 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1662 GST_DEBUG_PAD_NAME (realsink));
1663 gst_caps_debug (sinkcaps,
1664 "sink caps, awaiting negotiation, after applying filter");
1665 intersection = gst_caps_intersect (srccaps, sinkcaps);
1666 filtered_intersection = gst_caps_intersect (intersection, filter);
1667 gst_caps_unref (intersection);
1669 /* no negotiation is performed if the pads have filtercaps */
1670 if (filtered_intersection) {
1671 GstPadLinkReturn link_res;
1673 link_res = gst_pad_try_set_caps_func (realsrc, filtered_intersection, TRUE);
1674 if (link_res == GST_PAD_LINK_REFUSED)
1676 if (link_res == GST_PAD_LINK_DONE)
1679 link_res = gst_pad_try_set_caps_func (realsink, filtered_intersection, TRUE);
1680 if (link_res == GST_PAD_LINK_REFUSED)
1682 if (link_res == GST_PAD_LINK_DONE)
1685 /* no filtered_intersection, some pads had caps and ther was a filter */
1686 else if ((srccaps || sinkcaps) && filter) {
1692 gst_caps_sink (srccaps);
1693 gst_caps_sink (sinkcaps);
1694 gst_caps_unref (filtered_intersection);
1703 * gst_pad_try_relink_filtered:
1704 * @srcpad: the source #GstPad to relink.
1705 * @sinkpad: the sink #GstPad to relink.
1706 * @filtercaps: the #GstPad to use as a filter in the relink.
1708 * Tries to relink the given source and sink pad, constrained by the given
1711 * Returns: TRUE if the pads were succesfully renegotiated, FALSE otherwise.
1714 gst_pad_try_relink_filtered (GstPad *srcpad, GstPad *sinkpad,
1715 GstCaps *filtercaps)
1717 GstRealPad *realsrc, *realsink;
1719 g_return_val_if_fail (srcpad != NULL, FALSE);
1720 g_return_val_if_fail (sinkpad != NULL, FALSE);
1722 realsrc = GST_PAD_REALIZE (srcpad);
1723 realsink = GST_PAD_REALIZE (sinkpad);
1725 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1726 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1728 return gst_pad_try_relink_filtered_func (realsrc, realsink,
1733 * gst_pad_relink_filtered:
1734 * @srcpad: the source #GstPad to relink.
1735 * @sinkpad: the sink #GstPad to relink.
1736 * @filtercaps: the #GstPad to use as a filter in the relink.
1738 * Relinks the given source and sink pad, constrained by the given
1739 * capabilities. If the relink fails, the pads are unlinked
1740 * and FALSE is returned.
1742 * Returns: TRUE if the pads were succesfully relinked, FALSE otherwise.
1745 gst_pad_relink_filtered (GstPad *srcpad, GstPad *sinkpad,
1746 GstCaps *filtercaps)
1748 GstRealPad *realsrc, *realsink;
1750 g_return_val_if_fail (srcpad != NULL, FALSE);
1751 g_return_val_if_fail (sinkpad != NULL, FALSE);
1753 realsrc = GST_PAD_REALIZE (srcpad);
1754 realsink = GST_PAD_REALIZE (sinkpad);
1756 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1757 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1759 if (!gst_pad_try_relink_filtered_func (realsrc, realsink,
1762 gst_pad_unlink (srcpad, GST_PAD (GST_PAD_PEER (srcpad)));
1769 * gst_pad_proxy_link:
1770 * @pad: a #GstPad to proxy to.
1771 * @caps: the #GstCaps to use in proxying.
1773 * Proxies the link function to the specified pad.
1775 * Returns: TRUE if the peer pad accepted the caps, FALSE otherwise.
1778 gst_pad_proxy_link (GstPad *pad, GstCaps *caps)
1780 GstRealPad *peer, *realpad;
1782 realpad = GST_PAD_REALIZE (pad);
1784 peer = GST_RPAD_PEER (realpad);
1786 GST_INFO (GST_CAT_CAPS, "proxy link to pad %s:%s",
1787 GST_DEBUG_PAD_NAME (realpad));
1789 if (peer && gst_pad_try_set_caps_func (peer, caps, TRUE) < 0)
1790 return GST_PAD_LINK_REFUSED;
1791 if (gst_pad_try_set_caps_func (realpad, caps, FALSE) < 0)
1792 return GST_PAD_LINK_REFUSED;
1795 gst_caps_debug (caps, "proxy link filter");
1797 GST_INFO (GST_CAT_CAPS, "setting filter on %s:%s and %s:%s",
1798 GST_DEBUG_PAD_NAME (peer), GST_DEBUG_PAD_NAME (realpad));
1800 gst_caps_replace_sink (&GST_RPAD_FILTER (peer), caps);
1801 gst_caps_replace_sink (&GST_RPAD_FILTER (realpad), caps);
1804 return GST_PAD_LINK_OK;
1809 * @pad: a #GstPad to get the capabilities of.
1811 * Gets the capabilities of this pad.
1813 * Returns: the #GstCaps of this pad. This function potentially
1814 * returns a floating caps, so use gst_caps_sink to get rid of
1818 gst_pad_get_caps (GstPad *pad)
1820 GstRealPad *realpad;
1822 g_return_val_if_fail (pad != NULL, NULL);
1823 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1825 realpad = GST_PAD_REALIZE (pad);
1827 GST_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1828 GST_DEBUG_PAD_NAME (realpad), realpad);
1830 /* note that we will not _ref the caps here as this function might be
1831 * called recursively */
1832 if (GST_PAD_CAPS (realpad)) {
1833 GST_DEBUG (GST_CAT_CAPS, "using pad real caps %p", GST_PAD_CAPS (realpad));
1834 return GST_PAD_CAPS (realpad);
1836 else if GST_RPAD_GETCAPSFUNC (realpad) {
1837 GST_DEBUG (GST_CAT_CAPS, "using pad get function");
1838 return GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD_CAST (realpad), NULL);
1840 else if (GST_PAD_PAD_TEMPLATE (realpad)) {
1841 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (realpad);
1842 GST_DEBUG (GST_CAT_CAPS, "using pad template %p with caps %p",
1843 templ, GST_PAD_TEMPLATE_CAPS (templ));
1844 return GST_PAD_TEMPLATE_CAPS (templ);
1846 GST_DEBUG (GST_CAT_CAPS, "pad has no caps");
1852 * gst_pad_get_pad_template_caps:
1853 * @pad: a #GstPad to get the template capabilities from.
1855 * Gets the template capabilities of this pad.
1857 * Returns: the template #GstCaps of this pad, unref the caps
1858 * if you no longer need it.
1861 gst_pad_get_pad_template_caps (GstPad *pad)
1863 g_return_val_if_fail (pad != NULL, NULL);
1864 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1866 if (GST_PAD_PAD_TEMPLATE (pad))
1867 return gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad)));
1873 * gst_pad_template_get_caps_by_name:
1874 * @templ: a #GstPadTemplate to get the capabilities of.
1875 * @name: the name of the capability to get.
1877 * Gets the capability with the given name from this pad template.
1879 * Returns: the #GstCaps, or NULL if not found or in case of an error. unref
1880 * the caps if you no longer need it.
1883 gst_pad_template_get_caps_by_name (GstPadTemplate *templ, const gchar *name)
1887 g_return_val_if_fail (templ != NULL, NULL);
1889 caps = GST_PAD_TEMPLATE_CAPS (templ);
1893 return gst_caps_ref (gst_caps_get_by_name (caps, name));
1897 * gst_pad_check_compatibility:
1898 * @srcpad: the source #GstPad to check.
1899 * @sinkpad: the sink #GstPad to check against.
1901 * Checks if two pads have compatible capabilities.
1903 * Returns: TRUE if they are compatible or if the capabilities
1904 * could not be checked
1907 gst_pad_check_compatibility (GstPad *srcpad, GstPad *sinkpad)
1909 g_return_val_if_fail (srcpad != NULL, FALSE);
1910 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1911 g_return_val_if_fail (sinkpad != NULL, FALSE);
1912 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1914 if (GST_PAD_CAPS (srcpad) && GST_PAD_CAPS (sinkpad)) {
1915 if (!gst_caps_is_always_compatible (GST_PAD_CAPS (srcpad),
1916 GST_PAD_CAPS (sinkpad))) {
1924 GST_DEBUG (GST_CAT_PADS,
1925 "could not check capabilities of pads (%s:%s) and (%s:%s) %p %p",
1926 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
1927 GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad));
1934 * @pad: a #GstPad to get the peer of.
1936 * Gets the peer pad of this pad.
1938 * Returns: the peer #GstPad.
1941 gst_pad_get_peer (GstPad *pad)
1943 g_return_val_if_fail (pad != NULL, NULL);
1944 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1946 return GST_PAD (GST_PAD_PEER (pad));
1950 * gst_pad_get_allowed_caps:
1951 * @pad: a #GstPad to get the allowed caps of.
1953 * Gets the capabilities of the allowed media types that can
1954 * flow through this pad. The caller must free the resulting caps.
1956 * Returns: the allowed #GstCaps of the pad link. unref the caps if
1957 * you no longer need it.
1960 gst_pad_get_allowed_caps (GstPad *pad)
1963 GstRealPad *realpad;
1965 g_return_val_if_fail (pad != NULL, NULL);
1966 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1968 realpad = GST_PAD_REALIZE (pad);
1970 GST_DEBUG (GST_CAT_PROPERTIES, "get allowed caps of %s:%s",
1971 GST_DEBUG_PAD_NAME (pad));
1973 caps = gst_caps_ref (GST_RPAD_FILTER (realpad));
1979 * gst_pad_recalc_allowed_caps:
1980 * @pad: a #GstPad to recalculate the capablities of.
1982 * Attempts to relink the pad to its peer through its filter,
1983 * set with gst_pad_[re]link_filtered. This function is useful when a
1984 * plug-in has new capabilities on a pad and wants to notify the peer.
1986 * Returns: TRUE on success, FALSE otherwise.
1989 gst_pad_recalc_allowed_caps (GstPad *pad)
1993 g_return_val_if_fail (pad != NULL, FALSE);
1994 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1996 GST_DEBUG (GST_CAT_PROPERTIES, "set allowed caps of %s:%s",
1997 GST_DEBUG_PAD_NAME (pad));
2000 peer = GST_RPAD_PEER (pad);
2002 return gst_pad_try_relink_filtered (pad, GST_PAD (peer),
2003 GST_RPAD_APPFILTER (pad));
2009 * gst_pad_recover_caps_error:
2010 * @pad: a #GstPad that had a failed capsnego
2011 * @allowed: possible caps for the link
2013 * Attempt to recover from a failed caps negotiation. This function
2014 * is typically called by a plugin that exhausted its list of caps
2015 * and wants the application to resolve the issue. The application
2016 * should connect to the pad's caps_nego_failed signal and should
2017 * resolve the issue by connecting another element for example.
2019 * Returns: TRUE when the issue was resolved, dumps detailed information
2020 * on the console and returns FALSE otherwise.
2023 gst_pad_recover_caps_error (GstPad *pad, GstCaps *allowed)
2027 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2029 /* see if someone can resolve this */
2030 if (g_signal_has_handler_pending (G_OBJECT (pad),
2031 gst_real_pad_signals[REAL_CAPS_NEGO_FAILED], 0, FALSE))
2033 /* clear pad caps first */
2034 gst_caps_replace (&GST_PAD_CAPS (pad), NULL);
2036 /* lets hope some signal manages to set the caps again */
2037 g_signal_emit (G_OBJECT (pad), gst_real_pad_signals[REAL_CAPS_NEGO_FAILED], 0, allowed);
2039 /* if the pad has caps now or is disabled, it's ok */
2040 if (GST_PAD_CAPS (pad) != NULL || !GST_PAD_IS_ACTIVE (pad))
2045 parent = gst_pad_get_parent (pad);
2046 gst_element_error (parent, "negotiation failed on pad %s:%s",
2047 GST_DEBUG_PAD_NAME (pad));
2053 * gst_pad_get_bufferpool:
2054 * @pad: a #GstPad to get the bufferpool from.
2056 * Gets the bufferpool of the peer pad of the given pad.Note that
2057 * a bufferpool can only be obtained from a srcpad.
2059 * Returns: the #GstBufferPool, or NULL in case of an error.
2062 gst_pad_get_bufferpool (GstPad *pad)
2066 g_return_val_if_fail (pad != NULL, NULL);
2067 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2068 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
2070 peer = GST_RPAD_PEER (pad);
2075 GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
2077 if (peer->bufferpoolfunc) {
2078 GST_DEBUG (GST_CAT_PADS,
2079 "calling bufferpoolfunc &%s (@%p) of peer pad %s:%s",
2080 GST_DEBUG_FUNCPTR_NAME (peer->bufferpoolfunc),
2081 &peer->bufferpoolfunc, GST_DEBUG_PAD_NAME (((GstPad*) peer)));
2082 return (peer->bufferpoolfunc) (((GstPad*) peer));
2084 GST_DEBUG (GST_CAT_PADS, "no bufferpoolfunc for peer pad %s:%s at %p",
2085 GST_DEBUG_PAD_NAME (((GstPad*) peer)), &peer->bufferpoolfunc);
2091 gst_real_pad_dispose (GObject *object)
2093 GstPad *pad = GST_PAD (object);
2095 /* No linked pad can ever be disposed.
2096 * It has to have a parent to be linked
2097 * and a parent would hold a reference */
2098 g_assert (GST_PAD_PEER (pad) == NULL);
2100 GST_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s", GST_DEBUG_PAD_NAME(pad));
2102 /* we destroy the ghostpads, because they are nothing without the real pad */
2103 if (GST_REAL_PAD (pad)->ghostpads) {
2104 GList *orig, *ghostpads;
2106 orig = ghostpads = g_list_copy (GST_REAL_PAD (pad)->ghostpads);
2109 GstPad *ghostpad = GST_PAD (ghostpads->data);
2111 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))){
2112 GST_DEBUG (GST_CAT_REFCOUNTING, "removing ghost pad from element '%s'",
2113 GST_OBJECT_NAME (GST_OBJECT_PARENT (ghostpad)));
2115 gst_element_remove_ghost_pad (GST_ELEMENT (GST_OBJECT_PARENT (ghostpad)), GST_PAD (ghostpad));
2117 ghostpads = g_list_next (ghostpads);
2120 g_list_free (GST_REAL_PAD(pad)->ghostpads);
2123 gst_caps_replace (&GST_PAD_CAPS (pad), NULL);
2124 gst_caps_replace (&GST_RPAD_APPFILTER (pad), NULL);
2126 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
2127 GST_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
2128 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
2130 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
2133 G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
2137 #ifndef GST_DISABLE_LOADSAVE
2138 /* FIXME: why isn't this on a GstElement ? */
2140 * gst_pad_load_and_link:
2141 * @self: an #xmlNodePtr to read the description from.
2142 * @parent: the #GstObject element that owns the pad.
2144 * Reads the pad definition from the XML node and links the given pad
2145 * in the element to a pad of an element up in the hierarchy.
2148 gst_pad_load_and_link (xmlNodePtr self, GstObject *parent)
2150 xmlNodePtr field = self->xmlChildrenNode;
2151 GstPad *pad = NULL, *targetpad;
2155 GstObject *grandparent;
2158 if (!strcmp (field->name, "name")) {
2159 pad = gst_element_get_pad (GST_ELEMENT (parent),
2160 xmlNodeGetContent (field));
2162 else if (!strcmp(field->name, "peer")) {
2163 peer = xmlNodeGetContent (field);
2165 field = field->next;
2167 g_return_if_fail (pad != NULL);
2169 if (peer == NULL) return;
2171 split = g_strsplit (peer, ".", 2);
2173 if (split[0] == NULL || split[1] == NULL) {
2174 GST_DEBUG (GST_CAT_XML,
2175 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
2176 peer, GST_DEBUG_PAD_NAME (pad));
2180 g_return_if_fail (split[0] != NULL);
2181 g_return_if_fail (split[1] != NULL);
2183 grandparent = gst_object_get_parent (parent);
2185 if (grandparent && GST_IS_BIN (grandparent)) {
2186 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2191 if (target == NULL) goto cleanup;
2193 targetpad = gst_element_get_pad (target, split[1]);
2195 if (targetpad == NULL) goto cleanup;
2197 gst_pad_link (pad, targetpad);
2204 * gst_pad_save_thyself:
2205 * @pad: a #GstPad to save.
2206 * @parent: the parent #xmlNodePtr to save the description in.
2208 * Saves the pad into an xml representation.
2210 * Returns: the #xmlNodePtr representation of the pad.
2213 gst_pad_save_thyself (GstObject *object, xmlNodePtr parent)
2215 GstRealPad *realpad;
2218 g_return_val_if_fail (GST_IS_REAL_PAD (object), NULL);
2220 realpad = GST_REAL_PAD (object);
2222 xmlNewChild (parent, NULL, "name", GST_PAD_NAME (realpad));
2223 if (GST_RPAD_PEER (realpad) != NULL) {
2226 peer = GST_PAD (GST_RPAD_PEER (realpad));
2227 /* first check to see if the peer's parent's parent is the same */
2228 /* we just save it off */
2229 content = g_strdup_printf ("%s.%s",
2230 GST_OBJECT_NAME (GST_PAD_PARENT (peer)),
2231 GST_PAD_NAME (peer));
2232 xmlNewChild (parent, NULL, "peer", content);
2235 xmlNewChild (parent, NULL, "peer", "");
2240 /* FIXME: shouldn't pad and ghost be switched ?
2243 * gst_ghost_pad_save_thyself:
2244 * @pad: a ghost #GstPad to save.
2245 * @parent: the parent #xmlNodePtr to save the description in.
2247 * Saves the ghost pad into an xml representation.
2249 * Returns: the #xmlNodePtr representation of the pad.
2252 gst_ghost_pad_save_thyself (GstPad *pad, xmlNodePtr parent)
2256 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2258 self = xmlNewChild (parent, NULL, "ghostpad", NULL);
2259 xmlNewChild (self, NULL, "name", GST_PAD_NAME (pad));
2260 xmlNewChild (self, NULL, "parent", GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
2262 /* FIXME FIXME FIXME! */
2266 #endif /* GST_DISABLE_LOADSAVE */
2270 * @pad: a #GstPad to push the buffer out of.
2271 * @buf: the #GstBuffer to push.
2273 * Pushes a buffer to the peer of the pad.
2276 gst_pad_push (GstPad *pad, GstBuffer *buf)
2280 GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
2282 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
2284 if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), (GstData **) &buf))
2287 peer = GST_RPAD_PEER (pad);
2290 g_warning ("push on pad %s:%s but it is unlinked",
2291 GST_DEBUG_PAD_NAME (pad));
2294 if (!GST_IS_EVENT (buf) && !GST_PAD_IS_ACTIVE (pad)) {
2295 g_warning ("push on pad %s:%s but it is not active",
2296 GST_DEBUG_PAD_NAME (pad));
2300 if (peer->chainhandler) {
2302 GST_DEBUG (GST_CAT_DATAFLOW,
2303 "calling chainhandler &%s of peer pad %s:%s",
2304 GST_DEBUG_FUNCPTR_NAME (peer->chainhandler),
2305 GST_DEBUG_PAD_NAME (GST_PAD (peer)));
2306 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, (GstData **) &buf))
2309 (peer->chainhandler) (GST_PAD_CAST (peer), buf);
2313 g_warning ("trying to push a NULL buffer on pad %s:%s",
2314 GST_DEBUG_PAD_NAME (peer));
2319 g_warning ("internal error: push on pad %s:%s but it has no chainhandler",
2320 GST_DEBUG_PAD_NAME (peer));
2323 /* clean up the mess here */
2324 if (buf != NULL) gst_data_unref (GST_DATA (buf));
2329 * @pad: a #GstPad to pull a buffer from.
2331 * Pulls a buffer from the peer pad.
2333 * Returns: a new #GstBuffer from the peer pad.
2336 gst_pad_pull (GstPad *pad)
2340 GST_DEBUG_ENTER("(%s:%s)",GST_DEBUG_PAD_NAME(pad));
2342 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
2343 GST_BUFFER (gst_event_new (GST_EVENT_INTERRUPT)));
2345 peer = GST_RPAD_PEER (pad);
2348 gst_element_error (GST_PAD_PARENT (pad),
2349 "pull on pad %s:%s but it was unlinked",
2350 GST_ELEMENT_NAME (GST_PAD_PARENT (pad)),
2351 GST_PAD_NAME (pad), NULL);
2355 if (peer->gethandler) {
2358 GST_DEBUG (GST_CAT_DATAFLOW, "calling gethandler %s of peer pad %s:%s",
2359 GST_DEBUG_FUNCPTR_NAME (peer->gethandler),
2360 GST_DEBUG_PAD_NAME (peer));
2362 buf = (peer->gethandler) (GST_PAD_CAST (peer));
2365 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, (GstData **) &buf))
2370 /* no null buffers allowed */
2371 gst_element_error (GST_PAD_PARENT (pad),
2372 "NULL buffer during pull on %s:%s",
2373 GST_DEBUG_PAD_NAME (pad), NULL);
2376 gst_element_error (GST_PAD_PARENT (pad),
2377 "internal error: pull on pad %s:%s "
2378 "but the peer pad %s:%s has no gethandler",
2379 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer),
2383 return GST_BUFFER (gst_event_new (GST_EVENT_INTERRUPT));
2388 * @padlist: a #GList of pads.
2390 * Waits for a buffer on any of the list of pads.
2392 * Returns: the #GstPad that has a buffer available.
2393 * Use #gst_pad_pull() to get the buffer.
2396 gst_pad_select (GList *padlist)
2400 pad = gst_scheduler_pad_select (GST_PAD_PARENT (padlist->data)->sched,
2407 * @pad: a first #GstPad to perform the select on.
2408 * @...: A NULL-terminated list of more pads to select on.
2410 * Waits for a buffer on the given set of pads.
2412 * Returns: the #GstPad that has a buffer available.
2413 * Use #gst_pad_pull() to get the buffer.
2416 gst_pad_selectv (GstPad *pad, ...)
2419 GList *padlist = NULL;
2425 va_start (var_args, pad);
2428 padlist = g_list_prepend (padlist, pad);
2429 pad = va_arg (var_args, GstPad *);
2431 result = gst_pad_select (padlist);
2432 g_list_free (padlist);
2439 /************************************************************************
2444 static void gst_pad_template_class_init (GstPadTemplateClass *klass);
2445 static void gst_pad_template_init (GstPadTemplate *templ);
2446 static void gst_pad_template_dispose (GObject *object);
2449 gst_pad_template_get_type (void)
2451 static GType padtemplate_type = 0;
2453 if (!padtemplate_type) {
2454 static const GTypeInfo padtemplate_info = {
2455 sizeof (GstPadTemplateClass), NULL, NULL,
2456 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
2457 sizeof (GstPadTemplate),
2459 (GInstanceInitFunc) gst_pad_template_init, NULL
2461 padtemplate_type = g_type_register_static(GST_TYPE_OBJECT, "GstPadTemplate",
2462 &padtemplate_info, 0);
2464 return padtemplate_type;
2468 gst_pad_template_class_init (GstPadTemplateClass *klass)
2470 GObjectClass *gobject_class;
2471 GstObjectClass *gstobject_class;
2473 gobject_class = (GObjectClass*) klass;
2474 gstobject_class = (GstObjectClass*) klass;
2476 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
2478 gst_pad_template_signals[TEMPL_PAD_CREATED] =
2479 g_signal_new ("pad_created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
2480 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
2481 NULL, NULL, gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
2484 gobject_class->dispose = gst_pad_template_dispose;
2486 gstobject_class->path_string_separator = "*";
2490 gst_pad_template_init (GstPadTemplate *templ)
2495 gst_pad_template_dispose (GObject *object)
2497 GstPadTemplate *templ = GST_PAD_TEMPLATE (object);
2499 g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
2500 gst_caps_unref (GST_PAD_TEMPLATE_CAPS (templ));
2502 G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object);
2505 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
2507 * SOMETIMES padtemplates can do whatever they want, they are provided by the
2509 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
2510 * 'sink%d' template is automatically selected), so we need to restrict their
2514 name_is_valid (const gchar *name, GstPadPresence presence)
2518 if (presence == GST_PAD_ALWAYS) {
2519 if (strchr (name, '%')) {
2520 g_warning ("invalid name template %s: conversion specifications are not"
2521 " allowed for GST_PAD_ALWAYS padtemplates", name);
2524 } else if (presence == GST_PAD_REQUEST) {
2525 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
2526 g_warning ("invalid name template %s: only one conversion specification"
2527 " allowed in GST_PAD_REQUEST padtemplate", name);
2530 if (str && (*(str+1) != 's' && *(str+1) != 'd')) {
2531 g_warning ("invalid name template %s: conversion specification must be of"
2532 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
2535 if (str && (*(str+2) != '\0')) {
2536 g_warning ("invalid name template %s: conversion specification must"
2537 " appear at the end of the GST_PAD_REQUEST padtemplate name",
2547 * gst_pad_template_new:
2548 * @name_template: the name template.
2549 * @direction: the #GstPadDirection of the template.
2550 * @presence: the #GstPadPresence of the pad.
2551 * @caps: a #GstCaps set for the template.
2552 * @...: a NULL-terminated list of #GstCaps.
2554 * Creates a new pad template with a name according to the given template
2555 * and with the given arguments.
2557 * Returns: a new #GstPadTemplate.
2560 gst_pad_template_new (const gchar *name_template,
2561 GstPadDirection direction, GstPadPresence presence,
2564 GstPadTemplate *new;
2566 GstCaps *thecaps = NULL;
2568 g_return_val_if_fail (name_template != NULL, NULL);
2570 if (!name_is_valid (name_template, presence))
2573 new = g_object_new (gst_pad_template_get_type (),
2574 "name", name_template,
2577 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
2578 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
2579 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
2581 va_start (var_args, caps);
2583 GST_FLAG_SET (GST_OBJECT (new), GST_PAD_TEMPLATE_FIXED);
2585 if (!GST_CAPS_IS_FIXED (caps)) {
2586 GST_FLAG_UNSET (GST_OBJECT (new), GST_PAD_TEMPLATE_FIXED);
2588 thecaps = gst_caps_append (thecaps, caps);
2589 caps = va_arg (var_args, GstCaps*);
2593 GST_PAD_TEMPLATE_CAPS (new) = thecaps;
2594 gst_caps_ref (thecaps);
2595 gst_caps_sink (thecaps);
2601 * gst_pad_template_get_caps:
2602 * @templ: a #GstPadTemplate to get capabilities of.
2604 * Gets the capabilities of the pad template.
2606 * Returns: the #GstCaps of the pad template. unref the caps
2610 gst_pad_template_get_caps (GstPadTemplate *templ)
2612 g_return_val_if_fail (templ != NULL, NULL);
2614 return gst_caps_ref (GST_PAD_TEMPLATE_CAPS (templ));
2618 * gst_pad_set_element_private:
2619 * @pad: the #GstPad to set the private data of.
2620 * @priv: The private data to attach to the pad.
2622 * Set the given private data gpointer on the pad.
2623 * This function can only be used by the element that owns the pad.
2626 gst_pad_set_element_private (GstPad *pad, gpointer priv)
2628 pad->element_private = priv;
2632 * gst_pad_get_element_private:
2633 * @pad: the #GstPad to get the private data of.
2635 * Gets the private data of a pad.
2637 * Returns: a #gpointer to the private data.
2640 gst_pad_get_element_private (GstPad *pad)
2642 return pad->element_private;
2646 /***** ghost pads *****/
2647 GType _gst_ghost_pad_type = 0;
2649 static void gst_ghost_pad_class_init (GstGhostPadClass *klass);
2650 static void gst_ghost_pad_init (GstGhostPad *pad);
2651 static void gst_ghost_pad_dispose (GObject *object);
2653 static GstPad *ghost_pad_parent_class = NULL;
2654 /* static guint gst_ghost_pad_signals[LAST_SIGNAL] = { 0 }; */
2657 gst_ghost_pad_get_type (void)
2659 if (!_gst_ghost_pad_type) {
2660 static const GTypeInfo pad_info = {
2661 sizeof (GstGhostPadClass), NULL, NULL,
2662 (GClassInitFunc) gst_ghost_pad_class_init, NULL, NULL,
2663 sizeof (GstGhostPad),
2665 (GInstanceInitFunc) gst_ghost_pad_init,
2668 _gst_ghost_pad_type = g_type_register_static (GST_TYPE_PAD, "GstGhostPad",
2671 return _gst_ghost_pad_type;
2675 gst_ghost_pad_class_init (GstGhostPadClass *klass)
2677 GObjectClass *gobject_class;
2679 gobject_class = (GObjectClass*) klass;
2681 ghost_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
2683 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_ghost_pad_dispose);
2687 gst_ghost_pad_init (GstGhostPad *pad)
2689 /* zeroed by glib */
2692 gst_ghost_pad_dispose (GObject *object)
2694 GstGhostPad *pad = GST_GHOST_PAD (object);
2697 gst_pad_remove_ghost_pad((GstPad *) pad->realpad, (GstPad *) pad);
2699 G_OBJECT_CLASS (ghost_pad_parent_class)->dispose (object);
2703 * gst_ghost_pad_new:
2704 * @name: the name of the new ghost pad.
2705 * @pad: the #GstPad to create a ghost pad for.
2707 * Creates a new ghost pad associated with the given pad, and names it with
2708 * the given name. If name is NULL, a guaranteed unique name (across all
2709 * ghost pads) will be assigned (most likely of the form ghostpad%d).
2711 * Returns: a new ghost #GstPad, or NULL in case of an error.
2715 gst_ghost_pad_new (const gchar *name,
2718 GstGhostPad *ghostpad;
2719 GstRealPad *realpad;
2721 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2723 ghostpad = g_object_new (gst_ghost_pad_get_type () ,NULL);
2724 gst_pad_set_name (GST_PAD (ghostpad), name);
2726 realpad = (GstRealPad *) pad;
2728 while (!GST_IS_REAL_PAD (realpad)) {
2729 realpad = GST_PAD_REALIZE (realpad);
2731 GST_GPAD_REALPAD (ghostpad) = realpad;
2732 gst_pad_set_pad_template (GST_PAD (ghostpad), GST_PAD_PAD_TEMPLATE (pad));
2734 /* add ourselves to the real pad's list of ghostpads */
2735 gst_pad_add_ghost_pad (pad, GST_PAD (ghostpad));
2737 /* FIXME need to ref the real pad here... ? */
2739 GST_DEBUG (GST_CAT_PADS, "created ghost pad \"%s\"",
2740 gst_pad_get_name (GST_PAD (ghostpad)));
2742 return GST_PAD (ghostpad);
2746 * gst_pad_get_internal_links_default:
2747 * @pad: the #GstPad to get the internal links of.
2749 * Gets a list of pads to which the given pad is linked to
2750 * inside of the parent element.
2751 * This is the default handler, and thus returns a list of all of the
2752 * pads inside the parent element with opposite direction.
2753 * The caller must free this list after use.
2755 * Returns: a newly allocated #GList of pads.
2758 gst_pad_get_internal_links_default (GstPad *pad)
2763 GstPadDirection direction;
2766 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2768 rpad = GST_PAD_REALIZE (pad);
2769 direction = rpad->direction;
2771 parent = GST_PAD_PARENT (rpad);
2772 parent_pads = parent->pads;
2774 while (parent_pads) {
2775 GstRealPad *parent_pad = GST_PAD_REALIZE (parent_pads->data);
2777 if (parent_pad->direction != direction) {
2778 res = g_list_prepend (res, parent_pad);
2781 parent_pads = g_list_next (parent_pads);
2788 * gst_pad_get_internal_links:
2789 * @pad: the #GstPad to get the internal links of.
2791 * Gets a list of pads to which the given pad is linked to
2792 * inside of the parent element.
2793 * The caller must free this list after use.
2795 * Returns: a newly allocated #GList of pads.
2798 gst_pad_get_internal_links (GstPad *pad)
2803 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2805 rpad = GST_PAD_REALIZE (pad);
2807 if (GST_RPAD_INTLINKFUNC (rpad))
2808 res = GST_RPAD_INTLINKFUNC (rpad) (GST_PAD_CAST (rpad));
2815 gst_pad_event_default_dispatch (GstPad *pad, GstElement *element,
2820 orig = pads = gst_pad_get_internal_links (pad);
2823 GstPad *eventpad = GST_PAD (pads->data);
2824 pads = g_list_next (pads);
2826 /* for all pads in the opposite direction that are linked */
2827 if (GST_PAD_IS_LINKED (eventpad)) {
2828 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
2829 /* increase the refcount */
2830 gst_event_ref (event);
2831 gst_pad_push (eventpad, GST_BUFFER (event));
2834 GstPad *peerpad = GST_PAD_CAST (GST_RPAD_PEER (eventpad));
2836 /* we only send the event on one pad, multi-sinkpad elements
2837 * should implement a handler */
2839 return gst_pad_send_event (peerpad, event);
2843 gst_event_unref (event);
2849 * gst_pad_event_default:
2850 * @pad: a #GstPad to call the default event handler on.
2851 * @event: the #GstEvent to handle.
2853 * Invokes the default event handler for the given pad.
2855 * Returns: TRUE if the event was sent succesfully.
2858 gst_pad_event_default (GstPad *pad, GstEvent *event)
2860 GstElement *element;
2862 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2863 g_return_val_if_fail (event, FALSE);
2865 element = GST_PAD_PARENT (pad);
2867 switch (GST_EVENT_TYPE (event)) {
2869 gst_pad_event_default_dispatch (pad, element, event);
2870 gst_element_set_eos (element);
2872 case GST_EVENT_DISCONTINUOUS:
2876 if (gst_event_discont_get_value (event, GST_FORMAT_TIME, &time)) {
2877 if (gst_element_requires_clock (element) && element->clock) {
2878 gst_clock_handle_discont (element->clock, time);
2882 case GST_EVENT_FLUSH:
2884 return gst_pad_event_default_dispatch (pad, element, event);
2890 * gst_pad_dispatcher:
2891 * @pad: a #GstPad to dispatch.
2892 * @dispatch: the #GstDispatcherFunction to call.
2893 * @data: gpointer user data passed to the dispatcher function.
2895 * Invokes the given dispatcher function on all pads that are
2896 * internally linked to the given pad.
2897 * The GstPadDispatcherFunction should return TRUE when no further pads
2898 * need to be processed.
2900 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2903 gst_pad_dispatcher (GstPad *pad, GstPadDispatcherFunction dispatch,
2906 gboolean res = FALSE;
2907 GList *int_pads, *orig;
2909 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2910 g_return_val_if_fail (data, FALSE);
2912 orig = int_pads = gst_pad_get_internal_links (pad);
2915 GstRealPad *int_rpad = GST_PAD_REALIZE (int_pads->data);
2916 GstRealPad *int_peer = GST_RPAD_PEER (int_rpad);
2919 res = dispatch (GST_PAD_CAST (int_peer), data);
2923 int_pads = g_list_next (int_pads);
2932 * gst_pad_send_event:
2933 * @pad: a #GstPad to send the event to.
2934 * @event: the #GstEvent to send to the pad.
2936 * Sends the event to the pad.
2938 * Returns: TRUE if the event was handled.
2941 gst_pad_send_event (GstPad *pad, GstEvent *event)
2943 gboolean success = FALSE;
2946 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2947 g_return_val_if_fail (event, FALSE);
2949 rpad = GST_PAD_REALIZE (pad);
2951 if (GST_EVENT_SRC (event) == NULL)
2952 GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (rpad));
2954 GST_DEBUG (GST_CAT_EVENT, "have event %d on pad %s:%s",
2955 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (rpad));
2957 if (GST_RPAD_EVENTHANDLER (rpad))
2958 success = GST_RPAD_EVENTHANDLER (rpad) (GST_PAD_CAST (rpad), event);
2960 GST_DEBUG (GST_CAT_EVENT, "there's no event function for pad %s:%s",
2961 GST_DEBUG_PAD_NAME (rpad));
2962 gst_event_unref (event);
2970 GstFormat src_format;
2972 GstFormat *dest_format;
2974 } GstPadConvertData;
2977 gst_pad_convert_dispatcher (GstPad *pad, GstPadConvertData *data)
2979 return gst_pad_convert (pad, data->src_format, data->src_value,
2980 data->dest_format, data->dest_value);
2984 * gst_pad_convert_default:
2985 * @pad: a #GstPad to invoke the default converter on.
2986 * @src_format: the source #GstFormat.
2987 * @src_value: the source value.
2988 * @dest_format: a pointer to the destination #GstFormat.
2989 * @dest_value: a pointer to the destination value.
2991 * Invokes the default converter on a pad.
2992 * This will forward the call to the pad obtained
2993 * using the internal link of
2996 * Returns: TRUE if the conversion could be performed.
2999 gst_pad_convert_default (GstPad *pad,
3000 GstFormat src_format, gint64 src_value,
3001 GstFormat *dest_format, gint64 *dest_value)
3003 GstPadConvertData data;
3005 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3006 g_return_val_if_fail (dest_format, FALSE);
3007 g_return_val_if_fail (dest_value, FALSE);
3009 data.src_format = src_format;
3010 data.src_value = src_value;
3011 data.dest_format = dest_format;
3012 data.dest_value = dest_value;
3014 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3015 gst_pad_convert_dispatcher, &data);
3020 * @pad: a #GstPad to invoke the default converter on.
3021 * @src_format: the source #GstFormat.
3022 * @src_value: the source value.
3023 * @dest_format: a pointer to the destination #GstFormat.
3024 * @dest_value: a pointer to the destination value.
3026 * Invokes a conversion on the pad.
3028 * Returns: TRUE if the conversion could be performed.
3031 gst_pad_convert (GstPad *pad,
3032 GstFormat src_format, gint64 src_value,
3033 GstFormat *dest_format, gint64 *dest_value)
3037 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3038 g_return_val_if_fail (dest_format, FALSE);
3039 g_return_val_if_fail (dest_value, FALSE);
3041 if (src_format == *dest_format) {
3042 *dest_value = src_value;
3046 rpad = GST_PAD_REALIZE (pad);
3048 if (GST_RPAD_CONVERTFUNC (rpad)) {
3049 return GST_RPAD_CONVERTFUNC (rpad) (GST_PAD_CAST (rpad), src_format,
3050 src_value, dest_format, dest_value);
3064 gst_pad_query_dispatcher (GstPad *pad, GstPadQueryData *data)
3066 return gst_pad_query (pad, data->type, data->format, data->value);
3070 * gst_pad_query_default:
3071 * @pad: a #GstPad to invoke the default query on.
3072 * @type: the #GstQueryType of the query to perform.
3073 * @format: a pointer to the #GstFormat of the result.
3074 * @value: a pointer to the result.
3076 * Invokes the default query function on a pad.
3078 * Returns: TRUE if the query could be performed.
3081 gst_pad_query_default (GstPad *pad, GstQueryType type,
3082 GstFormat *format, gint64 *value)
3084 GstPadQueryData data;
3086 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3087 g_return_val_if_fail (format, FALSE);
3088 g_return_val_if_fail (value, FALSE);
3091 data.format = format;
3094 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3095 gst_pad_query_dispatcher, &data);
3100 * @pad: a #GstPad to invoke the default query on.
3101 * @type: the #GstQueryType of the query to perform.
3102 * @format: a pointer to the #GstFormat asked for.
3103 * On return contains the #GstFormat used.
3104 * @value: a pointer to the result.
3106 * Queries a pad for one of the available properties. The format will be
3107 * adjusted to the actual format used when specifying formats such as
3108 * GST_FORMAT_DEFAULT.
3109 * FIXME: Tell if the format can be adjusted when specifying a definite format.
3111 * Returns: TRUE if the query could be performed.
3114 gst_pad_query (GstPad *pad, GstQueryType type,
3115 GstFormat *format, gint64 *value)
3119 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3120 g_return_val_if_fail (format, FALSE);
3121 g_return_val_if_fail (value, FALSE);
3123 rpad = GST_PAD_REALIZE (pad);
3125 g_return_val_if_fail (rpad, FALSE);
3127 if (GST_RPAD_QUERYFUNC (rpad))
3128 return GST_RPAD_QUERYFUNC (rpad) (GST_PAD_CAST (pad), type, format, value);
3134 gst_pad_get_formats_dispatcher (GstPad *pad, const GstFormat **data)
3136 *data = gst_pad_get_formats (pad);
3142 * gst_pad_get_formats_default:
3143 * @pad: a #GstPad to query
3145 * Invoke the default format dispatcher for the pad.
3147 * Returns: An array of GstFormats ended with a 0 value.
3150 gst_pad_get_formats_default (GstPad *pad)
3152 GstFormat *result = NULL;
3154 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3155 gst_pad_get_formats_dispatcher, &result);
3161 * gst_pad_get_formats:
3162 * @pad: a #GstPad to query
3164 * Gets the list of supported formats from the pad.
3166 * Returns: An array of GstFormats ended with a 0 value.
3169 gst_pad_get_formats (GstPad *pad)
3173 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3175 rpad = GST_PAD_REALIZE (pad);
3177 if (GST_RPAD_FORMATSFUNC (rpad))
3178 return GST_RPAD_FORMATSFUNC (rpad) (GST_PAD_CAST (pad));