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)
262 #define GST_GHOST_PAD_PRIVATE(obj) (GST_GHOST_PAD_CAST (obj)->priv)
264 struct _GstGhostPadPrivate
266 /* with PROXY_LOCK */
267 gboolean constructed;
270 G_DEFINE_TYPE_WITH_PRIVATE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
272 static void gst_ghost_pad_dispose (GObject * object);
275 gst_ghost_pad_internal_activate_push_default (GstPad * pad, GstObject * parent,
281 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, we're ok",
282 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
284 /* in both cases (SRC and SINK) we activate just the internal pad. The targets
285 * will be activated later (or already in case of a ghost sinkpad). */
286 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
287 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
288 GST_PROXY_PAD_RELEASE_INTERNAL (other);
294 gst_ghost_pad_internal_activate_pull_default (GstPad * pad, GstObject * parent,
300 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
301 GST_DEBUG_PAD_NAME (pad));
303 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
304 /* we are activated in pull mode by our peer element, which is a sinkpad
305 * that wants to operate in pull mode. This activation has to propagate
306 * upstream through the pipeline. We call the internal activation function,
307 * which will trigger gst_ghost_pad_activate_pull_default, which propagates even
308 * further upstream */
309 GST_LOG_OBJECT (pad, "pad is src, activate internal");
310 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
311 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
312 GST_PROXY_PAD_RELEASE_INTERNAL (other);
313 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
314 /* We are SINK, the ghostpad is SRC, we propagate the activation upstream
315 * since we hold a pointer to the upstream peer. */
316 GST_LOG_OBJECT (pad, "activating peer");
317 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
318 gst_object_unref (other);
320 /* this is failure, we can't activate pull if there is no peer */
321 GST_LOG_OBJECT (pad, "not src and no peer, failing");
324 GST_LOG_OBJECT (pad, "deactivating pull, with no peer - allowing");
332 * gst_ghost_pad_internal_activate_mode_default:
333 * @pad: the #GstPad to activate or deactivate.
334 * @parent: (allow-none): the parent of @pad or %NULL
335 * @mode: the requested activation mode
336 * @active: whether the pad should be active or not.
338 * Invoke the default activate mode function of a proxy pad that is
339 * owned by a ghost pad.
341 * Returns: %TRUE if the operation was successful.
344 gst_ghost_pad_internal_activate_mode_default (GstPad * pad, GstObject * parent,
345 GstPadMode mode, gboolean active)
349 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
352 case GST_PAD_MODE_PULL:
353 res = gst_ghost_pad_internal_activate_pull_default (pad, parent, active);
355 case GST_PAD_MODE_PUSH:
356 res = gst_ghost_pad_internal_activate_push_default (pad, parent, active);
359 GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
367 gst_ghost_pad_activate_push_default (GstPad * pad, GstObject * parent,
373 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
375 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, proxy internal",
376 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
378 /* just activate the internal pad */
379 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
380 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
381 GST_PROXY_PAD_RELEASE_INTERNAL (other);
387 gst_ghost_pad_activate_pull_default (GstPad * pad, GstObject * parent,
393 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
394 GST_DEBUG_PAD_NAME (pad));
396 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
397 /* the ghostpad is SRC and activated in pull mode by its peer, call the
398 * activation function of the internal pad to propagate the activation
400 GST_LOG_OBJECT (pad, "pad is src, activate internal");
401 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
402 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
403 GST_PROXY_PAD_RELEASE_INTERNAL (other);
404 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
405 /* We are SINK and activated by the internal pad, propagate activation
406 * upstream because we hold a ref to the upstream peer */
407 GST_LOG_OBJECT (pad, "activating peer");
408 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
409 gst_object_unref (other);
411 /* this is failure, we can't activate pull if there is no peer */
412 GST_LOG_OBJECT (pad, "not src and no peer, failing");
415 GST_LOG_OBJECT (pad, "deactivating pull, with no peer - allowing");
423 * gst_ghost_pad_activate_mode_default:
424 * @pad: the #GstPad to activate or deactivate.
425 * @parent: (allow-none): the parent of @pad or %NULL
426 * @mode: the requested activation mode
427 * @active: whether the pad should be active or not.
429 * Invoke the default activate mode function of a ghost pad.
431 * Returns: %TRUE if the operation was successful.
434 gst_ghost_pad_activate_mode_default (GstPad * pad, GstObject * parent,
435 GstPadMode mode, gboolean active)
439 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
442 case GST_PAD_MODE_PULL:
443 res = gst_ghost_pad_activate_pull_default (pad, parent, active);
445 case GST_PAD_MODE_PUSH:
446 res = gst_ghost_pad_activate_push_default (pad, parent, active);
449 GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
457 gst_ghost_pad_class_init (GstGhostPadClass * klass)
459 GObjectClass *gobject_class = (GObjectClass *) klass;
461 gobject_class->dispose = gst_ghost_pad_dispose;
463 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_pull_default);
464 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_push_default);
468 gst_ghost_pad_init (GstGhostPad * pad)
470 GST_GHOST_PAD_PRIVATE (pad) = gst_ghost_pad_get_instance_private (pad);
472 gst_pad_set_activatemode_function (GST_PAD_CAST (pad),
473 gst_ghost_pad_activate_mode_default);
477 gst_ghost_pad_dispose (GObject * object)
483 pad = GST_PAD (object);
485 GST_DEBUG_OBJECT (pad, "dispose");
487 gst_ghost_pad_set_target (GST_GHOST_PAD (pad), NULL);
489 /* Unlink here so that gst_pad_dispose doesn't. That would lead to a call to
490 * gst_ghost_pad_unlink_default when the ghost pad is in an inconsistent state */
491 peer = gst_pad_get_peer (pad);
493 if (GST_PAD_IS_SRC (pad))
494 gst_pad_unlink (pad, peer);
496 gst_pad_unlink (peer, pad);
498 gst_object_unref (peer);
501 GST_OBJECT_LOCK (pad);
502 internal = GST_PROXY_PAD_INTERNAL (pad);
504 gst_pad_set_activatemode_function (internal, NULL);
506 GST_PROXY_PAD_INTERNAL (pad) = NULL;
507 GST_PROXY_PAD_INTERNAL (internal) = NULL;
509 /* disposes of the internal pad, since the ghostpad is the only possible object
510 * that has a refcount on the internal pad. */
511 gst_object_unparent (GST_OBJECT_CAST (internal));
514 GST_OBJECT_UNLOCK (pad);
516 G_OBJECT_CLASS (gst_ghost_pad_parent_class)->dispose (object);
520 * gst_ghost_pad_construct:
521 * @gpad: the newly allocated ghost pad
523 * Finish initialization of a newly allocated ghost pad.
525 * This function is most useful in language bindings and when subclassing
526 * #GstGhostPad; plugin and application developers normally will not call this
527 * function. Call this function directly after a call to g_object_new
528 * (GST_TYPE_GHOST_PAD, "direction", @dir, ..., NULL).
530 * Returns: %TRUE if the construction succeeds, %FALSE otherwise.
533 gst_ghost_pad_construct (GstGhostPad * gpad)
535 GstPadDirection dir, otherdir;
536 GstPadTemplate *templ;
537 GstPad *pad, *internal;
539 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
540 g_return_val_if_fail (!GST_GHOST_PAD_PRIVATE (gpad)->constructed, FALSE);
542 g_object_get (gpad, "direction", &dir, "template", &templ, NULL);
544 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, FALSE);
546 pad = GST_PAD (gpad);
548 /* Set directional padfunctions for ghostpad */
549 if (dir == GST_PAD_SINK) {
550 gst_pad_set_chain_function (pad, gst_proxy_pad_chain_default);
551 gst_pad_set_chain_list_function (pad, gst_proxy_pad_chain_list_default);
553 gst_pad_set_getrange_function (pad, gst_proxy_pad_getrange_default);
556 /* INTERNAL PAD, it always exists and is child of the ghostpad */
557 otherdir = (dir == GST_PAD_SRC) ? GST_PAD_SINK : GST_PAD_SRC;
560 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
561 "direction", otherdir, "template", templ, NULL);
562 /* release ref obtained via g_object_get */
563 gst_object_unref (templ);
566 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
567 "direction", otherdir, NULL);
569 GST_PAD_UNSET_FLUSHING (internal);
571 /* Set directional padfunctions for internal pad */
572 if (dir == GST_PAD_SRC) {
573 gst_pad_set_chain_function (internal, gst_proxy_pad_chain_default);
574 gst_pad_set_chain_list_function (internal,
575 gst_proxy_pad_chain_list_default);
577 gst_pad_set_getrange_function (internal, gst_proxy_pad_getrange_default);
580 GST_OBJECT_LOCK (pad);
582 /* now make the ghostpad a parent of the internal pad */
583 if (!gst_object_set_parent (GST_OBJECT_CAST (internal),
584 GST_OBJECT_CAST (pad)))
587 /* The ghostpad is the parent of the internal pad and is the only object that
588 * can have a refcount on the internal pad.
589 * At this point, the GstGhostPad has a refcount of 1, and the internal pad has
591 * When the refcount of the GstGhostPad drops to 0, the ghostpad will dispose
592 * its refcount on the internal pad in the dispose method by un-parenting it.
593 * This is why we don't take extra refcounts in the assignments below
595 GST_PROXY_PAD_INTERNAL (pad) = internal;
596 GST_PROXY_PAD_INTERNAL (internal) = pad;
598 /* special activation functions for the internal pad */
599 gst_pad_set_activatemode_function (internal,
600 gst_ghost_pad_internal_activate_mode_default);
602 GST_OBJECT_UNLOCK (pad);
604 GST_GHOST_PAD_PRIVATE (gpad)->constructed = TRUE;
610 GST_WARNING_OBJECT (gpad, "Could not set internal pad %s:%s",
611 GST_DEBUG_PAD_NAME (internal));
612 g_critical ("Could not set internal pad %s:%s",
613 GST_DEBUG_PAD_NAME (internal));
614 GST_OBJECT_UNLOCK (pad);
620 gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
621 GstPadTemplate * templ)
624 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
626 /* OBJECT CREATION */
629 GST_PAD_TEMPLATE_GTYPE (templ) ==
630 G_TYPE_NONE ? GST_TYPE_GHOST_PAD : GST_PAD_TEMPLATE_GTYPE (templ);
632 g_return_val_if_fail (g_type_is_a (pad_type, GST_TYPE_GHOST_PAD), NULL);
634 ret = g_object_new (pad_type, "name", name,
635 "direction", dir, "template", templ, NULL);
637 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
638 "direction", dir, NULL);
641 if (!gst_ghost_pad_construct (ret))
642 goto construct_failed;
644 return GST_PAD_CAST (ret);
648 gst_object_unref (ret);
653 * gst_ghost_pad_new_no_target:
654 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name.
655 * @dir: the direction of the ghostpad
657 * Create a new ghostpad without a target with the given direction.
658 * A target can be set on the ghostpad later with the
659 * gst_ghost_pad_set_target() function.
661 * The created ghostpad will not have a padtemplate.
663 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
667 gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
671 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
673 GST_LOG ("name:%s, direction:%d", GST_STR_NULL (name), dir);
675 ret = gst_ghost_pad_new_full (name, dir, NULL);
682 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name
683 * @target: (transfer none): the pad to ghost.
685 * Create a new ghostpad with @target as the target. The direction will be taken
686 * from the target pad. @target must be unlinked.
688 * Will ref the target.
690 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
694 gst_ghost_pad_new (const gchar * name, GstPad * target)
698 g_return_val_if_fail (GST_IS_PAD (target), NULL);
699 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
701 GST_LOG ("name:%s, target:%s:%s", GST_STR_NULL (name),
702 GST_DEBUG_PAD_NAME (target));
704 if ((ret = gst_ghost_pad_new_no_target (name, GST_PAD_DIRECTION (target))))
705 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
706 goto set_target_failed;
713 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
714 GST_DEBUG_PAD_NAME (target));
715 gst_object_unref (ret);
721 * gst_ghost_pad_new_from_template:
722 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name.
723 * @target: (transfer none): the pad to ghost.
724 * @templ: (transfer none): the #GstPadTemplate to use on the ghostpad.
726 * Create a new ghostpad with @target as the target. The direction will be taken
727 * from the target pad. The template used on the ghostpad will be @template.
729 * Will ref the target.
731 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
736 gst_ghost_pad_new_from_template (const gchar * name, GstPad * target,
737 GstPadTemplate * templ)
741 g_return_val_if_fail (GST_IS_PAD (target), NULL);
742 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
743 g_return_val_if_fail (templ != NULL, NULL);
744 g_return_val_if_fail (GST_PAD_TEMPLATE_DIRECTION (templ) ==
745 GST_PAD_DIRECTION (target), NULL);
747 GST_LOG ("name:%s, target:%s:%s, templ:%p", GST_STR_NULL (name),
748 GST_DEBUG_PAD_NAME (target), templ);
750 if ((ret = gst_ghost_pad_new_full (name, GST_PAD_DIRECTION (target), templ)))
751 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
752 goto set_target_failed;
759 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
760 GST_DEBUG_PAD_NAME (target));
761 gst_object_unref (ret);
767 * gst_ghost_pad_new_no_target_from_template:
768 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name
769 * @templ: (transfer none): the #GstPadTemplate to create the ghostpad from.
771 * Create a new ghostpad based on @templ, without setting a target. The
772 * direction will be taken from the @templ.
774 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
778 gst_ghost_pad_new_no_target_from_template (const gchar * name,
779 GstPadTemplate * templ)
783 g_return_val_if_fail (templ != NULL, NULL);
786 gst_ghost_pad_new_full (name, GST_PAD_TEMPLATE_DIRECTION (templ), templ);
792 * gst_ghost_pad_get_target:
793 * @gpad: the #GstGhostPad
795 * Get the target pad of @gpad. Unref target pad after usage.
797 * Returns: (transfer full) (nullable): the target #GstPad, can be
798 * %NULL if the ghostpad has no target set. Unref target pad after
802 gst_ghost_pad_get_target (GstGhostPad * gpad)
806 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), NULL);
808 ret = gst_proxy_pad_get_target (GST_PAD_CAST (gpad));
810 GST_DEBUG_OBJECT (gpad, "get target %s:%s", GST_DEBUG_PAD_NAME (ret));
816 * gst_ghost_pad_set_target:
817 * @gpad: the #GstGhostPad
818 * @newtarget: (transfer none) (allow-none): the new pad target
820 * Set the new target of the ghostpad @gpad. Any existing target
821 * is unlinked and links to the new target are established. if @newtarget is
822 * %NULL the target will be cleared.
824 * Returns: %TRUE if the new target could be set. This function
825 * can return %FALSE when the internal pads could not be linked.
828 gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
832 GstPadLinkReturn lret;
834 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
835 g_return_val_if_fail (GST_PAD_CAST (gpad) != newtarget, FALSE);
837 GST_OBJECT_LOCK (gpad);
838 internal = GST_PROXY_PAD_INTERNAL (gpad);
840 if (newtarget == internal) {
841 GST_OBJECT_UNLOCK (gpad);
842 GST_WARNING_OBJECT (gpad, "Target has already been set to %s:%s",
843 GST_DEBUG_PAD_NAME (newtarget));
848 GST_DEBUG_OBJECT (gpad, "set target %s:%s", GST_DEBUG_PAD_NAME (newtarget));
850 GST_DEBUG_OBJECT (gpad, "clearing target");
852 /* clear old target */
853 if ((oldtarget = gst_pad_get_peer (internal))) {
854 GST_OBJECT_UNLOCK (gpad);
856 /* unlink internal pad */
857 if (GST_PAD_IS_SRC (internal))
858 gst_pad_unlink (internal, oldtarget);
860 gst_pad_unlink (oldtarget, internal);
862 gst_object_unref (oldtarget);
864 GST_OBJECT_UNLOCK (gpad);
868 /* and link to internal pad without any checks */
869 GST_DEBUG_OBJECT (gpad, "connecting internal pad to target %"
870 GST_PTR_FORMAT, newtarget);
872 if (GST_PAD_IS_SRC (internal))
874 gst_pad_link_full (internal, newtarget, GST_PAD_LINK_CHECK_NOTHING);
877 gst_pad_link_full (newtarget, internal, GST_PAD_LINK_CHECK_NOTHING);
879 if (lret != GST_PAD_LINK_OK)
888 GST_WARNING_OBJECT (gpad, "could not link internal and target, reason:%s",
889 gst_pad_link_get_name (lret));