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_default:
97 * @pad: a #GstPad to invoke the default query on.
98 * @query: (transfer none): the #GstQuery to perform.
100 * Invoke the default query function of the proxy pad.
102 * Returns: TRUE if the query could be performed.
107 gst_proxy_pad_query_default (GstPad * pad, GstQuery * query)
111 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
112 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
114 switch (GST_QUERY_TYPE (query)) {
119 if (!(target = gst_proxy_pad_get_target (pad)))
122 res = gst_pad_query (target, query);
123 gst_object_unref (target);
133 GST_DEBUG_OBJECT (pad, "no target pad");
139 * gst_proyx_pad_iterate_internal_links_default:
140 * @pad: the #GstPad to get the internal links of.
142 * Invoke the default iterate internal links function of the proxy pad.
144 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
145 * returned pad with gst_object_unref().
150 gst_proxy_pad_iterate_internal_links_default (GstPad * pad)
152 GstIterator *res = NULL;
156 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
158 internal = GST_PROXY_PAD_INTERNAL (pad);
159 g_value_init (&v, GST_TYPE_PAD);
160 g_value_set_object (&v, internal);
161 res = gst_iterator_new_single (GST_TYPE_PAD, &v);
168 * gst_proxy_pad_chain_default:
169 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
170 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
173 * Invoke the default chain function of the proxy pad.
175 * Returns: a #GstFlowReturn from the pad.
180 gst_proxy_pad_chain_default (GstPad * pad, GstBuffer * buffer)
185 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
186 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
188 internal = GST_PROXY_PAD_INTERNAL (pad);
189 res = gst_pad_push (internal, buffer);
195 * gst_proxy_pad_chain_list_default:
196 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
197 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
200 * Invoke the default chain list function of the proxy pad.
202 * Returns: a #GstFlowReturn from the pad.
207 gst_proxy_pad_chain_list_default (GstPad * pad, GstBufferList * list)
212 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
213 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
215 internal = GST_PROXY_PAD_INTERNAL (pad);
216 res = gst_pad_push_list (internal, list);
222 * gst_proxy_pad_get_range_default:
223 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
224 * @offset: The start offset of the buffer
225 * @size: The length of the buffer
226 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
227 * returns #GST_FLOW_ERROR if %NULL.
229 * Invoke the default getrange function of the proxy pad.
231 * Returns: a #GstFlowReturn from the pad.
236 gst_proxy_pad_getrange_default (GstPad * pad, guint64 offset, guint size,
242 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
243 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
245 internal = GST_PROXY_PAD_INTERNAL (pad);
246 res = gst_pad_pull_range (internal, offset, size, buffer);
252 * gst_proxy_pad_getcaps_default:
253 * @pad: a #GstPad to get the capabilities of.
254 * @filter: a #GstCaps filter.
256 * Invoke the default getcaps function of the proxy pad.
258 * Returns: (transfer full): the caps of the pad with incremented ref-count
263 gst_proxy_pad_getcaps_default (GstPad * pad, GstCaps * filter)
267 GstPadTemplate *templ;
269 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
271 templ = GST_PAD_PAD_TEMPLATE (pad);
272 target = gst_proxy_pad_get_target (pad);
274 /* if we have a real target, proxy the call */
275 res = gst_pad_get_caps (target, filter);
277 GST_DEBUG_OBJECT (pad, "get caps of target %s:%s : %" GST_PTR_FORMAT,
278 GST_DEBUG_PAD_NAME (target), res);
280 gst_object_unref (target);
282 /* filter against the template */
286 filt = GST_PAD_TEMPLATE_CAPS (templ);
288 tmp = gst_caps_intersect_full (res, filt, GST_CAPS_INTERSECT_FIRST);
289 gst_caps_unref (res);
291 GST_DEBUG_OBJECT (pad,
292 "filtered against template gives %" GST_PTR_FORMAT, res);
296 /* else, if we have a template, use its caps. */
298 res = GST_PAD_TEMPLATE_CAPS (templ);
299 GST_DEBUG_OBJECT (pad,
300 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, res,
302 res = gst_caps_ref (res);
305 GstCaps *intersection =
306 gst_caps_intersect_full (filter, res, GST_CAPS_INTERSECT_FIRST);
308 gst_caps_unref (res);
315 /* If there's a filter, return that */
316 if (filter != NULL) {
317 res = gst_caps_ref (filter);
321 /* last resort, any caps */
322 GST_DEBUG_OBJECT (pad, "pad has no template, returning ANY");
323 res = gst_caps_new_any ();
331 * gst_proxy_pad_acceptcaps_default:
332 * @pad: a #GstPad to check
333 * @caps: a #GstCaps to check on the pad
335 * Invoke the default acceptcaps function of the proxy pad.
337 * Returns: TRUE if the pad can accept the caps.
342 gst_proxy_pad_acceptcaps_default (GstPad * pad, GstCaps * caps)
347 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
348 g_return_val_if_fail (caps == NULL || GST_IS_CAPS (caps), FALSE);
350 target = gst_proxy_pad_get_target (pad);
352 res = gst_pad_accept_caps (target, caps);
353 gst_object_unref (target);
355 GST_DEBUG_OBJECT (pad, "no target");
356 /* We don't have a target, we return TRUE and we assume that any future
357 * target will be able to deal with any configured caps. */
365 * gst_proxy_pad_fixatecaps_default:
366 * @pad: a #GstPad to fixate
367 * @caps: the #GstCaps to fixate
369 * Invoke the default fixatecaps function of the proxy pad.
374 gst_proxy_pad_fixatecaps_default (GstPad * pad, GstCaps * caps)
378 g_return_if_fail (GST_IS_PROXY_PAD (pad));
379 g_return_if_fail (GST_IS_CAPS (caps));
381 if (!(target = gst_proxy_pad_get_target (pad)))
384 gst_pad_fixate_caps (target, caps);
385 gst_object_unref (target);
392 GST_DEBUG_OBJECT (pad, "no target");
398 gst_proxy_pad_get_target (GstPad * pad)
402 GST_OBJECT_LOCK (pad);
403 target = GST_PROXY_PAD_TARGET (pad);
405 gst_object_ref (target);
406 GST_OBJECT_UNLOCK (pad);
412 * gst_proxy_pad_get_internal:
413 * @pad: the #GstProxyPad
415 * Get the internal pad of @pad. Unref target pad after usage.
417 * The internal pad of a #GstGhostPad is the internally used
418 * pad of opposite direction, which is used to link to the target.
420 * Returns: (transfer full): the target #GstProxyPad, can be NULL.
421 * Unref target pad after usage.
426 gst_proxy_pad_get_internal (GstProxyPad * pad)
430 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
432 GST_OBJECT_LOCK (pad);
433 internal = GST_PROXY_PAD_INTERNAL (pad);
435 gst_object_ref (internal);
436 GST_OBJECT_UNLOCK (pad);
438 return GST_PROXY_PAD_CAST (internal);
442 * gst_proxy_pad_unlink_default:
443 * @pad: a #GstPad to unlink
445 * Invoke the default unlink function of the proxy pad.
450 gst_proxy_pad_unlink_default (GstPad * pad)
452 /* nothing to do anymore */
453 GST_DEBUG_OBJECT (pad, "pad is unlinked");
457 gst_proxy_pad_class_init (GstProxyPadClass * klass)
459 g_type_class_add_private (klass, sizeof (GstProxyPadPrivate));
461 /* Register common function pointer descriptions */
462 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_event_default);
463 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_query_default);
464 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_iterate_internal_links_default);
465 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getcaps_default);
466 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_acceptcaps_default);
467 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_fixatecaps_default);
468 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_unlink_default);
469 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_default);
470 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_list_default);
471 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getrange_default);
475 gst_proxy_pad_init (GstProxyPad * ppad)
477 GstPad *pad = (GstPad *) ppad;
479 GST_PROXY_PAD_PRIVATE (ppad) = G_TYPE_INSTANCE_GET_PRIVATE (ppad,
480 GST_TYPE_PROXY_PAD, GstProxyPadPrivate);
482 gst_pad_set_event_function (pad, gst_proxy_pad_event_default);
483 gst_pad_set_query_function (pad, gst_proxy_pad_query_default);
484 gst_pad_set_iterate_internal_links_function (pad,
485 gst_proxy_pad_iterate_internal_links_default);
487 gst_pad_set_getcaps_function (pad, gst_proxy_pad_getcaps_default);
488 gst_pad_set_acceptcaps_function (pad, gst_proxy_pad_acceptcaps_default);
489 gst_pad_set_fixatecaps_function (pad, gst_proxy_pad_fixatecaps_default);
490 gst_pad_set_unlink_function (pad, gst_proxy_pad_unlink_default);
494 /***********************************************************************
495 * Ghost pads, implemented as a pair of proxy pads (sort of)
499 #define GST_GHOST_PAD_PRIVATE(obj) (GST_GHOST_PAD_CAST (obj)->priv)
501 struct _GstGhostPadPrivate
503 /* with PROXY_LOCK */
504 gboolean constructed;
507 G_DEFINE_TYPE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
509 static void gst_ghost_pad_dispose (GObject * object);
512 * gst_ghost_pad_internal_activate_push_default:
513 * @pad: the #GstPad to activate or deactivate.
514 * @active: whether the pad should be active or not.
516 * Invoke the default activate push function of a proxy pad that is
517 * owned by a ghost pad.
519 * Returns: %TRUE if the operation was successful.
524 gst_ghost_pad_internal_activate_push_default (GstPad * pad, gboolean active)
529 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
531 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, we're ok",
532 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
534 /* in both cases (SRC and SINK) we activate just the internal pad. The targets
535 * will be activated later (or already in case of a ghost sinkpad). */
536 other = GST_PROXY_PAD_INTERNAL (pad);
537 ret = gst_pad_activate_push (other, active);
543 * gst_ghost_pad_internal_activate_pull_default:
544 * @pad: the #GstPad to activate or deactivate.
545 * @active: whether the pad should be active or not.
547 * Invoke the default activate pull function of a proxy pad that is
548 * owned by a ghost pad.
550 * Returns: %TRUE if the operation was successful.
555 gst_ghost_pad_internal_activate_pull_default (GstPad * pad, gboolean active)
560 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
562 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
563 GST_DEBUG_PAD_NAME (pad));
565 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
566 /* we are activated in pull mode by our peer element, which is a sinkpad
567 * that wants to operate in pull mode. This activation has to propagate
568 * upstream through the pipeline. We call the internal activation function,
569 * which will trigger gst_ghost_pad_activate_pull_default, which propagates even
570 * further upstream */
571 GST_LOG_OBJECT (pad, "pad is src, activate internal");
572 other = GST_PROXY_PAD_INTERNAL (pad);
573 ret = gst_pad_activate_pull (other, active);
574 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
575 /* We are SINK, the ghostpad is SRC, we propagate the activation upstream
576 * since we hold a pointer to the upstream peer. */
577 GST_LOG_OBJECT (pad, "activating peer");
578 ret = gst_pad_activate_pull (other, active);
579 gst_object_unref (other);
581 /* this is failure, we can't activate pull if there is no peer */
582 GST_LOG_OBJECT (pad, "not src and no peer, failing");
590 * gst_ghost_pad_activate_push_default:
591 * @pad: the #GstPad to activate or deactivate.
592 * @active: whether the pad should be active or not.
594 * Invoke the default activate push function of a ghost pad.
596 * Returns: %TRUE if the operation was successful.
601 gst_ghost_pad_activate_push_default (GstPad * pad, gboolean active)
606 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
608 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, proxy internal",
609 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
611 /* just activate the internal pad */
612 other = GST_PROXY_PAD_INTERNAL (pad);
613 ret = gst_pad_activate_push (other, active);
619 * gst_ghost_pad_activate_pull_default:
620 * @pad: the #GstPad to activate or deactivate.
621 * @active: whether the pad should be active or not.
623 * Invoke the default activate pull function of a ghost pad.
625 * Returns: %TRUE if the operation was successful.
630 gst_ghost_pad_activate_pull_default (GstPad * pad, gboolean active)
635 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
637 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
638 GST_DEBUG_PAD_NAME (pad));
640 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
641 /* the ghostpad is SRC and activated in pull mode by its peer, call the
642 * activation function of the internal pad to propagate the activation
644 GST_LOG_OBJECT (pad, "pad is src, activate internal");
645 other = GST_PROXY_PAD_INTERNAL (pad);
646 ret = gst_pad_activate_pull (other, active);
647 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
648 /* We are SINK and activated by the internal pad, propagate activation
649 * upstream because we hold a ref to the upstream peer */
650 GST_LOG_OBJECT (pad, "activating peer");
651 ret = gst_pad_activate_pull (other, active);
652 gst_object_unref (other);
654 /* no peer, we fail */
655 GST_LOG_OBJECT (pad, "pad not src and no peer, failing");
663 * gst_ghost_pad_link_default:
664 * @pad: the #GstPad to link.
665 * @peer: the #GstPad peer
667 * Invoke the default link function of a ghost pad.
669 * Returns: #GstPadLinkReturn of the operation
674 gst_ghost_pad_link_default (GstPad * pad, GstPad * peer)
676 GstPadLinkReturn ret;
678 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), GST_PAD_LINK_REFUSED);
679 g_return_val_if_fail (GST_IS_PAD (peer), GST_PAD_LINK_REFUSED);
681 GST_DEBUG_OBJECT (pad, "linking ghostpad");
683 ret = GST_PAD_LINK_OK;
684 /* if we are a source pad, we should call the peer link function
685 * if the peer has one, see design docs. */
686 if (GST_PAD_IS_SRC (pad)) {
687 if (GST_PAD_LINKFUNC (peer)) {
688 ret = GST_PAD_LINKFUNC (peer) (peer, pad);
689 if (ret != GST_PAD_LINK_OK)
690 GST_DEBUG_OBJECT (pad, "linking failed");
697 * gst_ghost_pad_unlink_default:
698 * @pad: the #GstPad to link.
700 * Invoke the default unlink function of a ghost pad.
705 gst_ghost_pad_unlink_default (GstPad * pad)
707 g_return_if_fail (GST_IS_GHOST_PAD (pad));
709 GST_DEBUG_OBJECT (pad, "unlinking ghostpad");
713 gst_ghost_pad_class_init (GstGhostPadClass * klass)
715 GObjectClass *gobject_class = (GObjectClass *) klass;
717 g_type_class_add_private (klass, sizeof (GstGhostPadPrivate));
719 gobject_class->dispose = gst_ghost_pad_dispose;
721 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_pull_default);
722 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_push_default);
723 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_link_default);
727 gst_ghost_pad_init (GstGhostPad * pad)
729 GST_GHOST_PAD_PRIVATE (pad) = G_TYPE_INSTANCE_GET_PRIVATE (pad,
730 GST_TYPE_GHOST_PAD, GstGhostPadPrivate);
732 gst_pad_set_activatepull_function (GST_PAD_CAST (pad),
733 gst_ghost_pad_activate_pull_default);
734 gst_pad_set_activatepush_function (GST_PAD_CAST (pad),
735 gst_ghost_pad_activate_push_default);
739 gst_ghost_pad_dispose (GObject * object)
745 pad = GST_PAD (object);
747 GST_DEBUG_OBJECT (pad, "dispose");
749 gst_ghost_pad_set_target (GST_GHOST_PAD (pad), NULL);
751 /* Unlink here so that gst_pad_dispose doesn't. That would lead to a call to
752 * gst_ghost_pad_unlink_default when the ghost pad is in an inconsistent state */
753 peer = gst_pad_get_peer (pad);
755 if (GST_PAD_IS_SRC (pad))
756 gst_pad_unlink (pad, peer);
758 gst_pad_unlink (peer, pad);
760 gst_object_unref (peer);
763 GST_OBJECT_LOCK (pad);
764 internal = GST_PROXY_PAD_INTERNAL (pad);
766 gst_pad_set_activatepull_function (internal, NULL);
767 gst_pad_set_activatepush_function (internal, NULL);
769 /* disposes of the internal pad, since the ghostpad is the only possible object
770 * that has a refcount on the internal pad. */
771 gst_object_unparent (GST_OBJECT_CAST (internal));
772 GST_PROXY_PAD_INTERNAL (pad) = NULL;
774 GST_OBJECT_UNLOCK (pad);
776 G_OBJECT_CLASS (gst_ghost_pad_parent_class)->dispose (object);
780 * gst_ghost_pad_construct:
781 * @gpad: the newly allocated ghost pad
783 * Finish initialization of a newly allocated ghost pad.
785 * This function is most useful in language bindings and when subclassing
786 * #GstGhostPad; plugin and application developers normally will not call this
787 * function. Call this function directly after a call to g_object_new
788 * (GST_TYPE_GHOST_PAD, "direction", @dir, ..., NULL).
790 * Returns: %TRUE if the construction succeeds, %FALSE otherwise.
795 gst_ghost_pad_construct (GstGhostPad * gpad)
797 GstPadDirection dir, otherdir;
798 GstPadTemplate *templ;
799 GstPad *pad, *internal;
801 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
802 g_return_val_if_fail (GST_GHOST_PAD_PRIVATE (gpad)->constructed == FALSE,
805 g_object_get (gpad, "direction", &dir, "template", &templ, NULL);
807 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, FALSE);
809 pad = GST_PAD (gpad);
811 /* Set directional padfunctions for ghostpad */
812 if (dir == GST_PAD_SINK) {
813 gst_pad_set_chain_function (pad, gst_proxy_pad_chain_default);
814 gst_pad_set_chain_list_function (pad, gst_proxy_pad_chain_list_default);
816 gst_pad_set_getrange_function (pad, gst_proxy_pad_getrange_default);
819 /* link/unlink functions */
820 gst_pad_set_link_function (pad, gst_ghost_pad_link_default);
821 gst_pad_set_unlink_function (pad, gst_ghost_pad_unlink_default);
823 /* INTERNAL PAD, it always exists and is child of the ghostpad */
824 otherdir = (dir == GST_PAD_SRC) ? GST_PAD_SINK : GST_PAD_SRC;
827 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
828 "direction", otherdir, "template", templ, NULL);
829 /* release ref obtained via g_object_get */
830 gst_object_unref (templ);
833 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
834 "direction", otherdir, NULL);
836 GST_PAD_UNSET_FLUSHING (internal);
838 /* Set directional padfunctions for internal pad */
839 if (dir == GST_PAD_SRC) {
840 gst_pad_set_chain_function (internal, gst_proxy_pad_chain_default);
841 gst_pad_set_chain_list_function (internal,
842 gst_proxy_pad_chain_list_default);
844 gst_pad_set_getrange_function (internal, gst_proxy_pad_getrange_default);
847 GST_OBJECT_LOCK (pad);
849 /* now make the ghostpad a parent of the internal pad */
850 if (!gst_object_set_parent (GST_OBJECT_CAST (internal),
851 GST_OBJECT_CAST (pad)))
854 /* The ghostpad is the parent of the internal pad and is the only object that
855 * can have a refcount on the internal pad.
856 * At this point, the GstGhostPad has a refcount of 1, and the internal pad has
858 * When the refcount of the GstGhostPad drops to 0, the ghostpad will dispose
859 * its refcount on the internal pad in the dispose method by un-parenting it.
860 * This is why we don't take extra refcounts in the assignments below
862 GST_PROXY_PAD_INTERNAL (pad) = internal;
863 GST_PROXY_PAD_INTERNAL (internal) = pad;
865 /* special activation functions for the internal pad */
866 gst_pad_set_activatepull_function (internal,
867 gst_ghost_pad_internal_activate_pull_default);
868 gst_pad_set_activatepush_function (internal,
869 gst_ghost_pad_internal_activate_push_default);
871 GST_OBJECT_UNLOCK (pad);
873 GST_GHOST_PAD_PRIVATE (gpad)->constructed = TRUE;
879 GST_WARNING_OBJECT (gpad, "Could not set internal pad %s:%s",
880 GST_DEBUG_PAD_NAME (internal));
881 g_critical ("Could not set internal pad %s:%s",
882 GST_DEBUG_PAD_NAME (internal));
883 GST_OBJECT_UNLOCK (pad);
884 gst_object_unref (internal);
890 gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
891 GstPadTemplate * templ)
895 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
897 /* OBJECT CREATION */
899 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
900 "direction", dir, "template", templ, NULL);
902 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
903 "direction", dir, NULL);
906 if (!gst_ghost_pad_construct (ret))
907 goto construct_failed;
909 return GST_PAD_CAST (ret);
913 gst_object_unref (ret);
918 * gst_ghost_pad_new_no_target:
919 * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
920 * @dir: the direction of the ghostpad
922 * Create a new ghostpad without a target with the given direction.
923 * A target can be set on the ghostpad later with the
924 * gst_ghost_pad_set_target() function.
926 * The created ghostpad will not have a padtemplate.
928 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
931 gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
935 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
937 GST_LOG ("name:%s, direction:%d", GST_STR_NULL (name), dir);
939 ret = gst_ghost_pad_new_full (name, dir, NULL);
946 * @name: (allow-none): the name of the new pad, or NULL to assign a default name
947 * @target: (transfer none): the pad to ghost.
949 * Create a new ghostpad with @target as the target. The direction will be taken
950 * from the target pad. @target must be unlinked.
952 * Will ref the target.
954 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
957 gst_ghost_pad_new (const gchar * name, GstPad * target)
961 g_return_val_if_fail (GST_IS_PAD (target), NULL);
962 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
964 GST_LOG ("name:%s, target:%s:%s", GST_STR_NULL (name),
965 GST_DEBUG_PAD_NAME (target));
967 if ((ret = gst_ghost_pad_new_no_target (name, GST_PAD_DIRECTION (target))))
968 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
969 goto set_target_failed;
976 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
977 GST_DEBUG_PAD_NAME (target));
978 gst_object_unref (ret);
984 * gst_ghost_pad_new_from_template:
985 * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
986 * @target: (transfer none): the pad to ghost.
987 * @templ: (transfer none): the #GstPadTemplate to use on the ghostpad.
989 * Create a new ghostpad with @target as the target. The direction will be taken
990 * from the target pad. The template used on the ghostpad will be @template.
992 * Will ref the target.
994 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
1000 gst_ghost_pad_new_from_template (const gchar * name, GstPad * target,
1001 GstPadTemplate * templ)
1005 g_return_val_if_fail (GST_IS_PAD (target), NULL);
1006 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
1007 g_return_val_if_fail (templ != NULL, NULL);
1008 g_return_val_if_fail (GST_PAD_TEMPLATE_DIRECTION (templ) ==
1009 GST_PAD_DIRECTION (target), NULL);
1011 GST_LOG ("name:%s, target:%s:%s, templ:%p", GST_STR_NULL (name),
1012 GST_DEBUG_PAD_NAME (target), templ);
1014 if ((ret = gst_ghost_pad_new_full (name, GST_PAD_DIRECTION (target), templ)))
1015 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
1016 goto set_target_failed;
1023 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
1024 GST_DEBUG_PAD_NAME (target));
1025 gst_object_unref (ret);
1031 * gst_ghost_pad_new_no_target_from_template:
1032 * @name: (allow-none): the name of the new pad, or NULL to assign a default name
1033 * @templ: (transfer none): the #GstPadTemplate to create the ghostpad from.
1035 * Create a new ghostpad based on @templ, without setting a target. The
1036 * direction will be taken from the @templ.
1038 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
1043 gst_ghost_pad_new_no_target_from_template (const gchar * name,
1044 GstPadTemplate * templ)
1048 g_return_val_if_fail (templ != NULL, NULL);
1051 gst_ghost_pad_new_full (name, GST_PAD_TEMPLATE_DIRECTION (templ), templ);
1057 * gst_ghost_pad_get_target:
1058 * @gpad: the #GstGhostPad
1060 * Get the target pad of @gpad. Unref target pad after usage.
1062 * Returns: (transfer full): the target #GstPad, can be NULL if the ghostpad
1063 * has no target set. Unref target pad after usage.
1066 gst_ghost_pad_get_target (GstGhostPad * gpad)
1070 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), NULL);
1072 ret = gst_proxy_pad_get_target (GST_PAD_CAST (gpad));
1074 GST_DEBUG_OBJECT (gpad, "get target %s:%s", GST_DEBUG_PAD_NAME (ret));
1080 * gst_ghost_pad_set_target:
1081 * @gpad: the #GstGhostPad
1082 * @newtarget: (transfer none) (allow-none): the new pad target
1084 * Set the new target of the ghostpad @gpad. Any existing target
1085 * is unlinked and links to the new target are established. if @newtarget is
1086 * NULL the target will be cleared.
1088 * Returns: (transfer full): TRUE if the new target could be set. This function
1089 * can return FALSE when the internal pads could not be linked.
1092 gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
1096 GstPadLinkReturn lret;
1098 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
1099 g_return_val_if_fail (GST_PAD_CAST (gpad) != newtarget, FALSE);
1100 g_return_val_if_fail (newtarget != GST_PROXY_PAD_INTERNAL (gpad), FALSE);
1102 /* no need for locking, the internal pad's lifecycle is directly linked to the
1104 internal = GST_PROXY_PAD_INTERNAL (gpad);
1107 GST_DEBUG_OBJECT (gpad, "set target %s:%s", GST_DEBUG_PAD_NAME (newtarget));
1109 GST_DEBUG_OBJECT (gpad, "clearing target");
1111 /* clear old target */
1112 GST_OBJECT_LOCK (gpad);
1113 if ((oldtarget = GST_PROXY_PAD_TARGET (gpad))) {
1114 GST_OBJECT_UNLOCK (gpad);
1116 /* unlink internal pad */
1117 if (GST_PAD_IS_SRC (internal))
1118 gst_pad_unlink (internal, oldtarget);
1120 gst_pad_unlink (oldtarget, internal);
1122 GST_OBJECT_UNLOCK (gpad);
1126 /* and link to internal pad without any checks */
1127 GST_DEBUG_OBJECT (gpad, "connecting internal pad to target");
1129 if (GST_PAD_IS_SRC (internal))
1131 gst_pad_link_full (internal, newtarget, GST_PAD_LINK_CHECK_NOTHING);
1134 gst_pad_link_full (newtarget, internal, GST_PAD_LINK_CHECK_NOTHING);
1136 if (lret != GST_PAD_LINK_OK)
1145 GST_WARNING_OBJECT (gpad, "could not link internal and target, reason:%d",