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"
34 GType _gst_pad_type = 0;
36 /***** Start with the base GstPad class *****/
37 static void gst_pad_class_init (GstPadClass *klass);
38 static void gst_pad_init (GstPad *pad);
40 static gboolean gst_pad_try_reconnect_filtered_func (GstPad *pad, GstCaps *caps, gboolean clear);
42 #ifndef GST_DISABLE_LOADSAVE
43 static xmlNodePtr gst_pad_save_thyself (GstObject *object, xmlNodePtr parent);
46 static GstObject *pad_parent_class = NULL;
49 gst_pad_get_type(void)
52 static const GTypeInfo pad_info = {
56 (GClassInitFunc)gst_pad_class_init,
61 (GInstanceInitFunc)gst_pad_init,
64 _gst_pad_type = g_type_register_static(GST_TYPE_OBJECT, "GstPad", &pad_info, 0);
70 gst_pad_class_init (GstPadClass *klass)
72 pad_parent_class = g_type_class_ref(GST_TYPE_OBJECT);
76 gst_pad_init (GstPad *pad)
78 pad->element_private = NULL;
80 pad->padtemplate = NULL;
85 /***** Then do the Real Pad *****/
86 /* Pad signals and args */
90 REAL_CAPS_NEGO_FAILED,
104 static void gst_real_pad_class_init (GstRealPadClass *klass);
105 static void gst_real_pad_init (GstRealPad *pad);
107 static void gst_real_pad_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
108 static void gst_real_pad_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
110 static void gst_real_pad_dispose (GObject *object);
112 static void gst_pad_push_func (GstPad *pad, GstBuffer *buf);
114 GType _gst_real_pad_type = 0;
116 static GstPad *real_pad_parent_class = NULL;
117 static guint gst_real_pad_signals[REAL_LAST_SIGNAL] = { 0 };
120 gst_real_pad_get_type(void) {
121 if (!_gst_real_pad_type) {
122 static const GTypeInfo pad_info = {
123 sizeof(GstRealPadClass),
126 (GClassInitFunc)gst_real_pad_class_init,
131 (GInstanceInitFunc)gst_real_pad_init,
134 _gst_real_pad_type = g_type_register_static(GST_TYPE_PAD, "GstRealPad", &pad_info, 0);
136 return _gst_real_pad_type;
140 gst_real_pad_class_init (GstRealPadClass *klass)
142 GObjectClass *gobject_class;
143 GstObjectClass *gstobject_class;
145 gobject_class = (GObjectClass*) klass;
146 gstobject_class = (GstObjectClass*) klass;
148 real_pad_parent_class = g_type_class_ref (GST_TYPE_PAD);
150 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_real_pad_dispose);
151 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_real_pad_set_property);
152 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_real_pad_get_property);
154 gst_real_pad_signals[REAL_SET_ACTIVE] =
155 g_signal_new ("set_active", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
156 G_STRUCT_OFFSET (GstRealPadClass, set_active), NULL, NULL,
157 gst_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1,
159 gst_real_pad_signals[REAL_CAPS_CHANGED] =
160 g_signal_new ("caps_changed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
161 G_STRUCT_OFFSET (GstRealPadClass, caps_changed), NULL, NULL,
162 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
164 gst_real_pad_signals[REAL_CAPS_NEGO_FAILED] =
165 g_signal_new ("caps_nego_failed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
166 G_STRUCT_OFFSET (GstRealPadClass, caps_nego_failed), NULL, NULL,
167 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
169 gst_real_pad_signals[REAL_CONNECTED] =
170 g_signal_new ("connected", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
171 G_STRUCT_OFFSET (GstRealPadClass, connected), NULL, NULL,
172 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
174 gst_real_pad_signals[REAL_DISCONNECTED] =
175 g_signal_new ("disconnected", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
176 G_STRUCT_OFFSET (GstRealPadClass, disconnected), NULL, NULL,
177 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
179 gst_real_pad_signals[REAL_EVENT_RECEIVED] =
180 g_signal_new ("event_received", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
181 G_STRUCT_OFFSET (GstRealPadClass, event_received), NULL, NULL,
182 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
185 /* gtk_object_add_arg_type ("GstRealPad::active", G_TYPE_BOOLEAN, */
186 /* GTK_ARG_READWRITE, REAL_ARG_ACTIVE); */
187 g_object_class_install_property (G_OBJECT_CLASS (klass), REAL_ARG_ACTIVE,
188 g_param_spec_boolean ("active", "Active", "Whether the pad is active.",
189 TRUE,G_PARAM_READWRITE));
191 #ifndef GST_DISABLE_LOADSAVE
192 gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_pad_save_thyself);
194 gstobject_class->path_string_separator = ".";
198 gst_real_pad_init (GstRealPad *pad)
200 pad->direction = GST_PAD_UNKNOWN;
204 pad->sched_private = NULL;
206 pad->chainfunc = NULL;
208 pad->getregionfunc = NULL;
210 pad->chainhandler = GST_DEBUG_FUNCPTR (gst_pad_push_func);
211 pad->gethandler = NULL;
212 pad->pullregionfunc = NULL;
214 pad->bufferpoolfunc = NULL;
215 pad->ghostpads = NULL;
218 pad->connectfunc = NULL;
219 pad->getcapsfunc = NULL;
223 gst_real_pad_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
225 g_return_if_fail (GST_IS_PAD (object));
228 case REAL_ARG_ACTIVE:
229 if (g_value_get_boolean (value)) {
230 GST_DEBUG (GST_CAT_PADS, "activating pad %s:%s\n", GST_DEBUG_PAD_NAME (object));
231 GST_FLAG_UNSET (object, GST_PAD_DISABLED);
233 GST_DEBUG (GST_CAT_PADS, "de-activating pad %s:%s\n", GST_DEBUG_PAD_NAME (object));
234 GST_FLAG_SET (object, GST_PAD_DISABLED);
236 g_signal_emit (G_OBJECT (object), gst_real_pad_signals[REAL_SET_ACTIVE], 0,
237 !GST_FLAG_IS_SET (object, GST_PAD_DISABLED));
245 gst_real_pad_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
247 /* it's not null if we got it, but it might not be ours */
248 g_return_if_fail (GST_IS_PAD (object));
251 case REAL_ARG_ACTIVE:
252 g_value_set_boolean (value, !GST_FLAG_IS_SET (object, GST_PAD_DISABLED));
262 * @name: name of new pad
263 * @direction: either GST_PAD_SRC or GST_PAD_SINK
265 * Create a new pad with given name.
270 gst_pad_new (gchar *name,
271 GstPadDirection direction)
275 g_return_val_if_fail (name != NULL, NULL);
276 g_return_val_if_fail (direction != GST_PAD_UNKNOWN, NULL);
278 pad = g_object_new (gst_real_pad_get_type (), NULL);
279 gst_object_set_name (GST_OBJECT (pad), name);
280 GST_RPAD_DIRECTION (pad) = direction;
282 return GST_PAD (pad);
286 * gst_pad_new_from_template:
287 * @templ: the pad template to use
288 * @name: the name of the element
290 * Create a new pad with given name from the given template.
295 gst_pad_new_from_template (GstPadTemplate *templ,
300 g_return_val_if_fail (name != NULL, NULL);
301 g_return_val_if_fail (templ != NULL, NULL);
303 pad = gst_pad_new (name, templ->direction);
305 gst_object_ref (GST_OBJECT (templ));
306 GST_PAD_PADTEMPLATE (pad) = templ;
312 * gst_pad_get_direction:
313 * @pad: the Pad to get the direction from
315 * Get the direction of the pad.
317 * Returns: the direction of the pad
320 gst_pad_get_direction (GstPad *pad)
322 g_return_val_if_fail (pad != NULL, GST_PAD_UNKNOWN);
323 g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_UNKNOWN);
325 return GST_PAD_DIRECTION (pad);
330 * @pad: the pad to set the name of
331 * @name: the name of the pad
333 * Set the name of a pad.
336 gst_pad_set_name (GstPad *pad,
339 g_return_if_fail (pad != NULL);
340 g_return_if_fail (GST_IS_PAD (pad));
342 gst_object_set_name (GST_OBJECT (pad), name);
347 * @pad: the pad to get the name of
349 * Get the name of a pad.
351 * Returns: the name of the pad, don't free.
354 gst_pad_get_name (GstPad *pad)
356 g_return_val_if_fail (pad != NULL, NULL);
357 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
359 return GST_OBJECT_NAME (pad);
363 * gst_pad_set_chain_function:
364 * @pad: the pad to set the chain function for
365 * @chain: the chain function
367 * Set the given chain function for the pad.
369 void gst_pad_set_chain_function (GstPad *pad,
370 GstPadChainFunction chain)
372 g_return_if_fail (pad != NULL);
373 g_return_if_fail (GST_IS_REAL_PAD (pad));
375 GST_RPAD_CHAINFUNC(pad) = chain;
376 GST_DEBUG (GST_CAT_PADS, "chainfunc for %s:%s set to %s\n",
377 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (chain));
381 * gst_pad_set_get_function:
382 * @pad: the pad to set the get function for
383 * @get: the get function
385 * Set the given get function for the pad.
388 gst_pad_set_get_function (GstPad *pad,
389 GstPadGetFunction get)
391 g_return_if_fail (pad != NULL);
392 g_return_if_fail (GST_IS_REAL_PAD (pad));
394 GST_RPAD_GETFUNC(pad) = get;
395 GST_DEBUG (GST_CAT_PADS, "getfunc for %s:%s set to %s\n",
396 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (get));
400 * gst_pad_set_event_function:
401 * @pad: the pad to set the event handler for
402 * @event: the event handler
404 * Set the given event handler for the pad.
407 gst_pad_set_event_function (GstPad *pad,
408 GstPadEventFunction event)
410 g_return_if_fail (pad != NULL);
411 g_return_if_fail (GST_IS_REAL_PAD (pad));
413 GST_RPAD_EVENTFUNC(pad) = event;
414 GST_DEBUG (GST_CAT_PADS, "eventfunc for %s:%s set to %s\n",
415 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (event));
419 * gst_pad_set_getregion_function:
420 * @pad: the pad to set the getregion function for
421 * @getregion: the getregion function
423 * Set the given getregion function for the pad.
426 gst_pad_set_getregion_function (GstPad *pad,
427 GstPadGetRegionFunction getregion)
429 g_return_if_fail (pad != NULL);
430 g_return_if_fail (GST_IS_REAL_PAD (pad));
432 GST_RPAD_GETREGIONFUNC(pad) = getregion;
433 GST_DEBUG (GST_CAT_PADS, "getregionfunc for %s:%s set to %s\n",
434 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getregion));
438 * gst_pad_set_connect_function:
439 * @pad: the pad to set the connect function for
440 * @connect: the connect function
442 * Set the given connect function for the pad. It will be called
443 * when the pad is connected or reconnected with caps.
446 gst_pad_set_connect_function (GstPad *pad,
447 GstPadConnectFunction connect)
449 g_return_if_fail (pad != NULL);
450 g_return_if_fail (GST_IS_REAL_PAD (pad));
452 GST_RPAD_CONNECTFUNC (pad) = connect;
453 GST_DEBUG (GST_CAT_PADS, "connectfunc for %s:%s set to %s\n",
454 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (connect));
458 * gst_pad_set_getcaps_function:
459 * @pad: the pad to set the getcaps function for
460 * @getcaps: the getcaps function
462 * Set the given getcaps function for the pad.
465 gst_pad_set_getcaps_function (GstPad *pad,
466 GstPadGetCapsFunction getcaps)
468 g_return_if_fail (pad != NULL);
469 g_return_if_fail (GST_IS_REAL_PAD (pad));
471 GST_RPAD_GETCAPSFUNC (pad) = getcaps;
472 GST_DEBUG (GST_CAT_PADS, "getcapsfunc for %s:%s set to %s\n",
473 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (getcaps));
476 * gst_pad_set_bufferpool_function:
477 * @pad: the pad to set the bufferpool function for
478 * @bufpool: the bufferpool function
480 * Set the given bufferpool function for the pad.
483 gst_pad_set_bufferpool_function (GstPad *pad,
484 GstPadBufferPoolFunction bufpool)
486 g_return_if_fail (pad != NULL);
487 g_return_if_fail (GST_IS_REAL_PAD (pad));
489 GST_RPAD_BUFFERPOOLFUNC (pad) = bufpool;
490 GST_DEBUG (GST_CAT_PADS, "bufferpoolfunc for %s:%s set to %s\n",
491 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_FUNCPTR_NAME (bufpool));
495 gst_pad_push_func(GstPad *pad, GstBuffer *buf)
497 if (GST_RPAD_CHAINFUNC (GST_RPAD_PEER (pad)) != NULL) {
498 GST_DEBUG (GST_CAT_DATAFLOW, "calling chain function %s\n",
499 GST_DEBUG_FUNCPTR_NAME (GST_RPAD_CHAINFUNC (GST_RPAD_PEER (pad))));
500 (GST_RPAD_CHAINFUNC (GST_RPAD_PEER (pad))) (pad, buf);
502 GST_DEBUG (GST_CAT_DATAFLOW, "default pad_push handler in place, no chain function\n");
503 g_warning ("(internal error) default pad_push in place for pad %s:%s but it has no chain function",
504 GST_DEBUG_PAD_NAME (pad));
510 * gst_pad_disconnect:
511 * @srcpad: the source pad to disconnect
512 * @sinkpad: the sink pad to disconnect
514 * Disconnects the source pad from the sink pad.
517 gst_pad_disconnect (GstPad *srcpad,
520 GstRealPad *realsrc, *realsink;
523 g_return_if_fail (srcpad != NULL);
524 g_return_if_fail (GST_IS_PAD (srcpad));
525 g_return_if_fail (sinkpad != NULL);
526 g_return_if_fail (GST_IS_PAD (sinkpad));
528 GST_INFO (GST_CAT_ELEMENT_PADS, "disconnecting %s:%s(%p) and %s:%s(%p)",
529 GST_DEBUG_PAD_NAME (srcpad), srcpad, GST_DEBUG_PAD_NAME (sinkpad), sinkpad);
531 /* now we need to deal with the real/ghost stuff */
532 realsrc = GST_PAD_REALIZE (srcpad);
533 realsink = GST_PAD_REALIZE (sinkpad);
535 g_return_if_fail (GST_RPAD_PEER (realsrc) != NULL);
536 g_return_if_fail (GST_RPAD_PEER (realsink) != NULL);
538 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
539 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
546 g_return_if_fail ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
547 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK));
549 /* first clear peers */
550 GST_RPAD_PEER (realsrc) = NULL;
551 GST_RPAD_PEER (realsink) = NULL;
553 /* reset the filters, both filters are refcounted once */
554 if (GST_RPAD_FILTER (realsrc)) {
555 gst_caps_unref (GST_RPAD_FILTER (realsrc));
556 GST_RPAD_FILTER (realsink) = NULL;
557 GST_RPAD_FILTER (realsrc) = NULL;
560 /* now tell the scheduler */
561 if (GST_PAD_PARENT (realsrc)->sched)
562 gst_scheduler_pad_disconnect (GST_PAD_PARENT (realsrc)->sched, (GstPad *)realsrc, (GstPad *)realsink);
563 else if (GST_PAD_PARENT (realsink)->sched)
564 gst_scheduler_pad_disconnect (GST_PAD_PARENT (realsink)->sched, (GstPad *)realsrc, (GstPad *)realsink);
566 /* fire off a signal to each of the pads telling them that they've been disconnected */
567 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_DISCONNECTED], 0, realsink);
568 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_DISCONNECTED], 0, realsrc);
570 GST_INFO (GST_CAT_ELEMENT_PADS, "disconnected %s:%s and %s:%s",
571 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
575 * gst_pad_connect_filtered:
576 * @srcpad: the source pad to connect
577 * @sinkpad: the sink pad to connect
578 * @filtercaps: the filter caps.
580 * Connects the source pad to the sink pad. The filter indicates the media type
581 * that should flow trought this connection.
583 * Returns: TRUE if the pad could be connected, FALSE otherwise
586 gst_pad_connect_filtered (GstPad *srcpad, GstPad *sinkpad, GstCaps *filtercaps)
588 GstRealPad *realsrc, *realsink;
589 gboolean negotiated = FALSE;
590 gint num_decoupled = 0;
593 g_return_val_if_fail (srcpad != NULL, FALSE);
594 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
595 g_return_val_if_fail (sinkpad != NULL, FALSE);
596 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
598 GST_INFO (GST_CAT_PADS, "connecting %s:%s and %s:%s",
599 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
601 /* now we need to deal with the real/ghost stuff */
602 realsrc = GST_PAD_REALIZE (srcpad);
603 realsink = GST_PAD_REALIZE (sinkpad);
605 if ((GST_PAD (realsrc) != srcpad) || (GST_PAD (realsink) != sinkpad))
606 GST_INFO (GST_CAT_PADS, "*actually* connecting %s:%s and %s:%s",
607 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
609 g_return_val_if_fail (GST_RPAD_PEER (realsrc) == NULL, FALSE);
610 g_return_val_if_fail (GST_RPAD_PEER (realsink) == NULL, FALSE);
611 g_return_val_if_fail (GST_PAD_PARENT (realsrc) != NULL, FALSE);
612 g_return_val_if_fail (GST_PAD_PARENT (realsink) != NULL, FALSE);
614 if (realsrc->sched && realsink->sched) {
615 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsrc), GST_ELEMENT_DECOUPLED))
617 if (GST_FLAG_IS_SET (GST_PAD_PARENT (realsink), GST_ELEMENT_DECOUPLED))
620 if (realsrc->sched == realsink->sched && num_decoupled != 0) {
621 g_warning ("cannot connect pads from decoupled elements with the same sched\n");
623 } else if (realsrc->sched != realsink->sched && num_decoupled != 1) {
624 g_warning ("connecting pads with different scheds requires exactly one decoupled element (queue)\n");
629 /* check for reversed directions and swap if necessary */
630 if ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SINK) &&
631 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SRC)) {
638 g_return_val_if_fail ((GST_RPAD_DIRECTION (realsrc) == GST_PAD_SRC) &&
639 (GST_RPAD_DIRECTION (realsink) == GST_PAD_SINK), FALSE);
641 /* first set peers */
642 GST_RPAD_PEER (realsrc) = realsink;
643 GST_RPAD_PEER (realsink) = realsrc;
645 if (!gst_pad_try_reconnect_filtered_func (GST_PAD (realsrc), filtercaps, FALSE)) {
646 GST_DEBUG (GST_CAT_CAPS, "pads cannot connect\n");
648 GST_RPAD_PEER (realsrc) = NULL;
649 GST_RPAD_PEER (realsink) = NULL;
654 /* fire off a signal to each of the pads telling them that they've been connected */
655 g_signal_emit (G_OBJECT (realsrc), gst_real_pad_signals[REAL_CONNECTED], 0, realsink);
656 g_signal_emit (G_OBJECT (realsink), gst_real_pad_signals[REAL_CONNECTED], 0, realsrc);
658 /* now tell the scheduler(s) */
660 gst_scheduler_pad_connect (realsrc->sched, (GstPad *)realsrc, (GstPad *)realsink);
661 else if (realsink->sched)
662 gst_scheduler_pad_connect (realsink->sched, (GstPad *)realsrc, (GstPad *)realsink);
664 GST_INFO (GST_CAT_PADS, "connected %s:%s and %s:%s",
665 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad));
672 * @srcpad: the source pad to connect
673 * @sinkpad: the sink pad to connect
675 * Connects the source pad to the sink pad.
677 * Returns: TRUE if the pad could be connected, FALSE otherwise
680 gst_pad_connect (GstPad *srcpad, GstPad *sinkpad)
682 return gst_pad_connect_filtered (srcpad, sinkpad, NULL);
686 * gst_pad_set_parent:
687 * @pad: the pad to set the parent
688 * @parent: the object to set the parent to
690 * Sets the parent object of a pad.
693 gst_pad_set_parent (GstPad *pad,
696 g_return_if_fail (pad != NULL);
697 g_return_if_fail (GST_IS_PAD (pad));
698 g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
699 g_return_if_fail (parent != NULL);
700 g_return_if_fail (GST_IS_OBJECT (parent));
701 g_return_if_fail ((gpointer)pad != (gpointer)parent);
703 gst_object_set_parent (GST_OBJECT (pad), parent);
707 * gst_pad_get_parent:
708 * @pad: the pad to get the parent from
710 * Get the parent object of this pad.
712 * Returns: the parent object
715 gst_pad_get_parent (GstPad *pad)
717 g_return_val_if_fail (pad != NULL, NULL);
718 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
720 return GST_PAD_PARENT (pad);
724 * gst_pad_get_padtemplate:
725 * @pad: the pad to get the padtemplate from
727 * Get the padtemplate object of this pad.
729 * Returns: the padtemplate object
732 gst_pad_get_padtemplate (GstPad *pad)
734 g_return_val_if_fail (pad != NULL, NULL);
735 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
737 return GST_PAD_PADTEMPLATE (pad);
743 * @pad: the pad to set the scheduler for
744 * @sched: The scheduler to set
746 * Set the scheduler for the pad
749 gst_pad_set_sched (GstPad *pad, GstScheduler *sched)
751 g_return_if_fail (pad != NULL);
752 g_return_if_fail (GST_IS_PAD (pad));
754 GST_RPAD_SCHED(pad) = sched;
759 * @pad: the pad to get the scheduler from
761 * Get the scheduler of the pad
763 * Returns: the scheduler of the pad.
766 gst_pad_get_sched (GstPad *pad)
768 g_return_val_if_fail (pad != NULL, NULL);
769 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
771 return GST_RPAD_SCHED(pad);
775 * gst_pad_unset_sched:
776 * @pad: the pad to unset the scheduler for
778 * Unset the scheduler for the pad
781 gst_pad_unset_sched (GstPad *pad)
783 g_return_if_fail (pad != NULL);
784 g_return_if_fail (GST_IS_PAD (pad));
786 GST_RPAD_SCHED(pad) = NULL;
790 * gst_pad_get_real_parent:
791 * @pad: the pad to get the parent from
793 * Get the real parent object of this pad. If the pad
794 * is a ghostpad, the actual owner of the real pad is
795 * returned, as opposed to the gst_pad_get_parent().
797 * Returns: the parent object
800 gst_pad_get_real_parent (GstPad *pad)
802 g_return_val_if_fail (pad != NULL, NULL);
803 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
805 return GST_PAD_PARENT (GST_PAD (GST_PAD_REALIZE (pad)));
809 * gst_pad_add_ghost_pad:
810 * @pad: the pad to set the ghost parent
811 * @ghostpad: the ghost pad to add
813 * Add a ghost pad to a pad.
816 gst_pad_add_ghost_pad (GstPad *pad,
821 g_return_if_fail (pad != NULL);
822 g_return_if_fail (GST_IS_PAD (pad));
823 g_return_if_fail (ghostpad != NULL);
824 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
826 realpad = GST_PAD_REALIZE (pad);
828 realpad->ghostpads = g_list_prepend (realpad->ghostpads, ghostpad);
833 * gst_pad_remove_ghost_pad:
834 * @pad: the pad to remove the ghost parent
835 * @ghostpad: the ghost pad to remove from the pad
837 * Remove a ghost pad from a pad.
840 gst_pad_remove_ghost_pad (GstPad *pad,
845 g_return_if_fail (pad != NULL);
846 g_return_if_fail (GST_IS_PAD (pad));
847 g_return_if_fail (ghostpad != NULL);
848 g_return_if_fail (GST_IS_GHOST_PAD (ghostpad));
850 realpad = GST_PAD_REALIZE (pad);
852 realpad->ghostpads = g_list_remove (realpad->ghostpads, ghostpad);
856 * gst_pad_get_ghost_pad_list:
857 * @pad: the pad to get the ghost parents from
859 * Get the ghost parents of this pad.
861 * Returns: a GList of ghost pads
864 gst_pad_get_ghost_pad_list (GstPad *pad)
866 g_return_val_if_fail (pad != NULL, NULL);
867 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
869 return GST_PAD_REALIZE(pad)->ghostpads;
872 static GstPadConnectReturn
873 gst_pad_try_set_caps_func (GstPad *pad, GstCaps *caps, gboolean notify, gboolean set_caps)
877 GST_INFO (GST_CAT_CAPS, "trying to set caps %p on pad %s:%s",
878 caps, GST_DEBUG_PAD_NAME (pad));
880 if (notify && GST_RPAD_CONNECTFUNC (pad)) {
881 GstPadConnectReturn res;
884 GST_INFO (GST_CAT_CAPS, "calling connect function on pad %s:%s",
885 GST_DEBUG_PAD_NAME (pad));
887 res = GST_RPAD_CONNECTFUNC (pad) (pad, caps);
890 case GST_PAD_CONNECT_REFUSED:
891 debug_string = "REFUSED";
893 case GST_PAD_CONNECT_OK:
896 case GST_PAD_CONNECT_DONE:
897 debug_string = "DONE";
899 case GST_PAD_CONNECT_DELAYED:
900 debug_string = "DELAYED";
903 g_warning ("unknown return code from connect function of pad %s:%s",
904 GST_DEBUG_PAD_NAME (pad));
905 return GST_PAD_CONNECT_REFUSED;
908 GST_INFO (GST_CAT_CAPS, "got reply %s (%d) from connect function on pad %s:%s",
909 debug_string, res, GST_DEBUG_PAD_NAME (pad));
911 if (res == GST_PAD_CONNECT_DONE) {
912 GST_INFO (GST_CAT_CAPS, "pad %s:%s is done", GST_DEBUG_PAD_NAME (pad));
913 return GST_PAD_CONNECT_DONE;
915 if (res == GST_PAD_CONNECT_REFUSED) {
916 GST_INFO (GST_CAT_CAPS, "pad %s:%s doesn't accept caps",
917 GST_DEBUG_PAD_NAME (pad));
918 return GST_PAD_CONNECT_REFUSED;
921 /* we can only set caps on the pad if they are ficed */
922 if (GST_CAPS_IS_FIXED (caps)) {
925 GST_INFO (GST_CAT_CAPS, "setting caps on pad %s:%s",
926 GST_DEBUG_PAD_NAME (pad));
927 /* if we got this far all is ok */
928 oldcaps = GST_PAD_CAPS (pad);
929 if (caps) gst_caps_ref (caps);
930 GST_PAD_CAPS (pad) = caps;
931 if (oldcaps) gst_caps_unref (oldcaps);
934 GST_INFO (GST_CAT_CAPS, "NOT setting caps on pad %s:%s, as requested",
935 GST_DEBUG_PAD_NAME (pad));
939 GST_INFO (GST_CAT_CAPS, "caps are not fixed on pad %s:%s, not setting them yet",
940 GST_DEBUG_PAD_NAME (pad));
943 return GST_PAD_CONNECT_OK;
947 gst_pad_try_set_caps (GstPad *pad, GstCaps *caps)
952 peer = GST_PAD (GST_RPAD_PEER (pad));
954 GST_INFO (GST_CAT_CAPS, "trying to set caps %p on pad %s:%s",
955 caps, GST_DEBUG_PAD_NAME (pad));
957 if (!GST_CAPS_IS_FIXED (caps)) {
958 g_warning ("trying to set non fixed caps on pad %s:%s, caps dump follow",
959 GST_DEBUG_PAD_NAME (pad));
960 gst_caps_debug (caps);
963 if (peer && !gst_pad_try_set_caps_func (peer, caps, TRUE, TRUE))
965 if (!gst_pad_try_set_caps_func (pad, caps, FALSE, TRUE))
973 gst_pad_try_reconnect_filtered_func (GstPad *pad, GstCaps *filtercaps, gboolean clear)
975 GstCaps *srccaps, *sinkcaps;
976 GstCaps *intersection = NULL;
977 GstRealPad *realsrc, *realsink;
979 g_return_val_if_fail (pad != NULL, FALSE);
981 realsrc = GST_PAD_REALIZE (pad);
982 realsink = GST_PAD_REALIZE (GST_RPAD_PEER (realsrc));
984 g_return_val_if_fail (GST_RPAD_PEER (realsrc) != NULL, FALSE);
985 g_return_val_if_fail (GST_RPAD_PEER (realsink) != NULL, FALSE);
987 GST_INFO (GST_CAT_PADS, "reconnect filtered %s:%s and %s:%s",
988 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
991 GST_INFO (GST_CAT_PADS, "reconnect filtered %s:%s and %s:%s, clearing caps",
992 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
994 GST_PAD_CAPS (GST_PAD (realsrc)) = NULL;
995 GST_PAD_CAPS (GST_PAD (realsink)) = NULL;
998 srccaps = gst_pad_get_caps (GST_PAD (realsrc));
999 GST_INFO (GST_CAT_PADS, "dumping caps of pad %s:%s", GST_DEBUG_PAD_NAME (realsrc));
1000 gst_caps_debug (srccaps);
1001 sinkcaps = gst_pad_get_caps (GST_PAD (realsink));
1002 GST_INFO (GST_CAT_PADS, "dumping caps of pad %s:%s", GST_DEBUG_PAD_NAME (realsink));
1003 gst_caps_debug (sinkcaps);
1005 intersection = gst_caps_intersect (srccaps, sinkcaps);
1007 /* if we have no intersection but one of the caps was not NULL.. */
1008 if (!intersection && (srccaps || sinkcaps )) {
1009 /* the intersection is NULL, this means they have no common format */
1010 GST_INFO (GST_CAT_PADS, "pads %s:%s and %s:%s have no common type",
1011 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1015 GST_INFO (GST_CAT_PADS, "pads %s:%s and %s:%s intersected to %s caps",
1016 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink),
1017 ((intersection && GST_CAPS_IS_FIXED (intersection)) ? "fixed" : "variable"));
1020 GstCaps *filtered_intersection = gst_caps_intersect (intersection, filtercaps);
1022 /* get rid of the old intersection here */
1023 gst_caps_unref (intersection);
1025 if (!filtered_intersection) {
1026 GST_INFO (GST_CAT_PADS, "filtered connection between pads %s:%s and %s:%s is empty, disconnecting",
1027 GST_DEBUG_PAD_NAME (realsrc), GST_DEBUG_PAD_NAME (realsink));
1030 intersection = filtered_intersection;
1032 GST_RPAD_APPFILTER (realsink) = filtercaps;
1033 GST_RPAD_APPFILTER (realsrc) = filtercaps;
1036 GST_DEBUG (GST_CAT_CAPS, "setting filter for connection to:\n");
1037 gst_caps_debug (intersection);
1039 GST_RPAD_FILTER (realsrc) = intersection;
1040 GST_RPAD_FILTER (realsink) = intersection;
1043 GstPadConnectReturn res;
1045 res = gst_pad_try_set_caps_func (GST_PAD (realsrc), intersection, TRUE, TRUE);
1046 if (res == GST_PAD_CONNECT_REFUSED)
1048 if (res == GST_PAD_CONNECT_DONE)
1051 res = gst_pad_try_set_caps_func (GST_PAD (realsink), intersection, TRUE, TRUE);
1052 if (res == GST_PAD_CONNECT_REFUSED)
1054 if (res == GST_PAD_CONNECT_DONE)
1062 * gst_pad_try_reconnect_filtered:
1063 * @pad: the pad to reconnect
1064 * @caps: the capabilities to use in the reconnectiong
1066 * Try to reconnect this pad and its peer with the specified caps
1068 * Returns: a boolean indicating the peer pad could accept the caps.
1071 gst_pad_try_reconnect_filtered (GstPad *pad, GstCaps *filtercaps)
1073 g_return_val_if_fail (pad != NULL, FALSE);
1074 g_return_val_if_fail (GST_IS_REAL_PAD (pad), FALSE);
1075 g_return_val_if_fail (GST_PAD_IS_CONNECTED (pad), FALSE);
1077 return gst_pad_try_reconnect_filtered_func (pad, filtercaps, TRUE);
1081 * gst_pad_reconnect_filtered:
1082 * @pad: the pad to reconnect
1083 * @caps: the capabilities to use in the reconnectiong
1085 * Try to reconnect this pad and its peer with the specified caps.
1087 * Returns: a boolean indicating the peer pad could accept the caps.
1088 * if FALSE is returned, the pads are disconnected.
1091 gst_pad_reconnect_filtered (GstPad *pad, GstCaps *filtercaps)
1093 g_return_val_if_fail (pad != NULL, FALSE);
1094 g_return_val_if_fail (GST_IS_REAL_PAD (pad), FALSE);
1095 g_return_val_if_fail (GST_PAD_IS_CONNECTED (pad), FALSE);
1097 if (!gst_pad_try_reconnect_filtered_func (pad, filtercaps, TRUE)) {
1098 gst_pad_disconnect (pad, GST_PAD (GST_PAD_PEER (pad)));
1105 * gst_pad_proxy_connect:
1106 * @pad: the pad to proxy to
1107 * @caps: the capabilities to use in the proxying
1109 * Proxy the connect function to the specified pad.
1111 * Returns: a boolean indicating the peer pad could accept the caps.
1114 gst_pad_proxy_connect (GstPad *pad, GstCaps *caps)
1118 peer = GST_PAD (GST_RPAD_PEER (pad));
1120 GST_INFO (GST_CAT_CAPS, "proxy connect to pad %s:%s",
1121 GST_DEBUG_PAD_NAME (pad));
1123 if (peer && !gst_pad_try_set_caps_func (peer, caps, TRUE, TRUE))
1124 return GST_PAD_CONNECT_REFUSED;
1125 if (!gst_pad_try_set_caps_func (pad, caps, FALSE, TRUE))
1126 return GST_PAD_CONNECT_REFUSED;
1128 return GST_PAD_CONNECT_OK;
1133 * @pad: the pad to get the capabilities from
1135 * Get the capabilities of this pad.
1137 * Returns: the capabilities of this pad
1140 gst_pad_get_caps (GstPad *pad)
1142 g_return_val_if_fail (pad != NULL, NULL);
1143 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1145 GST_DEBUG (GST_CAT_CAPS, "get pad caps of %s:%s (%p)\n",
1146 GST_DEBUG_PAD_NAME (pad), pad);
1148 if (GST_PAD_CAPS (pad)) {
1149 GST_DEBUG (GST_CAT_CAPS, "using pad real caps\n");
1150 return GST_PAD_CAPS (pad);
1152 else if GST_RPAD_GETCAPSFUNC (pad) {
1153 GST_DEBUG (GST_CAT_CAPS, "using pad get function\n");
1154 return GST_RPAD_GETCAPSFUNC (pad) (pad, NULL);
1156 else if (GST_PAD_PADTEMPLATE (pad)) {
1157 GST_DEBUG (GST_CAT_CAPS, "using pad template\n");
1158 return GST_PADTEMPLATE_CAPS (GST_PAD_PADTEMPLATE (pad));
1160 GST_DEBUG (GST_CAT_CAPS, "pad has no caps\n");
1166 * gst_pad_get_padtemplate_caps:
1167 * @pad: the pad to get the capabilities from
1169 * Get the capabilities of this pad.
1171 * Returns: a list of the capabilities of this pad
1174 gst_pad_get_padtemplate_caps (GstPad *pad)
1176 g_return_val_if_fail (pad != NULL, NULL);
1177 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1179 if (GST_PAD_PADTEMPLATE (pad))
1180 return GST_PADTEMPLATE_CAPS (GST_PAD_PADTEMPLATE (pad));
1187 * gst_padtemplate_get_caps_by_name:
1188 * @templ: the padtemplate to get the capabilities from
1189 * @name: the name of the capability to get
1191 * Get the capability with the given name from this padtemplate.
1193 * Returns: a capability or NULL if not found
1196 gst_padtemplate_get_caps_by_name (GstPadTemplate *templ, const gchar *name)
1200 g_return_val_if_fail (templ != NULL, NULL);
1202 caps = GST_PADTEMPLATE_CAPS (templ);
1206 return gst_caps_get_by_name (caps, name);
1210 * gst_pad_check_compatibility:
1211 * @srcpad: the srcpad to check
1212 * @sinkpad: the sinkpad to check against
1214 * Check if two pads have compatible capabilities.
1216 * Returns: TRUE if they are compatible or the capabilities
1217 * could not be checked
1220 gst_pad_check_compatibility (GstPad *srcpad, GstPad *sinkpad)
1222 g_return_val_if_fail (srcpad != NULL, FALSE);
1223 g_return_val_if_fail (GST_IS_PAD (srcpad), FALSE);
1224 g_return_val_if_fail (sinkpad != NULL, FALSE);
1225 g_return_val_if_fail (GST_IS_PAD (sinkpad), FALSE);
1227 if (GST_PAD_CAPS (srcpad) && GST_PAD_CAPS (sinkpad)) {
1228 if (!gst_caps_check_compatibility (GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad))) {
1236 GST_DEBUG (GST_CAT_PADS, "could not check capabilities of pads (%s:%s) and (%s:%s) %p %p\n",
1237 GST_DEBUG_PAD_NAME (srcpad), GST_DEBUG_PAD_NAME (sinkpad),
1238 GST_PAD_CAPS (srcpad), GST_PAD_CAPS (sinkpad));
1245 * @pad: the pad to get the peer from
1247 * Get the peer pad of this pad.
1249 * Returns: the peer pad
1252 gst_pad_get_peer (GstPad *pad)
1254 g_return_val_if_fail (pad != NULL, NULL);
1255 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1257 return GST_PAD (GST_PAD_PEER (pad));
1261 * gst_pad_get_allowed_caps:
1262 * @pad: the pad to get the allowed caps from
1264 * Gst the caps of the allowed media types that can
1265 * go through this pad.
1267 * Returns: the allowed caps
1270 gst_pad_get_allowed_caps (GstPad *pad)
1274 g_return_val_if_fail (pad != NULL, NULL);
1275 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1277 peer = GST_RPAD_PEER (pad);
1279 GST_DEBUG (GST_CAT_PROPERTIES, "get allowed caps of %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1280 /* this is not very correct: ...
1281 if (peer && GST_RPAD_GETCAPSFUNC (peer)) {
1282 GST_DEBUG (GST_CAT_PROPERTIES, "using getcaps function of peer %s:%s\n",
1283 GST_DEBUG_PAD_NAME (peer));
1284 return GST_RPAD_GETCAPSFUNC (peer) (GST_PAD (peer), NULL);
1287 return gst_caps_copy (GST_RPAD_FILTER (pad));
1291 * gst_pad_get_allowed_caps:
1292 * @pad: the pad to get the allowed caps from
1294 * Gst the caps of the allowed media types that can
1295 * go through this pad.
1297 * Returns: the allowed caps
1300 gst_pad_recalc_allowed_caps (GstPad *pad)
1304 g_return_if_fail (pad != NULL);
1305 g_return_if_fail (GST_IS_PAD (pad));
1307 GST_DEBUG (GST_CAT_PROPERTIES, "set allowed caps of %s:%s\n", GST_DEBUG_PAD_NAME (pad));
1309 peer = GST_RPAD_PEER (pad);
1311 gst_pad_try_reconnect_filtered (pad, GST_RPAD_APPFILTER (pad));
1315 * gst_pad_get_bufferpool:
1316 * @pad: the pad to get the bufferpool from
1318 * Get the bufferpool of the peer pad of the given
1321 * Returns: The GstBufferPool or NULL.
1324 gst_pad_get_bufferpool (GstPad *pad)
1328 g_return_val_if_fail (pad != NULL, NULL);
1329 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
1331 peer = GST_RPAD_PEER (pad);
1336 GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
1338 if (peer->bufferpoolfunc) {
1339 GST_DEBUG (GST_CAT_PADS, "calling bufferpoolfunc &%s (@%p) of peer pad %s:%s\n",
1340 GST_DEBUG_FUNCPTR_NAME (peer->bufferpoolfunc), &peer->bufferpoolfunc, GST_DEBUG_PAD_NAME (((GstPad*) peer)));
1341 return (peer->bufferpoolfunc) (((GstPad*) peer));
1343 GST_DEBUG (GST_CAT_PADS, "no bufferpoolfunc for peer pad %s:%s at %p\n",
1344 GST_DEBUG_PAD_NAME (((GstPad*) peer)), &peer->bufferpoolfunc);
1350 gst_real_pad_dispose (GObject *object)
1352 GstPad *pad = GST_PAD (object);
1354 GST_DEBUG (GST_CAT_REFCOUNTING, "dispose %s:%s\n", GST_DEBUG_PAD_NAME(pad));
1356 if (GST_PAD (pad)->padtemplate){
1357 GST_DEBUG (GST_CAT_REFCOUNTING, "unreffing padtemplate'%s'\n",GST_OBJECT_NAME(GST_OBJECT (GST_PAD (pad)->padtemplate)));
1358 gst_object_unref (GST_OBJECT (GST_PAD (pad)->padtemplate));
1361 if (GST_PAD_PEER (pad)){
1362 GST_DEBUG (GST_CAT_REFCOUNTING, "disconnecting pad '%s'\n",GST_OBJECT_NAME(GST_OBJECT (GST_PAD (GST_PAD_PEER (pad)))));
1363 gst_pad_disconnect (pad, GST_PAD (GST_PAD_PEER (pad)));
1366 /* we destroy the ghostpads, because they are nothing without the real pad */
1367 if (GST_REAL_PAD (pad)->ghostpads) {
1368 GList *orig, *ghostpads;
1370 orig = ghostpads = g_list_copy (GST_REAL_PAD (pad)->ghostpads);
1373 GstPad *ghostpad = GST_PAD (ghostpads->data);
1375 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (ghostpad))){
1376 GST_DEBUG (GST_CAT_REFCOUNTING, "removing ghost pad from element '%s'\n",
1377 GST_OBJECT_NAME (GST_OBJECT_PARENT (ghostpad)));
1379 gst_element_remove_ghost_pad (GST_ELEMENT (GST_OBJECT_PARENT (ghostpad)), GST_PAD (ghostpad));
1381 ghostpads = g_list_next (ghostpads);
1384 g_list_free (GST_REAL_PAD(pad)->ghostpads);
1387 if (GST_IS_ELEMENT (GST_OBJECT_PARENT (pad))){
1388 GST_DEBUG (GST_CAT_REFCOUNTING, "removing pad from element '%s'\n",
1389 GST_OBJECT_NAME (GST_OBJECT (GST_ELEMENT (GST_OBJECT_PARENT (pad)))));
1391 gst_element_remove_pad (GST_ELEMENT (GST_OBJECT_PARENT (pad)), pad);
1394 G_OBJECT_CLASS (real_pad_parent_class)->dispose (object);
1398 #ifndef GST_DISABLE_LOADSAVE
1400 * gst_pad_load_and_connect:
1401 * @self: the XML node to read the description from
1402 * @parent: the element that has the pad
1404 * Read the pad definition from the XML node and connect the given pad
1405 * in element to a pad of an element up in the hierarchy.
1408 gst_pad_load_and_connect (xmlNodePtr self,
1411 xmlNodePtr field = self->xmlChildrenNode;
1412 GstPad *pad = NULL, *targetpad;
1413 guchar *peer = NULL;
1416 GstObject *grandparent;
1419 if (!strcmp (field->name, "name")) {
1420 pad = gst_element_get_pad (GST_ELEMENT (parent), xmlNodeGetContent (field));
1422 else if (!strcmp(field->name, "peer")) {
1423 peer = xmlNodeGetContent (field);
1425 field = field->next;
1427 g_return_if_fail (pad != NULL);
1429 if (peer == NULL) return;
1431 split = g_strsplit (peer, ".", 2);
1433 g_return_if_fail (split[0] != NULL);
1434 g_return_if_fail (split[1] != NULL);
1436 grandparent = gst_object_get_parent (parent);
1438 if (grandparent && GST_IS_BIN (grandparent)) {
1439 target = gst_bin_get_by_name_recurse_up (GST_BIN (grandparent), split[0]);
1444 if (target == NULL) goto cleanup;
1446 targetpad = gst_element_get_pad (target, split[1]);
1448 if (targetpad == NULL) goto cleanup;
1450 gst_pad_connect (pad, targetpad);
1457 * gst_pad_save_thyself:
1458 * @pad: the pad to save
1459 * @parent: the parent XML node to save the description in
1461 * Saves the pad into an xml representation
1463 * Returns: the xml representation of the pad
1466 gst_pad_save_thyself (GstObject *object,
1469 GstRealPad *realpad;
1472 g_return_val_if_fail (GST_IS_REAL_PAD (object), NULL);
1474 realpad = GST_REAL_PAD(object);
1476 xmlNewChild(parent,NULL,"name", GST_PAD_NAME (realpad));
1477 if (GST_RPAD_PEER(realpad) != NULL) {
1478 peer = GST_PAD(GST_RPAD_PEER(realpad));
1479 /* first check to see if the peer's parent's parent is the same */
1480 /* we just save it off */
1481 xmlNewChild(parent,NULL,"peer",g_strdup_printf("%s.%s",
1482 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer)));
1484 xmlNewChild(parent,NULL,"peer","");
1490 * gst_pad_ghost_save_thyself:
1491 * @pad: the pad to save
1493 * @parent: the parent XML node to save the description in
1495 * Saves the ghost pad into an xml representation.
1497 * Returns: the xml representation of the pad
1500 gst_pad_ghost_save_thyself (GstPad *pad,
1506 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), NULL);
1508 self = xmlNewChild(parent,NULL,"ghostpad",NULL);
1509 xmlNewChild(self,NULL,"name", GST_PAD_NAME (pad));
1510 xmlNewChild(self,NULL,"parent", GST_OBJECT_NAME (GST_PAD_PARENT (pad)));
1512 /* FIXME FIXME FIXME! */
1516 #endif /* GST_DISABLE_LOADSAVE */
1518 #ifndef gst_pad_push
1521 * @pad: the pad to push
1522 * @buf: the buffer to push
1524 * Push a buffer to the peer of the pad.
1527 gst_pad_push (GstPad *pad, GstBuffer *buf)
1529 GstRealPad *peer = GST_RPAD_PEER (pad);
1531 GST_DEBUG_ENTER ("(%s:%s)", GST_DEBUG_PAD_NAME (pad));
1533 g_return_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SRC);
1536 g_warning ("push on pad %s:%s but it is unconnected", GST_DEBUG_PAD_NAME (pad));
1539 if (peer->chainhandler) {
1541 GST_DEBUG (GST_CAT_DATAFLOW, "calling chainhandler &%s of peer pad %s:%s\n",
1542 GST_DEBUG_FUNCPTR_NAME (peer->chainhandler), GST_DEBUG_PAD_NAME (GST_PAD (peer)));
1543 (peer->chainhandler) (GST_PAD_CAST (peer), buf);
1547 g_warning ("trying to push a NULL buffer on pad %s:%s", GST_DEBUG_PAD_NAME (peer));
1552 g_warning ("(internal error) push on pad %s:%s but it has no chainhandler", GST_DEBUG_PAD_NAME (peer));
1555 /* clean up the mess here */
1557 if (GST_IS_BUFFER (buf))
1558 gst_buffer_unref (buf);
1560 gst_event_free (GST_EVENT (buf));
1565 #ifndef gst_pad_pull
1568 * @pad: the pad to pull
1570 * Pull a buffer from the peer pad.
1572 * Returns: a new buffer from the peer pad.
1575 gst_pad_pull (GstPad *pad)
1577 GstRealPad *peer = GST_RPAD_PEER(pad);
1579 GST_DEBUG_ENTER("(%s:%s)",GST_DEBUG_PAD_NAME(pad));
1581 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK, NULL);
1584 gst_element_error (GST_PAD_PARENT (pad),
1585 "pull on pad %s:%s but it was unconnected",
1586 GST_ELEMENT_NAME (GST_PAD_PARENT (pad)), GST_PAD_NAME (pad),
1590 if (peer->gethandler) {
1593 GST_DEBUG (GST_CAT_DATAFLOW, "calling gethandler %s of peer pad %s:%s\n",
1594 GST_DEBUG_FUNCPTR_NAME (peer->gethandler), GST_DEBUG_PAD_NAME (peer));
1596 buf = (peer->gethandler) (GST_PAD_CAST (peer));
1599 /* no null buffers allowed */
1600 gst_element_error (GST_PAD_PARENT (pad),
1601 "NULL buffer during pull on %s:%s", GST_DEBUG_PAD_NAME (pad), NULL);
1604 gst_element_error (GST_PAD_PARENT (pad),
1605 "(internal error) pull on pad %s:%s but the peer pad %s:%s has no gethandler",
1606 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (peer),
1614 #ifndef gst_pad_pullregion
1616 * gst_pad_pullregion:
1617 * @pad: the pad to pull the region from
1618 * @type: the regiontype
1619 * @offset: the offset/start of the buffer to pull
1620 * @len: the length of the buffer to pull
1622 * Pull a buffer region from the peer pad. The region to pull can be
1623 * specified with a offset/lenght pair or with a start/legnth time
1624 * indicator as specified by the type parameter.
1626 * Returns: a new buffer from the peer pad with data in the specified
1630 gst_pad_pullregion (GstPad *pad, GstRegionType type, guint64 offset, guint64 len)
1633 GstBuffer *result = NULL;
1635 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK, NULL);
1638 peer = GST_RPAD_PEER(pad);
1639 g_return_val_if_fail (peer != NULL, NULL);
1642 gst_buffer_unref (result);
1644 GST_DEBUG_ENTER("(%s:%s,%d,%lld,%lld)",GST_DEBUG_PAD_NAME(pad),type,offset,len);
1646 if (peer->pullregionfunc) {
1647 GST_DEBUG (GST_CAT_DATAFLOW, "calling pullregionfunc &%s of peer pad %s:%s\n",
1648 GST_DEBUG_FUNCPTR_NAME (peer->pullregionfunc), GST_DEBUG_PAD_NAME(GST_PAD_CAST (peer)));
1649 result = (peer->pullregionfunc) (GST_PAD_CAST (peer), type, offset, len);
1651 GST_DEBUG (GST_CAT_DATAFLOW,"no pullregionfunc\n");
1657 while (result && !(GST_BUFFER_OFFSET (result) == offset &&
1658 GST_BUFFER_SIZE (result) == len));
1666 * @pad: the pad to peek
1668 * Peek for a buffer from the peer pad.
1670 * Returns: a from the peer pad or NULL if the peer has no buffer.
1673 gst_pad_peek (GstPad *pad)
1675 g_return_val_if_fail (GST_PAD_DIRECTION (pad) == GST_PAD_SINK, NULL);
1677 return GST_RPAD_BUFPEN (GST_RPAD_PEER (pad));
1682 * @padlist: A list of pads
1684 * Wait for a buffer on the list of pads.
1686 * Returns: The pad that has a buffer available, use
1687 * #gst_pad_pull to get the buffer.
1690 gst_pad_select (GList *padlist)
1694 pad = gst_scheduler_pad_select (GST_PAD_PARENT (padlist->data)->sched, padlist);
1701 * @pad: The first pad to perform the select on
1704 * Wait for a buffer on the given of pads.
1706 * Returns: The pad that has a buffer available, use
1707 * #gst_pad_pull to get the buffer.
1710 gst_pad_selectv (GstPad *pad, ...)
1713 GList *padlist = NULL;
1719 va_start (var_args, pad);
1722 padlist = g_list_prepend (padlist, pad);
1723 pad = va_arg (var_args, GstPad *);
1725 result = gst_pad_select (padlist);
1726 g_list_free (padlist);
1733 /************************************************************************
1738 static void gst_padtemplate_class_init (GstPadTemplateClass *klass);
1739 static void gst_padtemplate_init (GstPadTemplate *templ);
1747 static GstObject *padtemplate_parent_class = NULL;
1748 static guint gst_padtemplate_signals[TEMPL_LAST_SIGNAL] = { 0 };
1751 gst_padtemplate_get_type (void)
1753 static GType padtemplate_type = 0;
1755 if (!padtemplate_type) {
1756 static const GTypeInfo padtemplate_info = {
1757 sizeof(GstPadTemplateClass),
1760 (GClassInitFunc)gst_padtemplate_class_init,
1763 sizeof(GstPadTemplate),
1765 (GInstanceInitFunc)gst_padtemplate_init,
1768 padtemplate_type = g_type_register_static(GST_TYPE_OBJECT, "GstPadTemplate", &padtemplate_info, 0);
1770 return padtemplate_type;
1774 gst_padtemplate_class_init (GstPadTemplateClass *klass)
1776 GObjectClass *gobject_class;
1777 GstObjectClass *gstobject_class;
1779 gobject_class = (GObjectClass*)klass;
1780 gstobject_class = (GstObjectClass*)klass;
1782 padtemplate_parent_class = g_type_class_ref(GST_TYPE_OBJECT);
1784 gst_padtemplate_signals[TEMPL_PAD_CREATED] =
1785 g_signal_new ("pad_created", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST,
1786 G_STRUCT_OFFSET (GstPadTemplateClass, pad_created), NULL, NULL,
1787 gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
1791 gstobject_class->path_string_separator = "*";
1795 gst_padtemplate_init (GstPadTemplate *templ)
1800 * gst_padtemplate_new:
1801 * @name_template: the name template
1802 * @direction: the direction for the template
1803 * @presence: the presence of the pad
1804 * @caps: a list of capabilities for the template
1805 * @...: more capabilities
1807 * Creates a new padtemplate from the given arguments.
1809 * Returns: the new padtemplate
1812 gst_padtemplate_new (gchar *name_template,
1813 GstPadDirection direction, GstPadPresence presence,
1816 GstPadTemplate *new;
1818 GstCaps *thecaps = NULL;
1820 g_return_val_if_fail (name_template != NULL, NULL);
1822 new = g_object_new(gst_padtemplate_get_type () ,NULL);
1824 GST_PADTEMPLATE_NAME_TEMPLATE (new) = name_template;
1825 GST_PADTEMPLATE_DIRECTION (new) = direction;
1826 GST_PADTEMPLATE_PRESENCE (new) = presence;
1828 va_start (var_args, caps);
1831 new->fixed &= caps->fixed;
1832 thecaps = gst_caps_append (thecaps, caps);
1833 caps = va_arg (var_args, GstCaps*);
1837 GST_PADTEMPLATE_CAPS (new) = thecaps;
1843 * gst_padtemplate_get_caps:
1844 * @templ: the padtemplate to use
1846 * Get the capabilities of the padtemplate
1848 * Returns: a GstCaps*
1851 gst_padtemplate_get_caps (GstPadTemplate *templ)
1853 g_return_val_if_fail (templ != NULL, NULL);
1855 return GST_PADTEMPLATE_CAPS (templ);
1858 #ifndef GST_DISABLE_LOADSAVE
1860 * gst_padtemplate_save_thyself:
1861 * @templ: the padtemplate to save
1862 * @parent: the parent XML tree
1864 * Saves the padtemplate into XML.
1866 * Returns: the new XML tree
1869 gst_padtemplate_save_thyself (GstPadTemplate *templ, xmlNodePtr parent)
1874 GST_DEBUG (GST_CAT_XML,"saving padtemplate %s\n", templ->name_template);
1876 xmlNewChild(parent,NULL,"nametemplate", templ->name_template);
1877 xmlNewChild(parent,NULL,"direction", (templ->direction == GST_PAD_SINK? "sink":"src"));
1879 switch (templ->presence) {
1880 case GST_PAD_ALWAYS:
1881 presence = "always";
1883 case GST_PAD_SOMETIMES:
1884 presence = "sometimes";
1886 case GST_PAD_REQUEST:
1887 presence = "request";
1890 presence = "unknown";
1893 xmlNewChild(parent,NULL,"presence", presence);
1895 if (GST_PADTEMPLATE_CAPS (templ)) {
1896 subtree = xmlNewChild (parent, NULL, "caps", NULL);
1897 gst_caps_save_thyself (GST_PADTEMPLATE_CAPS (templ), subtree);
1904 * gst_padtemplate_load_thyself:
1905 * @parent: the source XML tree
1907 * Loads a padtemplate from the XML tree.
1909 * Returns: the new padtemplate
1912 gst_padtemplate_load_thyself (xmlNodePtr parent)
1914 xmlNodePtr field = parent->xmlChildrenNode;
1915 GstPadTemplate *factory;
1916 gchar *name_template = NULL;
1917 GstPadDirection direction = GST_PAD_UNKNOWN;
1918 GstPadPresence presence = GST_PAD_ALWAYS;
1919 GstCaps *caps = NULL;
1922 if (!strcmp(field->name, "nametemplate")) {
1923 name_template = xmlNodeGetContent(field);
1925 if (!strcmp(field->name, "direction")) {
1926 gchar *value = xmlNodeGetContent(field);
1928 if (!strcmp(value, "sink")) {
1929 direction = GST_PAD_SINK;
1931 else if (!strcmp(value, "src")) {
1932 direction = GST_PAD_SRC;
1936 if (!strcmp(field->name, "presence")) {
1937 gchar *value = xmlNodeGetContent(field);
1939 if (!strcmp(value, "always")) {
1940 presence = GST_PAD_ALWAYS;
1942 else if (!strcmp(value, "sometimes")) {
1943 presence = GST_PAD_SOMETIMES;
1945 else if (!strcmp(value, "request")) {
1946 presence = GST_PAD_REQUEST;
1950 else if (!strcmp(field->name, "caps")) {
1951 caps = gst_caps_load_thyself (field);
1953 field = field->next;
1956 factory = gst_padtemplate_new (name_template, direction, presence, caps, NULL);
1960 #endif /* !GST_DISABLE_LOADSAVE */
1964 * gst_pad_set_element_private:
1965 * @pad: the pad to set the private data to
1966 * @priv: The private data to attach to the pad
1968 * Set the given private data pointer to the pad. This
1969 * function can only be used by the element that own the
1973 gst_pad_set_element_private (GstPad *pad, gpointer priv)
1975 pad->element_private = priv;
1979 * gst_pad_get_element_private:
1980 * @pad: the pad to get the private data of
1982 * Get the private data of a pad. The private data can
1983 * only be set by the parent element of this pad.
1985 * Returns: a pointer to the private data.
1988 gst_pad_get_element_private (GstPad *pad)
1990 return pad->element_private;
1994 /***** ghost pads *****/
1995 GType _gst_ghost_pad_type = 0;
1997 static void gst_ghost_pad_class_init (GstGhostPadClass *klass);
1998 static void gst_ghost_pad_init (GstGhostPad *pad);
2000 static GstPad *ghost_pad_parent_class = NULL;
2001 /* static guint gst_ghost_pad_signals[LAST_SIGNAL] = { 0 }; */
2004 gst_ghost_pad_get_type(void) {
2005 if (!_gst_ghost_pad_type) {
2006 static const GTypeInfo pad_info = {
2007 sizeof(GstGhostPadClass),
2010 (GClassInitFunc)gst_ghost_pad_class_init,
2013 sizeof(GstGhostPad),
2015 (GInstanceInitFunc)gst_ghost_pad_init,
2018 _gst_ghost_pad_type = g_type_register_static(GST_TYPE_PAD, "GstGhostPad", &pad_info, 0);
2020 return _gst_ghost_pad_type;
2024 gst_ghost_pad_class_init (GstGhostPadClass *klass)
2026 GObjectClass *gobject_class;
2028 gobject_class = (GObjectClass*)klass;
2030 ghost_pad_parent_class = g_type_class_ref(GST_TYPE_PAD);
2034 gst_ghost_pad_init (GstGhostPad *pad)
2036 pad->realpad = NULL;
2040 * gst_ghost_pad_new:
2041 * @name: name of the new ghost pad
2042 * @pad: the pad to create a ghost pad of
2044 * Create a new ghost pad associated with the given pad.
2046 * Returns: new ghost pad
2049 gst_ghost_pad_new (gchar *name,
2052 GstGhostPad *ghostpad;
2054 g_return_val_if_fail (name != NULL, NULL);
2055 g_return_val_if_fail (GST_IS_PAD (pad), NULL);
2057 ghostpad = g_object_new (gst_ghost_pad_get_type () ,NULL);
2058 gst_pad_set_name (GST_PAD (ghostpad), name);
2059 GST_GPAD_REALPAD (ghostpad) = GST_PAD_REALIZE (pad);
2060 GST_PAD_PADTEMPLATE (ghostpad) = GST_PAD_PADTEMPLATE (pad);
2062 /* add ourselves to the real pad's list of ghostpads */
2063 gst_pad_add_ghost_pad (pad, GST_PAD (ghostpad));
2065 /* FIXME need to ref the real pad here... ? */
2067 GST_DEBUG (GST_CAT_PADS, "created ghost pad \"%s\"\n", name);
2069 return GST_PAD (ghostpad);
2073 gst_pad_event_default_dispatch (GstPad *pad, GstElement *element, GstEvent *event)
2075 GList *pads = element->pads;
2078 GstPad *eventpad = GST_PAD (pads->data);
2079 pads = g_list_next (pads);
2081 /* for all pads in the opposite direction that are connected */
2082 if (GST_PAD_DIRECTION (eventpad) != GST_PAD_DIRECTION (pad) && GST_PAD_IS_CONNECTED (eventpad)) {
2083 if (GST_PAD_DIRECTION (eventpad) == GST_PAD_SRC) {
2084 gst_pad_push (eventpad, GST_BUFFER (gst_event_new (GST_EVENT_TYPE (event))));
2088 GstPad *peerpad = GST_PAD_CAST (GST_RPAD_PEER (eventpad));
2090 gst_pad_send_event (peerpad, gst_event_new (GST_EVENT_TYPE (event)));
2097 * gst_pad_event_default:
2098 * @pad: the pad to operate on
2099 * @event: the event to handle
2101 * Invoke the default event handler for the given pad.
2104 gst_pad_event_default (GstPad *pad, GstEvent *event)
2106 GstElement *element = GST_PAD_PARENT (pad);
2108 g_signal_emit (G_OBJECT (pad), gst_real_pad_signals[REAL_EVENT_RECEIVED], 0, event);
2110 switch (GST_EVENT_TYPE (event)) {
2112 gst_element_set_eos (element);
2113 gst_pad_event_default_dispatch (pad, element, event);
2114 gst_event_free (event);
2115 /* we have to try to schedule another element because this one is disabled */
2116 gst_element_yield (element);
2118 case GST_EVENT_FLUSH:
2120 gst_pad_event_default_dispatch (pad, element, event);
2121 gst_event_free (event);
2127 * gst_pad_send_event:
2128 * @pad: the pad to send the event to
2129 * @event: the event to send to the pad.
2131 * Send the event to the pad.
2133 * Returns: TRUE if the event was handled.
2136 gst_pad_send_event (GstPad *pad, GstEvent *event)
2138 gboolean handled = FALSE;
2140 g_return_val_if_fail (event, FALSE);
2142 if (GST_EVENT_SRC (event) == NULL)
2143 GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (pad));
2145 GST_DEBUG (GST_CAT_EVENT, "have event %d on pad %s:%s\n",
2146 GST_EVENT_TYPE (event), GST_DEBUG_PAD_NAME (pad));
2148 if (GST_RPAD_EVENTFUNC (pad))
2149 handled = GST_RPAD_EVENTFUNC (pad) (pad, event);
2151 GST_DEBUG(GST_CAT_EVENT, "there's no event function for pad %s:%s\n", GST_DEBUG_PAD_NAME (pad));
2155 GST_DEBUG(GST_CAT_EVENT, "proceeding with default event behavior here\n");
2156 gst_pad_event_default (pad, event);