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 */
97 REAL_CAPS_NEGO_FAILED,
111 static void gst_real_pad_class_init (GstRealPadClass *klass);
112 static void gst_real_pad_init (GstRealPad *pad);
114 static void gst_real_pad_set_property (GObject *object, guint prop_id,
117 static void gst_real_pad_get_property (GObject *object, guint prop_id,
121 static void gst_real_pad_dispose (GObject *object);
123 static void gst_pad_push_func (GstPad *pad, GstBuffer *buf);
125 GType _gst_real_pad_type = 0;
127 static GstPad *real_pad_parent_class = NULL;
128 static guint gst_real_pad_signals[REAL_LAST_SIGNAL] = { 0 };
131 gst_real_pad_get_type (void) {
132 if (!_gst_real_pad_type) {
133 static const GTypeInfo pad_info = {
134 sizeof (GstRealPadClass), NULL, NULL,
135 (GClassInitFunc) gst_real_pad_class_init, NULL, NULL,
138 (GInstanceInitFunc) gst_real_pad_init, NULL
140 _gst_real_pad_type = g_type_register_static (GST_TYPE_PAD, "GstRealPad",
143 return _gst_real_pad_type;
147 gst_real_pad_class_init (GstRealPadClass *klass)
149 GObjectClass *gobject_class;
150 GstObjectClass *gstobject_class;
152 gobject_class = (GObjectClass*) klass;
153 gstobject_class = (GstObjectClass*) klass;
155 real_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
157 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_real_pad_dispose);
158 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_real_pad_set_property);
159 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_real_pad_get_property);
161 gst_real_pad_signals[REAL_SET_ACTIVE] =
162 g_signal_new ("set_active", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
163 G_STRUCT_OFFSET (GstRealPadClass, set_active), NULL, NULL,
164 gst_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1,
166 gst_real_pad_signals[REAL_CAPS_CHANGED] =
167 g_signal_new ("caps_changed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
168 G_STRUCT_OFFSET (GstRealPadClass, caps_changed), NULL, NULL,
169 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
171 gst_real_pad_signals[REAL_CAPS_NEGO_FAILED] =
172 g_signal_new ("caps_nego_failed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
173 G_STRUCT_OFFSET (GstRealPadClass, caps_nego_failed), NULL, NULL,
174 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
176 gst_real_pad_signals[REAL_CONNECTED] =
177 g_signal_new ("connected", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
178 G_STRUCT_OFFSET (GstRealPadClass, connected), NULL, NULL,
179 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
181 gst_real_pad_signals[REAL_DISCONNECTED] =
182 g_signal_new ("disconnected", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
183 G_STRUCT_OFFSET (GstRealPadClass, disconnected), NULL, NULL,
184 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
186 gst_real_pad_signals[REAL_EVENT_RECEIVED] =
187 g_signal_new ("event_received", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
188 G_STRUCT_OFFSET (GstRealPadClass, event_received), NULL, NULL,
189 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
192 /* gtk_object_add_arg_type ("GstRealPad::active", G_TYPE_BOOLEAN, */
193 /* GTK_ARG_READWRITE, REAL_ARG_ACTIVE); */
194 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_ACTIVE,
195 g_param_spec_boolean ("active", "Active", "Whether the pad is active.",
196 TRUE, G_PARAM_READWRITE));
198 #ifndef GST_DISABLE_LOADSAVE
199 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
201 gstobject_class->path_string_separator = ".";
205 gst_real_pad_init (GstRealPad *pad)
207 pad->direction = GST_PAD_UNKNOWN;
210 pad->chainfunc = NULL;
213 pad->chainhandler = GST_DEBUG_FUNCPTR (gst_pad_push_func);
214 pad->gethandler = NULL;
216 pad->bufferpoolfunc = NULL;
217 pad->ghostpads = NULL;
220 pad->connectfunc = NULL;
221 pad->getcapsfunc = NULL;
223 pad->convertfunc = gst_pad_convert_default;
224 pad->eventfunc = gst_pad_event_default;
225 pad->convertfunc = gst_pad_convert_default;
226 pad->queryfunc = gst_pad_query_default;
227 pad->intconnfunc = gst_pad_get_internal_connections_default;
229 pad->eventmaskfunc = gst_pad_get_event_masks_default;
230 pad->formatsfunc = gst_pad_get_formats_default;
231 pad->querytypefunc = gst_pad_get_query_types_default;
235 gst_real_pad_set_property (GObject *object, guint prop_id,
236 const GValue *value, GParamSpec *pspec)
238 g_return_if_fail (GST_IS_PAD (object));
241 case REAL_ARG_ACTIVE:
242 gst_pad_set_active (GST_PAD (object), g_value_get_boolean (value));
245 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
251 gst_real_pad_get_property (GObject *object, guint prop_id,
252 GValue *value, GParamSpec *pspec)
254 g_return_if_fail (GST_IS_PAD (object));
257 case REAL_ARG_ACTIVE:
258 g_value_set_boolean (value, !GST_FLAG_IS_SET (object, GST_PAD_DISABLED));
261 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
268 * gst_pad_custom_new:
269 * @type: the #Gtype of the pad.
270 * @name: the name of the new pad.
271 * @direction: the #GstPadDirection of the pad.
273 * Creates a new pad with the given name and type in the given direction.
274 * If name is NULL, a guaranteed unique name (across all pads)
277 * Returns: a new #GstPad, or NULL in case of an error.
280 gst_pad_custom_new (GType type, const gchar *name,
281 GstPadDirection direction)
285 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
287 pad = g_object_new (type, NULL);
288 gst_object_set_name (GST_OBJECT (pad), name);
289 GST_RPAD_DIRECTION (pad) = direction;
291 return GST_PAD (pad);
296 * @name: the name of the new pad.
297 * @direction: the #GstPadDirection of the pad.
299 * Creates a new real pad with the given name in the given direction.
300 * If name is NULL, a guaranteed unique name (across all pads)
303 * Returns: a new #GstPad, or NULL in case of an error.
306 gst_pad_new (const gchar *name,
307 GstPadDirection direction)
309 return gst_pad_custom_new (gst_real_pad_get_type (), name, direction);
313 * gst_pad_custom_new_from_template:
314 * @type: the custom #GType of the pad.
315 * @templ: the #GstPadTemplate to instantiate from.
316 * @name: the name of the new pad.
318 * Creates a new custom pad with the given name from the given template.
319 * If name is NULL, a guaranteed unique name (across all pads)
322 * Returns: a new #GstPad, or NULL in case of an error.
325 gst_pad_custom_new_from_template (GType type, GstPadTemplate *templ,
330 g_return_val_if_fail (templ != NULL, NULL);
332 pad = gst_pad_new (name, templ->direction);
334 gst_object_ref (GST_OBJECT (templ));
335 GST_PAD_PAD_TEMPLATE (pad) = templ;
337 g_signal_emit (G_OBJECT (templ), gst_pad_template_signals[TEMPL_PAD_CREATED], 0, pad);
343 * gst_pad_new_from_template:
344 * @templ: the pad template to use
345 * @name: the name of the element
347 * Creates a new real pad with the given name from the given template.
348 * If name is NULL, a guaranteed unique name (across all pads)
351 * Returns: a new #GstPad, or NULL in case of an error.
354 gst_pad_new_from_template (GstPadTemplate *templ, const gchar *name)
356 return gst_pad_custom_new_from_template (gst_real_pad_get_type (),
361 * gst_pad_get_direction:
362 * @pad: a #GstPad to get the direction of.
364 * Gets the direction of the pad.
366 * Returns: the #GstPadDirection of the pad.
369 gst_pad_get_direction (GstPad *pad)
371 g_return_val_if_fail (pad != NULL, GST_PAD_UNKNOWN);
372 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
374 return GST_PAD_DIRECTION (pad);
378 * gst_pad_set_active:
379 * @pad: the #GstPad to activate or deactivate.
381 * Activates or deactivates the given pad.
384 gst_pad_set_active (GstPad *pad, gboolean active)
388 g_return_if_fail (pad != NULL);
389 g_return_if_fail (GST_IS_PAD (pad));
391 if (GST_PAD_IS_ACTIVE (pad) == active)
394 realpad = GST_PAD_REALIZE (pad);
397 GST_DEBUG (GST_CAT_PADS, "activating pad %s:%s",
398 GST_DEBUG_PAD_NAME (realpad));
399 GST_FLAG_UNSET (realpad, GST_PAD_DISABLED);
401 GST_DEBUG (GST_CAT_PADS, "de-activating pad %s:%s",
402 GST_DEBUG_PAD_NAME (realpad));
403 GST_FLAG_SET (realpad, GST_PAD_DISABLED);
405 g_signal_emit (G_OBJECT (realpad), gst_real_pad_signals[REAL_SET_ACTIVE], 0,
406 !GST_FLAG_IS_SET (realpad, GST_PAD_DISABLED));
411 * @pad: a #GstPad to set the name of.
412 * @name: the name of the pad.
414 * Sets the name of a pad. If name is NULL, then a guaranteed unique
415 * name will be assigned.
418 gst_pad_set_name (GstPad *pad, const gchar *name)
420 g_return_if_fail (pad != NULL);
421 g_return_if_fail (GST_IS_PAD (pad));
423 gst_object_set_name (GST_OBJECT (pad), name);
428 * @pad: a #GstPad to get the name of.
430 * Gets the name of a pad.
432 * Returns: the name of the pad. This is not a newly allocated pointer
433 * so you must not free it.
436 gst_pad_get_name (GstPad *pad)
438 g_return_val_if_fail (pad != NULL, NULL);
439 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
441 return GST_OBJECT_NAME (pad);
445 * gst_pad_set_chain_function:
446 * @pad: a #GstPad to set the chain function for.
447 * @chain: the #GstPadChainFunction to set.
449 * Sets the given chain function for the pad.
452 gst_pad_set_chain_function (GstPad *pad, GstPadChainFunction chain)
454 g_return_if_fail (pad != NULL);
455 g_return_if_fail (GST_IS_REAL_PAD (pad));
457 GST_RPAD_CHAINFUNC (pad) = chain;
458 GST_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s",
459 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
463 * gst_pad_set_get_function:
464 * @pad: a #GstPad to set the get function for.
465 * @get: the #GstPadGetFunction to set.
467 * Sets the given get function for the pad.
470 gst_pad_set_get_function (GstPad *pad,
471 GstPadGetFunction get)
473 g_return_if_fail (pad != NULL);
474 g_return_if_fail (GST_IS_REAL_PAD (pad));
476 GST_RPAD_GETFUNC (pad) = get;
478 GST_DEBUG (GST_CAT_PADS, "getfunc for %s:%s set to %s",
479 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
483 * gst_pad_set_event_function:
484 * @pad: a #GstPad to set the event handler for.
485 * @event: the #GstPadEventFunction to set.
487 * Sets the given event handler for the pad.
490 gst_pad_set_event_function (GstPad *pad,
491 GstPadEventFunction event)
493 g_return_if_fail (pad != NULL);
494 g_return_if_fail (GST_IS_REAL_PAD (pad));
496 GST_RPAD_EVENTFUNC (pad) = event;
498 GST_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s",
499 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
503 gst_pad_set_event_mask_function (GstPad *pad,
504 GstPadEventMaskFunction mask_function)
506 g_return_if_fail (pad != NULL);
507 g_return_if_fail (GST_IS_REAL_PAD (pad));
509 GST_RPAD_EVENTMASKFUNC (pad) = mask_function;
511 GST_DEBUG (GST_CAT_PADS, "eventmaskfunc for %s:%s set to %s",
512 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (mask_function));
516 gst_pad_get_event_masks (GstPad *pad)
523 rpad = GST_PAD_REALIZE (pad);
525 g_return_val_if_fail (rpad, FALSE);
527 if (GST_RPAD_EVENTMASKFUNC (rpad))
528 return GST_RPAD_EVENTMASKFUNC (rpad) (GST_PAD_CAST (pad));
534 gst_pad_get_event_masks_dispatcher (GstPad *pad, const GstFormat **data)
536 *data = gst_pad_get_formats (pad);
542 gst_pad_get_event_masks_default (GstPad *pad)
544 GstEventMask *result = NULL;
546 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
547 gst_pad_get_event_masks_dispatcher, &result);
553 gst_pad_handles_event (GstPad *pad, GstEventMask *mask)
555 const GstEventMask *masks;
557 g_return_val_if_fail (pad != NULL, FALSE);
558 g_return_val_if_fail (mask != NULL, FALSE);
560 masks = gst_pad_get_event_masks (pad);
564 while (masks->type) {
565 if (masks->type == mask->type &&
566 (masks->flags & mask->flags) == mask->flags)
576 * gst_pad_set_convert_function:
577 * @pad: a #GstPad to set the convert function for.
578 * @convert: the #GstPadConvertFunction to set.
580 * Sets the given convert function for the pad.
583 gst_pad_set_convert_function (GstPad *pad,
584 GstPadConvertFunction convert)
586 g_return_if_fail (pad != NULL);
587 g_return_if_fail (GST_IS_REAL_PAD (pad));
589 GST_RPAD_CONVERTFUNC (pad) = convert;
591 GST_DEBUG (GST_CAT_PADS, "convertfunc for %s:%s set to %s",
592 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (convert));
596 * gst_pad_set_query_function:
597 * @pad: the #GstPad to set the query function for.
598 * @query: the #GstPadQueryFunction to set.
600 * Set the given query function for the pad.
603 gst_pad_set_query_function (GstPad *pad, GstPadQueryFunction query)
605 g_return_if_fail (pad != NULL);
606 g_return_if_fail (GST_IS_REAL_PAD (pad));
608 GST_RPAD_QUERYFUNC (pad) = query;
610 GST_DEBUG (GST_CAT_PADS, "queryfunc for %s:%s set to %s",
611 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (query));
615 gst_pad_set_query_type_function (GstPad *pad, GstPadQueryTypeFunction type_func)
617 g_return_if_fail (pad != NULL);
618 g_return_if_fail (GST_IS_REAL_PAD (pad));
620 GST_RPAD_QUERYTYPEFUNC (pad) = type_func;
622 GST_DEBUG (GST_CAT_PADS, "querytypefunc for %s:%s set to %s",
623 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (type_func));
626 const GstPadQueryType*
627 gst_pad_get_query_types (GstPad *pad)
634 rpad = GST_PAD_REALIZE (pad);
636 g_return_val_if_fail (rpad, FALSE);
638 if (GST_RPAD_QUERYTYPEFUNC (rpad))
639 return GST_RPAD_QUERYTYPEFUNC (rpad) (GST_PAD_CAST (pad));
645 gst_pad_get_query_types_dispatcher (GstPad *pad, const GstPadQueryType **data)
647 *data = gst_pad_get_query_types (pad);
652 const GstPadQueryType*
653 gst_pad_get_query_types_default (GstPad *pad)
655 GstPadQueryType *result = NULL;
657 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
658 gst_pad_get_query_types_dispatcher, &result);
664 * gst_pad_set_internal_connection_function:
665 * @pad: a #GstPad to set the internal connection function for.
666 * @intconn: the #GstPadIntConnFunction to set.
668 * Sets the given internal connection function for the pad.
671 gst_pad_set_internal_connection_function (GstPad *pad,
672 GstPadIntConnFunction intconn)
674 g_return_if_fail (pad != NULL);
675 g_return_if_fail (GST_IS_REAL_PAD (pad));
677 GST_RPAD_INTCONNFUNC (pad) = intconn;
678 GST_DEBUG (GST_CAT_PADS, "internal connection for %s:%s set to %s",
679 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (intconn));
683 * gst_pad_set_formats_function:
684 * @pad: the #GstPad to set the formats function for.
685 * @formats: the #GstPadFormatsFunction to set.
687 * Sets the given formats function for the pad.
690 gst_pad_set_formats_function (GstPad *pad, GstPadFormatsFunction formats)
692 g_return_if_fail (pad != NULL);
693 g_return_if_fail (GST_IS_REAL_PAD (pad));
695 GST_RPAD_FORMATSFUNC (pad) = formats;
696 GST_DEBUG (GST_CAT_PADS, "formats function for %s:%s set to %s",
697 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (formats));
701 * gst_pad_set_connect_function:
702 * @pad: a #GstPad to set the connect function for.
703 * @connect: the #GstPadConnectFunction to set.
705 * Sets the given connect function for the pad. It will be called
706 * when the pad is connected or reconnected with caps.
709 gst_pad_set_connect_function (GstPad *pad,
710 GstPadConnectFunction connect)
712 g_return_if_fail (pad != NULL);
713 g_return_if_fail (GST_IS_REAL_PAD (pad));
715 GST_RPAD_CONNECTFUNC (pad) = connect;
716 GST_DEBUG (GST_CAT_PADS, "connectfunc for %s:%s set to %s",
717 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (connect));
721 * gst_pad_set_getcaps_function:
722 * @pad: a #GstPad to set the getcaps function for.
723 * @getcaps: the #GstPadGetCapsFunction to set.
725 * Sets the given getcaps function for the pad.
728 gst_pad_set_getcaps_function (GstPad *pad,
729 GstPadGetCapsFunction getcaps)
731 g_return_if_fail (pad != NULL);
732 g_return_if_fail (GST_IS_REAL_PAD (pad));
734 GST_RPAD_GETCAPSFUNC (pad) = getcaps;
735 GST_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s",
736 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
739 * gst_pad_set_bufferpool_function:
740 * @pad: a #GstPad to set the bufferpool function for.
741 * @bufpool: the #GstPadBufferPoolFunction to set.
743 * Sets the given bufferpool function for the pad.
746 gst_pad_set_bufferpool_function (GstPad *pad,
747 GstPadBufferPoolFunction bufpool)
749 g_return_if_fail (pad != NULL);
750 g_return_if_fail (GST_IS_REAL_PAD (pad));
752 GST_RPAD_BUFFERPOOLFUNC (pad) = bufpool;
753 GST_DEBUG (GST_CAT_PADS, "bufferpoolfunc for %s:%s set to %s",
754 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufpool));
758 gst_pad_push_func (GstPad *pad, GstBuffer *buf)
760 if (GST_RPAD_CHAINFUNC (GST_RPAD_PEER (pad)) != NULL) {
761 GST_DEBUG (GST_CAT_DATAFLOW, "calling chain function %s",
762 GST_DEBUG_FUNCPTR_NAME (GST_RPAD_CHAINFUNC (GST_RPAD_PEER (pad))));
763 (GST_RPAD_CHAINFUNC (GST_RPAD_PEER (pad))) (pad, buf);
765 GST_DEBUG (GST_CAT_DATAFLOW,
766 "default pad_push handler in place, no chain function");
767 g_warning ("(internal error) default pad_push in place for pad %s:%s"
768 "but it has no chain function", GST_DEBUG_PAD_NAME (pad));
774 * gst_pad_disconnect:
775 * @srcpad: the source #GstPad to disconnect.
776 * @sinkpad: the sink #GstPad to disconnect.
778 * Disconnects the source pad from the sink pad.
781 gst_pad_disconnect (GstPad *srcpad,
784 GstRealPad *realsrc, *realsink;
785 GstScheduler *src_sched, *sink_sched;
788 g_return_if_fail (srcpad != NULL);
789 g_return_if_fail (GST_IS_PAD (srcpad));
790 g_return_if_fail (sinkpad != NULL);
791 g_return_if_fail (GST_IS_PAD (sinkpad));
793 GST_INFO (GST_CAT_ELEMENT_PADS, "disconnecting %s:%s(%p) and %s:%s(%p)",
794 GST_DEBUG_PAD_NAME (srcpad), srcpad,
795 GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
797 /* now we need to deal with the real/ghost stuff */
798 realsrc = GST_PAD_REALIZE (srcpad);
799 realsink = GST_PAD_REALIZE (sinkpad);
801 g_return_if_fail (GST_RPAD_PEER (realsrc) != NULL);
802 g_return_if_fail (GST_RPAD_PEER (realsink) == realsrc);
804 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
805 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
812 g_return_if_fail ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
813 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK));
815 /* get the schedulers before we disconnect */
816 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
817 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
819 /* first clear peers */
820 GST_RPAD_PEER (realsrc) = NULL;
821 GST_RPAD_PEER (realsink) = NULL;
823 /* reset the filters, both filters are refcounted once */
824 if (GST_RPAD_FILTER (realsrc)) {
825 gst_caps_unref (GST_RPAD_FILTER (realsrc));
826 GST_RPAD_FILTER (realsink) = NULL;
827 GST_RPAD_FILTER (realsrc) = NULL;
830 /* now tell the scheduler */
832 gst_scheduler_pad_disconnect (src_sched,
833 GST_PAD_CAST (realsrc), GST_PAD_CAST (realsink));
835 gst_scheduler_pad_disconnect (sink_sched,
836 GST_PAD_CAST (realsrc), GST_PAD_CAST (realsink));
838 /* hold a reference, as they can go away in the signal handlers */
839 gst_object_ref (GST_OBJECT (realsrc));
840 gst_object_ref (GST_OBJECT (realsink));
842 /* fire off a signal to each of the pads telling them
843 * that they've been disconnected */
844 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_DISCONNECTED],
846 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_DISCONNECTED],
849 GST_INFO (GST_CAT_ELEMENT_PADS, "disconnected %s:%s and %s:%s",
850 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
852 gst_object_unref (GST_OBJECT (realsrc));
853 gst_object_unref (GST_OBJECT (realsink));
857 gst_pad_check_schedulers (GstRealPad *realsrc, GstRealPad *realsink)
859 GstScheduler *src_sched, *sink_sched;
860 gint num_decoupled = 0;
862 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
863 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
865 if (src_sched && sink_sched) {
866 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsrc), GST_ELEMENT_DECOUPLED))
868 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsink), GST_ELEMENT_DECOUPLED))
871 if (src_sched != sink_sched && num_decoupled != 1) {
879 * gst_pad_can_connect_filtered:
880 * @srcpad: the source #GstPad to connect.
881 * @sinkpad: the sink #GstPad to connect.
882 * @filtercaps: the filter #GstCaps.
884 * Checks if the source pad and the sink pad can be connected when constrained
885 * by the given filter caps.
887 * Returns: TRUE if the pads can be connected, FALSE otherwise.
890 gst_pad_can_connect_filtered (GstPad *srcpad, GstPad *sinkpad,
893 GstRealPad *realsrc, *realsink;
896 g_return_val_if_fail (srcpad != NULL, FALSE);
897 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
898 g_return_val_if_fail (sinkpad != NULL, FALSE);
899 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
901 /* now we need to deal with the real/ghost stuff */
902 realsrc = GST_PAD_REALIZE (srcpad);
903 realsink = GST_PAD_REALIZE (sinkpad);
905 g_return_val_if_fail (GST_RPAD_PEER (realsrc) == NULL, FALSE);
906 g_return_val_if_fail (GST_RPAD_PEER (realsink) == NULL, FALSE);
907 g_return_val_if_fail (GST_PAD_PARENT (realsrc) != NULL, FALSE);
908 g_return_val_if_fail (GST_PAD_PARENT (realsink) != NULL, FALSE);
910 if (!gst_pad_check_schedulers (realsrc, realsink)) {
911 g_warning ("connecting pads with different scheds requires "
912 "exactly one decoupled element (queue)");
916 /* check if the directions are compatible */
917 if (!(((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
918 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) ||
919 ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
920 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK))))
926 * gst_pad_can_connect:
927 * @srcpad: the source #GstPad to connect.
928 * @sinkpad: the sink #GstPad to connect.
930 * Checks if the source pad and the sink pad can be connected.
932 * Returns: TRUE if the pads can be connected, FALSE otherwise.
935 gst_pad_can_connect (GstPad *srcpad, GstPad *sinkpad)
937 return gst_pad_can_connect_filtered (srcpad, sinkpad, NULL);
941 * gst_pad_connect_filtered:
942 * @srcpad: the source #GstPad to connect.
943 * @sinkpad: the sink #GstPad to connect.
944 * @filtercaps: the filter #GstCaps.
946 * Connects the source pad and the sink pad can be connected, constrained
947 * by the given filter caps.
949 * Returns: TRUE if the pads have been connected, FALSE otherwise.
952 gst_pad_connect_filtered (GstPad *srcpad, GstPad *sinkpad, GstCaps *filtercaps)
954 GstRealPad *realsrc, *realsink;
955 GstScheduler *src_sched, *sink_sched;
958 g_return_val_if_fail (srcpad != NULL, FALSE);
959 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
960 g_return_val_if_fail (sinkpad != NULL, FALSE);
961 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
963 GST_INFO (GST_CAT_PADS, "trying to connect %s:%s and %s:%s",
964 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
966 /* now we need to deal with the real/ghost stuff */
967 realsrc = GST_PAD_REALIZE (srcpad);
968 realsink = GST_PAD_REALIZE (sinkpad);
970 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad)) {
971 GST_INFO (GST_CAT_PADS, "*actually* connecting %s:%s and %s:%s",
972 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
974 if (GST_RPAD_PEER (realsrc) != NULL)
976 GST_INFO (GST_CAT_PADS, "Real source pad %s:%s has a peer, failed",
977 GST_DEBUG_PAD_NAME (realsrc));
980 if (GST_RPAD_PEER (realsink) != NULL)
982 GST_INFO (GST_CAT_PADS, "Real sink pad %s:%s has a peer, failed",
983 GST_DEBUG_PAD_NAME (realsink));
986 if (GST_PAD_PARENT (realsrc) == NULL)
988 GST_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
989 GST_DEBUG_PAD_NAME (realsrc));
992 if (GST_PAD_PARENT (realsink) == NULL)
994 GST_INFO (GST_CAT_PADS, "Real src pad %s:%s has no parent, failed",
995 GST_DEBUG_PAD_NAME (realsrc));
999 if (!gst_pad_check_schedulers (realsrc, realsink)) {
1000 g_warning ("connecting pads with different scheds requires "
1001 "exactly one decoupled element (such as queue)");
1005 /* check for reversed directions and swap if necessary */
1006 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
1007 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
1008 GstRealPad *temppad;
1014 if (GST_PAD_PARENT (realsink) == NULL)
1015 if (GST_RPAD_DIRECTION (realsrc) != GST_PAD_SRC)
1017 GST_INFO (GST_CAT_PADS, "Real src pad %s:%s is not a source pad, failed",
1018 GST_DEBUG_PAD_NAME (realsrc));
1021 if (GST_RPAD_DIRECTION (realsink) != GST_PAD_SINK)
1023 GST_INFO (GST_CAT_PADS, "Real sink pad %s:%s is not a sink pad, failed",
1024 GST_DEBUG_PAD_NAME (realsink));
1027 /* first set peers */
1028 GST_RPAD_PEER (realsrc) = realsink;
1029 GST_RPAD_PEER (realsink) = realsrc;
1031 /* try to negotiate the pads, we don't need to clear the caps here */
1032 if (!gst_pad_try_reconnect_filtered_func (realsrc, realsink,
1033 filtercaps, FALSE)) {
1034 GST_DEBUG (GST_CAT_CAPS, "reconnect_filtered_func failed, can't connect");
1036 GST_RPAD_PEER (realsrc) = NULL;
1037 GST_RPAD_PEER (realsink) = NULL;
1042 /* fire off a signal to each of the pads telling them
1043 * that they've been connected */
1044 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_CONNECTED],
1046 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_CONNECTED],
1049 src_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsrc));
1050 sink_sched = gst_pad_get_scheduler (GST_PAD_CAST (realsink));
1052 /* now tell the scheduler */
1054 gst_scheduler_pad_connect (src_sched,
1055 GST_PAD_CAST (realsrc), GST_PAD_CAST (realsink));
1056 else if (sink_sched)
1057 gst_scheduler_pad_connect (sink_sched,
1058 GST_PAD_CAST (realsrc), GST_PAD_CAST (realsink));
1060 GST_INFO (GST_CAT_PADS, "connected %s:%s and %s:%s, successful",
1061 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
1062 gst_caps_debug (gst_pad_get_caps (GST_PAD_CAST (realsrc)),
1063 "caps of newly connected src pad");
1070 * @srcpad: the source #GstPad to connect.
1071 * @sinkpad: the sink #GstPad to connect.
1073 * Connects the source pad to the sink pad.
1075 * Returns: TRUE if the pad could be connected, FALSE otherwise.
1078 gst_pad_connect (GstPad *srcpad, GstPad *sinkpad)
1080 return gst_pad_connect_filtered (srcpad, sinkpad, NULL);
1084 * gst_pad_set_parent:
1085 * @pad: a #GstPad to set the parent of.
1086 * @parent: the new parent #GstElement.
1088 * Sets the parent object of a pad.
1091 gst_pad_set_parent (GstPad *pad, GstElement *parent)
1093 g_return_if_fail (pad != NULL);
1094 g_return_if_fail (GST_IS_PAD (pad));
1095 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
1096 g_return_if_fail (parent != NULL);
1097 g_return_if_fail (GST_IS_OBJECT (parent));
1098 g_return_if_fail ((gpointer) pad != (gpointer) parent);
1100 gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (parent));
1104 * gst_pad_get_parent:
1105 * @pad: the #GstPad to get the parent of.
1107 * Gets the parent object of this pad.
1109 * Returns: the parent #GstElement.
1112 gst_pad_get_parent (GstPad *pad)
1114 g_return_val_if_fail (pad != NULL, NULL);
1115 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1117 return GST_PAD_PARENT (pad);
1121 * gst_pad_get_pad_template:
1122 * @pad: a #GstPad to get the pad template of.
1124 * Gets the pad template object of this pad.
1126 * Returns: the #GstPadTemplate from which this pad was instantiated.
1129 gst_pad_get_pad_template (GstPad *pad)
1131 g_return_val_if_fail (pad != NULL, NULL);
1132 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1134 return GST_PAD_PAD_TEMPLATE (pad);
1139 * gst_pad_get_scheduler:
1140 * @pad: a #GstPad to get the scheduler of.
1142 * Gets the scheduler of the pad.
1144 * Returns: the #GstScheduler of the pad.
1147 gst_pad_get_scheduler (GstPad *pad)
1149 GstScheduler *scheduler = NULL;
1152 g_return_val_if_fail (pad != NULL, NULL);
1153 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1155 parent = gst_pad_get_parent (pad);
1157 if (GST_FLAG_IS_SET (parent, GST_ELEMENT_DECOUPLED)) {
1158 GstRealPad *peer = GST_RPAD_PEER (pad);
1161 scheduler = gst_element_get_scheduler (gst_pad_get_parent (GST_PAD_CAST (peer)));
1165 scheduler = gst_element_get_scheduler (parent);
1173 * gst_pad_get_real_parent:
1174 * @pad: a #GstPad to get the real parent of.
1176 * Gets the real parent object of this pad. If the pad
1177 * is a ghost pad, the actual owner of the real pad is
1178 * returned, as opposed to #gst_pad_get_parent().
1180 * Returns: the parent #GstElement.
1183 gst_pad_get_real_parent (GstPad *pad)
1185 g_return_val_if_fail (pad != NULL, NULL);
1186 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1188 return GST_PAD_PARENT (GST_PAD (GST_PAD_REALIZE (pad)));
1192 * gst_pad_add_ghost_pad:
1193 * @pad: a #GstPad to attach the ghost pad to.
1194 * @ghostpad: the ghost #GstPad to to the pad.
1196 * Adds a ghost pad to a pad.
1199 gst_pad_add_ghost_pad (GstPad *pad,
1202 GstRealPad *realpad;
1204 g_return_if_fail (pad != NULL);
1205 g_return_if_fail (GST_IS_PAD (pad));
1206 g_return_if_fail (ghostpad != NULL);
1207 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1209 realpad = GST_PAD_REALIZE (pad);
1211 realpad->ghostpads = g_list_prepend (realpad->ghostpads, ghostpad);
1216 * gst_pad_remove_ghost_pad:
1217 * @pad: a #GstPad to remove the ghost pad from.
1218 * @ghostpad: the ghost #GstPad to remove from the pad.
1220 * Removes a ghost pad from a pad.
1223 gst_pad_remove_ghost_pad (GstPad *pad,
1226 GstRealPad *realpad;
1228 g_return_if_fail (pad != NULL);
1229 g_return_if_fail (GST_IS_PAD (pad));
1230 g_return_if_fail (ghostpad != NULL);
1231 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
1233 realpad = GST_PAD_REALIZE (pad);
1235 realpad->ghostpads = g_list_remove (realpad->ghostpads, ghostpad);
1239 * gst_pad_get_ghost_pad_list:
1240 * @pad: a #GstPad to get the ghost pads of.
1242 * Gets the ghost pads of this pad.
1244 * Returns: a #GList of ghost pads.
1247 gst_pad_get_ghost_pad_list (GstPad *pad)
1249 g_return_val_if_fail (pad != NULL, NULL);
1250 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1252 return GST_PAD_REALIZE(pad)->ghostpads;
1255 /* an internal caps negotiation helper function:
1257 * 1. optionally calls the pad connect function with the provided caps
1258 * 2. deals with the result code of the connect function
1259 * 3. sets fixed caps on the pad.
1261 static GstPadConnectReturn
1262 gst_pad_try_set_caps_func (GstRealPad *pad, GstCaps *caps, gboolean notify)
1265 GstPadTemplate *template;
1266 GstElement *parent = GST_PAD_PARENT (pad);
1268 g_return_val_if_fail (pad != NULL, GST_PAD_CONNECT_REFUSED);
1269 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_CONNECT_REFUSED);
1271 /* if this pad has a parent and the parent is not READY, delay the
1273 if (parent && GST_STATE (parent) < GST_STATE_READY)
1275 GST_DEBUG (GST_CAT_CAPS, "parent %s of pad %s:%s is not READY",
1276 GST_ELEMENT_NAME (parent), GST_DEBUG_PAD_NAME (pad));
1277 return GST_PAD_CONNECT_DELAYED;
1280 GST_INFO (GST_CAT_CAPS, "trying to set caps %p on pad %s:%s",
1281 caps, GST_DEBUG_PAD_NAME (pad));
1283 if ((template = gst_pad_get_pad_template (GST_PAD_CAST (pad)))) {
1284 if (!gst_caps_intersect (caps, gst_pad_template_get_caps (template))) {
1285 GST_INFO (GST_CAT_CAPS, "caps did not intersect with %s:%s's padtemplate",
1286 GST_DEBUG_PAD_NAME (pad));
1287 gst_caps_debug (caps, "caps themselves (attemped to set)");
1288 gst_caps_debug (gst_pad_template_get_caps (template),
1289 "pad template caps that did not agree with caps");
1290 return GST_PAD_CONNECT_REFUSED;
1292 /* given that the caps are fixed, we know that their intersection with the
1293 * padtemplate caps is the same as caps itself */
1296 /* we need to notify the connect function */
1297 if (notify && GST_RPAD_CONNECTFUNC (pad)) {
1298 GstPadConnectReturn res;
1299 gchar *debug_string;
1301 GST_INFO (GST_CAT_CAPS, "calling connect function on pad %s:%s",
1302 GST_DEBUG_PAD_NAME (pad));
1304 /* call the connect function */
1305 res = GST_RPAD_CONNECTFUNC (pad) (GST_PAD (pad), caps);
1308 case GST_PAD_CONNECT_REFUSED:
1309 debug_string = "REFUSED";
1311 case GST_PAD_CONNECT_OK:
1312 debug_string = "OK";
1314 case GST_PAD_CONNECT_DONE:
1315 debug_string = "DONE";
1317 case GST_PAD_CONNECT_DELAYED:
1318 debug_string = "DELAYED";
1321 g_warning ("unknown return code from connect function of pad %s:%s %d",
1322 GST_DEBUG_PAD_NAME (pad), res);
1323 return GST_PAD_CONNECT_REFUSED;
1326 GST_INFO (GST_CAT_CAPS,
1327 "got reply %s (%d) from connect function on pad %s:%s",
1328 debug_string, res, GST_DEBUG_PAD_NAME (pad));
1330 /* done means the connect function called another caps negotiate function
1331 * on this pad that succeeded, we dont need to continue */
1332 if (res == GST_PAD_CONNECT_DONE) {
1333 GST_INFO (GST_CAT_CAPS, "pad %s:%s is done", GST_DEBUG_PAD_NAME (pad));
1334 return GST_PAD_CONNECT_DONE;
1336 if (res == GST_PAD_CONNECT_REFUSED) {
1337 GST_INFO (GST_CAT_CAPS, "pad %s:%s doesn't accept caps",
1338 GST_DEBUG_PAD_NAME (pad));
1339 return GST_PAD_CONNECT_REFUSED;
1342 /* we can only set caps on the pad if they are fixed */
1343 if (GST_CAPS_IS_FIXED (caps)) {
1345 GST_INFO (GST_CAT_CAPS, "setting caps on pad %s:%s",
1346 GST_DEBUG_PAD_NAME (pad));
1347 /* if we got this far all is ok, remove the old caps, set the new one */
1348 oldcaps = GST_PAD_CAPS (pad);
1349 if (caps) gst_caps_ref (caps);
1350 GST_PAD_CAPS (pad) = caps;
1351 if (oldcaps) gst_caps_unref (oldcaps);
1354 GST_INFO (GST_CAT_CAPS,
1355 "caps are not fixed on pad %s:%s, not setting them yet",
1356 GST_DEBUG_PAD_NAME (pad));
1358 return GST_PAD_CONNECT_OK;
1362 * gst_pad_try_set_caps:
1363 * @pad: a #GstPad to try to set the caps on.
1364 * @caps: the #GstCaps to set.
1366 * Tries to set the caps on the given pad.
1368 * Returns: A GstPadConnectReturn value indicating whether the caps
1372 gst_pad_try_set_caps (GstPad *pad, GstCaps *caps)
1374 GstRealPad *peer, *realpad;
1375 GstPadConnectReturn set_retval;
1377 realpad = GST_PAD_REALIZE (pad);
1378 peer = GST_RPAD_PEER (realpad);
1380 GST_INFO (GST_CAT_CAPS, "trying to set caps %p on pad %s:%s",
1381 caps, GST_DEBUG_PAD_NAME (realpad));
1383 gst_caps_debug (caps, "caps that we are trying to set");
1385 /* setting non fixed caps on a pad is not allowed */
1386 if (!GST_CAPS_IS_FIXED (caps)) {
1387 GST_INFO (GST_CAT_CAPS,
1388 "trying to set unfixed caps on pad %s:%s, not allowed",
1389 GST_DEBUG_PAD_NAME (realpad));
1390 g_warning ("trying to set non fixed caps on pad %s:%s, not allowed",
1391 GST_DEBUG_PAD_NAME (realpad));
1392 gst_caps_debug (caps, "unfixed caps");
1393 return GST_PAD_CONNECT_DELAYED;
1396 /* if we have a peer try to set the caps, notifying the peerpad
1397 * if it has a connect function */
1398 if (peer && ((set_retval = gst_pad_try_set_caps_func (peer, caps, TRUE)) <= 0))
1400 GST_INFO (GST_CAT_CAPS, "tried to set caps on peerpad %s:%s but couldn't, return value %d",
1401 GST_DEBUG_PAD_NAME (peer), set_retval);
1405 /* then try to set our own caps, we don't need to be notified */
1406 if ((set_retval = gst_pad_try_set_caps_func (realpad, caps, FALSE)) <= 0)
1408 GST_INFO (GST_CAT_CAPS, "tried to set own caps on pad %s:%s but couldn't, return value %d",
1409 GST_DEBUG_PAD_NAME (realpad), set_retval);
1412 GST_INFO (GST_CAT_CAPS, "succeeded setting caps %p on pad %s:%s, return value %d",
1413 caps, GST_DEBUG_PAD_NAME (realpad), set_retval);
1414 g_assert (GST_PAD_CAPS (pad));
1419 /* this is a caps negotiation convenience routine, it:
1421 * 1. optionally clears any pad caps.
1422 * 2. calculates the intersection between the two pad tamplate/getcaps caps.
1423 * 3. calculates the intersection with the (optional) filtercaps.
1424 * 4. stores the intersection in the pad filter.
1425 * 5. stores the app filtercaps in the pad appfilter.
1426 * 6. starts the caps negotiation.
1429 gst_pad_try_reconnect_filtered_func (GstRealPad *srcpad, GstRealPad *sinkpad,
1430 GstCaps *filtercaps, gboolean clear)
1432 GstCaps *srccaps, *sinkcaps;
1433 GstCaps *intersection = NULL;
1434 GstRealPad *realsrc, *realsink;
1436 realsrc = GST_PAD_REALIZE (srcpad);
1437 realsink = GST_PAD_REALIZE (sinkpad);
1439 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1440 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1442 /* optinally clear the caps */
1444 GST_INFO (GST_CAT_PADS, "reconnect filtered %s:%s and %s:%s, clearing caps",
1445 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1447 GST_PAD_CAPS (GST_PAD (realsrc)) = NULL;
1448 GST_PAD_CAPS (GST_PAD (realsink)) = NULL;
1451 GST_INFO (GST_CAT_PADS, "reconnect filtered %s:%s and %s:%s",
1452 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1455 srccaps = gst_pad_get_caps (GST_PAD (realsrc));
1456 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1457 GST_DEBUG_PAD_NAME (realsrc));
1458 gst_caps_debug (srccaps, "caps of src pad (pre-reconnect)");
1459 sinkcaps = gst_pad_get_caps (GST_PAD (realsink));
1460 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1461 GST_DEBUG_PAD_NAME (realsink));
1462 gst_caps_debug (sinkcaps, "caps of sink pad (pre-reconnect)");
1464 /* first take the intersection of the pad caps */
1465 intersection = gst_caps_intersect (srccaps, sinkcaps);
1467 /* if we have no intersection but one of the caps was not NULL.. */
1468 if (!intersection && (srccaps || sinkcaps)) {
1469 /* the intersection is NULL but the pad caps were not both NULL,
1470 * this means they have no common format */
1471 GST_INFO (GST_CAT_PADS, "pads %s:%s and %s:%s have no common type",
1472 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1474 } else if (intersection) {
1475 GST_INFO (GST_CAT_PADS, "pads %s:%s and %s:%s intersected to %s caps",
1476 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink),
1477 ((intersection && GST_CAPS_IS_FIXED (intersection)) ? "fixed" : "variable"));
1479 /* then filter this against the app filter */
1481 GstCaps *filtered_intersection = gst_caps_intersect (intersection,
1484 /* get rid of the old intersection here */
1485 gst_caps_unref (intersection);
1487 if (!filtered_intersection) {
1488 GST_INFO (GST_CAT_PADS,
1489 "filtered connection between pads %s:%s and %s:%s is empty",
1490 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1493 intersection = filtered_intersection;
1495 /* keep a reference to the app caps */
1496 GST_RPAD_APPFILTER (realsink) = filtercaps;
1497 GST_RPAD_APPFILTER (realsrc) = filtercaps;
1500 GST_DEBUG (GST_CAT_CAPS, "setting filter for connection to:");
1501 gst_caps_debug (intersection, "filter for connection");
1503 /* both the app filter and the filter, while stored on both peer pads,
1504 * are equal to the same thing on both */
1505 GST_RPAD_FILTER (realsrc) = intersection;
1506 GST_RPAD_FILTER (realsink) = intersection;
1508 return gst_pad_perform_negotiate (GST_PAD (realsrc), GST_PAD (realsink));
1512 * gst_pad_perform_negotiate:
1513 * @srcpad: the source #GstPad.
1514 * @sinkpad: the sink #GstPad.
1516 * Tries to negotiate the pads.
1518 * Returns: TRUE if the pads were succesfully negotiated, FALSE otherwise.
1521 gst_pad_perform_negotiate (GstPad *srcpad, GstPad *sinkpad)
1523 GstCaps *intersection, *filtered_intersection;
1524 GstRealPad *realsrc, *realsink;
1525 GstCaps *srccaps, *sinkcaps, *filter;
1527 g_return_val_if_fail (srcpad != NULL, FALSE);
1528 g_return_val_if_fail (sinkpad != NULL, FALSE);
1530 realsrc = GST_PAD_REALIZE (srcpad);
1531 realsink = GST_PAD_REALIZE (sinkpad);
1533 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1534 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1536 filter = GST_RPAD_APPFILTER (realsrc);
1538 GST_INFO (GST_CAT_PADS, "dumping filter for connection %s:%s-%s:%s",
1539 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1540 gst_caps_debug (filter, "connection filter caps");
1543 /* calculate the new caps here */
1544 srccaps = gst_pad_get_caps (GST_PAD (realsrc));
1545 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1546 GST_DEBUG_PAD_NAME (realsrc));
1547 gst_caps_debug (srccaps,
1548 "src caps, awaiting negotiation, after applying filter");
1549 sinkcaps = gst_pad_get_caps (GST_PAD (realsink));
1550 GST_DEBUG (GST_CAT_PADS, "dumping caps of pad %s:%s",
1551 GST_DEBUG_PAD_NAME (realsink));
1552 gst_caps_debug (sinkcaps,
1553 "sink caps, awaiting negotiation, after applying filter");
1554 intersection = gst_caps_intersect (srccaps, sinkcaps);
1555 filtered_intersection = gst_caps_intersect (intersection, filter);
1556 if (filtered_intersection) {
1557 gst_caps_unref (intersection);
1558 intersection = filtered_intersection;
1561 /* no negotiation is performed if the pads have filtercaps */
1563 GstPadConnectReturn res;
1565 res = gst_pad_try_set_caps_func (realsrc, intersection, TRUE);
1566 if (res == GST_PAD_CONNECT_REFUSED)
1568 if (res == GST_PAD_CONNECT_DONE)
1571 res = gst_pad_try_set_caps_func (realsink, intersection, TRUE);
1572 if (res == GST_PAD_CONNECT_REFUSED)
1574 if (res == GST_PAD_CONNECT_DONE)
1581 * gst_pad_try_reconnect_filtered:
1582 * @srcpad: the source #GstPad to reconnect.
1583 * @sinkpad: the sink #GstPad to reconnect.
1584 * @filtercaps: the #GstPad to use as a filter in the reconnection.
1586 * Tries to reconnect the given source and sink pad, constrained by the given
1589 * Returns: TRUE if the pads were succesfully renegotiated, FALSE otherwise.
1592 gst_pad_try_reconnect_filtered (GstPad *srcpad, GstPad *sinkpad,
1593 GstCaps *filtercaps)
1595 GstRealPad *realsrc, *realsink;
1597 g_return_val_if_fail (srcpad != NULL, FALSE);
1598 g_return_val_if_fail (sinkpad != NULL, FALSE);
1600 realsrc = GST_PAD_REALIZE (srcpad);
1601 realsink = GST_PAD_REALIZE (sinkpad);
1603 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1604 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1606 return gst_pad_try_reconnect_filtered_func (realsrc, realsink,
1611 * gst_pad_reconnect_filtered:
1612 * @srcpad: the source #GstPad to reconnect.
1613 * @sinkpad: the sink #GstPad to reconnect.
1614 * @filtercaps: the #GstPad to use as a filter in the reconnection.
1616 * Reconnects the given source and sink pad, constrained by the given
1617 * capabilities. If the reconnection fails, the pads are disconnected
1618 * and FALSE is returned.
1620 * Returns: TRUE if the pads were succesfully reconnected, FALSE otherwise.
1623 gst_pad_reconnect_filtered (GstPad *srcpad, GstPad *sinkpad,
1624 GstCaps *filtercaps)
1626 GstRealPad *realsrc, *realsink;
1628 g_return_val_if_fail (srcpad != NULL, FALSE);
1629 g_return_val_if_fail (sinkpad != NULL, FALSE);
1631 realsrc = GST_PAD_REALIZE (srcpad);
1632 realsink = GST_PAD_REALIZE (sinkpad);
1634 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
1635 g_return_val_if_fail (GST_RPAD_PEER (realsink) == realsrc, FALSE);
1637 if (! gst_pad_try_reconnect_filtered_func (realsrc, realsink,
1638 filtercaps, TRUE)) {
1639 gst_pad_disconnect (srcpad, GST_PAD (GST_PAD_PEER (srcpad)));
1646 * gst_pad_proxy_connect:
1647 * @pad: a #GstPad to proxy to.
1648 * @caps: the #GstCaps to use in proxying.
1650 * Proxies the connect function to the specified pad.
1652 * Returns: TRUE if the peer pad accepted the caps, FALSE otherwise.
1655 gst_pad_proxy_connect (GstPad *pad, GstCaps *caps)
1657 GstRealPad *peer, *realpad;
1659 realpad = GST_PAD_REALIZE (pad);
1661 peer = GST_RPAD_PEER (realpad);
1663 GST_INFO (GST_CAT_CAPS, "proxy connect to pad %s:%s",
1664 GST_DEBUG_PAD_NAME (realpad));
1666 if (peer && gst_pad_try_set_caps_func (peer, caps, TRUE) < 0)
1667 return GST_PAD_CONNECT_REFUSED;
1668 if (gst_pad_try_set_caps_func (realpad, caps, FALSE) < 0)
1669 return GST_PAD_CONNECT_REFUSED;
1671 return GST_PAD_CONNECT_OK;
1676 * @pad: a #GstPad to get the capabilities of.
1678 * Gets the capabilities of this pad.
1680 * Returns: the #GstCaps of this pad.
1683 gst_pad_get_caps (GstPad *pad)
1685 GstRealPad *realpad;
1687 g_return_val_if_fail (pad != NULL, NULL);
1688 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1690 realpad = GST_PAD_REALIZE (pad);
1692 GST_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)",
1693 GST_DEBUG_PAD_NAME (realpad), realpad);
1695 if (GST_PAD_CAPS (realpad)) {
1696 GST_DEBUG (GST_CAT_CAPS, "using pad real caps %p", GST_PAD_CAPS (realpad));
1697 return GST_PAD_CAPS (realpad);
1699 else if GST_RPAD_GETCAPSFUNC (realpad) {
1700 GST_DEBUG (GST_CAT_CAPS, "using pad get function");
1701 return GST_RPAD_GETCAPSFUNC (realpad) (GST_PAD_CAST (realpad), NULL);
1703 else if (GST_PAD_PAD_TEMPLATE (realpad)) {
1704 GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (realpad);
1705 GST_DEBUG (GST_CAT_CAPS, "using pad template %p with caps %p",
1706 templ, GST_PAD_TEMPLATE_CAPS (templ));
1707 return GST_PAD_TEMPLATE_CAPS (templ);
1709 GST_DEBUG (GST_CAT_CAPS, "pad has no caps");
1715 * gst_pad_get_pad_template_caps:
1716 * @pad: a #GstPad to get the template capabilities from.
1718 * Gets the template capabilities of this pad.
1720 * Returns: the template #GstCaps of this pad.
1723 gst_pad_get_pad_template_caps (GstPad *pad)
1725 g_return_val_if_fail (pad != NULL, NULL);
1726 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1728 if (GST_PAD_PAD_TEMPLATE (pad))
1729 return GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
1735 * gst_pad_template_get_caps_by_name:
1736 * @templ: a #GstPadTemplate to get the capabilities of.
1737 * @name: the name of the capability to get.
1739 * Gets the capability with the given name from this pad template.
1741 * Returns: the #GstCaps, or NULL if not found or in case of an error.
1744 gst_pad_template_get_caps_by_name (GstPadTemplate *templ, const gchar *name)
1748 g_return_val_if_fail (templ != NULL, NULL);
1750 caps = GST_PAD_TEMPLATE_CAPS (templ);
1754 return gst_caps_get_by_name (caps, name);
1758 * gst_pad_check_compatibility:
1759 * @srcpad: the source #GstPad to check.
1760 * @sinkpad: the sink #GstPad to check against.
1762 * Checks if two pads have compatible capabilities.
1764 * Returns: TRUE if they are compatible or if the capabilities
1765 * could not be checked
1768 gst_pad_check_compatibility (GstPad *srcpad, GstPad *sinkpad)
1770 g_return_val_if_fail (srcpad != NULL, FALSE);
1771 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1772 g_return_val_if_fail (sinkpad != NULL, FALSE);
1773 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1775 if (GST_PAD_CAPS (srcpad) && GST_PAD_CAPS (sinkpad)) {
1776 if (!gst_caps_check_compatibility (GST_PAD_CAPS (srcpad),
1777 GST_PAD_CAPS (sinkpad))) {
1785 GST_DEBUG (GST_CAT_PADS,
1786 "could not check capabilities of pads (%s:%s) and (%s:%s) %p %p",
1787 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
1788 GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad));
1795 * @pad: a #GstPad to get the peer of.
1797 * Gets the peer pad of this pad.
1799 * Returns: the peer #GstPad.
1802 gst_pad_get_peer (GstPad *pad)
1804 g_return_val_if_fail (pad != NULL, NULL);
1805 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1807 return GST_PAD (GST_PAD_PEER (pad));
1811 * gst_pad_get_allowed_caps:
1812 * @pad: a #GstPad to get the allowed caps of.
1814 * Gets the capabilities of the allowed media types that can
1815 * flow through this pad. The caller must free the resulting caps.
1817 * Returns: a newly allocated copy of the allowed #GstCaps.
1820 gst_pad_get_allowed_caps (GstPad *pad)
1822 g_return_val_if_fail (pad != NULL, NULL);
1823 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1825 GST_DEBUG (GST_CAT_PROPERTIES, "get allowed caps of %s:%s",
1826 GST_DEBUG_PAD_NAME (pad));
1828 return gst_caps_copy (GST_RPAD_FILTER (pad));
1832 * gst_pad_recalc_allowed_caps:
1833 * @pad: a #GstPad to recalculate the capablities of.
1835 * Attempts to reconnect the pad to its peer through its filter,
1836 * set with gst_pad_[re]connect_filtered. This function is useful when a
1837 * plug-in has new capabilities on a pad and wants to notify the peer.
1839 * Returns: TRUE on success, FALSE otherwise.
1842 gst_pad_recalc_allowed_caps (GstPad *pad)
1846 g_return_val_if_fail (pad != NULL, FALSE);
1847 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
1849 GST_DEBUG (GST_CAT_PROPERTIES, "set allowed caps of %s:%s",
1850 GST_DEBUG_PAD_NAME (pad));
1852 peer = GST_RPAD_PEER (pad);
1854 return gst_pad_try_reconnect_filtered (pad, GST_PAD (peer),
1855 GST_RPAD_APPFILTER (pad));
1861 * gst_pad_get_bufferpool:
1862 * @pad: a #GstPad to get the bufferpool from.
1864 * Gets the bufferpool of the peer pad of the given pad.
1866 * Returns: the #GstBufferPool, or NULL in case of an error.
1869 gst_pad_get_bufferpool (GstPad *pad)
1873 g_return_val_if_fail (pad != NULL, NULL);
1874 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1876 peer = GST_RPAD_PEER (pad);
1881 GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
1883 if (peer->bufferpoolfunc) {
1884 GST_DEBUG (GST_CAT_PADS,
1885 "calling bufferpoolfunc &%s (@%p) of peer pad %s:%s",
1886 GST_DEBUG_FUNCPTR_NAME (peer->bufferpoolfunc),
1887 &peer->bufferpoolfunc, GST_DEBUG_PAD_NAME (((GstPad*) peer)));
1888 return (peer->bufferpoolfunc) (((GstPad*) peer));
1890 GST_DEBUG (GST_CAT_PADS, "no bufferpoolfunc for peer pad %s:%s at %p",
1891 GST_DEBUG_PAD_NAME (((GstPad*) peer)), &peer->bufferpoolfunc);
1897 gst_real_pad_dispose (GObject *object)
1899 GstPad *pad = GST_PAD (object);
1901 /* No connected pad can ever be disposed.
1902 * It has to have a parent to be connected
1903 * and a parent would hold a reference */
1904 g_assert (GST_PAD_PEER (pad) == NULL);
1906 GST_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s", GST_DEBUG_PAD_NAME(pad));
1908 if (GST_PAD_PAD_TEMPLATE (pad)){
1909 GST_DEBUG (GST_CAT_REFCOUNTING, "unreffing padtemplate'%s'",
1910 GST_OBJECT_NAME (GST_PAD_PAD_TEMPLATE (pad)));
1911 gst_object_unref (GST_OBJECT (GST_PAD_PAD_TEMPLATE (pad)));
1912 GST_PAD_PAD_TEMPLATE (pad) = NULL;
1915 /* we destroy the ghostpads, because they are nothing without the real pad */
1916 if (GST_REAL_PAD (pad)->ghostpads) {
1917 GList *orig, *ghostpads;
1919 orig = ghostpads = g_list_copy (GST_REAL_PAD (pad)->ghostpads);
1922 GstPad *ghostpad = GST_PAD (ghostpads->data);
1924 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))){
1925 GST_DEBUG (GST_CAT_REFCOUNTING, "removing ghost pad from element '%s'",
1926 GST_OBJECT_NAME (GST_OBJECT_PARENT (ghostpad)));
1928 gst_element_remove_ghost_pad (GST_ELEMENT (GST_OBJECT_PARENT (ghostpad)), GST_PAD (ghostpad));
1930 ghostpads = g_list_next (ghostpads);
1933 g_list_free (GST_REAL_PAD(pad)->ghostpads);
1936 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))) {
1937 GST_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'",
1938 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
1940 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
1943 G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
1947 #ifndef GST_DISABLE_LOADSAVE
1948 /* FIXME: why isn't this on a GstElement ? */
1950 * gst_pad_load_and_connect:
1951 * @self: an #xmlNodePtr to read the description from.
1952 * @parent: the #GstObject element that owns the pad.
1954 * Reads the pad definition from the XML node and connects the given pad
1955 * in the element to a pad of an element up in the hierarchy.
1958 gst_pad_load_and_connect (xmlNodePtr self, GstObject *parent)
1960 xmlNodePtr field = self->xmlChildrenNode;
1961 GstPad *pad = NULL, *targetpad;
1965 GstObject *grandparent;
1968 if (!strcmp (field->name, "name")) {
1969 pad = gst_element_get_pad (GST_ELEMENT (parent),
1970 xmlNodeGetContent (field));
1972 else if (!strcmp(field->name, "peer")) {
1973 peer = xmlNodeGetContent (field);
1975 field = field->next;
1977 g_return_if_fail (pad != NULL);
1979 if (peer == NULL) return;
1981 split = g_strsplit (peer, ".", 2);
1983 if (split[0] == NULL || split[1] == NULL) {
1984 GST_DEBUG (GST_CAT_XML,
1985 "Could not parse peer '%s' for pad %s:%s, leaving unconnected",
1986 peer, GST_DEBUG_PAD_NAME (pad));
1990 g_return_if_fail (split[0] != NULL);
1991 g_return_if_fail (split[1] != NULL);
1993 grandparent = gst_object_get_parent (parent);
1995 if (grandparent && GST_IS_BIN (grandparent)) {
1996 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
2001 if (target == NULL) goto cleanup;
2003 targetpad = gst_element_get_pad (target, split[1]);
2005 if (targetpad == NULL) goto cleanup;
2007 gst_pad_connect (pad, targetpad);
2014 * gst_pad_save_thyself:
2015 * @pad: a #GstPad to save.
2016 * @parent: the parent #xmlNodePtr to save the description in.
2018 * Saves the pad into an xml representation.
2020 * Returns: the #xmlNodePtr representation of the pad.
2023 gst_pad_save_thyself (GstObject *object, xmlNodePtr parent)
2025 GstRealPad *realpad;
2028 g_return_val_if_fail (GST_IS_REAL_PAD (object), NULL);
2030 realpad = GST_REAL_PAD (object);
2032 xmlNewChild (parent, NULL, "name", GST_PAD_NAME (realpad));
2033 if (GST_RPAD_PEER (realpad) != NULL) {
2036 peer = GST_PAD (GST_RPAD_PEER (realpad));
2037 /* first check to see if the peer's parent's parent is the same */
2038 /* we just save it off */
2039 content = g_strdup_printf ("%s.%s",
2040 GST_OBJECT_NAME (GST_PAD_PARENT (peer)),
2041 GST_PAD_NAME (peer));
2042 xmlNewChild (parent, NULL, "peer", content);
2045 xmlNewChild (parent, NULL, "peer", "");
2050 /* FIXME: shouldn't pad and ghost be switched ?
2051 * FIXME: shouldn't the bin argument be dumped ?
2054 * gst_ghost_pad_save_thyself:
2055 * @pad: a ghost #GstPad to save.
2057 * @parent: the parent #xmlNodePtr to save the description in.
2059 * Saves the ghost pad into an xml representation.
2061 * Returns: the #xmlNodePtr representation of the pad.
2064 gst_ghost_pad_save_thyself (GstPad *pad, xmlNodePtr parent)
2068 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
2070 self = xmlNewChild (parent, NULL, "ghostpad", NULL);
2071 xmlNewChild (self, NULL, "name", GST_PAD_NAME (pad));
2072 xmlNewChild (self, NULL, "parent", GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
2074 /* FIXME FIXME FIXME! */
2078 #endif /* GST_DISABLE_LOADSAVE */
2082 * @pad: a #GstPad to push the buffer out of.
2083 * @buf: the #GstBuffer to push.
2085 * Pushes a buffer to the peer of the pad.
2088 gst_pad_push (GstPad *pad, GstBuffer *buf)
2090 GstRealPad *peer = GST_RPAD_PEER (pad);
2092 GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
2094 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
2097 g_warning ("push on pad %s:%s but it is unconnected",
2098 GST_DEBUG_PAD_NAME (pad));
2101 if (peer->chainhandler) {
2103 GST_DEBUG (GST_CAT_DATAFLOW,
2104 "calling chainhandler &%s of peer pad %s:%s",
2105 GST_DEBUG_FUNCPTR_NAME (peer->chainhandler),
2106 GST_DEBUG_PAD_NAME (GST_PAD (peer)));
2107 (peer->chainhandler) (GST_PAD_CAST (peer), buf);
2111 g_warning ("trying to push a NULL buffer on pad %s:%s",
2112 GST_DEBUG_PAD_NAME (peer));
2117 g_warning ("internal error: push on pad %s:%s but it has no chainhandler",
2118 GST_DEBUG_PAD_NAME (peer));
2121 /* clean up the mess here */
2122 if (buf != NULL) gst_data_unref (GST_DATA (buf));
2127 * @pad: a #GstPad to pull a buffer from.
2129 * Pulls a buffer from the peer pad.
2131 * Returns: a new #GstBuffer from the peer pad.
2134 gst_pad_pull (GstPad *pad)
2138 peer = GST_RPAD_PEER (pad);
2140 GST_DEBUG_ENTER("(%s:%s)",GST_DEBUG_PAD_NAME(pad));
2142 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK, NULL);
2145 gst_element_error (GST_PAD_PARENT (pad),
2146 "pull on pad %s:%s but it was unconnected",
2147 GST_ELEMENT_NAME (GST_PAD_PARENT (pad)),
2148 GST_PAD_NAME (pad), NULL);
2151 if (peer->gethandler) {
2154 GST_DEBUG (GST_CAT_DATAFLOW, "calling gethandler %s of peer pad %s:%s",
2155 GST_DEBUG_FUNCPTR_NAME (peer->gethandler),
2156 GST_DEBUG_PAD_NAME (peer));
2158 buf = (peer->gethandler) (GST_PAD_CAST (peer));
2163 /* no null buffers allowed */
2164 gst_element_error (GST_PAD_PARENT (pad),
2165 "NULL buffer during pull on %s:%s",
2166 GST_DEBUG_PAD_NAME (pad), NULL);
2169 gst_element_error (GST_PAD_PARENT (pad),
2170 "internal error: pull on pad %s:%s "
2171 "but the peer pad %s:%s has no gethandler",
2172 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer),
2181 * @padlist: a #GList of pads.
2183 * Waits for a buffer on any of the list of pads.
2185 * Returns: the #GstPad that has a buffer available.
2186 * Use #gst_pad_pull() to get the buffer.
2189 gst_pad_select (GList *padlist)
2193 pad = gst_scheduler_pad_select (GST_PAD_PARENT (padlist->data)->sched,
2200 * @pad: a first #GstPad to perform the select on.
2201 * @...: A NULL-terminated list of more pads to select on.
2203 * Waits for a buffer on the given set of pads.
2205 * Returns: the #GstPad that has a buffer available.
2206 * Use #gst_pad_pull() to get the buffer.
2209 gst_pad_selectv (GstPad *pad, ...)
2212 GList *padlist = NULL;
2218 va_start (var_args, pad);
2221 padlist = g_list_prepend (padlist, pad);
2222 pad = va_arg (var_args, GstPad *);
2224 result = gst_pad_select (padlist);
2225 g_list_free (padlist);
2232 /************************************************************************
2237 static void gst_pad_template_class_init (GstPadTemplateClass *klass);
2238 static void gst_pad_template_init (GstPadTemplate *templ);
2241 gst_pad_template_get_type (void)
2243 static GType padtemplate_type = 0;
2245 if (!padtemplate_type) {
2246 static const GTypeInfo padtemplate_info = {
2247 sizeof (GstPadTemplateClass), NULL, NULL,
2248 (GClassInitFunc) gst_pad_template_class_init, NULL, NULL,
2249 sizeof (GstPadTemplate),
2251 (GInstanceInitFunc) gst_pad_template_init, NULL
2253 padtemplate_type = g_type_register_static(GST_TYPE_OBJECT, "GstPadTemplate",
2254 &padtemplate_info, 0);
2256 return padtemplate_type;
2260 gst_pad_template_class_init (GstPadTemplateClass *klass)
2262 GObjectClass *gobject_class;
2263 GstObjectClass *gstobject_class;
2265 gobject_class = (GObjectClass*) klass;
2266 gstobject_class = (GstObjectClass*) klass;
2268 padtemplate_parent_class = g_type_class_ref (GST_TYPE_OBJECT);
2270 gst_pad_template_signals[TEMPL_PAD_CREATED] =
2271 g_signal_new ("pad_created", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
2272 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created),
2273 NULL, NULL, gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
2276 gstobject_class->path_string_separator = "*";
2280 gst_pad_template_init (GstPadTemplate *templ)
2284 /* ALWAYS padtemplates cannot have conversion specifications, it doesn't make
2286 * SOMETIMES padtemplates can do whatever they want, they are provided by the
2288 * REQUEST padtemplates can be reverse-parsed (the user asks for 'sink1', the
2289 * 'sink%d' template is automatically selected), so we need to restrict their
2293 name_is_valid (const gchar *name, GstPadPresence presence)
2297 if (presence == GST_PAD_ALWAYS) {
2298 if (strchr (name, '%')) {
2299 g_warning ("invalid name template %s: conversion specifications are not"
2300 " allowed for GST_PAD_ALWAYS padtemplates", name);
2303 } else if (presence == GST_PAD_REQUEST) {
2304 if ((str = strchr (name, '%')) && strchr (str + 1, '%')) {
2305 g_warning ("invalid name template %s: only one conversion specification"
2306 " allowed in GST_PAD_REQUEST padtemplate", name);
2309 if (str && (*(str+1) != 's' && *(str+1) != 'd')) {
2310 g_warning ("invalid name template %s: conversion specification must be of"
2311 " type '%%d' or '%%s' for GST_PAD_REQUEST padtemplate", name);
2314 if (str && (*(str+2) != '\0')) {
2315 g_warning ("invalid name template %s: conversion specification must"
2316 " appear at the end of the GST_PAD_REQUEST padtemplate name",
2326 * gst_pad_template_new:
2327 * @name_template: the name template.
2328 * @direction: the #GstPadDirection of the template.
2329 * @presence: the #GstPadPresence of the pad.
2330 * @caps: a #GstCaps set for the template.
2331 * @...: a NULL-terminated list of #GstCaps.
2333 * Creates a new pad template with a name according to the given template
2334 * and with the given arguments.
2336 * Returns: a new #GstPadTemplate.
2339 gst_pad_template_new (const gchar *name_template,
2340 GstPadDirection direction, GstPadPresence presence,
2343 GstPadTemplate *new;
2345 GstCaps *thecaps = NULL;
2347 g_return_val_if_fail (name_template != NULL, NULL);
2349 if (!name_is_valid (name_template, presence))
2352 new = g_object_new (gst_pad_template_get_type (),
2353 "name", name_template,
2356 GST_PAD_TEMPLATE_NAME_TEMPLATE (new) = g_strdup (name_template);
2357 GST_PAD_TEMPLATE_DIRECTION (new) = direction;
2358 GST_PAD_TEMPLATE_PRESENCE (new) = presence;
2360 va_start (var_args, caps);
2363 new->fixed &= caps->fixed;
2364 thecaps = gst_caps_append (thecaps, gst_caps_ref (caps));
2365 caps = va_arg (var_args, GstCaps*);
2369 GST_PAD_TEMPLATE_CAPS (new) = thecaps;
2375 * gst_pad_template_get_caps:
2376 * @templ: a #GstPadTemplate to get capabilities of.
2378 * Gets the capabilities of the pad template.
2380 * Returns: the #GstCaps of the pad template.
2383 gst_pad_template_get_caps (GstPadTemplate *templ)
2385 g_return_val_if_fail (templ != NULL, NULL);
2387 return GST_PAD_TEMPLATE_CAPS (templ);
2391 * gst_pad_set_element_private:
2392 * @pad: the #GstPad to set the private data of.
2393 * @priv: The private data to attach to the pad.
2395 * Set the given private data gpointer on the pad.
2396 * This function can only be used by the element that owns the pad.
2399 gst_pad_set_element_private (GstPad *pad, gpointer priv)
2401 pad->element_private = priv;
2405 * gst_pad_get_element_private:
2406 * @pad: the #GstPad to get the private data of.
2408 * Gets the private data of a pad.
2410 * Returns: a #gpointer to the private data.
2413 gst_pad_get_element_private (GstPad *pad)
2415 return pad->element_private;
2419 /***** ghost pads *****/
2420 GType _gst_ghost_pad_type = 0;
2422 static void gst_ghost_pad_class_init (GstGhostPadClass *klass);
2423 static void gst_ghost_pad_init (GstGhostPad *pad);
2425 static GstPad *ghost_pad_parent_class = NULL;
2426 /* static guint gst_ghost_pad_signals[LAST_SIGNAL] = { 0 }; */
2429 gst_ghost_pad_get_type (void)
2431 if (!_gst_ghost_pad_type) {
2432 static const GTypeInfo pad_info = {
2433 sizeof (GstGhostPadClass), NULL, NULL,
2434 (GClassInitFunc) gst_ghost_pad_class_init, NULL, NULL,
2435 sizeof (GstGhostPad),
2437 (GInstanceInitFunc) gst_ghost_pad_init,
2440 _gst_ghost_pad_type = g_type_register_static (GST_TYPE_PAD, "GstGhostPad",
2443 return _gst_ghost_pad_type;
2447 gst_ghost_pad_class_init (GstGhostPadClass *klass)
2449 GObjectClass *gobject_class;
2451 gobject_class = (GObjectClass*) klass;
2453 ghost_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
2457 gst_ghost_pad_init (GstGhostPad *pad)
2459 pad->realpad = NULL;
2463 * gst_ghost_pad_new:
2464 * @name: the name of the new ghost pad.
2465 * @pad: the #GstPad to create a ghost pad for.
2467 * Creates a new ghost pad associated with the given pad, and names it with
2468 * the given name. If name is NULL, a guaranteed unique name (across all
2469 * ghost pads) will be assigned (most likely of the form ghostpad%d).
2471 * Returns: a new ghost #GstPad, or NULL in case of an error.
2475 gst_ghost_pad_new (const gchar *name,
2478 GstGhostPad *ghostpad;
2479 GstRealPad *realpad;
2481 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2483 ghostpad = g_object_new (gst_ghost_pad_get_type () ,NULL);
2484 gst_pad_set_name (GST_PAD (ghostpad), name);
2486 realpad = (GstRealPad *) pad;
2488 while (!GST_IS_REAL_PAD (realpad)) {
2489 realpad = GST_PAD_REALIZE (realpad);
2491 GST_GPAD_REALPAD (ghostpad) = realpad;
2492 GST_PAD_PAD_TEMPLATE (ghostpad) = GST_PAD_PAD_TEMPLATE (pad);
2494 /* add ourselves to the real pad's list of ghostpads */
2495 gst_pad_add_ghost_pad (pad, GST_PAD (ghostpad));
2497 /* FIXME need to ref the real pad here... ? */
2499 GST_DEBUG (GST_CAT_PADS, "created ghost pad \"%s\"",
2500 gst_pad_get_name (GST_PAD (ghostpad)));
2502 return GST_PAD (ghostpad);
2506 * gst_pad_get_internal_connections_default:
2507 * @pad: the #GstPad to get the internal connections of.
2509 * Gets a list of pads to which the given pad is connected to
2510 * inside of the parent element.
2511 * This is the default handler, and thus returns a list of all of the
2512 * pads inside the parent element with opposite direction.
2513 * The caller must free this list after use.
2515 * Returns: a newly allocated #GList of pads.
2518 gst_pad_get_internal_connections_default (GstPad *pad)
2523 GstPadDirection direction;
2526 g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
2528 rpad = GST_PAD_REALIZE (pad);
2529 direction = rpad->direction;
2531 parent = GST_PAD_PARENT (rpad);
2532 parent_pads = parent->pads;
2534 while (parent_pads) {
2535 GstRealPad *parent_pad = GST_PAD_REALIZE (parent_pads->data);
2537 if (parent_pad->direction != direction) {
2538 res = g_list_prepend (res, parent_pad);
2541 parent_pads = g_list_next (parent_pads);
2548 * gst_pad_get_internal_connections:
2549 * @pad: the #GstPad to get the internal connections of.
2551 * Gets a list of pads to which the given pad is connected to
2552 * inside of the parent element.
2553 * The caller must free this list after use.
2555 * Returns: a newly allocated #GList of pads.
2558 gst_pad_get_internal_connections (GstPad *pad)
2563 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2565 rpad = GST_PAD_REALIZE (pad);
2567 if (GST_RPAD_INTCONNFUNC (rpad))
2568 res = GST_RPAD_INTCONNFUNC (rpad) (GST_PAD_CAST (rpad));
2575 gst_pad_event_default_dispatch (GstPad *pad, GstElement *element,
2578 GList *pads = element->pads;
2581 GstPad *eventpad = GST_PAD (pads->data);
2582 pads = g_list_next (pads);
2584 /* for all pads in the opposite direction that are connected */
2585 if (GST_PAD_DIRECTION (eventpad) != GST_PAD_DIRECTION (pad)
2586 && GST_PAD_IS_USABLE (eventpad)) {
2587 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
2588 /* increase the refcount */
2589 gst_event_ref (event);
2590 gst_pad_push (eventpad, GST_BUFFER (event));
2593 GstPad *peerpad = GST_PAD_CAST (GST_RPAD_PEER (eventpad));
2595 /* we only send the event on one pad, multi-sinkpad elements
2596 * should implement a handler */
2597 return gst_pad_send_event (peerpad, event);
2601 gst_event_unref (event);
2606 * gst_pad_event_default:
2607 * @pad: a #GstPad to call the default event handler on.
2608 * @event: the #GstEvent to handle.
2610 * Invokes the default event handler for the given pad.
2612 * Returns: TRUE if the event was sent succesfully.
2615 gst_pad_event_default (GstPad *pad, GstEvent *event)
2617 GstElement *element = GST_PAD_PARENT (pad);
2619 g_signal_emit (G_OBJECT (pad), gst_real_pad_signals[REAL_EVENT_RECEIVED],
2622 switch (GST_EVENT_TYPE (event)) {
2624 gst_pad_event_default_dispatch (pad, element, event);
2625 gst_element_set_eos (element);
2626 /* we have to try to schedule another element
2627 * because this one is disabled */
2628 gst_element_yield (element);
2630 case GST_EVENT_DISCONTINUOUS:
2634 if (gst_event_discont_get_value (event, GST_FORMAT_TIME, &time)) {
2635 if (element->setclockfunc && element->clock) {
2636 gst_clock_handle_discont (element->clock, time);
2640 case GST_EVENT_FLUSH:
2642 return gst_pad_event_default_dispatch (pad, element, event);
2648 * gst_pad_dispatcher:
2649 * @pad: a #GstPad to dispatch.
2650 * @dispatch: the #GstDispatcherFunction to call.
2651 * @data: gpointer user data passed to the dispatcher function.
2653 * Invokes the given dispatcher function on all pads that are
2654 * internally connected to the given pad.
2655 * The GstPadDispatcherFunction should return TRUE when no further pads
2656 * need to be processed.
2658 * Returns: TRUE if one of the dispatcher functions returned TRUE.
2661 gst_pad_dispatcher (GstPad *pad, GstPadDispatcherFunction dispatch,
2664 gboolean res = FALSE;
2665 GList *int_pads, *orig;
2667 g_return_val_if_fail (pad, FALSE);
2668 g_return_val_if_fail (data, FALSE);
2670 orig = int_pads = gst_pad_get_internal_connections (pad);
2673 GstRealPad *int_rpad = GST_PAD_REALIZE (int_pads->data);
2674 GstRealPad *int_peer = GST_RPAD_PEER (int_rpad);
2676 if (int_peer && GST_PAD_IS_USABLE (int_peer)) {
2677 res = dispatch (GST_PAD_CAST (int_peer), data);
2681 int_pads = g_list_next (int_pads);
2690 * gst_pad_send_event:
2691 * @pad: a #GstPad to send the event to.
2692 * @event: the #GstEvent to send to the pad.
2694 * Sends the event to the pad.
2696 * Returns: TRUE if the event was handled.
2699 gst_pad_send_event (GstPad *pad, GstEvent *event)
2701 gboolean success = FALSE;
2703 g_return_val_if_fail (event, FALSE);
2705 if (!pad || (GST_PAD_IS_SINK (pad) && !GST_PAD_IS_USABLE (pad)))
2708 if (GST_EVENT_SRC (event) == NULL)
2709 GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (pad));
2711 GST_DEBUG (GST_CAT_EVENT, "have event %d on pad %s:%s",
2712 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (pad));
2714 if (GST_RPAD_EVENTFUNC (pad))
2715 success = GST_RPAD_EVENTFUNC (pad) (pad, event);
2717 GST_DEBUG (GST_CAT_EVENT, "there's no event function for pad %s:%s",
2718 GST_DEBUG_PAD_NAME (pad));
2719 gst_event_unref (event);
2727 GstFormat src_format;
2729 GstFormat *dest_format;
2731 } GstPadConvertData;
2734 gst_pad_convert_dispatcher (GstPad *pad, GstPadConvertData *data)
2736 return gst_pad_convert (pad, data->src_format, data->src_value,
2737 data->dest_format, data->dest_value);
2741 * gst_pad_convert_default:
2742 * @pad: a #GstPad to invoke the default converter on.
2743 * @src_format: the source #GstFormat.
2744 * @src_value: the source value.
2745 * @dest_format: a pointer to the destination #GstFormat.
2746 * @dest_value: a pointer to the destination value.
2748 * Invokes the default converter on a pad.
2749 * This will forward the call to the pad obtained
2750 * using the internal connection of
2753 * Returns: TRUE if the conversion could be performed.
2756 gst_pad_convert_default (GstPad *pad,
2757 GstFormat src_format, gint64 src_value,
2758 GstFormat *dest_format, gint64 *dest_value)
2760 GstPadConvertData data;
2762 g_return_val_if_fail (pad, FALSE);
2763 g_return_val_if_fail (dest_format, FALSE);
2764 g_return_val_if_fail (dest_value, FALSE);
2766 data.src_format = src_format;
2767 data.src_value = src_value;
2768 data.dest_format = dest_format;
2769 data.dest_value = dest_value;
2771 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
2772 gst_pad_convert_dispatcher, &data);
2777 * @pad: a #GstPad to invoke the default converter on.
2778 * @src_format: the source #GstFormat.
2779 * @src_value: the source value.
2780 * @dest_format: a pointer to the destination #GstFormat.
2781 * @dest_value: a pointer to the destination value.
2783 * Invokes a conversion on the pad.
2785 * Returns: TRUE if the conversion could be performed.
2788 gst_pad_convert (GstPad *pad,
2789 GstFormat src_format, gint64 src_value,
2790 GstFormat *dest_format, gint64 *dest_value)
2794 g_return_val_if_fail (pad, FALSE);
2795 g_return_val_if_fail (dest_format, FALSE);
2796 g_return_val_if_fail (dest_value, FALSE);
2798 if (src_format == *dest_format) {
2799 *dest_value = src_value;
2803 rpad = GST_PAD_REALIZE (pad);
2805 g_return_val_if_fail (rpad, FALSE);
2807 if (GST_RPAD_CONVERTFUNC (rpad)) {
2808 return GST_RPAD_CONVERTFUNC (rpad) (GST_PAD_CAST (rpad), src_format,
2809 src_value, dest_format, dest_value);
2817 GstPadQueryType type;
2823 gst_pad_query_dispatcher (GstPad *pad, GstPadQueryData *data)
2825 return gst_pad_query (pad, data->type, data->format, data->value);
2829 * gst_pad_query_default:
2830 * @pad: a #GstPad to invoke the default query on.
2831 * @type: the #GstPadQueryType of the query to perform.
2832 * @format: a pointer to the #GstFormat of the result.
2833 * @value: a pointer to the result.
2835 * Invokes the default query function on a pad.
2837 * Returns: TRUE if the query could be performed.
2840 gst_pad_query_default (GstPad *pad, GstPadQueryType type,
2841 GstFormat *format, gint64 *value)
2843 GstPadQueryData data;
2845 g_return_val_if_fail (pad, FALSE);
2846 g_return_val_if_fail (format, FALSE);
2847 g_return_val_if_fail (value, FALSE);
2850 data.format = format;
2853 return gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
2854 gst_pad_query_dispatcher, &data);
2859 * @pad: a #GstPad to invoke the default query on.
2860 * @type: the #GstPadQueryType of the query to perform.
2861 * @format: a pointer to the #GstFormat of the result.
2862 * @value: a pointer to the result.
2864 * Queries a pad for one of the available properties.
2866 * Returns: TRUE if the query could be performed.
2869 gst_pad_query (GstPad *pad, GstPadQueryType type,
2870 GstFormat *format, gint64 *value)
2877 g_return_val_if_fail (format, FALSE);
2878 g_return_val_if_fail (value, FALSE);
2880 rpad = GST_PAD_REALIZE (pad);
2882 g_return_val_if_fail (rpad, FALSE);
2884 if (GST_RPAD_QUERYFUNC (rpad))
2885 return GST_RPAD_QUERYFUNC (rpad) (GST_PAD_CAST (pad), type, format, value);
2891 gst_pad_handles_format (GstPad *pad, GstFormat format)
2893 const GstFormat *formats;
2895 formats = gst_pad_get_formats (pad);
2900 if (*formats == format)
2910 gst_pad_get_formats_dispatcher (GstPad *pad, const GstFormat **data)
2912 *data = gst_pad_get_formats (pad);
2918 gst_pad_get_formats_default (GstPad *pad)
2920 GstFormat *result = NULL;
2922 gst_pad_dispatcher (pad, (GstPadDispatcherFunction)
2923 gst_pad_get_formats_dispatcher, &result);
2929 gst_pad_get_formats (GstPad *pad)
2936 rpad = GST_PAD_REALIZE (pad);
2938 g_return_val_if_fail (rpad, FALSE);
2940 if (GST_RPAD_FORMATSFUNC (rpad))
2941 return GST_RPAD_FORMATSFUNC (rpad) (GST_PAD_CAST (pad));