2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstpad.c: Pads for connecting 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);
50 static gboolean gst_pad_try_reconnect_filtered_func (GstRealPad *srcpad, GstRealPad *sinkpad,
51 GstCaps *caps, gboolean clear);
53 #ifndef GST_DISABLE_LOADSAVE
54 static xmlNodePtr gst_pad_save_thyself (GstObject *object, xmlNodePtr parent);
57 static GstObject *pad_parent_class = NULL;
60 gst_pad_get_type (void)
63 static const GTypeInfo pad_info = {
64 sizeof (GstPadClass), NULL, NULL,
65 (GClassInitFunc) gst_pad_class_init, NULL, NULL,
68 (GInstanceInitFunc) gst_pad_init, NULL
70 _gst_pad_type = g_type_register_static (GST_TYPE_OBJECT, "GstPad",
77 gst_pad_class_init (GstPadClass *klass)
79 pad_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
83 gst_pad_init (GstPad *pad)
85 pad->element_private = NULL;
87 pad->padtemplate = NULL;
92 /***** Then do the Real Pad *****/
93 /* Pad signals and args */
95 REAL_CAPS_NEGO_FAILED,
109 static void gst_real_pad_class_init (GstRealPadClass *klass);
110 static void gst_real_pad_init (GstRealPad *pad);
112 static void gst_real_pad_set_property (GObject *object, guint prop_id,
115 static void gst_real_pad_get_property (GObject *object, guint prop_id,
119 static void gst_real_pad_dispose (GObject *object);
121 GType _gst_real_pad_type = 0;
123 static GstPad *real_pad_parent_class = NULL;
124 static guint gst_real_pad_signals[REAL_LAST_SIGNAL] = { 0 };
127 gst_real_pad_get_type (void) {
128 if (!_gst_real_pad_type) {
129 static const GTypeInfo pad_info = {
130 sizeof (GstRealPadClass), NULL, NULL,
131 (GClassInitFunc) gst_real_pad_class_init, NULL, NULL,
134 (GInstanceInitFunc) gst_real_pad_init, NULL
136 _gst_real_pad_type = g_type_register_static (GST_TYPE_PAD, "GstRealPad",
139 return _gst_real_pad_type;
143 gst_real_pad_class_init (GstRealPadClass *klass)
145 GObjectClass *gobject_class;
146 GstObjectClass *gstobject_class;
148 gobject_class = (GObjectClass*) klass;
149 gstobject_class = (GstObjectClass*) klass;
151 real_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
153 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_real_pad_dispose);
154 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_real_pad_set_property);
155 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_real_pad_get_property);
157 gst_real_pad_signals[REAL_CAPS_NEGO_FAILED] =
158 g_signal_new ("caps_nego_failed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
159 G_STRUCT_OFFSET (GstRealPadClass, caps_nego_failed), NULL, NULL,
160 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
162 gst_real_pad_signals[REAL_CONNECTED] =
163 g_signal_new ("connected", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
164 G_STRUCT_OFFSET (GstRealPadClass, connected), NULL, NULL,
165 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
167 gst_real_pad_signals[REAL_DISCONNECTED] =
168 g_signal_new ("disconnected", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
169 G_STRUCT_OFFSET (GstRealPadClass, disconnected), NULL, NULL,
170 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
173 /* gtk_object_add_arg_type ("GstRealPad::active", G_TYPE_BOOLEAN, */
174 /* GTK_ARG_READWRITE, REAL_ARG_ACTIVE); */
175 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_ACTIVE,
176 g_param_spec_boolean ("active", "Active", "Whether the pad is active.",
177 TRUE, G_PARAM_READWRITE));
178 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_CAPS,
179 g_param_spec_boxed ("caps", "Caps", "The capabilities of the pad",
180 GST_TYPE_CAPS, G_PARAM_READABLE));
182 #ifndef GST_DISABLE_LOADSAVE
183 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
185 gstobject_class->path_string_separator = ".";
189 gst_real_pad_init (GstRealPad *pad)
191 pad->direction = GST_PAD_UNKNOWN;
194 pad->chainfunc = NULL;
197 pad->chainhandler = NULL;
198 pad->gethandler = NULL;
200 pad->bufferpoolfunc = NULL;
201 pad->ghostpads = NULL;
204 pad->connectfunc = NULL;
205 pad->getcapsfunc = NULL;
207 pad->convertfunc = gst_pad_convert_default;
208 pad->eventfunc = gst_pad_event_default;
209 pad->convertfunc = gst_pad_convert_default;
210 pad->queryfunc = gst_pad_query_default;
211 pad->intconnfunc = gst_pad_get_internal_connections_default;
213 pad->eventmaskfunc = gst_pad_get_event_masks_default;
214 pad->formatsfunc = gst_pad_get_formats_default;
215 pad->querytypefunc = gst_pad_get_query_types_default;
217 GST_FLAG_SET (pad, GST_PAD_DISABLED);
219 gst_probe_dispatcher_init (&pad->probedisp);
223 gst_real_pad_set_property (GObject *object, guint prop_id,
224 const GValue *value, GParamSpec *pspec)
226 g_return_if_fail (GST_IS_PAD (object));
229 case REAL_ARG_ACTIVE:
230 gst_pad_set_active (GST_PAD (object), g_value_get_boolean (value));
233 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
239 gst_real_pad_get_property (GObject *object, guint prop_id,
240 GValue *value, GParamSpec *pspec)
242 g_return_if_fail (GST_IS_PAD (object));
245 case REAL_ARG_ACTIVE:
246 g_value_set_boolean (value, !GST_FLAG_IS_SET (object, GST_PAD_DISABLED));
249 g_value_set_boxed (value, GST_PAD_CAPS (GST_REAL_PAD (object)));
252 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
259 * gst_pad_custom_new:
260 * @type: the #Gtype of the pad.
261 * @name: the name of the new pad.
262 * @direction: the #GstPadDirection of the pad.
264 * Creates a new pad with the given name and type in the given direction.
265 * If name is NULL, a guaranteed unique name (across all pads)
268 * Returns: a new #GstPad, or NULL in case of an error.
271 gst_pad_custom_new (GType type, const gchar *name,
272 GstPadDirection direction)
276 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
278 pad = g_object_new (type, NULL);
279 gst_object_set_name (GST_OBJECT (pad), name);
280 GST_RPAD_DIRECTION (pad) = direction;
282 return GST_PAD (pad);
287 * @name: the name of the new pad.
288 * @direction: the #GstPadDirection of the pad.
290 * Creates a new real pad with the given name in the given direction.
291 * If name is NULL, a guaranteed unique name (across all pads)
294 * Returns: a new #GstPad, or NULL in case of an error.
297 gst_pad_new (const gchar *name,
298 GstPadDirection direction)
300 return gst_pad_custom_new (gst_real_pad_get_type (), name, direction);
304 * gst_pad_custom_new_from_template:
305 * @type: the custom #GType of the pad.
306 * @templ: the #GstPadTemplate to instantiate from.
307 * @name: the name of the new pad.
309 * Creates a new custom pad with the given name from the given template.
310 * If name is NULL, a guaranteed unique name (across all pads)
313 * Returns: a new #GstPad, or NULL in case of an error.
316 gst_pad_custom_new_from_template (GType type, GstPadTemplate *templ,
321 g_return_val_if_fail (templ != NULL, NULL);
323 pad = gst_pad_new (name, templ->direction);
325 gst_object_ref (GST_OBJECT (templ));
326 GST_PAD_PAD_TEMPLATE (pad) = templ;
328 g_signal_emit (G_OBJECT (templ), gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
334 * gst_pad_new_from_template:
335 * @templ: the pad template to use
336 * @name: the name of the element
338 * Creates a new real pad with the given name from the given template.
339 * If name is NULL, a guaranteed unique name (across all pads)
342 * Returns: a new #GstPad, or NULL in case of an error.
345 gst_pad_new_from_template (GstPadTemplate *templ, const gchar *name)
347 return gst_pad_custom_new_from_template (gst_real_pad_get_type (),
352 * gst_pad_get_direction:
353 * @pad: a #GstPad to get the direction of.
355 * Gets the direction of the pad.
357 * Returns: the #GstPadDirection of the pad.
360 gst_pad_get_direction (GstPad *pad)
362 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
364 return GST_PAD_DIRECTION (pad);
368 * gst_pad_set_active:
369 * @pad: the #GstPad to activate or deactivate.
370 * @active: TRUE to activate the pad.
372 * Activates or deactivates the given pad.
375 gst_pad_set_active (GstPad *pad, gboolean active)
380 g_return_if_fail (GST_IS_PAD (pad));
382 old = GST_PAD_IS_ACTIVE (pad);
387 realpad = GST_PAD_REALIZE (pad);
390 GST_DEBUG (GST_CAT_PADS, "activating pad %s:%s",
391 GST_DEBUG_PAD_NAME (realpad));
392 GST_FLAG_UNSET (realpad, GST_PAD_DISABLED);
394 GST_DEBUG (GST_CAT_PADS, "de-activating pad %s:%s",
395 GST_DEBUG_PAD_NAME (realpad));
396 GST_FLAG_SET (realpad, GST_PAD_DISABLED);
399 g_object_notify (G_OBJECT (realpad), "active");
404 * @pad: the #GstPad to query
406 * Query if a pad is active
408 * Returns: TRUE if the pad is active.
411 gst_pad_is_active (GstPad *pad)
413 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
415 return !GST_FLAG_IS_SET (pad, GST_PAD_DISABLED);
420 * @pad: a #GstPad to set the name of.
421 * @name: the name of the pad.
423 * Sets the name of a pad. If name is NULL, then a guaranteed unique
424 * name will be assigned.
427 gst_pad_set_name (GstPad *pad, const gchar *name)
429 g_return_if_fail (GST_IS_PAD (pad));
431 gst_object_set_name (GST_OBJECT (pad), name);
436 * @pad: a #GstPad to get the name of.
438 * Gets the name of a pad.
440 * Returns: the name of the pad. This is not a newly allocated pointer
441 * so you must not free it.
444 gst_pad_get_name (GstPad *pad)
446 g_return_val_if_fail (pad != NULL, NULL);
447 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
449 return GST_OBJECT_NAME (pad);
453 * gst_pad_set_chain_function:
454 * @pad: a #GstPad to set the chain function for.
455 * @chain: the #GstPadChainFunction to set.
457 * Sets the given chain function for the pad.
460 gst_pad_set_chain_function (GstPad *pad, GstPadChainFunction chain)
462 g_return_if_fail (pad != NULL);
463 g_return_if_fail (GST_IS_REAL_PAD (pad));
465 GST_RPAD_CHAINFUNC (pad) = chain;
466 GST_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
467 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
471 * gst_pad_set_get_function:
472 * @pad: a #GstPad to set the get function for.
473 * @get: the #GstPadGetFunction to set.
475 * Sets the given get function for the pad.
478 gst_pad_set_get_function (GstPad *pad,
479 GstPadGetFunction get)
481 g_return_if_fail (pad != NULL);
482 g_return_if_fail (GST_IS_REAL_PAD (pad));
484 GST_RPAD_GETFUNC (pad) = get;
486 GST_DEBUG (GST_CAT_PADS, "getfunc for %s:%s set to %s",
487 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
491 * gst_pad_set_event_function:
492 * @pad: a #GstPad to set the event handler for.
493 * @event: the #GstPadEventFunction to set.
495 * Sets the given event handler for the pad.
498 gst_pad_set_event_function (GstPad *pad,
499 GstPadEventFunction event)
501 g_return_if_fail (GST_IS_REAL_PAD (pad));
503 GST_RPAD_EVENTFUNC (pad) = event;
505 GST_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
506 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
510 * gst_pad_set_event_mask_function:
511 * @pad: a #GstPad to set the event mask function for.
512 * @mask_func: the #GstPadEventMaskFunction to set.
514 * Sets the given event mask function for the pad.
517 gst_pad_set_event_mask_function (GstPad *pad,
518 GstPadEventMaskFunction mask_func)
520 g_return_if_fail (GST_IS_REAL_PAD (pad));
522 GST_RPAD_EVENTMASKFUNC (pad) = mask_func;
524 GST_DEBUG (GST_CAT_PADS, "eventmaskfunc for %s:%s set to %s",
525 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (mask_func));
529 * gst_pad_get_event_masks:
530 * @pad: a #GstPad to get the event mask for.
532 * Gets the array of eventmasks from the given pad.
534 * Returns: an array with eventmasks, the list is ended
538 gst_pad_get_event_masks (GstPad *pad)
545 rpad = GST_PAD_REALIZE (pad);
547 g_return_val_if_fail (rpad, FALSE);
549 if (GST_RPAD_EVENTMASKFUNC (rpad))
550 return GST_RPAD_EVENTMASKFUNC (rpad) (GST_PAD_CAST (pad));
556 gst_pad_get_event_masks_dispatcher (GstPad *pad, const GstEventMask **data)
558 *data = gst_pad_get_event_masks (pad);
564 * gst_pad_get_event_masks_default:
565 * @pad: a #GstPad to get the event mask for.
567 * Invokes the default event masks dispatcher on the pad.
569 * Returns: an array with eventmasks, the list is ended
573 gst_pad_get_event_masks_default (GstPad *pad)
575 GstEventMask *result = NULL;
577 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
578 gst_pad_get_event_masks_dispatcher, &result);
584 * gst_pad_handles_event:
585 * @pad: a #GstPad to check
586 * @mask: the mask to check
588 * Checks if the pad can handle the given eventmask.
590 * Returns: TRUE if the pad can handle the given eventmask
593 gst_pad_handles_event (GstPad *pad, GstEventMask *mask)
595 const GstEventMask *masks;
597 g_return_val_if_fail (pad != NULL, FALSE);
598 g_return_val_if_fail (mask != NULL, FALSE);
600 masks = gst_pad_get_event_masks (pad);
604 while (masks->type) {
605 if (masks->type == mask->type &&
606 (masks->flags & mask->flags) == mask->flags)
616 * gst_pad_set_convert_function:
617 * @pad: a #GstPad to set the convert function for.
618 * @convert: the #GstPadConvertFunction to set.
620 * Sets the given convert function for the pad.
623 gst_pad_set_convert_function (GstPad *pad,
624 GstPadConvertFunction convert)
626 g_return_if_fail (pad != NULL);
627 g_return_if_fail (GST_IS_REAL_PAD (pad));
629 GST_RPAD_CONVERTFUNC (pad) = convert;
631 GST_DEBUG (GST_CAT_PADS, "convertfunc for %s:%s set to %s",
632 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (convert));
636 * gst_pad_set_query_function:
637 * @pad: the #GstPad to set the query function for.
638 * @query: the #GstPadQueryFunction to set.
640 * Set the given query function for the pad.
643 gst_pad_set_query_function (GstPad *pad, GstPadQueryFunction query)
645 g_return_if_fail (pad != NULL);
646 g_return_if_fail (GST_IS_REAL_PAD (pad));
648 GST_RPAD_QUERYFUNC (pad) = query;
650 GST_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
651 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
655 * gst_pad_set_query_type_function:
656 * @pad: the #GstPad to set the query type function for.
657 * @type_func: the #GstPadQueryTypeFunction to set.
659 * Set the given query type function for the pad.
662 gst_pad_set_query_type_function (GstPad *pad, GstPadQueryTypeFunction type_func)
664 g_return_if_fail (pad != NULL);
665 g_return_if_fail (GST_IS_REAL_PAD (pad));
667 GST_RPAD_QUERYTYPEFUNC (pad) = type_func;
669 GST_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
670 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
674 * gst_pad_get_query_types:
675 * @pad: the #GstPad to query
677 * Get an array of supported queries that can be performed
680 * Returns: an array of querytypes anded with 0.
682 const GstPadQueryType*
683 gst_pad_get_query_types (GstPad *pad)
690 rpad = GST_PAD_REALIZE (pad);
692 g_return_val_if_fail (rpad, FALSE);
694 if (GST_RPAD_QUERYTYPEFUNC (rpad))
695 return GST_RPAD_QUERYTYPEFUNC (rpad) (GST_PAD_CAST (pad));
701 gst_pad_get_query_types_dispatcher (GstPad *pad, const GstPadQueryType **data)
703 *data = gst_pad_get_query_types (pad);
709 * gst_pad_get_query_types_default:
710 * @pad: the #GstPad to query
712 * Invoke the default dispatcher for the query types on
715 * Returns: an array of querytypes anded with 0.
717 const GstPadQueryType*
718 gst_pad_get_query_types_default (GstPad *pad)
720 GstPadQueryType *result = NULL;
722 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
723 gst_pad_get_query_types_dispatcher, &result);
729 * gst_pad_set_internal_connection_function:
730 * @pad: a #GstPad to set the internal connection function for.
731 * @intconn: the #GstPadIntConnFunction to set.
733 * Sets the given internal connection function for the pad.
736 gst_pad_set_internal_connection_function (GstPad *pad,
737 GstPadIntConnFunction intconn)
739 g_return_if_fail (pad != NULL);
740 g_return_if_fail (GST_IS_REAL_PAD (pad));
742 GST_RPAD_INTCONNFUNC (pad) = intconn;
743 GST_DEBUG (GST_CAT_PADS, "internal connection for %s:%s set to %s",
744 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intconn));
748 * gst_pad_set_formats_function:
749 * @pad: the #GstPad to set the formats function for.
750 * @formats: the #GstPadFormatsFunction to set.
752 * Sets the given formats function for the pad.
755 gst_pad_set_formats_function (GstPad *pad, GstPadFormatsFunction formats)
757 g_return_if_fail (pad != NULL);
758 g_return_if_fail (GST_IS_REAL_PAD (pad));
760 GST_RPAD_FORMATSFUNC (pad) = formats;
761 GST_DEBUG (GST_CAT_PADS, "formats function for %s:%s set to %s",
762 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (formats));
766 * gst_pad_set_connect_function:
767 * @pad: a #GstPad to set the connect function for.
768 * @connect: the #GstPadConnectFunction to set.
770 * Sets the given connect function for the pad. It will be called
771 * when the pad is connected or reconnected with caps.
774 gst_pad_set_connect_function (GstPad *pad,
775 GstPadConnectFunction connect)
777 g_return_if_fail (pad != NULL);
778 g_return_if_fail (GST_IS_REAL_PAD (pad));
780 GST_RPAD_CONNECTFUNC (pad) = connect;
781 GST_DEBUG (GST_CAT_PADS, "connectfunc for %s:%s set to %s",
782 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (connect));
786 * gst_pad_set_getcaps_function:
787 * @pad: a #GstPad to set the getcaps function for.
788 * @getcaps: the #GstPadGetCapsFunction to set.
790 * Sets the given getcaps function for the pad.
793 gst_pad_set_getcaps_function (GstPad *pad,
794 GstPadGetCapsFunction getcaps)
796 g_return_if_fail (pad != NULL);
797 g_return_if_fail (GST_IS_REAL_PAD (pad));
799 GST_RPAD_GETCAPSFUNC (pad) = getcaps;
800 GST_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
801 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
804 * gst_pad_set_bufferpool_function:
805 * @pad: a #GstPad to set the bufferpool function for.
806 * @bufpool: the #GstPadBufferPoolFunction to set.
808 * Sets the given bufferpool function for the pad. Note that the
809 * bufferpool function can only be set on sinkpads.
812 gst_pad_set_bufferpool_function (GstPad *pad,
813 GstPadBufferPoolFunction bufpool)
815 g_return_if_fail (pad != NULL);
816 g_return_if_fail (GST_IS_REAL_PAD (pad));
817 g_return_if_fail (GST_PAD_IS_SINK (pad));
819 GST_RPAD_BUFFERPOOLFUNC (pad) = bufpool;
820 GST_DEBUG (GST_CAT_PADS, "bufferpoolfunc for %s:%s set to %s",
821 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufpool));
825 * gst_pad_disconnect:
826 * @srcpad: the source #GstPad to disconnect.
827 * @sinkpad: the sink #GstPad to disconnect.
829 * Disconnects the source pad from the sink pad.
832 gst_pad_disconnect (GstPad *srcpad,
835 GstRealPad *realsrc, *realsink;
836 GstScheduler *src_sched, *sink_sched;
839 g_return_if_fail (srcpad != NULL);
840 g_return_if_fail (GST_IS_PAD (srcpad));
841 g_return_if_fail (sinkpad != NULL);
842 g_return_if_fail (GST_IS_PAD (sinkpad));
844 GST_INFO (GST_CAT_ELEMENT_PADS, "disconnecting %s:%s(%p) and %s:%s(%p)",
845 GST_DEBUG_PAD_NAME (srcpad), srcpad,
846 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
848 /* now we need to deal with the real/ghost stuff */
849 realsrc = GST_PAD_REALIZE (srcpad);
850 realsink = GST_PAD_REALIZE (sinkpad);
852 g_return_if_fail (GST_RPAD_PEER (realsrc) != NULL);
853 g_return_if_fail (GST_RPAD_PEER (realsink) == realsrc);
855 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
856 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
863 g_return_if_fail ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
864 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK));
866 /* get the schedulers before we disconnect */
867 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
868 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
870 /* first clear peers */
871 GST_RPAD_PEER (realsrc) = NULL;
872 GST_RPAD_PEER (realsink) = NULL;
874 /* reset the filters, both filters are refcounted once */
875 if (GST_RPAD_FILTER (realsrc)) {
876 gst_caps_unref (GST_RPAD_FILTER (realsrc));
877 GST_RPAD_FILTER (realsink) = NULL;
878 GST_RPAD_FILTER (realsrc) = NULL;
881 /* now tell the scheduler */
882 if (src_sched && src_sched == sink_sched) {
883 gst_scheduler_pad_disconnect (src_sched,
884 GST_PAD_CAST (realsrc), GST_PAD_CAST (realsink));
887 /* hold a reference, as they can go away in the signal handlers */
888 gst_object_ref (GST_OBJECT (realsrc));
889 gst_object_ref (GST_OBJECT (realsink));
891 /* fire off a signal to each of the pads telling them
892 * that they've been disconnected */
893 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_DISCONNECTED],
895 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_DISCONNECTED],
898 GST_INFO (GST_CAT_ELEMENT_PADS, "disconnected %s:%s and %s:%s",
899 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
901 gst_object_unref (GST_OBJECT (realsrc));
902 gst_object_unref (GST_OBJECT (realsink));
906 gst_pad_check_schedulers (GstRealPad *realsrc, GstRealPad *realsink)
908 GstScheduler *src_sched, *sink_sched;
909 gint num_decoupled = 0;
911 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
912 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
914 if (src_sched && sink_sched) {
915 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsrc), GST_ELEMENT_DECOUPLED))
917 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsink), GST_ELEMENT_DECOUPLED))
920 if (src_sched != sink_sched && num_decoupled != 1) {
928 * gst_pad_can_connect_filtered:
929 * @srcpad: the source #GstPad to connect.
930 * @sinkpad: the sink #GstPad to connect.
931 * @filtercaps: the filter #GstCaps.
933 * Checks if the source pad and the sink pad can be connected when constrained
934 * by the given filter caps.
936 * Returns: TRUE if the pads can be connected, FALSE otherwise.
939 gst_pad_can_connect_filtered (GstPad *srcpad, GstPad *sinkpad,
942 GstRealPad *realsrc, *realsink;
945 g_return_val_if_fail (srcpad != NULL, FALSE);
946 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
947 g_return_val_if_fail (sinkpad != NULL, FALSE);
948 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
950 /* now we need to deal with the real/ghost stuff */
951 realsrc = GST_PAD_REALIZE (srcpad);
952 realsink = GST_PAD_REALIZE (sinkpad);
954 g_return_val_if_fail (GST_RPAD_PEER (realsrc) == NULL, FALSE);
955 g_return_val_if_fail (GST_RPAD_PEER (realsink) == NULL, FALSE);
956 g_return_val_if_fail (GST_PAD_PARENT (realsrc) != NULL, FALSE);
957 g_return_val_if_fail (GST_PAD_PARENT (realsink) != NULL, FALSE);
959 if (!gst_pad_check_schedulers (realsrc, realsink)) {
960 g_warning ("connecting pads with different scheds requires "
961 "exactly one decoupled element (queue)");
965 /* check if the directions are compatible */
966 if (!(((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
967 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) ||
968 ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
969 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK))))
975 * gst_pad_can_connect:
976 * @srcpad: the source #GstPad to connect.
977 * @sinkpad: the sink #GstPad to connect.
979 * Checks if the source pad and the sink pad can be connected.
981 * Returns: TRUE if the pads can be connected, FALSE otherwise.
984 gst_pad_can_connect (GstPad *srcpad, GstPad *sinkpad)
986 return gst_pad_can_connect_filtered (srcpad, sinkpad, NULL);
990 * gst_pad_connect_filtered:
991 * @srcpad: the source #GstPad to connect.
992 * @sinkpad: the sink #GstPad to connect.
993 * @filtercaps: the filter #GstCaps.
995 * Connects the source pad and the sink pad can be connected, constrained
996 * by the given filter caps.
998 * Returns: TRUE if the pads have been connected, FALSE otherwise.
1001 gst_pad_connect_filtered (GstPad *srcpad, GstPad *sinkpad, GstCaps *filtercaps)
1003 GstRealPad *realsrc, *realsink;
1004 GstScheduler *src_sched, *sink_sched;
1006 /* generic checks */
1007 g_return_val_if_fail (srcpad != NULL, FALSE);
1008 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1009 g_return_val_if_fail (sinkpad != NULL, FALSE);
1010 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1012 GST_INFO (GST_CAT_PADS, "trying to connect %s:%s and %s:%s",
1013 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1015 /* now we need to deal with the real/ghost stuff */
1016 realsrc = GST_PAD_REALIZE (srcpad);
1017 realsink = GST_PAD_REALIZE (sinkpad);
1019 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1020 GST_INFO (GST_CAT_PADS, "*actually* connecting %s:%s and %s:%s",
1021 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1023 if (GST_RPAD_PEER (realsrc) != NULL)
1025 GST_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1026 GST_DEBUG_PAD_NAME (realsrc));
1029 if (GST_RPAD_PEER (realsink) != NULL)
1031 GST_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1032 GST_DEBUG_PAD_NAME (realsink));
1035 if (GST_PAD_PARENT (realsrc) == NULL)
1037 GST_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1038 GST_DEBUG_PAD_NAME (realsrc));
1041 if (GST_PAD_PARENT (realsink) == NULL)
1043 GST_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1044 GST_DEBUG_PAD_NAME (realsrc));
1048 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1049 g_warning ("connecting pads with different scheds requires "
1050 "exactly one decoupled element (such as queue)");
1054 /* check for reversed directions and swap if necessary */
1055 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
1056 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
1057 GstRealPad *temppad;
1063 if (GST_PAD_PARENT (realsink) == NULL)
1064 if (GST_RPAD_DIRECTION (realsrc) != GST_PAD_SRC)
1066 GST_INFO (GST_CAT_PADS, "Real src pad %s:%s is not a source pad, failed",
1067 GST_DEBUG_PAD_NAME (realsrc));
1070 if (GST_RPAD_DIRECTION (realsink) != GST_PAD_SINK)
1072 GST_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1073 GST_DEBUG_PAD_NAME (realsink));
1076 /* first set peers */
1077 GST_RPAD_PEER (realsrc) = realsink;
1078 GST_RPAD_PEER (realsink) = realsrc;
1080 /* try to negotiate the pads, we don't need to clear the caps here */
1081 if (!gst_pad_try_reconnect_filtered_func (realsrc, realsink,
1082 filtercaps, FALSE)) {
1083 GST_DEBUG (GST_CAT_CAPS, "reconnect_filtered_func failed, can't connect");
1085 GST_RPAD_PEER (realsrc) = NULL;
1086 GST_RPAD_PEER (realsink) = NULL;
1091 /* fire off a signal to each of the pads telling them
1092 * that they've been connected */
1093 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_CONNECTED],
1095 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_CONNECTED],
1098 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
1099 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
1101 /* now tell the scheduler */
1102 if (src_sched && src_sched == sink_sched) {
1103 gst_scheduler_pad_connect (src_sched,
1104 GST_PAD_CAST (realsrc), GST_PAD_CAST (realsink));
1107 GST_INFO (GST_CAT_PADS, "connected %s:%s and %s:%s, successful",
1108 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1109 gst_caps_debug (gst_pad_get_caps (GST_PAD_CAST (realsrc)),
1110 "caps of newly connected src pad");
1117 * @srcpad: the source #GstPad to connect.
1118 * @sinkpad: the sink #GstPad to connect.
1120 * Connects the source pad to the sink pad.
1122 * Returns: TRUE if the pad could be connected, FALSE otherwise.
1125 gst_pad_connect (GstPad *srcpad, GstPad *sinkpad)
1127 return gst_pad_connect_filtered (srcpad, sinkpad, NULL);
1131 * gst_pad_set_parent:
1132 * @pad: a #GstPad to set the parent of.
1133 * @parent: the new parent #GstElement.
1135 * Sets the parent object of a pad.
1138 gst_pad_set_parent (GstPad *pad, GstElement *parent)
1140 g_return_if_fail (pad != NULL);
1141 g_return_if_fail (GST_IS_PAD (pad));
1142 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
1143 g_return_if_fail (parent != NULL);
1144 g_return_if_fail (GST_IS_OBJECT (parent));
1145 g_return_if_fail ((gpointer) pad != (gpointer) parent);
1147 gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (parent));
1151 * gst_pad_get_parent:
1152 * @pad: the #GstPad to get the parent of.
1154 * Gets the parent object of this pad.
1156 * Returns: the parent #GstElement.
1159 gst_pad_get_parent (GstPad *pad)
1161 g_return_val_if_fail (pad != NULL, NULL);
1162 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1164 return GST_PAD_PARENT (pad);
1168 * gst_pad_get_pad_template:
1169 * @pad: a #GstPad to get the pad template of.
1171 * Gets the pad template object of this pad.
1173 * Returns: the #GstPadTemplate from which this pad was instantiated.
1176 gst_pad_get_pad_template (GstPad *pad)
1178 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1180 return GST_PAD_PAD_TEMPLATE (pad);
1185 * gst_pad_get_scheduler:
1186 * @pad: a #GstPad to get the scheduler of.
1188 * Gets the scheduler of the pad. Since the pad does not
1189 * have a scheduler of its own, the scheduler of the parent
1190 * is taken. For decoupled pads, the scheduler of the peer
1193 * Returns: the #GstScheduler of the pad.
1196 gst_pad_get_scheduler (GstPad *pad)
1198 GstScheduler *scheduler = NULL;
1201 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1203 parent = gst_pad_get_parent (pad);
1205 if (GST_FLAG_IS_SET (parent, GST_ELEMENT_DECOUPLED)) {
1206 GstRealPad *peer = GST_RPAD_PEER (pad);
1209 scheduler = gst_element_get_scheduler (gst_pad_get_parent (GST_PAD_CAST (peer)));
1213 scheduler = gst_element_get_scheduler (parent);
1221 * gst_pad_get_real_parent:
1222 * @pad: a #GstPad to get the real parent of.
1224 * Gets the real parent object of this pad. If the pad
1225 * is a ghost pad, the actual owner of the real pad is
1226 * returned, as opposed to #gst_pad_get_parent().
1228 * Returns: the parent #GstElement.
1231 gst_pad_get_real_parent (GstPad *pad)
1233 g_return_val_if_fail (pad != NULL, NULL);
1234 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1236 return GST_PAD_PARENT (GST_PAD (GST_PAD_REALIZE (pad)));
1240 * gst_pad_add_ghost_pad:
1241 * @pad: a #GstPad to attach the ghost pad to.
1242 * @ghostpad: the ghost #GstPad to to the pad.
1244 * Adds a ghost pad to a pad.
1247 gst_pad_add_ghost_pad (GstPad *pad,
1250 GstRealPad *realpad;
1252 g_return_if_fail (pad != NULL);
1253 g_return_if_fail (GST_IS_PAD (pad));
1254 g_return_if_fail (ghostpad != NULL);
1255 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1257 realpad = GST_PAD_REALIZE (pad);
1259 realpad->ghostpads = g_list_prepend (realpad->ghostpads, ghostpad);
1264 * gst_pad_remove_ghost_pad:
1265 * @pad: a #GstPad to remove the ghost pad from.
1266 * @ghostpad: the ghost #GstPad to remove from the pad.
1268 * Removes a ghost pad from a pad.
1271 gst_pad_remove_ghost_pad (GstPad *pad,
1274 GstRealPad *realpad;
1276 g_return_if_fail (pad != NULL);
1277 g_return_if_fail (GST_IS_PAD (pad));
1278 g_return_if_fail (ghostpad != NULL);
1279 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1281 realpad = GST_PAD_REALIZE (pad);
1283 realpad->ghostpads = g_list_remove (realpad->ghostpads, ghostpad);
1287 * gst_pad_get_ghost_pad_list:
1288 * @pad: a #GstPad to get the ghost pads of.
1290 * Gets the ghost pads of this pad.
1292 * Returns: a #GList of ghost pads.
1295 gst_pad_get_ghost_pad_list (GstPad *pad)
1297 g_return_val_if_fail (pad != NULL, NULL);
1298 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1300 return GST_PAD_REALIZE(pad)->ghostpads;
1303 /* an internal caps negotiation helper function:
1305 * 1. optionally calls the pad connect function with the provided caps
1306 * 2. deals with the result code of the connect function
1307 * 3. sets fixed caps on the pad.
1309 static GstPadConnectReturn
1310 gst_pad_try_set_caps_func (GstRealPad *pad, GstCaps *caps, gboolean notify)
1312 GstCaps *oldcaps, *allowed = NULL;
1313 GstPadTemplate *template;
1314 GstElement *parent = GST_PAD_PARENT (pad);
1316 g_return_val_if_fail (pad != NULL, GST_PAD_CONNECT_REFUSED);
1317 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_CONNECT_REFUSED);
1319 /* if this pad has a parent and the parent is not READY, delay the
1321 if (parent && GST_STATE (parent) < GST_STATE_READY)
1323 GST_DEBUG (GST_CAT_CAPS, "parent %s of pad %s:%s is not READY",
1324 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (pad));
1325 return GST_PAD_CONNECT_DELAYED;
1328 GST_INFO (GST_CAT_CAPS, "trying to set caps %p on pad %s:%s",
1329 caps, GST_DEBUG_PAD_NAME (pad));
1331 /* first see if we have to check against a filter */
1332 if (!(allowed = GST_RPAD_FILTER (pad))) {
1333 /* no filter, make sure we check against the padtemplate then */
1334 if ((template = gst_pad_get_pad_template (GST_PAD_CAST (pad)))) {
1335 allowed = gst_pad_template_get_caps (template);
1339 /* do we have to check the caps against something? */
1341 GstCaps *intersection;
1343 /* check against calculated caps */
1344 intersection = gst_caps_intersect (caps, allowed);
1346 /* oops, empty intersection, caps don"t have anything in common */
1347 if (!intersection) {
1348 GST_INFO (GST_CAT_CAPS, "caps did not intersect with %s:%s's allowed caps",
1349 GST_DEBUG_PAD_NAME (pad));
1350 gst_caps_debug (caps, "caps themselves (attemped to set)");
1351 gst_caps_debug (allowed,
1352 "allowed caps that did not agree with caps");
1353 return GST_PAD_CONNECT_REFUSED;
1355 /* caps checks out fine, we can unref the intersection now */
1356 gst_caps_unref (intersection);
1357 /* given that the caps are fixed, we know that their intersection with the
1358 * padtemplate caps is the same as caps itself */
1361 /* we need to notify the connect function */
1362 if (notify && GST_RPAD_CONNECTFUNC (pad)) {
1363 GstPadConnectReturn res;
1364 gchar *debug_string;
1366 GST_INFO (GST_CAT_CAPS, "calling connect function on pad %s:%s",
1367 GST_DEBUG_PAD_NAME (pad));
1369 /* call the connect function */
1370 res = GST_RPAD_CONNECTFUNC (pad) (GST_PAD (pad), caps);
1373 case GST_PAD_CONNECT_REFUSED:
1374 debug_string = "REFUSED";
1376 case GST_PAD_CONNECT_OK:
1377 debug_string = "OK";
1379 case GST_PAD_CONNECT_DONE:
1380 debug_string = "DONE";
1382 case GST_PAD_CONNECT_DELAYED:
1383 debug_string = "DELAYED";
1386 g_warning ("unknown return code from connect function of pad %s:%s %d",
1387 GST_DEBUG_PAD_NAME (pad), res);
1388 return GST_PAD_CONNECT_REFUSED;
1391 GST_INFO (GST_CAT_CAPS,
1392 "got reply %s (%d) from connect function on pad %s:%s",
1393 debug_string, res, GST_DEBUG_PAD_NAME (pad));
1395 /* done means the connect function called another caps negotiate function
1396 * on this pad that succeeded, we dont need to continue */
1397 if (res == GST_PAD_CONNECT_DONE) {
1398 GST_INFO (GST_CAT_CAPS, "pad %s:%s is done", GST_DEBUG_PAD_NAME (pad));
1399 return GST_PAD_CONNECT_DONE;
1401 if (res == GST_PAD_CONNECT_REFUSED) {
1402 GST_INFO (GST_CAT_CAPS, "pad %s:%s doesn't accept caps",
1403 GST_DEBUG_PAD_NAME (pad));
1404 return GST_PAD_CONNECT_REFUSED;
1407 /* we can only set caps on the pad if they are fixed */
1408 if (GST_CAPS_IS_FIXED (caps)) {
1410 GST_INFO (GST_CAT_CAPS, "setting caps on pad %s:%s",
1411 GST_DEBUG_PAD_NAME (pad));
1412 /* if we got this far all is ok, remove the old caps, set the new one */
1413 oldcaps = GST_PAD_CAPS (pad);
1414 if (caps) gst_caps_ref (caps);
1415 GST_PAD_CAPS (pad) = caps;
1416 if (oldcaps) gst_caps_unref (oldcaps);
1418 g_object_notify (G_OBJECT (pad), "caps");
1421 GST_INFO (GST_CAT_CAPS,
1422 "caps are not fixed on pad %s:%s, not setting them yet",
1423 GST_DEBUG_PAD_NAME (pad));
1425 return GST_PAD_CONNECT_OK;
1429 * gst_pad_try_set_caps:
1430 * @pad: a #GstPad to try to set the caps on.
1431 * @caps: the #GstCaps to set.
1433 * Tries to set the caps on the given pad.
1435 * Returns: A GstPadConnectReturn value indicating whether the caps
1439 gst_pad_try_set_caps (GstPad *pad, GstCaps *caps)
1441 GstRealPad *peer, *realpad;
1442 GstPadConnectReturn set_retval;
1444 realpad = GST_PAD_REALIZE (pad);
1445 peer = GST_RPAD_PEER (realpad);
1447 GST_INFO (GST_CAT_CAPS, "trying to set caps %p on pad %s:%s",
1448 caps, GST_DEBUG_PAD_NAME (realpad));
1450 gst_caps_debug (caps, "caps that we are trying to set");
1452 /* setting non fixed caps on a pad is not allowed */
1453 if (!GST_CAPS_IS_FIXED (caps)) {
1454 GST_INFO (GST_CAT_CAPS,
1455 "trying to set unfixed caps on pad %s:%s, not allowed",
1456 GST_DEBUG_PAD_NAME (realpad));
1457 g_warning ("trying to set non fixed caps on pad %s:%s, not allowed",
1458 GST_DEBUG_PAD_NAME (realpad));
1459 gst_caps_debug (caps, "unfixed caps");
1460 return GST_PAD_CONNECT_DELAYED;
1463 /* if we have a peer try to set the caps, notifying the peerpad
1464 * if it has a connect function */
1465 if (peer && ((set_retval = gst_pad_try_set_caps_func (peer, caps, TRUE)) <= 0))
1467 GST_INFO (GST_CAT_CAPS, "tried to set caps on peerpad %s:%s but couldn't, return value %d",
1468 GST_DEBUG_PAD_NAME (peer), set_retval);
1472 /* then try to set our own caps, we don't need to be notified */
1473 if ((set_retval = gst_pad_try_set_caps_func (realpad, caps, FALSE)) <= 0)
1475 GST_INFO (GST_CAT_CAPS, "tried to set own caps on pad %s:%s but couldn't, return value %d",
1476 GST_DEBUG_PAD_NAME (realpad), set_retval);
1479 GST_INFO (GST_CAT_CAPS, "succeeded setting caps %p on pad %s:%s, return value %d",
1480 caps, GST_DEBUG_PAD_NAME (realpad), set_retval);
1481 g_assert (GST_PAD_CAPS (pad));
1486 /* this is a caps negotiation convenience routine, it:
1488 * 1. optionally clears any pad caps.
1489 * 2. calculates the intersection between the two pad tamplate/getcaps caps.
1490 * 3. calculates the intersection with the (optional) filtercaps.
1491 * 4. stores the intersection in the pad filter.
1492 * 5. stores the app filtercaps in the pad appfilter.
1493 * 6. starts the caps negotiation.
1496 gst_pad_try_reconnect_filtered_func (GstRealPad *srcpad, GstRealPad *sinkpad,
1497 GstCaps *filtercaps, gboolean clear)
1499 GstCaps *srccaps, *sinkcaps;
1500 GstCaps *intersection = NULL;
1501 GstRealPad *realsrc, *realsink;
1503 realsrc = GST_PAD_REALIZE (srcpad);
1504 realsink = GST_PAD_REALIZE (sinkpad);
1506 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1507 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1509 /* optinally clear the caps */
1511 GST_INFO (GST_CAT_PADS,
1512 "start reconnect filtered %s:%s and %s:%s, clearing caps",
1513 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1515 GST_PAD_CAPS (GST_PAD (realsrc)) = NULL;
1516 GST_PAD_CAPS (GST_PAD (realsink)) = NULL;
1519 GST_INFO (GST_CAT_PADS, "start reconnect filtered %s:%s and %s:%s",
1520 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1523 srccaps = gst_pad_get_caps (GST_PAD (realsrc));
1524 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1525 GST_DEBUG_PAD_NAME (realsrc));
1526 gst_caps_debug (srccaps, "caps of src pad (pre-reconnect)");
1527 sinkcaps = gst_pad_get_caps (GST_PAD (realsink));
1528 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1529 GST_DEBUG_PAD_NAME (realsink));
1530 gst_caps_debug (sinkcaps, "caps of sink pad (pre-reconnect)");
1532 /* first take the intersection of the pad caps */
1533 intersection = gst_caps_intersect (srccaps, sinkcaps);
1534 gst_caps_debug (intersection, "caps of intersection");
1536 /* if we have no intersection but one of the caps was not NULL.. */
1537 if (!intersection && (srccaps || sinkcaps)) {
1538 /* the intersection is NULL but the pad caps were not both NULL,
1539 * this means they have no common format */
1540 GST_INFO (GST_CAT_PADS, "pads %s:%s and %s:%s have no common type",
1541 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1543 } else if (intersection) {
1544 GST_INFO (GST_CAT_PADS, "pads %s:%s and %s:%s intersected to %s caps",
1545 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink),
1546 ((intersection && GST_CAPS_IS_FIXED (intersection)) ? "fixed" : "variable"));
1548 /* then filter this against the app filter */
1550 GstCaps *filtered_intersection = gst_caps_intersect (intersection,
1553 /* get rid of the old intersection here */
1554 gst_caps_unref (intersection);
1556 if (!filtered_intersection) {
1557 GST_INFO (GST_CAT_PADS,
1558 "filtered connection between pads %s:%s and %s:%s is empty",
1559 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1562 intersection = filtered_intersection;
1564 /* keep a reference to the app caps */
1565 GST_RPAD_APPFILTER (realsink) = filtercaps;
1566 GST_RPAD_APPFILTER (realsrc) = filtercaps;
1569 GST_DEBUG (GST_CAT_CAPS, "setting filter for connection to:");
1570 gst_caps_debug (intersection, "filter for connection");
1572 /* both the app filter and the filter, while stored on both peer pads,
1573 * are equal to the same thing on both */
1574 GST_RPAD_FILTER (realsrc) = intersection;
1575 GST_RPAD_FILTER (realsink) = intersection;
1577 return gst_pad_perform_negotiate (GST_PAD (realsrc), GST_PAD (realsink));
1581 * gst_pad_perform_negotiate:
1582 * @srcpad: the source #GstPad.
1583 * @sinkpad: the sink #GstPad.
1585 * Tries to negotiate the pads.
1587 * Returns: TRUE if the pads were succesfully negotiated, FALSE otherwise.
1590 gst_pad_perform_negotiate (GstPad *srcpad, GstPad *sinkpad)
1592 GstCaps *intersection, *filtered_intersection;
1593 GstRealPad *realsrc, *realsink;
1594 GstCaps *srccaps, *sinkcaps, *filter;
1596 g_return_val_if_fail (srcpad != NULL, FALSE);
1597 g_return_val_if_fail (sinkpad != NULL, FALSE);
1599 realsrc = GST_PAD_REALIZE (srcpad);
1600 realsink = GST_PAD_REALIZE (sinkpad);
1602 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1603 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1605 filter = GST_RPAD_APPFILTER (realsrc);
1607 GST_INFO (GST_CAT_PADS, "dumping filter for connection %s:%s-%s:%s",
1608 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1609 gst_caps_debug (filter, "connection filter caps");
1612 /* calculate the new caps here */
1613 srccaps = gst_pad_get_caps (GST_PAD (realsrc));
1614 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1615 GST_DEBUG_PAD_NAME (realsrc));
1616 gst_caps_debug (srccaps,
1617 "src caps, awaiting negotiation, after applying filter");
1618 sinkcaps = gst_pad_get_caps (GST_PAD (realsink));
1619 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1620 GST_DEBUG_PAD_NAME (realsink));
1621 gst_caps_debug (sinkcaps,
1622 "sink caps, awaiting negotiation, after applying filter");
1623 intersection = gst_caps_intersect (srccaps, sinkcaps);
1624 filtered_intersection = gst_caps_intersect (intersection, filter);
1625 if (filtered_intersection) {
1626 gst_caps_unref (intersection);
1627 intersection = filtered_intersection;
1630 /* no negotiation is performed if the pads have filtercaps */
1632 GstPadConnectReturn res;
1634 res = gst_pad_try_set_caps_func (realsrc, intersection, TRUE);
1635 if (res == GST_PAD_CONNECT_REFUSED)
1637 if (res == GST_PAD_CONNECT_DONE)
1640 res = gst_pad_try_set_caps_func (realsink, intersection, TRUE);
1641 if (res == GST_PAD_CONNECT_REFUSED)
1643 if (res == GST_PAD_CONNECT_DONE)
1650 * gst_pad_try_reconnect_filtered:
1651 * @srcpad: the source #GstPad to reconnect.
1652 * @sinkpad: the sink #GstPad to reconnect.
1653 * @filtercaps: the #GstPad to use as a filter in the reconnection.
1655 * Tries to reconnect the given source and sink pad, constrained by the given
1658 * Returns: TRUE if the pads were succesfully renegotiated, FALSE otherwise.
1661 gst_pad_try_reconnect_filtered (GstPad *srcpad, GstPad *sinkpad,
1662 GstCaps *filtercaps)
1664 GstRealPad *realsrc, *realsink;
1666 g_return_val_if_fail (srcpad != NULL, FALSE);
1667 g_return_val_if_fail (sinkpad != NULL, FALSE);
1669 realsrc = GST_PAD_REALIZE (srcpad);
1670 realsink = GST_PAD_REALIZE (sinkpad);
1672 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1673 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1675 return gst_pad_try_reconnect_filtered_func (realsrc, realsink,
1680 * gst_pad_reconnect_filtered:
1681 * @srcpad: the source #GstPad to reconnect.
1682 * @sinkpad: the sink #GstPad to reconnect.
1683 * @filtercaps: the #GstPad to use as a filter in the reconnection.
1685 * Reconnects the given source and sink pad, constrained by the given
1686 * capabilities. If the reconnection fails, the pads are disconnected
1687 * and FALSE is returned.
1689 * Returns: TRUE if the pads were succesfully reconnected, FALSE otherwise.
1692 gst_pad_reconnect_filtered (GstPad *srcpad, GstPad *sinkpad,
1693 GstCaps *filtercaps)
1695 GstRealPad *realsrc, *realsink;
1697 g_return_val_if_fail (srcpad != NULL, FALSE);
1698 g_return_val_if_fail (sinkpad != NULL, FALSE);
1700 realsrc = GST_PAD_REALIZE (srcpad);
1701 realsink = GST_PAD_REALIZE (sinkpad);
1703 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1704 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1706 if (! gst_pad_try_reconnect_filtered_func (realsrc, realsink,
1707 filtercaps, TRUE)) {
1708 gst_pad_disconnect (srcpad, GST_PAD (GST_PAD_PEER (srcpad)));
1715 * gst_pad_proxy_connect:
1716 * @pad: a #GstPad to proxy to.
1717 * @caps: the #GstCaps to use in proxying.
1719 * Proxies the connect function to the specified pad.
1721 * Returns: TRUE if the peer pad accepted the caps, FALSE otherwise.
1724 gst_pad_proxy_connect (GstPad *pad, GstCaps *caps)
1726 GstRealPad *peer, *realpad;
1728 realpad = GST_PAD_REALIZE (pad);
1730 peer = GST_RPAD_PEER (realpad);
1732 GST_INFO (GST_CAT_CAPS, "proxy connect to pad %s:%s",
1733 GST_DEBUG_PAD_NAME (realpad));
1735 if (peer && gst_pad_try_set_caps_func (peer, caps, TRUE) < 0)
1736 return GST_PAD_CONNECT_REFUSED;
1737 if (gst_pad_try_set_caps_func (realpad, caps, FALSE) < 0)
1738 return GST_PAD_CONNECT_REFUSED;
1740 return GST_PAD_CONNECT_OK;
1745 * @pad: a #GstPad to get the capabilities of.
1747 * Gets the capabilities of this pad.
1749 * Returns: the #GstCaps of this pad.
1752 gst_pad_get_caps (GstPad *pad)
1754 GstRealPad *realpad;
1756 g_return_val_if_fail (pad != NULL, NULL);
1757 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1759 realpad = GST_PAD_REALIZE (pad);
1761 GST_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1762 GST_DEBUG_PAD_NAME (realpad), realpad);
1764 if (GST_PAD_CAPS (realpad)) {
1765 GST_DEBUG (GST_CAT_CAPS, "using pad real caps %p", GST_PAD_CAPS (realpad));
1766 return GST_PAD_CAPS (realpad);
1768 else if GST_RPAD_GETCAPSFUNC (realpad) {
1769 GST_DEBUG (GST_CAT_CAPS, "using pad get function");
1770 return GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD_CAST (realpad), NULL);
1772 else if (GST_PAD_PAD_TEMPLATE (realpad)) {
1773 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (realpad);
1774 GST_DEBUG (GST_CAT_CAPS, "using pad template %p with caps %p",
1775 templ, GST_PAD_TEMPLATE_CAPS (templ));
1776 return GST_PAD_TEMPLATE_CAPS (templ);
1778 GST_DEBUG (GST_CAT_CAPS, "pad has no caps");
1784 * gst_pad_get_pad_template_caps:
1785 * @pad: a #GstPad to get the template capabilities from.
1787 * Gets the template capabilities of this pad.
1789 * Returns: the template #GstCaps of this pad.
1792 gst_pad_get_pad_template_caps (GstPad *pad)
1794 g_return_val_if_fail (pad != NULL, NULL);
1795 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1797 if (GST_PAD_PAD_TEMPLATE (pad))
1798 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
1804 * gst_pad_template_get_caps_by_name:
1805 * @templ: a #GstPadTemplate to get the capabilities of.
1806 * @name: the name of the capability to get.
1808 * Gets the capability with the given name from this pad template.
1810 * Returns: the #GstCaps, or NULL if not found or in case of an error.
1813 gst_pad_template_get_caps_by_name (GstPadTemplate *templ, const gchar *name)
1817 g_return_val_if_fail (templ != NULL, NULL);
1819 caps = GST_PAD_TEMPLATE_CAPS (templ);
1823 return gst_caps_get_by_name (caps, name);
1827 * gst_pad_check_compatibility:
1828 * @srcpad: the source #GstPad to check.
1829 * @sinkpad: the sink #GstPad to check against.
1831 * Checks if two pads have compatible capabilities.
1833 * Returns: TRUE if they are compatible or if the capabilities
1834 * could not be checked
1837 gst_pad_check_compatibility (GstPad *srcpad, GstPad *sinkpad)
1839 g_return_val_if_fail (srcpad != NULL, FALSE);
1840 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1841 g_return_val_if_fail (sinkpad != NULL, FALSE);
1842 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1844 if (GST_PAD_CAPS (srcpad) && GST_PAD_CAPS (sinkpad)) {
1845 if (!gst_caps_is_always_compatible (GST_PAD_CAPS (srcpad),
1846 GST_PAD_CAPS (sinkpad))) {
1854 GST_DEBUG (GST_CAT_PADS,
1855 "could not check capabilities of pads (%s:%s) and (%s:%s) %p %p",
1856 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
1857 GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad));
1864 * @pad: a #GstPad to get the peer of.
1866 * Gets the peer pad of this pad.
1868 * Returns: the peer #GstPad.
1871 gst_pad_get_peer (GstPad *pad)
1873 g_return_val_if_fail (pad != NULL, NULL);
1874 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1876 return GST_PAD (GST_PAD_PEER (pad));
1880 * gst_pad_get_allowed_caps:
1881 * @pad: a #GstPad to get the allowed caps of.
1883 * Gets the capabilities of the allowed media types that can
1884 * flow through this pad. The caller must free the resulting caps.
1886 * Returns: a newly allocated copy of the allowed #GstCaps.
1889 gst_pad_get_allowed_caps (GstPad *pad)
1891 g_return_val_if_fail (pad != NULL, NULL);
1892 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1894 GST_DEBUG (GST_CAT_PROPERTIES, "get allowed caps of %s:%s",
1895 GST_DEBUG_PAD_NAME (pad));
1897 return gst_caps_copy (GST_RPAD_FILTER (pad));
1901 * gst_pad_recalc_allowed_caps:
1902 * @pad: a #GstPad to recalculate the capablities of.
1904 * Attempts to reconnect the pad to its peer through its filter,
1905 * set with gst_pad_[re]connect_filtered. This function is useful when a
1906 * plug-in has new capabilities on a pad and wants to notify the peer.
1908 * Returns: TRUE on success, FALSE otherwise.
1911 gst_pad_recalc_allowed_caps (GstPad *pad)
1915 g_return_val_if_fail (pad != NULL, FALSE);
1916 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1918 GST_DEBUG (GST_CAT_PROPERTIES, "set allowed caps of %s:%s",
1919 GST_DEBUG_PAD_NAME (pad));
1921 peer = GST_RPAD_PEER (pad);
1923 return gst_pad_try_reconnect_filtered (pad, GST_PAD (peer),
1924 GST_RPAD_APPFILTER (pad));
1930 * gst_pad_get_bufferpool:
1931 * @pad: a #GstPad to get the bufferpool from.
1933 * Gets the bufferpool of the peer pad of the given pad.Note that
1934 * a bufferpool can only be obtained from a srcpad.
1936 * Returns: the #GstBufferPool, or NULL in case of an error.
1939 gst_pad_get_bufferpool (GstPad *pad)
1943 g_return_val_if_fail (pad != NULL, NULL);
1944 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1945 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
1947 peer = GST_RPAD_PEER (pad);
1952 GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
1954 if (peer->bufferpoolfunc) {
1955 GST_DEBUG (GST_CAT_PADS,
1956 "calling bufferpoolfunc &%s (@%p) of peer pad %s:%s",
1957 GST_DEBUG_FUNCPTR_NAME (peer->bufferpoolfunc),
1958 &peer->bufferpoolfunc, GST_DEBUG_PAD_NAME (((GstPad*) peer)));
1959 return (peer->bufferpoolfunc) (((GstPad*) peer));
1961 GST_DEBUG (GST_CAT_PADS, "no bufferpoolfunc for peer pad %s:%s at %p",
1962 GST_DEBUG_PAD_NAME (((GstPad*) peer)), &peer->bufferpoolfunc);
1968 gst_real_pad_dispose (GObject *object)
1970 GstPad *pad = GST_PAD (object);
1972 /* No connected pad can ever be disposed.
1973 * It has to have a parent to be connected
1974 * and a parent would hold a reference */
1975 g_assert (GST_PAD_PEER (pad) == NULL);
1977 GST_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s", GST_DEBUG_PAD_NAME(pad));
1979 if (GST_PAD_PAD_TEMPLATE (pad)){
1980 GST_DEBUG (GST_CAT_REFCOUNTING, "unreffing padtemplate'%s'",
1981 GST_OBJECT_NAME (GST_PAD_PAD_TEMPLATE (pad)));
1982 gst_object_unref (GST_OBJECT (GST_PAD_PAD_TEMPLATE (pad)));
1983 GST_PAD_PAD_TEMPLATE (pad) = NULL;
1986 /* we destroy the ghostpads, because they are nothing without the real pad */
1987 if (GST_REAL_PAD (pad)->ghostpads) {
1988 GList *orig, *ghostpads;
1990 orig = ghostpads = g_list_copy (GST_REAL_PAD (pad)->ghostpads);
1993 GstPad *ghostpad = GST_PAD (ghostpads->data);
1995 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))){
1996 GST_DEBUG (GST_CAT_REFCOUNTING, "removing ghost pad from element '%s'",
1997 GST_OBJECT_NAME (GST_OBJECT_PARENT (ghostpad)));
1999 gst_element_remove_ghost_pad (GST_ELEMENT (GST_OBJECT_PARENT (ghostpad)), GST_PAD (ghostpad));
2001 ghostpads = g_list_next (ghostpads);
2004 g_list_free (GST_REAL_PAD(pad)->ghostpads);
2007 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
2008 GST_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
2009 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
2011 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
2014 G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
2018 #ifndef GST_DISABLE_LOADSAVE
2019 /* FIXME: why isn't this on a GstElement ? */
2021 * gst_pad_load_and_connect:
2022 * @self: an #xmlNodePtr to read the description from.
2023 * @parent: the #GstObject element that owns the pad.
2025 * Reads the pad definition from the XML node and connects the given pad
2026 * in the element to a pad of an element up in the hierarchy.
2029 gst_pad_load_and_connect (xmlNodePtr self, GstObject *parent)
2031 xmlNodePtr field = self->xmlChildrenNode;
2032 GstPad *pad = NULL, *targetpad;
2036 GstObject *grandparent;
2039 if (!strcmp (field->name, "name")) {
2040 pad = gst_element_get_pad (GST_ELEMENT (parent),
2041 xmlNodeGetContent (field));
2043 else if (!strcmp(field->name, "peer")) {
2044 peer = xmlNodeGetContent (field);
2046 field = field->next;
2048 g_return_if_fail (pad != NULL);
2050 if (peer == NULL) return;
2052 split = g_strsplit (peer, ".", 2);
2054 if (split[0] == NULL || split[1] == NULL) {
2055 GST_DEBUG (GST_CAT_XML,
2056 "Could not parse peer '%s' for pad %s:%s, leaving unconnected",
2057 peer, GST_DEBUG_PAD_NAME (pad));
2061 g_return_if_fail (split[0] != NULL);
2062 g_return_if_fail (split[1] != NULL);
2064 grandparent = gst_object_get_parent (parent);
2066 if (grandparent && GST_IS_BIN (grandparent)) {
2067 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2072 if (target == NULL) goto cleanup;
2074 targetpad = gst_element_get_pad (target, split[1]);
2076 if (targetpad == NULL) goto cleanup;
2078 gst_pad_connect (pad, targetpad);
2085 * gst_pad_save_thyself:
2086 * @pad: a #GstPad to save.
2087 * @parent: the parent #xmlNodePtr to save the description in.
2089 * Saves the pad into an xml representation.
2091 * Returns: the #xmlNodePtr representation of the pad.
2094 gst_pad_save_thyself (GstObject *object, xmlNodePtr parent)
2096 GstRealPad *realpad;
2099 g_return_val_if_fail (GST_IS_REAL_PAD (object), NULL);
2101 realpad = GST_REAL_PAD (object);
2103 xmlNewChild (parent, NULL, "name", GST_PAD_NAME (realpad));
2104 if (GST_RPAD_PEER (realpad) != NULL) {
2107 peer = GST_PAD (GST_RPAD_PEER (realpad));
2108 /* first check to see if the peer's parent's parent is the same */
2109 /* we just save it off */
2110 content = g_strdup_printf ("%s.%s",
2111 GST_OBJECT_NAME (GST_PAD_PARENT (peer)),
2112 GST_PAD_NAME (peer));
2113 xmlNewChild (parent, NULL, "peer", content);
2116 xmlNewChild (parent, NULL, "peer", "");
2121 /* FIXME: shouldn't pad and ghost be switched ?
2124 * gst_ghost_pad_save_thyself:
2125 * @pad: a ghost #GstPad to save.
2126 * @parent: the parent #xmlNodePtr to save the description in.
2128 * Saves the ghost pad into an xml representation.
2130 * Returns: the #xmlNodePtr representation of the pad.
2133 gst_ghost_pad_save_thyself (GstPad *pad, xmlNodePtr parent)
2137 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2139 self = xmlNewChild (parent, NULL, "ghostpad", NULL);
2140 xmlNewChild (self, NULL, "name", GST_PAD_NAME (pad));
2141 xmlNewChild (self, NULL, "parent", GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
2143 /* FIXME FIXME FIXME! */
2147 #endif /* GST_DISABLE_LOADSAVE */
2151 * @pad: a #GstPad to push the buffer out of.
2152 * @buf: the #GstBuffer to push.
2154 * Pushes a buffer to the peer of the pad.
2157 gst_pad_push (GstPad *pad, GstBuffer *buf)
2161 GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
2163 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
2165 if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), GST_DATA (buf)))
2168 peer = GST_RPAD_PEER (pad);
2171 g_warning ("push on pad %s:%s but it is unconnected",
2172 GST_DEBUG_PAD_NAME (pad));
2175 if (!GST_IS_EVENT (buf) && !GST_PAD_IS_ACTIVE (pad)) {
2176 g_warning ("push on pad %s:%s but it is unusable",
2177 GST_DEBUG_PAD_NAME (pad));
2181 if (peer->chainhandler) {
2183 GST_DEBUG (GST_CAT_DATAFLOW,
2184 "calling chainhandler &%s of peer pad %s:%s",
2185 GST_DEBUG_FUNCPTR_NAME (peer->chainhandler),
2186 GST_DEBUG_PAD_NAME (GST_PAD (peer)));
2187 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, GST_DATA (buf)))
2190 (peer->chainhandler) (GST_PAD_CAST (peer), buf);
2194 g_warning ("trying to push a NULL buffer on pad %s:%s",
2195 GST_DEBUG_PAD_NAME (peer));
2200 g_warning ("internal error: push on pad %s:%s but it has no chainhandler",
2201 GST_DEBUG_PAD_NAME (peer));
2204 /* clean up the mess here */
2205 if (buf != NULL) gst_data_unref (GST_DATA (buf));
2210 * @pad: a #GstPad to pull a buffer from.
2212 * Pulls a buffer from the peer pad.
2214 * Returns: a new #GstBuffer from the peer pad.
2217 gst_pad_pull (GstPad *pad)
2221 GST_DEBUG_ENTER("(%s:%s)",GST_DEBUG_PAD_NAME(pad));
2223 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK, NULL);
2225 peer = GST_RPAD_PEER (pad);
2228 gst_element_error (GST_PAD_PARENT (pad),
2229 "pull on pad %s:%s but it was unconnected",
2230 GST_ELEMENT_NAME (GST_PAD_PARENT (pad)),
2231 GST_PAD_NAME (pad), NULL);
2234 if (peer->gethandler) {
2237 GST_DEBUG (GST_CAT_DATAFLOW, "calling gethandler %s of peer pad %s:%s",
2238 GST_DEBUG_FUNCPTR_NAME (peer->gethandler),
2239 GST_DEBUG_PAD_NAME (peer));
2241 buf = (peer->gethandler) (GST_PAD_CAST (peer));
2244 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, GST_DATA (buf)))
2250 /* no null buffers allowed */
2251 gst_element_error (GST_PAD_PARENT (pad),
2252 "NULL buffer during pull on %s:%s",
2253 GST_DEBUG_PAD_NAME (pad), NULL);
2256 gst_element_error (GST_PAD_PARENT (pad),
2257 "internal error: pull on pad %s:%s "
2258 "but the peer pad %s:%s has no gethandler",
2259 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer),
2268 * @padlist: a #GList of pads.
2270 * Waits for a buffer on any of the list of pads.
2272 * Returns: the #GstPad that has a buffer available.
2273 * Use #gst_pad_pull() to get the buffer.
2276 gst_pad_select (GList *padlist)
2280 pad = gst_scheduler_pad_select (GST_PAD_PARENT (padlist->data)->sched,
2287 * @pad: a first #GstPad to perform the select on.
2288 * @...: A NULL-terminated list of more pads to select on.
2290 * Waits for a buffer on the given set of pads.
2292 * Returns: the #GstPad that has a buffer available.
2293 * Use #gst_pad_pull() to get the buffer.
2296 gst_pad_selectv (GstPad *pad, ...)
2299 GList *padlist = NULL;
2305 va_start (var_args, pad);
2308 padlist = g_list_prepend (padlist, pad);
2309 pad = va_arg (var_args, GstPad *);
2311 result = gst_pad_select (padlist);
2312 g_list_free (padlist);
2319 /************************************************************************
2324 static void gst_pad_template_class_init (GstPadTemplateClass *klass);
2325 static void gst_pad_template_init (GstPadTemplate *templ);
2328 gst_pad_template_get_type (void)
2330 static GType padtemplate_type = 0;
2332 if (!padtemplate_type) {
2333 static const GTypeInfo padtemplate_info = {
2334 sizeof (GstPadTemplateClass), NULL, NULL,
2335 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
2336 sizeof (GstPadTemplate),
2338 (GInstanceInitFunc) gst_pad_template_init, NULL
2340 padtemplate_type = g_type_register_static(GST_TYPE_OBJECT, "GstPadTemplate",
2341 &padtemplate_info, 0);
2343 return padtemplate_type;
2347 gst_pad_template_class_init (GstPadTemplateClass *klass)
2349 GObjectClass *gobject_class;
2350 GstObjectClass *gstobject_class;
2352 gobject_class = (GObjectClass*) klass;
2353 gstobject_class = (GstObjectClass*) klass;
2355 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
2357 gst_pad_template_signals[TEMPL_PAD_CREATED] =
2358 g_signal_new ("pad_created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
2359 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
2360 NULL, NULL, gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
2363 gstobject_class->path_string_separator = "*";
2367 gst_pad_template_init (GstPadTemplate *templ)
2371 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
2373 * SOMETIMES padtemplates can do whatever they want, they are provided by the
2375 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
2376 * 'sink%d' template is automatically selected), so we need to restrict their
2380 name_is_valid (const gchar *name, GstPadPresence presence)
2384 if (presence == GST_PAD_ALWAYS) {
2385 if (strchr (name, '%')) {
2386 g_warning ("invalid name template %s: conversion specifications are not"
2387 " allowed for GST_PAD_ALWAYS padtemplates", name);
2390 } else if (presence == GST_PAD_REQUEST) {
2391 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
2392 g_warning ("invalid name template %s: only one conversion specification"
2393 " allowed in GST_PAD_REQUEST padtemplate", name);
2396 if (str && (*(str+1) != 's' && *(str+1) != 'd')) {
2397 g_warning ("invalid name template %s: conversion specification must be of"
2398 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
2401 if (str && (*(str+2) != '\0')) {
2402 g_warning ("invalid name template %s: conversion specification must"
2403 " appear at the end of the GST_PAD_REQUEST padtemplate name",
2413 * gst_pad_template_new:
2414 * @name_template: the name template.
2415 * @direction: the #GstPadDirection of the template.
2416 * @presence: the #GstPadPresence of the pad.
2417 * @caps: a #GstCaps set for the template.
2418 * @...: a NULL-terminated list of #GstCaps.
2420 * Creates a new pad template with a name according to the given template
2421 * and with the given arguments.
2423 * Returns: a new #GstPadTemplate.
2426 gst_pad_template_new (const gchar *name_template,
2427 GstPadDirection direction, GstPadPresence presence,
2430 GstPadTemplate *new;
2432 GstCaps *thecaps = NULL;
2434 g_return_val_if_fail (name_template != NULL, NULL);
2436 if (!name_is_valid (name_template, presence))
2439 new = g_object_new (gst_pad_template_get_type (),
2440 "name", name_template,
2443 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
2444 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
2445 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
2447 va_start (var_args, caps);
2450 new->fixed &= caps->fixed;
2451 thecaps = gst_caps_append (thecaps, gst_caps_ref (caps));
2452 caps = va_arg (var_args, GstCaps*);
2456 GST_PAD_TEMPLATE_CAPS (new) = thecaps;
2462 * gst_pad_template_get_caps:
2463 * @templ: a #GstPadTemplate to get capabilities of.
2465 * Gets the capabilities of the pad template.
2467 * Returns: the #GstCaps of the pad template.
2470 gst_pad_template_get_caps (GstPadTemplate *templ)
2472 g_return_val_if_fail (templ != NULL, NULL);
2474 return GST_PAD_TEMPLATE_CAPS (templ);
2478 * gst_pad_set_element_private:
2479 * @pad: the #GstPad to set the private data of.
2480 * @priv: The private data to attach to the pad.
2482 * Set the given private data gpointer on the pad.
2483 * This function can only be used by the element that owns the pad.
2486 gst_pad_set_element_private (GstPad *pad, gpointer priv)
2488 pad->element_private = priv;
2492 * gst_pad_get_element_private:
2493 * @pad: the #GstPad to get the private data of.
2495 * Gets the private data of a pad.
2497 * Returns: a #gpointer to the private data.
2500 gst_pad_get_element_private (GstPad *pad)
2502 return pad->element_private;
2506 /***** ghost pads *****/
2507 GType _gst_ghost_pad_type = 0;
2509 static void gst_ghost_pad_class_init (GstGhostPadClass *klass);
2510 static void gst_ghost_pad_init (GstGhostPad *pad);
2512 static GstPad *ghost_pad_parent_class = NULL;
2513 /* static guint gst_ghost_pad_signals[LAST_SIGNAL] = { 0 }; */
2516 gst_ghost_pad_get_type (void)
2518 if (!_gst_ghost_pad_type) {
2519 static const GTypeInfo pad_info = {
2520 sizeof (GstGhostPadClass), NULL, NULL,
2521 (GClassInitFunc) gst_ghost_pad_class_init, NULL, NULL,
2522 sizeof (GstGhostPad),
2524 (GInstanceInitFunc) gst_ghost_pad_init,
2527 _gst_ghost_pad_type = g_type_register_static (GST_TYPE_PAD, "GstGhostPad",
2530 return _gst_ghost_pad_type;
2534 gst_ghost_pad_class_init (GstGhostPadClass *klass)
2536 GObjectClass *gobject_class;
2538 gobject_class = (GObjectClass*) klass;
2540 ghost_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
2544 gst_ghost_pad_init (GstGhostPad *pad)
2546 pad->realpad = NULL;
2550 * gst_ghost_pad_new:
2551 * @name: the name of the new ghost pad.
2552 * @pad: the #GstPad to create a ghost pad for.
2554 * Creates a new ghost pad associated with the given pad, and names it with
2555 * the given name. If name is NULL, a guaranteed unique name (across all
2556 * ghost pads) will be assigned (most likely of the form ghostpad&perc;d).
2558 * Returns: a new ghost #GstPad, or NULL in case of an error.
2562 gst_ghost_pad_new (const gchar *name,
2565 GstGhostPad *ghostpad;
2566 GstRealPad *realpad;
2568 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2570 ghostpad = g_object_new (gst_ghost_pad_get_type () ,NULL);
2571 gst_pad_set_name (GST_PAD (ghostpad), name);
2573 realpad = (GstRealPad *) pad;
2575 while (!GST_IS_REAL_PAD (realpad)) {
2576 realpad = GST_PAD_REALIZE (realpad);
2578 GST_GPAD_REALPAD (ghostpad) = realpad;
2579 GST_PAD_PAD_TEMPLATE (ghostpad) = GST_PAD_PAD_TEMPLATE (pad);
2581 /* add ourselves to the real pad's list of ghostpads */
2582 gst_pad_add_ghost_pad (pad, GST_PAD (ghostpad));
2584 /* FIXME need to ref the real pad here... ? */
2586 GST_DEBUG (GST_CAT_PADS, "created ghost pad \"%s\"",
2587 gst_pad_get_name (GST_PAD (ghostpad)));
2589 return GST_PAD (ghostpad);
2593 * gst_pad_get_internal_connections_default:
2594 * @pad: the #GstPad to get the internal connections of.
2596 * Gets a list of pads to which the given pad is connected to
2597 * inside of the parent element.
2598 * This is the default handler, and thus returns a list of all of the
2599 * pads inside the parent element with opposite direction.
2600 * The caller must free this list after use.
2602 * Returns: a newly allocated #GList of pads.
2605 gst_pad_get_internal_connections_default (GstPad *pad)
2610 GstPadDirection direction;
2613 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2615 rpad = GST_PAD_REALIZE (pad);
2616 direction = rpad->direction;
2618 parent = GST_PAD_PARENT (rpad);
2619 parent_pads = parent->pads;
2621 while (parent_pads) {
2622 GstRealPad *parent_pad = GST_PAD_REALIZE (parent_pads->data);
2624 if (parent_pad->direction != direction) {
2625 res = g_list_prepend (res, parent_pad);
2628 parent_pads = g_list_next (parent_pads);
2635 * gst_pad_get_internal_connections:
2636 * @pad: the #GstPad to get the internal connections of.
2638 * Gets a list of pads to which the given pad is connected to
2639 * inside of the parent element.
2640 * The caller must free this list after use.
2642 * Returns: a newly allocated #GList of pads.
2645 gst_pad_get_internal_connections (GstPad *pad)
2650 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2652 rpad = GST_PAD_REALIZE (pad);
2654 if (GST_RPAD_INTCONNFUNC (rpad))
2655 res = GST_RPAD_INTCONNFUNC (rpad) (GST_PAD_CAST (rpad));
2662 gst_pad_event_default_dispatch (GstPad *pad, GstElement *element,
2665 GList *pads = element->pads;
2668 GstPad *eventpad = GST_PAD (pads->data);
2669 pads = g_list_next (pads);
2671 /* for all pads in the opposite direction that are connected */
2672 if (GST_PAD_DIRECTION (eventpad) != GST_PAD_DIRECTION (pad)
2673 && GST_PAD_IS_USABLE (eventpad)) {
2674 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
2675 /* increase the refcount */
2676 gst_event_ref (event);
2677 gst_pad_push (eventpad, GST_BUFFER (event));
2680 GstPad *peerpad = GST_PAD_CAST (GST_RPAD_PEER (eventpad));
2682 /* we only send the event on one pad, multi-sinkpad elements
2683 * should implement a handler */
2684 return gst_pad_send_event (peerpad, event);
2688 gst_event_unref (event);
2693 * gst_pad_event_default:
2694 * @pad: a #GstPad to call the default event handler on.
2695 * @event: the #GstEvent to handle.
2697 * Invokes the default event handler for the given pad.
2699 * Returns: TRUE if the event was sent succesfully.
2702 gst_pad_event_default (GstPad *pad, GstEvent *event)
2704 GstElement *element;
2706 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2707 g_return_val_if_fail (event, FALSE);
2709 element = GST_PAD_PARENT (pad);
2711 switch (GST_EVENT_TYPE (event)) {
2713 gst_pad_event_default_dispatch (pad, element, event);
2714 gst_element_set_eos (element);
2715 /* we have to try to schedule another element
2716 * because this one is disabled */
2717 gst_element_yield (element);
2719 case GST_EVENT_DISCONTINUOUS:
2720 case GST_EVENT_FLUSH:
2722 return gst_pad_event_default_dispatch (pad, element, event);
2728 * gst_pad_dispatcher:
2729 * @pad: a #GstPad to dispatch.
2730 * @dispatch: the #GstDispatcherFunction to call.
2731 * @data: gpointer user data passed to the dispatcher function.
2733 * Invokes the given dispatcher function on all pads that are
2734 * internally connected to the given pad.
2735 * The GstPadDispatcherFunction should return TRUE when no further pads
2736 * need to be processed.
2738 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2741 gst_pad_dispatcher (GstPad *pad, GstPadDispatcherFunction dispatch,
2744 gboolean res = FALSE;
2745 GList *int_pads, *orig;
2747 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2748 g_return_val_if_fail (data, FALSE);
2750 orig = int_pads = gst_pad_get_internal_connections (pad);
2753 GstRealPad *int_rpad = GST_PAD_REALIZE (int_pads->data);
2754 GstRealPad *int_peer = GST_RPAD_PEER (int_rpad);
2756 if (int_peer && GST_PAD_IS_USABLE (int_peer)) {
2757 res = dispatch (GST_PAD_CAST (int_peer), data);
2761 int_pads = g_list_next (int_pads);
2770 * gst_pad_send_event:
2771 * @pad: a #GstPad to send the event to.
2772 * @event: the #GstEvent to send to the pad.
2774 * Sends the event to the pad.
2776 * Returns: TRUE if the event was handled.
2779 gst_pad_send_event (GstPad *pad, GstEvent *event)
2781 gboolean success = FALSE;
2784 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2785 g_return_val_if_fail (event, FALSE);
2787 rpad = GST_PAD_REALIZE (pad);
2789 /* don't send events on usuable pads */
2790 if (GST_PAD_IS_SINK (rpad) && !GST_PAD_IS_USABLE (rpad)) {
2791 GST_DEBUG (GST_CAT_EVENT, "pad %s:%s is not usable",
2792 GST_DEBUG_PAD_NAME (rpad));
2796 if (GST_EVENT_SRC (event) == NULL)
2797 GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (rpad));
2799 GST_DEBUG (GST_CAT_EVENT, "have event %d on pad %s:%s",
2800 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (rpad));
2802 if (GST_RPAD_EVENTFUNC (rpad))
2803 success = GST_RPAD_EVENTFUNC (rpad) (GST_PAD_CAST (rpad), event);
2805 GST_DEBUG (GST_CAT_EVENT, "there's no event function for pad %s:%s",
2806 GST_DEBUG_PAD_NAME (rpad));
2807 gst_event_unref (event);
2815 GstFormat src_format;
2817 GstFormat *dest_format;
2819 } GstPadConvertData;
2822 gst_pad_convert_dispatcher (GstPad *pad, GstPadConvertData *data)
2824 return gst_pad_convert (pad, data->src_format, data->src_value,
2825 data->dest_format, data->dest_value);
2829 * gst_pad_convert_default:
2830 * @pad: a #GstPad to invoke the default converter on.
2831 * @src_format: the source #GstFormat.
2832 * @src_value: the source value.
2833 * @dest_format: a pointer to the destination #GstFormat.
2834 * @dest_value: a pointer to the destination value.
2836 * Invokes the default converter on a pad.
2837 * This will forward the call to the pad obtained
2838 * using the internal connection of
2841 * Returns: TRUE if the conversion could be performed.
2844 gst_pad_convert_default (GstPad *pad,
2845 GstFormat src_format, gint64 src_value,
2846 GstFormat *dest_format, gint64 *dest_value)
2848 GstPadConvertData data;
2850 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2851 g_return_val_if_fail (dest_format, FALSE);
2852 g_return_val_if_fail (dest_value, FALSE);
2854 data.src_format = src_format;
2855 data.src_value = src_value;
2856 data.dest_format = dest_format;
2857 data.dest_value = dest_value;
2859 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
2860 gst_pad_convert_dispatcher, &data);
2865 * @pad: a #GstPad to invoke the default converter on.
2866 * @src_format: the source #GstFormat.
2867 * @src_value: the source value.
2868 * @dest_format: a pointer to the destination #GstFormat.
2869 * @dest_value: a pointer to the destination value.
2871 * Invokes a conversion on the pad.
2873 * Returns: TRUE if the conversion could be performed.
2876 gst_pad_convert (GstPad *pad,
2877 GstFormat src_format, gint64 src_value,
2878 GstFormat *dest_format, gint64 *dest_value)
2882 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2883 g_return_val_if_fail (dest_format, FALSE);
2884 g_return_val_if_fail (dest_value, FALSE);
2886 if (src_format == *dest_format) {
2887 *dest_value = src_value;
2891 rpad = GST_PAD_REALIZE (pad);
2893 if (GST_RPAD_CONVERTFUNC (rpad)) {
2894 return GST_RPAD_CONVERTFUNC (rpad) (GST_PAD_CAST (rpad), src_format,
2895 src_value, dest_format, dest_value);
2903 GstPadQueryType type;
2909 gst_pad_query_dispatcher (GstPad *pad, GstPadQueryData *data)
2911 return gst_pad_query (pad, data->type, data->format, data->value);
2915 * gst_pad_query_default:
2916 * @pad: a #GstPad to invoke the default query on.
2917 * @type: the #GstPadQueryType of the query to perform.
2918 * @format: a pointer to the #GstFormat of the result.
2919 * @value: a pointer to the result.
2921 * Invokes the default query function on a pad.
2923 * Returns: TRUE if the query could be performed.
2926 gst_pad_query_default (GstPad *pad, GstPadQueryType type,
2927 GstFormat *format, gint64 *value)
2929 GstPadQueryData data;
2931 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2932 g_return_val_if_fail (format, FALSE);
2933 g_return_val_if_fail (value, FALSE);
2936 data.format = format;
2939 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
2940 gst_pad_query_dispatcher, &data);
2945 * @pad: a #GstPad to invoke the default query on.
2946 * @type: the #GstPadQueryType of the query to perform.
2947 * @format: a pointer to the #GstFormat of the result.
2948 * @value: a pointer to the result.
2950 * Queries a pad for one of the available properties.
2952 * Returns: TRUE if the query could be performed.
2955 gst_pad_query (GstPad *pad, GstPadQueryType type,
2956 GstFormat *format, gint64 *value)
2960 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2961 g_return_val_if_fail (format, FALSE);
2962 g_return_val_if_fail (value, FALSE);
2964 rpad = GST_PAD_REALIZE (pad);
2966 g_return_val_if_fail (rpad, FALSE);
2968 if (GST_RPAD_QUERYFUNC (rpad))
2969 return GST_RPAD_QUERYFUNC (rpad) (GST_PAD_CAST (pad), type, format, value);
2975 * gst_pad_handles_format:
2976 * @pad: a #GstPad to check
2977 * @format: the format to check
2979 * Checks if the pad can handle the given format.
2981 * Returns: TRUE if the pad can handle the given format
2984 gst_pad_handles_format (GstPad *pad, GstFormat format)
2986 const GstFormat *formats;
2988 formats = gst_pad_get_formats (pad);
2990 return gst_formats_contains (formats, format);
2994 gst_pad_get_formats_dispatcher (GstPad *pad, const GstFormat **data)
2996 *data = gst_pad_get_formats (pad);
3002 * gst_pad_get_formats_default:
3003 * @pad: a #GstPad to query
3005 * Invoke the default format dispatcher for the pad.
3007 * Returns: An array of GstFormats ended with a 0 value.
3010 gst_pad_get_formats_default (GstPad *pad)
3012 GstFormat *result = NULL;
3014 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3015 gst_pad_get_formats_dispatcher, &result);
3021 * gst_pad_get_formats:
3022 * @pad: a #GstPad to query
3024 * Gets the list of supported formats from the pad.
3026 * Returns: An array of GstFormats ended with a 0 value.
3029 gst_pad_get_formats (GstPad *pad)
3033 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3035 rpad = GST_PAD_REALIZE (pad);
3037 if (GST_RPAD_FORMATSFUNC (rpad))
3038 return GST_RPAD_FORMATSFUNC (rpad) (GST_PAD_CAST (pad));