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.
44 * Last reviewed on 2005-11-18 (0.9.5)
47 #include "gst_private.h"
50 #include "gstghostpad.h"
53 #define GST_CAT_DEFAULT GST_CAT_PADS
55 #define GST_PROXY_PAD_CAST(obj) ((GstProxyPad *)obj)
56 #define GST_PROXY_PAD_PRIVATE(obj) (GST_PROXY_PAD_CAST (obj)->priv)
57 #define GST_PROXY_PAD_TARGET(pad) (GST_PAD_PEER (GST_PROXY_PAD_INTERNAL (pad)))
58 #define GST_PROXY_PAD_INTERNAL(pad) (GST_PROXY_PAD_PRIVATE (pad)->internal)
60 #define GST_PROXY_PAD_ACQUIRE_INTERNAL(pad, internal, retval) \
62 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD_CAST (pad))); \
63 if (internal == NULL) \
66 #define GST_PROXY_PAD_RELEASE_INTERNAL(internal) gst_object_unref (internal);
68 struct _GstProxyPadPrivate
73 G_DEFINE_TYPE (GstProxyPad, gst_proxy_pad, GST_TYPE_PAD);
75 static GstPad *gst_proxy_pad_get_target (GstPad * pad);
78 * gst_proxy_pad_iterate_internal_links_default:
79 * @pad: the #GstPad to get the internal links of.
80 * @parent: (allow-none): the parent of @pad or NULL
82 * Invoke the default iterate internal links function of the proxy pad.
84 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
85 * returned pad with gst_object_unref().
88 gst_proxy_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
90 GstIterator *res = NULL;
94 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
96 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, NULL);
98 g_value_init (&v, GST_TYPE_PAD);
99 g_value_take_object (&v, internal);
100 res = gst_iterator_new_single (GST_TYPE_PAD, &v);
107 * gst_proxy_pad_chain_default:
108 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
109 * @parent: (allow-none): the parent of @pad or NULL
110 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
113 * Invoke the default chain function of the proxy pad.
115 * Returns: a #GstFlowReturn from the pad.
118 gst_proxy_pad_chain_default (GstPad * pad, GstObject * parent,
124 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
125 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
127 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
128 res = gst_pad_push (internal, buffer);
129 GST_PROXY_PAD_RELEASE_INTERNAL (internal);
135 * gst_proxy_pad_chain_list_default:
136 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
137 * @parent: (allow-none): the parent of @pad or NULL
138 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
141 * Invoke the default chain list function of the proxy pad.
143 * Returns: a #GstFlowReturn from the pad.
146 gst_proxy_pad_chain_list_default (GstPad * pad, GstObject * parent,
147 GstBufferList * list)
152 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
153 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
155 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
156 res = gst_pad_push_list (internal, list);
157 GST_PROXY_PAD_RELEASE_INTERNAL (internal);
163 * gst_proxy_pad_getrange_default:
164 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
165 * @parent: the parent of @pad
166 * @offset: The start offset of the buffer
167 * @size: The length of the buffer
168 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
169 * returns #GST_FLOW_ERROR if %NULL.
171 * Invoke the default getrange function of the proxy pad.
173 * Returns: a #GstFlowReturn from the pad.
176 gst_proxy_pad_getrange_default (GstPad * pad, GstObject * parent,
177 guint64 offset, guint size, GstBuffer ** buffer)
182 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
183 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
185 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
186 res = gst_pad_pull_range (internal, offset, size, buffer);
187 GST_PROXY_PAD_RELEASE_INTERNAL (internal);
193 gst_proxy_pad_get_target (GstPad * pad)
197 GST_OBJECT_LOCK (pad);
198 target = GST_PROXY_PAD_TARGET (pad);
200 gst_object_ref (target);
201 GST_OBJECT_UNLOCK (pad);
207 * gst_proxy_pad_get_internal:
208 * @pad: the #GstProxyPad
210 * Get the internal pad of @pad. Unref target pad after usage.
212 * The internal pad of a #GstGhostPad is the internally used
213 * pad of opposite direction, which is used to link to the target.
215 * Returns: (transfer full): the target #GstProxyPad, can be NULL.
216 * Unref target pad after usage.
219 gst_proxy_pad_get_internal (GstProxyPad * pad)
223 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
225 GST_OBJECT_LOCK (pad);
226 internal = GST_PROXY_PAD_INTERNAL (pad);
228 gst_object_ref (internal);
229 GST_OBJECT_UNLOCK (pad);
231 return GST_PROXY_PAD_CAST (internal);
235 gst_proxy_pad_class_init (GstProxyPadClass * klass)
237 g_type_class_add_private (klass, sizeof (GstProxyPadPrivate));
239 /* Register common function pointer descriptions */
240 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_iterate_internal_links_default);
241 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_default);
242 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_list_default);
243 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getrange_default);
247 gst_proxy_pad_init (GstProxyPad * ppad)
249 GstPad *pad = (GstPad *) ppad;
251 GST_PROXY_PAD_PRIVATE (ppad) = G_TYPE_INSTANCE_GET_PRIVATE (ppad,
252 GST_TYPE_PROXY_PAD, GstProxyPadPrivate);
254 gst_pad_set_iterate_internal_links_function (pad,
255 gst_proxy_pad_iterate_internal_links_default);
257 GST_PAD_SET_PROXY_CAPS (pad);
258 GST_PAD_SET_PROXY_SCHEDULING (pad);
259 GST_PAD_SET_PROXY_ALLOCATION (pad);
263 /***********************************************************************
264 * Ghost pads, implemented as a pair of proxy pads (sort of)
268 #define GST_GHOST_PAD_PRIVATE(obj) (GST_GHOST_PAD_CAST (obj)->priv)
270 struct _GstGhostPadPrivate
272 /* with PROXY_LOCK */
273 gboolean constructed;
276 G_DEFINE_TYPE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
278 static void gst_ghost_pad_dispose (GObject * object);
281 gst_ghost_pad_internal_activate_push_default (GstPad * pad, GstObject * parent,
287 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, we're ok",
288 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
290 /* in both cases (SRC and SINK) we activate just the internal pad. The targets
291 * will be activated later (or already in case of a ghost sinkpad). */
292 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
293 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
294 GST_PROXY_PAD_RELEASE_INTERNAL (other);
300 gst_ghost_pad_internal_activate_pull_default (GstPad * pad, GstObject * parent,
306 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
307 GST_DEBUG_PAD_NAME (pad));
309 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
310 /* we are activated in pull mode by our peer element, which is a sinkpad
311 * that wants to operate in pull mode. This activation has to propagate
312 * upstream through the pipeline. We call the internal activation function,
313 * which will trigger gst_ghost_pad_activate_pull_default, which propagates even
314 * further upstream */
315 GST_LOG_OBJECT (pad, "pad is src, activate internal");
316 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
317 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
318 GST_PROXY_PAD_RELEASE_INTERNAL (other);
319 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
320 /* We are SINK, the ghostpad is SRC, we propagate the activation upstream
321 * since we hold a pointer to the upstream peer. */
322 GST_LOG_OBJECT (pad, "activating peer");
323 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
324 gst_object_unref (other);
326 /* this is failure, we can't activate pull if there is no peer */
327 GST_LOG_OBJECT (pad, "not src and no peer, failing");
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 /* no peer, we fail */
415 GST_LOG_OBJECT (pad, "pad not src and no peer, failing");
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 g_type_class_add_private (klass, sizeof (GstGhostPadPrivate));
463 gobject_class->dispose = gst_ghost_pad_dispose;
465 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_pull_default);
466 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_push_default);
470 gst_ghost_pad_init (GstGhostPad * pad)
472 GST_GHOST_PAD_PRIVATE (pad) = G_TYPE_INSTANCE_GET_PRIVATE (pad,
473 GST_TYPE_GHOST_PAD, GstGhostPadPrivate);
475 gst_pad_set_activatemode_function (GST_PAD_CAST (pad),
476 gst_ghost_pad_activate_mode_default);
480 gst_ghost_pad_dispose (GObject * object)
486 pad = GST_PAD (object);
488 GST_DEBUG_OBJECT (pad, "dispose");
490 gst_ghost_pad_set_target (GST_GHOST_PAD (pad), NULL);
492 /* Unlink here so that gst_pad_dispose doesn't. That would lead to a call to
493 * gst_ghost_pad_unlink_default when the ghost pad is in an inconsistent state */
494 peer = gst_pad_get_peer (pad);
496 if (GST_PAD_IS_SRC (pad))
497 gst_pad_unlink (pad, peer);
499 gst_pad_unlink (peer, pad);
501 gst_object_unref (peer);
504 GST_OBJECT_LOCK (pad);
505 internal = GST_PROXY_PAD_INTERNAL (pad);
507 gst_pad_set_activatemode_function (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));
512 GST_PROXY_PAD_INTERNAL (pad) = NULL;
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,
543 g_object_get (gpad, "direction", &dir, "template", &templ, NULL);
545 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, FALSE);
547 pad = GST_PAD (gpad);
549 /* Set directional padfunctions for ghostpad */
550 if (dir == GST_PAD_SINK) {
551 gst_pad_set_chain_function (pad, gst_proxy_pad_chain_default);
552 gst_pad_set_chain_list_function (pad, gst_proxy_pad_chain_list_default);
554 gst_pad_set_getrange_function (pad, gst_proxy_pad_getrange_default);
557 /* INTERNAL PAD, it always exists and is child of the ghostpad */
558 otherdir = (dir == GST_PAD_SRC) ? GST_PAD_SINK : GST_PAD_SRC;
561 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
562 "direction", otherdir, "template", templ, NULL);
563 /* release ref obtained via g_object_get */
564 gst_object_unref (templ);
567 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
568 "direction", otherdir, NULL);
570 GST_PAD_UNSET_FLUSHING (internal);
572 /* Set directional padfunctions for internal pad */
573 if (dir == GST_PAD_SRC) {
574 gst_pad_set_chain_function (internal, gst_proxy_pad_chain_default);
575 gst_pad_set_chain_list_function (internal,
576 gst_proxy_pad_chain_list_default);
578 gst_pad_set_getrange_function (internal, gst_proxy_pad_getrange_default);
581 GST_OBJECT_LOCK (pad);
583 /* now make the ghostpad a parent of the internal pad */
584 if (!gst_object_set_parent (GST_OBJECT_CAST (internal),
585 GST_OBJECT_CAST (pad)))
588 /* The ghostpad is the parent of the internal pad and is the only object that
589 * can have a refcount on the internal pad.
590 * At this point, the GstGhostPad has a refcount of 1, and the internal pad has
592 * When the refcount of the GstGhostPad drops to 0, the ghostpad will dispose
593 * its refcount on the internal pad in the dispose method by un-parenting it.
594 * This is why we don't take extra refcounts in the assignments below
596 GST_PROXY_PAD_INTERNAL (pad) = internal;
597 GST_PROXY_PAD_INTERNAL (internal) = pad;
599 /* special activation functions for the internal pad */
600 gst_pad_set_activatemode_function (internal,
601 gst_ghost_pad_internal_activate_mode_default);
603 GST_OBJECT_UNLOCK (pad);
605 GST_GHOST_PAD_PRIVATE (gpad)->constructed = TRUE;
611 GST_WARNING_OBJECT (gpad, "Could not set internal pad %s:%s",
612 GST_DEBUG_PAD_NAME (internal));
613 g_critical ("Could not set internal pad %s:%s",
614 GST_DEBUG_PAD_NAME (internal));
615 GST_OBJECT_UNLOCK (pad);
616 gst_object_unref (internal);
622 gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
623 GstPadTemplate * templ)
627 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
629 /* OBJECT CREATION */
631 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
632 "direction", dir, "template", templ, NULL);
634 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
635 "direction", dir, NULL);
638 if (!gst_ghost_pad_construct (ret))
639 goto construct_failed;
641 return GST_PAD_CAST (ret);
645 gst_object_unref (ret);
650 * gst_ghost_pad_new_no_target:
651 * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
652 * @dir: the direction of the ghostpad
654 * Create a new ghostpad without a target with the given direction.
655 * A target can be set on the ghostpad later with the
656 * gst_ghost_pad_set_target() function.
658 * The created ghostpad will not have a padtemplate.
660 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
663 gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
667 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
669 GST_LOG ("name:%s, direction:%d", GST_STR_NULL (name), dir);
671 ret = gst_ghost_pad_new_full (name, dir, NULL);
678 * @name: (allow-none): the name of the new pad, or NULL to assign a default name
679 * @target: (transfer none): the pad to ghost.
681 * Create a new ghostpad with @target as the target. The direction will be taken
682 * from the target pad. @target must be unlinked.
684 * Will ref the target.
686 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
689 gst_ghost_pad_new (const gchar * name, GstPad * target)
693 g_return_val_if_fail (GST_IS_PAD (target), NULL);
694 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
696 GST_LOG ("name:%s, target:%s:%s", GST_STR_NULL (name),
697 GST_DEBUG_PAD_NAME (target));
699 if ((ret = gst_ghost_pad_new_no_target (name, GST_PAD_DIRECTION (target))))
700 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
701 goto set_target_failed;
708 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
709 GST_DEBUG_PAD_NAME (target));
710 gst_object_unref (ret);
716 * gst_ghost_pad_new_from_template:
717 * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
718 * @target: (transfer none): the pad to ghost.
719 * @templ: (transfer none): the #GstPadTemplate to use on the ghostpad.
721 * Create a new ghostpad with @target as the target. The direction will be taken
722 * from the target pad. The template used on the ghostpad will be @template.
724 * Will ref the target.
726 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
730 gst_ghost_pad_new_from_template (const gchar * name, GstPad * target,
731 GstPadTemplate * templ)
735 g_return_val_if_fail (GST_IS_PAD (target), NULL);
736 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
737 g_return_val_if_fail (templ != NULL, NULL);
738 g_return_val_if_fail (GST_PAD_TEMPLATE_DIRECTION (templ) ==
739 GST_PAD_DIRECTION (target), NULL);
741 GST_LOG ("name:%s, target:%s:%s, templ:%p", GST_STR_NULL (name),
742 GST_DEBUG_PAD_NAME (target), templ);
744 if ((ret = gst_ghost_pad_new_full (name, GST_PAD_DIRECTION (target), templ)))
745 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
746 goto set_target_failed;
753 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
754 GST_DEBUG_PAD_NAME (target));
755 gst_object_unref (ret);
761 * gst_ghost_pad_new_no_target_from_template:
762 * @name: (allow-none): the name of the new pad, or NULL to assign a default name
763 * @templ: (transfer none): the #GstPadTemplate to create the ghostpad from.
765 * Create a new ghostpad based on @templ, without setting a target. The
766 * direction will be taken from the @templ.
768 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
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): the target #GstPad, can be NULL if the ghostpad
791 * has no target set. Unref target pad after usage.
794 gst_ghost_pad_get_target (GstGhostPad * gpad)
798 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), NULL);
800 ret = gst_proxy_pad_get_target (GST_PAD_CAST (gpad));
802 GST_DEBUG_OBJECT (gpad, "get target %s:%s", GST_DEBUG_PAD_NAME (ret));
808 * gst_ghost_pad_set_target:
809 * @gpad: the #GstGhostPad
810 * @newtarget: (transfer none) (allow-none): the new pad target
812 * Set the new target of the ghostpad @gpad. Any existing target
813 * is unlinked and links to the new target are established. if @newtarget is
814 * NULL the target will be cleared.
816 * Returns: (transfer full): TRUE if the new target could be set. This function
817 * can return FALSE when the internal pads could not be linked.
820 gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
824 GstPadLinkReturn lret;
826 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
827 g_return_val_if_fail (GST_PAD_CAST (gpad) != newtarget, FALSE);
828 g_return_val_if_fail (newtarget != GST_PROXY_PAD_INTERNAL (gpad), FALSE);
830 GST_OBJECT_LOCK (gpad);
831 internal = GST_PROXY_PAD_INTERNAL (gpad);
834 GST_DEBUG_OBJECT (gpad, "set target %s:%s", GST_DEBUG_PAD_NAME (newtarget));
836 GST_DEBUG_OBJECT (gpad, "clearing target");
838 /* clear old target */
839 if ((oldtarget = GST_PROXY_PAD_TARGET (gpad))) {
840 GST_OBJECT_UNLOCK (gpad);
842 /* unlink internal pad */
843 if (GST_PAD_IS_SRC (internal))
844 gst_pad_unlink (internal, oldtarget);
846 gst_pad_unlink (oldtarget, internal);
848 GST_OBJECT_UNLOCK (gpad);
852 /* and link to internal pad without any checks */
853 GST_DEBUG_OBJECT (gpad, "connecting internal pad to target %"
854 GST_PTR_FORMAT, newtarget);
856 if (GST_PAD_IS_SRC (internal))
858 gst_pad_link_full (internal, newtarget, GST_PAD_LINK_CHECK_NOTHING);
861 gst_pad_link_full (newtarget, internal, GST_PAD_LINK_CHECK_NOTHING);
863 if (lret != GST_PAD_LINK_OK)
872 GST_WARNING_OBJECT (gpad, "could not link internal and target, reason:%d",