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.
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.
45 #include "gst_private.h"
48 #include "gstghostpad.h"
51 #define GST_CAT_DEFAULT GST_CAT_PADS
53 #define GST_PROXY_PAD_CAST(obj) ((GstProxyPad *)obj)
54 #define GST_PROXY_PAD_PRIVATE(obj) (GST_PROXY_PAD_CAST (obj)->priv)
55 #define GST_PROXY_PAD_TARGET(pad) (GST_PAD_PEER (GST_PROXY_PAD_INTERNAL (pad)))
56 #define GST_PROXY_PAD_INTERNAL(pad) (GST_PROXY_PAD_PRIVATE (pad)->internal)
58 #define GST_PROXY_PAD_ACQUIRE_INTERNAL(pad, internal, retval) \
60 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD_CAST (pad))); \
61 if (internal == NULL) \
64 #define GST_PROXY_PAD_RELEASE_INTERNAL(internal) gst_object_unref (internal);
66 struct _GstProxyPadPrivate
71 G_DEFINE_TYPE (GstProxyPad, gst_proxy_pad, GST_TYPE_PAD);
73 static GstPad *gst_proxy_pad_get_target (GstPad * pad);
76 * gst_proxy_pad_iterate_internal_links_default:
77 * @pad: the #GstPad to get the internal links of.
78 * @parent: (allow-none): the parent of @pad or %NULL
80 * Invoke the default iterate internal links function of the proxy pad.
82 * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
83 * has no parent. Unref each returned pad with gst_object_unref().
86 gst_proxy_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
88 GstIterator *res = NULL;
92 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
94 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, NULL);
96 g_value_init (&v, GST_TYPE_PAD);
97 g_value_take_object (&v, internal);
98 res = gst_iterator_new_single (GST_TYPE_PAD, &v);
105 * gst_proxy_pad_chain_default:
106 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
107 * @parent: (allow-none): the parent of @pad or %NULL
108 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
111 * Invoke the default chain function of the proxy pad.
113 * Returns: a #GstFlowReturn from the pad.
116 gst_proxy_pad_chain_default (GstPad * pad, GstObject * parent,
122 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
123 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
125 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
126 res = gst_pad_push (internal, buffer);
127 GST_PROXY_PAD_RELEASE_INTERNAL (internal);
133 * gst_proxy_pad_chain_list_default:
134 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
135 * @parent: (allow-none): the parent of @pad or %NULL
136 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
139 * Invoke the default chain list function of the proxy pad.
141 * Returns: a #GstFlowReturn from the pad.
144 gst_proxy_pad_chain_list_default (GstPad * pad, GstObject * parent,
145 GstBufferList * list)
150 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
151 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
153 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
154 res = gst_pad_push_list (internal, list);
155 GST_PROXY_PAD_RELEASE_INTERNAL (internal);
161 * gst_proxy_pad_getrange_default:
162 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
163 * @parent: the parent of @pad
164 * @offset: The start offset of the buffer
165 * @size: The length of the buffer
166 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
167 * returns #GST_FLOW_ERROR if %NULL.
169 * Invoke the default getrange function of the proxy pad.
171 * Returns: a #GstFlowReturn from the pad.
174 gst_proxy_pad_getrange_default (GstPad * pad, GstObject * parent,
175 guint64 offset, guint size, GstBuffer ** buffer)
180 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
181 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
183 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
184 res = gst_pad_pull_range (internal, offset, size, buffer);
185 GST_PROXY_PAD_RELEASE_INTERNAL (internal);
191 gst_proxy_pad_get_target (GstPad * pad)
195 GST_OBJECT_LOCK (pad);
196 target = gst_pad_get_peer (GST_PROXY_PAD_INTERNAL (pad));
197 GST_OBJECT_UNLOCK (pad);
203 * gst_proxy_pad_get_internal:
204 * @pad: the #GstProxyPad
206 * Get the internal pad of @pad. Unref target pad after usage.
208 * The internal pad of a #GstGhostPad is the internally used
209 * pad of opposite direction, which is used to link to the target.
211 * Returns: (transfer full) (nullable): the target #GstProxyPad, can
212 * be %NULL. Unref target pad after usage.
215 gst_proxy_pad_get_internal (GstProxyPad * pad)
219 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
221 GST_OBJECT_LOCK (pad);
222 internal = GST_PROXY_PAD_INTERNAL (pad);
224 gst_object_ref (internal);
225 GST_OBJECT_UNLOCK (pad);
227 return GST_PROXY_PAD_CAST (internal);
231 gst_proxy_pad_class_init (GstProxyPadClass * klass)
233 g_type_class_add_private (klass, sizeof (GstProxyPadPrivate));
235 /* Register common function pointer descriptions */
236 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_iterate_internal_links_default);
237 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_default);
238 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_list_default);
239 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getrange_default);
243 gst_proxy_pad_init (GstProxyPad * ppad)
245 GstPad *pad = (GstPad *) ppad;
247 GST_PROXY_PAD_PRIVATE (ppad) = G_TYPE_INSTANCE_GET_PRIVATE (ppad,
248 GST_TYPE_PROXY_PAD, GstProxyPadPrivate);
250 gst_pad_set_iterate_internal_links_function (pad,
251 gst_proxy_pad_iterate_internal_links_default);
253 GST_PAD_SET_PROXY_CAPS (pad);
254 GST_PAD_SET_PROXY_SCHEDULING (pad);
255 GST_PAD_SET_PROXY_ALLOCATION (pad);
259 /***********************************************************************
260 * Ghost pads, implemented as a pair of proxy pads (sort of)
264 #define GST_GHOST_PAD_PRIVATE(obj) (GST_GHOST_PAD_CAST (obj)->priv)
266 struct _GstGhostPadPrivate
268 /* with PROXY_LOCK */
269 gboolean constructed;
272 G_DEFINE_TYPE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
274 static void gst_ghost_pad_dispose (GObject * object);
277 gst_ghost_pad_internal_activate_push_default (GstPad * pad, GstObject * parent,
283 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, we're ok",
284 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
286 /* in both cases (SRC and SINK) we activate just the internal pad. The targets
287 * will be activated later (or already in case of a ghost sinkpad). */
288 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
289 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
290 GST_PROXY_PAD_RELEASE_INTERNAL (other);
296 gst_ghost_pad_internal_activate_pull_default (GstPad * pad, GstObject * parent,
302 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
303 GST_DEBUG_PAD_NAME (pad));
305 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
306 /* we are activated in pull mode by our peer element, which is a sinkpad
307 * that wants to operate in pull mode. This activation has to propagate
308 * upstream through the pipeline. We call the internal activation function,
309 * which will trigger gst_ghost_pad_activate_pull_default, which propagates even
310 * further upstream */
311 GST_LOG_OBJECT (pad, "pad is src, activate internal");
312 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
313 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
314 GST_PROXY_PAD_RELEASE_INTERNAL (other);
315 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
316 /* We are SINK, the ghostpad is SRC, we propagate the activation upstream
317 * since we hold a pointer to the upstream peer. */
318 GST_LOG_OBJECT (pad, "activating peer");
319 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
320 gst_object_unref (other);
322 /* this is failure, we can't activate pull if there is no peer */
323 GST_LOG_OBJECT (pad, "not src and no peer, failing");
331 * gst_ghost_pad_internal_activate_mode_default:
332 * @pad: the #GstPad to activate or deactivate.
333 * @parent: (allow-none): the parent of @pad or %NULL
334 * @mode: the requested activation mode
335 * @active: whether the pad should be active or not.
337 * Invoke the default activate mode function of a proxy pad that is
338 * owned by a ghost pad.
340 * Returns: %TRUE if the operation was successful.
343 gst_ghost_pad_internal_activate_mode_default (GstPad * pad, GstObject * parent,
344 GstPadMode mode, gboolean active)
348 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
351 case GST_PAD_MODE_PULL:
352 res = gst_ghost_pad_internal_activate_pull_default (pad, parent, active);
354 case GST_PAD_MODE_PUSH:
355 res = gst_ghost_pad_internal_activate_push_default (pad, parent, active);
358 GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
366 gst_ghost_pad_activate_push_default (GstPad * pad, GstObject * parent,
372 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
374 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, proxy internal",
375 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
377 /* just activate the internal pad */
378 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
379 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
380 GST_PROXY_PAD_RELEASE_INTERNAL (other);
386 gst_ghost_pad_activate_pull_default (GstPad * pad, GstObject * parent,
392 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
393 GST_DEBUG_PAD_NAME (pad));
395 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
396 /* the ghostpad is SRC and activated in pull mode by its peer, call the
397 * activation function of the internal pad to propagate the activation
399 GST_LOG_OBJECT (pad, "pad is src, activate internal");
400 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
401 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
402 GST_PROXY_PAD_RELEASE_INTERNAL (other);
403 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
404 /* We are SINK and activated by the internal pad, propagate activation
405 * upstream because we hold a ref to the upstream peer */
406 GST_LOG_OBJECT (pad, "activating peer");
407 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
408 gst_object_unref (other);
410 /* no peer, we fail */
411 GST_LOG_OBJECT (pad, "pad not src and no peer, failing");
419 * gst_ghost_pad_activate_mode_default:
420 * @pad: the #GstPad to activate or deactivate.
421 * @parent: (allow-none): the parent of @pad or %NULL
422 * @mode: the requested activation mode
423 * @active: whether the pad should be active or not.
425 * Invoke the default activate mode function of a ghost pad.
427 * Returns: %TRUE if the operation was successful.
430 gst_ghost_pad_activate_mode_default (GstPad * pad, GstObject * parent,
431 GstPadMode mode, gboolean active)
435 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
438 case GST_PAD_MODE_PULL:
439 res = gst_ghost_pad_activate_pull_default (pad, parent, active);
441 case GST_PAD_MODE_PUSH:
442 res = gst_ghost_pad_activate_push_default (pad, parent, active);
445 GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
453 gst_ghost_pad_class_init (GstGhostPadClass * klass)
455 GObjectClass *gobject_class = (GObjectClass *) klass;
457 g_type_class_add_private (klass, sizeof (GstGhostPadPrivate));
459 gobject_class->dispose = gst_ghost_pad_dispose;
461 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_pull_default);
462 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_push_default);
466 gst_ghost_pad_init (GstGhostPad * pad)
468 GST_GHOST_PAD_PRIVATE (pad) = G_TYPE_INSTANCE_GET_PRIVATE (pad,
469 GST_TYPE_GHOST_PAD, GstGhostPadPrivate);
471 gst_pad_set_activatemode_function (GST_PAD_CAST (pad),
472 gst_ghost_pad_activate_mode_default);
476 gst_ghost_pad_dispose (GObject * object)
482 pad = GST_PAD (object);
484 GST_DEBUG_OBJECT (pad, "dispose");
486 gst_ghost_pad_set_target (GST_GHOST_PAD (pad), NULL);
488 /* Unlink here so that gst_pad_dispose doesn't. That would lead to a call to
489 * gst_ghost_pad_unlink_default when the ghost pad is in an inconsistent state */
490 peer = gst_pad_get_peer (pad);
492 if (GST_PAD_IS_SRC (pad))
493 gst_pad_unlink (pad, peer);
495 gst_pad_unlink (peer, pad);
497 gst_object_unref (peer);
500 GST_OBJECT_LOCK (pad);
501 internal = GST_PROXY_PAD_INTERNAL (pad);
503 gst_pad_set_activatemode_function (internal, NULL);
505 /* disposes of the internal pad, since the ghostpad is the only possible object
506 * that has a refcount on the internal pad. */
507 gst_object_unparent (GST_OBJECT_CAST (internal));
508 GST_PROXY_PAD_INTERNAL (pad) = NULL;
510 GST_OBJECT_UNLOCK (pad);
512 G_OBJECT_CLASS (gst_ghost_pad_parent_class)->dispose (object);
516 * gst_ghost_pad_construct:
517 * @gpad: the newly allocated ghost pad
519 * Finish initialization of a newly allocated ghost pad.
521 * This function is most useful in language bindings and when subclassing
522 * #GstGhostPad; plugin and application developers normally will not call this
523 * function. Call this function directly after a call to g_object_new
524 * (GST_TYPE_GHOST_PAD, "direction", @dir, ..., NULL).
526 * Returns: %TRUE if the construction succeeds, %FALSE otherwise.
529 gst_ghost_pad_construct (GstGhostPad * gpad)
531 GstPadDirection dir, otherdir;
532 GstPadTemplate *templ;
533 GstPad *pad, *internal;
535 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
536 g_return_val_if_fail (GST_GHOST_PAD_PRIVATE (gpad)->constructed == FALSE,
539 g_object_get (gpad, "direction", &dir, "template", &templ, NULL);
541 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, FALSE);
543 pad = GST_PAD (gpad);
545 /* Set directional padfunctions for ghostpad */
546 if (dir == GST_PAD_SINK) {
547 gst_pad_set_chain_function (pad, gst_proxy_pad_chain_default);
548 gst_pad_set_chain_list_function (pad, gst_proxy_pad_chain_list_default);
550 gst_pad_set_getrange_function (pad, gst_proxy_pad_getrange_default);
553 /* INTERNAL PAD, it always exists and is child of the ghostpad */
554 otherdir = (dir == GST_PAD_SRC) ? GST_PAD_SINK : GST_PAD_SRC;
557 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
558 "direction", otherdir, "template", templ, NULL);
559 /* release ref obtained via g_object_get */
560 gst_object_unref (templ);
563 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
564 "direction", otherdir, NULL);
566 GST_PAD_UNSET_FLUSHING (internal);
568 /* Set directional padfunctions for internal pad */
569 if (dir == GST_PAD_SRC) {
570 gst_pad_set_chain_function (internal, gst_proxy_pad_chain_default);
571 gst_pad_set_chain_list_function (internal,
572 gst_proxy_pad_chain_list_default);
574 gst_pad_set_getrange_function (internal, gst_proxy_pad_getrange_default);
577 GST_OBJECT_LOCK (pad);
579 /* now make the ghostpad a parent of the internal pad */
580 if (!gst_object_set_parent (GST_OBJECT_CAST (internal),
581 GST_OBJECT_CAST (pad)))
584 /* The ghostpad is the parent of the internal pad and is the only object that
585 * can have a refcount on the internal pad.
586 * At this point, the GstGhostPad has a refcount of 1, and the internal pad has
588 * When the refcount of the GstGhostPad drops to 0, the ghostpad will dispose
589 * its refcount on the internal pad in the dispose method by un-parenting it.
590 * This is why we don't take extra refcounts in the assignments below
592 GST_PROXY_PAD_INTERNAL (pad) = internal;
593 GST_PROXY_PAD_INTERNAL (internal) = pad;
595 /* special activation functions for the internal pad */
596 gst_pad_set_activatemode_function (internal,
597 gst_ghost_pad_internal_activate_mode_default);
599 GST_OBJECT_UNLOCK (pad);
601 GST_GHOST_PAD_PRIVATE (gpad)->constructed = TRUE;
607 GST_WARNING_OBJECT (gpad, "Could not set internal pad %s:%s",
608 GST_DEBUG_PAD_NAME (internal));
609 g_critical ("Could not set internal pad %s:%s",
610 GST_DEBUG_PAD_NAME (internal));
611 GST_OBJECT_UNLOCK (pad);
612 gst_object_unref (internal);
618 gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
619 GstPadTemplate * templ)
623 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
625 /* OBJECT CREATION */
627 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
628 "direction", dir, "template", templ, NULL);
630 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
631 "direction", dir, NULL);
634 if (!gst_ghost_pad_construct (ret))
635 goto construct_failed;
637 return GST_PAD_CAST (ret);
641 gst_object_unref (ret);
646 * gst_ghost_pad_new_no_target:
647 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name.
648 * @dir: the direction of the ghostpad
650 * Create a new ghostpad without a target with the given direction.
651 * A target can be set on the ghostpad later with the
652 * gst_ghost_pad_set_target() function.
654 * The created ghostpad will not have a padtemplate.
656 * Returns: (transfer full) (nullable): a new #GstPad, or %NULL in
660 gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
664 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
666 GST_LOG ("name:%s, direction:%d", GST_STR_NULL (name), dir);
668 ret = gst_ghost_pad_new_full (name, dir, NULL);
675 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name
676 * @target: (transfer none): the pad to ghost.
678 * Create a new ghostpad with @target as the target. The direction will be taken
679 * from the target pad. @target must be unlinked.
681 * Will ref the target.
683 * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
687 gst_ghost_pad_new (const gchar * name, GstPad * target)
691 g_return_val_if_fail (GST_IS_PAD (target), NULL);
692 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
694 GST_LOG ("name:%s, target:%s:%s", GST_STR_NULL (name),
695 GST_DEBUG_PAD_NAME (target));
697 if ((ret = gst_ghost_pad_new_no_target (name, GST_PAD_DIRECTION (target))))
698 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
699 goto set_target_failed;
706 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
707 GST_DEBUG_PAD_NAME (target));
708 gst_object_unref (ret);
714 * gst_ghost_pad_new_from_template:
715 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name.
716 * @target: (transfer none): the pad to ghost.
717 * @templ: (transfer none): the #GstPadTemplate to use on the ghostpad.
719 * Create a new ghostpad with @target as the target. The direction will be taken
720 * from the target pad. The template used on the ghostpad will be @template.
722 * Will ref the target.
724 * Returns: (transfer full) (nullable): a new #GstPad, or %NULL in
729 gst_ghost_pad_new_from_template (const gchar * name, GstPad * target,
730 GstPadTemplate * templ)
734 g_return_val_if_fail (GST_IS_PAD (target), NULL);
735 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
736 g_return_val_if_fail (templ != NULL, NULL);
737 g_return_val_if_fail (GST_PAD_TEMPLATE_DIRECTION (templ) ==
738 GST_PAD_DIRECTION (target), NULL);
740 GST_LOG ("name:%s, target:%s:%s, templ:%p", GST_STR_NULL (name),
741 GST_DEBUG_PAD_NAME (target), templ);
743 if ((ret = gst_ghost_pad_new_full (name, GST_PAD_DIRECTION (target), templ)))
744 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
745 goto set_target_failed;
752 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
753 GST_DEBUG_PAD_NAME (target));
754 gst_object_unref (ret);
760 * gst_ghost_pad_new_no_target_from_template:
761 * @name: (allow-none): the name of the new pad, or %NULL to assign a default name
762 * @templ: (transfer none): the #GstPadTemplate to create the ghostpad from.
764 * Create a new ghostpad based on @templ, without setting a target. The
765 * direction will be taken from the @templ.
767 * Returns: (transfer full) (nullable): a new #GstPad, or %NULL in
771 gst_ghost_pad_new_no_target_from_template (const gchar * name,
772 GstPadTemplate * templ)
776 g_return_val_if_fail (templ != NULL, NULL);
779 gst_ghost_pad_new_full (name, GST_PAD_TEMPLATE_DIRECTION (templ), templ);
785 * gst_ghost_pad_get_target:
786 * @gpad: the #GstGhostPad
788 * Get the target pad of @gpad. Unref target pad after usage.
790 * Returns: (transfer full) (nullable): the target #GstPad, can be
791 * %NULL if the ghostpad has no target set. Unref target pad after
795 gst_ghost_pad_get_target (GstGhostPad * gpad)
799 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), NULL);
801 ret = gst_proxy_pad_get_target (GST_PAD_CAST (gpad));
803 GST_DEBUG_OBJECT (gpad, "get target %s:%s", GST_DEBUG_PAD_NAME (ret));
809 * gst_ghost_pad_set_target:
810 * @gpad: the #GstGhostPad
811 * @newtarget: (transfer none) (allow-none): the new pad target
813 * Set the new target of the ghostpad @gpad. Any existing target
814 * is unlinked and links to the new target are established. if @newtarget is
815 * %NULL the target will be cleared.
817 * Returns: (transfer full): %TRUE if the new target could be set. This function
818 * can return %FALSE when the internal pads could not be linked.
821 gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
825 GstPadLinkReturn lret;
827 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
828 g_return_val_if_fail (GST_PAD_CAST (gpad) != newtarget, FALSE);
829 g_return_val_if_fail (newtarget != GST_PROXY_PAD_INTERNAL (gpad), FALSE);
831 GST_OBJECT_LOCK (gpad);
832 internal = GST_PROXY_PAD_INTERNAL (gpad);
835 GST_DEBUG_OBJECT (gpad, "set target %s:%s", GST_DEBUG_PAD_NAME (newtarget));
837 GST_DEBUG_OBJECT (gpad, "clearing target");
839 /* clear old target */
840 if ((oldtarget = gst_pad_get_peer (internal))) {
841 GST_OBJECT_UNLOCK (gpad);
843 /* unlink internal pad */
844 if (GST_PAD_IS_SRC (internal))
845 gst_pad_unlink (internal, oldtarget);
847 gst_pad_unlink (oldtarget, internal);
849 gst_object_unref (oldtarget);
851 GST_OBJECT_UNLOCK (gpad);
855 /* and link to internal pad without any checks */
856 GST_DEBUG_OBJECT (gpad, "connecting internal pad to target %"
857 GST_PTR_FORMAT, newtarget);
859 if (GST_PAD_IS_SRC (internal))
861 gst_pad_link_full (internal, newtarget, GST_PAD_LINK_CHECK_NOTHING);
864 gst_pad_link_full (newtarget, internal, GST_PAD_LINK_CHECK_NOTHING);
866 if (lret != GST_PAD_LINK_OK)
875 GST_WARNING_OBJECT (gpad, "could not link internal and target, reason:%s",
876 gst_pad_link_get_name (lret));