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"
27 #include "gstelement.h"
30 #include "gstscheduler.h"
40 static GstObject *padtemplate_parent_class = NULL;
41 static guint gst_pad_template_signals[TEMPL_LAST_SIGNAL] = { 0 };
43 GType _gst_pad_type = 0;
45 /***** Start with the base GstPad class *****/
46 static void gst_pad_class_init (GstPadClass *klass);
47 static void gst_pad_init (GstPad *pad);
48 static void gst_pad_dispose (GObject *object);
50 static gboolean gst_pad_try_relink_filtered_func (GstRealPad *srcpad, GstRealPad *sinkpad,
51 GstCaps *caps, gboolean clear);
52 static void gst_pad_set_pad_template (GstPad *pad, GstPadTemplate *templ);
54 #ifndef GST_DISABLE_LOADSAVE
55 static xmlNodePtr gst_pad_save_thyself (GstObject *object, xmlNodePtr parent);
58 static GstObject *pad_parent_class = NULL;
61 gst_pad_get_type (void)
64 static const GTypeInfo pad_info = {
65 sizeof (GstPadClass), NULL, NULL,
66 (GClassInitFunc) gst_pad_class_init, NULL, NULL,
69 (GInstanceInitFunc) gst_pad_init, NULL
71 _gst_pad_type = g_type_register_static (GST_TYPE_OBJECT, "GstPad",
78 gst_pad_class_init (GstPadClass *klass)
80 GObjectClass *gobject_class;
82 gobject_class = (GObjectClass*) klass;
84 pad_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
86 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_pad_dispose);
90 gst_pad_init (GstPad *pad)
92 /* all structs are initialized to NULL by glib */
95 gst_pad_dispose (GObject *object)
97 GstPad *pad = GST_PAD (object);
99 gst_pad_set_pad_template (pad, NULL);
101 G_OBJECT_CLASS (pad_parent_class)->dispose (object);
106 /***** Then do the Real Pad *****/
107 /* Pad signals and args */
109 REAL_CAPS_NEGO_FAILED,
123 static void gst_real_pad_class_init (GstRealPadClass *klass);
124 static void gst_real_pad_init (GstRealPad *pad);
125 static void gst_real_pad_dispose (GObject *object);
127 static void gst_real_pad_set_property (GObject *object, guint prop_id,
130 static void gst_real_pad_get_property (GObject *object, guint prop_id,
134 GType _gst_real_pad_type = 0;
136 static GstPad *real_pad_parent_class = NULL;
137 static guint gst_real_pad_signals[REAL_LAST_SIGNAL] = { 0 };
140 gst_real_pad_get_type (void) {
141 if (!_gst_real_pad_type) {
142 static const GTypeInfo pad_info = {
143 sizeof (GstRealPadClass), NULL, NULL,
144 (GClassInitFunc) gst_real_pad_class_init, NULL, NULL,
147 (GInstanceInitFunc) gst_real_pad_init, NULL
149 _gst_real_pad_type = g_type_register_static (GST_TYPE_PAD, "GstRealPad",
152 return _gst_real_pad_type;
156 gst_real_pad_class_init (GstRealPadClass *klass)
158 GObjectClass *gobject_class;
159 GstObjectClass *gstobject_class;
161 gobject_class = (GObjectClass*) klass;
162 gstobject_class = (GstObjectClass*) klass;
164 real_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
166 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_real_pad_dispose);
167 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_real_pad_set_property);
168 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_real_pad_get_property);
170 gst_real_pad_signals[REAL_CAPS_NEGO_FAILED] =
171 g_signal_new ("caps_nego_failed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
172 G_STRUCT_OFFSET (GstRealPadClass, caps_nego_failed), NULL, NULL,
173 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
175 gst_real_pad_signals[REAL_LINKED] =
176 g_signal_new ("linked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
177 G_STRUCT_OFFSET (GstRealPadClass, linked), NULL, NULL,
178 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
180 gst_real_pad_signals[REAL_UNLINKED] =
181 g_signal_new ("unlinked", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
182 G_STRUCT_OFFSET (GstRealPadClass, unlinked), NULL, NULL,
183 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
186 /* gtk_object_add_arg_type ("GstRealPad::active", G_TYPE_BOOLEAN, */
187 /* GTK_ARG_READWRITE, REAL_ARG_ACTIVE); */
188 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_ACTIVE,
189 g_param_spec_boolean ("active", "Active", "Whether the pad is active.",
190 TRUE, G_PARAM_READWRITE));
191 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_CAPS,
192 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
193 GST_TYPE_CAPS, G_PARAM_READABLE));
195 #ifndef GST_DISABLE_LOADSAVE
196 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
198 gstobject_class->path_string_separator = ".";
202 gst_real_pad_init (GstRealPad *pad)
204 pad->direction = GST_PAD_UNKNOWN;
207 pad->chainfunc = NULL;
210 pad->chainhandler = NULL;
211 pad->gethandler = NULL;
213 pad->bufferpoolfunc = NULL;
214 pad->ghostpads = NULL;
217 pad->linkfunc = NULL;
218 pad->getcapsfunc = NULL;
220 pad->convertfunc = gst_pad_convert_default;
221 pad->eventfunc = gst_pad_event_default;
222 pad->convertfunc = gst_pad_convert_default;
223 pad->queryfunc = gst_pad_query_default;
224 pad->intlinkfunc = gst_pad_get_internal_links_default;
226 pad->eventmaskfunc = gst_pad_get_event_masks_default;
227 pad->formatsfunc = gst_pad_get_formats_default;
228 pad->querytypefunc = gst_pad_get_query_types_default;
230 GST_FLAG_SET (pad, GST_PAD_DISABLED);
231 GST_FLAG_UNSET (pad, GST_PAD_NEGOTIATING);
233 gst_probe_dispatcher_init (&pad->probedisp);
237 gst_real_pad_set_property (GObject *object, guint prop_id,
238 const GValue *value, GParamSpec *pspec)
240 g_return_if_fail (GST_IS_PAD (object));
243 case REAL_ARG_ACTIVE:
244 gst_pad_set_active (GST_PAD (object), g_value_get_boolean (value));
247 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
253 gst_real_pad_get_property (GObject *object, guint prop_id,
254 GValue *value, GParamSpec *pspec)
256 g_return_if_fail (GST_IS_PAD (object));
259 case REAL_ARG_ACTIVE:
260 g_value_set_boolean (value, !GST_FLAG_IS_SET (object, GST_PAD_DISABLED));
263 g_value_set_boxed (value, GST_PAD_CAPS (GST_REAL_PAD (object)));
266 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
273 * gst_pad_custom_new:
274 * @type: the #Gtype of the pad.
275 * @name: the name of the new pad.
276 * @direction: the #GstPadDirection of the pad.
278 * Creates a new pad with the given name and type in the given direction.
279 * If name is NULL, a guaranteed unique name (across all pads)
282 * Returns: a new #GstPad, or NULL in case of an error.
285 gst_pad_custom_new (GType type, const gchar *name,
286 GstPadDirection direction)
290 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
292 pad = g_object_new (type, NULL);
293 gst_object_set_name (GST_OBJECT (pad), name);
294 GST_RPAD_DIRECTION (pad) = direction;
296 return GST_PAD (pad);
301 * @name: the name of the new pad.
302 * @direction: the #GstPadDirection of the pad.
304 * Creates a new real pad with the given name in the given direction.
305 * If name is NULL, a guaranteed unique name (across all pads)
308 * Returns: a new #GstPad, or NULL in case of an error.
311 gst_pad_new (const gchar *name,
312 GstPadDirection direction)
314 return gst_pad_custom_new (gst_real_pad_get_type (), name, direction);
318 * gst_pad_custom_new_from_template:
319 * @type: the custom #GType of the pad.
320 * @templ: the #GstPadTemplate to instantiate from.
321 * @name: the name of the new pad.
323 * Creates a new custom pad with the given name from the given template.
324 * If name is NULL, a guaranteed unique name (across all pads)
327 * Returns: a new #GstPad, or NULL in case of an error.
330 gst_pad_custom_new_from_template (GType type, GstPadTemplate *templ,
335 g_return_val_if_fail (templ != NULL, NULL);
337 pad = gst_pad_new (name, templ->direction);
338 gst_pad_set_pad_template (pad, templ);
344 * gst_pad_new_from_template:
345 * @templ: the pad template to use
346 * @name: the name of the element
348 * Creates a new real pad with the given name from the given template.
349 * If name is NULL, a guaranteed unique name (across all pads)
352 * Returns: a new #GstPad, or NULL in case of an error.
355 gst_pad_new_from_template (GstPadTemplate *templ, const gchar *name)
357 return gst_pad_custom_new_from_template (gst_real_pad_get_type (),
362 * gst_pad_get_direction:
363 * @pad: a #GstPad to get the direction of.
365 * Gets the direction of the pad.
367 * Returns: the #GstPadDirection of the pad.
370 gst_pad_get_direction (GstPad *pad)
372 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
374 return GST_PAD_DIRECTION (pad);
378 * gst_pad_set_active:
379 * @pad: the #GstPad to activate or deactivate.
380 * @active: TRUE to activate the pad.
382 * Activates or deactivates the given pad.
385 gst_pad_set_active (GstPad *pad, gboolean active)
390 g_return_if_fail (GST_IS_PAD (pad));
392 old = GST_PAD_IS_ACTIVE (pad);
397 realpad = GST_PAD_REALIZE (pad);
400 GST_CAT_DEBUG (GST_CAT_PADS, "activating pad %s:%s",
401 GST_DEBUG_PAD_NAME (realpad));
402 GST_FLAG_UNSET (realpad, GST_PAD_DISABLED);
404 GST_CAT_DEBUG (GST_CAT_PADS, "de-activating pad %s:%s",
405 GST_DEBUG_PAD_NAME (realpad));
406 GST_FLAG_SET (realpad, GST_PAD_DISABLED);
409 g_object_notify (G_OBJECT (realpad), "active");
414 * @pad: the #GstPad to query
416 * Query if a pad is active
418 * Returns: TRUE if the pad is active.
421 gst_pad_is_active (GstPad *pad)
423 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
425 return !GST_FLAG_IS_SET (pad, GST_PAD_DISABLED);
430 * @pad: a #GstPad to set the name of.
431 * @name: the name of the pad.
433 * Sets the name of a pad. If name is NULL, then a guaranteed unique
434 * name will be assigned.
437 gst_pad_set_name (GstPad *pad, const gchar *name)
439 g_return_if_fail (GST_IS_PAD (pad));
441 gst_object_set_name (GST_OBJECT (pad), name);
446 * @pad: a #GstPad to get the name of.
448 * Gets the name of a pad.
450 * Returns: the name of the pad. This is not a newly allocated pointer
451 * so you must not free it.
454 gst_pad_get_name (GstPad *pad)
456 g_return_val_if_fail (pad != NULL, NULL);
457 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
459 return GST_OBJECT_NAME (pad);
463 * gst_pad_set_chain_function:
464 * @pad: a #GstPad to set the chain function for.
465 * @chain: the #GstPadChainFunction to set.
467 * Sets the given chain function for the pad.
470 gst_pad_set_chain_function (GstPad *pad, GstPadChainFunction chain)
472 g_return_if_fail (pad != NULL);
473 g_return_if_fail (GST_IS_REAL_PAD (pad));
475 GST_RPAD_CHAINFUNC (pad) = chain;
476 GST_CAT_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
477 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
481 * gst_pad_set_get_function:
482 * @pad: a #GstPad to set the get function for.
483 * @get: the #GstPadGetFunction to set.
485 * Sets the given get function for the pad.
488 gst_pad_set_get_function (GstPad *pad,
489 GstPadGetFunction get)
491 g_return_if_fail (pad != NULL);
492 g_return_if_fail (GST_IS_REAL_PAD (pad));
494 GST_RPAD_GETFUNC (pad) = get;
496 GST_CAT_DEBUG (GST_CAT_PADS, "getfunc for %s:%s set to %s",
497 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
501 * gst_pad_set_event_function:
502 * @pad: a #GstPad to set the event handler for.
503 * @event: the #GstPadEventFunction to set.
505 * Sets the given event handler for the pad.
508 gst_pad_set_event_function (GstPad *pad,
509 GstPadEventFunction event)
511 g_return_if_fail (GST_IS_REAL_PAD (pad));
513 GST_RPAD_EVENTFUNC (pad) = event;
515 GST_CAT_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
516 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
520 * gst_pad_set_event_mask_function:
521 * @pad: a #GstPad to set the event mask function for.
522 * @mask_func: the #GstPadEventMaskFunction to set.
524 * Sets the given event mask function for the pad.
527 gst_pad_set_event_mask_function (GstPad *pad,
528 GstPadEventMaskFunction mask_func)
530 g_return_if_fail (GST_IS_REAL_PAD (pad));
532 GST_RPAD_EVENTMASKFUNC (pad) = mask_func;
534 GST_CAT_DEBUG (GST_CAT_PADS, "eventmaskfunc for %s:%s set to %s",
535 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (mask_func));
539 * gst_pad_get_event_masks:
540 * @pad: a #GstPad to get the event mask for.
542 * Gets the array of eventmasks from the given pad.
544 * Returns: an array with eventmasks, the list is ended
548 gst_pad_get_event_masks (GstPad *pad)
555 rpad = GST_PAD_REALIZE (pad);
557 g_return_val_if_fail (rpad, FALSE);
559 if (GST_RPAD_EVENTMASKFUNC (rpad))
560 return GST_RPAD_EVENTMASKFUNC (rpad) (GST_PAD_CAST (pad));
566 gst_pad_get_event_masks_dispatcher (GstPad *pad, const GstEventMask **data)
568 *data = gst_pad_get_event_masks (pad);
574 * gst_pad_get_event_masks_default:
575 * @pad: a #GstPad to get the event mask for.
577 * Invokes the default event masks dispatcher on the pad.
579 * Returns: an array with eventmasks, the list is ended
583 gst_pad_get_event_masks_default (GstPad *pad)
585 GstEventMask *result = NULL;
587 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
588 gst_pad_get_event_masks_dispatcher, &result);
594 * gst_pad_set_convert_function:
595 * @pad: a #GstPad to set the convert function for.
596 * @convert: the #GstPadConvertFunction to set.
598 * Sets the given convert function for the pad.
601 gst_pad_set_convert_function (GstPad *pad,
602 GstPadConvertFunction convert)
604 g_return_if_fail (pad != NULL);
605 g_return_if_fail (GST_IS_REAL_PAD (pad));
607 GST_RPAD_CONVERTFUNC (pad) = convert;
609 GST_CAT_DEBUG (GST_CAT_PADS, "convertfunc for %s:%s set to %s",
610 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (convert));
614 * gst_pad_set_query_function:
615 * @pad: the #GstPad to set the query function for.
616 * @query: the #GstPadQueryFunction to set.
618 * Set the given query function for the pad.
621 gst_pad_set_query_function (GstPad *pad, GstPadQueryFunction query)
623 g_return_if_fail (pad != NULL);
624 g_return_if_fail (GST_IS_REAL_PAD (pad));
626 GST_RPAD_QUERYFUNC (pad) = query;
628 GST_CAT_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
629 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
633 * gst_pad_set_query_type_function:
634 * @pad: the #GstPad to set the query type function for.
635 * @type_func: the #GstPadQueryTypeFunction to set.
637 * Set the given query type function for the pad.
640 gst_pad_set_query_type_function (GstPad *pad, GstPadQueryTypeFunction type_func)
642 g_return_if_fail (pad != NULL);
643 g_return_if_fail (GST_IS_REAL_PAD (pad));
645 GST_RPAD_QUERYTYPEFUNC (pad) = type_func;
647 GST_CAT_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
648 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
652 * gst_pad_get_query_types:
653 * @pad: the #GstPad to query
655 * Get an array of supported queries that can be performed
658 * Returns: an array of querytypes anded with 0.
661 gst_pad_get_query_types (GstPad *pad)
668 rpad = GST_PAD_REALIZE (pad);
670 g_return_val_if_fail (rpad, FALSE);
672 if (GST_RPAD_QUERYTYPEFUNC (rpad))
673 return GST_RPAD_QUERYTYPEFUNC (rpad) (GST_PAD_CAST (pad));
679 gst_pad_get_query_types_dispatcher (GstPad *pad, const GstQueryType **data)
681 *data = gst_pad_get_query_types (pad);
687 * gst_pad_get_query_types_default:
688 * @pad: the #GstPad to query
690 * Invoke the default dispatcher for the query types on
693 * Returns: an array of querytypes anded with 0.
696 gst_pad_get_query_types_default (GstPad *pad)
698 GstQueryType *result = NULL;
700 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
701 gst_pad_get_query_types_dispatcher, &result);
707 * gst_pad_set_internal_link_function:
708 * @pad: a #GstPad to set the internal link function for.
709 * @intlink: the #GstPadIntLinkFunction to set.
711 * Sets the given internal link function for the pad.
714 gst_pad_set_internal_link_function (GstPad *pad,
715 GstPadIntLinkFunction intlink)
717 g_return_if_fail (pad != NULL);
718 g_return_if_fail (GST_IS_REAL_PAD (pad));
720 GST_RPAD_INTLINKFUNC (pad) = intlink;
721 GST_CAT_DEBUG (GST_CAT_PADS, "internal link for %s:%s set to %s",
722 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intlink));
726 * gst_pad_set_formats_function:
727 * @pad: the #GstPad to set the formats function for.
728 * @formats: the #GstPadFormatsFunction to set.
730 * Sets the given formats function for the pad.
733 gst_pad_set_formats_function (GstPad *pad, GstPadFormatsFunction formats)
735 g_return_if_fail (pad != NULL);
736 g_return_if_fail (GST_IS_REAL_PAD (pad));
738 GST_RPAD_FORMATSFUNC (pad) = formats;
739 GST_CAT_DEBUG (GST_CAT_PADS, "formats function for %s:%s set to %s",
740 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (formats));
744 * gst_pad_set_link_function:
745 * @pad: a #GstPad to set the link function for.
746 * @link: the #GstPadLinkFunction to set.
748 * Sets the given link function for the pad. It will be called
749 * when the pad is linked or relinked with caps.
752 gst_pad_set_link_function (GstPad *pad,
753 GstPadLinkFunction link)
755 g_return_if_fail (pad != NULL);
756 g_return_if_fail (GST_IS_REAL_PAD (pad));
758 GST_RPAD_LINKFUNC (pad) = link;
759 GST_CAT_DEBUG (GST_CAT_PADS, "linkfunc for %s:%s set to %s",
760 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (link));
764 * gst_pad_set_getcaps_function:
765 * @pad: a #GstPad to set the getcaps function for.
766 * @getcaps: the #GstPadGetCapsFunction to set.
768 * Sets the given getcaps function for the pad.
771 gst_pad_set_getcaps_function (GstPad *pad,
772 GstPadGetCapsFunction getcaps)
774 g_return_if_fail (pad != NULL);
775 g_return_if_fail (GST_IS_REAL_PAD (pad));
777 GST_RPAD_GETCAPSFUNC (pad) = getcaps;
778 GST_CAT_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
779 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
782 * gst_pad_set_bufferpool_function:
783 * @pad: a #GstPad to set the bufferpool function for.
784 * @bufpool: the #GstPadBufferPoolFunction to set.
786 * Sets the given bufferpool function for the pad. Note that the
787 * bufferpool function can only be set on sinkpads.
790 gst_pad_set_bufferpool_function (GstPad *pad,
791 GstPadBufferPoolFunction bufpool)
793 g_return_if_fail (pad != NULL);
794 g_return_if_fail (GST_IS_REAL_PAD (pad));
795 g_return_if_fail (GST_PAD_IS_SINK (pad));
797 GST_RPAD_BUFFERPOOLFUNC (pad) = bufpool;
798 GST_CAT_DEBUG (GST_CAT_PADS, "bufferpoolfunc for %s:%s set to %s",
799 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufpool));
804 * @srcpad: the source #GstPad to unlink.
805 * @sinkpad: the sink #GstPad to unlink.
807 * Unlinks the source pad from the sink pad.
810 gst_pad_unlink (GstPad *srcpad,
813 GstRealPad *realsrc, *realsink;
814 GstScheduler *src_sched, *sink_sched;
817 g_return_if_fail (srcpad != NULL);
818 g_return_if_fail (GST_IS_PAD (srcpad));
819 g_return_if_fail (sinkpad != NULL);
820 g_return_if_fail (GST_IS_PAD (sinkpad));
822 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinking %s:%s(%p) and %s:%s(%p)",
823 GST_DEBUG_PAD_NAME (srcpad), srcpad,
824 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
826 /* now we need to deal with the real/ghost stuff */
827 realsrc = GST_PAD_REALIZE (srcpad);
828 realsink = GST_PAD_REALIZE (sinkpad);
830 g_return_if_fail (GST_RPAD_PEER (realsrc) != NULL);
831 g_return_if_fail (GST_RPAD_PEER (realsink) == realsrc);
833 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
834 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
841 g_return_if_fail ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
842 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK));
844 /* get the schedulers before we unlink */
845 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
846 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
848 /* first clear peers */
849 GST_RPAD_PEER (realsrc) = NULL;
850 GST_RPAD_PEER (realsink) = NULL;
852 /* reset the filters, both filters are refcounted once */
853 if (GST_RPAD_FILTER (realsrc)) {
854 gst_caps_replace (&GST_RPAD_FILTER (realsink), NULL);
855 gst_caps_replace (&GST_RPAD_FILTER (realsrc), NULL);
858 /* now tell the scheduler */
859 if (src_sched && src_sched == sink_sched) {
860 gst_scheduler_pad_unlink (src_sched,
861 GST_PAD_CAST (realsrc),
862 GST_PAD_CAST (realsink));
865 /* hold a reference, as they can go away in the signal handlers */
866 gst_object_ref (GST_OBJECT (realsrc));
867 gst_object_ref (GST_OBJECT (realsink));
869 /* fire off a signal to each of the pads telling them
870 * that they've been unlinked */
871 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_UNLINKED],
873 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_UNLINKED],
876 GST_CAT_INFO (GST_CAT_ELEMENT_PADS, "unlinked %s:%s and %s:%s",
877 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
879 gst_object_unref (GST_OBJECT (realsrc));
880 gst_object_unref (GST_OBJECT (realsink));
884 gst_pad_check_schedulers (GstRealPad *realsrc, GstRealPad *realsink)
886 GstScheduler *src_sched, *sink_sched;
887 gint num_decoupled = 0;
889 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
890 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
892 if (src_sched && sink_sched) {
893 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsrc), GST_ELEMENT_DECOUPLED))
895 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsink), GST_ELEMENT_DECOUPLED))
898 if (src_sched != sink_sched && num_decoupled != 1) {
906 * gst_pad_can_link_filtered:
907 * @srcpad: the source #GstPad to link.
908 * @sinkpad: the sink #GstPad to link.
909 * @filtercaps: the filter #GstCaps.
911 * Checks if the source pad and the sink pad can be linked when constrained
912 * by the given filter caps.
914 * Returns: TRUE if the pads can be linked, FALSE otherwise.
917 gst_pad_can_link_filtered (GstPad *srcpad, GstPad *sinkpad,
920 GstRealPad *realsrc, *realsink;
923 g_return_val_if_fail (srcpad != NULL, FALSE);
924 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
925 g_return_val_if_fail (sinkpad != NULL, FALSE);
926 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
928 /* now we need to deal with the real/ghost stuff */
929 realsrc = GST_PAD_REALIZE (srcpad);
930 realsink = GST_PAD_REALIZE (sinkpad);
932 g_return_val_if_fail (GST_RPAD_PEER (realsrc) == NULL, FALSE);
933 g_return_val_if_fail (GST_RPAD_PEER (realsink) == NULL, FALSE);
934 g_return_val_if_fail (GST_PAD_PARENT (realsrc) != NULL, FALSE);
935 g_return_val_if_fail (GST_PAD_PARENT (realsink) != NULL, FALSE);
937 if (!gst_pad_check_schedulers (realsrc, realsink)) {
938 g_warning ("linking pads with different scheds requires "
939 "exactly one decoupled element (queue)");
943 /* check if the directions are compatible */
944 if (!(((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
945 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) ||
946 ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
947 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK))))
954 * @srcpad: the source #GstPad to link.
955 * @sinkpad: the sink #GstPad to link.
957 * Checks if the source pad and the sink pad can be link.
959 * Returns: TRUE if the pads can be linked, FALSE otherwise.
962 gst_pad_can_link (GstPad *srcpad, GstPad *sinkpad)
964 return gst_pad_can_link_filtered (srcpad, sinkpad, NULL);
968 * gst_pad_link_filtered:
969 * @srcpad: the source #GstPad to link.
970 * @sinkpad: the sink #GstPad to link.
971 * @filtercaps: the filter #GstCaps.
973 * Links the source pad and the sink pad, constrained
974 * by the given filter caps. This function sinks the caps.
976 * Returns: TRUE if the pads have been linked, FALSE otherwise.
979 gst_pad_link_filtered (GstPad *srcpad, GstPad *sinkpad, GstCaps *filtercaps)
981 GstRealPad *realsrc, *realsink;
982 GstScheduler *src_sched, *sink_sched;
985 g_return_val_if_fail (srcpad != NULL, FALSE);
986 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
987 g_return_val_if_fail (sinkpad != NULL, FALSE);
988 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
990 GST_CAT_INFO (GST_CAT_PADS, "trying to link %s:%s and %s:%s",
991 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
993 /* now we need to deal with the real/ghost stuff */
994 realsrc = GST_PAD_REALIZE (srcpad);
995 realsink = GST_PAD_REALIZE (sinkpad);
997 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
998 GST_CAT_INFO (GST_CAT_PADS, "*actually* linking %s:%s and %s:%s",
999 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1001 /* FIXME: shouldn't we convert this to g_return_val_if_fail? */
1002 if (GST_RPAD_PEER (realsrc) != NULL) {
1003 GST_CAT_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1004 GST_DEBUG_PAD_NAME (realsrc));
1007 if (GST_RPAD_PEER (realsink) != NULL) {
1008 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1009 GST_DEBUG_PAD_NAME (realsink));
1012 if (GST_PAD_PARENT (realsrc) == NULL) {
1013 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1014 GST_DEBUG_PAD_NAME (realsrc));
1017 if (GST_PAD_PARENT (realsink) == NULL) {
1018 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s has no parent, failed",
1019 GST_DEBUG_PAD_NAME (realsrc));
1023 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1024 g_warning ("linking pads with different scheds requires "
1025 "exactly one decoupled element (such as queue)");
1029 /* check for reversed directions and swap if necessary */
1030 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
1031 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
1032 GstRealPad *temppad;
1038 if (GST_RPAD_DIRECTION (realsrc) != GST_PAD_SRC) {
1039 GST_CAT_INFO (GST_CAT_PADS, "Real src pad %s:%s is not a source pad, failed",
1040 GST_DEBUG_PAD_NAME (realsrc));
1043 if (GST_RPAD_DIRECTION (realsink) != GST_PAD_SINK) {
1044 GST_CAT_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1045 GST_DEBUG_PAD_NAME (realsink));
1048 /* first set peers */
1049 GST_RPAD_PEER (realsrc) = realsink;
1050 GST_RPAD_PEER (realsink) = realsrc;
1052 /* try to negotiate the pads, we don't need to clear the caps here */
1053 if (!gst_pad_try_relink_filtered_func (realsrc, realsink,
1054 filtercaps, FALSE)) {
1055 GST_CAT_DEBUG (GST_CAT_CAPS, "relink_filtered_func failed, can't link");
1057 GST_RPAD_PEER (realsrc) = NULL;
1058 GST_RPAD_PEER (realsink) = NULL;
1063 /* fire off a signal to each of the pads telling them
1064 * that they've been linked */
1065 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_LINKED],
1067 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_LINKED],
1070 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
1071 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
1073 /* now tell the scheduler */
1074 if (src_sched && src_sched == sink_sched) {
1075 gst_scheduler_pad_link (src_sched,
1076 GST_PAD_CAST (realsrc), GST_PAD_CAST (realsink));
1079 GST_CAT_INFO (GST_CAT_PADS, "not telling link to scheduler %s:%s and %s:%s, %p %p",
1080 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
1081 src_sched, sink_sched);
1084 GST_CAT_INFO (GST_CAT_PADS, "linked %s:%s and %s:%s, successful",
1085 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1092 * @srcpad: the source #GstPad to link.
1093 * @sinkpad: the sink #GstPad to link.
1095 * Links the source pad to the sink pad.
1097 * Returns: TRUE if the pad could be linked, FALSE otherwise.
1100 gst_pad_link (GstPad *srcpad, GstPad *sinkpad)
1102 return gst_pad_link_filtered (srcpad, sinkpad, NULL);
1106 * gst_pad_set_parent:
1107 * @pad: a #GstPad to set the parent of.
1108 * @parent: the new parent #GstElement.
1110 * Sets the parent object of a pad.
1113 gst_pad_set_parent (GstPad *pad, GstElement *parent)
1115 g_return_if_fail (pad != NULL);
1116 g_return_if_fail (GST_IS_PAD (pad));
1117 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
1118 g_return_if_fail (parent != NULL);
1119 g_return_if_fail (GST_IS_OBJECT (parent));
1120 g_return_if_fail ((gpointer) pad != (gpointer) parent);
1122 gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (parent));
1126 * gst_pad_get_parent:
1127 * @pad: the #GstPad to get the parent of.
1129 * Gets the parent object of this pad.
1131 * Returns: the parent #GstElement.
1134 gst_pad_get_parent (GstPad *pad)
1136 g_return_val_if_fail (pad != NULL, NULL);
1137 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1139 return GST_PAD_PARENT (pad);
1143 gst_pad_set_pad_template (GstPad *pad, GstPadTemplate *templ)
1145 /* this function would need checks if it weren't static */
1147 gst_object_replace ((GstObject **) &pad->padtemplate, (GstObject *) templ);
1150 g_signal_emit (G_OBJECT (templ), gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
1153 * gst_pad_get_pad_template:
1154 * @pad: a #GstPad to get the pad template of.
1156 * Gets the pad template object of this pad.
1158 * Returns: the #GstPadTemplate from which this pad was instantiated.
1161 gst_pad_get_pad_template (GstPad *pad)
1163 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1165 return GST_PAD_PAD_TEMPLATE (pad);
1170 * gst_pad_get_scheduler:
1171 * @pad: a #GstPad to get the scheduler of.
1173 * Gets the scheduler of the pad. Since the pad does not
1174 * have a scheduler of its own, the scheduler of the parent
1175 * is taken. For decoupled pads, the scheduler of the peer
1178 * Returns: the #GstScheduler of the pad.
1181 gst_pad_get_scheduler (GstPad *pad)
1183 GstScheduler *scheduler = NULL;
1186 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1188 parent = gst_pad_get_parent (pad);
1190 if (GST_FLAG_IS_SET (parent, GST_ELEMENT_DECOUPLED)) {
1191 GstRealPad *peer = GST_RPAD_PEER (pad);
1194 scheduler = gst_element_get_scheduler (gst_pad_get_parent (GST_PAD_CAST (peer)));
1198 scheduler = gst_element_get_scheduler (parent);
1206 * gst_pad_get_real_parent:
1207 * @pad: a #GstPad to get the real parent of.
1209 * Gets the real parent object of this pad. If the pad
1210 * is a ghost pad, the actual owner of the real pad is
1211 * returned, as opposed to #gst_pad_get_parent().
1213 * Returns: the parent #GstElement.
1216 gst_pad_get_real_parent (GstPad *pad)
1218 g_return_val_if_fail (pad != NULL, NULL);
1219 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1221 return GST_PAD_PARENT (GST_PAD (GST_PAD_REALIZE (pad)));
1225 * gst_pad_add_ghost_pad:
1226 * @pad: a #GstPad to attach the ghost pad to.
1227 * @ghostpad: the ghost #GstPad to to the pad.
1229 * Adds a ghost pad to a pad.
1232 gst_pad_add_ghost_pad (GstPad *pad,
1235 GstRealPad *realpad;
1237 g_return_if_fail (pad != NULL);
1238 g_return_if_fail (GST_IS_PAD (pad));
1239 g_return_if_fail (ghostpad != NULL);
1240 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1242 realpad = GST_PAD_REALIZE (pad);
1244 realpad->ghostpads = g_list_prepend (realpad->ghostpads, ghostpad);
1249 * gst_pad_remove_ghost_pad:
1250 * @pad: a #GstPad to remove the ghost pad from.
1251 * @ghostpad: the ghost #GstPad to remove from the pad.
1253 * Removes a ghost pad from a pad.
1256 gst_pad_remove_ghost_pad (GstPad *pad,
1259 GstRealPad *realpad;
1261 g_return_if_fail (GST_IS_PAD (pad));
1262 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1263 realpad = GST_PAD_REALIZE (pad);
1264 g_return_if_fail (GST_GPAD_REALPAD (ghostpad) == realpad);
1266 realpad->ghostpads = g_list_remove (realpad->ghostpads, ghostpad);
1267 GST_GPAD_REALPAD (ghostpad) = NULL;
1271 * gst_pad_get_ghost_pad_list:
1272 * @pad: a #GstPad to get the ghost pads of.
1274 * Gets the ghost pads of this pad.
1276 * Returns: a #GList of ghost pads.
1279 gst_pad_get_ghost_pad_list (GstPad *pad)
1281 g_return_val_if_fail (pad != NULL, NULL);
1282 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1284 return GST_PAD_REALIZE(pad)->ghostpads;
1287 /* an internal caps negotiation helper function:
1289 * 1. optionally calls the pad link function with the provided caps
1290 * 2. deals with the result code of the link function
1291 * 3. sets fixed caps on the pad.
1293 static GstPadLinkReturn
1294 gst_pad_try_set_caps_func (GstRealPad *pad, GstCaps *caps, gboolean notify)
1296 GstCaps *allowed = NULL;
1297 GstPadTemplate *template;
1298 GstElement *parent = GST_PAD_PARENT (pad);
1300 g_return_val_if_fail (pad != NULL, GST_PAD_LINK_REFUSED);
1301 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED);
1303 /* if this pad has a parent and the parent is not READY, delay the
1305 if (parent && GST_STATE (parent) < GST_STATE_READY)
1307 GST_CAT_DEBUG (GST_CAT_CAPS, "parent %s of pad %s:%s is not READY",
1308 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (pad));
1309 return GST_PAD_LINK_DELAYED;
1312 GST_CAT_INFO (GST_CAT_CAPS, "trying to set caps %p on pad %s:%s",
1313 caps, GST_DEBUG_PAD_NAME (pad));
1315 /* first see if we have to check against a filter, we ref the caps here as we're
1316 * going to unref it later on */
1317 if (!(allowed = gst_caps_ref (GST_RPAD_FILTER (pad)))) {
1318 /* no filter, make sure we check against the padtemplate then */
1319 if ((template = gst_pad_get_pad_template (GST_PAD_CAST (pad)))) {
1320 allowed = gst_pad_template_get_caps (template);
1324 /* do we have to check the caps against something? */
1326 GstCaps *intersection;
1328 /* check against calculated caps */
1329 intersection = gst_caps_intersect (caps, allowed);
1331 /* oops, empty intersection, caps don"t have anything in common */
1332 if (!intersection) {
1333 GST_CAT_INFO (GST_CAT_CAPS, "caps did not intersect with %s:%s's allowed caps",
1334 GST_DEBUG_PAD_NAME (pad));
1335 gst_caps_debug (caps, "caps themselves (attemped to set)");
1336 gst_caps_debug (allowed,
1337 "allowed caps that did not agree with caps");
1338 gst_caps_unref (allowed);
1339 return GST_PAD_LINK_REFUSED;
1341 /* caps checks out fine, we can unref the intersection now */
1342 gst_caps_unref (intersection);
1343 gst_caps_unref (allowed);
1344 /* given that the caps are fixed, we know that their intersection with the
1345 * padtemplate caps is the same as caps itself */
1348 /* we need to notify the link function */
1349 if (notify && GST_RPAD_LINKFUNC (pad)) {
1350 GstPadLinkReturn res;
1351 gchar *debug_string;
1352 gboolean negotiating;
1354 GST_CAT_INFO (GST_CAT_CAPS, "calling link function on pad %s:%s",
1355 GST_DEBUG_PAD_NAME (pad));
1357 negotiating = GST_FLAG_IS_SET (pad, GST_PAD_NEGOTIATING);
1359 /* set the NEGOTIATING flag if not already done */
1361 GST_FLAG_SET (pad, GST_PAD_NEGOTIATING);
1363 /* call the link function */
1364 res = GST_RPAD_LINKFUNC (pad) (GST_PAD (pad), caps);
1366 /* unset again after negotiating only if we set it */
1368 GST_FLAG_UNSET (pad, GST_PAD_NEGOTIATING);
1371 case GST_PAD_LINK_REFUSED:
1372 debug_string = "REFUSED";
1374 case GST_PAD_LINK_OK:
1375 debug_string = "OK";
1377 case GST_PAD_LINK_DONE:
1378 debug_string = "DONE";
1380 case GST_PAD_LINK_DELAYED:
1381 debug_string = "DELAYED";
1384 g_warning ("unknown return code from link function of pad %s:%s %d",
1385 GST_DEBUG_PAD_NAME (pad), res);
1386 return GST_PAD_LINK_REFUSED;
1389 GST_CAT_INFO (GST_CAT_CAPS,
1390 "got reply %s (%d) from link function on pad %s:%s",
1391 debug_string, res, GST_DEBUG_PAD_NAME (pad));
1393 /* done means the link function called another caps negotiate function
1394 * on this pad that succeeded, we dont need to continue */
1395 if (res == GST_PAD_LINK_DONE) {
1396 GST_CAT_INFO (GST_CAT_CAPS, "pad %s:%s is done", GST_DEBUG_PAD_NAME (pad));
1397 return GST_PAD_LINK_DONE;
1399 if (res == GST_PAD_LINK_REFUSED) {
1400 GST_CAT_INFO (GST_CAT_CAPS, "pad %s:%s doesn't accept caps",
1401 GST_DEBUG_PAD_NAME (pad));
1402 return GST_PAD_LINK_REFUSED;
1405 /* we can only set caps on the pad if they are fixed */
1406 if (GST_CAPS_IS_FIXED (caps)) {
1408 GST_CAT_INFO (GST_CAT_CAPS, "setting caps on pad %s:%s",
1409 GST_DEBUG_PAD_NAME (pad));
1410 /* if we got this far all is ok, remove the old caps, set the new one */
1411 gst_caps_replace_sink (&GST_PAD_CAPS (pad), caps);
1413 g_object_notify (G_OBJECT (pad), "caps");
1416 GST_CAT_INFO (GST_CAT_CAPS,
1417 "caps are not fixed on pad %s:%s, not setting them yet",
1418 GST_DEBUG_PAD_NAME (pad));
1420 return GST_PAD_LINK_DELAYED;
1422 return GST_PAD_LINK_OK;
1426 * gst_pad_try_set_caps:
1427 * @pad: a #GstPad to try to set the caps on.
1428 * @caps: the #GstCaps to set.
1430 * Tries to set the caps on the given pad. Ownership is always taken
1431 * of the caps, so you will need to unref non-floating caps.
1433 * Returns: A #GstPadLinkReturn value indicating whether the caps
1437 gst_pad_try_set_caps (GstPad *pad, GstCaps *caps)
1439 GstRealPad *peer, *realpad;
1440 GstPadLinkReturn set_retval;
1442 realpad = GST_PAD_REALIZE (pad);
1443 peer = GST_RPAD_PEER (realpad);
1445 GST_CAT_INFO (GST_CAT_CAPS, "trying to set caps %p on pad %s:%s",
1446 caps, GST_DEBUG_PAD_NAME (realpad));
1448 gst_caps_debug (caps, "caps that we are trying to set");
1450 /* try to take ownership */
1451 gst_caps_ref (caps);
1452 gst_caps_sink (caps);
1454 /* setting non fixed caps on a pad is not allowed */
1455 if (!GST_CAPS_IS_FIXED (caps)) {
1456 GST_CAT_INFO (GST_CAT_CAPS,
1457 "trying to set unfixed caps on pad %s:%s, not allowed",
1458 GST_DEBUG_PAD_NAME (realpad));
1459 g_warning ("trying to set non fixed caps on pad %s:%s, not allowed",
1460 GST_DEBUG_PAD_NAME (realpad));
1462 gst_caps_debug (caps, "unfixed caps");
1463 set_retval = GST_PAD_LINK_DELAYED;
1467 /* if we have a peer try to set the caps, notifying the peerpad
1468 * if it has a link function */
1469 if (peer && ((set_retval = gst_pad_try_set_caps_func (peer, caps, TRUE)) <= 0))
1471 GST_CAT_INFO (GST_CAT_CAPS, "tried to set caps on peerpad %s:%s but couldn't, return value %d",
1472 GST_DEBUG_PAD_NAME (peer), set_retval);
1476 /* then try to set our own caps, we don't need to be notified */
1477 if ((set_retval = gst_pad_try_set_caps_func (realpad, caps, FALSE)) <= 0)
1479 GST_CAT_INFO (GST_CAT_CAPS, "tried to set own caps on pad %s:%s but couldn't, return value %d",
1480 GST_DEBUG_PAD_NAME (realpad), set_retval);
1483 GST_CAT_INFO (GST_CAT_CAPS, "succeeded setting caps %p on pad %s:%s, return value %d",
1484 caps, GST_DEBUG_PAD_NAME (realpad), set_retval);
1485 g_assert (GST_PAD_CAPS (pad));
1488 /* if we took ownership, the caps will be freed */
1489 gst_caps_unref (caps);
1494 /* this is a caps negotiation convenience routine, it:
1496 * 1. optionally clears any pad caps.
1497 * 2. calculates the intersection between the two pad tamplate/getcaps caps.
1498 * 3. calculates the intersection with the (optional) filtercaps.
1499 * 4. stores the intersection in the pad filter.
1500 * 5. stores the app filtercaps in the pad appfilter.
1501 * 6. starts the caps negotiation.
1504 gst_pad_try_relink_filtered_func (GstRealPad *srcpad, GstRealPad *sinkpad,
1505 GstCaps *filtercaps, gboolean clear)
1507 GstCaps *srccaps, *sinkcaps;
1508 GstCaps *intersection = NULL;
1509 GstRealPad *realsrc, *realsink;
1511 realsrc = GST_PAD_REALIZE (srcpad);
1512 realsink = GST_PAD_REALIZE (sinkpad);
1514 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1515 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1517 /* optinally clear the caps */
1519 GST_CAT_INFO (GST_CAT_PADS,
1520 "start relink filtered %s:%s and %s:%s, clearing caps",
1521 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1523 gst_caps_replace (&GST_PAD_CAPS (GST_PAD (realsrc)), NULL);
1524 gst_caps_replace (&GST_PAD_CAPS (GST_PAD (realsink)), NULL);
1525 gst_caps_replace (&GST_RPAD_FILTER (realsrc), NULL);
1526 gst_caps_replace (&GST_RPAD_FILTER (realsink), NULL);
1529 GST_CAT_INFO (GST_CAT_PADS, "start relink filtered %s:%s and %s:%s",
1530 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1533 srccaps = gst_pad_get_caps (GST_PAD (realsrc));
1534 GST_CAT_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1535 GST_DEBUG_PAD_NAME (realsrc));
1536 gst_caps_debug (srccaps, "caps of src pad (pre-relink)");
1537 sinkcaps = gst_pad_get_caps (GST_PAD (realsink));
1538 GST_CAT_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1539 GST_DEBUG_PAD_NAME (realsink));
1540 gst_caps_debug (sinkcaps, "caps of sink pad (pre-relink)");
1542 /* first take the intersection of the pad caps */
1543 intersection = gst_caps_intersect (srccaps, sinkcaps);
1544 gst_caps_debug (intersection, "caps of intersection");
1546 /* if we have no intersection but one of the caps was not NULL.. */
1547 if (!intersection && (srccaps || sinkcaps)) {
1548 /* the intersection is NULL but the pad caps were not both NULL,
1549 * this means they have no common format */
1550 GST_CAT_INFO (GST_CAT_PADS, "pads %s:%s and %s:%s have no common type",
1551 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1552 /* make sure any floating caps from gst_pad_get_caps are freed here */
1553 gst_caps_sink (srccaps);
1554 gst_caps_sink (sinkcaps);
1557 GST_CAT_INFO (GST_CAT_PADS, "pads %s:%s and %s:%s intersected to %s caps",
1558 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink),
1560 (GST_CAPS_IS_FIXED (intersection) ? "fixed" : "variable") :
1563 /* we don't need those anymore, as the caps can be floating */
1564 gst_caps_sink (srccaps);
1565 gst_caps_sink (sinkcaps);
1567 /* then filter this against the app filter */
1569 GstCaps *filtered_intersection;
1571 filtered_intersection = gst_caps_intersect (intersection,
1574 gst_caps_sink (intersection);
1576 if (!filtered_intersection) {
1577 GST_CAT_INFO (GST_CAT_PADS,
1578 "filtered link between pads %s:%s and %s:%s is empty",
1579 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1582 intersection = filtered_intersection;
1584 /* keep a reference to the app caps */
1585 gst_caps_replace_sink (&GST_RPAD_APPFILTER (realsink), filtercaps);
1586 gst_caps_replace_sink (&GST_RPAD_APPFILTER (realsrc), filtercaps);
1589 GST_CAT_DEBUG (GST_CAT_CAPS, "setting filter for link to:");
1590 gst_caps_debug (intersection, "filter for link");
1592 /* both the app filter and the filter, while stored on both peer pads,
1593 * are equal to the same thing on both */
1594 gst_caps_replace_sink (&GST_RPAD_FILTER (realsrc), intersection);
1595 gst_caps_replace_sink (&GST_RPAD_FILTER (realsink), intersection);
1596 gst_caps_sink (intersection);
1598 return gst_pad_perform_negotiate (GST_PAD (realsrc), GST_PAD (realsink));
1602 * gst_pad_perform_negotiate:
1603 * @srcpad: the source #GstPad.
1604 * @sinkpad: the sink #GstPad.
1606 * Tries to negotiate the pads.
1608 * Returns: TRUE if the pads were succesfully negotiated, FALSE otherwise.
1611 gst_pad_perform_negotiate (GstPad *srcpad, GstPad *sinkpad)
1613 GstCaps *intersection, *filtered_intersection;
1614 GstRealPad *realsrc, *realsink;
1615 GstCaps *srccaps, *sinkcaps, *filter;
1616 gboolean res = TRUE;
1620 g_return_val_if_fail (srcpad != NULL, FALSE);
1621 g_return_val_if_fail (sinkpad != NULL, FALSE);
1623 realsrc = GST_PAD_REALIZE (srcpad);
1624 realsink = GST_PAD_REALIZE (sinkpad);
1626 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1627 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1629 /* shortcut negotiation */
1630 parent = GST_PAD_PARENT (realsrc);
1631 if (parent && GST_STATE (parent) < GST_STATE_READY) {
1632 GST_CAT_DEBUG (GST_CAT_CAPS, "parent %s of pad %s:%s is not READY",
1633 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (realsrc));
1636 parent = GST_PAD_PARENT (realsink);
1637 if (parent && GST_STATE (parent) < GST_STATE_READY) {
1638 GST_CAT_DEBUG (GST_CAT_CAPS, "parent %s of pad %s:%s is not READY",
1639 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (realsink));
1643 GST_CAT_INFO (GST_CAT_PADS, "perform negotiate for link %s:%s-%s:%s",
1644 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1646 filter = GST_RPAD_APPFILTER (realsrc);
1648 GST_CAT_INFO (GST_CAT_PADS, "dumping filter for link %s:%s-%s:%s",
1649 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1650 gst_caps_debug (filter, "link filter caps");
1653 /* calculate the new caps here */
1654 srccaps = gst_pad_get_caps (GST_PAD (realsrc));
1655 GST_CAT_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1656 GST_DEBUG_PAD_NAME (realsrc));
1657 gst_caps_debug (srccaps,
1658 "src caps, awaiting negotiation, after applying filter");
1659 sinkcaps = gst_pad_get_caps (GST_PAD (realsink));
1660 GST_CAT_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1661 GST_DEBUG_PAD_NAME (realsink));
1662 gst_caps_debug (sinkcaps,
1663 "sink caps, awaiting negotiation, after applying filter");
1664 intersection = gst_caps_intersect (srccaps, sinkcaps);
1665 filtered_intersection = gst_caps_intersect (intersection, filter);
1666 gst_caps_unref (intersection);
1668 /* no negotiation is performed if the pads have filtercaps */
1669 if (filtered_intersection) {
1670 GstPadLinkReturn link_res;
1672 link_res = gst_pad_try_set_caps_func (realsrc, filtered_intersection, TRUE);
1673 if (link_res == GST_PAD_LINK_REFUSED)
1675 if (link_res == GST_PAD_LINK_DONE)
1678 link_res = gst_pad_try_set_caps_func (realsink, filtered_intersection, TRUE);
1679 if (link_res == GST_PAD_LINK_REFUSED)
1681 if (link_res == GST_PAD_LINK_DONE)
1684 /* no filtered_intersection, some pads had caps and ther was a filter */
1685 else if ((srccaps || sinkcaps) && filter) {
1691 gst_caps_sink (srccaps);
1692 gst_caps_sink (sinkcaps);
1693 gst_caps_unref (filtered_intersection);
1702 * gst_pad_try_relink_filtered:
1703 * @srcpad: the source #GstPad to relink.
1704 * @sinkpad: the sink #GstPad to relink.
1705 * @filtercaps: the #GstPad to use as a filter in the relink.
1707 * Tries to relink the given source and sink pad, constrained by the given
1710 * Returns: TRUE if the pads were succesfully renegotiated, FALSE otherwise.
1713 gst_pad_try_relink_filtered (GstPad *srcpad, GstPad *sinkpad,
1714 GstCaps *filtercaps)
1716 GstRealPad *realsrc, *realsink;
1718 g_return_val_if_fail (srcpad != NULL, FALSE);
1719 g_return_val_if_fail (sinkpad != NULL, FALSE);
1721 realsrc = GST_PAD_REALIZE (srcpad);
1722 realsink = GST_PAD_REALIZE (sinkpad);
1724 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1725 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1727 return gst_pad_try_relink_filtered_func (realsrc, realsink,
1732 * gst_pad_relink_filtered:
1733 * @srcpad: the source #GstPad to relink.
1734 * @sinkpad: the sink #GstPad to relink.
1735 * @filtercaps: the #GstPad to use as a filter in the relink.
1737 * Relinks the given source and sink pad, constrained by the given
1738 * capabilities. If the relink fails, the pads are unlinked
1739 * and FALSE is returned.
1741 * Returns: TRUE if the pads were succesfully relinked, FALSE otherwise.
1744 gst_pad_relink_filtered (GstPad *srcpad, GstPad *sinkpad,
1745 GstCaps *filtercaps)
1747 GstRealPad *realsrc, *realsink;
1749 g_return_val_if_fail (srcpad != NULL, FALSE);
1750 g_return_val_if_fail (sinkpad != NULL, FALSE);
1752 realsrc = GST_PAD_REALIZE (srcpad);
1753 realsink = GST_PAD_REALIZE (sinkpad);
1755 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1756 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1758 if (!gst_pad_try_relink_filtered_func (realsrc, realsink,
1761 gst_pad_unlink (srcpad, GST_PAD (GST_PAD_PEER (srcpad)));
1768 * gst_pad_proxy_link:
1769 * @pad: a #GstPad to proxy to.
1770 * @caps: the #GstCaps to use in proxying.
1772 * Proxies the link function to the specified pad.
1774 * Returns: TRUE if the peer pad accepted the caps, FALSE otherwise.
1777 gst_pad_proxy_link (GstPad *pad, GstCaps *caps)
1779 GstRealPad *peer, *realpad;
1781 realpad = GST_PAD_REALIZE (pad);
1783 peer = GST_RPAD_PEER (realpad);
1785 GST_CAT_INFO (GST_CAT_CAPS, "proxy link to pad %s:%s",
1786 GST_DEBUG_PAD_NAME (realpad));
1788 if (peer && gst_pad_try_set_caps_func (peer, caps, TRUE) < 0)
1789 return GST_PAD_LINK_REFUSED;
1790 if (gst_pad_try_set_caps_func (realpad, caps, FALSE) < 0)
1791 return GST_PAD_LINK_REFUSED;
1794 gst_caps_debug (caps, "proxy link filter");
1796 GST_CAT_INFO (GST_CAT_CAPS, "setting filter on %s:%s and %s:%s",
1797 GST_DEBUG_PAD_NAME (peer), GST_DEBUG_PAD_NAME (realpad));
1799 gst_caps_replace_sink (&GST_RPAD_FILTER (peer), caps);
1800 gst_caps_replace_sink (&GST_RPAD_FILTER (realpad), caps);
1803 return GST_PAD_LINK_OK;
1808 * @pad: a #GstPad to get the capabilities of.
1810 * Gets the capabilities of this pad.
1812 * Returns: the #GstCaps of this pad. This function potentially
1813 * returns a floating caps, so use gst_caps_sink to get rid of
1817 gst_pad_get_caps (GstPad *pad)
1819 GstRealPad *realpad;
1821 g_return_val_if_fail (pad != NULL, NULL);
1822 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1824 realpad = GST_PAD_REALIZE (pad);
1826 GST_CAT_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1827 GST_DEBUG_PAD_NAME (realpad), realpad);
1829 /* note that we will not _ref the caps here as this function might be
1830 * called recursively */
1831 if (GST_PAD_CAPS (realpad)) {
1832 GST_CAT_DEBUG (GST_CAT_CAPS, "using pad real caps %p", GST_PAD_CAPS (realpad));
1833 return GST_PAD_CAPS (realpad);
1835 else if GST_RPAD_GETCAPSFUNC (realpad) {
1836 GST_CAT_DEBUG (GST_CAT_CAPS, "using pad get function");
1837 return GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD_CAST (realpad), NULL);
1839 else if (GST_PAD_PAD_TEMPLATE (realpad)) {
1840 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (realpad);
1841 GST_CAT_DEBUG (GST_CAT_CAPS, "using pad template %p with caps %p",
1842 templ, GST_PAD_TEMPLATE_CAPS (templ));
1843 return GST_PAD_TEMPLATE_CAPS (templ);
1845 GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
1851 * gst_pad_get_pad_template_caps:
1852 * @pad: a #GstPad to get the template capabilities from.
1854 * Gets the template capabilities of this pad.
1856 * Returns: the template #GstCaps of this pad, unref the caps
1857 * if you no longer need it.
1860 gst_pad_get_pad_template_caps (GstPad *pad)
1862 g_return_val_if_fail (pad != NULL, NULL);
1863 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1865 if (GST_PAD_PAD_TEMPLATE (pad))
1866 return gst_caps_ref (GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad)));
1872 * gst_pad_template_get_caps_by_name:
1873 * @templ: a #GstPadTemplate to get the capabilities of.
1874 * @name: the name of the capability to get.
1876 * Gets the capability with the given name from this pad template.
1878 * Returns: the #GstCaps, or NULL if not found or in case of an error. unref
1879 * the caps if you no longer need it.
1882 gst_pad_template_get_caps_by_name (GstPadTemplate *templ, const gchar *name)
1886 g_return_val_if_fail (templ != NULL, NULL);
1888 caps = GST_PAD_TEMPLATE_CAPS (templ);
1892 return gst_caps_ref (gst_caps_get_by_name (caps, name));
1896 * gst_pad_check_compatibility:
1897 * @srcpad: the source #GstPad to check.
1898 * @sinkpad: the sink #GstPad to check against.
1900 * Checks if two pads have compatible capabilities.
1902 * Returns: TRUE if they are compatible or if the capabilities
1903 * could not be checked
1906 gst_pad_check_compatibility (GstPad *srcpad, GstPad *sinkpad)
1908 g_return_val_if_fail (srcpad != NULL, FALSE);
1909 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1910 g_return_val_if_fail (sinkpad != NULL, FALSE);
1911 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1913 if (GST_PAD_CAPS (srcpad) && GST_PAD_CAPS (sinkpad)) {
1914 if (!gst_caps_is_always_compatible (GST_PAD_CAPS (srcpad),
1915 GST_PAD_CAPS (sinkpad))) {
1923 GST_CAT_DEBUG (GST_CAT_PADS,
1924 "could not check capabilities of pads (%s:%s) and (%s:%s) %p %p",
1925 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
1926 GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad));
1933 * @pad: a #GstPad to get the peer of.
1935 * Gets the peer pad of this pad.
1937 * Returns: the peer #GstPad.
1940 gst_pad_get_peer (GstPad *pad)
1942 g_return_val_if_fail (pad != NULL, NULL);
1943 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1945 return GST_PAD (GST_PAD_PEER (pad));
1949 * gst_pad_get_allowed_caps:
1950 * @pad: a #GstPad to get the allowed caps of.
1952 * Gets the capabilities of the allowed media types that can
1953 * flow through this pad. The caller must free the resulting caps.
1955 * Returns: the allowed #GstCaps of the pad link. unref the caps if
1956 * you no longer need it.
1959 gst_pad_get_allowed_caps (GstPad *pad)
1962 GstRealPad *realpad;
1964 g_return_val_if_fail (pad != NULL, NULL);
1965 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1967 realpad = GST_PAD_REALIZE (pad);
1969 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "get allowed caps of %s:%s",
1970 GST_DEBUG_PAD_NAME (pad));
1972 caps = gst_caps_ref (GST_RPAD_FILTER (realpad));
1978 * gst_pad_recalc_allowed_caps:
1979 * @pad: a #GstPad to recalculate the capablities of.
1981 * Attempts to relink the pad to its peer through its filter,
1982 * set with gst_pad_[re]link_filtered. This function is useful when a
1983 * plug-in has new capabilities on a pad and wants to notify the peer.
1985 * Returns: TRUE on success, FALSE otherwise.
1988 gst_pad_recalc_allowed_caps (GstPad *pad)
1992 g_return_val_if_fail (pad != NULL, FALSE);
1993 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1995 GST_CAT_DEBUG (GST_CAT_PROPERTIES, "set allowed caps of %s:%s",
1996 GST_DEBUG_PAD_NAME (pad));
1999 peer = GST_RPAD_PEER (pad);
2001 return gst_pad_try_relink_filtered (pad, GST_PAD (peer),
2002 GST_RPAD_APPFILTER (pad));
2008 * gst_pad_recover_caps_error:
2009 * @pad: a #GstPad that had a failed capsnego
2010 * @allowed: possible caps for the link
2012 * Attempt to recover from a failed caps negotiation. This function
2013 * is typically called by a plugin that exhausted its list of caps
2014 * and wants the application to resolve the issue. The application
2015 * should connect to the pad's caps_nego_failed signal and should
2016 * resolve the issue by connecting another element for example.
2018 * Returns: TRUE when the issue was resolved, dumps detailed information
2019 * on the console and returns FALSE otherwise.
2022 gst_pad_recover_caps_error (GstPad *pad, GstCaps *allowed)
2026 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2028 /* see if someone can resolve this */
2029 if (g_signal_has_handler_pending (G_OBJECT (pad),
2030 gst_real_pad_signals[REAL_CAPS_NEGO_FAILED], 0, FALSE))
2032 /* clear pad caps first */
2033 gst_caps_replace (&GST_PAD_CAPS (pad), NULL);
2035 /* lets hope some signal manages to set the caps again */
2036 g_signal_emit (G_OBJECT (pad), gst_real_pad_signals[REAL_CAPS_NEGO_FAILED], 0, allowed);
2038 /* if the pad has caps now or is disabled, it's ok */
2039 if (GST_PAD_CAPS (pad) != NULL || !GST_PAD_IS_ACTIVE (pad))
2044 parent = gst_pad_get_parent (pad);
2045 gst_element_error (parent, "negotiation failed on pad %s:%s",
2046 GST_DEBUG_PAD_NAME (pad));
2052 * gst_pad_get_bufferpool:
2053 * @pad: a #GstPad to get the bufferpool from.
2055 * Gets the bufferpool of the peer pad of the given pad.Note that
2056 * a bufferpool can only be obtained from a srcpad.
2058 * Returns: the #GstBufferPool, or NULL in case of an error.
2061 gst_pad_get_bufferpool (GstPad *pad)
2065 g_return_val_if_fail (pad != NULL, NULL);
2066 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2067 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
2069 peer = GST_RPAD_PEER (pad);
2074 GST_CAT_DEBUG (GST_CAT_BUFFER, "(%s:%s): getting bufferpool", GST_DEBUG_PAD_NAME (pad));
2076 if (peer->bufferpoolfunc) {
2077 GST_CAT_DEBUG (GST_CAT_PADS,
2078 "calling bufferpoolfunc &%s (@%p) of peer pad %s:%s",
2079 GST_DEBUG_FUNCPTR_NAME (peer->bufferpoolfunc),
2080 &peer->bufferpoolfunc, GST_DEBUG_PAD_NAME (((GstPad*) peer)));
2081 return (peer->bufferpoolfunc) (((GstPad*) peer));
2083 GST_CAT_DEBUG (GST_CAT_PADS, "no bufferpoolfunc for peer pad %s:%s at %p",
2084 GST_DEBUG_PAD_NAME (((GstPad*) peer)), &peer->bufferpoolfunc);
2090 gst_real_pad_dispose (GObject *object)
2092 GstPad *pad = GST_PAD (object);
2094 /* No linked pad can ever be disposed.
2095 * It has to have a parent to be linked
2096 * and a parent would hold a reference */
2097 g_assert (GST_PAD_PEER (pad) == NULL);
2099 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s", GST_DEBUG_PAD_NAME(pad));
2101 /* we destroy the ghostpads, because they are nothing without the real pad */
2102 if (GST_REAL_PAD (pad)->ghostpads) {
2103 GList *orig, *ghostpads;
2105 orig = ghostpads = g_list_copy (GST_REAL_PAD (pad)->ghostpads);
2108 GstPad *ghostpad = GST_PAD (ghostpads->data);
2110 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))){
2111 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "removing ghost pad from element '%s'",
2112 GST_OBJECT_NAME (GST_OBJECT_PARENT (ghostpad)));
2114 gst_element_remove_ghost_pad (GST_ELEMENT (GST_OBJECT_PARENT (ghostpad)), GST_PAD (ghostpad));
2116 ghostpads = g_list_next (ghostpads);
2119 g_list_free (GST_REAL_PAD(pad)->ghostpads);
2122 gst_caps_replace (&GST_PAD_CAPS (pad), NULL);
2123 gst_caps_replace (&GST_RPAD_APPFILTER (pad), NULL);
2125 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
2126 GST_CAT_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
2127 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
2129 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
2132 G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
2136 #ifndef GST_DISABLE_LOADSAVE
2137 /* FIXME: why isn't this on a GstElement ? */
2139 * gst_pad_load_and_link:
2140 * @self: an #xmlNodePtr to read the description from.
2141 * @parent: the #GstObject element that owns the pad.
2143 * Reads the pad definition from the XML node and links the given pad
2144 * in the element to a pad of an element up in the hierarchy.
2147 gst_pad_load_and_link (xmlNodePtr self, GstObject *parent)
2149 xmlNodePtr field = self->xmlChildrenNode;
2150 GstPad *pad = NULL, *targetpad;
2154 GstObject *grandparent;
2157 if (!strcmp (field->name, "name")) {
2158 pad = gst_element_get_pad (GST_ELEMENT (parent),
2159 xmlNodeGetContent (field));
2161 else if (!strcmp(field->name, "peer")) {
2162 peer = xmlNodeGetContent (field);
2164 field = field->next;
2166 g_return_if_fail (pad != NULL);
2168 if (peer == NULL) return;
2170 split = g_strsplit (peer, ".", 2);
2172 if (split[0] == NULL || split[1] == NULL) {
2173 GST_CAT_DEBUG (GST_CAT_XML,
2174 "Could not parse peer '%s' for pad %s:%s, leaving unlinked",
2175 peer, GST_DEBUG_PAD_NAME (pad));
2179 g_return_if_fail (split[0] != NULL);
2180 g_return_if_fail (split[1] != NULL);
2182 grandparent = gst_object_get_parent (parent);
2184 if (grandparent && GST_IS_BIN (grandparent)) {
2185 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2190 if (target == NULL) goto cleanup;
2192 targetpad = gst_element_get_pad (target, split[1]);
2194 if (targetpad == NULL) goto cleanup;
2196 gst_pad_link (pad, targetpad);
2203 * gst_pad_save_thyself:
2204 * @pad: a #GstPad to save.
2205 * @parent: the parent #xmlNodePtr to save the description in.
2207 * Saves the pad into an xml representation.
2209 * Returns: the #xmlNodePtr representation of the pad.
2212 gst_pad_save_thyself (GstObject *object, xmlNodePtr parent)
2214 GstRealPad *realpad;
2217 g_return_val_if_fail (GST_IS_REAL_PAD (object), NULL);
2219 realpad = GST_REAL_PAD (object);
2221 xmlNewChild (parent, NULL, "name", GST_PAD_NAME (realpad));
2222 if (GST_RPAD_PEER (realpad) != NULL) {
2225 peer = GST_PAD (GST_RPAD_PEER (realpad));
2226 /* first check to see if the peer's parent's parent is the same */
2227 /* we just save it off */
2228 content = g_strdup_printf ("%s.%s",
2229 GST_OBJECT_NAME (GST_PAD_PARENT (peer)),
2230 GST_PAD_NAME (peer));
2231 xmlNewChild (parent, NULL, "peer", content);
2234 xmlNewChild (parent, NULL, "peer", "");
2239 /* FIXME: shouldn't pad and ghost be switched ?
2242 * gst_ghost_pad_save_thyself:
2243 * @pad: a ghost #GstPad to save.
2244 * @parent: the parent #xmlNodePtr to save the description in.
2246 * Saves the ghost pad into an xml representation.
2248 * Returns: the #xmlNodePtr representation of the pad.
2251 gst_ghost_pad_save_thyself (GstPad *pad, xmlNodePtr parent)
2255 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2257 self = xmlNewChild (parent, NULL, "ghostpad", NULL);
2258 xmlNewChild (self, NULL, "name", GST_PAD_NAME (pad));
2259 xmlNewChild (self, NULL, "parent", GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
2261 /* FIXME FIXME FIXME! */
2265 #endif /* GST_DISABLE_LOADSAVE */
2269 * @pad: a #GstPad to push the buffer out of.
2270 * @buf: the #GstBuffer to push.
2272 * Pushes a buffer to the peer of the pad.
2275 gst_pad_push (GstPad *pad, GstBuffer *buf)
2278 GstData *data = GST_DATA(buf);
2280 g_assert (GST_IS_PAD (pad));
2281 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad, "pushing");
2283 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
2285 if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), &data))
2288 peer = GST_RPAD_PEER (pad);
2291 g_warning ("push on pad %s:%s but it is unlinked",
2292 GST_DEBUG_PAD_NAME (pad));
2295 if (!GST_IS_EVENT (data) && !GST_PAD_IS_ACTIVE (pad)) {
2296 g_warning ("push on pad %s:%s but it is not active",
2297 GST_DEBUG_PAD_NAME (pad));
2301 if (peer->chainhandler) {
2303 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad,
2304 "calling chainhandler &%s of peer pad %s:%s",
2305 GST_DEBUG_FUNCPTR_NAME (peer->chainhandler),
2306 GST_DEBUG_PAD_NAME (GST_PAD (peer)));
2307 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
2310 (peer->chainhandler) (GST_PAD_CAST (peer), (GstBuffer *)data);
2314 g_warning ("trying to push a NULL buffer on pad %s:%s",
2315 GST_DEBUG_PAD_NAME (peer));
2320 g_warning ("internal error: push on pad %s:%s but it has no chainhandler",
2321 GST_DEBUG_PAD_NAME (peer));
2324 /* clean up the mess here */
2325 if (data != NULL) gst_data_unref (data);
2330 * @pad: a #GstPad to pull a buffer from.
2332 * Pulls a buffer from the peer pad.
2334 * Returns: a new #GstBuffer from the peer pad.
2337 gst_pad_pull (GstPad *pad)
2341 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad, "pulling");
2343 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK,
2344 GST_BUFFER (gst_event_new (GST_EVENT_INTERRUPT)));
2346 peer = GST_RPAD_PEER (pad);
2349 gst_element_error (GST_PAD_PARENT (pad),
2350 "pull on pad %s:%s but it was unlinked",
2351 GST_ELEMENT_NAME (GST_PAD_PARENT (pad)),
2352 GST_PAD_NAME (pad), NULL);
2356 if (peer->gethandler) {
2359 GST_CAT_LOG_OBJECT (GST_CAT_DATAFLOW, pad,
2360 "calling gethandler %s of peer pad %s:%s",
2361 GST_DEBUG_FUNCPTR_NAME (peer->gethandler),
2362 GST_DEBUG_PAD_NAME (peer));
2364 data = GST_DATA((peer->gethandler) (GST_PAD_CAST (peer)));
2367 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, &data))
2369 return GST_BUFFER(data);
2372 /* no null buffers allowed */
2373 gst_element_error (GST_PAD_PARENT (pad),
2374 "NULL buffer during pull on %s:%s",
2375 GST_DEBUG_PAD_NAME (pad));
2378 gst_element_error (GST_PAD_PARENT (pad),
2379 "internal error: pull on pad %s:%s "
2380 "but the peer pad %s:%s has no gethandler",
2381 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer));
2384 return GST_BUFFER (gst_event_new (GST_EVENT_INTERRUPT));
2389 * @padlist: a #GList of pads.
2391 * Waits for a buffer on any of the list of pads.
2393 * Returns: the #GstPad that has a buffer available.
2394 * Use #gst_pad_pull() to get the buffer.
2397 gst_pad_select (GList *padlist)
2401 pad = gst_scheduler_pad_select (GST_PAD_PARENT (padlist->data)->sched,
2408 * @pad: a first #GstPad to perform the select on.
2409 * @...: A NULL-terminated list of more pads to select on.
2411 * Waits for a buffer on the given set of pads.
2413 * Returns: the #GstPad that has a buffer available.
2414 * Use #gst_pad_pull() to get the buffer.
2417 gst_pad_selectv (GstPad *pad, ...)
2420 GList *padlist = NULL;
2426 va_start (var_args, pad);
2429 padlist = g_list_prepend (padlist, pad);
2430 pad = va_arg (var_args, GstPad *);
2432 result = gst_pad_select (padlist);
2433 g_list_free (padlist);
2440 /************************************************************************
2445 static void gst_pad_template_class_init (GstPadTemplateClass *klass);
2446 static void gst_pad_template_init (GstPadTemplate *templ);
2447 static void gst_pad_template_dispose (GObject *object);
2450 gst_pad_template_get_type (void)
2452 static GType padtemplate_type = 0;
2454 if (!padtemplate_type) {
2455 static const GTypeInfo padtemplate_info = {
2456 sizeof (GstPadTemplateClass), NULL, NULL,
2457 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
2458 sizeof (GstPadTemplate),
2460 (GInstanceInitFunc) gst_pad_template_init, NULL
2462 padtemplate_type = g_type_register_static(GST_TYPE_OBJECT, "GstPadTemplate",
2463 &padtemplate_info, 0);
2465 return padtemplate_type;
2469 gst_pad_template_class_init (GstPadTemplateClass *klass)
2471 GObjectClass *gobject_class;
2472 GstObjectClass *gstobject_class;
2474 gobject_class = (GObjectClass*) klass;
2475 gstobject_class = (GstObjectClass*) klass;
2477 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
2479 gst_pad_template_signals[TEMPL_PAD_CREATED] =
2480 g_signal_new ("pad_created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
2481 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
2482 NULL, NULL, gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
2485 gobject_class->dispose = gst_pad_template_dispose;
2487 gstobject_class->path_string_separator = "*";
2491 gst_pad_template_init (GstPadTemplate *templ)
2496 gst_pad_template_dispose (GObject *object)
2498 GstPadTemplate *templ = GST_PAD_TEMPLATE (object);
2500 g_free (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
2501 gst_caps_unref (GST_PAD_TEMPLATE_CAPS (templ));
2503 G_OBJECT_CLASS (padtemplate_parent_class)->dispose (object);
2506 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
2508 * SOMETIMES padtemplates can do whatever they want, they are provided by the
2510 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
2511 * 'sink%d' template is automatically selected), so we need to restrict their
2515 name_is_valid (const gchar *name, GstPadPresence presence)
2519 if (presence == GST_PAD_ALWAYS) {
2520 if (strchr (name, '%')) {
2521 g_warning ("invalid name template %s: conversion specifications are not"
2522 " allowed for GST_PAD_ALWAYS padtemplates", name);
2525 } else if (presence == GST_PAD_REQUEST) {
2526 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
2527 g_warning ("invalid name template %s: only one conversion specification"
2528 " allowed in GST_PAD_REQUEST padtemplate", name);
2531 if (str && (*(str+1) != 's' && *(str+1) != 'd')) {
2532 g_warning ("invalid name template %s: conversion specification must be of"
2533 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
2536 if (str && (*(str+2) != '\0')) {
2537 g_warning ("invalid name template %s: conversion specification must"
2538 " appear at the end of the GST_PAD_REQUEST padtemplate name",
2548 * gst_pad_template_newv:
2549 * @name_template: the name template.
2550 * @direction: the #GstPadDirection of the template.
2551 * @presence: the #GstPadPresence of the pad.
2552 * @caps: a #GstCaps set for the template.
2553 * @var_args: a NULL-terminated list of #GstCaps.
2555 * Creates a new pad template with a name according to the given template
2556 * and with the given arguments.
2558 * Returns: a new #GstPadTemplate.
2561 gst_pad_template_newv (const gchar *name_template,
2562 GstPadDirection direction, GstPadPresence presence,
2563 GstCaps *caps, va_list var_args)
2565 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 GST_FLAG_SET (GST_OBJECT (new), GST_PAD_TEMPLATE_FIXED);
2583 if (!GST_CAPS_IS_FIXED (caps)) {
2584 GST_FLAG_UNSET (GST_OBJECT (new), GST_PAD_TEMPLATE_FIXED);
2586 thecaps = gst_caps_append (thecaps, caps);
2587 caps = va_arg (var_args, GstCaps*);
2590 GST_PAD_TEMPLATE_CAPS (new) = thecaps;
2591 gst_caps_ref (thecaps);
2592 gst_caps_sink (thecaps);
2598 * gst_pad_template_new:
2599 * @name_template: the name template.
2600 * @direction: the #GstPadDirection of the template.
2601 * @presence: the #GstPadPresence of the pad.
2602 * @caps: a #GstCaps set for the template.
2603 * @...: a NULL-terminated list of #GstCaps.
2605 * Creates a new pad template with a name according to the given template
2606 * and with the given arguments.
2608 * Returns: a new #GstPadTemplate.
2611 gst_pad_template_new (const gchar *name_template,
2612 GstPadDirection direction, GstPadPresence presence,
2615 GstPadTemplate *new;
2618 va_start (var_args, caps);
2620 new = gst_pad_template_newv (name_template, direction, presence,
2629 * gst_pad_template_get_caps:
2630 * @templ: a #GstPadTemplate to get capabilities of.
2632 * Gets the capabilities of the pad template.
2634 * Returns: the #GstCaps of the pad template. unref the caps
2638 gst_pad_template_get_caps (GstPadTemplate *templ)
2640 g_return_val_if_fail (templ != NULL, NULL);
2642 return gst_caps_ref (GST_PAD_TEMPLATE_CAPS (templ));
2646 * gst_pad_set_element_private:
2647 * @pad: the #GstPad to set the private data of.
2648 * @priv: The private data to attach to the pad.
2650 * Set the given private data gpointer on the pad.
2651 * This function can only be used by the element that owns the pad.
2654 gst_pad_set_element_private (GstPad *pad, gpointer priv)
2656 pad->element_private = priv;
2660 * gst_pad_get_element_private:
2661 * @pad: the #GstPad to get the private data of.
2663 * Gets the private data of a pad.
2665 * Returns: a #gpointer to the private data.
2668 gst_pad_get_element_private (GstPad *pad)
2670 return pad->element_private;
2674 /***** ghost pads *****/
2675 GType _gst_ghost_pad_type = 0;
2677 static void gst_ghost_pad_class_init (GstGhostPadClass *klass);
2678 static void gst_ghost_pad_init (GstGhostPad *pad);
2679 static void gst_ghost_pad_dispose (GObject *object);
2681 static GstPad *ghost_pad_parent_class = NULL;
2682 /* static guint gst_ghost_pad_signals[LAST_SIGNAL] = { 0 }; */
2685 gst_ghost_pad_get_type (void)
2687 if (!_gst_ghost_pad_type) {
2688 static const GTypeInfo pad_info = {
2689 sizeof (GstGhostPadClass), NULL, NULL,
2690 (GClassInitFunc) gst_ghost_pad_class_init, NULL, NULL,
2691 sizeof (GstGhostPad),
2693 (GInstanceInitFunc) gst_ghost_pad_init,
2696 _gst_ghost_pad_type = g_type_register_static (GST_TYPE_PAD, "GstGhostPad",
2699 return _gst_ghost_pad_type;
2703 gst_ghost_pad_class_init (GstGhostPadClass *klass)
2705 GObjectClass *gobject_class;
2707 gobject_class = (GObjectClass*) klass;
2709 ghost_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
2711 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_ghost_pad_dispose);
2715 gst_ghost_pad_init (GstGhostPad *pad)
2717 /* zeroed by glib */
2720 gst_ghost_pad_dispose (GObject *object)
2722 GstGhostPad *pad = GST_GHOST_PAD (object);
2725 gst_pad_remove_ghost_pad((GstPad *) pad->realpad, (GstPad *) pad);
2727 G_OBJECT_CLASS (ghost_pad_parent_class)->dispose (object);
2731 * gst_ghost_pad_new:
2732 * @name: the name of the new ghost pad.
2733 * @pad: the #GstPad to create a ghost pad for.
2735 * Creates a new ghost pad associated with the given pad, and names it with
2736 * the given name. If name is NULL, a guaranteed unique name (across all
2737 * ghost pads) will be assigned (most likely of the form ghostpad%d).
2739 * Returns: a new ghost #GstPad, or NULL in case of an error.
2743 gst_ghost_pad_new (const gchar *name,
2746 GstGhostPad *ghostpad;
2747 GstRealPad *realpad;
2749 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2751 ghostpad = g_object_new (gst_ghost_pad_get_type () ,NULL);
2752 gst_pad_set_name (GST_PAD (ghostpad), name);
2754 realpad = (GstRealPad *) pad;
2756 while (!GST_IS_REAL_PAD (realpad)) {
2757 realpad = GST_PAD_REALIZE (realpad);
2759 GST_GPAD_REALPAD (ghostpad) = realpad;
2760 gst_pad_set_pad_template (GST_PAD (ghostpad), GST_PAD_PAD_TEMPLATE (pad));
2762 /* add ourselves to the real pad's list of ghostpads */
2763 gst_pad_add_ghost_pad (pad, GST_PAD (ghostpad));
2765 /* FIXME need to ref the real pad here... ? */
2767 GST_CAT_DEBUG (GST_CAT_PADS, "created ghost pad \"%s\"",
2768 gst_pad_get_name (GST_PAD (ghostpad)));
2770 return GST_PAD (ghostpad);
2774 * gst_pad_get_internal_links_default:
2775 * @pad: the #GstPad to get the internal links of.
2777 * Gets a list of pads to which the given pad is linked to
2778 * inside of the parent element.
2779 * This is the default handler, and thus returns a list of all of the
2780 * pads inside the parent element with opposite direction.
2781 * The caller must free this list after use.
2783 * Returns: a newly allocated #GList of pads.
2786 gst_pad_get_internal_links_default (GstPad *pad)
2791 GstPadDirection direction;
2794 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2796 rpad = GST_PAD_REALIZE (pad);
2797 direction = rpad->direction;
2799 parent = GST_PAD_PARENT (rpad);
2800 parent_pads = parent->pads;
2802 while (parent_pads) {
2803 GstRealPad *parent_pad = GST_PAD_REALIZE (parent_pads->data);
2805 if (parent_pad->direction != direction) {
2806 res = g_list_prepend (res, parent_pad);
2809 parent_pads = g_list_next (parent_pads);
2816 * gst_pad_get_internal_links:
2817 * @pad: the #GstPad to get the internal links of.
2819 * Gets a list of pads to which the given pad is linked to
2820 * inside of the parent element.
2821 * The caller must free this list after use.
2823 * Returns: a newly allocated #GList of pads.
2826 gst_pad_get_internal_links (GstPad *pad)
2831 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2833 rpad = GST_PAD_REALIZE (pad);
2835 if (GST_RPAD_INTLINKFUNC (rpad))
2836 res = GST_RPAD_INTLINKFUNC (rpad) (GST_PAD_CAST (rpad));
2843 gst_pad_event_default_dispatch (GstPad *pad, GstElement *element,
2848 orig = pads = gst_pad_get_internal_links (pad);
2851 GstPad *eventpad = GST_PAD (pads->data);
2852 pads = g_list_next (pads);
2854 /* for all pads in the opposite direction that are linked */
2855 if (GST_PAD_IS_LINKED (eventpad)) {
2856 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
2857 /* increase the refcount */
2858 gst_event_ref (event);
2859 gst_pad_push (eventpad, GST_BUFFER (event));
2862 GstPad *peerpad = GST_PAD_CAST (GST_RPAD_PEER (eventpad));
2864 /* we only send the event on one pad, multi-sinkpad elements
2865 * should implement a handler */
2867 return gst_pad_send_event (peerpad, event);
2871 gst_event_unref (event);
2877 * gst_pad_event_default:
2878 * @pad: a #GstPad to call the default event handler on.
2879 * @event: the #GstEvent to handle.
2881 * Invokes the default event handler for the given pad.
2883 * Returns: TRUE if the event was sent succesfully.
2886 gst_pad_event_default (GstPad *pad, GstEvent *event)
2888 GstElement *element;
2890 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2891 g_return_val_if_fail (event, FALSE);
2893 element = GST_PAD_PARENT (pad);
2895 switch (GST_EVENT_TYPE (event)) {
2897 gst_pad_event_default_dispatch (pad, element, event);
2898 gst_element_set_eos (element);
2900 case GST_EVENT_DISCONTINUOUS:
2904 if (gst_event_discont_get_value (event, GST_FORMAT_TIME, &time)) {
2905 if (gst_element_requires_clock (element) && element->clock) {
2906 gst_clock_handle_discont (element->clock, time);
2910 case GST_EVENT_FLUSH:
2912 return gst_pad_event_default_dispatch (pad, element, event);
2918 * gst_pad_dispatcher:
2919 * @pad: a #GstPad to dispatch.
2920 * @dispatch: the #GstDispatcherFunction to call.
2921 * @data: gpointer user data passed to the dispatcher function.
2923 * Invokes the given dispatcher function on all pads that are
2924 * internally linked to the given pad.
2925 * The GstPadDispatcherFunction should return TRUE when no further pads
2926 * need to be processed.
2928 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2931 gst_pad_dispatcher (GstPad *pad, GstPadDispatcherFunction dispatch,
2934 gboolean res = FALSE;
2935 GList *int_pads, *orig;
2937 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2938 g_return_val_if_fail (data, FALSE);
2940 orig = int_pads = gst_pad_get_internal_links (pad);
2943 GstRealPad *int_rpad = GST_PAD_REALIZE (int_pads->data);
2944 GstRealPad *int_peer = GST_RPAD_PEER (int_rpad);
2947 res = dispatch (GST_PAD_CAST (int_peer), data);
2951 int_pads = g_list_next (int_pads);
2960 * gst_pad_send_event:
2961 * @pad: a #GstPad to send the event to.
2962 * @event: the #GstEvent to send to the pad.
2964 * Sends the event to the pad.
2966 * Returns: TRUE if the event was handled.
2969 gst_pad_send_event (GstPad *pad, GstEvent *event)
2971 gboolean success = FALSE;
2974 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2975 g_return_val_if_fail (event, FALSE);
2977 rpad = GST_PAD_REALIZE (pad);
2979 if (GST_EVENT_SRC (event) == NULL)
2980 GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (rpad));
2982 GST_CAT_DEBUG (GST_CAT_EVENT, "have event %d on pad %s:%s",
2983 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (rpad));
2985 if (GST_RPAD_EVENTHANDLER (rpad))
2986 success = GST_RPAD_EVENTHANDLER (rpad) (GST_PAD_CAST (rpad), event);
2988 GST_CAT_DEBUG (GST_CAT_EVENT, "there's no event function for pad %s:%s",
2989 GST_DEBUG_PAD_NAME (rpad));
2990 gst_event_unref (event);
2998 GstFormat src_format;
3000 GstFormat *dest_format;
3002 } GstPadConvertData;
3005 gst_pad_convert_dispatcher (GstPad *pad, GstPadConvertData *data)
3007 return gst_pad_convert (pad, data->src_format, data->src_value,
3008 data->dest_format, data->dest_value);
3012 * gst_pad_convert_default:
3013 * @pad: a #GstPad to invoke the default converter on.
3014 * @src_format: the source #GstFormat.
3015 * @src_value: the source value.
3016 * @dest_format: a pointer to the destination #GstFormat.
3017 * @dest_value: a pointer to the destination value.
3019 * Invokes the default converter on a pad.
3020 * This will forward the call to the pad obtained
3021 * using the internal link of
3024 * Returns: TRUE if the conversion could be performed.
3027 gst_pad_convert_default (GstPad *pad,
3028 GstFormat src_format, gint64 src_value,
3029 GstFormat *dest_format, gint64 *dest_value)
3031 GstPadConvertData data;
3033 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3034 g_return_val_if_fail (dest_format, FALSE);
3035 g_return_val_if_fail (dest_value, FALSE);
3037 data.src_format = src_format;
3038 data.src_value = src_value;
3039 data.dest_format = dest_format;
3040 data.dest_value = dest_value;
3042 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3043 gst_pad_convert_dispatcher, &data);
3048 * @pad: a #GstPad to invoke the default converter on.
3049 * @src_format: the source #GstFormat.
3050 * @src_value: the source value.
3051 * @dest_format: a pointer to the destination #GstFormat.
3052 * @dest_value: a pointer to the destination value.
3054 * Invokes a conversion on the pad.
3056 * Returns: TRUE if the conversion could be performed.
3059 gst_pad_convert (GstPad *pad,
3060 GstFormat src_format, gint64 src_value,
3061 GstFormat *dest_format, gint64 *dest_value)
3065 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3066 g_return_val_if_fail (dest_format, FALSE);
3067 g_return_val_if_fail (dest_value, FALSE);
3069 if (src_format == *dest_format) {
3070 *dest_value = src_value;
3074 rpad = GST_PAD_REALIZE (pad);
3076 if (GST_RPAD_CONVERTFUNC (rpad)) {
3077 return GST_RPAD_CONVERTFUNC (rpad) (GST_PAD_CAST (rpad), src_format,
3078 src_value, dest_format, dest_value);
3092 gst_pad_query_dispatcher (GstPad *pad, GstPadQueryData *data)
3094 return gst_pad_query (pad, data->type, data->format, data->value);
3098 * gst_pad_query_default:
3099 * @pad: a #GstPad to invoke the default query on.
3100 * @type: the #GstQueryType of the query to perform.
3101 * @format: a pointer to the #GstFormat of the result.
3102 * @value: a pointer to the result.
3104 * Invokes the default query function on a pad.
3106 * Returns: TRUE if the query could be performed.
3109 gst_pad_query_default (GstPad *pad, GstQueryType type,
3110 GstFormat *format, gint64 *value)
3112 GstPadQueryData data;
3114 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3115 g_return_val_if_fail (format, FALSE);
3116 g_return_val_if_fail (value, FALSE);
3119 data.format = format;
3122 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3123 gst_pad_query_dispatcher, &data);
3128 * @pad: a #GstPad to invoke the default query on.
3129 * @type: the #GstQueryType of the query to perform.
3130 * @format: a pointer to the #GstFormat asked for.
3131 * On return contains the #GstFormat used.
3132 * @value: a pointer to the result.
3134 * Queries a pad for one of the available properties. The format will be
3135 * adjusted to the actual format used when specifying formats such as
3136 * GST_FORMAT_DEFAULT.
3137 * FIXME: Tell if the format can be adjusted when specifying a definite format.
3139 * Returns: TRUE if the query could be performed.
3142 gst_pad_query (GstPad *pad, GstQueryType type,
3143 GstFormat *format, gint64 *value)
3147 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3148 g_return_val_if_fail (format, FALSE);
3149 g_return_val_if_fail (value, FALSE);
3151 rpad = GST_PAD_REALIZE (pad);
3153 g_return_val_if_fail (rpad, FALSE);
3155 if (GST_RPAD_QUERYFUNC (rpad))
3156 return GST_RPAD_QUERYFUNC (rpad) (GST_PAD_CAST (pad), type, format, value);
3162 gst_pad_get_formats_dispatcher (GstPad *pad, const GstFormat **data)
3164 *data = gst_pad_get_formats (pad);
3170 * gst_pad_get_formats_default:
3171 * @pad: a #GstPad to query
3173 * Invoke the default format dispatcher for the pad.
3175 * Returns: An array of GstFormats ended with a 0 value.
3178 gst_pad_get_formats_default (GstPad *pad)
3180 GstFormat *result = NULL;
3182 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3183 gst_pad_get_formats_dispatcher, &result);
3189 * gst_pad_get_formats:
3190 * @pad: a #GstPad to query
3192 * Gets the list of supported formats from the pad.
3194 * Returns: An array of GstFormats ended with a 0 value.
3197 gst_pad_get_formats (GstPad *pad)
3201 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3203 rpad = GST_PAD_REALIZE (pad);
3205 if (GST_RPAD_FORMATSFUNC (rpad))
3206 return GST_RPAD_FORMATSFUNC (rpad) (GST_PAD_CAST (pad));