2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2005 Andy Wingo <wingo@pobox.com>
5 * 2006 Edward Hervey <bilboed@bilboed.com>
7 * gstghostpad.c: Proxy pads
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
27 * @short_description: Pseudo link pads
30 * GhostPads are useful when organizing pipelines with #GstBin like elements.
31 * The idea here is to create hierarchical element graphs. The bin element
32 * contains a sub-graph. Now one would like to treat the bin-element like any
33 * other #GstElement. This is where GhostPads come into play. A GhostPad acts as
34 * a proxy for another pad. Thus the bin can have sink and source ghost-pads
35 * that are associated with sink and source pads of the child elements.
37 * If the target pad is known at creation time, gst_ghost_pad_new() is the
38 * function to use to get a ghost-pad. Otherwise one can use gst_ghost_pad_new_no_target()
39 * to create the ghost-pad and use gst_ghost_pad_set_target() to establish the
40 * association later on.
42 * Note that GhostPads add overhead to the data processing of a pipeline.
44 * Last reviewed on 2005-11-18 (0.9.5)
47 #include "gst_private.h"
50 #include "gstghostpad.h"
53 #define GST_CAT_DEFAULT GST_CAT_PADS
55 #define GST_PROXY_PAD_CAST(obj) ((GstProxyPad *)obj)
56 #define GST_PROXY_PAD_PRIVATE(obj) (GST_PROXY_PAD_CAST (obj)->priv)
57 #define GST_PROXY_PAD_TARGET(pad) (GST_PAD_PEER (GST_PROXY_PAD_INTERNAL (pad)))
58 #define GST_PROXY_PAD_INTERNAL(pad) (GST_PROXY_PAD_PRIVATE (pad)->internal)
60 struct _GstProxyPadPrivate
65 G_DEFINE_TYPE (GstProxyPad, gst_proxy_pad, GST_TYPE_PAD);
67 static GstPad *gst_proxy_pad_get_target (GstPad * pad);
70 * gst_proxy_pad_iterate_internal_links_default:
71 * @pad: the #GstPad to get the internal links of.
72 * @parent: the parent of @pad or NULL
74 * Invoke the default iterate internal links function of the proxy pad.
76 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
77 * returned pad with gst_object_unref().
80 gst_proxy_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
82 GstIterator *res = NULL;
86 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
88 internal = GST_PROXY_PAD_INTERNAL (pad);
89 g_value_init (&v, GST_TYPE_PAD);
90 g_value_set_object (&v, internal);
91 res = gst_iterator_new_single (GST_TYPE_PAD, &v);
98 * gst_proxy_pad_chain_default:
99 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
100 * @parent: the parent of @pad or NULL
101 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
104 * Invoke the default chain function of the proxy pad.
106 * Returns: a #GstFlowReturn from the pad.
109 gst_proxy_pad_chain_default (GstPad * pad, GstObject * parent,
115 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
116 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
118 internal = GST_PROXY_PAD_INTERNAL (pad);
119 res = gst_pad_push (internal, buffer);
125 * gst_proxy_pad_chain_list_default:
126 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
127 * @parent: the parent of @pad or NULL
128 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
131 * Invoke the default chain list function of the proxy pad.
133 * Returns: a #GstFlowReturn from the pad.
136 gst_proxy_pad_chain_list_default (GstPad * pad, GstObject * parent,
137 GstBufferList * list)
142 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
143 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
145 internal = GST_PROXY_PAD_INTERNAL (pad);
146 res = gst_pad_push_list (internal, list);
152 * gst_proxy_pad_getrange_default:
153 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
154 * @parent: the parent of @pad
155 * @offset: The start offset of the buffer
156 * @size: The length of the buffer
157 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
158 * returns #GST_FLOW_ERROR if %NULL.
160 * Invoke the default getrange function of the proxy pad.
162 * Returns: a #GstFlowReturn from the pad.
165 gst_proxy_pad_getrange_default (GstPad * pad, GstObject * parent,
166 guint64 offset, guint size, GstBuffer ** buffer)
171 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
172 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
174 internal = GST_PROXY_PAD_INTERNAL (pad);
175 res = gst_pad_pull_range (internal, offset, size, buffer);
181 gst_proxy_pad_get_target (GstPad * pad)
185 GST_OBJECT_LOCK (pad);
186 target = GST_PROXY_PAD_TARGET (pad);
188 gst_object_ref (target);
189 GST_OBJECT_UNLOCK (pad);
195 * gst_proxy_pad_get_internal:
196 * @pad: the #GstProxyPad
198 * Get the internal pad of @pad. Unref target pad after usage.
200 * The internal pad of a #GstGhostPad is the internally used
201 * pad of opposite direction, which is used to link to the target.
203 * Returns: (transfer full): the target #GstProxyPad, can be NULL.
204 * Unref target pad after usage.
207 gst_proxy_pad_get_internal (GstProxyPad * pad)
211 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
213 GST_OBJECT_LOCK (pad);
214 internal = GST_PROXY_PAD_INTERNAL (pad);
216 gst_object_ref (internal);
217 GST_OBJECT_UNLOCK (pad);
219 return GST_PROXY_PAD_CAST (internal);
223 gst_proxy_pad_class_init (GstProxyPadClass * klass)
225 g_type_class_add_private (klass, sizeof (GstProxyPadPrivate));
227 /* Register common function pointer descriptions */
228 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_iterate_internal_links_default);
229 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_default);
230 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_list_default);
231 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getrange_default);
235 gst_proxy_pad_init (GstProxyPad * ppad)
237 GstPad *pad = (GstPad *) ppad;
239 GST_PROXY_PAD_PRIVATE (ppad) = G_TYPE_INSTANCE_GET_PRIVATE (ppad,
240 GST_TYPE_PROXY_PAD, GstProxyPadPrivate);
242 gst_pad_set_iterate_internal_links_function (pad,
243 gst_proxy_pad_iterate_internal_links_default);
245 GST_PAD_SET_PROXY_CAPS (pad);
246 GST_PAD_SET_PROXY_SCHEDULING (pad);
247 GST_PAD_SET_PROXY_ALLOCATION (pad);
251 /***********************************************************************
252 * Ghost pads, implemented as a pair of proxy pads (sort of)
256 #define GST_GHOST_PAD_PRIVATE(obj) (GST_GHOST_PAD_CAST (obj)->priv)
258 struct _GstGhostPadPrivate
260 /* with PROXY_LOCK */
261 gboolean constructed;
264 G_DEFINE_TYPE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
266 static void gst_ghost_pad_dispose (GObject * object);
269 gst_ghost_pad_internal_activate_push_default (GstPad * pad, GstObject * parent,
275 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, we're ok",
276 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
278 /* in both cases (SRC and SINK) we activate just the internal pad. The targets
279 * will be activated later (or already in case of a ghost sinkpad). */
280 other = GST_PROXY_PAD_INTERNAL (pad);
281 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
287 gst_ghost_pad_internal_activate_pull_default (GstPad * pad, GstObject * parent,
293 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
294 GST_DEBUG_PAD_NAME (pad));
296 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
297 /* we are activated in pull mode by our peer element, which is a sinkpad
298 * that wants to operate in pull mode. This activation has to propagate
299 * upstream through the pipeline. We call the internal activation function,
300 * which will trigger gst_ghost_pad_activate_pull_default, which propagates even
301 * further upstream */
302 GST_LOG_OBJECT (pad, "pad is src, activate internal");
303 other = GST_PROXY_PAD_INTERNAL (pad);
304 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
305 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
306 /* We are SINK, the ghostpad is SRC, we propagate the activation upstream
307 * since we hold a pointer to the upstream peer. */
308 GST_LOG_OBJECT (pad, "activating peer");
309 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
310 gst_object_unref (other);
312 /* this is failure, we can't activate pull if there is no peer */
313 GST_LOG_OBJECT (pad, "not src and no peer, failing");
321 * gst_ghost_pad_internal_activate_mode_default:
322 * @pad: the #GstPad to activate or deactivate.
323 * @parent: the parent of @pad or NULL
324 * @mode: the requested activation mode
325 * @active: whether the pad should be active or not.
327 * Invoke the default activate mode function of a proxy pad that is
328 * owned by a ghost pad.
330 * Returns: %TRUE if the operation was successful.
333 gst_ghost_pad_internal_activate_mode_default (GstPad * pad, GstObject * parent,
334 GstPadMode mode, gboolean active)
338 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
341 case GST_PAD_MODE_PULL:
342 res = gst_ghost_pad_internal_activate_pull_default (pad, parent, active);
344 case GST_PAD_MODE_PUSH:
345 res = gst_ghost_pad_internal_activate_push_default (pad, parent, active);
348 GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
356 gst_ghost_pad_activate_push_default (GstPad * pad, GstObject * parent,
362 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
364 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, proxy internal",
365 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
367 /* just activate the internal pad */
368 other = GST_PROXY_PAD_INTERNAL (pad);
369 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
375 gst_ghost_pad_activate_pull_default (GstPad * pad, GstObject * parent,
381 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
382 GST_DEBUG_PAD_NAME (pad));
384 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
385 /* the ghostpad is SRC and activated in pull mode by its peer, call the
386 * activation function of the internal pad to propagate the activation
388 GST_LOG_OBJECT (pad, "pad is src, activate internal");
389 other = GST_PROXY_PAD_INTERNAL (pad);
390 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
391 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
392 /* We are SINK and activated by the internal pad, propagate activation
393 * upstream because we hold a ref to the upstream peer */
394 GST_LOG_OBJECT (pad, "activating peer");
395 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
396 gst_object_unref (other);
398 /* no peer, we fail */
399 GST_LOG_OBJECT (pad, "pad not src and no peer, failing");
407 * gst_ghost_pad_activate_mode_default:
408 * @pad: the #GstPad to activate or deactivate.
409 * @parent: the parent of @pad or NULL
410 * @mode: the requested activation mode
411 * @active: whether the pad should be active or not.
413 * Invoke the default activate mode function of a ghost pad.
415 * Returns: %TRUE if the operation was successful.
418 gst_ghost_pad_activate_mode_default (GstPad * pad, GstObject * parent,
419 GstPadMode mode, gboolean active)
423 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
426 case GST_PAD_MODE_PULL:
427 res = gst_ghost_pad_activate_pull_default (pad, parent, active);
429 case GST_PAD_MODE_PUSH:
430 res = gst_ghost_pad_activate_push_default (pad, parent, active);
433 GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
441 gst_ghost_pad_class_init (GstGhostPadClass * klass)
443 GObjectClass *gobject_class = (GObjectClass *) klass;
445 g_type_class_add_private (klass, sizeof (GstGhostPadPrivate));
447 gobject_class->dispose = gst_ghost_pad_dispose;
449 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_pull_default);
450 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_push_default);
454 gst_ghost_pad_init (GstGhostPad * pad)
456 GST_GHOST_PAD_PRIVATE (pad) = G_TYPE_INSTANCE_GET_PRIVATE (pad,
457 GST_TYPE_GHOST_PAD, GstGhostPadPrivate);
459 gst_pad_set_activatemode_function (GST_PAD_CAST (pad),
460 gst_ghost_pad_activate_mode_default);
464 gst_ghost_pad_dispose (GObject * object)
470 pad = GST_PAD (object);
472 GST_DEBUG_OBJECT (pad, "dispose");
474 gst_ghost_pad_set_target (GST_GHOST_PAD (pad), NULL);
476 /* Unlink here so that gst_pad_dispose doesn't. That would lead to a call to
477 * gst_ghost_pad_unlink_default when the ghost pad is in an inconsistent state */
478 peer = gst_pad_get_peer (pad);
480 if (GST_PAD_IS_SRC (pad))
481 gst_pad_unlink (pad, peer);
483 gst_pad_unlink (peer, pad);
485 gst_object_unref (peer);
488 GST_OBJECT_LOCK (pad);
489 internal = GST_PROXY_PAD_INTERNAL (pad);
491 gst_pad_set_activatemode_function (internal, NULL);
493 /* disposes of the internal pad, since the ghostpad is the only possible object
494 * that has a refcount on the internal pad. */
495 gst_object_unparent (GST_OBJECT_CAST (internal));
496 GST_PROXY_PAD_INTERNAL (pad) = NULL;
498 GST_OBJECT_UNLOCK (pad);
500 G_OBJECT_CLASS (gst_ghost_pad_parent_class)->dispose (object);
504 * gst_ghost_pad_construct:
505 * @gpad: the newly allocated ghost pad
507 * Finish initialization of a newly allocated ghost pad.
509 * This function is most useful in language bindings and when subclassing
510 * #GstGhostPad; plugin and application developers normally will not call this
511 * function. Call this function directly after a call to g_object_new
512 * (GST_TYPE_GHOST_PAD, "direction", @dir, ..., NULL).
514 * Returns: %TRUE if the construction succeeds, %FALSE otherwise.
517 gst_ghost_pad_construct (GstGhostPad * gpad)
519 GstPadDirection dir, otherdir;
520 GstPadTemplate *templ;
521 GstPad *pad, *internal;
523 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
524 g_return_val_if_fail (GST_GHOST_PAD_PRIVATE (gpad)->constructed == FALSE,
527 g_object_get (gpad, "direction", &dir, "template", &templ, NULL);
529 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, FALSE);
531 pad = GST_PAD (gpad);
533 /* Set directional padfunctions for ghostpad */
534 if (dir == GST_PAD_SINK) {
535 gst_pad_set_chain_function (pad, gst_proxy_pad_chain_default);
536 gst_pad_set_chain_list_function (pad, gst_proxy_pad_chain_list_default);
538 gst_pad_set_getrange_function (pad, gst_proxy_pad_getrange_default);
541 /* INTERNAL PAD, it always exists and is child of the ghostpad */
542 otherdir = (dir == GST_PAD_SRC) ? GST_PAD_SINK : GST_PAD_SRC;
545 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
546 "direction", otherdir, "template", templ, NULL);
547 /* release ref obtained via g_object_get */
548 gst_object_unref (templ);
551 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
552 "direction", otherdir, NULL);
554 GST_PAD_UNSET_FLUSHING (internal);
556 /* Set directional padfunctions for internal pad */
557 if (dir == GST_PAD_SRC) {
558 gst_pad_set_chain_function (internal, gst_proxy_pad_chain_default);
559 gst_pad_set_chain_list_function (internal,
560 gst_proxy_pad_chain_list_default);
562 gst_pad_set_getrange_function (internal, gst_proxy_pad_getrange_default);
565 GST_OBJECT_LOCK (pad);
567 /* now make the ghostpad a parent of the internal pad */
568 if (!gst_object_set_parent (GST_OBJECT_CAST (internal),
569 GST_OBJECT_CAST (pad)))
572 /* The ghostpad is the parent of the internal pad and is the only object that
573 * can have a refcount on the internal pad.
574 * At this point, the GstGhostPad has a refcount of 1, and the internal pad has
576 * When the refcount of the GstGhostPad drops to 0, the ghostpad will dispose
577 * its refcount on the internal pad in the dispose method by un-parenting it.
578 * This is why we don't take extra refcounts in the assignments below
580 GST_PROXY_PAD_INTERNAL (pad) = internal;
581 GST_PROXY_PAD_INTERNAL (internal) = pad;
583 /* special activation functions for the internal pad */
584 gst_pad_set_activatemode_function (internal,
585 gst_ghost_pad_internal_activate_mode_default);
587 GST_OBJECT_UNLOCK (pad);
589 GST_GHOST_PAD_PRIVATE (gpad)->constructed = TRUE;
595 GST_WARNING_OBJECT (gpad, "Could not set internal pad %s:%s",
596 GST_DEBUG_PAD_NAME (internal));
597 g_critical ("Could not set internal pad %s:%s",
598 GST_DEBUG_PAD_NAME (internal));
599 GST_OBJECT_UNLOCK (pad);
600 gst_object_unref (internal);
606 gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
607 GstPadTemplate * templ)
611 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
613 /* OBJECT CREATION */
615 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
616 "direction", dir, "template", templ, NULL);
618 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
619 "direction", dir, NULL);
622 if (!gst_ghost_pad_construct (ret))
623 goto construct_failed;
625 return GST_PAD_CAST (ret);
629 gst_object_unref (ret);
634 * gst_ghost_pad_new_no_target:
635 * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
636 * @dir: the direction of the ghostpad
638 * Create a new ghostpad without a target with the given direction.
639 * A target can be set on the ghostpad later with the
640 * gst_ghost_pad_set_target() function.
642 * The created ghostpad will not have a padtemplate.
644 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
647 gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
651 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
653 GST_LOG ("name:%s, direction:%d", GST_STR_NULL (name), dir);
655 ret = gst_ghost_pad_new_full (name, dir, NULL);
662 * @name: (allow-none): the name of the new pad, or NULL to assign a default name
663 * @target: (transfer none): the pad to ghost.
665 * Create a new ghostpad with @target as the target. The direction will be taken
666 * from the target pad. @target must be unlinked.
668 * Will ref the target.
670 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
673 gst_ghost_pad_new (const gchar * name, GstPad * target)
677 g_return_val_if_fail (GST_IS_PAD (target), NULL);
678 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
680 GST_LOG ("name:%s, target:%s:%s", GST_STR_NULL (name),
681 GST_DEBUG_PAD_NAME (target));
683 if ((ret = gst_ghost_pad_new_no_target (name, GST_PAD_DIRECTION (target))))
684 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
685 goto set_target_failed;
692 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
693 GST_DEBUG_PAD_NAME (target));
694 gst_object_unref (ret);
700 * gst_ghost_pad_new_from_template:
701 * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
702 * @target: (transfer none): the pad to ghost.
703 * @templ: (transfer none): the #GstPadTemplate to use on the ghostpad.
705 * Create a new ghostpad with @target as the target. The direction will be taken
706 * from the target pad. The template used on the ghostpad will be @template.
708 * Will ref the target.
710 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
714 gst_ghost_pad_new_from_template (const gchar * name, GstPad * target,
715 GstPadTemplate * templ)
719 g_return_val_if_fail (GST_IS_PAD (target), NULL);
720 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
721 g_return_val_if_fail (templ != NULL, NULL);
722 g_return_val_if_fail (GST_PAD_TEMPLATE_DIRECTION (templ) ==
723 GST_PAD_DIRECTION (target), NULL);
725 GST_LOG ("name:%s, target:%s:%s, templ:%p", GST_STR_NULL (name),
726 GST_DEBUG_PAD_NAME (target), templ);
728 if ((ret = gst_ghost_pad_new_full (name, GST_PAD_DIRECTION (target), templ)))
729 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
730 goto set_target_failed;
737 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
738 GST_DEBUG_PAD_NAME (target));
739 gst_object_unref (ret);
745 * gst_ghost_pad_new_no_target_from_template:
746 * @name: (allow-none): the name of the new pad, or NULL to assign a default name
747 * @templ: (transfer none): the #GstPadTemplate to create the ghostpad from.
749 * Create a new ghostpad based on @templ, without setting a target. The
750 * direction will be taken from the @templ.
752 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
755 gst_ghost_pad_new_no_target_from_template (const gchar * name,
756 GstPadTemplate * templ)
760 g_return_val_if_fail (templ != NULL, NULL);
763 gst_ghost_pad_new_full (name, GST_PAD_TEMPLATE_DIRECTION (templ), templ);
769 * gst_ghost_pad_get_target:
770 * @gpad: the #GstGhostPad
772 * Get the target pad of @gpad. Unref target pad after usage.
774 * Returns: (transfer full): the target #GstPad, can be NULL if the ghostpad
775 * has no target set. Unref target pad after usage.
778 gst_ghost_pad_get_target (GstGhostPad * gpad)
782 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), NULL);
784 ret = gst_proxy_pad_get_target (GST_PAD_CAST (gpad));
786 GST_DEBUG_OBJECT (gpad, "get target %s:%s", GST_DEBUG_PAD_NAME (ret));
792 * gst_ghost_pad_set_target:
793 * @gpad: the #GstGhostPad
794 * @newtarget: (transfer none) (allow-none): the new pad target
796 * Set the new target of the ghostpad @gpad. Any existing target
797 * is unlinked and links to the new target are established. if @newtarget is
798 * NULL the target will be cleared.
800 * Returns: (transfer full): TRUE if the new target could be set. This function
801 * can return FALSE when the internal pads could not be linked.
804 gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
808 GstPadLinkReturn lret;
810 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
811 g_return_val_if_fail (GST_PAD_CAST (gpad) != newtarget, FALSE);
812 g_return_val_if_fail (newtarget != GST_PROXY_PAD_INTERNAL (gpad), FALSE);
814 /* no need for locking, the internal pad's lifecycle is directly linked to the
816 internal = GST_PROXY_PAD_INTERNAL (gpad);
819 GST_DEBUG_OBJECT (gpad, "set target %s:%s", GST_DEBUG_PAD_NAME (newtarget));
821 GST_DEBUG_OBJECT (gpad, "clearing target");
823 /* clear old target */
824 GST_OBJECT_LOCK (gpad);
825 if ((oldtarget = GST_PROXY_PAD_TARGET (gpad))) {
826 GST_OBJECT_UNLOCK (gpad);
828 /* unlink internal pad */
829 if (GST_PAD_IS_SRC (internal))
830 gst_pad_unlink (internal, oldtarget);
832 gst_pad_unlink (oldtarget, internal);
834 GST_OBJECT_UNLOCK (gpad);
838 /* and link to internal pad without any checks */
839 GST_DEBUG_OBJECT (gpad, "connecting internal pad to target");
841 if (GST_PAD_IS_SRC (internal))
843 gst_pad_link_full (internal, newtarget, GST_PAD_LINK_CHECK_NOTHING);
846 gst_pad_link_full (newtarget, internal, GST_PAD_LINK_CHECK_NOTHING);
848 if (lret != GST_PAD_LINK_OK)
857 GST_WARNING_OBJECT (gpad, "could not link internal and target, reason:%d",