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 * @parent: the parent of @pad or NULL
180 * @query: (transfer none): the #GstQuery to perform.
182 * Invoke the default query function of the proxy pad.
184 * Returns: TRUE if the query could be performed.
189 gst_proxy_pad_query_default (GstPad * pad, GstObject * parent, GstQuery * query)
194 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
195 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
198 switch (GST_QUERY_TYPE (query)) {
199 case GST_QUERY_ACCEPT_CAPS:
201 target = gst_proxy_pad_get_target (pad);
203 res = gst_pad_query (target, query);
204 gst_object_unref (target);
206 GST_DEBUG_OBJECT (pad, "no target");
207 /* We don't have a target, we return TRUE and we assume that any future
208 * target will be able to deal with any configured caps. */
215 res = gst_proxy_pad_query_caps (pad, query);
220 target = gst_proxy_pad_get_target (pad);
222 res = gst_pad_query (target, query);
223 gst_object_unref (target);
225 GST_DEBUG_OBJECT (pad, "no target pad");
235 * gst_proyx_pad_iterate_internal_links_default:
236 * @pad: the #GstPad to get the internal links of.
238 * Invoke the default iterate internal links function of the proxy pad.
240 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
241 * returned pad with gst_object_unref().
246 gst_proxy_pad_iterate_internal_links_default (GstPad * pad)
248 GstIterator *res = NULL;
252 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
254 internal = GST_PROXY_PAD_INTERNAL (pad);
255 g_value_init (&v, GST_TYPE_PAD);
256 g_value_set_object (&v, internal);
257 res = gst_iterator_new_single (GST_TYPE_PAD, &v);
264 * gst_proxy_pad_chain_default:
265 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
266 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
269 * Invoke the default chain function of the proxy pad.
271 * Returns: a #GstFlowReturn from the pad.
276 gst_proxy_pad_chain_default (GstPad * pad, GstBuffer * buffer)
281 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
282 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
284 internal = GST_PROXY_PAD_INTERNAL (pad);
285 res = gst_pad_push (internal, buffer);
291 * gst_proxy_pad_chain_list_default:
292 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
293 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
296 * Invoke the default chain list function of the proxy pad.
298 * Returns: a #GstFlowReturn from the pad.
303 gst_proxy_pad_chain_list_default (GstPad * pad, GstBufferList * list)
308 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
309 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
311 internal = GST_PROXY_PAD_INTERNAL (pad);
312 res = gst_pad_push_list (internal, list);
318 * gst_proxy_pad_get_range_default:
319 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
320 * @offset: The start offset of the buffer
321 * @size: The length of the buffer
322 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
323 * returns #GST_FLOW_ERROR if %NULL.
325 * Invoke the default getrange function of the proxy pad.
327 * Returns: a #GstFlowReturn from the pad.
332 gst_proxy_pad_getrange_default (GstPad * pad, guint64 offset, guint size,
338 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
339 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
341 internal = GST_PROXY_PAD_INTERNAL (pad);
342 res = gst_pad_pull_range (internal, offset, size, buffer);
348 gst_proxy_pad_get_target (GstPad * pad)
352 GST_OBJECT_LOCK (pad);
353 target = GST_PROXY_PAD_TARGET (pad);
355 gst_object_ref (target);
356 GST_OBJECT_UNLOCK (pad);
362 * gst_proxy_pad_get_internal:
363 * @pad: the #GstProxyPad
365 * Get the internal pad of @pad. Unref target pad after usage.
367 * The internal pad of a #GstGhostPad is the internally used
368 * pad of opposite direction, which is used to link to the target.
370 * Returns: (transfer full): the target #GstProxyPad, can be NULL.
371 * Unref target pad after usage.
376 gst_proxy_pad_get_internal (GstProxyPad * pad)
380 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
382 GST_OBJECT_LOCK (pad);
383 internal = GST_PROXY_PAD_INTERNAL (pad);
385 gst_object_ref (internal);
386 GST_OBJECT_UNLOCK (pad);
388 return GST_PROXY_PAD_CAST (internal);
392 * gst_proxy_pad_unlink_default:
393 * @pad: a #GstPad to unlink
395 * Invoke the default unlink function of the proxy pad.
400 gst_proxy_pad_unlink_default (GstPad * pad)
402 /* nothing to do anymore */
403 GST_DEBUG_OBJECT (pad, "pad is unlinked");
407 gst_proxy_pad_class_init (GstProxyPadClass * klass)
409 g_type_class_add_private (klass, sizeof (GstProxyPadPrivate));
411 /* Register common function pointer descriptions */
412 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_event_default);
413 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_query_default);
414 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_iterate_internal_links_default);
415 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_unlink_default);
416 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_default);
417 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_list_default);
418 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getrange_default);
422 gst_proxy_pad_init (GstProxyPad * ppad)
424 GstPad *pad = (GstPad *) ppad;
426 GST_PROXY_PAD_PRIVATE (ppad) = G_TYPE_INSTANCE_GET_PRIVATE (ppad,
427 GST_TYPE_PROXY_PAD, GstProxyPadPrivate);
429 gst_pad_set_event_function (pad, gst_proxy_pad_event_default);
430 gst_pad_set_query_function (pad, gst_proxy_pad_query_default);
431 gst_pad_set_iterate_internal_links_function (pad,
432 gst_proxy_pad_iterate_internal_links_default);
434 gst_pad_set_unlink_function (pad, gst_proxy_pad_unlink_default);
438 /***********************************************************************
439 * Ghost pads, implemented as a pair of proxy pads (sort of)
443 #define GST_GHOST_PAD_PRIVATE(obj) (GST_GHOST_PAD_CAST (obj)->priv)
445 struct _GstGhostPadPrivate
447 /* with PROXY_LOCK */
448 gboolean constructed;
451 G_DEFINE_TYPE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
453 static void gst_ghost_pad_dispose (GObject * object);
456 * gst_ghost_pad_internal_activate_push_default:
457 * @pad: the #GstPad to activate or deactivate.
458 * @active: whether the pad should be active or not.
460 * Invoke the default activate push function of a proxy pad that is
461 * owned by a ghost pad.
463 * Returns: %TRUE if the operation was successful.
468 gst_ghost_pad_internal_activate_push_default (GstPad * pad, gboolean active)
473 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
475 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, we're ok",
476 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
478 /* in both cases (SRC and SINK) we activate just the internal pad. The targets
479 * will be activated later (or already in case of a ghost sinkpad). */
480 other = GST_PROXY_PAD_INTERNAL (pad);
481 ret = gst_pad_activate_push (other, active);
487 * gst_ghost_pad_internal_activate_pull_default:
488 * @pad: the #GstPad to activate or deactivate.
489 * @active: whether the pad should be active or not.
491 * Invoke the default activate pull function of a proxy pad that is
492 * owned by a ghost pad.
494 * Returns: %TRUE if the operation was successful.
499 gst_ghost_pad_internal_activate_pull_default (GstPad * pad, gboolean active)
504 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
506 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
507 GST_DEBUG_PAD_NAME (pad));
509 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
510 /* we are activated in pull mode by our peer element, which is a sinkpad
511 * that wants to operate in pull mode. This activation has to propagate
512 * upstream through the pipeline. We call the internal activation function,
513 * which will trigger gst_ghost_pad_activate_pull_default, which propagates even
514 * further upstream */
515 GST_LOG_OBJECT (pad, "pad is src, activate internal");
516 other = GST_PROXY_PAD_INTERNAL (pad);
517 ret = gst_pad_activate_pull (other, active);
518 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
519 /* We are SINK, the ghostpad is SRC, we propagate the activation upstream
520 * since we hold a pointer to the upstream peer. */
521 GST_LOG_OBJECT (pad, "activating peer");
522 ret = gst_pad_activate_pull (other, active);
523 gst_object_unref (other);
525 /* this is failure, we can't activate pull if there is no peer */
526 GST_LOG_OBJECT (pad, "not src and no peer, failing");
534 * gst_ghost_pad_activate_push_default:
535 * @pad: the #GstPad to activate or deactivate.
536 * @active: whether the pad should be active or not.
538 * Invoke the default activate push function of a ghost pad.
540 * Returns: %TRUE if the operation was successful.
545 gst_ghost_pad_activate_push_default (GstPad * pad, gboolean active)
550 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
552 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, proxy internal",
553 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
555 /* just activate the internal pad */
556 other = GST_PROXY_PAD_INTERNAL (pad);
557 ret = gst_pad_activate_push (other, active);
563 * gst_ghost_pad_activate_pull_default:
564 * @pad: the #GstPad to activate or deactivate.
565 * @active: whether the pad should be active or not.
567 * Invoke the default activate pull function of a ghost pad.
569 * Returns: %TRUE if the operation was successful.
574 gst_ghost_pad_activate_pull_default (GstPad * pad, gboolean active)
579 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
581 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
582 GST_DEBUG_PAD_NAME (pad));
584 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
585 /* the ghostpad is SRC and activated in pull mode by its peer, call the
586 * activation function of the internal pad to propagate the activation
588 GST_LOG_OBJECT (pad, "pad is src, activate internal");
589 other = GST_PROXY_PAD_INTERNAL (pad);
590 ret = gst_pad_activate_pull (other, active);
591 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
592 /* We are SINK and activated by the internal pad, propagate activation
593 * upstream because we hold a ref to the upstream peer */
594 GST_LOG_OBJECT (pad, "activating peer");
595 ret = gst_pad_activate_pull (other, active);
596 gst_object_unref (other);
598 /* no peer, we fail */
599 GST_LOG_OBJECT (pad, "pad not src and no peer, failing");
607 * gst_ghost_pad_link_default:
608 * @pad: the #GstPad to link.
609 * @peer: the #GstPad peer
611 * Invoke the default link function of a ghost pad.
613 * Returns: #GstPadLinkReturn of the operation
618 gst_ghost_pad_link_default (GstPad * pad, GstPad * peer)
620 GstPadLinkReturn ret;
622 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), GST_PAD_LINK_REFUSED);
623 g_return_val_if_fail (GST_IS_PAD (peer), GST_PAD_LINK_REFUSED);
625 GST_DEBUG_OBJECT (pad, "linking ghostpad");
627 ret = GST_PAD_LINK_OK;
628 /* if we are a source pad, we should call the peer link function
629 * if the peer has one, see design docs. */
630 if (GST_PAD_IS_SRC (pad)) {
631 if (GST_PAD_LINKFUNC (peer)) {
632 ret = GST_PAD_LINKFUNC (peer) (peer, pad);
633 if (ret != GST_PAD_LINK_OK)
634 GST_DEBUG_OBJECT (pad, "linking failed");
641 * gst_ghost_pad_unlink_default:
642 * @pad: the #GstPad to link.
644 * Invoke the default unlink function of a ghost pad.
649 gst_ghost_pad_unlink_default (GstPad * pad)
651 g_return_if_fail (GST_IS_GHOST_PAD (pad));
653 GST_DEBUG_OBJECT (pad, "unlinking ghostpad");
657 gst_ghost_pad_class_init (GstGhostPadClass * klass)
659 GObjectClass *gobject_class = (GObjectClass *) klass;
661 g_type_class_add_private (klass, sizeof (GstGhostPadPrivate));
663 gobject_class->dispose = gst_ghost_pad_dispose;
665 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_pull_default);
666 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_push_default);
667 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_link_default);
671 gst_ghost_pad_init (GstGhostPad * pad)
673 GST_GHOST_PAD_PRIVATE (pad) = G_TYPE_INSTANCE_GET_PRIVATE (pad,
674 GST_TYPE_GHOST_PAD, GstGhostPadPrivate);
676 gst_pad_set_activatepull_function (GST_PAD_CAST (pad),
677 gst_ghost_pad_activate_pull_default);
678 gst_pad_set_activatepush_function (GST_PAD_CAST (pad),
679 gst_ghost_pad_activate_push_default);
683 gst_ghost_pad_dispose (GObject * object)
689 pad = GST_PAD (object);
691 GST_DEBUG_OBJECT (pad, "dispose");
693 gst_ghost_pad_set_target (GST_GHOST_PAD (pad), NULL);
695 /* Unlink here so that gst_pad_dispose doesn't. That would lead to a call to
696 * gst_ghost_pad_unlink_default when the ghost pad is in an inconsistent state */
697 peer = gst_pad_get_peer (pad);
699 if (GST_PAD_IS_SRC (pad))
700 gst_pad_unlink (pad, peer);
702 gst_pad_unlink (peer, pad);
704 gst_object_unref (peer);
707 GST_OBJECT_LOCK (pad);
708 internal = GST_PROXY_PAD_INTERNAL (pad);
710 gst_pad_set_activatepull_function (internal, NULL);
711 gst_pad_set_activatepush_function (internal, NULL);
713 /* disposes of the internal pad, since the ghostpad is the only possible object
714 * that has a refcount on the internal pad. */
715 gst_object_unparent (GST_OBJECT_CAST (internal));
716 GST_PROXY_PAD_INTERNAL (pad) = NULL;
718 GST_OBJECT_UNLOCK (pad);
720 G_OBJECT_CLASS (gst_ghost_pad_parent_class)->dispose (object);
724 * gst_ghost_pad_construct:
725 * @gpad: the newly allocated ghost pad
727 * Finish initialization of a newly allocated ghost pad.
729 * This function is most useful in language bindings and when subclassing
730 * #GstGhostPad; plugin and application developers normally will not call this
731 * function. Call this function directly after a call to g_object_new
732 * (GST_TYPE_GHOST_PAD, "direction", @dir, ..., NULL).
734 * Returns: %TRUE if the construction succeeds, %FALSE otherwise.
739 gst_ghost_pad_construct (GstGhostPad * gpad)
741 GstPadDirection dir, otherdir;
742 GstPadTemplate *templ;
743 GstPad *pad, *internal;
745 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
746 g_return_val_if_fail (GST_GHOST_PAD_PRIVATE (gpad)->constructed == FALSE,
749 g_object_get (gpad, "direction", &dir, "template", &templ, NULL);
751 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, FALSE);
753 pad = GST_PAD (gpad);
755 /* Set directional padfunctions for ghostpad */
756 if (dir == GST_PAD_SINK) {
757 gst_pad_set_chain_function (pad, gst_proxy_pad_chain_default);
758 gst_pad_set_chain_list_function (pad, gst_proxy_pad_chain_list_default);
760 gst_pad_set_getrange_function (pad, gst_proxy_pad_getrange_default);
763 /* link/unlink functions */
764 gst_pad_set_link_function (pad, gst_ghost_pad_link_default);
765 gst_pad_set_unlink_function (pad, gst_ghost_pad_unlink_default);
767 /* INTERNAL PAD, it always exists and is child of the ghostpad */
768 otherdir = (dir == GST_PAD_SRC) ? GST_PAD_SINK : GST_PAD_SRC;
771 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
772 "direction", otherdir, "template", templ, NULL);
773 /* release ref obtained via g_object_get */
774 gst_object_unref (templ);
777 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
778 "direction", otherdir, NULL);
780 GST_PAD_UNSET_FLUSHING (internal);
782 /* Set directional padfunctions for internal pad */
783 if (dir == GST_PAD_SRC) {
784 gst_pad_set_chain_function (internal, gst_proxy_pad_chain_default);
785 gst_pad_set_chain_list_function (internal,
786 gst_proxy_pad_chain_list_default);
788 gst_pad_set_getrange_function (internal, gst_proxy_pad_getrange_default);
791 GST_OBJECT_LOCK (pad);
793 /* now make the ghostpad a parent of the internal pad */
794 if (!gst_object_set_parent (GST_OBJECT_CAST (internal),
795 GST_OBJECT_CAST (pad)))
798 /* The ghostpad is the parent of the internal pad and is the only object that
799 * can have a refcount on the internal pad.
800 * At this point, the GstGhostPad has a refcount of 1, and the internal pad has
802 * When the refcount of the GstGhostPad drops to 0, the ghostpad will dispose
803 * its refcount on the internal pad in the dispose method by un-parenting it.
804 * This is why we don't take extra refcounts in the assignments below
806 GST_PROXY_PAD_INTERNAL (pad) = internal;
807 GST_PROXY_PAD_INTERNAL (internal) = pad;
809 /* special activation functions for the internal pad */
810 gst_pad_set_activatepull_function (internal,
811 gst_ghost_pad_internal_activate_pull_default);
812 gst_pad_set_activatepush_function (internal,
813 gst_ghost_pad_internal_activate_push_default);
815 GST_OBJECT_UNLOCK (pad);
817 GST_GHOST_PAD_PRIVATE (gpad)->constructed = TRUE;
823 GST_WARNING_OBJECT (gpad, "Could not set internal pad %s:%s",
824 GST_DEBUG_PAD_NAME (internal));
825 g_critical ("Could not set internal pad %s:%s",
826 GST_DEBUG_PAD_NAME (internal));
827 GST_OBJECT_UNLOCK (pad);
828 gst_object_unref (internal);
834 gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
835 GstPadTemplate * templ)
839 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
841 /* OBJECT CREATION */
843 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
844 "direction", dir, "template", templ, NULL);
846 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
847 "direction", dir, NULL);
850 if (!gst_ghost_pad_construct (ret))
851 goto construct_failed;
853 return GST_PAD_CAST (ret);
857 gst_object_unref (ret);
862 * gst_ghost_pad_new_no_target:
863 * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
864 * @dir: the direction of the ghostpad
866 * Create a new ghostpad without a target with the given direction.
867 * A target can be set on the ghostpad later with the
868 * gst_ghost_pad_set_target() function.
870 * The created ghostpad will not have a padtemplate.
872 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
875 gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
879 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
881 GST_LOG ("name:%s, direction:%d", GST_STR_NULL (name), dir);
883 ret = gst_ghost_pad_new_full (name, dir, NULL);
890 * @name: (allow-none): the name of the new pad, or NULL to assign a default name
891 * @target: (transfer none): the pad to ghost.
893 * Create a new ghostpad with @target as the target. The direction will be taken
894 * from the target pad. @target must be unlinked.
896 * Will ref the target.
898 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
901 gst_ghost_pad_new (const gchar * name, GstPad * target)
905 g_return_val_if_fail (GST_IS_PAD (target), NULL);
906 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
908 GST_LOG ("name:%s, target:%s:%s", GST_STR_NULL (name),
909 GST_DEBUG_PAD_NAME (target));
911 if ((ret = gst_ghost_pad_new_no_target (name, GST_PAD_DIRECTION (target))))
912 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
913 goto set_target_failed;
920 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
921 GST_DEBUG_PAD_NAME (target));
922 gst_object_unref (ret);
928 * gst_ghost_pad_new_from_template:
929 * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
930 * @target: (transfer none): the pad to ghost.
931 * @templ: (transfer none): the #GstPadTemplate to use on the ghostpad.
933 * Create a new ghostpad with @target as the target. The direction will be taken
934 * from the target pad. The template used on the ghostpad will be @template.
936 * Will ref the target.
938 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
944 gst_ghost_pad_new_from_template (const gchar * name, GstPad * target,
945 GstPadTemplate * templ)
949 g_return_val_if_fail (GST_IS_PAD (target), NULL);
950 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
951 g_return_val_if_fail (templ != NULL, NULL);
952 g_return_val_if_fail (GST_PAD_TEMPLATE_DIRECTION (templ) ==
953 GST_PAD_DIRECTION (target), NULL);
955 GST_LOG ("name:%s, target:%s:%s, templ:%p", GST_STR_NULL (name),
956 GST_DEBUG_PAD_NAME (target), templ);
958 if ((ret = gst_ghost_pad_new_full (name, GST_PAD_DIRECTION (target), templ)))
959 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
960 goto set_target_failed;
967 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
968 GST_DEBUG_PAD_NAME (target));
969 gst_object_unref (ret);
975 * gst_ghost_pad_new_no_target_from_template:
976 * @name: (allow-none): the name of the new pad, or NULL to assign a default name
977 * @templ: (transfer none): the #GstPadTemplate to create the ghostpad from.
979 * Create a new ghostpad based on @templ, without setting a target. The
980 * direction will be taken from the @templ.
982 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
987 gst_ghost_pad_new_no_target_from_template (const gchar * name,
988 GstPadTemplate * templ)
992 g_return_val_if_fail (templ != NULL, NULL);
995 gst_ghost_pad_new_full (name, GST_PAD_TEMPLATE_DIRECTION (templ), templ);
1001 * gst_ghost_pad_get_target:
1002 * @gpad: the #GstGhostPad
1004 * Get the target pad of @gpad. Unref target pad after usage.
1006 * Returns: (transfer full): the target #GstPad, can be NULL if the ghostpad
1007 * has no target set. Unref target pad after usage.
1010 gst_ghost_pad_get_target (GstGhostPad * gpad)
1014 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), NULL);
1016 ret = gst_proxy_pad_get_target (GST_PAD_CAST (gpad));
1018 GST_DEBUG_OBJECT (gpad, "get target %s:%s", GST_DEBUG_PAD_NAME (ret));
1024 * gst_ghost_pad_set_target:
1025 * @gpad: the #GstGhostPad
1026 * @newtarget: (transfer none) (allow-none): the new pad target
1028 * Set the new target of the ghostpad @gpad. Any existing target
1029 * is unlinked and links to the new target are established. if @newtarget is
1030 * NULL the target will be cleared.
1032 * Returns: (transfer full): TRUE if the new target could be set. This function
1033 * can return FALSE when the internal pads could not be linked.
1036 gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
1040 GstPadLinkReturn lret;
1042 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
1043 g_return_val_if_fail (GST_PAD_CAST (gpad) != newtarget, FALSE);
1044 g_return_val_if_fail (newtarget != GST_PROXY_PAD_INTERNAL (gpad), FALSE);
1046 /* no need for locking, the internal pad's lifecycle is directly linked to the
1048 internal = GST_PROXY_PAD_INTERNAL (gpad);
1051 GST_DEBUG_OBJECT (gpad, "set target %s:%s", GST_DEBUG_PAD_NAME (newtarget));
1053 GST_DEBUG_OBJECT (gpad, "clearing target");
1055 /* clear old target */
1056 GST_OBJECT_LOCK (gpad);
1057 if ((oldtarget = GST_PROXY_PAD_TARGET (gpad))) {
1058 GST_OBJECT_UNLOCK (gpad);
1060 /* unlink internal pad */
1061 if (GST_PAD_IS_SRC (internal))
1062 gst_pad_unlink (internal, oldtarget);
1064 gst_pad_unlink (oldtarget, internal);
1066 GST_OBJECT_UNLOCK (gpad);
1070 /* and link to internal pad without any checks */
1071 GST_DEBUG_OBJECT (gpad, "connecting internal pad to target");
1073 if (GST_PAD_IS_SRC (internal))
1075 gst_pad_link_full (internal, newtarget, GST_PAD_LINK_CHECK_NOTHING);
1078 gst_pad_link_full (newtarget, internal, GST_PAD_LINK_CHECK_NOTHING);
1080 if (lret != GST_PAD_LINK_OK)
1089 GST_WARNING_OBJECT (gpad, "could not link internal and target, reason:%d",