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_pad_get_peer (GST_PROXY_PAD_INTERNAL (pad));
199 GST_OBJECT_UNLOCK (pad);
205 * gst_proxy_pad_get_internal:
206 * @pad: the #GstProxyPad
208 * Get the internal pad of @pad. Unref target pad after usage.
210 * The internal pad of a #GstGhostPad is the internally used
211 * pad of opposite direction, which is used to link to the target.
213 * Returns: (transfer full): the target #GstProxyPad, can be NULL.
214 * Unref target pad after usage.
217 gst_proxy_pad_get_internal (GstProxyPad * pad)
221 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
223 GST_OBJECT_LOCK (pad);
224 internal = GST_PROXY_PAD_INTERNAL (pad);
226 gst_object_ref (internal);
227 GST_OBJECT_UNLOCK (pad);
229 return GST_PROXY_PAD_CAST (internal);
233 gst_proxy_pad_class_init (GstProxyPadClass * klass)
235 g_type_class_add_private (klass, sizeof (GstProxyPadPrivate));
237 /* Register common function pointer descriptions */
238 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_iterate_internal_links_default);
239 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_default);
240 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_list_default);
241 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getrange_default);
245 gst_proxy_pad_init (GstProxyPad * ppad)
247 GstPad *pad = (GstPad *) ppad;
249 GST_PROXY_PAD_PRIVATE (ppad) = G_TYPE_INSTANCE_GET_PRIVATE (ppad,
250 GST_TYPE_PROXY_PAD, GstProxyPadPrivate);
252 gst_pad_set_iterate_internal_links_function (pad,
253 gst_proxy_pad_iterate_internal_links_default);
255 GST_PAD_SET_PROXY_CAPS (pad);
256 GST_PAD_SET_PROXY_SCHEDULING (pad);
257 GST_PAD_SET_PROXY_ALLOCATION (pad);
261 /***********************************************************************
262 * Ghost pads, implemented as a pair of proxy pads (sort of)
266 #define GST_GHOST_PAD_PRIVATE(obj) (GST_GHOST_PAD_CAST (obj)->priv)
268 struct _GstGhostPadPrivate
270 /* with PROXY_LOCK */
271 gboolean constructed;
274 G_DEFINE_TYPE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
276 static void gst_ghost_pad_dispose (GObject * object);
279 gst_ghost_pad_internal_activate_push_default (GstPad * pad, GstObject * parent,
285 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, we're ok",
286 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
288 /* in both cases (SRC and SINK) we activate just the internal pad. The targets
289 * will be activated later (or already in case of a ghost sinkpad). */
290 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
291 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
292 GST_PROXY_PAD_RELEASE_INTERNAL (other);
298 gst_ghost_pad_internal_activate_pull_default (GstPad * pad, GstObject * parent,
304 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
305 GST_DEBUG_PAD_NAME (pad));
307 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
308 /* we are activated in pull mode by our peer element, which is a sinkpad
309 * that wants to operate in pull mode. This activation has to propagate
310 * upstream through the pipeline. We call the internal activation function,
311 * which will trigger gst_ghost_pad_activate_pull_default, which propagates even
312 * further upstream */
313 GST_LOG_OBJECT (pad, "pad is src, activate internal");
314 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
315 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
316 GST_PROXY_PAD_RELEASE_INTERNAL (other);
317 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
318 /* We are SINK, the ghostpad is SRC, we propagate the activation upstream
319 * since we hold a pointer to the upstream peer. */
320 GST_LOG_OBJECT (pad, "activating peer");
321 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
322 gst_object_unref (other);
324 /* this is failure, we can't activate pull if there is no peer */
325 GST_LOG_OBJECT (pad, "not src and no peer, failing");
333 * gst_ghost_pad_internal_activate_mode_default:
334 * @pad: the #GstPad to activate or deactivate.
335 * @parent: (allow-none): the parent of @pad or NULL
336 * @mode: the requested activation mode
337 * @active: whether the pad should be active or not.
339 * Invoke the default activate mode function of a proxy pad that is
340 * owned by a ghost pad.
342 * Returns: %TRUE if the operation was successful.
345 gst_ghost_pad_internal_activate_mode_default (GstPad * pad, GstObject * parent,
346 GstPadMode mode, gboolean active)
350 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
353 case GST_PAD_MODE_PULL:
354 res = gst_ghost_pad_internal_activate_pull_default (pad, parent, active);
356 case GST_PAD_MODE_PUSH:
357 res = gst_ghost_pad_internal_activate_push_default (pad, parent, active);
360 GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
368 gst_ghost_pad_activate_push_default (GstPad * pad, GstObject * parent,
374 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
376 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, proxy internal",
377 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
379 /* just activate the internal pad */
380 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
381 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
382 GST_PROXY_PAD_RELEASE_INTERNAL (other);
388 gst_ghost_pad_activate_pull_default (GstPad * pad, GstObject * parent,
394 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
395 GST_DEBUG_PAD_NAME (pad));
397 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
398 /* the ghostpad is SRC and activated in pull mode by its peer, call the
399 * activation function of the internal pad to propagate the activation
401 GST_LOG_OBJECT (pad, "pad is src, activate internal");
402 GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
403 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
404 GST_PROXY_PAD_RELEASE_INTERNAL (other);
405 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
406 /* We are SINK and activated by the internal pad, propagate activation
407 * upstream because we hold a ref to the upstream peer */
408 GST_LOG_OBJECT (pad, "activating peer");
409 ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
410 gst_object_unref (other);
412 /* no peer, we fail */
413 GST_LOG_OBJECT (pad, "pad not src and no peer, failing");
421 * gst_ghost_pad_activate_mode_default:
422 * @pad: the #GstPad to activate or deactivate.
423 * @parent: (allow-none): the parent of @pad or NULL
424 * @mode: the requested activation mode
425 * @active: whether the pad should be active or not.
427 * Invoke the default activate mode function of a ghost pad.
429 * Returns: %TRUE if the operation was successful.
432 gst_ghost_pad_activate_mode_default (GstPad * pad, GstObject * parent,
433 GstPadMode mode, gboolean active)
437 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
440 case GST_PAD_MODE_PULL:
441 res = gst_ghost_pad_activate_pull_default (pad, parent, active);
443 case GST_PAD_MODE_PUSH:
444 res = gst_ghost_pad_activate_push_default (pad, parent, active);
447 GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
455 gst_ghost_pad_class_init (GstGhostPadClass * klass)
457 GObjectClass *gobject_class = (GObjectClass *) klass;
459 g_type_class_add_private (klass, sizeof (GstGhostPadPrivate));
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) = G_TYPE_INSTANCE_GET_PRIVATE (pad,
471 GST_TYPE_GHOST_PAD, GstGhostPadPrivate);
473 gst_pad_set_activatemode_function (GST_PAD_CAST (pad),
474 gst_ghost_pad_activate_mode_default);
478 gst_ghost_pad_dispose (GObject * object)
484 pad = GST_PAD (object);
486 GST_DEBUG_OBJECT (pad, "dispose");
488 gst_ghost_pad_set_target (GST_GHOST_PAD (pad), NULL);
490 /* Unlink here so that gst_pad_dispose doesn't. That would lead to a call to
491 * gst_ghost_pad_unlink_default when the ghost pad is in an inconsistent state */
492 peer = gst_pad_get_peer (pad);
494 if (GST_PAD_IS_SRC (pad))
495 gst_pad_unlink (pad, peer);
497 gst_pad_unlink (peer, pad);
499 gst_object_unref (peer);
502 GST_OBJECT_LOCK (pad);
503 internal = GST_PROXY_PAD_INTERNAL (pad);
505 gst_pad_set_activatemode_function (internal, NULL);
507 /* disposes of the internal pad, since the ghostpad is the only possible object
508 * that has a refcount on the internal pad. */
509 gst_object_unparent (GST_OBJECT_CAST (internal));
510 GST_PROXY_PAD_INTERNAL (pad) = NULL;
512 GST_OBJECT_UNLOCK (pad);
514 G_OBJECT_CLASS (gst_ghost_pad_parent_class)->dispose (object);
518 * gst_ghost_pad_construct:
519 * @gpad: the newly allocated ghost pad
521 * Finish initialization of a newly allocated ghost pad.
523 * This function is most useful in language bindings and when subclassing
524 * #GstGhostPad; plugin and application developers normally will not call this
525 * function. Call this function directly after a call to g_object_new
526 * (GST_TYPE_GHOST_PAD, "direction", @dir, ..., NULL).
528 * Returns: %TRUE if the construction succeeds, %FALSE otherwise.
531 gst_ghost_pad_construct (GstGhostPad * gpad)
533 GstPadDirection dir, otherdir;
534 GstPadTemplate *templ;
535 GstPad *pad, *internal;
537 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
538 g_return_val_if_fail (GST_GHOST_PAD_PRIVATE (gpad)->constructed == FALSE,
541 g_object_get (gpad, "direction", &dir, "template", &templ, NULL);
543 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, FALSE);
545 pad = GST_PAD (gpad);
547 /* Set directional padfunctions for ghostpad */
548 if (dir == GST_PAD_SINK) {
549 gst_pad_set_chain_function (pad, gst_proxy_pad_chain_default);
550 gst_pad_set_chain_list_function (pad, gst_proxy_pad_chain_list_default);
552 gst_pad_set_getrange_function (pad, gst_proxy_pad_getrange_default);
555 /* INTERNAL PAD, it always exists and is child of the ghostpad */
556 otherdir = (dir == GST_PAD_SRC) ? GST_PAD_SINK : GST_PAD_SRC;
559 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
560 "direction", otherdir, "template", templ, NULL);
561 /* release ref obtained via g_object_get */
562 gst_object_unref (templ);
565 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
566 "direction", otherdir, NULL);
568 GST_PAD_UNSET_FLUSHING (internal);
570 /* Set directional padfunctions for internal pad */
571 if (dir == GST_PAD_SRC) {
572 gst_pad_set_chain_function (internal, gst_proxy_pad_chain_default);
573 gst_pad_set_chain_list_function (internal,
574 gst_proxy_pad_chain_list_default);
576 gst_pad_set_getrange_function (internal, gst_proxy_pad_getrange_default);
579 GST_OBJECT_LOCK (pad);
581 /* now make the ghostpad a parent of the internal pad */
582 if (!gst_object_set_parent (GST_OBJECT_CAST (internal),
583 GST_OBJECT_CAST (pad)))
586 /* The ghostpad is the parent of the internal pad and is the only object that
587 * can have a refcount on the internal pad.
588 * At this point, the GstGhostPad has a refcount of 1, and the internal pad has
590 * When the refcount of the GstGhostPad drops to 0, the ghostpad will dispose
591 * its refcount on the internal pad in the dispose method by un-parenting it.
592 * This is why we don't take extra refcounts in the assignments below
594 GST_PROXY_PAD_INTERNAL (pad) = internal;
595 GST_PROXY_PAD_INTERNAL (internal) = pad;
597 /* special activation functions for the internal pad */
598 gst_pad_set_activatemode_function (internal,
599 gst_ghost_pad_internal_activate_mode_default);
601 GST_OBJECT_UNLOCK (pad);
603 GST_GHOST_PAD_PRIVATE (gpad)->constructed = TRUE;
609 GST_WARNING_OBJECT (gpad, "Could not set internal pad %s:%s",
610 GST_DEBUG_PAD_NAME (internal));
611 g_critical ("Could not set internal pad %s:%s",
612 GST_DEBUG_PAD_NAME (internal));
613 GST_OBJECT_UNLOCK (pad);
614 gst_object_unref (internal);
620 gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
621 GstPadTemplate * templ)
625 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
627 /* OBJECT CREATION */
629 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
630 "direction", dir, "template", templ, NULL);
632 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
633 "direction", dir, NULL);
636 if (!gst_ghost_pad_construct (ret))
637 goto construct_failed;
639 return GST_PAD_CAST (ret);
643 gst_object_unref (ret);
648 * gst_ghost_pad_new_no_target:
649 * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
650 * @dir: the direction of the ghostpad
652 * Create a new ghostpad without a target with the given direction.
653 * A target can be set on the ghostpad later with the
654 * gst_ghost_pad_set_target() function.
656 * The created ghostpad will not have a padtemplate.
658 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
661 gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
665 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
667 GST_LOG ("name:%s, direction:%d", GST_STR_NULL (name), dir);
669 ret = gst_ghost_pad_new_full (name, dir, NULL);
676 * @name: (allow-none): the name of the new pad, or NULL to assign a default name
677 * @target: (transfer none): the pad to ghost.
679 * Create a new ghostpad with @target as the target. The direction will be taken
680 * from the target pad. @target must be unlinked.
682 * Will ref the target.
684 * Returns: (transfer floating): a new #GstPad, or NULL in case of an error.
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): a new #GstPad, or NULL in case of an error.
728 gst_ghost_pad_new_from_template (const gchar * name, GstPad * target,
729 GstPadTemplate * templ)
733 g_return_val_if_fail (GST_IS_PAD (target), NULL);
734 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
735 g_return_val_if_fail (templ != NULL, NULL);
736 g_return_val_if_fail (GST_PAD_TEMPLATE_DIRECTION (templ) ==
737 GST_PAD_DIRECTION (target), NULL);
739 GST_LOG ("name:%s, target:%s:%s, templ:%p", GST_STR_NULL (name),
740 GST_DEBUG_PAD_NAME (target), templ);
742 if ((ret = gst_ghost_pad_new_full (name, GST_PAD_DIRECTION (target), templ)))
743 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
744 goto set_target_failed;
751 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
752 GST_DEBUG_PAD_NAME (target));
753 gst_object_unref (ret);
759 * gst_ghost_pad_new_no_target_from_template:
760 * @name: (allow-none): the name of the new pad, or NULL to assign a default name
761 * @templ: (transfer none): the #GstPadTemplate to create the ghostpad from.
763 * Create a new ghostpad based on @templ, without setting a target. The
764 * direction will be taken from the @templ.
766 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
769 gst_ghost_pad_new_no_target_from_template (const gchar * name,
770 GstPadTemplate * templ)
774 g_return_val_if_fail (templ != NULL, NULL);
777 gst_ghost_pad_new_full (name, GST_PAD_TEMPLATE_DIRECTION (templ), templ);
783 * gst_ghost_pad_get_target:
784 * @gpad: the #GstGhostPad
786 * Get the target pad of @gpad. Unref target pad after usage.
788 * Returns: (transfer full): the target #GstPad, can be NULL if the ghostpad
789 * has no target set. Unref target pad after usage.
792 gst_ghost_pad_get_target (GstGhostPad * gpad)
796 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), NULL);
798 ret = gst_proxy_pad_get_target (GST_PAD_CAST (gpad));
800 GST_DEBUG_OBJECT (gpad, "get target %s:%s", GST_DEBUG_PAD_NAME (ret));
806 * gst_ghost_pad_set_target:
807 * @gpad: the #GstGhostPad
808 * @newtarget: (transfer none) (allow-none): the new pad target
810 * Set the new target of the ghostpad @gpad. Any existing target
811 * is unlinked and links to the new target are established. if @newtarget is
812 * NULL the target will be cleared.
814 * Returns: (transfer full): TRUE if the new target could be set. This function
815 * can return FALSE when the internal pads could not be linked.
818 gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
822 GstPadLinkReturn lret;
824 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
825 g_return_val_if_fail (GST_PAD_CAST (gpad) != newtarget, FALSE);
826 g_return_val_if_fail (newtarget != GST_PROXY_PAD_INTERNAL (gpad), FALSE);
828 GST_OBJECT_LOCK (gpad);
829 internal = GST_PROXY_PAD_INTERNAL (gpad);
832 GST_DEBUG_OBJECT (gpad, "set target %s:%s", GST_DEBUG_PAD_NAME (newtarget));
834 GST_DEBUG_OBJECT (gpad, "clearing target");
836 /* clear old target */
837 if ((oldtarget = gst_pad_get_peer (internal))) {
838 GST_OBJECT_UNLOCK (gpad);
840 /* unlink internal pad */
841 if (GST_PAD_IS_SRC (internal))
842 gst_pad_unlink (internal, oldtarget);
844 gst_pad_unlink (oldtarget, internal);
846 gst_object_unref (oldtarget);
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:%s",
873 gst_pad_link_get_name (lret));