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 (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 g_type_class_add_private (klass, sizeof (GstProxyPadPrivate));
236 /* Register common function pointer descriptions */
237 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_iterate_internal_links_default);
238 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_default);
239 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_list_default);
240 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getrange_default);
244 gst_proxy_pad_init (GstProxyPad * ppad)
246 GstPad *pad = (GstPad *) ppad;
248 GST_PROXY_PAD_PRIVATE (ppad) = G_TYPE_INSTANCE_GET_PRIVATE (ppad,
249 GST_TYPE_PROXY_PAD, GstProxyPadPrivate);
251 gst_pad_set_iterate_internal_links_function (pad,
252 gst_proxy_pad_iterate_internal_links_default);
254 GST_PAD_SET_PROXY_CAPS (pad);
255 GST_PAD_SET_PROXY_SCHEDULING (pad);
256 GST_PAD_SET_PROXY_ALLOCATION (pad);
260 /***********************************************************************
261 * Ghost pads, implemented as a pair of proxy pads (sort of)
265 #define GST_GHOST_PAD_PRIVATE(obj) (GST_GHOST_PAD_CAST (obj)->priv)
267 struct _GstGhostPadPrivate
269 /* with PROXY_LOCK */
270 gboolean constructed;
273 G_DEFINE_TYPE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
275 static void gst_ghost_pad_dispose (GObject * object);
278 gst_ghost_pad_internal_activate_push_default (GstPad * pad, GstObject * parent,
284 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, we're ok",
285 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
287 /* in both cases (SRC and SINK) we activate just the internal pad. The targets
288 * will be activated later (or already in case of a ghost sinkpad). */
289 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
290 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
291 GST_PROXY_PAD_RELEASE_INTERNAL (other);
297 gst_ghost_pad_internal_activate_pull_default (GstPad * pad, GstObject * parent,
303 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
304 GST_DEBUG_PAD_NAME (pad));
306 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
307 /* we are activated in pull mode by our peer element, which is a sinkpad
308 * that wants to operate in pull mode. This activation has to propagate
309 * upstream through the pipeline. We call the internal activation function,
310 * which will trigger gst_ghost_pad_activate_pull_default, which propagates even
311 * further upstream */
312 GST_LOG_OBJECT (pad, "pad is src, activate internal");
313 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
314 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
315 GST_PROXY_PAD_RELEASE_INTERNAL (other);
316 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
317 /* We are SINK, the ghostpad is SRC, we propagate the activation upstream
318 * since we hold a pointer to the upstream peer. */
319 GST_LOG_OBJECT (pad, "activating peer");
320 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
321 gst_object_unref (other);
323 /* this is failure, we can't activate pull if there is no peer */
324 GST_LOG_OBJECT (pad, "not src and no peer, failing");
327 GST_LOG_OBJECT (pad, "deactivating pull, with no peer - allowing");
335 * gst_ghost_pad_internal_activate_mode_default:
336 * @pad: the #GstPad to activate or deactivate.
337 * @parent: (allow-none): the parent of @pad or %NULL
338 * @mode: the requested activation mode
339 * @active: whether the pad should be active or not.
341 * Invoke the default activate mode function of a proxy pad that is
342 * owned by a ghost pad.
344 * Returns: %TRUE if the operation was successful.
347 gst_ghost_pad_internal_activate_mode_default (GstPad * pad, GstObject * parent,
348 GstPadMode mode, gboolean active)
352 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
355 case GST_PAD_MODE_PULL:
356 res = gst_ghost_pad_internal_activate_pull_default (pad, parent, active);
358 case GST_PAD_MODE_PUSH:
359 res = gst_ghost_pad_internal_activate_push_default (pad, parent, active);
362 GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
370 gst_ghost_pad_activate_push_default (GstPad * pad, GstObject * parent,
376 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
378 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, proxy internal",
379 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
381 /* just activate the internal pad */
382 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
383 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
384 GST_PROXY_PAD_RELEASE_INTERNAL (other);
390 gst_ghost_pad_activate_pull_default (GstPad * pad, GstObject * parent,
396 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
397 GST_DEBUG_PAD_NAME (pad));
399 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
400 /* the ghostpad is SRC and activated in pull mode by its peer, call the
401 * activation function of the internal pad to propagate the activation
403 GST_LOG_OBJECT (pad, "pad is src, activate internal");
404 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
405 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
406 GST_PROXY_PAD_RELEASE_INTERNAL (other);
407 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
408 /* We are SINK and activated by the internal pad, propagate activation
409 * upstream because we hold a ref to the upstream peer */
410 GST_LOG_OBJECT (pad, "activating peer");
411 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
412 gst_object_unref (other);
414 /* this is failure, we can't activate pull if there is no peer */
415 GST_LOG_OBJECT (pad, "not src and no peer, failing");
418 GST_LOG_OBJECT (pad, "deactivating pull, with no peer - allowing");
426 * gst_ghost_pad_activate_mode_default:
427 * @pad: the #GstPad to activate or deactivate.
428 * @parent: (allow-none): the parent of @pad or %NULL
429 * @mode: the requested activation mode
430 * @active: whether the pad should be active or not.
432 * Invoke the default activate mode function of a ghost pad.
434 * Returns: %TRUE if the operation was successful.
437 gst_ghost_pad_activate_mode_default (GstPad * pad, GstObject * parent,
438 GstPadMode mode, gboolean active)
442 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
445 case GST_PAD_MODE_PULL:
446 res = gst_ghost_pad_activate_pull_default (pad, parent, active);
448 case GST_PAD_MODE_PUSH:
449 res = gst_ghost_pad_activate_push_default (pad, parent, active);
452 GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
460 gst_ghost_pad_class_init (GstGhostPadClass * klass)
462 GObjectClass *gobject_class = (GObjectClass *) klass;
464 g_type_class_add_private (klass, sizeof (GstGhostPadPrivate));
466 gobject_class->dispose = gst_ghost_pad_dispose;
468 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_pull_default);
469 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_push_default);
473 gst_ghost_pad_init (GstGhostPad * pad)
475 GST_GHOST_PAD_PRIVATE (pad) = G_TYPE_INSTANCE_GET_PRIVATE (pad,
476 GST_TYPE_GHOST_PAD, GstGhostPadPrivate);
478 gst_pad_set_activatemode_function (GST_PAD_CAST (pad),
479 gst_ghost_pad_activate_mode_default);
483 gst_ghost_pad_dispose (GObject * object)
489 pad = GST_PAD (object);
491 GST_DEBUG_OBJECT (pad, "dispose");
493 gst_ghost_pad_set_target (GST_GHOST_PAD (pad), NULL);
495 /* Unlink here so that gst_pad_dispose doesn't. That would lead to a call to
496 * gst_ghost_pad_unlink_default when the ghost pad is in an inconsistent state */
497 peer = gst_pad_get_peer (pad);
499 if (GST_PAD_IS_SRC (pad))
500 gst_pad_unlink (pad, peer);
502 gst_pad_unlink (peer, pad);
504 gst_object_unref (peer);
507 GST_OBJECT_LOCK (pad);
508 internal = GST_PROXY_PAD_INTERNAL (pad);
510 gst_pad_set_activatemode_function (internal, NULL);
512 GST_PROXY_PAD_INTERNAL (pad) = NULL;
513 GST_PROXY_PAD_INTERNAL (internal) = NULL;
515 /* disposes of the internal pad, since the ghostpad is the only possible object
516 * that has a refcount on the internal pad. */
517 gst_object_unparent (GST_OBJECT_CAST (internal));
520 GST_OBJECT_UNLOCK (pad);
522 G_OBJECT_CLASS (gst_ghost_pad_parent_class)->dispose (object);
526 * gst_ghost_pad_construct:
527 * @gpad: the newly allocated ghost pad
529 * Finish initialization of a newly allocated ghost pad.
531 * This function is most useful in language bindings and when subclassing
532 * #GstGhostPad; plugin and application developers normally will not call this
533 * function. Call this function directly after a call to g_object_new
534 * (GST_TYPE_GHOST_PAD, "direction", @dir, ..., NULL).
536 * Returns: %TRUE if the construction succeeds, %FALSE otherwise.
539 gst_ghost_pad_construct (GstGhostPad * gpad)
541 GstPadDirection dir, otherdir;
542 GstPadTemplate *templ;
543 GstPad *pad, *internal;
545 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
546 g_return_val_if_fail (!GST_GHOST_PAD_PRIVATE (gpad)->constructed, FALSE);
548 g_object_get (gpad, "direction", &dir, "template", &templ, NULL);
550 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, FALSE);
552 pad = GST_PAD (gpad);
554 /* Set directional padfunctions for ghostpad */
555 if (dir == GST_PAD_SINK) {
556 gst_pad_set_chain_function (pad, gst_proxy_pad_chain_default);
557 gst_pad_set_chain_list_function (pad, gst_proxy_pad_chain_list_default);
559 gst_pad_set_getrange_function (pad, gst_proxy_pad_getrange_default);
562 /* INTERNAL PAD, it always exists and is child of the ghostpad */
563 otherdir = (dir == GST_PAD_SRC) ? GST_PAD_SINK : GST_PAD_SRC;
566 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
567 "direction", otherdir, "template", templ, NULL);
568 /* release ref obtained via g_object_get */
569 gst_object_unref (templ);
572 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
573 "direction", otherdir, NULL);
575 GST_PAD_UNSET_FLUSHING (internal);
577 /* Set directional padfunctions for internal pad */
578 if (dir == GST_PAD_SRC) {
579 gst_pad_set_chain_function (internal, gst_proxy_pad_chain_default);
580 gst_pad_set_chain_list_function (internal,
581 gst_proxy_pad_chain_list_default);
583 gst_pad_set_getrange_function (internal, gst_proxy_pad_getrange_default);
586 GST_OBJECT_LOCK (pad);
588 /* now make the ghostpad a parent of the internal pad */
589 if (!gst_object_set_parent (GST_OBJECT_CAST (internal),
590 GST_OBJECT_CAST (pad)))
593 /* The ghostpad is the parent of the internal pad and is the only object that
594 * can have a refcount on the internal pad.
595 * At this point, the GstGhostPad has a refcount of 1, and the internal pad has
597 * When the refcount of the GstGhostPad drops to 0, the ghostpad will dispose
598 * its refcount on the internal pad in the dispose method by un-parenting it.
599 * This is why we don't take extra refcounts in the assignments below
601 GST_PROXY_PAD_INTERNAL (pad) = internal;
602 GST_PROXY_PAD_INTERNAL (internal) = pad;
604 /* special activation functions for the internal pad */
605 gst_pad_set_activatemode_function (internal,
606 gst_ghost_pad_internal_activate_mode_default);
608 GST_OBJECT_UNLOCK (pad);
610 GST_GHOST_PAD_PRIVATE (gpad)->constructed = TRUE;
616 GST_WARNING_OBJECT (gpad, "Could not set internal pad %s:%s",
617 GST_DEBUG_PAD_NAME (internal));
618 g_critical ("Could not set internal pad %s:%s",
619 GST_DEBUG_PAD_NAME (internal));
620 GST_OBJECT_UNLOCK (pad);
626 gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
627 GstPadTemplate * templ)
631 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
633 /* OBJECT CREATION */
635 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
636 "direction", dir, "template", templ, NULL);
638 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
639 "direction", dir, NULL);
642 if (!gst_ghost_pad_construct (ret))
643 goto construct_failed;
645 return GST_PAD_CAST (ret);
649 gst_object_unref (ret);
654 * gst_ghost_pad_new_no_target:
655 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name.
656 * @dir: the direction of the ghostpad
658 * Create a new ghostpad without a target with the given direction.
659 * A target can be set on the ghostpad later with the
660 * gst_ghost_pad_set_target() function.
662 * The created ghostpad will not have a padtemplate.
664 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
668 gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
672 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
674 GST_LOG ("name:%s, direction:%d", GST_STR_NULL (name), dir);
676 ret = gst_ghost_pad_new_full (name, dir, NULL);
683 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name
684 * @target: (transfer none): the pad to ghost.
686 * Create a new ghostpad with @target as the target. The direction will be taken
687 * from the target pad. @target must be unlinked.
689 * Will ref the target.
691 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
695 gst_ghost_pad_new (const gchar * name, GstPad * target)
699 g_return_val_if_fail (GST_IS_PAD (target), NULL);
700 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
702 GST_LOG ("name:%s, target:%s:%s", GST_STR_NULL (name),
703 GST_DEBUG_PAD_NAME (target));
705 if ((ret = gst_ghost_pad_new_no_target (name, GST_PAD_DIRECTION (target))))
706 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
707 goto set_target_failed;
714 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
715 GST_DEBUG_PAD_NAME (target));
716 gst_object_unref (ret);
722 * gst_ghost_pad_new_from_template:
723 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name.
724 * @target: (transfer none): the pad to ghost.
725 * @templ: (transfer none): the #GstPadTemplate to use on the ghostpad.
727 * Create a new ghostpad with @target as the target. The direction will be taken
728 * from the target pad. The template used on the ghostpad will be @template.
730 * Will ref the target.
732 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
737 gst_ghost_pad_new_from_template (const gchar * name, GstPad * target,
738 GstPadTemplate * templ)
742 g_return_val_if_fail (GST_IS_PAD (target), NULL);
743 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
744 g_return_val_if_fail (templ != NULL, NULL);
745 g_return_val_if_fail (GST_PAD_TEMPLATE_DIRECTION (templ) ==
746 GST_PAD_DIRECTION (target), NULL);
748 GST_LOG ("name:%s, target:%s:%s, templ:%p", GST_STR_NULL (name),
749 GST_DEBUG_PAD_NAME (target), templ);
751 if ((ret = gst_ghost_pad_new_full (name, GST_PAD_DIRECTION (target), templ)))
752 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
753 goto set_target_failed;
760 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
761 GST_DEBUG_PAD_NAME (target));
762 gst_object_unref (ret);
768 * gst_ghost_pad_new_no_target_from_template:
769 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name
770 * @templ: (transfer none): the #GstPadTemplate to create the ghostpad from.
772 * Create a new ghostpad based on @templ, without setting a target. The
773 * direction will be taken from the @templ.
775 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
779 gst_ghost_pad_new_no_target_from_template (const gchar * name,
780 GstPadTemplate * templ)
784 g_return_val_if_fail (templ != NULL, NULL);
787 gst_ghost_pad_new_full (name, GST_PAD_TEMPLATE_DIRECTION (templ), templ);
793 * gst_ghost_pad_get_target:
794 * @gpad: the #GstGhostPad
796 * Get the target pad of @gpad. Unref target pad after usage.
798 * Returns: (transfer full) (nullable): the target #GstPad, can be
799 * %NULL if the ghostpad has no target set. Unref target pad after
803 gst_ghost_pad_get_target (GstGhostPad * gpad)
807 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), NULL);
809 ret = gst_proxy_pad_get_target (GST_PAD_CAST (gpad));
811 GST_DEBUG_OBJECT (gpad, "get target %s:%s", GST_DEBUG_PAD_NAME (ret));
817 * gst_ghost_pad_set_target:
818 * @gpad: the #GstGhostPad
819 * @newtarget: (transfer none) (allow-none): the new pad target
821 * Set the new target of the ghostpad @gpad. Any existing target
822 * is unlinked and links to the new target are established. if @newtarget is
823 * %NULL the target will be cleared.
825 * Returns: %TRUE if the new target could be set. This function
826 * can return %FALSE when the internal pads could not be linked.
829 gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
833 GstPadLinkReturn lret;
835 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
836 g_return_val_if_fail (GST_PAD_CAST (gpad) != newtarget, FALSE);
838 GST_OBJECT_LOCK (gpad);
839 internal = GST_PROXY_PAD_INTERNAL (gpad);
841 if (newtarget == internal) {
842 GST_OBJECT_UNLOCK (gpad);
843 GST_WARNING_OBJECT (gpad, "Target has already been set to %s:%s",
844 GST_DEBUG_PAD_NAME (newtarget));
849 GST_DEBUG_OBJECT (gpad, "set target %s:%s", GST_DEBUG_PAD_NAME (newtarget));
851 GST_DEBUG_OBJECT (gpad, "clearing target");
853 /* clear old target */
854 if ((oldtarget = gst_pad_get_peer (internal))) {
855 GST_OBJECT_UNLOCK (gpad);
857 /* unlink internal pad */
858 if (GST_PAD_IS_SRC (internal))
859 gst_pad_unlink (internal, oldtarget);
861 gst_pad_unlink (oldtarget, internal);
863 gst_object_unref (oldtarget);
865 GST_OBJECT_UNLOCK (gpad);
869 /* and link to internal pad without any checks */
870 GST_DEBUG_OBJECT (gpad, "connecting internal pad to target %"
871 GST_PTR_FORMAT, newtarget);
873 if (GST_PAD_IS_SRC (internal))
875 gst_pad_link_full (internal, newtarget, GST_PAD_LINK_CHECK_NOTHING);
878 gst_pad_link_full (newtarget, internal, GST_PAD_LINK_CHECK_NOTHING);
880 if (lret != GST_PAD_LINK_OK)
889 GST_WARNING_OBJECT (gpad, "could not link internal and target, reason:%s",
890 gst_pad_link_get_name (lret));