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., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, 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 struct _GstProxyPadPrivate
65 G_DEFINE_TYPE (GstProxyPad, gst_proxy_pad, GST_TYPE_PAD);
67 static GstPad *gst_proxy_pad_get_target (GstPad * pad);
70 * gst_proxy_pad_event_default:
71 * @pad: a #GstPad to push the event to.
72 * @event: (transfer full): the #GstEvent to send to the pad.
74 * Invoke the default event of the proxy pad.
76 * Returns: TRUE if the event was handled.
81 gst_proxy_pad_event_default (GstPad * pad, GstEvent * event)
86 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
87 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
89 internal = GST_PROXY_PAD_INTERNAL (pad);
90 res = gst_pad_push_event (internal, event);
96 gst_proxy_pad_query_caps (GstPad * pad, GstQuery * query)
101 GstPadTemplate *templ;
103 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
105 templ = GST_PAD_PAD_TEMPLATE (pad);
106 target = gst_proxy_pad_get_target (pad);
108 /* if we have a real target, proxy the call */
109 res = gst_pad_query (target, query);
111 GST_DEBUG_OBJECT (pad, "get caps of target %s:%s : %" GST_PTR_FORMAT,
112 GST_DEBUG_PAD_NAME (target), query);
114 gst_object_unref (target);
116 /* filter against the template */
120 filt = GST_PAD_TEMPLATE_CAPS (templ);
122 gst_query_parse_caps_result (query, &result);
123 tmp = gst_caps_intersect_full (result, filt, GST_CAPS_INTERSECT_FIRST);
124 gst_query_set_caps_result (query, tmp);
125 GST_DEBUG_OBJECT (pad,
126 "filtered against template gives %" GST_PTR_FORMAT, tmp);
127 gst_caps_unref (tmp);
135 gst_query_parse_caps (query, &filter);
137 /* else, if we have a template, use its caps. */
139 result = GST_PAD_TEMPLATE_CAPS (templ);
140 GST_DEBUG_OBJECT (pad,
141 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
145 GstCaps *intersection;
147 GST_DEBUG_OBJECT (pad, "intersect with filter");
149 gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST);
150 gst_query_set_caps_result (query, intersection);
151 gst_caps_unref (intersection);
153 gst_query_set_caps_result (query, result);
158 /* If there's a filter, return that */
159 if (filter != NULL) {
160 GST_DEBUG_OBJECT (pad, "return filter");
161 gst_query_set_caps_result (query, filter);
165 /* last resort, any caps */
166 GST_DEBUG_OBJECT (pad, "pad has no template, returning ANY");
167 result = gst_caps_new_any ();
168 gst_query_set_caps_result (query, result);
169 gst_caps_unref (result);
177 * gst_proxy_pad_query_default:
178 * @pad: a #GstPad to invoke the default query on.
179 * @query: (transfer none): the #GstQuery to perform.
181 * Invoke the default query function of the proxy pad.
183 * Returns: TRUE if the query could be performed.
188 gst_proxy_pad_query_default (GstPad * pad, GstQuery * query)
193 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
194 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
197 switch (GST_QUERY_TYPE (query)) {
198 case GST_QUERY_ACCEPT_CAPS:
200 target = gst_proxy_pad_get_target (pad);
202 res = gst_pad_query (target, query);
203 gst_object_unref (target);
205 GST_DEBUG_OBJECT (pad, "no target");
206 /* We don't have a target, we return TRUE and we assume that any future
207 * target will be able to deal with any configured caps. */
214 res = gst_proxy_pad_query_caps (pad, query);
219 target = gst_proxy_pad_get_target (pad);
221 res = gst_pad_query (target, query);
222 gst_object_unref (target);
224 GST_DEBUG_OBJECT (pad, "no target pad");
234 * gst_proyx_pad_iterate_internal_links_default:
235 * @pad: the #GstPad to get the internal links of.
237 * Invoke the default iterate internal links function of the proxy pad.
239 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
240 * returned pad with gst_object_unref().
245 gst_proxy_pad_iterate_internal_links_default (GstPad * pad)
247 GstIterator *res = NULL;
251 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
253 internal = GST_PROXY_PAD_INTERNAL (pad);
254 g_value_init (&v, GST_TYPE_PAD);
255 g_value_set_object (&v, internal);
256 res = gst_iterator_new_single (GST_TYPE_PAD, &v);
263 * gst_proxy_pad_chain_default:
264 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
265 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
268 * Invoke the default chain function of the proxy pad.
270 * Returns: a #GstFlowReturn from the pad.
275 gst_proxy_pad_chain_default (GstPad * pad, GstBuffer * buffer)
280 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
281 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
283 internal = GST_PROXY_PAD_INTERNAL (pad);
284 res = gst_pad_push (internal, buffer);
290 * gst_proxy_pad_chain_list_default:
291 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
292 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
295 * Invoke the default chain list function of the proxy pad.
297 * Returns: a #GstFlowReturn from the pad.
302 gst_proxy_pad_chain_list_default (GstPad * pad, GstBufferList * list)
307 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
308 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
310 internal = GST_PROXY_PAD_INTERNAL (pad);
311 res = gst_pad_push_list (internal, list);
317 * gst_proxy_pad_get_range_default:
318 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
319 * @offset: The start offset of the buffer
320 * @size: The length of the buffer
321 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
322 * returns #GST_FLOW_ERROR if %NULL.
324 * Invoke the default getrange function of the proxy pad.
326 * Returns: a #GstFlowReturn from the pad.
331 gst_proxy_pad_getrange_default (GstPad * pad, guint64 offset, guint size,
337 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
338 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
340 internal = GST_PROXY_PAD_INTERNAL (pad);
341 res = gst_pad_pull_range (internal, offset, size, buffer);
347 gst_proxy_pad_get_target (GstPad * pad)
351 GST_OBJECT_LOCK (pad);
352 target = GST_PROXY_PAD_TARGET (pad);
354 gst_object_ref (target);
355 GST_OBJECT_UNLOCK (pad);
361 * gst_proxy_pad_get_internal:
362 * @pad: the #GstProxyPad
364 * Get the internal pad of @pad. Unref target pad after usage.
366 * The internal pad of a #GstGhostPad is the internally used
367 * pad of opposite direction, which is used to link to the target.
369 * Returns: (transfer full): the target #GstProxyPad, can be NULL.
370 * Unref target pad after usage.
375 gst_proxy_pad_get_internal (GstProxyPad * pad)
379 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
381 GST_OBJECT_LOCK (pad);
382 internal = GST_PROXY_PAD_INTERNAL (pad);
384 gst_object_ref (internal);
385 GST_OBJECT_UNLOCK (pad);
387 return GST_PROXY_PAD_CAST (internal);
391 * gst_proxy_pad_unlink_default:
392 * @pad: a #GstPad to unlink
394 * Invoke the default unlink function of the proxy pad.
399 gst_proxy_pad_unlink_default (GstPad * pad)
401 /* nothing to do anymore */
402 GST_DEBUG_OBJECT (pad, "pad is unlinked");
406 gst_proxy_pad_class_init (GstProxyPadClass * klass)
408 g_type_class_add_private (klass, sizeof (GstProxyPadPrivate));
410 /* Register common function pointer descriptions */
411 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_event_default);
412 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_query_default);
413 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_iterate_internal_links_default);
414 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_unlink_default);
415 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_default);
416 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_list_default);
417 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getrange_default);
421 gst_proxy_pad_init (GstProxyPad * ppad)
423 GstPad *pad = (GstPad *) ppad;
425 GST_PROXY_PAD_PRIVATE (ppad) = G_TYPE_INSTANCE_GET_PRIVATE (ppad,
426 GST_TYPE_PROXY_PAD, GstProxyPadPrivate);
428 gst_pad_set_event_function (pad, gst_proxy_pad_event_default);
429 gst_pad_set_query_function (pad, gst_proxy_pad_query_default);
430 gst_pad_set_iterate_internal_links_function (pad,
431 gst_proxy_pad_iterate_internal_links_default);
433 gst_pad_set_unlink_function (pad, gst_proxy_pad_unlink_default);
437 /***********************************************************************
438 * Ghost pads, implemented as a pair of proxy pads (sort of)
442 #define GST_GHOST_PAD_PRIVATE(obj) (GST_GHOST_PAD_CAST (obj)->priv)
444 struct _GstGhostPadPrivate
446 /* with PROXY_LOCK */
447 gboolean constructed;
450 G_DEFINE_TYPE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
452 static void gst_ghost_pad_dispose (GObject * object);
455 * gst_ghost_pad_internal_activate_push_default:
456 * @pad: the #GstPad to activate or deactivate.
457 * @active: whether the pad should be active or not.
459 * Invoke the default activate push function of a proxy pad that is
460 * owned by a ghost pad.
462 * Returns: %TRUE if the operation was successful.
467 gst_ghost_pad_internal_activate_push_default (GstPad * pad, gboolean active)
472 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
474 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, we're ok",
475 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
477 /* in both cases (SRC and SINK) we activate just the internal pad. The targets
478 * will be activated later (or already in case of a ghost sinkpad). */
479 other = GST_PROXY_PAD_INTERNAL (pad);
480 ret = gst_pad_activate_push (other, active);
486 * gst_ghost_pad_internal_activate_pull_default:
487 * @pad: the #GstPad to activate or deactivate.
488 * @active: whether the pad should be active or not.
490 * Invoke the default activate pull function of a proxy pad that is
491 * owned by a ghost pad.
493 * Returns: %TRUE if the operation was successful.
498 gst_ghost_pad_internal_activate_pull_default (GstPad * pad, gboolean active)
503 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
505 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
506 GST_DEBUG_PAD_NAME (pad));
508 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
509 /* we are activated in pull mode by our peer element, which is a sinkpad
510 * that wants to operate in pull mode. This activation has to propagate
511 * upstream through the pipeline. We call the internal activation function,
512 * which will trigger gst_ghost_pad_activate_pull_default, which propagates even
513 * further upstream */
514 GST_LOG_OBJECT (pad, "pad is src, activate internal");
515 other = GST_PROXY_PAD_INTERNAL (pad);
516 ret = gst_pad_activate_pull (other, active);
517 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
518 /* We are SINK, the ghostpad is SRC, we propagate the activation upstream
519 * since we hold a pointer to the upstream peer. */
520 GST_LOG_OBJECT (pad, "activating peer");
521 ret = gst_pad_activate_pull (other, active);
522 gst_object_unref (other);
524 /* this is failure, we can't activate pull if there is no peer */
525 GST_LOG_OBJECT (pad, "not src and no peer, failing");
533 * gst_ghost_pad_activate_push_default:
534 * @pad: the #GstPad to activate or deactivate.
535 * @active: whether the pad should be active or not.
537 * Invoke the default activate push function of a ghost pad.
539 * Returns: %TRUE if the operation was successful.
544 gst_ghost_pad_activate_push_default (GstPad * pad, gboolean active)
549 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
551 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, proxy internal",
552 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
554 /* just activate the internal pad */
555 other = GST_PROXY_PAD_INTERNAL (pad);
556 ret = gst_pad_activate_push (other, active);
562 * gst_ghost_pad_activate_pull_default:
563 * @pad: the #GstPad to activate or deactivate.
564 * @active: whether the pad should be active or not.
566 * Invoke the default activate pull function of a ghost pad.
568 * Returns: %TRUE if the operation was successful.
573 gst_ghost_pad_activate_pull_default (GstPad * pad, gboolean active)
578 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
580 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
581 GST_DEBUG_PAD_NAME (pad));
583 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
584 /* the ghostpad is SRC and activated in pull mode by its peer, call the
585 * activation function of the internal pad to propagate the activation
587 GST_LOG_OBJECT (pad, "pad is src, activate internal");
588 other = GST_PROXY_PAD_INTERNAL (pad);
589 ret = gst_pad_activate_pull (other, active);
590 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
591 /* We are SINK and activated by the internal pad, propagate activation
592 * upstream because we hold a ref to the upstream peer */
593 GST_LOG_OBJECT (pad, "activating peer");
594 ret = gst_pad_activate_pull (other, active);
595 gst_object_unref (other);
597 /* no peer, we fail */
598 GST_LOG_OBJECT (pad, "pad not src and no peer, failing");
606 * gst_ghost_pad_link_default:
607 * @pad: the #GstPad to link.
608 * @peer: the #GstPad peer
610 * Invoke the default link function of a ghost pad.
612 * Returns: #GstPadLinkReturn of the operation
617 gst_ghost_pad_link_default (GstPad * pad, GstPad * peer)
619 GstPadLinkReturn ret;
621 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), GST_PAD_LINK_REFUSED);
622 g_return_val_if_fail (GST_IS_PAD (peer), GST_PAD_LINK_REFUSED);
624 GST_DEBUG_OBJECT (pad, "linking ghostpad");
626 ret = GST_PAD_LINK_OK;
627 /* if we are a source pad, we should call the peer link function
628 * if the peer has one, see design docs. */
629 if (GST_PAD_IS_SRC (pad)) {
630 if (GST_PAD_LINKFUNC (peer)) {
631 ret = GST_PAD_LINKFUNC (peer) (peer, pad);
632 if (ret != GST_PAD_LINK_OK)
633 GST_DEBUG_OBJECT (pad, "linking failed");
640 * gst_ghost_pad_unlink_default:
641 * @pad: the #GstPad to link.
643 * Invoke the default unlink function of a ghost pad.
648 gst_ghost_pad_unlink_default (GstPad * pad)
650 g_return_if_fail (GST_IS_GHOST_PAD (pad));
652 GST_DEBUG_OBJECT (pad, "unlinking ghostpad");
656 gst_ghost_pad_class_init (GstGhostPadClass * klass)
658 GObjectClass *gobject_class = (GObjectClass *) klass;
660 g_type_class_add_private (klass, sizeof (GstGhostPadPrivate));
662 gobject_class->dispose = gst_ghost_pad_dispose;
664 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_pull_default);
665 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_push_default);
666 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_link_default);
670 gst_ghost_pad_init (GstGhostPad * pad)
672 GST_GHOST_PAD_PRIVATE (pad) = G_TYPE_INSTANCE_GET_PRIVATE (pad,
673 GST_TYPE_GHOST_PAD, GstGhostPadPrivate);
675 gst_pad_set_activatepull_function (GST_PAD_CAST (pad),
676 gst_ghost_pad_activate_pull_default);
677 gst_pad_set_activatepush_function (GST_PAD_CAST (pad),
678 gst_ghost_pad_activate_push_default);
682 gst_ghost_pad_dispose (GObject * object)
688 pad = GST_PAD (object);
690 GST_DEBUG_OBJECT (pad, "dispose");
692 gst_ghost_pad_set_target (GST_GHOST_PAD (pad), NULL);
694 /* Unlink here so that gst_pad_dispose doesn't. That would lead to a call to
695 * gst_ghost_pad_unlink_default when the ghost pad is in an inconsistent state */
696 peer = gst_pad_get_peer (pad);
698 if (GST_PAD_IS_SRC (pad))
699 gst_pad_unlink (pad, peer);
701 gst_pad_unlink (peer, pad);
703 gst_object_unref (peer);
706 GST_OBJECT_LOCK (pad);
707 internal = GST_PROXY_PAD_INTERNAL (pad);
709 gst_pad_set_activatepull_function (internal, NULL);
710 gst_pad_set_activatepush_function (internal, NULL);
712 /* disposes of the internal pad, since the ghostpad is the only possible object
713 * that has a refcount on the internal pad. */
714 gst_object_unparent (GST_OBJECT_CAST (internal));
715 GST_PROXY_PAD_INTERNAL (pad) = NULL;
717 GST_OBJECT_UNLOCK (pad);
719 G_OBJECT_CLASS (gst_ghost_pad_parent_class)->dispose (object);
723 * gst_ghost_pad_construct:
724 * @gpad: the newly allocated ghost pad
726 * Finish initialization of a newly allocated ghost pad.
728 * This function is most useful in language bindings and when subclassing
729 * #GstGhostPad; plugin and application developers normally will not call this
730 * function. Call this function directly after a call to g_object_new
731 * (GST_TYPE_GHOST_PAD, "direction", @dir, ..., NULL).
733 * Returns: %TRUE if the construction succeeds, %FALSE otherwise.
738 gst_ghost_pad_construct (GstGhostPad * gpad)
740 GstPadDirection dir, otherdir;
741 GstPadTemplate *templ;
742 GstPad *pad, *internal;
744 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
745 g_return_val_if_fail (GST_GHOST_PAD_PRIVATE (gpad)->constructed == FALSE,
748 g_object_get (gpad, "direction", &dir, "template", &templ, NULL);
750 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, FALSE);
752 pad = GST_PAD (gpad);
754 /* Set directional padfunctions for ghostpad */
755 if (dir == GST_PAD_SINK) {
756 gst_pad_set_chain_function (pad, gst_proxy_pad_chain_default);
757 gst_pad_set_chain_list_function (pad, gst_proxy_pad_chain_list_default);
759 gst_pad_set_getrange_function (pad, gst_proxy_pad_getrange_default);
762 /* link/unlink functions */
763 gst_pad_set_link_function (pad, gst_ghost_pad_link_default);
764 gst_pad_set_unlink_function (pad, gst_ghost_pad_unlink_default);
766 /* INTERNAL PAD, it always exists and is child of the ghostpad */
767 otherdir = (dir == GST_PAD_SRC) ? GST_PAD_SINK : GST_PAD_SRC;
770 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
771 "direction", otherdir, "template", templ, NULL);
772 /* release ref obtained via g_object_get */
773 gst_object_unref (templ);
776 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
777 "direction", otherdir, NULL);
779 GST_PAD_UNSET_FLUSHING (internal);
781 /* Set directional padfunctions for internal pad */
782 if (dir == GST_PAD_SRC) {
783 gst_pad_set_chain_function (internal, gst_proxy_pad_chain_default);
784 gst_pad_set_chain_list_function (internal,
785 gst_proxy_pad_chain_list_default);
787 gst_pad_set_getrange_function (internal, gst_proxy_pad_getrange_default);
790 GST_OBJECT_LOCK (pad);
792 /* now make the ghostpad a parent of the internal pad */
793 if (!gst_object_set_parent (GST_OBJECT_CAST (internal),
794 GST_OBJECT_CAST (pad)))
797 /* The ghostpad is the parent of the internal pad and is the only object that
798 * can have a refcount on the internal pad.
799 * At this point, the GstGhostPad has a refcount of 1, and the internal pad has
801 * When the refcount of the GstGhostPad drops to 0, the ghostpad will dispose
802 * its refcount on the internal pad in the dispose method by un-parenting it.
803 * This is why we don't take extra refcounts in the assignments below
805 GST_PROXY_PAD_INTERNAL (pad) = internal;
806 GST_PROXY_PAD_INTERNAL (internal) = pad;
808 /* special activation functions for the internal pad */
809 gst_pad_set_activatepull_function (internal,
810 gst_ghost_pad_internal_activate_pull_default);
811 gst_pad_set_activatepush_function (internal,
812 gst_ghost_pad_internal_activate_push_default);
814 GST_OBJECT_UNLOCK (pad);
816 GST_GHOST_PAD_PRIVATE (gpad)->constructed = TRUE;
822 GST_WARNING_OBJECT (gpad, "Could not set internal pad %s:%s",
823 GST_DEBUG_PAD_NAME (internal));
824 g_critical ("Could not set internal pad %s:%s",
825 GST_DEBUG_PAD_NAME (internal));
826 GST_OBJECT_UNLOCK (pad);
827 gst_object_unref (internal);
833 gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
834 GstPadTemplate * templ)
838 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
840 /* OBJECT CREATION */
842 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
843 "direction", dir, "template", templ, NULL);
845 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
846 "direction", dir, NULL);
849 if (!gst_ghost_pad_construct (ret))
850 goto construct_failed;
852 return GST_PAD_CAST (ret);
856 gst_object_unref (ret);
861 * gst_ghost_pad_new_no_target:
862 * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
863 * @dir: the direction of the ghostpad
865 * Create a new ghostpad without a target with the given direction.
866 * A target can be set on the ghostpad later with the
867 * gst_ghost_pad_set_target() function.
869 * The created ghostpad will not have a padtemplate.
871 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
874 gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
878 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
880 GST_LOG ("name:%s, direction:%d", GST_STR_NULL (name), dir);
882 ret = gst_ghost_pad_new_full (name, dir, NULL);
889 * @name: (allow-none): the name of the new pad, or NULL to assign a default name
890 * @target: (transfer none): the pad to ghost.
892 * Create a new ghostpad with @target as the target. The direction will be taken
893 * from the target pad. @target must be unlinked.
895 * Will ref the target.
897 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
900 gst_ghost_pad_new (const gchar * name, GstPad * target)
904 g_return_val_if_fail (GST_IS_PAD (target), NULL);
905 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
907 GST_LOG ("name:%s, target:%s:%s", GST_STR_NULL (name),
908 GST_DEBUG_PAD_NAME (target));
910 if ((ret = gst_ghost_pad_new_no_target (name, GST_PAD_DIRECTION (target))))
911 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
912 goto set_target_failed;
919 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
920 GST_DEBUG_PAD_NAME (target));
921 gst_object_unref (ret);
927 * gst_ghost_pad_new_from_template:
928 * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
929 * @target: (transfer none): the pad to ghost.
930 * @templ: (transfer none): the #GstPadTemplate to use on the ghostpad.
932 * Create a new ghostpad with @target as the target. The direction will be taken
933 * from the target pad. The template used on the ghostpad will be @template.
935 * Will ref the target.
937 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
943 gst_ghost_pad_new_from_template (const gchar * name, GstPad * target,
944 GstPadTemplate * templ)
948 g_return_val_if_fail (GST_IS_PAD (target), NULL);
949 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
950 g_return_val_if_fail (templ != NULL, NULL);
951 g_return_val_if_fail (GST_PAD_TEMPLATE_DIRECTION (templ) ==
952 GST_PAD_DIRECTION (target), NULL);
954 GST_LOG ("name:%s, target:%s:%s, templ:%p", GST_STR_NULL (name),
955 GST_DEBUG_PAD_NAME (target), templ);
957 if ((ret = gst_ghost_pad_new_full (name, GST_PAD_DIRECTION (target), templ)))
958 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
959 goto set_target_failed;
966 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
967 GST_DEBUG_PAD_NAME (target));
968 gst_object_unref (ret);
974 * gst_ghost_pad_new_no_target_from_template:
975 * @name: (allow-none): the name of the new pad, or NULL to assign a default name
976 * @templ: (transfer none): the #GstPadTemplate to create the ghostpad from.
978 * Create a new ghostpad based on @templ, without setting a target. The
979 * direction will be taken from the @templ.
981 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
986 gst_ghost_pad_new_no_target_from_template (const gchar * name,
987 GstPadTemplate * templ)
991 g_return_val_if_fail (templ != NULL, NULL);
994 gst_ghost_pad_new_full (name, GST_PAD_TEMPLATE_DIRECTION (templ), templ);
1000 * gst_ghost_pad_get_target:
1001 * @gpad: the #GstGhostPad
1003 * Get the target pad of @gpad. Unref target pad after usage.
1005 * Returns: (transfer full): the target #GstPad, can be NULL if the ghostpad
1006 * has no target set. Unref target pad after usage.
1009 gst_ghost_pad_get_target (GstGhostPad * gpad)
1013 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), NULL);
1015 ret = gst_proxy_pad_get_target (GST_PAD_CAST (gpad));
1017 GST_DEBUG_OBJECT (gpad, "get target %s:%s", GST_DEBUG_PAD_NAME (ret));
1023 * gst_ghost_pad_set_target:
1024 * @gpad: the #GstGhostPad
1025 * @newtarget: (transfer none) (allow-none): the new pad target
1027 * Set the new target of the ghostpad @gpad. Any existing target
1028 * is unlinked and links to the new target are established. if @newtarget is
1029 * NULL the target will be cleared.
1031 * Returns: (transfer full): TRUE if the new target could be set. This function
1032 * can return FALSE when the internal pads could not be linked.
1035 gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
1039 GstPadLinkReturn lret;
1041 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
1042 g_return_val_if_fail (GST_PAD_CAST (gpad) != newtarget, FALSE);
1043 g_return_val_if_fail (newtarget != GST_PROXY_PAD_INTERNAL (gpad), FALSE);
1045 /* no need for locking, the internal pad's lifecycle is directly linked to the
1047 internal = GST_PROXY_PAD_INTERNAL (gpad);
1050 GST_DEBUG_OBJECT (gpad, "set target %s:%s", GST_DEBUG_PAD_NAME (newtarget));
1052 GST_DEBUG_OBJECT (gpad, "clearing target");
1054 /* clear old target */
1055 GST_OBJECT_LOCK (gpad);
1056 if ((oldtarget = GST_PROXY_PAD_TARGET (gpad))) {
1057 GST_OBJECT_UNLOCK (gpad);
1059 /* unlink internal pad */
1060 if (GST_PAD_IS_SRC (internal))
1061 gst_pad_unlink (internal, oldtarget);
1063 gst_pad_unlink (oldtarget, internal);
1065 GST_OBJECT_UNLOCK (gpad);
1069 /* and link to internal pad without any checks */
1070 GST_DEBUG_OBJECT (gpad, "connecting internal pad to target");
1072 if (GST_PAD_IS_SRC (internal))
1074 gst_pad_link_full (internal, newtarget, GST_PAD_LINK_CHECK_NOTHING);
1077 gst_pad_link_full (newtarget, internal, GST_PAD_LINK_CHECK_NOTHING);
1079 if (lret != GST_PAD_LINK_OK)
1088 GST_WARNING_OBJECT (gpad, "could not link internal and target, reason:%d",