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_probe_dispatcher_init (&pad->probedisp);
221 gst_real_pad_set_property (GObject *object, guint prop_id,
222 const GValue *value, GParamSpec *pspec)
224 g_return_if_fail (GST_IS_PAD (object));
227 case REAL_ARG_ACTIVE:
228 gst_pad_set_active (GST_PAD (object), g_value_get_boolean (value));
231 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
237 gst_real_pad_get_property (GObject *object, guint prop_id,
238 GValue *value, GParamSpec *pspec)
240 g_return_if_fail (GST_IS_PAD (object));
243 case REAL_ARG_ACTIVE:
244 g_value_set_boolean (value, !GST_FLAG_IS_SET (object, GST_PAD_DISABLED));
247 g_value_set_boxed (value, GST_PAD_CAPS (GST_REAL_PAD (object)));
250 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
257 * gst_pad_custom_new:
258 * @type: the #Gtype of the pad.
259 * @name: the name of the new pad.
260 * @direction: the #GstPadDirection of the pad.
262 * Creates a new pad with the given name and type in the given direction.
263 * If name is NULL, a guaranteed unique name (across all pads)
266 * Returns: a new #GstPad, or NULL in case of an error.
269 gst_pad_custom_new (GType type, const gchar *name,
270 GstPadDirection direction)
274 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
276 pad = g_object_new (type, NULL);
277 gst_object_set_name (GST_OBJECT (pad), name);
278 GST_RPAD_DIRECTION (pad) = direction;
280 return GST_PAD (pad);
285 * @name: the name of the new pad.
286 * @direction: the #GstPadDirection of the pad.
288 * Creates a new real pad with the given name in the given direction.
289 * If name is NULL, a guaranteed unique name (across all pads)
292 * Returns: a new #GstPad, or NULL in case of an error.
295 gst_pad_new (const gchar *name,
296 GstPadDirection direction)
298 return gst_pad_custom_new (gst_real_pad_get_type (), name, direction);
302 * gst_pad_custom_new_from_template:
303 * @type: the custom #GType of the pad.
304 * @templ: the #GstPadTemplate to instantiate from.
305 * @name: the name of the new pad.
307 * Creates a new custom pad with the given name from the given template.
308 * If name is NULL, a guaranteed unique name (across all pads)
311 * Returns: a new #GstPad, or NULL in case of an error.
314 gst_pad_custom_new_from_template (GType type, GstPadTemplate *templ,
319 g_return_val_if_fail (templ != NULL, NULL);
321 pad = gst_pad_new (name, templ->direction);
323 gst_object_ref (GST_OBJECT (templ));
324 GST_PAD_PAD_TEMPLATE (pad) = templ;
326 g_signal_emit (G_OBJECT (templ), gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
332 * gst_pad_new_from_template:
333 * @templ: the pad template to use
334 * @name: the name of the element
336 * Creates a new real pad with the given name from the given template.
337 * If name is NULL, a guaranteed unique name (across all pads)
340 * Returns: a new #GstPad, or NULL in case of an error.
343 gst_pad_new_from_template (GstPadTemplate *templ, const gchar *name)
345 return gst_pad_custom_new_from_template (gst_real_pad_get_type (),
350 * gst_pad_get_direction:
351 * @pad: a #GstPad to get the direction of.
353 * Gets the direction of the pad.
355 * Returns: the #GstPadDirection of the pad.
358 gst_pad_get_direction (GstPad *pad)
360 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
362 return GST_PAD_DIRECTION (pad);
366 * gst_pad_set_active:
367 * @pad: the #GstPad to activate or deactivate.
368 * @active: TRUE to activate the pad.
370 * Activates or deactivates the given pad.
373 gst_pad_set_active (GstPad *pad, gboolean active)
378 g_return_if_fail (GST_IS_PAD (pad));
380 old = GST_PAD_IS_ACTIVE (pad);
385 realpad = GST_PAD_REALIZE (pad);
388 GST_DEBUG (GST_CAT_PADS, "activating pad %s:%s",
389 GST_DEBUG_PAD_NAME (realpad));
390 GST_FLAG_UNSET (realpad, GST_PAD_DISABLED);
392 GST_DEBUG (GST_CAT_PADS, "de-activating pad %s:%s",
393 GST_DEBUG_PAD_NAME (realpad));
394 GST_FLAG_SET (realpad, GST_PAD_DISABLED);
397 g_object_notify (G_OBJECT (realpad), "active");
402 * @pad: the #GstPad to query
404 * Query if a pad is active
406 * Returns: TRUE if the pad is active.
409 gst_pad_is_active (GstPad *pad)
411 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
413 return !GST_FLAG_IS_SET (pad, GST_PAD_DISABLED);
418 * @pad: a #GstPad to set the name of.
419 * @name: the name of the pad.
421 * Sets the name of a pad. If name is NULL, then a guaranteed unique
422 * name will be assigned.
425 gst_pad_set_name (GstPad *pad, const gchar *name)
427 g_return_if_fail (GST_IS_PAD (pad));
429 gst_object_set_name (GST_OBJECT (pad), name);
434 * @pad: a #GstPad to get the name of.
436 * Gets the name of a pad.
438 * Returns: the name of the pad. This is not a newly allocated pointer
439 * so you must not free it.
442 gst_pad_get_name (GstPad *pad)
444 g_return_val_if_fail (pad != NULL, NULL);
445 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
447 return GST_OBJECT_NAME (pad);
451 * gst_pad_set_chain_function:
452 * @pad: a #GstPad to set the chain function for.
453 * @chain: the #GstPadChainFunction to set.
455 * Sets the given chain function for the pad.
458 gst_pad_set_chain_function (GstPad *pad, GstPadChainFunction chain)
460 g_return_if_fail (pad != NULL);
461 g_return_if_fail (GST_IS_REAL_PAD (pad));
463 GST_RPAD_CHAINFUNC (pad) = chain;
464 GST_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
465 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
469 * gst_pad_set_get_function:
470 * @pad: a #GstPad to set the get function for.
471 * @get: the #GstPadGetFunction to set.
473 * Sets the given get function for the pad.
476 gst_pad_set_get_function (GstPad *pad,
477 GstPadGetFunction get)
479 g_return_if_fail (pad != NULL);
480 g_return_if_fail (GST_IS_REAL_PAD (pad));
482 GST_RPAD_GETFUNC (pad) = get;
484 GST_DEBUG (GST_CAT_PADS, "getfunc for %s:%s set to %s",
485 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
489 * gst_pad_set_event_function:
490 * @pad: a #GstPad to set the event handler for.
491 * @event: the #GstPadEventFunction to set.
493 * Sets the given event handler for the pad.
496 gst_pad_set_event_function (GstPad *pad,
497 GstPadEventFunction event)
499 g_return_if_fail (GST_IS_REAL_PAD (pad));
501 GST_RPAD_EVENTFUNC (pad) = event;
503 GST_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
504 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
508 * gst_pad_set_event_mask_function:
509 * @pad: a #GstPad to set the event mask function for.
510 * @mask_func: the #GstPadEventMaskFunction to set.
512 * Sets the given event mask function for the pad.
515 gst_pad_set_event_mask_function (GstPad *pad,
516 GstPadEventMaskFunction mask_func)
518 g_return_if_fail (GST_IS_REAL_PAD (pad));
520 GST_RPAD_EVENTMASKFUNC (pad) = mask_func;
522 GST_DEBUG (GST_CAT_PADS, "eventmaskfunc for %s:%s set to %s",
523 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (mask_func));
527 * gst_pad_get_event_masks:
528 * @pad: a #GstPad to get the event mask for.
530 * Gets the array of eventmasks from the given pad.
532 * Returns: an array with eventmasks, the list is ended
536 gst_pad_get_event_masks (GstPad *pad)
543 rpad = GST_PAD_REALIZE (pad);
545 g_return_val_if_fail (rpad, FALSE);
547 if (GST_RPAD_EVENTMASKFUNC (rpad))
548 return GST_RPAD_EVENTMASKFUNC (rpad) (GST_PAD_CAST (pad));
554 gst_pad_get_event_masks_dispatcher (GstPad *pad, const GstEventMask **data)
556 *data = gst_pad_get_event_masks (pad);
562 * gst_pad_get_event_masks_default:
563 * @pad: a #GstPad to get the event mask for.
565 * Invokes the default event masks dispatcher on the pad.
567 * Returns: an array with eventmasks, the list is ended
571 gst_pad_get_event_masks_default (GstPad *pad)
573 GstEventMask *result = NULL;
575 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
576 gst_pad_get_event_masks_dispatcher, &result);
582 * gst_pad_handles_event:
583 * @pad: a #GstPad to check
584 * @mask: the mask to check
586 * Checks if the pad can handle the given eventmask.
588 * Returns: TRUE if the pad can handle the given eventmask
591 gst_pad_handles_event (GstPad *pad, GstEventMask *mask)
593 const GstEventMask *masks;
595 g_return_val_if_fail (pad != NULL, FALSE);
596 g_return_val_if_fail (mask != NULL, FALSE);
598 masks = gst_pad_get_event_masks (pad);
602 while (masks->type) {
603 if (masks->type == mask->type &&
604 (masks->flags & mask->flags) == mask->flags)
614 * gst_pad_set_convert_function:
615 * @pad: a #GstPad to set the convert function for.
616 * @convert: the #GstPadConvertFunction to set.
618 * Sets the given convert function for the pad.
621 gst_pad_set_convert_function (GstPad *pad,
622 GstPadConvertFunction convert)
624 g_return_if_fail (pad != NULL);
625 g_return_if_fail (GST_IS_REAL_PAD (pad));
627 GST_RPAD_CONVERTFUNC (pad) = convert;
629 GST_DEBUG (GST_CAT_PADS, "convertfunc for %s:%s set to %s",
630 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (convert));
634 * gst_pad_set_query_function:
635 * @pad: the #GstPad to set the query function for.
636 * @query: the #GstPadQueryFunction to set.
638 * Set the given query function for the pad.
641 gst_pad_set_query_function (GstPad *pad, GstPadQueryFunction query)
643 g_return_if_fail (pad != NULL);
644 g_return_if_fail (GST_IS_REAL_PAD (pad));
646 GST_RPAD_QUERYFUNC (pad) = query;
648 GST_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
649 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
653 * gst_pad_set_query_type_function:
654 * @pad: the #GstPad to set the query type function for.
655 * @type_func: the #GstPadQueryTypeFunction to set.
657 * Set the given query type function for the pad.
660 gst_pad_set_query_type_function (GstPad *pad, GstPadQueryTypeFunction type_func)
662 g_return_if_fail (pad != NULL);
663 g_return_if_fail (GST_IS_REAL_PAD (pad));
665 GST_RPAD_QUERYTYPEFUNC (pad) = type_func;
667 GST_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
668 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
672 * gst_pad_get_query_types:
673 * @pad: the #GstPad to query
675 * Get an array of supported queries that can be performed
678 * Returns: an array of querytypes anded with 0.
680 const GstPadQueryType*
681 gst_pad_get_query_types (GstPad *pad)
688 rpad = GST_PAD_REALIZE (pad);
690 g_return_val_if_fail (rpad, FALSE);
692 if (GST_RPAD_QUERYTYPEFUNC (rpad))
693 return GST_RPAD_QUERYTYPEFUNC (rpad) (GST_PAD_CAST (pad));
699 gst_pad_get_query_types_dispatcher (GstPad *pad, const GstPadQueryType **data)
701 *data = gst_pad_get_query_types (pad);
707 * gst_pad_get_query_types_default:
708 * @pad: the #GstPad to query
710 * Invoke the default dispatcher for the query types on
713 * Returns: an array of querytypes anded with 0.
715 const GstPadQueryType*
716 gst_pad_get_query_types_default (GstPad *pad)
718 GstPadQueryType *result = NULL;
720 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
721 gst_pad_get_query_types_dispatcher, &result);
727 * gst_pad_set_internal_connection_function:
728 * @pad: a #GstPad to set the internal connection function for.
729 * @intconn: the #GstPadIntConnFunction to set.
731 * Sets the given internal connection function for the pad.
734 gst_pad_set_internal_connection_function (GstPad *pad,
735 GstPadIntConnFunction intconn)
737 g_return_if_fail (pad != NULL);
738 g_return_if_fail (GST_IS_REAL_PAD (pad));
740 GST_RPAD_INTCONNFUNC (pad) = intconn;
741 GST_DEBUG (GST_CAT_PADS, "internal connection for %s:%s set to %s",
742 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intconn));
746 * gst_pad_set_formats_function:
747 * @pad: the #GstPad to set the formats function for.
748 * @formats: the #GstPadFormatsFunction to set.
750 * Sets the given formats function for the pad.
753 gst_pad_set_formats_function (GstPad *pad, GstPadFormatsFunction formats)
755 g_return_if_fail (pad != NULL);
756 g_return_if_fail (GST_IS_REAL_PAD (pad));
758 GST_RPAD_FORMATSFUNC (pad) = formats;
759 GST_DEBUG (GST_CAT_PADS, "formats function for %s:%s set to %s",
760 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (formats));
764 * gst_pad_set_connect_function:
765 * @pad: a #GstPad to set the connect function for.
766 * @connect: the #GstPadConnectFunction to set.
768 * Sets the given connect function for the pad. It will be called
769 * when the pad is connected or reconnected with caps.
772 gst_pad_set_connect_function (GstPad *pad,
773 GstPadConnectFunction connect)
775 g_return_if_fail (pad != NULL);
776 g_return_if_fail (GST_IS_REAL_PAD (pad));
778 GST_RPAD_CONNECTFUNC (pad) = connect;
779 GST_DEBUG (GST_CAT_PADS, "connectfunc for %s:%s set to %s",
780 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (connect));
784 * gst_pad_set_getcaps_function:
785 * @pad: a #GstPad to set the getcaps function for.
786 * @getcaps: the #GstPadGetCapsFunction to set.
788 * Sets the given getcaps function for the pad.
791 gst_pad_set_getcaps_function (GstPad *pad,
792 GstPadGetCapsFunction getcaps)
794 g_return_if_fail (pad != NULL);
795 g_return_if_fail (GST_IS_REAL_PAD (pad));
797 GST_RPAD_GETCAPSFUNC (pad) = getcaps;
798 GST_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
799 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
802 * gst_pad_set_bufferpool_function:
803 * @pad: a #GstPad to set the bufferpool function for.
804 * @bufpool: the #GstPadBufferPoolFunction to set.
806 * Sets the given bufferpool function for the pad. Note that the
807 * bufferpool function can only be set on sinkpads.
810 gst_pad_set_bufferpool_function (GstPad *pad,
811 GstPadBufferPoolFunction bufpool)
813 g_return_if_fail (pad != NULL);
814 g_return_if_fail (GST_IS_REAL_PAD (pad));
815 g_return_if_fail (GST_PAD_IS_SINK (pad));
817 GST_RPAD_BUFFERPOOLFUNC (pad) = bufpool;
818 GST_DEBUG (GST_CAT_PADS, "bufferpoolfunc for %s:%s set to %s",
819 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufpool));
823 * gst_pad_disconnect:
824 * @srcpad: the source #GstPad to disconnect.
825 * @sinkpad: the sink #GstPad to disconnect.
827 * Disconnects the source pad from the sink pad.
830 gst_pad_disconnect (GstPad *srcpad,
833 GstRealPad *realsrc, *realsink;
834 GstScheduler *src_sched, *sink_sched;
837 g_return_if_fail (srcpad != NULL);
838 g_return_if_fail (GST_IS_PAD (srcpad));
839 g_return_if_fail (sinkpad != NULL);
840 g_return_if_fail (GST_IS_PAD (sinkpad));
842 GST_INFO (GST_CAT_ELEMENT_PADS, "disconnecting %s:%s(%p) and %s:%s(%p)",
843 GST_DEBUG_PAD_NAME (srcpad), srcpad,
844 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
846 /* now we need to deal with the real/ghost stuff */
847 realsrc = GST_PAD_REALIZE (srcpad);
848 realsink = GST_PAD_REALIZE (sinkpad);
850 g_return_if_fail (GST_RPAD_PEER (realsrc) != NULL);
851 g_return_if_fail (GST_RPAD_PEER (realsink) == realsrc);
853 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
854 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
861 g_return_if_fail ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
862 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK));
864 /* get the schedulers before we disconnect */
865 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
866 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
868 /* first clear peers */
869 GST_RPAD_PEER (realsrc) = NULL;
870 GST_RPAD_PEER (realsink) = NULL;
872 /* reset the filters, both filters are refcounted once */
873 if (GST_RPAD_FILTER (realsrc)) {
874 gst_caps_unref (GST_RPAD_FILTER (realsrc));
875 GST_RPAD_FILTER (realsink) = NULL;
876 GST_RPAD_FILTER (realsrc) = NULL;
879 /* now tell the scheduler */
880 if (src_sched && src_sched == sink_sched) {
881 gst_scheduler_pad_disconnect (src_sched,
882 GST_PAD_CAST (realsrc), GST_PAD_CAST (realsink));
885 /* hold a reference, as they can go away in the signal handlers */
886 gst_object_ref (GST_OBJECT (realsrc));
887 gst_object_ref (GST_OBJECT (realsink));
889 /* fire off a signal to each of the pads telling them
890 * that they've been disconnected */
891 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_DISCONNECTED],
893 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_DISCONNECTED],
896 GST_INFO (GST_CAT_ELEMENT_PADS, "disconnected %s:%s and %s:%s",
897 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
899 gst_object_unref (GST_OBJECT (realsrc));
900 gst_object_unref (GST_OBJECT (realsink));
904 gst_pad_check_schedulers (GstRealPad *realsrc, GstRealPad *realsink)
906 GstScheduler *src_sched, *sink_sched;
907 gint num_decoupled = 0;
909 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
910 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
912 if (src_sched && sink_sched) {
913 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsrc), GST_ELEMENT_DECOUPLED))
915 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsink), GST_ELEMENT_DECOUPLED))
918 if (src_sched != sink_sched && num_decoupled != 1) {
926 * gst_pad_can_connect_filtered:
927 * @srcpad: the source #GstPad to connect.
928 * @sinkpad: the sink #GstPad to connect.
929 * @filtercaps: the filter #GstCaps.
931 * Checks if the source pad and the sink pad can be connected when constrained
932 * by the given filter caps.
934 * Returns: TRUE if the pads can be connected, FALSE otherwise.
937 gst_pad_can_connect_filtered (GstPad *srcpad, GstPad *sinkpad,
940 GstRealPad *realsrc, *realsink;
943 g_return_val_if_fail (srcpad != NULL, FALSE);
944 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
945 g_return_val_if_fail (sinkpad != NULL, FALSE);
946 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
948 /* now we need to deal with the real/ghost stuff */
949 realsrc = GST_PAD_REALIZE (srcpad);
950 realsink = GST_PAD_REALIZE (sinkpad);
952 g_return_val_if_fail (GST_RPAD_PEER (realsrc) == NULL, FALSE);
953 g_return_val_if_fail (GST_RPAD_PEER (realsink) == NULL, FALSE);
954 g_return_val_if_fail (GST_PAD_PARENT (realsrc) != NULL, FALSE);
955 g_return_val_if_fail (GST_PAD_PARENT (realsink) != NULL, FALSE);
957 if (!gst_pad_check_schedulers (realsrc, realsink)) {
958 g_warning ("connecting pads with different scheds requires "
959 "exactly one decoupled element (queue)");
963 /* check if the directions are compatible */
964 if (!(((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
965 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) ||
966 ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
967 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK))))
973 * gst_pad_can_connect:
974 * @srcpad: the source #GstPad to connect.
975 * @sinkpad: the sink #GstPad to connect.
977 * Checks if the source pad and the sink pad can be connected.
979 * Returns: TRUE if the pads can be connected, FALSE otherwise.
982 gst_pad_can_connect (GstPad *srcpad, GstPad *sinkpad)
984 return gst_pad_can_connect_filtered (srcpad, sinkpad, NULL);
988 * gst_pad_connect_filtered:
989 * @srcpad: the source #GstPad to connect.
990 * @sinkpad: the sink #GstPad to connect.
991 * @filtercaps: the filter #GstCaps.
993 * Connects the source pad and the sink pad can be connected, constrained
994 * by the given filter caps.
996 * Returns: TRUE if the pads have been connected, FALSE otherwise.
999 gst_pad_connect_filtered (GstPad *srcpad, GstPad *sinkpad, GstCaps *filtercaps)
1001 GstRealPad *realsrc, *realsink;
1002 GstScheduler *src_sched, *sink_sched;
1004 /* generic checks */
1005 g_return_val_if_fail (srcpad != NULL, FALSE);
1006 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1007 g_return_val_if_fail (sinkpad != NULL, FALSE);
1008 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1010 GST_INFO (GST_CAT_PADS, "trying to connect %s:%s and %s:%s",
1011 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1013 /* now we need to deal with the real/ghost stuff */
1014 realsrc = GST_PAD_REALIZE (srcpad);
1015 realsink = GST_PAD_REALIZE (sinkpad);
1017 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
1018 GST_INFO (GST_CAT_PADS, "*actually* connecting %s:%s and %s:%s",
1019 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1021 if (GST_RPAD_PEER (realsrc) != NULL)
1023 GST_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
1024 GST_DEBUG_PAD_NAME (realsrc));
1027 if (GST_RPAD_PEER (realsink) != NULL)
1029 GST_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1030 GST_DEBUG_PAD_NAME (realsink));
1033 if (GST_PAD_PARENT (realsrc) == NULL)
1035 GST_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1036 GST_DEBUG_PAD_NAME (realsrc));
1039 if (GST_PAD_PARENT (realsink) == NULL)
1041 GST_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1042 GST_DEBUG_PAD_NAME (realsrc));
1046 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1047 g_warning ("connecting pads with different scheds requires "
1048 "exactly one decoupled element (such as queue)");
1052 /* check for reversed directions and swap if necessary */
1053 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
1054 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
1055 GstRealPad *temppad;
1061 if (GST_PAD_PARENT (realsink) == NULL)
1062 if (GST_RPAD_DIRECTION (realsrc) != GST_PAD_SRC)
1064 GST_INFO (GST_CAT_PADS, "Real src pad %s:%s is not a source pad, failed",
1065 GST_DEBUG_PAD_NAME (realsrc));
1068 if (GST_RPAD_DIRECTION (realsink) != GST_PAD_SINK)
1070 GST_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1071 GST_DEBUG_PAD_NAME (realsink));
1074 /* first set peers */
1075 GST_RPAD_PEER (realsrc) = realsink;
1076 GST_RPAD_PEER (realsink) = realsrc;
1078 /* try to negotiate the pads, we don't need to clear the caps here */
1079 if (!gst_pad_try_reconnect_filtered_func (realsrc, realsink,
1080 filtercaps, FALSE)) {
1081 GST_DEBUG (GST_CAT_CAPS, "reconnect_filtered_func failed, can't connect");
1083 GST_RPAD_PEER (realsrc) = NULL;
1084 GST_RPAD_PEER (realsink) = NULL;
1089 /* fire off a signal to each of the pads telling them
1090 * that they've been connected */
1091 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_CONNECTED],
1093 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_CONNECTED],
1096 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
1097 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
1099 /* now tell the scheduler */
1100 if (src_sched && src_sched == sink_sched) {
1101 gst_scheduler_pad_connect (src_sched,
1102 GST_PAD_CAST (realsrc), GST_PAD_CAST (realsink));
1105 GST_INFO (GST_CAT_PADS, "connected %s:%s and %s:%s, successful",
1106 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1107 gst_caps_debug (gst_pad_get_caps (GST_PAD_CAST (realsrc)),
1108 "caps of newly connected src pad");
1115 * @srcpad: the source #GstPad to connect.
1116 * @sinkpad: the sink #GstPad to connect.
1118 * Connects the source pad to the sink pad.
1120 * Returns: TRUE if the pad could be connected, FALSE otherwise.
1123 gst_pad_connect (GstPad *srcpad, GstPad *sinkpad)
1125 return gst_pad_connect_filtered (srcpad, sinkpad, NULL);
1129 * gst_pad_set_parent:
1130 * @pad: a #GstPad to set the parent of.
1131 * @parent: the new parent #GstElement.
1133 * Sets the parent object of a pad.
1136 gst_pad_set_parent (GstPad *pad, GstElement *parent)
1138 g_return_if_fail (pad != NULL);
1139 g_return_if_fail (GST_IS_PAD (pad));
1140 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
1141 g_return_if_fail (parent != NULL);
1142 g_return_if_fail (GST_IS_OBJECT (parent));
1143 g_return_if_fail ((gpointer) pad != (gpointer) parent);
1145 gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (parent));
1149 * gst_pad_get_parent:
1150 * @pad: the #GstPad to get the parent of.
1152 * Gets the parent object of this pad.
1154 * Returns: the parent #GstElement.
1157 gst_pad_get_parent (GstPad *pad)
1159 g_return_val_if_fail (pad != NULL, NULL);
1160 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1162 return GST_PAD_PARENT (pad);
1166 * gst_pad_get_pad_template:
1167 * @pad: a #GstPad to get the pad template of.
1169 * Gets the pad template object of this pad.
1171 * Returns: the #GstPadTemplate from which this pad was instantiated.
1174 gst_pad_get_pad_template (GstPad *pad)
1176 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1178 return GST_PAD_PAD_TEMPLATE (pad);
1183 * gst_pad_get_scheduler:
1184 * @pad: a #GstPad to get the scheduler of.
1186 * Gets the scheduler of the pad. Since the pad does not
1187 * have a scheduler of its own, the scheduler of the parent
1188 * is taken. For decoupled pads, the scheduler of the peer
1191 * Returns: the #GstScheduler of the pad.
1194 gst_pad_get_scheduler (GstPad *pad)
1196 GstScheduler *scheduler = NULL;
1199 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1201 parent = gst_pad_get_parent (pad);
1203 if (GST_FLAG_IS_SET (parent, GST_ELEMENT_DECOUPLED)) {
1204 GstRealPad *peer = GST_RPAD_PEER (pad);
1207 scheduler = gst_element_get_scheduler (gst_pad_get_parent (GST_PAD_CAST (peer)));
1211 scheduler = gst_element_get_scheduler (parent);
1219 * gst_pad_get_real_parent:
1220 * @pad: a #GstPad to get the real parent of.
1222 * Gets the real parent object of this pad. If the pad
1223 * is a ghost pad, the actual owner of the real pad is
1224 * returned, as opposed to #gst_pad_get_parent().
1226 * Returns: the parent #GstElement.
1229 gst_pad_get_real_parent (GstPad *pad)
1231 g_return_val_if_fail (pad != NULL, NULL);
1232 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1234 return GST_PAD_PARENT (GST_PAD (GST_PAD_REALIZE (pad)));
1238 * gst_pad_add_ghost_pad:
1239 * @pad: a #GstPad to attach the ghost pad to.
1240 * @ghostpad: the ghost #GstPad to to the pad.
1242 * Adds a ghost pad to a pad.
1245 gst_pad_add_ghost_pad (GstPad *pad,
1248 GstRealPad *realpad;
1250 g_return_if_fail (pad != NULL);
1251 g_return_if_fail (GST_IS_PAD (pad));
1252 g_return_if_fail (ghostpad != NULL);
1253 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1255 realpad = GST_PAD_REALIZE (pad);
1257 realpad->ghostpads = g_list_prepend (realpad->ghostpads, ghostpad);
1262 * gst_pad_remove_ghost_pad:
1263 * @pad: a #GstPad to remove the ghost pad from.
1264 * @ghostpad: the ghost #GstPad to remove from the pad.
1266 * Removes a ghost pad from a pad.
1269 gst_pad_remove_ghost_pad (GstPad *pad,
1272 GstRealPad *realpad;
1274 g_return_if_fail (pad != NULL);
1275 g_return_if_fail (GST_IS_PAD (pad));
1276 g_return_if_fail (ghostpad != NULL);
1277 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1279 realpad = GST_PAD_REALIZE (pad);
1281 realpad->ghostpads = g_list_remove (realpad->ghostpads, ghostpad);
1285 * gst_pad_get_ghost_pad_list:
1286 * @pad: a #GstPad to get the ghost pads of.
1288 * Gets the ghost pads of this pad.
1290 * Returns: a #GList of ghost pads.
1293 gst_pad_get_ghost_pad_list (GstPad *pad)
1295 g_return_val_if_fail (pad != NULL, NULL);
1296 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1298 return GST_PAD_REALIZE(pad)->ghostpads;
1301 /* an internal caps negotiation helper function:
1303 * 1. optionally calls the pad connect function with the provided caps
1304 * 2. deals with the result code of the connect function
1305 * 3. sets fixed caps on the pad.
1307 static GstPadConnectReturn
1308 gst_pad_try_set_caps_func (GstRealPad *pad, GstCaps *caps, gboolean notify)
1310 GstCaps *oldcaps, *allowed = NULL;
1311 GstPadTemplate *template;
1312 GstElement *parent = GST_PAD_PARENT (pad);
1314 g_return_val_if_fail (pad != NULL, GST_PAD_CONNECT_REFUSED);
1315 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_CONNECT_REFUSED);
1317 /* if this pad has a parent and the parent is not READY, delay the
1319 if (parent && GST_STATE (parent) < GST_STATE_READY)
1321 GST_DEBUG (GST_CAT_CAPS, "parent %s of pad %s:%s is not READY",
1322 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (pad));
1323 return GST_PAD_CONNECT_DELAYED;
1326 GST_INFO (GST_CAT_CAPS, "trying to set caps %p on pad %s:%s",
1327 caps, GST_DEBUG_PAD_NAME (pad));
1329 /* first see if we have to check against a filter */
1330 if (!(allowed = GST_RPAD_FILTER (pad))) {
1331 /* no filter, make sure we check against the padtemplate then */
1332 if ((template = gst_pad_get_pad_template (GST_PAD_CAST (pad)))) {
1333 allowed = gst_pad_template_get_caps (template);
1337 /* do we have to check the caps against something? */
1339 GstCaps *intersection;
1341 /* check against calculated caps */
1342 intersection = gst_caps_intersect (caps, allowed);
1344 /* oops, empty intersection, caps don"t have anything in common */
1345 if (!intersection) {
1346 GST_INFO (GST_CAT_CAPS, "caps did not intersect with %s:%s's allowed caps",
1347 GST_DEBUG_PAD_NAME (pad));
1348 gst_caps_debug (caps, "caps themselves (attemped to set)");
1349 gst_caps_debug (allowed,
1350 "allowed caps that did not agree with caps");
1351 return GST_PAD_CONNECT_REFUSED;
1353 /* caps checks out fine, we can unref the intersection now */
1354 gst_caps_unref (intersection);
1355 /* given that the caps are fixed, we know that their intersection with the
1356 * padtemplate caps is the same as caps itself */
1359 /* we need to notify the connect function */
1360 if (notify && GST_RPAD_CONNECTFUNC (pad)) {
1361 GstPadConnectReturn res;
1362 gchar *debug_string;
1364 GST_INFO (GST_CAT_CAPS, "calling connect function on pad %s:%s",
1365 GST_DEBUG_PAD_NAME (pad));
1367 /* call the connect function */
1368 res = GST_RPAD_CONNECTFUNC (pad) (GST_PAD (pad), caps);
1371 case GST_PAD_CONNECT_REFUSED:
1372 debug_string = "REFUSED";
1374 case GST_PAD_CONNECT_OK:
1375 debug_string = "OK";
1377 case GST_PAD_CONNECT_DONE:
1378 debug_string = "DONE";
1380 case GST_PAD_CONNECT_DELAYED:
1381 debug_string = "DELAYED";
1384 g_warning ("unknown return code from connect function of pad %s:%s %d",
1385 GST_DEBUG_PAD_NAME (pad), res);
1386 return GST_PAD_CONNECT_REFUSED;
1389 GST_INFO (GST_CAT_CAPS,
1390 "got reply %s (%d) from connect function on pad %s:%s",
1391 debug_string, res, GST_DEBUG_PAD_NAME (pad));
1393 /* done means the connect function called another caps negotiate function
1394 * on this pad that succeeded, we dont need to continue */
1395 if (res == GST_PAD_CONNECT_DONE) {
1396 GST_INFO (GST_CAT_CAPS, "pad %s:%s is done", GST_DEBUG_PAD_NAME (pad));
1397 return GST_PAD_CONNECT_DONE;
1399 if (res == GST_PAD_CONNECT_REFUSED) {
1400 GST_INFO (GST_CAT_CAPS, "pad %s:%s doesn't accept caps",
1401 GST_DEBUG_PAD_NAME (pad));
1402 return GST_PAD_CONNECT_REFUSED;
1405 /* we can only set caps on the pad if they are fixed */
1406 if (GST_CAPS_IS_FIXED (caps)) {
1408 GST_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 oldcaps = GST_PAD_CAPS (pad);
1412 if (caps) gst_caps_ref (caps);
1413 GST_PAD_CAPS (pad) = caps;
1414 if (oldcaps) gst_caps_unref (oldcaps);
1416 g_object_notify (G_OBJECT (pad), "caps");
1419 GST_INFO (GST_CAT_CAPS,
1420 "caps are not fixed on pad %s:%s, not setting them yet",
1421 GST_DEBUG_PAD_NAME (pad));
1423 return GST_PAD_CONNECT_OK;
1427 * gst_pad_try_set_caps:
1428 * @pad: a #GstPad to try to set the caps on.
1429 * @caps: the #GstCaps to set.
1431 * Tries to set the caps on the given pad.
1433 * Returns: A GstPadConnectReturn value indicating whether the caps
1437 gst_pad_try_set_caps (GstPad *pad, GstCaps *caps)
1439 GstRealPad *peer, *realpad;
1440 GstPadConnectReturn set_retval;
1442 realpad = GST_PAD_REALIZE (pad);
1443 peer = GST_RPAD_PEER (realpad);
1445 GST_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 /* setting non fixed caps on a pad is not allowed */
1451 if (!GST_CAPS_IS_FIXED (caps)) {
1452 GST_INFO (GST_CAT_CAPS,
1453 "trying to set unfixed caps on pad %s:%s, not allowed",
1454 GST_DEBUG_PAD_NAME (realpad));
1455 g_warning ("trying to set non fixed caps on pad %s:%s, not allowed",
1456 GST_DEBUG_PAD_NAME (realpad));
1457 gst_caps_debug (caps, "unfixed caps");
1458 return GST_PAD_CONNECT_DELAYED;
1461 /* if we have a peer try to set the caps, notifying the peerpad
1462 * if it has a connect function */
1463 if (peer && ((set_retval = gst_pad_try_set_caps_func (peer, caps, TRUE)) <= 0))
1465 GST_INFO (GST_CAT_CAPS, "tried to set caps on peerpad %s:%s but couldn't, return value %d",
1466 GST_DEBUG_PAD_NAME (peer), set_retval);
1470 /* then try to set our own caps, we don't need to be notified */
1471 if ((set_retval = gst_pad_try_set_caps_func (realpad, caps, FALSE)) <= 0)
1473 GST_INFO (GST_CAT_CAPS, "tried to set own caps on pad %s:%s but couldn't, return value %d",
1474 GST_DEBUG_PAD_NAME (realpad), set_retval);
1477 GST_INFO (GST_CAT_CAPS, "succeeded setting caps %p on pad %s:%s, return value %d",
1478 caps, GST_DEBUG_PAD_NAME (realpad), set_retval);
1479 g_assert (GST_PAD_CAPS (pad));
1484 /* this is a caps negotiation convenience routine, it:
1486 * 1. optionally clears any pad caps.
1487 * 2. calculates the intersection between the two pad tamplate/getcaps caps.
1488 * 3. calculates the intersection with the (optional) filtercaps.
1489 * 4. stores the intersection in the pad filter.
1490 * 5. stores the app filtercaps in the pad appfilter.
1491 * 6. starts the caps negotiation.
1494 gst_pad_try_reconnect_filtered_func (GstRealPad *srcpad, GstRealPad *sinkpad,
1495 GstCaps *filtercaps, gboolean clear)
1497 GstCaps *srccaps, *sinkcaps;
1498 GstCaps *intersection = NULL;
1499 GstRealPad *realsrc, *realsink;
1501 realsrc = GST_PAD_REALIZE (srcpad);
1502 realsink = GST_PAD_REALIZE (sinkpad);
1504 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1505 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1507 /* optinally clear the caps */
1509 GST_INFO (GST_CAT_PADS,
1510 "start reconnect filtered %s:%s and %s:%s, clearing caps",
1511 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1513 GST_PAD_CAPS (GST_PAD (realsrc)) = NULL;
1514 GST_PAD_CAPS (GST_PAD (realsink)) = NULL;
1517 GST_INFO (GST_CAT_PADS, "start reconnect filtered %s:%s and %s:%s",
1518 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1521 srccaps = gst_pad_get_caps (GST_PAD (realsrc));
1522 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1523 GST_DEBUG_PAD_NAME (realsrc));
1524 gst_caps_debug (srccaps, "caps of src pad (pre-reconnect)");
1525 sinkcaps = gst_pad_get_caps (GST_PAD (realsink));
1526 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1527 GST_DEBUG_PAD_NAME (realsink));
1528 gst_caps_debug (sinkcaps, "caps of sink pad (pre-reconnect)");
1530 /* first take the intersection of the pad caps */
1531 intersection = gst_caps_intersect (srccaps, sinkcaps);
1532 gst_caps_debug (intersection, "caps of intersection");
1534 /* if we have no intersection but one of the caps was not NULL.. */
1535 if (!intersection && (srccaps || sinkcaps)) {
1536 /* the intersection is NULL but the pad caps were not both NULL,
1537 * this means they have no common format */
1538 GST_INFO (GST_CAT_PADS, "pads %s:%s and %s:%s have no common type",
1539 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1541 } else if (intersection) {
1542 GST_INFO (GST_CAT_PADS, "pads %s:%s and %s:%s intersected to %s caps",
1543 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink),
1544 ((intersection && GST_CAPS_IS_FIXED (intersection)) ? "fixed" : "variable"));
1546 /* then filter this against the app filter */
1548 GstCaps *filtered_intersection = gst_caps_intersect (intersection,
1551 /* get rid of the old intersection here */
1552 gst_caps_unref (intersection);
1554 if (!filtered_intersection) {
1555 GST_INFO (GST_CAT_PADS,
1556 "filtered connection between pads %s:%s and %s:%s is empty",
1557 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1560 intersection = filtered_intersection;
1562 /* keep a reference to the app caps */
1563 GST_RPAD_APPFILTER (realsink) = filtercaps;
1564 GST_RPAD_APPFILTER (realsrc) = filtercaps;
1567 GST_DEBUG (GST_CAT_CAPS, "setting filter for connection to:");
1568 gst_caps_debug (intersection, "filter for connection");
1570 /* both the app filter and the filter, while stored on both peer pads,
1571 * are equal to the same thing on both */
1572 GST_RPAD_FILTER (realsrc) = intersection;
1573 GST_RPAD_FILTER (realsink) = intersection;
1575 return gst_pad_perform_negotiate (GST_PAD (realsrc), GST_PAD (realsink));
1579 * gst_pad_perform_negotiate:
1580 * @srcpad: the source #GstPad.
1581 * @sinkpad: the sink #GstPad.
1583 * Tries to negotiate the pads.
1585 * Returns: TRUE if the pads were succesfully negotiated, FALSE otherwise.
1588 gst_pad_perform_negotiate (GstPad *srcpad, GstPad *sinkpad)
1590 GstCaps *intersection, *filtered_intersection;
1591 GstRealPad *realsrc, *realsink;
1592 GstCaps *srccaps, *sinkcaps, *filter;
1594 g_return_val_if_fail (srcpad != NULL, FALSE);
1595 g_return_val_if_fail (sinkpad != NULL, FALSE);
1597 realsrc = GST_PAD_REALIZE (srcpad);
1598 realsink = GST_PAD_REALIZE (sinkpad);
1600 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1601 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1603 filter = GST_RPAD_APPFILTER (realsrc);
1605 GST_INFO (GST_CAT_PADS, "dumping filter for connection %s:%s-%s:%s",
1606 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1607 gst_caps_debug (filter, "connection filter caps");
1610 /* calculate the new caps here */
1611 srccaps = gst_pad_get_caps (GST_PAD (realsrc));
1612 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1613 GST_DEBUG_PAD_NAME (realsrc));
1614 gst_caps_debug (srccaps,
1615 "src caps, awaiting negotiation, after applying filter");
1616 sinkcaps = gst_pad_get_caps (GST_PAD (realsink));
1617 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1618 GST_DEBUG_PAD_NAME (realsink));
1619 gst_caps_debug (sinkcaps,
1620 "sink caps, awaiting negotiation, after applying filter");
1621 intersection = gst_caps_intersect (srccaps, sinkcaps);
1622 filtered_intersection = gst_caps_intersect (intersection, filter);
1623 if (filtered_intersection) {
1624 gst_caps_unref (intersection);
1625 intersection = filtered_intersection;
1628 /* no negotiation is performed if the pads have filtercaps */
1630 GstPadConnectReturn res;
1632 res = gst_pad_try_set_caps_func (realsrc, intersection, TRUE);
1633 if (res == GST_PAD_CONNECT_REFUSED)
1635 if (res == GST_PAD_CONNECT_DONE)
1638 res = gst_pad_try_set_caps_func (realsink, intersection, TRUE);
1639 if (res == GST_PAD_CONNECT_REFUSED)
1641 if (res == GST_PAD_CONNECT_DONE)
1648 * gst_pad_try_reconnect_filtered:
1649 * @srcpad: the source #GstPad to reconnect.
1650 * @sinkpad: the sink #GstPad to reconnect.
1651 * @filtercaps: the #GstPad to use as a filter in the reconnection.
1653 * Tries to reconnect the given source and sink pad, constrained by the given
1656 * Returns: TRUE if the pads were succesfully renegotiated, FALSE otherwise.
1659 gst_pad_try_reconnect_filtered (GstPad *srcpad, GstPad *sinkpad,
1660 GstCaps *filtercaps)
1662 GstRealPad *realsrc, *realsink;
1664 g_return_val_if_fail (srcpad != NULL, FALSE);
1665 g_return_val_if_fail (sinkpad != NULL, FALSE);
1667 realsrc = GST_PAD_REALIZE (srcpad);
1668 realsink = GST_PAD_REALIZE (sinkpad);
1670 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1671 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1673 return gst_pad_try_reconnect_filtered_func (realsrc, realsink,
1678 * gst_pad_reconnect_filtered:
1679 * @srcpad: the source #GstPad to reconnect.
1680 * @sinkpad: the sink #GstPad to reconnect.
1681 * @filtercaps: the #GstPad to use as a filter in the reconnection.
1683 * Reconnects the given source and sink pad, constrained by the given
1684 * capabilities. If the reconnection fails, the pads are disconnected
1685 * and FALSE is returned.
1687 * Returns: TRUE if the pads were succesfully reconnected, FALSE otherwise.
1690 gst_pad_reconnect_filtered (GstPad *srcpad, GstPad *sinkpad,
1691 GstCaps *filtercaps)
1693 GstRealPad *realsrc, *realsink;
1695 g_return_val_if_fail (srcpad != NULL, FALSE);
1696 g_return_val_if_fail (sinkpad != NULL, FALSE);
1698 realsrc = GST_PAD_REALIZE (srcpad);
1699 realsink = GST_PAD_REALIZE (sinkpad);
1701 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1702 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1704 if (! gst_pad_try_reconnect_filtered_func (realsrc, realsink,
1705 filtercaps, TRUE)) {
1706 gst_pad_disconnect (srcpad, GST_PAD (GST_PAD_PEER (srcpad)));
1713 * gst_pad_proxy_connect:
1714 * @pad: a #GstPad to proxy to.
1715 * @caps: the #GstCaps to use in proxying.
1717 * Proxies the connect function to the specified pad.
1719 * Returns: TRUE if the peer pad accepted the caps, FALSE otherwise.
1722 gst_pad_proxy_connect (GstPad *pad, GstCaps *caps)
1724 GstRealPad *peer, *realpad;
1726 realpad = GST_PAD_REALIZE (pad);
1728 peer = GST_RPAD_PEER (realpad);
1730 GST_INFO (GST_CAT_CAPS, "proxy connect to pad %s:%s",
1731 GST_DEBUG_PAD_NAME (realpad));
1733 if (peer && gst_pad_try_set_caps_func (peer, caps, TRUE) < 0)
1734 return GST_PAD_CONNECT_REFUSED;
1735 if (gst_pad_try_set_caps_func (realpad, caps, FALSE) < 0)
1736 return GST_PAD_CONNECT_REFUSED;
1738 return GST_PAD_CONNECT_OK;
1743 * @pad: a #GstPad to get the capabilities of.
1745 * Gets the capabilities of this pad.
1747 * Returns: the #GstCaps of this pad.
1750 gst_pad_get_caps (GstPad *pad)
1752 GstRealPad *realpad;
1754 g_return_val_if_fail (pad != NULL, NULL);
1755 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1757 realpad = GST_PAD_REALIZE (pad);
1759 GST_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1760 GST_DEBUG_PAD_NAME (realpad), realpad);
1762 if (GST_PAD_CAPS (realpad)) {
1763 GST_DEBUG (GST_CAT_CAPS, "using pad real caps %p", GST_PAD_CAPS (realpad));
1764 return GST_PAD_CAPS (realpad);
1766 else if GST_RPAD_GETCAPSFUNC (realpad) {
1767 GST_DEBUG (GST_CAT_CAPS, "using pad get function");
1768 return GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD_CAST (realpad), NULL);
1770 else if (GST_PAD_PAD_TEMPLATE (realpad)) {
1771 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (realpad);
1772 GST_DEBUG (GST_CAT_CAPS, "using pad template %p with caps %p",
1773 templ, GST_PAD_TEMPLATE_CAPS (templ));
1774 return GST_PAD_TEMPLATE_CAPS (templ);
1776 GST_DEBUG (GST_CAT_CAPS, "pad has no caps");
1782 * gst_pad_get_pad_template_caps:
1783 * @pad: a #GstPad to get the template capabilities from.
1785 * Gets the template capabilities of this pad.
1787 * Returns: the template #GstCaps of this pad.
1790 gst_pad_get_pad_template_caps (GstPad *pad)
1792 g_return_val_if_fail (pad != NULL, NULL);
1793 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1795 if (GST_PAD_PAD_TEMPLATE (pad))
1796 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
1802 * gst_pad_template_get_caps_by_name:
1803 * @templ: a #GstPadTemplate to get the capabilities of.
1804 * @name: the name of the capability to get.
1806 * Gets the capability with the given name from this pad template.
1808 * Returns: the #GstCaps, or NULL if not found or in case of an error.
1811 gst_pad_template_get_caps_by_name (GstPadTemplate *templ, const gchar *name)
1815 g_return_val_if_fail (templ != NULL, NULL);
1817 caps = GST_PAD_TEMPLATE_CAPS (templ);
1821 return gst_caps_get_by_name (caps, name);
1825 * gst_pad_check_compatibility:
1826 * @srcpad: the source #GstPad to check.
1827 * @sinkpad: the sink #GstPad to check against.
1829 * Checks if two pads have compatible capabilities.
1831 * Returns: TRUE if they are compatible or if the capabilities
1832 * could not be checked
1835 gst_pad_check_compatibility (GstPad *srcpad, GstPad *sinkpad)
1837 g_return_val_if_fail (srcpad != NULL, FALSE);
1838 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1839 g_return_val_if_fail (sinkpad != NULL, FALSE);
1840 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1842 if (GST_PAD_CAPS (srcpad) && GST_PAD_CAPS (sinkpad)) {
1843 if (!gst_caps_is_always_compatible (GST_PAD_CAPS (srcpad),
1844 GST_PAD_CAPS (sinkpad))) {
1852 GST_DEBUG (GST_CAT_PADS,
1853 "could not check capabilities of pads (%s:%s) and (%s:%s) %p %p",
1854 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
1855 GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad));
1862 * @pad: a #GstPad to get the peer of.
1864 * Gets the peer pad of this pad.
1866 * Returns: the peer #GstPad.
1869 gst_pad_get_peer (GstPad *pad)
1871 g_return_val_if_fail (pad != NULL, NULL);
1872 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1874 return GST_PAD (GST_PAD_PEER (pad));
1878 * gst_pad_get_allowed_caps:
1879 * @pad: a #GstPad to get the allowed caps of.
1881 * Gets the capabilities of the allowed media types that can
1882 * flow through this pad. The caller must free the resulting caps.
1884 * Returns: a newly allocated copy of the allowed #GstCaps.
1887 gst_pad_get_allowed_caps (GstPad *pad)
1889 g_return_val_if_fail (pad != NULL, NULL);
1890 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1892 GST_DEBUG (GST_CAT_PROPERTIES, "get allowed caps of %s:%s",
1893 GST_DEBUG_PAD_NAME (pad));
1895 return gst_caps_copy (GST_RPAD_FILTER (pad));
1899 * gst_pad_recalc_allowed_caps:
1900 * @pad: a #GstPad to recalculate the capablities of.
1902 * Attempts to reconnect the pad to its peer through its filter,
1903 * set with gst_pad_[re]connect_filtered. This function is useful when a
1904 * plug-in has new capabilities on a pad and wants to notify the peer.
1906 * Returns: TRUE on success, FALSE otherwise.
1909 gst_pad_recalc_allowed_caps (GstPad *pad)
1913 g_return_val_if_fail (pad != NULL, FALSE);
1914 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1916 GST_DEBUG (GST_CAT_PROPERTIES, "set allowed caps of %s:%s",
1917 GST_DEBUG_PAD_NAME (pad));
1919 peer = GST_RPAD_PEER (pad);
1921 return gst_pad_try_reconnect_filtered (pad, GST_PAD (peer),
1922 GST_RPAD_APPFILTER (pad));
1928 * gst_pad_get_bufferpool:
1929 * @pad: a #GstPad to get the bufferpool from.
1931 * Gets the bufferpool of the peer pad of the given pad.Note that
1932 * a bufferpool can only be obtained from a srcpad.
1934 * Returns: the #GstBufferPool, or NULL in case of an error.
1937 gst_pad_get_bufferpool (GstPad *pad)
1941 g_return_val_if_fail (pad != NULL, NULL);
1942 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1943 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
1945 peer = GST_RPAD_PEER (pad);
1950 GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
1952 if (peer->bufferpoolfunc) {
1953 GST_DEBUG (GST_CAT_PADS,
1954 "calling bufferpoolfunc &%s (@%p) of peer pad %s:%s",
1955 GST_DEBUG_FUNCPTR_NAME (peer->bufferpoolfunc),
1956 &peer->bufferpoolfunc, GST_DEBUG_PAD_NAME (((GstPad*) peer)));
1957 return (peer->bufferpoolfunc) (((GstPad*) peer));
1959 GST_DEBUG (GST_CAT_PADS, "no bufferpoolfunc for peer pad %s:%s at %p",
1960 GST_DEBUG_PAD_NAME (((GstPad*) peer)), &peer->bufferpoolfunc);
1966 gst_real_pad_dispose (GObject *object)
1968 GstPad *pad = GST_PAD (object);
1970 /* No connected pad can ever be disposed.
1971 * It has to have a parent to be connected
1972 * and a parent would hold a reference */
1973 g_assert (GST_PAD_PEER (pad) == NULL);
1975 GST_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s", GST_DEBUG_PAD_NAME(pad));
1977 if (GST_PAD_PAD_TEMPLATE (pad)){
1978 GST_DEBUG (GST_CAT_REFCOUNTING, "unreffing padtemplate'%s'",
1979 GST_OBJECT_NAME (GST_PAD_PAD_TEMPLATE (pad)));
1980 gst_object_unref (GST_OBJECT (GST_PAD_PAD_TEMPLATE (pad)));
1981 GST_PAD_PAD_TEMPLATE (pad) = NULL;
1984 /* we destroy the ghostpads, because they are nothing without the real pad */
1985 if (GST_REAL_PAD (pad)->ghostpads) {
1986 GList *orig, *ghostpads;
1988 orig = ghostpads = g_list_copy (GST_REAL_PAD (pad)->ghostpads);
1991 GstPad *ghostpad = GST_PAD (ghostpads->data);
1993 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))){
1994 GST_DEBUG (GST_CAT_REFCOUNTING, "removing ghost pad from element '%s'",
1995 GST_OBJECT_NAME (GST_OBJECT_PARENT (ghostpad)));
1997 gst_element_remove_ghost_pad (GST_ELEMENT (GST_OBJECT_PARENT (ghostpad)), GST_PAD (ghostpad));
1999 ghostpads = g_list_next (ghostpads);
2002 g_list_free (GST_REAL_PAD(pad)->ghostpads);
2005 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
2006 GST_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
2007 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
2009 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
2012 G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
2016 #ifndef GST_DISABLE_LOADSAVE
2017 /* FIXME: why isn't this on a GstElement ? */
2019 * gst_pad_load_and_connect:
2020 * @self: an #xmlNodePtr to read the description from.
2021 * @parent: the #GstObject element that owns the pad.
2023 * Reads the pad definition from the XML node and connects the given pad
2024 * in the element to a pad of an element up in the hierarchy.
2027 gst_pad_load_and_connect (xmlNodePtr self, GstObject *parent)
2029 xmlNodePtr field = self->xmlChildrenNode;
2030 GstPad *pad = NULL, *targetpad;
2034 GstObject *grandparent;
2037 if (!strcmp (field->name, "name")) {
2038 pad = gst_element_get_pad (GST_ELEMENT (parent),
2039 xmlNodeGetContent (field));
2041 else if (!strcmp(field->name, "peer")) {
2042 peer = xmlNodeGetContent (field);
2044 field = field->next;
2046 g_return_if_fail (pad != NULL);
2048 if (peer == NULL) return;
2050 split = g_strsplit (peer, ".", 2);
2052 if (split[0] == NULL || split[1] == NULL) {
2053 GST_DEBUG (GST_CAT_XML,
2054 "Could not parse peer '%s' for pad %s:%s, leaving unconnected",
2055 peer, GST_DEBUG_PAD_NAME (pad));
2059 g_return_if_fail (split[0] != NULL);
2060 g_return_if_fail (split[1] != NULL);
2062 grandparent = gst_object_get_parent (parent);
2064 if (grandparent && GST_IS_BIN (grandparent)) {
2065 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2070 if (target == NULL) goto cleanup;
2072 targetpad = gst_element_get_pad (target, split[1]);
2074 if (targetpad == NULL) goto cleanup;
2076 gst_pad_connect (pad, targetpad);
2083 * gst_pad_save_thyself:
2084 * @pad: a #GstPad to save.
2085 * @parent: the parent #xmlNodePtr to save the description in.
2087 * Saves the pad into an xml representation.
2089 * Returns: the #xmlNodePtr representation of the pad.
2092 gst_pad_save_thyself (GstObject *object, xmlNodePtr parent)
2094 GstRealPad *realpad;
2097 g_return_val_if_fail (GST_IS_REAL_PAD (object), NULL);
2099 realpad = GST_REAL_PAD (object);
2101 xmlNewChild (parent, NULL, "name", GST_PAD_NAME (realpad));
2102 if (GST_RPAD_PEER (realpad) != NULL) {
2105 peer = GST_PAD (GST_RPAD_PEER (realpad));
2106 /* first check to see if the peer's parent's parent is the same */
2107 /* we just save it off */
2108 content = g_strdup_printf ("%s.%s",
2109 GST_OBJECT_NAME (GST_PAD_PARENT (peer)),
2110 GST_PAD_NAME (peer));
2111 xmlNewChild (parent, NULL, "peer", content);
2114 xmlNewChild (parent, NULL, "peer", "");
2119 /* FIXME: shouldn't pad and ghost be switched ?
2122 * gst_ghost_pad_save_thyself:
2123 * @pad: a ghost #GstPad to save.
2124 * @parent: the parent #xmlNodePtr to save the description in.
2126 * Saves the ghost pad into an xml representation.
2128 * Returns: the #xmlNodePtr representation of the pad.
2131 gst_ghost_pad_save_thyself (GstPad *pad, xmlNodePtr parent)
2135 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2137 self = xmlNewChild (parent, NULL, "ghostpad", NULL);
2138 xmlNewChild (self, NULL, "name", GST_PAD_NAME (pad));
2139 xmlNewChild (self, NULL, "parent", GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
2141 /* FIXME FIXME FIXME! */
2145 #endif /* GST_DISABLE_LOADSAVE */
2149 * @pad: a #GstPad to push the buffer out of.
2150 * @buf: the #GstBuffer to push.
2152 * Pushes a buffer to the peer of the pad.
2155 gst_pad_push (GstPad *pad, GstBuffer *buf)
2157 GstRealPad *peer = GST_RPAD_PEER (pad);
2159 GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
2161 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
2163 if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), GST_DATA (buf)))
2167 g_warning ("push on pad %s:%s but it is unconnected",
2168 GST_DEBUG_PAD_NAME (pad));
2171 if (peer->chainhandler) {
2173 GST_DEBUG (GST_CAT_DATAFLOW,
2174 "calling chainhandler &%s of peer pad %s:%s",
2175 GST_DEBUG_FUNCPTR_NAME (peer->chainhandler),
2176 GST_DEBUG_PAD_NAME (GST_PAD (peer)));
2177 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, GST_DATA (buf)))
2180 (peer->chainhandler) (GST_PAD_CAST (peer), buf);
2184 g_warning ("trying to push a NULL buffer on pad %s:%s",
2185 GST_DEBUG_PAD_NAME (peer));
2190 g_warning ("internal error: push on pad %s:%s but it has no chainhandler",
2191 GST_DEBUG_PAD_NAME (peer));
2194 /* clean up the mess here */
2195 if (buf != NULL) gst_data_unref (GST_DATA (buf));
2200 * @pad: a #GstPad to pull a buffer from.
2202 * Pulls a buffer from the peer pad.
2204 * Returns: a new #GstBuffer from the peer pad.
2207 gst_pad_pull (GstPad *pad)
2211 peer = GST_RPAD_PEER (pad);
2213 GST_DEBUG_ENTER("(%s:%s)",GST_DEBUG_PAD_NAME(pad));
2215 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK, NULL);
2218 gst_element_error (GST_PAD_PARENT (pad),
2219 "pull on pad %s:%s but it was unconnected",
2220 GST_ELEMENT_NAME (GST_PAD_PARENT (pad)),
2221 GST_PAD_NAME (pad), NULL);
2224 if (peer->gethandler) {
2227 GST_DEBUG (GST_CAT_DATAFLOW, "calling gethandler %s of peer pad %s:%s",
2228 GST_DEBUG_FUNCPTR_NAME (peer->gethandler),
2229 GST_DEBUG_PAD_NAME (peer));
2231 buf = (peer->gethandler) (GST_PAD_CAST (peer));
2234 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, GST_DATA (buf)))
2240 /* no null buffers allowed */
2241 gst_element_error (GST_PAD_PARENT (pad),
2242 "NULL buffer during pull on %s:%s",
2243 GST_DEBUG_PAD_NAME (pad), NULL);
2246 gst_element_error (GST_PAD_PARENT (pad),
2247 "internal error: pull on pad %s:%s "
2248 "but the peer pad %s:%s has no gethandler",
2249 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer),
2258 * @padlist: a #GList of pads.
2260 * Waits for a buffer on any of the list of pads.
2262 * Returns: the #GstPad that has a buffer available.
2263 * Use #gst_pad_pull() to get the buffer.
2266 gst_pad_select (GList *padlist)
2270 pad = gst_scheduler_pad_select (GST_PAD_PARENT (padlist->data)->sched,
2277 * @pad: a first #GstPad to perform the select on.
2278 * @...: A NULL-terminated list of more pads to select on.
2280 * Waits for a buffer on the given set of pads.
2282 * Returns: the #GstPad that has a buffer available.
2283 * Use #gst_pad_pull() to get the buffer.
2286 gst_pad_selectv (GstPad *pad, ...)
2289 GList *padlist = NULL;
2295 va_start (var_args, pad);
2298 padlist = g_list_prepend (padlist, pad);
2299 pad = va_arg (var_args, GstPad *);
2301 result = gst_pad_select (padlist);
2302 g_list_free (padlist);
2309 /************************************************************************
2314 static void gst_pad_template_class_init (GstPadTemplateClass *klass);
2315 static void gst_pad_template_init (GstPadTemplate *templ);
2318 gst_pad_template_get_type (void)
2320 static GType padtemplate_type = 0;
2322 if (!padtemplate_type) {
2323 static const GTypeInfo padtemplate_info = {
2324 sizeof (GstPadTemplateClass), NULL, NULL,
2325 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
2326 sizeof (GstPadTemplate),
2328 (GInstanceInitFunc) gst_pad_template_init, NULL
2330 padtemplate_type = g_type_register_static(GST_TYPE_OBJECT, "GstPadTemplate",
2331 &padtemplate_info, 0);
2333 return padtemplate_type;
2337 gst_pad_template_class_init (GstPadTemplateClass *klass)
2339 GObjectClass *gobject_class;
2340 GstObjectClass *gstobject_class;
2342 gobject_class = (GObjectClass*) klass;
2343 gstobject_class = (GstObjectClass*) klass;
2345 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
2347 gst_pad_template_signals[TEMPL_PAD_CREATED] =
2348 g_signal_new ("pad_created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
2349 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
2350 NULL, NULL, gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
2353 gstobject_class->path_string_separator = "*";
2357 gst_pad_template_init (GstPadTemplate *templ)
2361 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
2363 * SOMETIMES padtemplates can do whatever they want, they are provided by the
2365 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
2366 * 'sink%d' template is automatically selected), so we need to restrict their
2370 name_is_valid (const gchar *name, GstPadPresence presence)
2374 if (presence == GST_PAD_ALWAYS) {
2375 if (strchr (name, '%')) {
2376 g_warning ("invalid name template %s: conversion specifications are not"
2377 " allowed for GST_PAD_ALWAYS padtemplates", name);
2380 } else if (presence == GST_PAD_REQUEST) {
2381 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
2382 g_warning ("invalid name template %s: only one conversion specification"
2383 " allowed in GST_PAD_REQUEST padtemplate", name);
2386 if (str && (*(str+1) != 's' && *(str+1) != 'd')) {
2387 g_warning ("invalid name template %s: conversion specification must be of"
2388 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
2391 if (str && (*(str+2) != '\0')) {
2392 g_warning ("invalid name template %s: conversion specification must"
2393 " appear at the end of the GST_PAD_REQUEST padtemplate name",
2403 * gst_pad_template_new:
2404 * @name_template: the name template.
2405 * @direction: the #GstPadDirection of the template.
2406 * @presence: the #GstPadPresence of the pad.
2407 * @caps: a #GstCaps set for the template.
2408 * @...: a NULL-terminated list of #GstCaps.
2410 * Creates a new pad template with a name according to the given template
2411 * and with the given arguments.
2413 * Returns: a new #GstPadTemplate.
2416 gst_pad_template_new (const gchar *name_template,
2417 GstPadDirection direction, GstPadPresence presence,
2420 GstPadTemplate *new;
2422 GstCaps *thecaps = NULL;
2424 g_return_val_if_fail (name_template != NULL, NULL);
2426 if (!name_is_valid (name_template, presence))
2429 new = g_object_new (gst_pad_template_get_type (),
2430 "name", name_template,
2433 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
2434 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
2435 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
2437 va_start (var_args, caps);
2440 new->fixed &= caps->fixed;
2441 thecaps = gst_caps_append (thecaps, gst_caps_ref (caps));
2442 caps = va_arg (var_args, GstCaps*);
2446 GST_PAD_TEMPLATE_CAPS (new) = thecaps;
2452 * gst_pad_template_get_caps:
2453 * @templ: a #GstPadTemplate to get capabilities of.
2455 * Gets the capabilities of the pad template.
2457 * Returns: the #GstCaps of the pad template.
2460 gst_pad_template_get_caps (GstPadTemplate *templ)
2462 g_return_val_if_fail (templ != NULL, NULL);
2464 return GST_PAD_TEMPLATE_CAPS (templ);
2468 * gst_pad_set_element_private:
2469 * @pad: the #GstPad to set the private data of.
2470 * @priv: The private data to attach to the pad.
2472 * Set the given private data gpointer on the pad.
2473 * This function can only be used by the element that owns the pad.
2476 gst_pad_set_element_private (GstPad *pad, gpointer priv)
2478 pad->element_private = priv;
2482 * gst_pad_get_element_private:
2483 * @pad: the #GstPad to get the private data of.
2485 * Gets the private data of a pad.
2487 * Returns: a #gpointer to the private data.
2490 gst_pad_get_element_private (GstPad *pad)
2492 return pad->element_private;
2496 /***** ghost pads *****/
2497 GType _gst_ghost_pad_type = 0;
2499 static void gst_ghost_pad_class_init (GstGhostPadClass *klass);
2500 static void gst_ghost_pad_init (GstGhostPad *pad);
2502 static GstPad *ghost_pad_parent_class = NULL;
2503 /* static guint gst_ghost_pad_signals[LAST_SIGNAL] = { 0 }; */
2506 gst_ghost_pad_get_type (void)
2508 if (!_gst_ghost_pad_type) {
2509 static const GTypeInfo pad_info = {
2510 sizeof (GstGhostPadClass), NULL, NULL,
2511 (GClassInitFunc) gst_ghost_pad_class_init, NULL, NULL,
2512 sizeof (GstGhostPad),
2514 (GInstanceInitFunc) gst_ghost_pad_init,
2517 _gst_ghost_pad_type = g_type_register_static (GST_TYPE_PAD, "GstGhostPad",
2520 return _gst_ghost_pad_type;
2524 gst_ghost_pad_class_init (GstGhostPadClass *klass)
2526 GObjectClass *gobject_class;
2528 gobject_class = (GObjectClass*) klass;
2530 ghost_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
2534 gst_ghost_pad_init (GstGhostPad *pad)
2536 pad->realpad = NULL;
2540 * gst_ghost_pad_new:
2541 * @name: the name of the new ghost pad.
2542 * @pad: the #GstPad to create a ghost pad for.
2544 * Creates a new ghost pad associated with the given pad, and names it with
2545 * the given name. If name is NULL, a guaranteed unique name (across all
2546 * ghost pads) will be assigned (most likely of the form ghostpad&perc;d).
2548 * Returns: a new ghost #GstPad, or NULL in case of an error.
2552 gst_ghost_pad_new (const gchar *name,
2555 GstGhostPad *ghostpad;
2556 GstRealPad *realpad;
2558 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2560 ghostpad = g_object_new (gst_ghost_pad_get_type () ,NULL);
2561 gst_pad_set_name (GST_PAD (ghostpad), name);
2563 realpad = (GstRealPad *) pad;
2565 while (!GST_IS_REAL_PAD (realpad)) {
2566 realpad = GST_PAD_REALIZE (realpad);
2568 GST_GPAD_REALPAD (ghostpad) = realpad;
2569 GST_PAD_PAD_TEMPLATE (ghostpad) = GST_PAD_PAD_TEMPLATE (pad);
2571 /* add ourselves to the real pad's list of ghostpads */
2572 gst_pad_add_ghost_pad (pad, GST_PAD (ghostpad));
2574 /* FIXME need to ref the real pad here... ? */
2576 GST_DEBUG (GST_CAT_PADS, "created ghost pad \"%s\"",
2577 gst_pad_get_name (GST_PAD (ghostpad)));
2579 return GST_PAD (ghostpad);
2583 * gst_pad_get_internal_connections_default:
2584 * @pad: the #GstPad to get the internal connections of.
2586 * Gets a list of pads to which the given pad is connected to
2587 * inside of the parent element.
2588 * This is the default handler, and thus returns a list of all of the
2589 * pads inside the parent element with opposite direction.
2590 * The caller must free this list after use.
2592 * Returns: a newly allocated #GList of pads.
2595 gst_pad_get_internal_connections_default (GstPad *pad)
2600 GstPadDirection direction;
2603 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2605 rpad = GST_PAD_REALIZE (pad);
2606 direction = rpad->direction;
2608 parent = GST_PAD_PARENT (rpad);
2609 parent_pads = parent->pads;
2611 while (parent_pads) {
2612 GstRealPad *parent_pad = GST_PAD_REALIZE (parent_pads->data);
2614 if (parent_pad->direction != direction) {
2615 res = g_list_prepend (res, parent_pad);
2618 parent_pads = g_list_next (parent_pads);
2625 * gst_pad_get_internal_connections:
2626 * @pad: the #GstPad to get the internal connections of.
2628 * Gets a list of pads to which the given pad is connected to
2629 * inside of the parent element.
2630 * The caller must free this list after use.
2632 * Returns: a newly allocated #GList of pads.
2635 gst_pad_get_internal_connections (GstPad *pad)
2640 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2642 rpad = GST_PAD_REALIZE (pad);
2644 if (GST_RPAD_INTCONNFUNC (rpad))
2645 res = GST_RPAD_INTCONNFUNC (rpad) (GST_PAD_CAST (rpad));
2652 gst_pad_event_default_dispatch (GstPad *pad, GstElement *element,
2655 GList *pads = element->pads;
2658 GstPad *eventpad = GST_PAD (pads->data);
2659 pads = g_list_next (pads);
2661 /* for all pads in the opposite direction that are connected */
2662 if (GST_PAD_DIRECTION (eventpad) != GST_PAD_DIRECTION (pad)
2663 && GST_PAD_IS_USABLE (eventpad)) {
2664 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
2665 /* increase the refcount */
2666 gst_event_ref (event);
2667 gst_pad_push (eventpad, GST_BUFFER (event));
2670 GstPad *peerpad = GST_PAD_CAST (GST_RPAD_PEER (eventpad));
2672 /* we only send the event on one pad, multi-sinkpad elements
2673 * should implement a handler */
2674 return gst_pad_send_event (peerpad, event);
2678 gst_event_unref (event);
2683 * gst_pad_event_default:
2684 * @pad: a #GstPad to call the default event handler on.
2685 * @event: the #GstEvent to handle.
2687 * Invokes the default event handler for the given pad.
2689 * Returns: TRUE if the event was sent succesfully.
2692 gst_pad_event_default (GstPad *pad, GstEvent *event)
2694 GstElement *element;
2696 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2697 g_return_val_if_fail (event, FALSE);
2699 element = GST_PAD_PARENT (pad);
2701 switch (GST_EVENT_TYPE (event)) {
2703 gst_pad_event_default_dispatch (pad, element, event);
2704 gst_element_set_eos (element);
2705 /* we have to try to schedule another element
2706 * because this one is disabled */
2707 gst_element_yield (element);
2709 case GST_EVENT_DISCONTINUOUS:
2710 case GST_EVENT_FLUSH:
2712 return gst_pad_event_default_dispatch (pad, element, event);
2718 * gst_pad_dispatcher:
2719 * @pad: a #GstPad to dispatch.
2720 * @dispatch: the #GstDispatcherFunction to call.
2721 * @data: gpointer user data passed to the dispatcher function.
2723 * Invokes the given dispatcher function on all pads that are
2724 * internally connected to the given pad.
2725 * The GstPadDispatcherFunction should return TRUE when no further pads
2726 * need to be processed.
2728 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2731 gst_pad_dispatcher (GstPad *pad, GstPadDispatcherFunction dispatch,
2734 gboolean res = FALSE;
2735 GList *int_pads, *orig;
2737 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2738 g_return_val_if_fail (data, FALSE);
2740 orig = int_pads = gst_pad_get_internal_connections (pad);
2743 GstRealPad *int_rpad = GST_PAD_REALIZE (int_pads->data);
2744 GstRealPad *int_peer = GST_RPAD_PEER (int_rpad);
2746 if (int_peer && GST_PAD_IS_USABLE (int_peer)) {
2747 res = dispatch (GST_PAD_CAST (int_peer), data);
2751 int_pads = g_list_next (int_pads);
2760 * gst_pad_send_event:
2761 * @pad: a #GstPad to send the event to.
2762 * @event: the #GstEvent to send to the pad.
2764 * Sends the event to the pad.
2766 * Returns: TRUE if the event was handled.
2769 gst_pad_send_event (GstPad *pad, GstEvent *event)
2771 gboolean success = FALSE;
2774 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2775 g_return_val_if_fail (event, FALSE);
2777 rpad = GST_PAD_REALIZE (pad);
2779 /* don't send events on usuable pads */
2780 if (GST_PAD_IS_SINK (rpad) && !GST_PAD_IS_USABLE (rpad)) {
2781 GST_DEBUG (GST_CAT_EVENT, "pad %s:%s is not usable",
2782 GST_DEBUG_PAD_NAME (rpad));
2786 if (GST_EVENT_SRC (event) == NULL)
2787 GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (rpad));
2789 GST_DEBUG (GST_CAT_EVENT, "have event %d on pad %s:%s",
2790 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (rpad));
2792 if (GST_RPAD_EVENTFUNC (rpad))
2793 success = GST_RPAD_EVENTFUNC (rpad) (GST_PAD_CAST (rpad), event);
2795 GST_DEBUG (GST_CAT_EVENT, "there's no event function for pad %s:%s",
2796 GST_DEBUG_PAD_NAME (rpad));
2797 gst_event_unref (event);
2805 GstFormat src_format;
2807 GstFormat *dest_format;
2809 } GstPadConvertData;
2812 gst_pad_convert_dispatcher (GstPad *pad, GstPadConvertData *data)
2814 return gst_pad_convert (pad, data->src_format, data->src_value,
2815 data->dest_format, data->dest_value);
2819 * gst_pad_convert_default:
2820 * @pad: a #GstPad to invoke the default converter on.
2821 * @src_format: the source #GstFormat.
2822 * @src_value: the source value.
2823 * @dest_format: a pointer to the destination #GstFormat.
2824 * @dest_value: a pointer to the destination value.
2826 * Invokes the default converter on a pad.
2827 * This will forward the call to the pad obtained
2828 * using the internal connection of
2831 * Returns: TRUE if the conversion could be performed.
2834 gst_pad_convert_default (GstPad *pad,
2835 GstFormat src_format, gint64 src_value,
2836 GstFormat *dest_format, gint64 *dest_value)
2838 GstPadConvertData data;
2840 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2841 g_return_val_if_fail (dest_format, FALSE);
2842 g_return_val_if_fail (dest_value, FALSE);
2844 data.src_format = src_format;
2845 data.src_value = src_value;
2846 data.dest_format = dest_format;
2847 data.dest_value = dest_value;
2849 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
2850 gst_pad_convert_dispatcher, &data);
2855 * @pad: a #GstPad to invoke the default converter on.
2856 * @src_format: the source #GstFormat.
2857 * @src_value: the source value.
2858 * @dest_format: a pointer to the destination #GstFormat.
2859 * @dest_value: a pointer to the destination value.
2861 * Invokes a conversion on the pad.
2863 * Returns: TRUE if the conversion could be performed.
2866 gst_pad_convert (GstPad *pad,
2867 GstFormat src_format, gint64 src_value,
2868 GstFormat *dest_format, gint64 *dest_value)
2872 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2873 g_return_val_if_fail (dest_format, FALSE);
2874 g_return_val_if_fail (dest_value, FALSE);
2876 if (src_format == *dest_format) {
2877 *dest_value = src_value;
2881 rpad = GST_PAD_REALIZE (pad);
2883 if (GST_RPAD_CONVERTFUNC (rpad)) {
2884 return GST_RPAD_CONVERTFUNC (rpad) (GST_PAD_CAST (rpad), src_format,
2885 src_value, dest_format, dest_value);
2893 GstPadQueryType type;
2899 gst_pad_query_dispatcher (GstPad *pad, GstPadQueryData *data)
2901 return gst_pad_query (pad, data->type, data->format, data->value);
2905 * gst_pad_query_default:
2906 * @pad: a #GstPad to invoke the default query on.
2907 * @type: the #GstPadQueryType of the query to perform.
2908 * @format: a pointer to the #GstFormat of the result.
2909 * @value: a pointer to the result.
2911 * Invokes the default query function on a pad.
2913 * Returns: TRUE if the query could be performed.
2916 gst_pad_query_default (GstPad *pad, GstPadQueryType type,
2917 GstFormat *format, gint64 *value)
2919 GstPadQueryData data;
2921 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2922 g_return_val_if_fail (format, FALSE);
2923 g_return_val_if_fail (value, FALSE);
2926 data.format = format;
2929 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
2930 gst_pad_query_dispatcher, &data);
2935 * @pad: a #GstPad to invoke the default query on.
2936 * @type: the #GstPadQueryType of the query to perform.
2937 * @format: a pointer to the #GstFormat of the result.
2938 * @value: a pointer to the result.
2940 * Queries a pad for one of the available properties.
2942 * Returns: TRUE if the query could be performed.
2945 gst_pad_query (GstPad *pad, GstPadQueryType type,
2946 GstFormat *format, gint64 *value)
2950 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2951 g_return_val_if_fail (format, FALSE);
2952 g_return_val_if_fail (value, FALSE);
2954 rpad = GST_PAD_REALIZE (pad);
2956 g_return_val_if_fail (rpad, FALSE);
2958 if (GST_RPAD_QUERYFUNC (rpad))
2959 return GST_RPAD_QUERYFUNC (rpad) (GST_PAD_CAST (pad), type, format, value);
2965 * gst_pad_handles_format:
2966 * @pad: a #GstPad to check
2967 * @format: the format to check
2969 * Checks if the pad can handle the given format.
2971 * Returns: TRUE if the pad can handle the given format
2974 gst_pad_handles_format (GstPad *pad, GstFormat format)
2976 const GstFormat *formats;
2978 formats = gst_pad_get_formats (pad);
2983 if (*formats == format)
2993 gst_pad_get_formats_dispatcher (GstPad *pad, const GstFormat **data)
2995 *data = gst_pad_get_formats (pad);
3001 * gst_pad_get_formats_default:
3002 * @pad: a #GstPad to query
3004 * Invoke the default format dispatcher for the pad.
3006 * Returns: An array of GstFormats ended with a 0 value.
3009 gst_pad_get_formats_default (GstPad *pad)
3011 GstFormat *result = NULL;
3013 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
3014 gst_pad_get_formats_dispatcher, &result);
3020 * gst_pad_get_formats:
3021 * @pad: a #GstPad to query
3023 * Gets the list of supported formats from the pad.
3025 * Returns: An array of GstFormats ended with a 0 value.
3028 gst_pad_get_formats (GstPad *pad)
3032 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
3034 rpad = GST_PAD_REALIZE (pad);
3036 if (GST_RPAD_FORMATSFUNC (rpad))
3037 return GST_RPAD_FORMATSFUNC (rpad) (GST_PAD_CAST (pad));