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_set_convert_function:
585 * @pad: a #GstPad to set the convert function for.
586 * @convert: the #GstPadConvertFunction to set.
588 * Sets the given convert function for the pad.
591 gst_pad_set_convert_function (GstPad *pad,
592 GstPadConvertFunction convert)
594 g_return_if_fail (pad != NULL);
595 g_return_if_fail (GST_IS_REAL_PAD (pad));
597 GST_RPAD_CONVERTFUNC (pad) = convert;
599 GST_DEBUG (GST_CAT_PADS, "convertfunc for %s:%s set to %s",
600 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (convert));
604 * gst_pad_set_query_function:
605 * @pad: the #GstPad to set the query function for.
606 * @query: the #GstPadQueryFunction to set.
608 * Set the given query function for the pad.
611 gst_pad_set_query_function (GstPad *pad, GstPadQueryFunction query)
613 g_return_if_fail (pad != NULL);
614 g_return_if_fail (GST_IS_REAL_PAD (pad));
616 GST_RPAD_QUERYFUNC (pad) = query;
618 GST_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
619 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
623 * gst_pad_set_query_type_function:
624 * @pad: the #GstPad to set the query type function for.
625 * @type_func: the #GstPadQueryTypeFunction to set.
627 * Set the given query type function for the pad.
630 gst_pad_set_query_type_function (GstPad *pad, GstPadQueryTypeFunction type_func)
632 g_return_if_fail (pad != NULL);
633 g_return_if_fail (GST_IS_REAL_PAD (pad));
635 GST_RPAD_QUERYTYPEFUNC (pad) = type_func;
637 GST_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
638 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
642 * gst_pad_get_query_types:
643 * @pad: the #GstPad to query
645 * Get an array of supported queries that can be performed
648 * Returns: an array of querytypes anded with 0.
651 gst_pad_get_query_types (GstPad *pad)
658 rpad = GST_PAD_REALIZE (pad);
660 g_return_val_if_fail (rpad, FALSE);
662 if (GST_RPAD_QUERYTYPEFUNC (rpad))
663 return GST_RPAD_QUERYTYPEFUNC (rpad) (GST_PAD_CAST (pad));
669 gst_pad_get_query_types_dispatcher (GstPad *pad, const GstQueryType **data)
671 *data = gst_pad_get_query_types (pad);
677 * gst_pad_get_query_types_default:
678 * @pad: the #GstPad to query
680 * Invoke the default dispatcher for the query types on
683 * Returns: an array of querytypes anded with 0.
686 gst_pad_get_query_types_default (GstPad *pad)
688 GstQueryType *result = NULL;
690 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
691 gst_pad_get_query_types_dispatcher, &result);
697 * gst_pad_set_internal_connection_function:
698 * @pad: a #GstPad to set the internal connection function for.
699 * @intconn: the #GstPadIntConnFunction to set.
701 * Sets the given internal connection function for the pad.
704 gst_pad_set_internal_connection_function (GstPad *pad,
705 GstPadIntConnFunction intconn)
707 g_return_if_fail (pad != NULL);
708 g_return_if_fail (GST_IS_REAL_PAD (pad));
710 GST_RPAD_INTCONNFUNC (pad) = intconn;
711 GST_DEBUG (GST_CAT_PADS, "internal connection for %s:%s set to %s",
712 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intconn));
716 * gst_pad_set_formats_function:
717 * @pad: the #GstPad to set the formats function for.
718 * @formats: the #GstPadFormatsFunction to set.
720 * Sets the given formats function for the pad.
723 gst_pad_set_formats_function (GstPad *pad, GstPadFormatsFunction formats)
725 g_return_if_fail (pad != NULL);
726 g_return_if_fail (GST_IS_REAL_PAD (pad));
728 GST_RPAD_FORMATSFUNC (pad) = formats;
729 GST_DEBUG (GST_CAT_PADS, "formats function for %s:%s set to %s",
730 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (formats));
734 * gst_pad_set_connect_function:
735 * @pad: a #GstPad to set the connect function for.
736 * @connect: the #GstPadConnectFunction to set.
738 * Sets the given connect function for the pad. It will be called
739 * when the pad is connected or reconnected with caps.
742 gst_pad_set_connect_function (GstPad *pad,
743 GstPadConnectFunction connect)
745 g_return_if_fail (pad != NULL);
746 g_return_if_fail (GST_IS_REAL_PAD (pad));
748 GST_RPAD_CONNECTFUNC (pad) = connect;
749 GST_DEBUG (GST_CAT_PADS, "connectfunc for %s:%s set to %s",
750 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (connect));
754 * gst_pad_set_getcaps_function:
755 * @pad: a #GstPad to set the getcaps function for.
756 * @getcaps: the #GstPadGetCapsFunction to set.
758 * Sets the given getcaps function for the pad.
761 gst_pad_set_getcaps_function (GstPad *pad,
762 GstPadGetCapsFunction getcaps)
764 g_return_if_fail (pad != NULL);
765 g_return_if_fail (GST_IS_REAL_PAD (pad));
767 GST_RPAD_GETCAPSFUNC (pad) = getcaps;
768 GST_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
769 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
772 * gst_pad_set_bufferpool_function:
773 * @pad: a #GstPad to set the bufferpool function for.
774 * @bufpool: the #GstPadBufferPoolFunction to set.
776 * Sets the given bufferpool function for the pad. Note that the
777 * bufferpool function can only be set on sinkpads.
780 gst_pad_set_bufferpool_function (GstPad *pad,
781 GstPadBufferPoolFunction bufpool)
783 g_return_if_fail (pad != NULL);
784 g_return_if_fail (GST_IS_REAL_PAD (pad));
785 g_return_if_fail (GST_PAD_IS_SINK (pad));
787 GST_RPAD_BUFFERPOOLFUNC (pad) = bufpool;
788 GST_DEBUG (GST_CAT_PADS, "bufferpoolfunc for %s:%s set to %s",
789 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufpool));
793 * gst_pad_disconnect:
794 * @srcpad: the source #GstPad to disconnect.
795 * @sinkpad: the sink #GstPad to disconnect.
797 * Disconnects the source pad from the sink pad.
800 gst_pad_disconnect (GstPad *srcpad,
803 GstRealPad *realsrc, *realsink;
804 GstScheduler *src_sched, *sink_sched;
807 g_return_if_fail (srcpad != NULL);
808 g_return_if_fail (GST_IS_PAD (srcpad));
809 g_return_if_fail (sinkpad != NULL);
810 g_return_if_fail (GST_IS_PAD (sinkpad));
812 GST_INFO (GST_CAT_ELEMENT_PADS, "disconnecting %s:%s(%p) and %s:%s(%p)",
813 GST_DEBUG_PAD_NAME (srcpad), srcpad,
814 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
816 /* now we need to deal with the real/ghost stuff */
817 realsrc = GST_PAD_REALIZE (srcpad);
818 realsink = GST_PAD_REALIZE (sinkpad);
820 g_return_if_fail (GST_RPAD_PEER (realsrc) != NULL);
821 g_return_if_fail (GST_RPAD_PEER (realsink) == realsrc);
823 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
824 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
831 g_return_if_fail ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
832 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK));
834 /* get the schedulers before we disconnect */
835 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
836 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
838 /* first clear peers */
839 GST_RPAD_PEER (realsrc) = NULL;
840 GST_RPAD_PEER (realsink) = NULL;
842 /* reset the filters, both filters are refcounted once */
843 if (GST_RPAD_FILTER (realsrc)) {
844 gst_caps_unref (GST_RPAD_FILTER (realsrc));
845 GST_RPAD_FILTER (realsink) = NULL;
846 GST_RPAD_FILTER (realsrc) = NULL;
849 /* now tell the scheduler */
850 if (src_sched && src_sched == sink_sched) {
851 gst_scheduler_pad_disconnect (src_sched,
852 GST_PAD_CAST (realsrc), GST_PAD_CAST (realsink));
855 /* hold a reference, as they can go away in the signal handlers */
856 gst_object_ref (GST_OBJECT (realsrc));
857 gst_object_ref (GST_OBJECT (realsink));
859 /* fire off a signal to each of the pads telling them
860 * that they've been disconnected */
861 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_DISCONNECTED],
863 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_DISCONNECTED],
866 GST_INFO (GST_CAT_ELEMENT_PADS, "disconnected %s:%s and %s:%s",
867 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
869 gst_object_unref (GST_OBJECT (realsrc));
870 gst_object_unref (GST_OBJECT (realsink));
874 gst_pad_check_schedulers (GstRealPad *realsrc, GstRealPad *realsink)
876 GstScheduler *src_sched, *sink_sched;
877 gint num_decoupled = 0;
879 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
880 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
882 if (src_sched && sink_sched) {
883 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsrc), GST_ELEMENT_DECOUPLED))
885 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsink), GST_ELEMENT_DECOUPLED))
888 if (src_sched != sink_sched && num_decoupled != 1) {
896 * gst_pad_can_connect_filtered:
897 * @srcpad: the source #GstPad to connect.
898 * @sinkpad: the sink #GstPad to connect.
899 * @filtercaps: the filter #GstCaps.
901 * Checks if the source pad and the sink pad can be connected when constrained
902 * by the given filter caps.
904 * Returns: TRUE if the pads can be connected, FALSE otherwise.
907 gst_pad_can_connect_filtered (GstPad *srcpad, GstPad *sinkpad,
910 GstRealPad *realsrc, *realsink;
913 g_return_val_if_fail (srcpad != NULL, FALSE);
914 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
915 g_return_val_if_fail (sinkpad != NULL, FALSE);
916 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
918 /* now we need to deal with the real/ghost stuff */
919 realsrc = GST_PAD_REALIZE (srcpad);
920 realsink = GST_PAD_REALIZE (sinkpad);
922 g_return_val_if_fail (GST_RPAD_PEER (realsrc) == NULL, FALSE);
923 g_return_val_if_fail (GST_RPAD_PEER (realsink) == NULL, FALSE);
924 g_return_val_if_fail (GST_PAD_PARENT (realsrc) != NULL, FALSE);
925 g_return_val_if_fail (GST_PAD_PARENT (realsink) != NULL, FALSE);
927 if (!gst_pad_check_schedulers (realsrc, realsink)) {
928 g_warning ("connecting pads with different scheds requires "
929 "exactly one decoupled element (queue)");
933 /* check if the directions are compatible */
934 if (!(((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
935 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) ||
936 ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
937 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK))))
943 * gst_pad_can_connect:
944 * @srcpad: the source #GstPad to connect.
945 * @sinkpad: the sink #GstPad to connect.
947 * Checks if the source pad and the sink pad can be connected.
949 * Returns: TRUE if the pads can be connected, FALSE otherwise.
952 gst_pad_can_connect (GstPad *srcpad, GstPad *sinkpad)
954 return gst_pad_can_connect_filtered (srcpad, sinkpad, NULL);
958 * gst_pad_connect_filtered:
959 * @srcpad: the source #GstPad to connect.
960 * @sinkpad: the sink #GstPad to connect.
961 * @filtercaps: the filter #GstCaps.
963 * Connects the source pad and the sink pad can be connected, constrained
964 * by the given filter caps.
966 * Returns: TRUE if the pads have been connected, FALSE otherwise.
969 gst_pad_connect_filtered (GstPad *srcpad, GstPad *sinkpad, GstCaps *filtercaps)
971 GstRealPad *realsrc, *realsink;
972 GstScheduler *src_sched, *sink_sched;
975 g_return_val_if_fail (srcpad != NULL, FALSE);
976 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
977 g_return_val_if_fail (sinkpad != NULL, FALSE);
978 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
980 GST_INFO (GST_CAT_PADS, "trying to connect %s:%s and %s:%s",
981 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
983 /* now we need to deal with the real/ghost stuff */
984 realsrc = GST_PAD_REALIZE (srcpad);
985 realsink = GST_PAD_REALIZE (sinkpad);
987 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
988 GST_INFO (GST_CAT_PADS, "*actually* connecting %s:%s and %s:%s",
989 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
991 if (GST_RPAD_PEER (realsrc) != NULL)
993 GST_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
994 GST_DEBUG_PAD_NAME (realsrc));
997 if (GST_RPAD_PEER (realsink) != NULL)
999 GST_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
1000 GST_DEBUG_PAD_NAME (realsink));
1003 if (GST_PAD_PARENT (realsrc) == NULL)
1005 GST_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1006 GST_DEBUG_PAD_NAME (realsrc));
1009 if (GST_PAD_PARENT (realsink) == NULL)
1011 GST_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
1012 GST_DEBUG_PAD_NAME (realsrc));
1016 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1017 g_warning ("connecting pads with different scheds requires "
1018 "exactly one decoupled element (such as queue)");
1022 /* check for reversed directions and swap if necessary */
1023 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
1024 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
1025 GstRealPad *temppad;
1031 if (GST_PAD_PARENT (realsink) == NULL)
1032 if (GST_RPAD_DIRECTION (realsrc) != GST_PAD_SRC)
1034 GST_INFO (GST_CAT_PADS, "Real src pad %s:%s is not a source pad, failed",
1035 GST_DEBUG_PAD_NAME (realsrc));
1038 if (GST_RPAD_DIRECTION (realsink) != GST_PAD_SINK)
1040 GST_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1041 GST_DEBUG_PAD_NAME (realsink));
1044 /* first set peers */
1045 GST_RPAD_PEER (realsrc) = realsink;
1046 GST_RPAD_PEER (realsink) = realsrc;
1048 /* try to negotiate the pads, we don't need to clear the caps here */
1049 if (!gst_pad_try_reconnect_filtered_func (realsrc, realsink,
1050 filtercaps, FALSE)) {
1051 GST_DEBUG (GST_CAT_CAPS, "reconnect_filtered_func failed, can't connect");
1053 GST_RPAD_PEER (realsrc) = NULL;
1054 GST_RPAD_PEER (realsink) = NULL;
1059 /* fire off a signal to each of the pads telling them
1060 * that they've been connected */
1061 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_CONNECTED],
1063 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_CONNECTED],
1066 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
1067 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
1069 /* now tell the scheduler */
1070 if (src_sched && src_sched == sink_sched) {
1071 gst_scheduler_pad_connect (src_sched,
1072 GST_PAD_CAST (realsrc), GST_PAD_CAST (realsink));
1075 GST_INFO (GST_CAT_PADS, "connected %s:%s and %s:%s, successful",
1076 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1077 gst_caps_debug (gst_pad_get_caps (GST_PAD_CAST (realsrc)),
1078 "caps of newly connected src pad");
1085 * @srcpad: the source #GstPad to connect.
1086 * @sinkpad: the sink #GstPad to connect.
1088 * Connects the source pad to the sink pad.
1090 * Returns: TRUE if the pad could be connected, FALSE otherwise.
1093 gst_pad_connect (GstPad *srcpad, GstPad *sinkpad)
1095 return gst_pad_connect_filtered (srcpad, sinkpad, NULL);
1099 * gst_pad_set_parent:
1100 * @pad: a #GstPad to set the parent of.
1101 * @parent: the new parent #GstElement.
1103 * Sets the parent object of a pad.
1106 gst_pad_set_parent (GstPad *pad, GstElement *parent)
1108 g_return_if_fail (pad != NULL);
1109 g_return_if_fail (GST_IS_PAD (pad));
1110 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
1111 g_return_if_fail (parent != NULL);
1112 g_return_if_fail (GST_IS_OBJECT (parent));
1113 g_return_if_fail ((gpointer) pad != (gpointer) parent);
1115 gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (parent));
1119 * gst_pad_get_parent:
1120 * @pad: the #GstPad to get the parent of.
1122 * Gets the parent object of this pad.
1124 * Returns: the parent #GstElement.
1127 gst_pad_get_parent (GstPad *pad)
1129 g_return_val_if_fail (pad != NULL, NULL);
1130 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1132 return GST_PAD_PARENT (pad);
1136 * gst_pad_get_pad_template:
1137 * @pad: a #GstPad to get the pad template of.
1139 * Gets the pad template object of this pad.
1141 * Returns: the #GstPadTemplate from which this pad was instantiated.
1144 gst_pad_get_pad_template (GstPad *pad)
1146 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1148 return GST_PAD_PAD_TEMPLATE (pad);
1153 * gst_pad_get_scheduler:
1154 * @pad: a #GstPad to get the scheduler of.
1156 * Gets the scheduler of the pad. Since the pad does not
1157 * have a scheduler of its own, the scheduler of the parent
1158 * is taken. For decoupled pads, the scheduler of the peer
1161 * Returns: the #GstScheduler of the pad.
1164 gst_pad_get_scheduler (GstPad *pad)
1166 GstScheduler *scheduler = NULL;
1169 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1171 parent = gst_pad_get_parent (pad);
1173 if (GST_FLAG_IS_SET (parent, GST_ELEMENT_DECOUPLED)) {
1174 GstRealPad *peer = GST_RPAD_PEER (pad);
1177 scheduler = gst_element_get_scheduler (gst_pad_get_parent (GST_PAD_CAST (peer)));
1181 scheduler = gst_element_get_scheduler (parent);
1189 * gst_pad_get_real_parent:
1190 * @pad: a #GstPad to get the real parent of.
1192 * Gets the real parent object of this pad. If the pad
1193 * is a ghost pad, the actual owner of the real pad is
1194 * returned, as opposed to #gst_pad_get_parent().
1196 * Returns: the parent #GstElement.
1199 gst_pad_get_real_parent (GstPad *pad)
1201 g_return_val_if_fail (pad != NULL, NULL);
1202 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1204 return GST_PAD_PARENT (GST_PAD (GST_PAD_REALIZE (pad)));
1208 * gst_pad_add_ghost_pad:
1209 * @pad: a #GstPad to attach the ghost pad to.
1210 * @ghostpad: the ghost #GstPad to to the pad.
1212 * Adds a ghost pad to a pad.
1215 gst_pad_add_ghost_pad (GstPad *pad,
1218 GstRealPad *realpad;
1220 g_return_if_fail (pad != NULL);
1221 g_return_if_fail (GST_IS_PAD (pad));
1222 g_return_if_fail (ghostpad != NULL);
1223 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1225 realpad = GST_PAD_REALIZE (pad);
1227 realpad->ghostpads = g_list_prepend (realpad->ghostpads, ghostpad);
1232 * gst_pad_remove_ghost_pad:
1233 * @pad: a #GstPad to remove the ghost pad from.
1234 * @ghostpad: the ghost #GstPad to remove from the pad.
1236 * Removes a ghost pad from a pad.
1239 gst_pad_remove_ghost_pad (GstPad *pad,
1242 GstRealPad *realpad;
1244 g_return_if_fail (pad != NULL);
1245 g_return_if_fail (GST_IS_PAD (pad));
1246 g_return_if_fail (ghostpad != NULL);
1247 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1249 realpad = GST_PAD_REALIZE (pad);
1251 realpad->ghostpads = g_list_remove (realpad->ghostpads, ghostpad);
1255 * gst_pad_get_ghost_pad_list:
1256 * @pad: a #GstPad to get the ghost pads of.
1258 * Gets the ghost pads of this pad.
1260 * Returns: a #GList of ghost pads.
1263 gst_pad_get_ghost_pad_list (GstPad *pad)
1265 g_return_val_if_fail (pad != NULL, NULL);
1266 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1268 return GST_PAD_REALIZE(pad)->ghostpads;
1271 /* an internal caps negotiation helper function:
1273 * 1. optionally calls the pad connect function with the provided caps
1274 * 2. deals with the result code of the connect function
1275 * 3. sets fixed caps on the pad.
1277 static GstPadConnectReturn
1278 gst_pad_try_set_caps_func (GstRealPad *pad, GstCaps *caps, gboolean notify)
1280 GstCaps *oldcaps, *allowed = NULL;
1281 GstPadTemplate *template;
1282 GstElement *parent = GST_PAD_PARENT (pad);
1284 g_return_val_if_fail (pad != NULL, GST_PAD_CONNECT_REFUSED);
1285 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_CONNECT_REFUSED);
1287 /* if this pad has a parent and the parent is not READY, delay the
1289 if (parent && GST_STATE (parent) < GST_STATE_READY)
1291 GST_DEBUG (GST_CAT_CAPS, "parent %s of pad %s:%s is not READY",
1292 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (pad));
1293 return GST_PAD_CONNECT_DELAYED;
1296 GST_INFO (GST_CAT_CAPS, "trying to set caps %p on pad %s:%s",
1297 caps, GST_DEBUG_PAD_NAME (pad));
1299 /* first see if we have to check against a filter */
1300 if (!(allowed = GST_RPAD_FILTER (pad))) {
1301 /* no filter, make sure we check against the padtemplate then */
1302 if ((template = gst_pad_get_pad_template (GST_PAD_CAST (pad)))) {
1303 allowed = gst_pad_template_get_caps (template);
1307 /* do we have to check the caps against something? */
1309 GstCaps *intersection;
1311 /* check against calculated caps */
1312 intersection = gst_caps_intersect (caps, allowed);
1314 /* oops, empty intersection, caps don"t have anything in common */
1315 if (!intersection) {
1316 GST_INFO (GST_CAT_CAPS, "caps did not intersect with %s:%s's allowed caps",
1317 GST_DEBUG_PAD_NAME (pad));
1318 gst_caps_debug (caps, "caps themselves (attemped to set)");
1319 gst_caps_debug (allowed,
1320 "allowed caps that did not agree with caps");
1321 return GST_PAD_CONNECT_REFUSED;
1323 /* caps checks out fine, we can unref the intersection now */
1324 gst_caps_unref (intersection);
1325 /* given that the caps are fixed, we know that their intersection with the
1326 * padtemplate caps is the same as caps itself */
1329 /* we need to notify the connect function */
1330 if (notify && GST_RPAD_CONNECTFUNC (pad)) {
1331 GstPadConnectReturn res;
1332 gchar *debug_string;
1334 GST_INFO (GST_CAT_CAPS, "calling connect function on pad %s:%s",
1335 GST_DEBUG_PAD_NAME (pad));
1337 /* call the connect function */
1338 res = GST_RPAD_CONNECTFUNC (pad) (GST_PAD (pad), caps);
1341 case GST_PAD_CONNECT_REFUSED:
1342 debug_string = "REFUSED";
1344 case GST_PAD_CONNECT_OK:
1345 debug_string = "OK";
1347 case GST_PAD_CONNECT_DONE:
1348 debug_string = "DONE";
1350 case GST_PAD_CONNECT_DELAYED:
1351 debug_string = "DELAYED";
1354 g_warning ("unknown return code from connect function of pad %s:%s %d",
1355 GST_DEBUG_PAD_NAME (pad), res);
1356 return GST_PAD_CONNECT_REFUSED;
1359 GST_INFO (GST_CAT_CAPS,
1360 "got reply %s (%d) from connect function on pad %s:%s",
1361 debug_string, res, GST_DEBUG_PAD_NAME (pad));
1363 /* done means the connect function called another caps negotiate function
1364 * on this pad that succeeded, we dont need to continue */
1365 if (res == GST_PAD_CONNECT_DONE) {
1366 GST_INFO (GST_CAT_CAPS, "pad %s:%s is done", GST_DEBUG_PAD_NAME (pad));
1367 return GST_PAD_CONNECT_DONE;
1369 if (res == GST_PAD_CONNECT_REFUSED) {
1370 GST_INFO (GST_CAT_CAPS, "pad %s:%s doesn't accept caps",
1371 GST_DEBUG_PAD_NAME (pad));
1372 return GST_PAD_CONNECT_REFUSED;
1375 /* we can only set caps on the pad if they are fixed */
1376 if (GST_CAPS_IS_FIXED (caps)) {
1378 GST_INFO (GST_CAT_CAPS, "setting caps on pad %s:%s",
1379 GST_DEBUG_PAD_NAME (pad));
1380 /* if we got this far all is ok, remove the old caps, set the new one */
1381 oldcaps = GST_PAD_CAPS (pad);
1382 if (caps) gst_caps_ref (caps);
1383 GST_PAD_CAPS (pad) = caps;
1384 if (oldcaps) gst_caps_unref (oldcaps);
1386 g_object_notify (G_OBJECT (pad), "caps");
1389 GST_INFO (GST_CAT_CAPS,
1390 "caps are not fixed on pad %s:%s, not setting them yet",
1391 GST_DEBUG_PAD_NAME (pad));
1393 return GST_PAD_CONNECT_OK;
1397 * gst_pad_try_set_caps:
1398 * @pad: a #GstPad to try to set the caps on.
1399 * @caps: the #GstCaps to set.
1401 * Tries to set the caps on the given pad.
1403 * Returns: A GstPadConnectReturn value indicating whether the caps
1407 gst_pad_try_set_caps (GstPad *pad, GstCaps *caps)
1409 GstRealPad *peer, *realpad;
1410 GstPadConnectReturn set_retval;
1412 realpad = GST_PAD_REALIZE (pad);
1413 peer = GST_RPAD_PEER (realpad);
1415 GST_INFO (GST_CAT_CAPS, "trying to set caps %p on pad %s:%s",
1416 caps, GST_DEBUG_PAD_NAME (realpad));
1418 gst_caps_debug (caps, "caps that we are trying to set");
1420 /* setting non fixed caps on a pad is not allowed */
1421 if (!GST_CAPS_IS_FIXED (caps)) {
1422 GST_INFO (GST_CAT_CAPS,
1423 "trying to set unfixed caps on pad %s:%s, not allowed",
1424 GST_DEBUG_PAD_NAME (realpad));
1425 g_warning ("trying to set non fixed caps on pad %s:%s, not allowed",
1426 GST_DEBUG_PAD_NAME (realpad));
1427 gst_caps_debug (caps, "unfixed caps");
1428 return GST_PAD_CONNECT_DELAYED;
1431 /* if we have a peer try to set the caps, notifying the peerpad
1432 * if it has a connect function */
1433 if (peer && ((set_retval = gst_pad_try_set_caps_func (peer, caps, TRUE)) <= 0))
1435 GST_INFO (GST_CAT_CAPS, "tried to set caps on peerpad %s:%s but couldn't, return value %d",
1436 GST_DEBUG_PAD_NAME (peer), set_retval);
1440 /* then try to set our own caps, we don't need to be notified */
1441 if ((set_retval = gst_pad_try_set_caps_func (realpad, caps, FALSE)) <= 0)
1443 GST_INFO (GST_CAT_CAPS, "tried to set own caps on pad %s:%s but couldn't, return value %d",
1444 GST_DEBUG_PAD_NAME (realpad), set_retval);
1447 GST_INFO (GST_CAT_CAPS, "succeeded setting caps %p on pad %s:%s, return value %d",
1448 caps, GST_DEBUG_PAD_NAME (realpad), set_retval);
1449 g_assert (GST_PAD_CAPS (pad));
1454 /* this is a caps negotiation convenience routine, it:
1456 * 1. optionally clears any pad caps.
1457 * 2. calculates the intersection between the two pad tamplate/getcaps caps.
1458 * 3. calculates the intersection with the (optional) filtercaps.
1459 * 4. stores the intersection in the pad filter.
1460 * 5. stores the app filtercaps in the pad appfilter.
1461 * 6. starts the caps negotiation.
1464 gst_pad_try_reconnect_filtered_func (GstRealPad *srcpad, GstRealPad *sinkpad,
1465 GstCaps *filtercaps, gboolean clear)
1467 GstCaps *srccaps, *sinkcaps;
1468 GstCaps *intersection = NULL;
1469 GstRealPad *realsrc, *realsink;
1471 realsrc = GST_PAD_REALIZE (srcpad);
1472 realsink = GST_PAD_REALIZE (sinkpad);
1474 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1475 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1477 /* optinally clear the caps */
1479 GST_INFO (GST_CAT_PADS,
1480 "start reconnect filtered %s:%s and %s:%s, clearing caps",
1481 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1483 GST_PAD_CAPS (GST_PAD (realsrc)) = NULL;
1484 GST_PAD_CAPS (GST_PAD (realsink)) = NULL;
1487 GST_INFO (GST_CAT_PADS, "start reconnect filtered %s:%s and %s:%s",
1488 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1491 srccaps = gst_pad_get_caps (GST_PAD (realsrc));
1492 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1493 GST_DEBUG_PAD_NAME (realsrc));
1494 gst_caps_debug (srccaps, "caps of src pad (pre-reconnect)");
1495 sinkcaps = gst_pad_get_caps (GST_PAD (realsink));
1496 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1497 GST_DEBUG_PAD_NAME (realsink));
1498 gst_caps_debug (sinkcaps, "caps of sink pad (pre-reconnect)");
1500 /* first take the intersection of the pad caps */
1501 intersection = gst_caps_intersect (srccaps, sinkcaps);
1502 gst_caps_debug (intersection, "caps of intersection");
1504 /* if we have no intersection but one of the caps was not NULL.. */
1505 if (!intersection && (srccaps || sinkcaps)) {
1506 /* the intersection is NULL but the pad caps were not both NULL,
1507 * this means they have no common format */
1508 GST_INFO (GST_CAT_PADS, "pads %s:%s and %s:%s have no common type",
1509 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1511 } else if (intersection) {
1512 GST_INFO (GST_CAT_PADS, "pads %s:%s and %s:%s intersected to %s caps",
1513 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink),
1514 ((intersection && GST_CAPS_IS_FIXED (intersection)) ? "fixed" : "variable"));
1516 /* then filter this against the app filter */
1518 GstCaps *filtered_intersection = gst_caps_intersect (intersection,
1521 /* get rid of the old intersection here */
1522 gst_caps_unref (intersection);
1524 if (!filtered_intersection) {
1525 GST_INFO (GST_CAT_PADS,
1526 "filtered connection between pads %s:%s and %s:%s is empty",
1527 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1530 intersection = filtered_intersection;
1532 /* keep a reference to the app caps */
1533 GST_RPAD_APPFILTER (realsink) = filtercaps;
1534 GST_RPAD_APPFILTER (realsrc) = filtercaps;
1537 GST_DEBUG (GST_CAT_CAPS, "setting filter for connection to:");
1538 gst_caps_debug (intersection, "filter for connection");
1540 /* both the app filter and the filter, while stored on both peer pads,
1541 * are equal to the same thing on both */
1542 GST_RPAD_FILTER (realsrc) = intersection;
1543 GST_RPAD_FILTER (realsink) = intersection;
1545 return gst_pad_perform_negotiate (GST_PAD (realsrc), GST_PAD (realsink));
1549 * gst_pad_perform_negotiate:
1550 * @srcpad: the source #GstPad.
1551 * @sinkpad: the sink #GstPad.
1553 * Tries to negotiate the pads.
1555 * Returns: TRUE if the pads were succesfully negotiated, FALSE otherwise.
1558 gst_pad_perform_negotiate (GstPad *srcpad, GstPad *sinkpad)
1560 GstCaps *intersection, *filtered_intersection;
1561 GstRealPad *realsrc, *realsink;
1562 GstCaps *srccaps, *sinkcaps, *filter;
1564 g_return_val_if_fail (srcpad != NULL, FALSE);
1565 g_return_val_if_fail (sinkpad != NULL, FALSE);
1567 realsrc = GST_PAD_REALIZE (srcpad);
1568 realsink = GST_PAD_REALIZE (sinkpad);
1570 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1571 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1573 filter = GST_RPAD_APPFILTER (realsrc);
1575 GST_INFO (GST_CAT_PADS, "dumping filter for connection %s:%s-%s:%s",
1576 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1577 gst_caps_debug (filter, "connection filter caps");
1580 /* calculate the new caps here */
1581 srccaps = gst_pad_get_caps (GST_PAD (realsrc));
1582 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1583 GST_DEBUG_PAD_NAME (realsrc));
1584 gst_caps_debug (srccaps,
1585 "src caps, awaiting negotiation, after applying filter");
1586 sinkcaps = gst_pad_get_caps (GST_PAD (realsink));
1587 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1588 GST_DEBUG_PAD_NAME (realsink));
1589 gst_caps_debug (sinkcaps,
1590 "sink caps, awaiting negotiation, after applying filter");
1591 intersection = gst_caps_intersect (srccaps, sinkcaps);
1592 filtered_intersection = gst_caps_intersect (intersection, filter);
1593 if (filtered_intersection) {
1594 gst_caps_unref (intersection);
1595 intersection = filtered_intersection;
1598 /* no negotiation is performed if the pads have filtercaps */
1600 GstPadConnectReturn res;
1602 res = gst_pad_try_set_caps_func (realsrc, intersection, TRUE);
1603 if (res == GST_PAD_CONNECT_REFUSED)
1605 if (res == GST_PAD_CONNECT_DONE)
1608 res = gst_pad_try_set_caps_func (realsink, intersection, TRUE);
1609 if (res == GST_PAD_CONNECT_REFUSED)
1611 if (res == GST_PAD_CONNECT_DONE)
1618 * gst_pad_try_reconnect_filtered:
1619 * @srcpad: the source #GstPad to reconnect.
1620 * @sinkpad: the sink #GstPad to reconnect.
1621 * @filtercaps: the #GstPad to use as a filter in the reconnection.
1623 * Tries to reconnect the given source and sink pad, constrained by the given
1626 * Returns: TRUE if the pads were succesfully renegotiated, FALSE otherwise.
1629 gst_pad_try_reconnect_filtered (GstPad *srcpad, GstPad *sinkpad,
1630 GstCaps *filtercaps)
1632 GstRealPad *realsrc, *realsink;
1634 g_return_val_if_fail (srcpad != NULL, FALSE);
1635 g_return_val_if_fail (sinkpad != NULL, FALSE);
1637 realsrc = GST_PAD_REALIZE (srcpad);
1638 realsink = GST_PAD_REALIZE (sinkpad);
1640 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1641 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1643 return gst_pad_try_reconnect_filtered_func (realsrc, realsink,
1648 * gst_pad_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 * Reconnects the given source and sink pad, constrained by the given
1654 * capabilities. If the reconnection fails, the pads are disconnected
1655 * and FALSE is returned.
1657 * Returns: TRUE if the pads were succesfully reconnected, FALSE otherwise.
1660 gst_pad_reconnect_filtered (GstPad *srcpad, GstPad *sinkpad,
1661 GstCaps *filtercaps)
1663 GstRealPad *realsrc, *realsink;
1665 g_return_val_if_fail (srcpad != NULL, FALSE);
1666 g_return_val_if_fail (sinkpad != NULL, FALSE);
1668 realsrc = GST_PAD_REALIZE (srcpad);
1669 realsink = GST_PAD_REALIZE (sinkpad);
1671 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1672 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1674 if (! gst_pad_try_reconnect_filtered_func (realsrc, realsink,
1675 filtercaps, TRUE)) {
1676 gst_pad_disconnect (srcpad, GST_PAD (GST_PAD_PEER (srcpad)));
1683 * gst_pad_proxy_connect:
1684 * @pad: a #GstPad to proxy to.
1685 * @caps: the #GstCaps to use in proxying.
1687 * Proxies the connect function to the specified pad.
1689 * Returns: TRUE if the peer pad accepted the caps, FALSE otherwise.
1692 gst_pad_proxy_connect (GstPad *pad, GstCaps *caps)
1694 GstRealPad *peer, *realpad;
1696 realpad = GST_PAD_REALIZE (pad);
1698 peer = GST_RPAD_PEER (realpad);
1700 GST_INFO (GST_CAT_CAPS, "proxy connect to pad %s:%s",
1701 GST_DEBUG_PAD_NAME (realpad));
1703 if (peer && gst_pad_try_set_caps_func (peer, caps, TRUE) < 0)
1704 return GST_PAD_CONNECT_REFUSED;
1705 if (gst_pad_try_set_caps_func (realpad, caps, FALSE) < 0)
1706 return GST_PAD_CONNECT_REFUSED;
1708 return GST_PAD_CONNECT_OK;
1713 * @pad: a #GstPad to get the capabilities of.
1715 * Gets the capabilities of this pad.
1717 * Returns: the #GstCaps of this pad.
1720 gst_pad_get_caps (GstPad *pad)
1722 GstRealPad *realpad;
1724 g_return_val_if_fail (pad != NULL, NULL);
1725 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1727 realpad = GST_PAD_REALIZE (pad);
1729 GST_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1730 GST_DEBUG_PAD_NAME (realpad), realpad);
1732 if (GST_PAD_CAPS (realpad)) {
1733 GST_DEBUG (GST_CAT_CAPS, "using pad real caps %p", GST_PAD_CAPS (realpad));
1734 return GST_PAD_CAPS (realpad);
1736 else if GST_RPAD_GETCAPSFUNC (realpad) {
1737 GST_DEBUG (GST_CAT_CAPS, "using pad get function");
1738 return GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD_CAST (realpad), NULL);
1740 else if (GST_PAD_PAD_TEMPLATE (realpad)) {
1741 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (realpad);
1742 GST_DEBUG (GST_CAT_CAPS, "using pad template %p with caps %p",
1743 templ, GST_PAD_TEMPLATE_CAPS (templ));
1744 return GST_PAD_TEMPLATE_CAPS (templ);
1746 GST_DEBUG (GST_CAT_CAPS, "pad has no caps");
1752 * gst_pad_get_pad_template_caps:
1753 * @pad: a #GstPad to get the template capabilities from.
1755 * Gets the template capabilities of this pad.
1757 * Returns: the template #GstCaps of this pad.
1760 gst_pad_get_pad_template_caps (GstPad *pad)
1762 g_return_val_if_fail (pad != NULL, NULL);
1763 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1765 if (GST_PAD_PAD_TEMPLATE (pad))
1766 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
1772 * gst_pad_template_get_caps_by_name:
1773 * @templ: a #GstPadTemplate to get the capabilities of.
1774 * @name: the name of the capability to get.
1776 * Gets the capability with the given name from this pad template.
1778 * Returns: the #GstCaps, or NULL if not found or in case of an error.
1781 gst_pad_template_get_caps_by_name (GstPadTemplate *templ, const gchar *name)
1785 g_return_val_if_fail (templ != NULL, NULL);
1787 caps = GST_PAD_TEMPLATE_CAPS (templ);
1791 return gst_caps_get_by_name (caps, name);
1795 * gst_pad_check_compatibility:
1796 * @srcpad: the source #GstPad to check.
1797 * @sinkpad: the sink #GstPad to check against.
1799 * Checks if two pads have compatible capabilities.
1801 * Returns: TRUE if they are compatible or if the capabilities
1802 * could not be checked
1805 gst_pad_check_compatibility (GstPad *srcpad, GstPad *sinkpad)
1807 g_return_val_if_fail (srcpad != NULL, FALSE);
1808 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1809 g_return_val_if_fail (sinkpad != NULL, FALSE);
1810 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1812 if (GST_PAD_CAPS (srcpad) && GST_PAD_CAPS (sinkpad)) {
1813 if (!gst_caps_is_always_compatible (GST_PAD_CAPS (srcpad),
1814 GST_PAD_CAPS (sinkpad))) {
1822 GST_DEBUG (GST_CAT_PADS,
1823 "could not check capabilities of pads (%s:%s) and (%s:%s) %p %p",
1824 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
1825 GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad));
1832 * @pad: a #GstPad to get the peer of.
1834 * Gets the peer pad of this pad.
1836 * Returns: the peer #GstPad.
1839 gst_pad_get_peer (GstPad *pad)
1841 g_return_val_if_fail (pad != NULL, NULL);
1842 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1844 return GST_PAD (GST_PAD_PEER (pad));
1848 * gst_pad_get_allowed_caps:
1849 * @pad: a #GstPad to get the allowed caps of.
1851 * Gets the capabilities of the allowed media types that can
1852 * flow through this pad. The caller must free the resulting caps.
1854 * Returns: a newly allocated copy of the allowed #GstCaps.
1857 gst_pad_get_allowed_caps (GstPad *pad)
1859 g_return_val_if_fail (pad != NULL, NULL);
1860 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1862 GST_DEBUG (GST_CAT_PROPERTIES, "get allowed caps of %s:%s",
1863 GST_DEBUG_PAD_NAME (pad));
1865 return gst_caps_copy (GST_RPAD_FILTER (pad));
1869 * gst_pad_recalc_allowed_caps:
1870 * @pad: a #GstPad to recalculate the capablities of.
1872 * Attempts to reconnect the pad to its peer through its filter,
1873 * set with gst_pad_[re]connect_filtered. This function is useful when a
1874 * plug-in has new capabilities on a pad and wants to notify the peer.
1876 * Returns: TRUE on success, FALSE otherwise.
1879 gst_pad_recalc_allowed_caps (GstPad *pad)
1883 g_return_val_if_fail (pad != NULL, FALSE);
1884 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1886 GST_DEBUG (GST_CAT_PROPERTIES, "set allowed caps of %s:%s",
1887 GST_DEBUG_PAD_NAME (pad));
1889 peer = GST_RPAD_PEER (pad);
1891 return gst_pad_try_reconnect_filtered (pad, GST_PAD (peer),
1892 GST_RPAD_APPFILTER (pad));
1898 * gst_pad_get_bufferpool:
1899 * @pad: a #GstPad to get the bufferpool from.
1901 * Gets the bufferpool of the peer pad of the given pad.Note that
1902 * a bufferpool can only be obtained from a srcpad.
1904 * Returns: the #GstBufferPool, or NULL in case of an error.
1907 gst_pad_get_bufferpool (GstPad *pad)
1911 g_return_val_if_fail (pad != NULL, NULL);
1912 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1913 g_return_val_if_fail (GST_PAD_IS_SRC (pad), NULL);
1915 peer = GST_RPAD_PEER (pad);
1920 GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
1922 if (peer->bufferpoolfunc) {
1923 GST_DEBUG (GST_CAT_PADS,
1924 "calling bufferpoolfunc &%s (@%p) of peer pad %s:%s",
1925 GST_DEBUG_FUNCPTR_NAME (peer->bufferpoolfunc),
1926 &peer->bufferpoolfunc, GST_DEBUG_PAD_NAME (((GstPad*) peer)));
1927 return (peer->bufferpoolfunc) (((GstPad*) peer));
1929 GST_DEBUG (GST_CAT_PADS, "no bufferpoolfunc for peer pad %s:%s at %p",
1930 GST_DEBUG_PAD_NAME (((GstPad*) peer)), &peer->bufferpoolfunc);
1936 gst_real_pad_dispose (GObject *object)
1938 GstPad *pad = GST_PAD (object);
1940 /* No connected pad can ever be disposed.
1941 * It has to have a parent to be connected
1942 * and a parent would hold a reference */
1943 g_assert (GST_PAD_PEER (pad) == NULL);
1945 GST_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s", GST_DEBUG_PAD_NAME(pad));
1947 if (GST_PAD_PAD_TEMPLATE (pad)){
1948 GST_DEBUG (GST_CAT_REFCOUNTING, "unreffing padtemplate'%s'",
1949 GST_OBJECT_NAME (GST_PAD_PAD_TEMPLATE (pad)));
1950 gst_object_unref (GST_OBJECT (GST_PAD_PAD_TEMPLATE (pad)));
1951 GST_PAD_PAD_TEMPLATE (pad) = NULL;
1954 /* we destroy the ghostpads, because they are nothing without the real pad */
1955 if (GST_REAL_PAD (pad)->ghostpads) {
1956 GList *orig, *ghostpads;
1958 orig = ghostpads = g_list_copy (GST_REAL_PAD (pad)->ghostpads);
1961 GstPad *ghostpad = GST_PAD (ghostpads->data);
1963 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))){
1964 GST_DEBUG (GST_CAT_REFCOUNTING, "removing ghost pad from element '%s'",
1965 GST_OBJECT_NAME (GST_OBJECT_PARENT (ghostpad)));
1967 gst_element_remove_ghost_pad (GST_ELEMENT (GST_OBJECT_PARENT (ghostpad)), GST_PAD (ghostpad));
1969 ghostpads = g_list_next (ghostpads);
1972 g_list_free (GST_REAL_PAD(pad)->ghostpads);
1975 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
1976 GST_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
1977 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
1979 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
1982 G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
1986 #ifndef GST_DISABLE_LOADSAVE
1987 /* FIXME: why isn't this on a GstElement ? */
1989 * gst_pad_load_and_connect:
1990 * @self: an #xmlNodePtr to read the description from.
1991 * @parent: the #GstObject element that owns the pad.
1993 * Reads the pad definition from the XML node and connects the given pad
1994 * in the element to a pad of an element up in the hierarchy.
1997 gst_pad_load_and_connect (xmlNodePtr self, GstObject *parent)
1999 xmlNodePtr field = self->xmlChildrenNode;
2000 GstPad *pad = NULL, *targetpad;
2004 GstObject *grandparent;
2007 if (!strcmp (field->name, "name")) {
2008 pad = gst_element_get_pad (GST_ELEMENT (parent),
2009 xmlNodeGetContent (field));
2011 else if (!strcmp(field->name, "peer")) {
2012 peer = xmlNodeGetContent (field);
2014 field = field->next;
2016 g_return_if_fail (pad != NULL);
2018 if (peer == NULL) return;
2020 split = g_strsplit (peer, ".", 2);
2022 if (split[0] == NULL || split[1] == NULL) {
2023 GST_DEBUG (GST_CAT_XML,
2024 "Could not parse peer '%s' for pad %s:%s, leaving unconnected",
2025 peer, GST_DEBUG_PAD_NAME (pad));
2029 g_return_if_fail (split[0] != NULL);
2030 g_return_if_fail (split[1] != NULL);
2032 grandparent = gst_object_get_parent (parent);
2034 if (grandparent && GST_IS_BIN (grandparent)) {
2035 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2040 if (target == NULL) goto cleanup;
2042 targetpad = gst_element_get_pad (target, split[1]);
2044 if (targetpad == NULL) goto cleanup;
2046 gst_pad_connect (pad, targetpad);
2053 * gst_pad_save_thyself:
2054 * @pad: a #GstPad to save.
2055 * @parent: the parent #xmlNodePtr to save the description in.
2057 * Saves the pad into an xml representation.
2059 * Returns: the #xmlNodePtr representation of the pad.
2062 gst_pad_save_thyself (GstObject *object, xmlNodePtr parent)
2064 GstRealPad *realpad;
2067 g_return_val_if_fail (GST_IS_REAL_PAD (object), NULL);
2069 realpad = GST_REAL_PAD (object);
2071 xmlNewChild (parent, NULL, "name", GST_PAD_NAME (realpad));
2072 if (GST_RPAD_PEER (realpad) != NULL) {
2075 peer = GST_PAD (GST_RPAD_PEER (realpad));
2076 /* first check to see if the peer's parent's parent is the same */
2077 /* we just save it off */
2078 content = g_strdup_printf ("%s.%s",
2079 GST_OBJECT_NAME (GST_PAD_PARENT (peer)),
2080 GST_PAD_NAME (peer));
2081 xmlNewChild (parent, NULL, "peer", content);
2084 xmlNewChild (parent, NULL, "peer", "");
2089 /* FIXME: shouldn't pad and ghost be switched ?
2092 * gst_ghost_pad_save_thyself:
2093 * @pad: a ghost #GstPad to save.
2094 * @parent: the parent #xmlNodePtr to save the description in.
2096 * Saves the ghost pad into an xml representation.
2098 * Returns: the #xmlNodePtr representation of the pad.
2101 gst_ghost_pad_save_thyself (GstPad *pad, xmlNodePtr parent)
2105 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2107 self = xmlNewChild (parent, NULL, "ghostpad", NULL);
2108 xmlNewChild (self, NULL, "name", GST_PAD_NAME (pad));
2109 xmlNewChild (self, NULL, "parent", GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
2111 /* FIXME FIXME FIXME! */
2115 #endif /* GST_DISABLE_LOADSAVE */
2119 * @pad: a #GstPad to push the buffer out of.
2120 * @buf: the #GstBuffer to push.
2122 * Pushes a buffer to the peer of the pad.
2125 gst_pad_push (GstPad *pad, GstBuffer *buf)
2129 GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
2131 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
2133 if (!gst_probe_dispatcher_dispatch (&(GST_REAL_PAD (pad)->probedisp), GST_DATA (buf)))
2136 peer = GST_RPAD_PEER (pad);
2139 g_warning ("push on pad %s:%s but it is unconnected",
2140 GST_DEBUG_PAD_NAME (pad));
2143 if (!GST_IS_EVENT (buf) && !GST_PAD_IS_ACTIVE (pad)) {
2144 g_warning ("push on pad %s:%s but it is not active",
2145 GST_DEBUG_PAD_NAME (pad));
2149 if (peer->chainhandler) {
2151 GST_DEBUG (GST_CAT_DATAFLOW,
2152 "calling chainhandler &%s of peer pad %s:%s",
2153 GST_DEBUG_FUNCPTR_NAME (peer->chainhandler),
2154 GST_DEBUG_PAD_NAME (GST_PAD (peer)));
2155 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, GST_DATA (buf)))
2158 (peer->chainhandler) (GST_PAD_CAST (peer), buf);
2162 g_warning ("trying to push a NULL buffer on pad %s:%s",
2163 GST_DEBUG_PAD_NAME (peer));
2168 g_warning ("internal error: push on pad %s:%s but it has no chainhandler",
2169 GST_DEBUG_PAD_NAME (peer));
2172 /* clean up the mess here */
2173 if (buf != NULL) gst_data_unref (GST_DATA (buf));
2178 * @pad: a #GstPad to pull a buffer from.
2180 * Pulls a buffer from the peer pad.
2182 * Returns: a new #GstBuffer from the peer pad.
2185 gst_pad_pull (GstPad *pad)
2189 GST_DEBUG_ENTER("(%s:%s)",GST_DEBUG_PAD_NAME(pad));
2191 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK, NULL);
2193 peer = GST_RPAD_PEER (pad);
2196 gst_element_error (GST_PAD_PARENT (pad),
2197 "pull on pad %s:%s but it was unconnected",
2198 GST_ELEMENT_NAME (GST_PAD_PARENT (pad)),
2199 GST_PAD_NAME (pad), NULL);
2202 if (peer->gethandler) {
2204 gboolean active = GST_PAD_IS_ACTIVE (peer);
2206 GST_DEBUG (GST_CAT_DATAFLOW, "calling gethandler %s of peer pad %s:%s",
2207 GST_DEBUG_FUNCPTR_NAME (peer->gethandler),
2208 GST_DEBUG_PAD_NAME (peer));
2210 buf = (peer->gethandler) (GST_PAD_CAST (peer));
2213 if (!gst_probe_dispatcher_dispatch (&peer->probedisp, GST_DATA (buf)))
2216 if (!GST_IS_EVENT (buf) && !active) {
2217 g_warning ("pull on pad %s:%s but it is not active",
2218 GST_DEBUG_PAD_NAME (peer));
2224 /* no null buffers allowed */
2225 gst_element_error (GST_PAD_PARENT (pad),
2226 "NULL buffer during pull on %s:%s",
2227 GST_DEBUG_PAD_NAME (pad), NULL);
2230 gst_element_error (GST_PAD_PARENT (pad),
2231 "internal error: pull on pad %s:%s "
2232 "but the peer pad %s:%s has no gethandler",
2233 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer),
2242 * @padlist: a #GList of pads.
2244 * Waits for a buffer on any of the list of pads.
2246 * Returns: the #GstPad that has a buffer available.
2247 * Use #gst_pad_pull() to get the buffer.
2250 gst_pad_select (GList *padlist)
2254 pad = gst_scheduler_pad_select (GST_PAD_PARENT (padlist->data)->sched,
2261 * @pad: a first #GstPad to perform the select on.
2262 * @...: A NULL-terminated list of more pads to select on.
2264 * Waits for a buffer on the given set of pads.
2266 * Returns: the #GstPad that has a buffer available.
2267 * Use #gst_pad_pull() to get the buffer.
2270 gst_pad_selectv (GstPad *pad, ...)
2273 GList *padlist = NULL;
2279 va_start (var_args, pad);
2282 padlist = g_list_prepend (padlist, pad);
2283 pad = va_arg (var_args, GstPad *);
2285 result = gst_pad_select (padlist);
2286 g_list_free (padlist);
2293 /************************************************************************
2298 static void gst_pad_template_class_init (GstPadTemplateClass *klass);
2299 static void gst_pad_template_init (GstPadTemplate *templ);
2302 gst_pad_template_get_type (void)
2304 static GType padtemplate_type = 0;
2306 if (!padtemplate_type) {
2307 static const GTypeInfo padtemplate_info = {
2308 sizeof (GstPadTemplateClass), NULL, NULL,
2309 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
2310 sizeof (GstPadTemplate),
2312 (GInstanceInitFunc) gst_pad_template_init, NULL
2314 padtemplate_type = g_type_register_static(GST_TYPE_OBJECT, "GstPadTemplate",
2315 &padtemplate_info, 0);
2317 return padtemplate_type;
2321 gst_pad_template_class_init (GstPadTemplateClass *klass)
2323 GObjectClass *gobject_class;
2324 GstObjectClass *gstobject_class;
2326 gobject_class = (GObjectClass*) klass;
2327 gstobject_class = (GstObjectClass*) klass;
2329 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
2331 gst_pad_template_signals[TEMPL_PAD_CREATED] =
2332 g_signal_new ("pad_created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
2333 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
2334 NULL, NULL, gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
2337 gstobject_class->path_string_separator = "*";
2341 gst_pad_template_init (GstPadTemplate *templ)
2345 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
2347 * SOMETIMES padtemplates can do whatever they want, they are provided by the
2349 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
2350 * 'sink%d' template is automatically selected), so we need to restrict their
2354 name_is_valid (const gchar *name, GstPadPresence presence)
2358 if (presence == GST_PAD_ALWAYS) {
2359 if (strchr (name, '%')) {
2360 g_warning ("invalid name template %s: conversion specifications are not"
2361 " allowed for GST_PAD_ALWAYS padtemplates", name);
2364 } else if (presence == GST_PAD_REQUEST) {
2365 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
2366 g_warning ("invalid name template %s: only one conversion specification"
2367 " allowed in GST_PAD_REQUEST padtemplate", name);
2370 if (str && (*(str+1) != 's' && *(str+1) != 'd')) {
2371 g_warning ("invalid name template %s: conversion specification must be of"
2372 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
2375 if (str && (*(str+2) != '\0')) {
2376 g_warning ("invalid name template %s: conversion specification must"
2377 " appear at the end of the GST_PAD_REQUEST padtemplate name",
2387 * gst_pad_template_new:
2388 * @name_template: the name template.
2389 * @direction: the #GstPadDirection of the template.
2390 * @presence: the #GstPadPresence of the pad.
2391 * @caps: a #GstCaps set for the template.
2392 * @...: a NULL-terminated list of #GstCaps.
2394 * Creates a new pad template with a name according to the given template
2395 * and with the given arguments.
2397 * Returns: a new #GstPadTemplate.
2400 gst_pad_template_new (const gchar *name_template,
2401 GstPadDirection direction, GstPadPresence presence,
2404 GstPadTemplate *new;
2406 GstCaps *thecaps = NULL;
2408 g_return_val_if_fail (name_template != NULL, NULL);
2410 if (!name_is_valid (name_template, presence))
2413 new = g_object_new (gst_pad_template_get_type (),
2414 "name", name_template,
2417 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
2418 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
2419 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
2421 va_start (var_args, caps);
2424 new->fixed &= caps->fixed;
2425 thecaps = gst_caps_append (thecaps, gst_caps_ref (caps));
2426 caps = va_arg (var_args, GstCaps*);
2430 GST_PAD_TEMPLATE_CAPS (new) = thecaps;
2436 * gst_pad_template_get_caps:
2437 * @templ: a #GstPadTemplate to get capabilities of.
2439 * Gets the capabilities of the pad template.
2441 * Returns: the #GstCaps of the pad template.
2444 gst_pad_template_get_caps (GstPadTemplate *templ)
2446 g_return_val_if_fail (templ != NULL, NULL);
2448 return GST_PAD_TEMPLATE_CAPS (templ);
2452 * gst_pad_set_element_private:
2453 * @pad: the #GstPad to set the private data of.
2454 * @priv: The private data to attach to the pad.
2456 * Set the given private data gpointer on the pad.
2457 * This function can only be used by the element that owns the pad.
2460 gst_pad_set_element_private (GstPad *pad, gpointer priv)
2462 pad->element_private = priv;
2466 * gst_pad_get_element_private:
2467 * @pad: the #GstPad to get the private data of.
2469 * Gets the private data of a pad.
2471 * Returns: a #gpointer to the private data.
2474 gst_pad_get_element_private (GstPad *pad)
2476 return pad->element_private;
2480 /***** ghost pads *****/
2481 GType _gst_ghost_pad_type = 0;
2483 static void gst_ghost_pad_class_init (GstGhostPadClass *klass);
2484 static void gst_ghost_pad_init (GstGhostPad *pad);
2486 static GstPad *ghost_pad_parent_class = NULL;
2487 /* static guint gst_ghost_pad_signals[LAST_SIGNAL] = { 0 }; */
2490 gst_ghost_pad_get_type (void)
2492 if (!_gst_ghost_pad_type) {
2493 static const GTypeInfo pad_info = {
2494 sizeof (GstGhostPadClass), NULL, NULL,
2495 (GClassInitFunc) gst_ghost_pad_class_init, NULL, NULL,
2496 sizeof (GstGhostPad),
2498 (GInstanceInitFunc) gst_ghost_pad_init,
2501 _gst_ghost_pad_type = g_type_register_static (GST_TYPE_PAD, "GstGhostPad",
2504 return _gst_ghost_pad_type;
2508 gst_ghost_pad_class_init (GstGhostPadClass *klass)
2510 GObjectClass *gobject_class;
2512 gobject_class = (GObjectClass*) klass;
2514 ghost_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
2518 gst_ghost_pad_init (GstGhostPad *pad)
2520 pad->realpad = NULL;
2524 * gst_ghost_pad_new:
2525 * @name: the name of the new ghost pad.
2526 * @pad: the #GstPad to create a ghost pad for.
2528 * Creates a new ghost pad associated with the given pad, and names it with
2529 * the given name. If name is NULL, a guaranteed unique name (across all
2530 * ghost pads) will be assigned (most likely of the form ghostpad&perc;d).
2532 * Returns: a new ghost #GstPad, or NULL in case of an error.
2536 gst_ghost_pad_new (const gchar *name,
2539 GstGhostPad *ghostpad;
2540 GstRealPad *realpad;
2542 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2544 ghostpad = g_object_new (gst_ghost_pad_get_type () ,NULL);
2545 gst_pad_set_name (GST_PAD (ghostpad), name);
2547 realpad = (GstRealPad *) pad;
2549 while (!GST_IS_REAL_PAD (realpad)) {
2550 realpad = GST_PAD_REALIZE (realpad);
2552 GST_GPAD_REALPAD (ghostpad) = realpad;
2553 GST_PAD_PAD_TEMPLATE (ghostpad) = GST_PAD_PAD_TEMPLATE (pad);
2555 /* add ourselves to the real pad's list of ghostpads */
2556 gst_pad_add_ghost_pad (pad, GST_PAD (ghostpad));
2558 /* FIXME need to ref the real pad here... ? */
2560 GST_DEBUG (GST_CAT_PADS, "created ghost pad \"%s\"",
2561 gst_pad_get_name (GST_PAD (ghostpad)));
2563 return GST_PAD (ghostpad);
2567 * gst_pad_get_internal_connections_default:
2568 * @pad: the #GstPad to get the internal connections of.
2570 * Gets a list of pads to which the given pad is connected to
2571 * inside of the parent element.
2572 * This is the default handler, and thus returns a list of all of the
2573 * pads inside the parent element with opposite direction.
2574 * The caller must free this list after use.
2576 * Returns: a newly allocated #GList of pads.
2579 gst_pad_get_internal_connections_default (GstPad *pad)
2584 GstPadDirection direction;
2587 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2589 rpad = GST_PAD_REALIZE (pad);
2590 direction = rpad->direction;
2592 parent = GST_PAD_PARENT (rpad);
2593 parent_pads = parent->pads;
2595 while (parent_pads) {
2596 GstRealPad *parent_pad = GST_PAD_REALIZE (parent_pads->data);
2598 if (parent_pad->direction != direction) {
2599 res = g_list_prepend (res, parent_pad);
2602 parent_pads = g_list_next (parent_pads);
2609 * gst_pad_get_internal_connections:
2610 * @pad: the #GstPad to get the internal connections of.
2612 * Gets a list of pads to which the given pad is connected to
2613 * inside of the parent element.
2614 * The caller must free this list after use.
2616 * Returns: a newly allocated #GList of pads.
2619 gst_pad_get_internal_connections (GstPad *pad)
2624 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2626 rpad = GST_PAD_REALIZE (pad);
2628 if (GST_RPAD_INTCONNFUNC (rpad))
2629 res = GST_RPAD_INTCONNFUNC (rpad) (GST_PAD_CAST (rpad));
2636 gst_pad_event_default_dispatch (GstPad *pad, GstElement *element,
2639 GList *pads = element->pads;
2642 GstPad *eventpad = GST_PAD (pads->data);
2643 pads = g_list_next (pads);
2645 /* for all pads in the opposite direction that are connected */
2646 if (GST_PAD_DIRECTION (eventpad) != GST_PAD_DIRECTION (pad)
2647 && GST_PAD_IS_CONNECTED (eventpad)) {
2648 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
2649 /* increase the refcount */
2650 gst_event_ref (event);
2651 gst_pad_push (eventpad, GST_BUFFER (event));
2654 GstPad *peerpad = GST_PAD_CAST (GST_RPAD_PEER (eventpad));
2656 /* we only send the event on one pad, multi-sinkpad elements
2657 * should implement a handler */
2658 return gst_pad_send_event (peerpad, event);
2662 gst_event_unref (event);
2667 * gst_pad_event_default:
2668 * @pad: a #GstPad to call the default event handler on.
2669 * @event: the #GstEvent to handle.
2671 * Invokes the default event handler for the given pad.
2673 * Returns: TRUE if the event was sent succesfully.
2676 gst_pad_event_default (GstPad *pad, GstEvent *event)
2678 GstElement *element;
2680 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2681 g_return_val_if_fail (event, FALSE);
2683 element = GST_PAD_PARENT (pad);
2685 switch (GST_EVENT_TYPE (event)) {
2687 gst_pad_event_default_dispatch (pad, element, event);
2688 gst_element_set_eos (element);
2689 /* we have to try to schedule another element
2690 * because this one is disabled */
2691 gst_element_yield (element);
2693 case GST_EVENT_DISCONTINUOUS:
2697 if (gst_event_discont_get_value (event, GST_FORMAT_TIME, &time)) {
2698 if (gst_element_requires_clock (element) && element->clock) {
2699 gst_clock_handle_discont (element->clock, time);
2703 case GST_EVENT_FLUSH:
2705 return gst_pad_event_default_dispatch (pad, element, event);
2711 * gst_pad_dispatcher:
2712 * @pad: a #GstPad to dispatch.
2713 * @dispatch: the #GstDispatcherFunction to call.
2714 * @data: gpointer user data passed to the dispatcher function.
2716 * Invokes the given dispatcher function on all pads that are
2717 * internally connected to the given pad.
2718 * The GstPadDispatcherFunction should return TRUE when no further pads
2719 * need to be processed.
2721 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2724 gst_pad_dispatcher (GstPad *pad, GstPadDispatcherFunction dispatch,
2727 gboolean res = FALSE;
2728 GList *int_pads, *orig;
2730 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2731 g_return_val_if_fail (data, FALSE);
2733 orig = int_pads = gst_pad_get_internal_connections (pad);
2736 GstRealPad *int_rpad = GST_PAD_REALIZE (int_pads->data);
2737 GstRealPad *int_peer = GST_RPAD_PEER (int_rpad);
2740 res = dispatch (GST_PAD_CAST (int_peer), data);
2744 int_pads = g_list_next (int_pads);
2753 * gst_pad_send_event:
2754 * @pad: a #GstPad to send the event to.
2755 * @event: the #GstEvent to send to the pad.
2757 * Sends the event to the pad.
2759 * Returns: TRUE if the event was handled.
2762 gst_pad_send_event (GstPad *pad, GstEvent *event)
2764 gboolean success = FALSE;
2767 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2768 g_return_val_if_fail (event, FALSE);
2770 rpad = GST_PAD_REALIZE (pad);
2772 if (GST_EVENT_SRC (event) == NULL)
2773 GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (rpad));
2775 GST_DEBUG (GST_CAT_EVENT, "have event %d on pad %s:%s",
2776 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (rpad));
2778 if (GST_RPAD_EVENTFUNC (rpad))
2779 success = GST_RPAD_EVENTFUNC (rpad) (GST_PAD_CAST (rpad), event);
2781 GST_DEBUG (GST_CAT_EVENT, "there's no event function for pad %s:%s",
2782 GST_DEBUG_PAD_NAME (rpad));
2783 gst_event_unref (event);
2791 GstFormat src_format;
2793 GstFormat *dest_format;
2795 } GstPadConvertData;
2798 gst_pad_convert_dispatcher (GstPad *pad, GstPadConvertData *data)
2800 return gst_pad_convert (pad, data->src_format, data->src_value,
2801 data->dest_format, data->dest_value);
2805 * gst_pad_convert_default:
2806 * @pad: a #GstPad to invoke the default converter on.
2807 * @src_format: the source #GstFormat.
2808 * @src_value: the source value.
2809 * @dest_format: a pointer to the destination #GstFormat.
2810 * @dest_value: a pointer to the destination value.
2812 * Invokes the default converter on a pad.
2813 * This will forward the call to the pad obtained
2814 * using the internal connection of
2817 * Returns: TRUE if the conversion could be performed.
2820 gst_pad_convert_default (GstPad *pad,
2821 GstFormat src_format, gint64 src_value,
2822 GstFormat *dest_format, gint64 *dest_value)
2824 GstPadConvertData data;
2826 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2827 g_return_val_if_fail (dest_format, FALSE);
2828 g_return_val_if_fail (dest_value, FALSE);
2830 data.src_format = src_format;
2831 data.src_value = src_value;
2832 data.dest_format = dest_format;
2833 data.dest_value = dest_value;
2835 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
2836 gst_pad_convert_dispatcher, &data);
2841 * @pad: a #GstPad to invoke the default converter on.
2842 * @src_format: the source #GstFormat.
2843 * @src_value: the source value.
2844 * @dest_format: a pointer to the destination #GstFormat.
2845 * @dest_value: a pointer to the destination value.
2847 * Invokes a conversion on the pad.
2849 * Returns: TRUE if the conversion could be performed.
2852 gst_pad_convert (GstPad *pad,
2853 GstFormat src_format, gint64 src_value,
2854 GstFormat *dest_format, gint64 *dest_value)
2858 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2859 g_return_val_if_fail (dest_format, FALSE);
2860 g_return_val_if_fail (dest_value, FALSE);
2862 if (src_format == *dest_format) {
2863 *dest_value = src_value;
2867 rpad = GST_PAD_REALIZE (pad);
2869 if (GST_RPAD_CONVERTFUNC (rpad)) {
2870 return GST_RPAD_CONVERTFUNC (rpad) (GST_PAD_CAST (rpad), src_format,
2871 src_value, dest_format, dest_value);
2885 gst_pad_query_dispatcher (GstPad *pad, GstPadQueryData *data)
2887 return gst_pad_query (pad, data->type, data->format, data->value);
2891 * gst_pad_query_default:
2892 * @pad: a #GstPad to invoke the default query on.
2893 * @type: the #GstQueryType of the query to perform.
2894 * @format: a pointer to the #GstFormat of the result.
2895 * @value: a pointer to the result.
2897 * Invokes the default query function on a pad.
2899 * Returns: TRUE if the query could be performed.
2902 gst_pad_query_default (GstPad *pad, GstQueryType type,
2903 GstFormat *format, gint64 *value)
2905 GstPadQueryData data;
2907 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2908 g_return_val_if_fail (format, FALSE);
2909 g_return_val_if_fail (value, FALSE);
2912 data.format = format;
2915 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
2916 gst_pad_query_dispatcher, &data);
2921 * @pad: a #GstPad to invoke the default query on.
2922 * @type: the #GstQueryType of the query to perform.
2923 * @format: a pointer to the #GstFormat of the result.
2924 * @value: a pointer to the result.
2926 * Queries a pad for one of the available properties.
2928 * Returns: TRUE if the query could be performed.
2931 gst_pad_query (GstPad *pad, GstQueryType type,
2932 GstFormat *format, gint64 *value)
2936 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2937 g_return_val_if_fail (format, FALSE);
2938 g_return_val_if_fail (value, FALSE);
2940 rpad = GST_PAD_REALIZE (pad);
2942 g_return_val_if_fail (rpad, FALSE);
2944 if (GST_RPAD_QUERYFUNC (rpad))
2945 return GST_RPAD_QUERYFUNC (rpad) (GST_PAD_CAST (pad), type, format, value);
2951 gst_pad_get_formats_dispatcher (GstPad *pad, const GstFormat **data)
2953 *data = gst_pad_get_formats (pad);
2959 * gst_pad_get_formats_default:
2960 * @pad: a #GstPad to query
2962 * Invoke the default format dispatcher for the pad.
2964 * Returns: An array of GstFormats ended with a 0 value.
2967 gst_pad_get_formats_default (GstPad *pad)
2969 GstFormat *result = NULL;
2971 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
2972 gst_pad_get_formats_dispatcher, &result);
2978 * gst_pad_get_formats:
2979 * @pad: a #GstPad to query
2981 * Gets the list of supported formats from the pad.
2983 * Returns: An array of GstFormats ended with a 0 value.
2986 gst_pad_get_formats (GstPad *pad)
2990 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2992 rpad = GST_PAD_REALIZE (pad);
2994 if (GST_RPAD_FORMATSFUNC (rpad))
2995 return GST_RPAD_FORMATSFUNC (rpad) (GST_PAD_CAST (pad));