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., 51 Franklin St, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
28 * @short_description: Pseudo link pads
31 * GhostPads are useful when organizing pipelines with #GstBin like elements.
32 * The idea here is to create hierarchical element graphs. The bin element
33 * contains a sub-graph. Now one would like to treat the bin-element like any
34 * other #GstElement. This is where GhostPads come into play. A GhostPad acts as
35 * a proxy for another pad. Thus the bin can have sink and source ghost-pads
36 * that are associated with sink and source pads of the child elements.
38 * If the target pad is known at creation time, gst_ghost_pad_new() is the
39 * function to use to get a ghost-pad. Otherwise one can use gst_ghost_pad_new_no_target()
40 * to create the ghost-pad and use gst_ghost_pad_set_target() to establish the
41 * association later on.
43 * Note that GhostPads add overhead to the data processing of a pipeline.
46 #include "gst_private.h"
49 #include "gstghostpad.h"
52 #define GST_CAT_DEFAULT GST_CAT_PADS
54 #define GST_PROXY_PAD_CAST(obj) ((GstProxyPad *)obj)
55 #define GST_PROXY_PAD_PRIVATE(obj) (GST_PROXY_PAD_CAST (obj)->priv)
56 #define GST_PROXY_PAD_TARGET(pad) (GST_PAD_PEER (GST_PROXY_PAD_INTERNAL (pad)))
57 #define GST_PROXY_PAD_INTERNAL(pad) (GST_PROXY_PAD_PRIVATE (pad)->internal)
59 #define GST_PROXY_PAD_ACQUIRE_INTERNAL(pad, internal, retval) \
61 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD_CAST (pad))); \
62 if (internal == NULL) \
65 #define GST_PROXY_PAD_RELEASE_INTERNAL(internal) gst_object_unref (internal);
67 struct _GstProxyPadPrivate
72 G_DEFINE_TYPE_WITH_PRIVATE (GstProxyPad, gst_proxy_pad, GST_TYPE_PAD);
74 static GstPad *gst_proxy_pad_get_target (GstPad * pad);
77 * gst_proxy_pad_iterate_internal_links_default:
78 * @pad: the #GstPad to get the internal links of.
79 * @parent: (allow-none): the parent of @pad or %NULL
81 * Invoke the default iterate internal links function of the proxy pad.
83 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
84 * has no parent. Unref each returned pad with gst_object_unref().
87 gst_proxy_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
89 GstIterator *res = NULL;
93 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
95 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, NULL);
97 g_value_init (&v, GST_TYPE_PAD);
98 g_value_take_object (&v, internal);
99 res = gst_iterator_new_single (GST_TYPE_PAD, &v);
106 * gst_proxy_pad_chain_default:
107 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
108 * @parent: (allow-none): the parent of @pad or %NULL
109 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
112 * Invoke the default chain function of the proxy pad.
114 * Returns: a #GstFlowReturn from the pad.
117 gst_proxy_pad_chain_default (GstPad * pad, GstObject * parent,
123 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
124 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
126 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
127 res = gst_pad_push (internal, buffer);
128 GST_PROXY_PAD_RELEASE_INTERNAL (internal);
134 * gst_proxy_pad_chain_list_default:
135 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
136 * @parent: (allow-none): the parent of @pad or %NULL
137 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
140 * Invoke the default chain list function of the proxy pad.
142 * Returns: a #GstFlowReturn from the pad.
145 gst_proxy_pad_chain_list_default (GstPad * pad, GstObject * parent,
146 GstBufferList * list)
151 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
152 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
154 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
155 res = gst_pad_push_list (internal, list);
156 GST_PROXY_PAD_RELEASE_INTERNAL (internal);
162 * gst_proxy_pad_getrange_default:
163 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
164 * @parent: the parent of @pad
165 * @offset: The start offset of the buffer
166 * @size: The length of the buffer
167 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
168 * returns #GST_FLOW_ERROR if %NULL.
170 * Invoke the default getrange function of the proxy pad.
172 * Returns: a #GstFlowReturn from the pad.
175 gst_proxy_pad_getrange_default (GstPad * pad, GstObject * parent,
176 guint64 offset, guint size, GstBuffer ** buffer)
181 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
182 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
184 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
185 res = gst_pad_pull_range (internal, offset, size, buffer);
186 GST_PROXY_PAD_RELEASE_INTERNAL (internal);
192 gst_proxy_pad_get_target (GstPad * pad)
196 GST_OBJECT_LOCK (pad);
197 target = gst_pad_get_peer (GST_PROXY_PAD_INTERNAL (pad));
198 GST_OBJECT_UNLOCK (pad);
204 * gst_proxy_pad_get_internal:
205 * @pad: the #GstProxyPad
207 * Get the internal pad of @pad. Unref target pad after usage.
209 * The internal pad of a #GstGhostPad is the internally used
210 * pad of opposite direction, which is used to link to the target.
212 * Returns: (transfer full) (nullable): the target #GstProxyPad, can
213 * be %NULL. Unref target pad after usage.
216 gst_proxy_pad_get_internal (GstProxyPad * pad)
220 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
222 GST_OBJECT_LOCK (pad);
223 internal = GST_PROXY_PAD_INTERNAL (pad);
225 gst_object_ref (internal);
226 GST_OBJECT_UNLOCK (pad);
228 return GST_PROXY_PAD_CAST (internal);
232 gst_proxy_pad_class_init (GstProxyPadClass * klass)
234 /* Register common function pointer descriptions */
235 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_iterate_internal_links_default);
236 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_default);
237 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_list_default);
238 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getrange_default);
242 gst_proxy_pad_init (GstProxyPad * ppad)
244 GstPad *pad = (GstPad *) ppad;
246 GST_PROXY_PAD_PRIVATE (ppad) = gst_proxy_pad_get_instance_private (ppad);
248 gst_pad_set_iterate_internal_links_function (pad,
249 gst_proxy_pad_iterate_internal_links_default);
251 GST_PAD_SET_PROXY_CAPS (pad);
252 GST_PAD_SET_PROXY_SCHEDULING (pad);
253 GST_PAD_SET_PROXY_ALLOCATION (pad);
257 /***********************************************************************
258 * Ghost pads, implemented as a pair of proxy pads (sort of)
260 G_DEFINE_TYPE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
262 static void gst_ghost_pad_dispose (GObject * object);
263 static void gst_ghost_pad_constructed (GObject * object);
266 gst_ghost_pad_internal_activate_push_default (GstPad * pad, GstObject * parent,
272 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, we're ok",
273 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
275 /* in both cases (SRC and SINK) we activate just the internal pad. The targets
276 * will be activated later (or already in case of a ghost sinkpad). */
277 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
278 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
279 GST_PROXY_PAD_RELEASE_INTERNAL (other);
285 gst_ghost_pad_internal_activate_pull_default (GstPad * pad, GstObject * parent,
291 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
292 GST_DEBUG_PAD_NAME (pad));
294 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
295 /* we are activated in pull mode by our peer element, which is a sinkpad
296 * that wants to operate in pull mode. This activation has to propagate
297 * upstream through the pipeline. We call the internal activation function,
298 * which will trigger gst_ghost_pad_activate_pull_default, which propagates even
299 * further upstream */
300 GST_LOG_OBJECT (pad, "pad is src, activate internal");
301 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
302 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
303 GST_PROXY_PAD_RELEASE_INTERNAL (other);
304 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
305 /* We are SINK, the ghostpad is SRC, we propagate the activation upstream
306 * since we hold a pointer to the upstream peer. */
307 GST_LOG_OBJECT (pad, "activating peer");
308 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
309 gst_object_unref (other);
311 /* this is failure, we can't activate pull if there is no peer */
312 GST_LOG_OBJECT (pad, "not src and no peer, failing");
315 GST_LOG_OBJECT (pad, "deactivating pull, with no peer - allowing");
323 * gst_ghost_pad_internal_activate_mode_default:
324 * @pad: the #GstPad to activate or deactivate.
325 * @parent: (allow-none): the parent of @pad or %NULL
326 * @mode: the requested activation mode
327 * @active: whether the pad should be active or not.
329 * Invoke the default activate mode function of a proxy pad that is
330 * owned by a ghost pad.
332 * Returns: %TRUE if the operation was successful.
335 gst_ghost_pad_internal_activate_mode_default (GstPad * pad, GstObject * parent,
336 GstPadMode mode, gboolean active)
340 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
343 case GST_PAD_MODE_PULL:
344 res = gst_ghost_pad_internal_activate_pull_default (pad, parent, active);
346 case GST_PAD_MODE_PUSH:
347 res = gst_ghost_pad_internal_activate_push_default (pad, parent, active);
350 GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
358 gst_ghost_pad_activate_push_default (GstPad * pad, GstObject * parent,
364 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
366 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, proxy internal",
367 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
369 /* just activate the internal pad */
370 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
371 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
372 GST_PROXY_PAD_RELEASE_INTERNAL (other);
378 gst_ghost_pad_activate_pull_default (GstPad * pad, GstObject * parent,
384 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
385 GST_DEBUG_PAD_NAME (pad));
387 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
388 /* the ghostpad is SRC and activated in pull mode by its peer, call the
389 * activation function of the internal pad to propagate the activation
391 GST_LOG_OBJECT (pad, "pad is src, activate internal");
392 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
393 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
394 GST_PROXY_PAD_RELEASE_INTERNAL (other);
395 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
396 /* We are SINK and activated by the internal pad, propagate activation
397 * upstream because we hold a ref to the upstream peer */
398 GST_LOG_OBJECT (pad, "activating peer");
399 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
400 gst_object_unref (other);
402 /* this is failure, we can't activate pull if there is no peer */
403 GST_LOG_OBJECT (pad, "not src and no peer, failing");
406 GST_LOG_OBJECT (pad, "deactivating pull, with no peer - allowing");
414 * gst_ghost_pad_activate_mode_default:
415 * @pad: the #GstPad to activate or deactivate.
416 * @parent: (allow-none): the parent of @pad or %NULL
417 * @mode: the requested activation mode
418 * @active: whether the pad should be active or not.
420 * Invoke the default activate mode function of a ghost pad.
422 * Returns: %TRUE if the operation was successful.
425 gst_ghost_pad_activate_mode_default (GstPad * pad, GstObject * parent,
426 GstPadMode mode, gboolean active)
430 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
433 case GST_PAD_MODE_PULL:
434 res = gst_ghost_pad_activate_pull_default (pad, parent, active);
436 case GST_PAD_MODE_PUSH:
437 res = gst_ghost_pad_activate_push_default (pad, parent, active);
440 GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
448 gst_ghost_pad_class_init (GstGhostPadClass * klass)
450 GObjectClass *gobject_class = (GObjectClass *) klass;
452 gobject_class->dispose = gst_ghost_pad_dispose;
453 gobject_class->constructed = gst_ghost_pad_constructed;
455 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_pull_default);
456 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_push_default);
460 gst_ghost_pad_init (GstGhostPad * pad)
462 gst_pad_set_activatemode_function (GST_PAD_CAST (pad),
463 gst_ghost_pad_activate_mode_default);
467 gst_ghost_pad_dispose (GObject * object)
473 pad = GST_PAD (object);
475 GST_DEBUG_OBJECT (pad, "dispose");
477 gst_ghost_pad_set_target (GST_GHOST_PAD (pad), NULL);
479 /* Unlink here so that gst_pad_dispose doesn't. That would lead to a call to
480 * gst_ghost_pad_unlink_default when the ghost pad is in an inconsistent state */
481 peer = gst_pad_get_peer (pad);
483 if (GST_PAD_IS_SRC (pad))
484 gst_pad_unlink (pad, peer);
486 gst_pad_unlink (peer, pad);
488 gst_object_unref (peer);
491 GST_OBJECT_LOCK (pad);
492 internal = GST_PROXY_PAD_INTERNAL (pad);
494 gst_pad_set_activatemode_function (internal, NULL);
496 GST_PROXY_PAD_INTERNAL (pad) = NULL;
497 GST_PROXY_PAD_INTERNAL (internal) = NULL;
499 /* disposes of the internal pad, since the ghostpad is the only possible object
500 * that has a refcount on the internal pad. */
501 gst_object_unparent (GST_OBJECT_CAST (internal));
504 GST_OBJECT_UNLOCK (pad);
506 G_OBJECT_CLASS (gst_ghost_pad_parent_class)->dispose (object);
510 gst_ghost_pad_constructed (GObject * object)
512 GstGhostPad *gpad = GST_GHOST_PAD (object);
513 GstPadDirection dir, otherdir;
514 GstPadTemplate *templ;
515 GstPad *pad, *internal;
517 G_OBJECT_CLASS (gst_ghost_pad_parent_class)->constructed (object);
519 g_object_get (gpad, "direction", &dir, "template", &templ, NULL);
521 g_return_if_fail (dir != GST_PAD_UNKNOWN);
523 pad = GST_PAD (gpad);
525 /* Set directional padfunctions for ghostpad */
526 if (dir == GST_PAD_SINK) {
527 gst_pad_set_chain_function (pad, gst_proxy_pad_chain_default);
528 gst_pad_set_chain_list_function (pad, gst_proxy_pad_chain_list_default);
530 gst_pad_set_getrange_function (pad, gst_proxy_pad_getrange_default);
533 /* INTERNAL PAD, it always exists and is child of the ghostpad */
534 otherdir = (dir == GST_PAD_SRC) ? GST_PAD_SINK : GST_PAD_SRC;
537 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
538 "direction", otherdir, "template", templ, NULL);
539 /* release ref obtained via g_object_get */
540 gst_object_unref (templ);
543 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
544 "direction", otherdir, NULL);
546 GST_PAD_UNSET_FLUSHING (internal);
548 /* Set directional padfunctions for internal pad */
549 if (dir == GST_PAD_SRC) {
550 gst_pad_set_chain_function (internal, gst_proxy_pad_chain_default);
551 gst_pad_set_chain_list_function (internal,
552 gst_proxy_pad_chain_list_default);
554 gst_pad_set_getrange_function (internal, gst_proxy_pad_getrange_default);
557 /* now make the ghostpad a parent of the internal pad */
558 gst_object_set_parent (GST_OBJECT_CAST (internal), GST_OBJECT_CAST (pad));
560 /* The ghostpad is the parent of the internal pad and is the only object that
561 * can have a refcount on the internal pad.
562 * At this point, the GstGhostPad has a refcount of 1, and the internal pad has
564 * When the refcount of the GstGhostPad drops to 0, the ghostpad will dispose
565 * its refcount on the internal pad in the dispose method by un-parenting it.
566 * This is why we don't take extra refcounts in the assignments below
568 GST_PROXY_PAD_INTERNAL (pad) = internal;
569 GST_PROXY_PAD_INTERNAL (internal) = pad;
571 /* special activation functions for the internal pad */
572 gst_pad_set_activatemode_function (internal,
573 gst_ghost_pad_internal_activate_mode_default);
576 #ifndef GST_REMOVE_DEPRECATED
578 * gst_ghost_pad_construct:
579 * @gpad: the newly allocated ghost pad
581 * Finish initialization of a newly allocated ghost pad.
583 * This function is most useful in language bindings and when subclassing
584 * #GstGhostPad; plugin and application developers normally will not call this
585 * function. Call this function directly after a call to g_object_new
586 * (GST_TYPE_GHOST_PAD, "direction", @dir, ..., NULL).
588 * Deprecated: This function is deprecated since 1.18 and does nothing
591 * Returns: %TRUE if the construction succeeds, %FALSE otherwise.
594 gst_ghost_pad_construct (GstGhostPad * gpad)
601 gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
602 GstPadTemplate * templ)
605 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
607 /* OBJECT CREATION */
610 GST_PAD_TEMPLATE_GTYPE (templ) ==
611 G_TYPE_NONE ? GST_TYPE_GHOST_PAD : GST_PAD_TEMPLATE_GTYPE (templ);
613 g_return_val_if_fail (g_type_is_a (pad_type, GST_TYPE_GHOST_PAD), NULL);
615 ret = g_object_new (pad_type, "name", name,
616 "direction", dir, "template", templ, NULL);
618 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
619 "direction", dir, NULL);
622 return GST_PAD_CAST (ret);
626 * gst_ghost_pad_new_no_target:
627 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name.
628 * @dir: the direction of the ghostpad
630 * Create a new ghostpad without a target with the given direction.
631 * A target can be set on the ghostpad later with the
632 * gst_ghost_pad_set_target() function.
634 * The created ghostpad will not have a padtemplate.
636 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
640 gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
644 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
646 GST_LOG ("name:%s, direction:%d", GST_STR_NULL (name), dir);
648 ret = gst_ghost_pad_new_full (name, dir, NULL);
655 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name
656 * @target: (transfer none): the pad to ghost.
658 * Create a new ghostpad with @target as the target. The direction will be taken
659 * from the target pad. @target must be unlinked.
661 * Will ref the target.
663 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
667 gst_ghost_pad_new (const gchar * name, GstPad * target)
671 g_return_val_if_fail (GST_IS_PAD (target), NULL);
672 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
674 GST_LOG ("name:%s, target:%s:%s", GST_STR_NULL (name),
675 GST_DEBUG_PAD_NAME (target));
677 if ((ret = gst_ghost_pad_new_no_target (name, GST_PAD_DIRECTION (target))))
678 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
679 goto set_target_failed;
686 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
687 GST_DEBUG_PAD_NAME (target));
688 gst_object_unref (ret);
694 * gst_ghost_pad_new_from_template:
695 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name.
696 * @target: (transfer none): the pad to ghost.
697 * @templ: (transfer none): the #GstPadTemplate to use on the ghostpad.
699 * Create a new ghostpad with @target as the target. The direction will be taken
700 * from the target pad. The template used on the ghostpad will be @template.
702 * Will ref the target.
704 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
709 gst_ghost_pad_new_from_template (const gchar * name, GstPad * target,
710 GstPadTemplate * templ)
714 g_return_val_if_fail (GST_IS_PAD (target), NULL);
715 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
716 g_return_val_if_fail (templ != NULL, NULL);
717 g_return_val_if_fail (GST_PAD_TEMPLATE_DIRECTION (templ) ==
718 GST_PAD_DIRECTION (target), NULL);
720 GST_LOG ("name:%s, target:%s:%s, templ:%p", GST_STR_NULL (name),
721 GST_DEBUG_PAD_NAME (target), templ);
723 if ((ret = gst_ghost_pad_new_full (name, GST_PAD_DIRECTION (target), templ)))
724 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
725 goto set_target_failed;
732 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
733 GST_DEBUG_PAD_NAME (target));
734 gst_object_unref (ret);
740 * gst_ghost_pad_new_no_target_from_template:
741 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name
742 * @templ: (transfer none): the #GstPadTemplate to create the ghostpad from.
744 * Create a new ghostpad based on @templ, without setting a target. The
745 * direction will be taken from the @templ.
747 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
751 gst_ghost_pad_new_no_target_from_template (const gchar * name,
752 GstPadTemplate * templ)
756 g_return_val_if_fail (templ != NULL, NULL);
759 gst_ghost_pad_new_full (name, GST_PAD_TEMPLATE_DIRECTION (templ), templ);
765 * gst_ghost_pad_get_target:
766 * @gpad: the #GstGhostPad
768 * Get the target pad of @gpad. Unref target pad after usage.
770 * Returns: (transfer full) (nullable): the target #GstPad, can be
771 * %NULL if the ghostpad has no target set. Unref target pad after
775 gst_ghost_pad_get_target (GstGhostPad * gpad)
779 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), NULL);
781 ret = gst_proxy_pad_get_target (GST_PAD_CAST (gpad));
783 GST_DEBUG_OBJECT (gpad, "get target %s:%s", GST_DEBUG_PAD_NAME (ret));
789 * gst_ghost_pad_set_target:
790 * @gpad: the #GstGhostPad
791 * @newtarget: (transfer none) (allow-none): the new pad target
793 * Set the new target of the ghostpad @gpad. Any existing target
794 * is unlinked and links to the new target are established. if @newtarget is
795 * %NULL the target will be cleared.
797 * Returns: %TRUE if the new target could be set. This function
798 * can return %FALSE when the internal pads could not be linked.
801 gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
805 GstPadLinkReturn lret;
807 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
808 g_return_val_if_fail (GST_PAD_CAST (gpad) != newtarget, FALSE);
810 GST_OBJECT_LOCK (gpad);
811 internal = GST_PROXY_PAD_INTERNAL (gpad);
813 if (newtarget == internal) {
814 GST_OBJECT_UNLOCK (gpad);
815 GST_WARNING_OBJECT (gpad, "Target has already been set to %s:%s",
816 GST_DEBUG_PAD_NAME (newtarget));
821 GST_DEBUG_OBJECT (gpad, "set target %s:%s", GST_DEBUG_PAD_NAME (newtarget));
823 GST_DEBUG_OBJECT (gpad, "clearing target");
825 /* clear old target */
826 if ((oldtarget = gst_pad_get_peer (internal))) {
827 GST_OBJECT_UNLOCK (gpad);
829 /* unlink internal pad */
830 if (GST_PAD_IS_SRC (internal))
831 gst_pad_unlink (internal, oldtarget);
833 gst_pad_unlink (oldtarget, internal);
835 gst_object_unref (oldtarget);
837 GST_OBJECT_UNLOCK (gpad);
841 /* and link to internal pad without any checks */
842 GST_DEBUG_OBJECT (gpad, "connecting internal pad to target %"
843 GST_PTR_FORMAT, newtarget);
845 if (GST_PAD_IS_SRC (internal))
847 gst_pad_link_full (internal, newtarget, GST_PAD_LINK_CHECK_NOTHING);
850 gst_pad_link_full (newtarget, internal, GST_PAD_LINK_CHECK_NOTHING);
852 if (lret != GST_PAD_LINK_OK)
861 GST_WARNING_OBJECT (gpad, "could not link internal and target, reason:%s",
862 gst_pad_link_get_name (lret));