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_PROXY_PAD_PRIVATE (pad)->target)
58 #define GST_PROXY_PAD_INTERNAL(pad) (GST_PROXY_PAD_PRIVATE (pad)->internal)
59 #define GST_PROXY_PAD_RETARGET(pad) (GST_PROXY_PAD_PRIVATE (pad)->retarget)
60 #define GST_PROXY_GET_LOCK(pad) (GST_PROXY_PAD_PRIVATE (pad)->proxy_lock)
61 #define GST_PROXY_LOCK(pad) (g_mutex_lock (GST_PROXY_GET_LOCK (pad)))
62 #define GST_PROXY_UNLOCK(pad) (g_mutex_unlock (GST_PROXY_GET_LOCK (pad)))
64 struct _GstProxyPadPrivate
73 G_DEFINE_TYPE (GstProxyPad, gst_proxy_pad, GST_TYPE_PAD);
75 static GstPad *gst_proxy_pad_get_target (GstPad * pad);
77 static void gst_proxy_pad_dispose (GObject * object);
78 static void gst_proxy_pad_finalize (GObject * object);
80 #if !defined(GST_DISABLE_LOADSAVE) && !defined(GST_REMOVE_DEPRECATED)
81 #ifdef GST_DISABLE_DEPRECATED
82 #include <libxml/parser.h>
84 static xmlNodePtr gst_proxy_pad_save_thyself (GstObject * object,
88 static void on_src_target_notify (GstPad * target,
89 GParamSpec * unused, gpointer user_data);
91 static GParamSpec *pspec_caps = NULL;
94 * gst_proxy_pad_query_type_default:
97 * Invoke the default query type handler of the proxy pad.
99 * Returns: (transfer none) (array zero-terminated=1): a zero-terminated array
105 gst_proxy_pad_query_type_default (GstPad * pad)
108 const GstQueryType *res = NULL;
110 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
112 target = gst_proxy_pad_get_target (pad);
114 res = gst_pad_get_query_types (target);
115 gst_object_unref (target);
121 * gst_proxy_pad_event_default:
122 * @pad: a #GstPad to push the event to.
123 * @event: (transfer full): the #GstEvent to send to the pad.
125 * Invoke the default event of the proxy pad.
127 * Returns: TRUE if the event was handled.
132 gst_proxy_pad_event_default (GstPad * pad, GstEvent * event)
134 gboolean res = FALSE;
137 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
138 g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
141 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD_CAST (pad)));
143 res = gst_pad_push_event (internal, event);
144 gst_object_unref (internal);
151 * gst_proxy_pad_query_default:
152 * @pad: a #GstPad to invoke the default query on.
153 * @query: (transfer none): the #GstQuery to perform.
155 * Invoke the default query function of the proxy pad.
157 * Returns: TRUE if the query could be performed.
162 gst_proxy_pad_query_default (GstPad * pad, GstQuery * query)
164 gboolean res = FALSE;
167 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
168 g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
170 target = gst_proxy_pad_get_target (pad);
172 res = gst_pad_query (target, query);
173 gst_object_unref (target);
180 * gst_proyx_pad_iterate_internal_links_default:
181 * @pad: the #GstPad to get the internal links of.
183 * Invoke the default iterate internal links function of the proxy pad.
185 * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
186 * returned pad with gst_object_unref().
191 gst_proxy_pad_iterate_internal_links_default (GstPad * pad)
193 GstIterator *res = NULL;
196 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
199 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD_CAST (pad)));
203 gst_iterator_new_single (GST_TYPE_PAD, internal,
204 (GstCopyFunction) gst_object_ref, (GFreeFunc) gst_object_unref);
205 gst_object_unref (internal);
212 * gst_proxy_pad_bufferalloc_default:
213 * @pad: a source #GstPad
214 * @offset: the offset of the new buffer in the stream
215 * @size: the size of the new buffer
216 * @caps: the caps of the new buffer
217 * @buf: a newly allocated buffer
219 * Invoke the default bufferalloc function of the proxy pad.
221 * Returns: a result code indicating success of the operation. Any
222 * result code other than #GST_FLOW_OK is an error and @buf should
224 * An error can occur if the pad is not connected or when the downstream
225 * peer elements cannot provide an acceptable buffer.
230 gst_proxy_pad_bufferalloc_default (GstPad * pad, guint64 offset, guint size,
231 GstCaps * caps, GstBuffer ** buf)
233 GstFlowReturn result = GST_FLOW_WRONG_STATE;
236 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
237 g_return_val_if_fail (caps == NULL || GST_IS_CAPS (caps), GST_FLOW_ERROR);
238 g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
241 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD_CAST (pad)));
243 result = gst_pad_alloc_buffer (internal, offset, size, caps, buf);
244 gst_object_unref (internal);
251 * gst_proxy_pad_chain_default:
252 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
253 * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
256 * Invoke the default chain function of the proxy pad.
258 * Returns: a #GstFlowReturn from the pad.
263 gst_proxy_pad_chain_default (GstPad * pad, GstBuffer * buffer)
268 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
269 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
271 internal = GST_PROXY_PAD_INTERNAL (pad);
272 res = gst_pad_push (internal, buffer);
278 * gst_proxy_pad_chain_list_default:
279 * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
280 * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
283 * Invoke the default chain list function of the proxy pad.
285 * Returns: a #GstFlowReturn from the pad.
290 gst_proxy_pad_chain_list_default (GstPad * pad, GstBufferList * list)
295 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
296 g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
298 internal = GST_PROXY_PAD_INTERNAL (pad);
299 res = gst_pad_push_list (internal, list);
305 * gst_proxy_pad_get_range_default:
306 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
307 * @offset: The start offset of the buffer
308 * @size: The length of the buffer
309 * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
310 * returns #GST_FLOW_ERROR if %NULL.
312 * Invoke the default getrange function of the proxy pad.
314 * Returns: a #GstFlowReturn from the pad.
319 gst_proxy_pad_getrange_default (GstPad * pad, guint64 offset, guint size,
325 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
326 g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
328 internal = GST_PROXY_PAD_INTERNAL (pad);
329 res = gst_pad_pull_range (internal, offset, size, buffer);
335 * gst_proxy_pad_checkgetrange_default:
336 * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
338 * Invoke the default checkgetrange function of the proxy pad.
340 * Returns: a #gboolean from the pad.
345 gst_proxy_pad_checkgetrange_default (GstPad * pad)
350 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
352 internal = GST_PROXY_PAD_INTERNAL (pad);
353 result = gst_pad_check_pull_range (internal);
359 * gst_proxy_pad_getcaps_default:
360 * @pad: a #GstPad to get the capabilities of.
362 * Invoke the default getcaps function of the proxy pad.
364 * Returns: (transfer full): the caps of the pad with incremented ref-count
369 gst_proxy_pad_getcaps_default (GstPad * pad)
373 GstPadTemplate *templ;
375 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
377 templ = GST_PAD_PAD_TEMPLATE (pad);
378 target = gst_proxy_pad_get_target (pad);
380 /* if we have a real target, proxy the call */
381 res = gst_pad_get_caps_reffed (target);
383 GST_DEBUG_OBJECT (pad, "get caps of target %s:%s : %" GST_PTR_FORMAT,
384 GST_DEBUG_PAD_NAME (target), res);
386 gst_object_unref (target);
388 /* filter against the template */
392 filt = GST_PAD_TEMPLATE_CAPS (templ);
394 tmp = gst_caps_intersect (filt, res);
395 gst_caps_unref (res);
397 GST_DEBUG_OBJECT (pad,
398 "filtered against template gives %" GST_PTR_FORMAT, res);
402 /* else, if we have a template, use its caps. */
404 res = GST_PAD_TEMPLATE_CAPS (templ);
405 GST_DEBUG_OBJECT (pad,
406 "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, res,
408 res = gst_caps_ref (res);
412 /* last resort, any caps */
413 GST_DEBUG_OBJECT (pad, "pad has no template, returning ANY");
414 res = gst_caps_new_any ();
422 * gst_proxy_pad_acceptcaps_default:
423 * @pad: a #GstPad to check
424 * @caps: a #GstCaps to check on the pad
426 * Invoke the default acceptcaps function of the proxy pad.
428 * Returns: TRUE if the pad can accept the caps.
433 gst_proxy_pad_acceptcaps_default (GstPad * pad, GstCaps * caps)
438 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
439 g_return_val_if_fail (caps == NULL || GST_IS_CAPS (caps), FALSE);
441 target = gst_proxy_pad_get_target (pad);
443 res = gst_pad_accept_caps (target, caps);
444 gst_object_unref (target);
446 /* We don't have a target, we return TRUE and we assume that any future
447 * target will be able to deal with any configured caps. */
455 * gst_proxy_pad_fixatecaps_default:
456 * @pad: a #GstPad to fixate
457 * @caps: the #GstCaps to fixate
459 * Invoke the default fixatecaps function of the proxy pad.
464 gst_proxy_pad_fixatecaps_default (GstPad * pad, GstCaps * caps)
468 g_return_if_fail (GST_IS_PROXY_PAD (pad));
469 g_return_if_fail (GST_IS_CAPS (caps));
471 target = gst_proxy_pad_get_target (pad);
473 gst_pad_fixate_caps (target, caps);
474 gst_object_unref (target);
479 * gst_proxy_pad_setcaps_default:
480 * @pad: a #GstPad to set the capabilities of.
481 * @caps: (transfer none): a #GstCaps to set.
483 * Invoke the default setcaps function of the proxy pad.
485 * Returns: TRUE if the caps could be set. FALSE if the caps were not fixed
486 * or bad parameters were provided to this function.
491 gst_proxy_pad_setcaps_default (GstPad * pad, GstCaps * caps)
496 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
497 g_return_val_if_fail (caps == NULL || GST_IS_CAPS (caps), FALSE);
499 target = gst_proxy_pad_get_target (pad);
501 res = gst_pad_set_caps (target, caps);
502 gst_object_unref (target);
504 /* We don't have any target, but we shouldn't return FALSE since this
505 * would stop the actual push of a buffer (which might trigger a pad block
506 * or probe, or properly return GST_FLOW_NOT_LINKED.
514 gst_proxy_pad_set_target_unlocked (GstPad * pad, GstPad * target)
519 GST_LOG_OBJECT (pad, "setting target %s:%s", GST_DEBUG_PAD_NAME (target));
521 if (G_UNLIKELY (GST_PAD_DIRECTION (pad) != GST_PAD_DIRECTION (target)))
522 goto wrong_direction;
524 GST_LOG_OBJECT (pad, "clearing target");
526 /* clear old target */
527 if ((oldtarget = GST_PROXY_PAD_TARGET (pad)))
528 gst_object_unref (oldtarget);
530 /* set and ref new target if any */
532 GST_PROXY_PAD_TARGET (pad) = gst_object_ref (target);
534 GST_PROXY_PAD_TARGET (pad) = NULL;
541 GST_ERROR_OBJECT (pad,
542 "target pad doesn't have the same direction as ourself");
548 gst_proxy_pad_set_target (GstPad * pad, GstPad * target)
552 GST_PROXY_LOCK (pad);
553 result = gst_proxy_pad_set_target_unlocked (pad, target);
554 GST_PROXY_UNLOCK (pad);
560 gst_proxy_pad_get_target (GstPad * pad)
564 GST_PROXY_LOCK (pad);
565 target = GST_PROXY_PAD_TARGET (pad);
567 gst_object_ref (target);
568 GST_PROXY_UNLOCK (pad);
574 * gst_proxy_pad_get_internal:
575 * @pad: the #GstProxyPad
577 * Get the internal pad of @pad. Unref target pad after usage.
579 * The internal pad of a #GstGhostPad is the internally used
580 * pad of opposite direction, which is used to link to the target.
582 * Returns: (transfer full): the target #GstProxyPad, can be NULL.
583 * Unref target pad after usage.
588 gst_proxy_pad_get_internal (GstProxyPad * pad)
592 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
594 GST_PROXY_LOCK (pad);
595 internal = GST_PROXY_PAD_INTERNAL (pad);
597 gst_object_ref (internal);
598 GST_PROXY_UNLOCK (pad);
600 return GST_PROXY_PAD_CAST (internal);
604 * gst_proxy_pad_unlink_default:
605 * @pad: a #GstPad to unlink
607 * Invoke the default unlink function of the proxy pad.
612 gst_proxy_pad_unlink_default (GstPad * pad)
616 /* don't do anything if this unlink resulted from retargeting the pad
617 * controlled by the ghostpad. We only want to invalidate the target pad when
618 * the element suddently unlinked with our internal pad. */
619 if (GST_PROXY_PAD_RETARGET (pad))
622 internal = GST_PROXY_PAD_INTERNAL (pad);
624 GST_DEBUG_OBJECT (pad, "pad is unlinked");
626 gst_proxy_pad_set_target (internal, NULL);
630 gst_proxy_pad_class_init (GstProxyPadClass * klass)
632 GObjectClass *gobject_class = (GObjectClass *) klass;
634 g_type_class_add_private (klass, sizeof (GstProxyPadPrivate));
636 gobject_class->dispose = gst_proxy_pad_dispose;
637 gobject_class->finalize = gst_proxy_pad_finalize;
639 #if !defined(GST_DISABLE_LOADSAVE) && !defined(GST_REMOVE_DEPRECATED)
641 GstObjectClass *gstobject_class = (GstObjectClass *) klass;
643 gstobject_class->save_thyself =
644 ((gpointer (*)(GstObject * object,
646 GST_DEBUG_FUNCPTR (gst_proxy_pad_save_thyself));
649 /* Register common function pointer descriptions */
650 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_query_type_default);
651 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_event_default);
652 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_query_default);
653 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_iterate_internal_links_default);
654 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getcaps_default);
655 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_acceptcaps_default);
656 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_fixatecaps_default);
657 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_setcaps_default);
658 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_unlink_default);
659 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_bufferalloc_default);
660 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_default);
661 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_list_default);
662 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getrange_default);
663 GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_checkgetrange_default);
667 gst_proxy_pad_dispose (GObject * object)
669 GstPad *pad = GST_PAD (object);
672 GST_PROXY_LOCK (pad);
673 /* remove and unref the target */
674 target_p = &GST_PROXY_PAD_TARGET (pad);
675 gst_object_replace ((GstObject **) target_p, NULL);
676 /* The internal is only cleared by GstGhostPad::dispose, since it is the
677 * parent of non-ghost GstProxyPad and owns the refcount on the internal.
679 GST_PROXY_UNLOCK (pad);
681 G_OBJECT_CLASS (gst_proxy_pad_parent_class)->dispose (object);
685 gst_proxy_pad_finalize (GObject * object)
687 GstProxyPad *pad = GST_PROXY_PAD (object);
689 g_mutex_free (GST_PROXY_GET_LOCK (pad));
690 GST_PROXY_GET_LOCK (pad) = NULL;
692 G_OBJECT_CLASS (gst_proxy_pad_parent_class)->finalize (object);
696 gst_proxy_pad_init (GstProxyPad * ppad)
698 GstPad *pad = (GstPad *) ppad;
700 GST_PROXY_PAD_PRIVATE (ppad) = G_TYPE_INSTANCE_GET_PRIVATE (ppad,
701 GST_TYPE_PROXY_PAD, GstProxyPadPrivate);
702 GST_PROXY_GET_LOCK (pad) = g_mutex_new ();
704 gst_pad_set_query_type_function (pad, gst_proxy_pad_query_type_default);
705 gst_pad_set_event_function (pad, gst_proxy_pad_event_default);
706 gst_pad_set_query_function (pad, gst_proxy_pad_query_default);
707 gst_pad_set_iterate_internal_links_function (pad,
708 gst_proxy_pad_iterate_internal_links_default);
710 gst_pad_set_getcaps_function (pad, gst_proxy_pad_getcaps_default);
711 gst_pad_set_acceptcaps_function (pad, gst_proxy_pad_acceptcaps_default);
712 gst_pad_set_fixatecaps_function (pad, gst_proxy_pad_fixatecaps_default);
713 gst_pad_set_setcaps_function (pad, gst_proxy_pad_setcaps_default);
714 gst_pad_set_unlink_function (pad, gst_proxy_pad_unlink_default);
717 #if !defined(GST_DISABLE_LOADSAVE) && !defined(GST_REMOVE_DEPRECATED)
719 * gst_proxy_pad_save_thyself:
720 * @pad: a ghost #GstPad to save.
721 * @parent: the parent #xmlNodePtr to save the description in.
723 * Saves the ghost pad into an xml representation.
725 * Returns: the #xmlNodePtr representation of the pad.
728 gst_proxy_pad_save_thyself (GstObject * object, xmlNodePtr parent)
731 GstProxyPad *proxypad;
735 g_return_val_if_fail (GST_IS_PROXY_PAD (object), NULL);
737 self = xmlNewChild (parent, NULL, (xmlChar *) "ghostpad", NULL);
738 xmlNewChild (self, NULL, (xmlChar *) "name",
739 (xmlChar *) GST_OBJECT_NAME (object));
740 xmlNewChild (self, NULL, (xmlChar *) "parent",
741 (xmlChar *) GST_OBJECT_NAME (GST_OBJECT_PARENT (object)));
743 proxypad = GST_PROXY_PAD_CAST (object);
744 pad = GST_PAD_CAST (proxypad);
745 peer = GST_PAD_CAST (pad->peer);
747 if (GST_IS_PAD (pad)) {
748 if (GST_PAD_IS_SRC (pad))
749 xmlNewChild (self, NULL, (xmlChar *) "direction", (xmlChar *) "source");
750 else if (GST_PAD_IS_SINK (pad))
751 xmlNewChild (self, NULL, (xmlChar *) "direction", (xmlChar *) "sink");
753 xmlNewChild (self, NULL, (xmlChar *) "direction", (xmlChar *) "unknown");
755 xmlNewChild (self, NULL, (xmlChar *) "direction", (xmlChar *) "unknown");
757 if (GST_IS_PAD (peer)) {
758 gchar *content = g_strdup_printf ("%s.%s",
759 GST_OBJECT_NAME (GST_PAD_PARENT (peer)), GST_PAD_NAME (peer));
761 xmlNewChild (self, NULL, (xmlChar *) "peer", (xmlChar *) content);
764 xmlNewChild (self, NULL, (xmlChar *) "peer", NULL);
769 #endif /* GST_DISABLE_LOADSAVE */
772 /***********************************************************************
773 * Ghost pads, implemented as a pair of proxy pads (sort of)
777 #define GST_GHOST_PAD_PRIVATE(obj) (GST_GHOST_PAD_CAST (obj)->priv)
779 struct _GstGhostPadPrivate
781 /* with PROXY_LOCK */
784 gboolean constructed;
787 G_DEFINE_TYPE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
789 static void gst_ghost_pad_dispose (GObject * object);
792 * gst_ghost_pad_internal_activate_push_default:
793 * @pad: the #GstPad to activate or deactivate.
794 * @active: whether the pad should be active or not.
796 * Invoke the default activate push function of a proxy pad that is
797 * owned by a ghost pad.
799 * Returns: %TRUE if the operation was successful.
804 gst_ghost_pad_internal_activate_push_default (GstPad * pad, gboolean active)
809 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
811 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, we're ok",
812 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
814 /* in both cases (SRC and SINK) we activate just the internal pad. The targets
815 * will be activated later (or already in case of a ghost sinkpad). */
816 other = GST_PROXY_PAD_INTERNAL (pad);
817 ret = gst_pad_activate_push (other, active);
823 * gst_ghost_pad_internal_activate_pull_default:
824 * @pad: the #GstPad to activate or deactivate.
825 * @active: whether the pad should be active or not.
827 * Invoke the default activate pull function of a proxy pad that is
828 * owned by a ghost pad.
830 * Returns: %TRUE if the operation was successful.
835 gst_ghost_pad_internal_activate_pull_default (GstPad * pad, gboolean active)
840 g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
842 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
843 GST_DEBUG_PAD_NAME (pad));
845 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
846 /* we are activated in pull mode by our peer element, which is a sinkpad
847 * that wants to operate in pull mode. This activation has to propagate
848 * upstream throught the pipeline. We call the internal activation function,
849 * which will trigger gst_ghost_pad_activate_pull_default, which propagates even
850 * further upstream */
851 GST_LOG_OBJECT (pad, "pad is src, activate internal");
852 other = GST_PROXY_PAD_INTERNAL (pad);
853 ret = gst_pad_activate_pull (other, active);
854 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
855 /* We are SINK, the ghostpad is SRC, we propagate the activation upstream
856 * since we hold a pointer to the upstream peer. */
857 GST_LOG_OBJECT (pad, "activating peer");
858 ret = gst_pad_activate_pull (other, active);
859 gst_object_unref (other);
861 /* this is failure, we can't activate pull if there is no peer */
862 GST_LOG_OBJECT (pad, "not src and no peer, failing");
870 * gst_ghost_pad_activate_push_default:
871 * @pad: the #GstPad to activate or deactivate.
872 * @active: whether the pad should be active or not.
874 * Invoke the default activate push function of a ghost pad.
876 * Returns: %TRUE if the operation was successful.
881 gst_ghost_pad_activate_push_default (GstPad * pad, gboolean active)
886 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
888 GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, proxy internal",
889 (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
891 /* just activate the internal pad */
892 other = GST_PROXY_PAD_INTERNAL (pad);
893 ret = gst_pad_activate_push (other, active);
899 * gst_ghost_pad_activate_pull_default:
900 * @pad: the #GstPad to activate or deactivate.
901 * @active: whether the pad should be active or not.
903 * Invoke the default activate pull function of a ghost pad.
905 * Returns: %TRUE if the operation was successful.
910 gst_ghost_pad_activate_pull_default (GstPad * pad, gboolean active)
915 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
917 GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
918 GST_DEBUG_PAD_NAME (pad));
920 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC) {
921 /* the ghostpad is SRC and activated in pull mode by its peer, call the
922 * activation function of the internal pad to propagate the activation
924 GST_LOG_OBJECT (pad, "pad is src, activate internal");
925 other = GST_PROXY_PAD_INTERNAL (pad);
926 ret = gst_pad_activate_pull (other, active);
927 } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
928 /* We are SINK and activated by the internal pad, propagate activation
929 * upstream because we hold a ref to the upstream peer */
930 GST_LOG_OBJECT (pad, "activating peer");
931 ret = gst_pad_activate_pull (other, active);
932 gst_object_unref (other);
934 /* no peer, we fail */
935 GST_LOG_OBJECT (pad, "pad not src and no peer, failing");
943 * gst_ghost_pad_link_default:
944 * @pad: the #GstPad to link.
945 * @peer: the #GstPad peer
947 * Invoke the default link function of a ghost pad.
949 * Returns: #GstPadLinkReturn of the operation
954 gst_ghost_pad_link_default (GstPad * pad, GstPad * peer)
956 GstPadLinkReturn ret;
959 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), GST_PAD_LINK_REFUSED);
960 g_return_val_if_fail (GST_IS_PAD (peer), GST_PAD_LINK_REFUSED);
962 GST_DEBUG_OBJECT (pad, "linking ghostpad");
964 internal = GST_PROXY_PAD_INTERNAL (pad);
965 if (!gst_proxy_pad_set_target (internal, peer))
968 ret = GST_PAD_LINK_OK;
969 /* if we are a source pad, we should call the peer link function
970 * if the peer has one, see design docs. */
971 if (GST_PAD_IS_SRC (pad)) {
972 if (GST_PAD_LINKFUNC (peer)) {
973 ret = GST_PAD_LINKFUNC (peer) (peer, pad);
974 if (ret != GST_PAD_LINK_OK)
983 GST_DEBUG_OBJECT (pad, "setting target failed");
984 return GST_PAD_LINK_REFUSED;
988 GST_DEBUG_OBJECT (pad, "linking failed");
989 /* clear target again */
990 gst_proxy_pad_set_target (internal, NULL);
996 * gst_ghost_pad_unlink_default:
997 * @pad: the #GstPad to link.
999 * Invoke the default unlink function of a ghost pad.
1004 gst_ghost_pad_unlink_default (GstPad * pad)
1008 g_return_if_fail (GST_IS_GHOST_PAD (pad));
1010 internal = GST_PROXY_PAD_INTERNAL (pad);
1012 GST_DEBUG_OBJECT (pad, "unlinking ghostpad");
1014 /* The target of the internal pad is no longer valid */
1015 gst_proxy_pad_set_target (internal, NULL);
1019 on_int_notify (GstPad * internal, GParamSpec * unused, GstGhostPad * pad)
1024 g_object_get (internal, "caps", &caps, NULL);
1026 GST_DEBUG_OBJECT (pad, "notified %p %" GST_PTR_FORMAT, caps, caps);
1028 GST_OBJECT_LOCK (pad);
1029 changed = (GST_PAD_CAPS (pad) != caps);
1031 gst_caps_replace (&(GST_PAD_CAPS (pad)), caps);
1032 GST_OBJECT_UNLOCK (pad);
1035 #if GLIB_CHECK_VERSION(2,26,0)
1036 g_object_notify_by_pspec ((GObject *) pad, pspec_caps);
1038 g_object_notify ((GObject *) pad, "caps");
1043 gst_caps_unref (caps);
1047 on_src_target_notify (GstPad * target, GParamSpec * unused, gpointer user_data)
1049 GstProxyPad *proxypad;
1054 g_object_get (target, "caps", &caps, NULL);
1056 GST_OBJECT_LOCK (target);
1057 /* First check if the peer is still available and our proxy pad */
1058 if (!GST_PAD_PEER (target) || !GST_IS_PROXY_PAD (GST_PAD_PEER (target))) {
1059 GST_OBJECT_UNLOCK (target);
1063 proxypad = GST_PROXY_PAD (GST_PAD_PEER (target));
1064 GST_PROXY_LOCK (proxypad);
1065 /* Now check if the proxypad's internal pad is still there and
1067 if (!GST_PROXY_PAD_INTERNAL (proxypad) ||
1068 !GST_IS_GHOST_PAD (GST_PROXY_PAD_INTERNAL (proxypad))) {
1069 GST_OBJECT_UNLOCK (target);
1070 GST_PROXY_UNLOCK (proxypad);
1073 gpad = GST_GHOST_PAD (GST_PROXY_PAD_INTERNAL (proxypad));
1074 g_object_ref (gpad);
1075 GST_PROXY_UNLOCK (proxypad);
1076 GST_OBJECT_UNLOCK (target);
1078 GST_OBJECT_LOCK (gpad);
1080 GST_DEBUG_OBJECT (gpad, "notified %p %" GST_PTR_FORMAT, caps, caps);
1082 changed = (GST_PAD_CAPS (gpad) != caps);
1084 gst_caps_replace (&(GST_PAD_CAPS (gpad)), caps);
1085 GST_OBJECT_UNLOCK (gpad);
1088 #if GLIB_CHECK_VERSION(2,26,0)
1089 g_object_notify_by_pspec ((GObject *) gpad, pspec_caps);
1091 g_object_notify ((GObject *) gpad, "caps");
1095 g_object_unref (gpad);
1099 gst_caps_unref (caps);
1103 * gst_ghost_pad_setcaps_default:
1104 * @pad: the #GstPad to link.
1105 * @caps: (transfer none): the #GstCaps to set
1107 * Invoke the default setcaps function of a ghost pad.
1109 * Returns: %TRUE if the operation was successful
1114 gst_ghost_pad_setcaps_default (GstPad * pad, GstCaps * caps)
1116 g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
1117 g_return_val_if_fail (caps == NULL || GST_IS_CAPS (caps), FALSE);
1119 if (GST_PAD_DIRECTION (pad) == GST_PAD_SRC)
1122 return gst_proxy_pad_setcaps_default (pad, caps);
1126 gst_ghost_pad_class_init (GstGhostPadClass * klass)
1128 GObjectClass *gobject_class = (GObjectClass *) klass;
1130 g_type_class_add_private (klass, sizeof (GstGhostPadPrivate));
1132 pspec_caps = g_object_class_find_property (gobject_class, "caps");
1134 gobject_class->dispose = gst_ghost_pad_dispose;
1136 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_setcaps_default);
1137 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_pull_default);
1138 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_push_default);
1139 GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_link_default);
1143 gst_ghost_pad_init (GstGhostPad * pad)
1145 GST_GHOST_PAD_PRIVATE (pad) = G_TYPE_INSTANCE_GET_PRIVATE (pad,
1146 GST_TYPE_GHOST_PAD, GstGhostPadPrivate);
1148 gst_pad_set_setcaps_function (GST_PAD_CAST (pad),
1149 gst_ghost_pad_setcaps_default);
1150 gst_pad_set_activatepull_function (GST_PAD_CAST (pad),
1151 gst_ghost_pad_activate_pull_default);
1152 gst_pad_set_activatepush_function (GST_PAD_CAST (pad),
1153 gst_ghost_pad_activate_push_default);
1157 gst_ghost_pad_dispose (GObject * object)
1163 pad = GST_PAD (object);
1165 GST_DEBUG_OBJECT (pad, "dispose");
1167 gst_ghost_pad_set_target (GST_GHOST_PAD (pad), NULL);
1169 /* Unlink here so that gst_pad_dispose doesn't. That would lead to a call to
1170 * gst_ghost_pad_unlink_default when the ghost pad is in an inconsistent state */
1171 peer = gst_pad_get_peer (pad);
1173 if (GST_PAD_IS_SRC (pad))
1174 gst_pad_unlink (pad, peer);
1176 gst_pad_unlink (peer, pad);
1178 gst_object_unref (peer);
1181 GST_PROXY_LOCK (pad);
1182 internal = GST_PROXY_PAD_INTERNAL (pad);
1184 gst_pad_set_activatepull_function (internal, NULL);
1185 gst_pad_set_activatepush_function (internal, NULL);
1187 g_signal_handler_disconnect (internal,
1188 GST_GHOST_PAD_PRIVATE (pad)->notify_id);
1190 /* disposes of the internal pad, since the ghostpad is the only possible object
1191 * that has a refcount on the internal pad. */
1192 gst_object_unparent (GST_OBJECT_CAST (internal));
1193 GST_PROXY_PAD_INTERNAL (pad) = NULL;
1195 GST_PROXY_UNLOCK (pad);
1197 G_OBJECT_CLASS (gst_ghost_pad_parent_class)->dispose (object);
1201 * gst_ghost_pad_construct:
1202 * @gpad: the newly allocated ghost pad
1204 * Finish initialization of a newly allocated ghost pad.
1206 * This function is most useful in language bindings and when subclassing
1207 * #GstGhostPad; plugin and application developers normally will not call this
1208 * function. Call this function directly after a call to g_object_new
1209 * (GST_TYPE_GHOST_PAD, "direction", @dir, ..., NULL).
1211 * Returns: %TRUE if the construction succeeds, %FALSE otherwise.
1216 gst_ghost_pad_construct (GstGhostPad * gpad)
1218 GstPadDirection dir, otherdir;
1219 GstPadTemplate *templ;
1220 GstPad *pad, *internal;
1222 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
1223 g_return_val_if_fail (GST_GHOST_PAD_PRIVATE (gpad)->constructed == FALSE,
1226 g_object_get (gpad, "direction", &dir, "template", &templ, NULL);
1228 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, FALSE);
1230 pad = GST_PAD (gpad);
1232 /* Set directional padfunctions for ghostpad */
1233 if (dir == GST_PAD_SINK) {
1234 gst_pad_set_bufferalloc_function (pad, gst_proxy_pad_bufferalloc_default);
1235 gst_pad_set_chain_function (pad, gst_proxy_pad_chain_default);
1236 gst_pad_set_chain_list_function (pad, gst_proxy_pad_chain_list_default);
1238 gst_pad_set_getrange_function (pad, gst_proxy_pad_getrange_default);
1239 gst_pad_set_checkgetrange_function (pad,
1240 gst_proxy_pad_checkgetrange_default);
1243 /* link/unlink functions */
1244 gst_pad_set_link_function (pad, gst_ghost_pad_link_default);
1245 gst_pad_set_unlink_function (pad, gst_ghost_pad_unlink_default);
1247 /* INTERNAL PAD, it always exists and is child of the ghostpad */
1248 otherdir = (dir == GST_PAD_SRC) ? GST_PAD_SINK : GST_PAD_SRC;
1251 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
1252 "direction", otherdir, "template", templ, NULL);
1253 /* release ref obtained via g_object_get */
1254 gst_object_unref (templ);
1257 g_object_new (GST_TYPE_PROXY_PAD, "name", NULL,
1258 "direction", otherdir, NULL);
1260 GST_PAD_UNSET_FLUSHING (internal);
1262 /* Set directional padfunctions for internal pad */
1263 if (dir == GST_PAD_SRC) {
1264 gst_pad_set_bufferalloc_function (internal,
1265 gst_proxy_pad_bufferalloc_default);
1266 gst_pad_set_chain_function (internal, gst_proxy_pad_chain_default);
1267 gst_pad_set_chain_list_function (internal,
1268 gst_proxy_pad_chain_list_default);
1270 gst_pad_set_getrange_function (internal, gst_proxy_pad_getrange_default);
1271 gst_pad_set_checkgetrange_function (internal,
1272 gst_proxy_pad_checkgetrange_default);
1275 GST_PROXY_LOCK (pad);
1277 /* now make the ghostpad a parent of the internal pad */
1278 if (!gst_object_set_parent (GST_OBJECT_CAST (internal),
1279 GST_OBJECT_CAST (pad)))
1282 /* The ghostpad is the parent of the internal pad and is the only object that
1283 * can have a refcount on the internal pad.
1284 * At this point, the GstGhostPad has a refcount of 1, and the internal pad has
1286 * When the refcount of the GstGhostPad drops to 0, the ghostpad will dispose
1287 * its refcount on the internal pad in the dispose method by un-parenting it.
1288 * This is why we don't take extra refcounts in the assignments below
1290 GST_PROXY_PAD_INTERNAL (pad) = internal;
1291 GST_PROXY_PAD_INTERNAL (internal) = pad;
1293 /* could be more general here, iterating over all writable properties...
1294 * taking the short road for now tho */
1295 GST_GHOST_PAD_PRIVATE (pad)->notify_id =
1296 g_signal_connect (internal, "notify::caps", G_CALLBACK (on_int_notify),
1299 /* call function to init values of the pad caps */
1300 on_int_notify (internal, NULL, GST_GHOST_PAD_CAST (pad));
1302 /* special activation functions for the internal pad */
1303 gst_pad_set_activatepull_function (internal,
1304 gst_ghost_pad_internal_activate_pull_default);
1305 gst_pad_set_activatepush_function (internal,
1306 gst_ghost_pad_internal_activate_push_default);
1308 GST_PROXY_UNLOCK (pad);
1310 GST_GHOST_PAD_PRIVATE (gpad)->constructed = TRUE;
1316 GST_WARNING_OBJECT (gpad, "Could not set internal pad %s:%s",
1317 GST_DEBUG_PAD_NAME (internal));
1318 g_critical ("Could not set internal pad %s:%s",
1319 GST_DEBUG_PAD_NAME (internal));
1320 GST_PROXY_UNLOCK (pad);
1321 gst_object_unref (internal);
1327 gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
1328 GstPadTemplate * templ)
1332 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
1334 /* OBJECT CREATION */
1336 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
1337 "direction", dir, "template", templ, NULL);
1339 ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
1340 "direction", dir, NULL);
1343 if (!gst_ghost_pad_construct (ret))
1344 goto construct_failed;
1346 return GST_PAD_CAST (ret);
1349 /* already logged */
1350 gst_object_unref (ret);
1355 * gst_ghost_pad_new_no_target:
1356 * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
1357 * @dir: the direction of the ghostpad
1359 * Create a new ghostpad without a target with the given direction.
1360 * A target can be set on the ghostpad later with the
1361 * gst_ghost_pad_set_target() function.
1363 * The created ghostpad will not have a padtemplate.
1365 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
1368 gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
1372 g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
1374 GST_LOG ("name:%s, direction:%d", GST_STR_NULL (name), dir);
1376 ret = gst_ghost_pad_new_full (name, dir, NULL);
1382 * gst_ghost_pad_new:
1383 * @name: (allow-none): the name of the new pad, or NULL to assign a default name
1384 * @target: (transfer none): the pad to ghost.
1386 * Create a new ghostpad with @target as the target. The direction will be taken
1387 * from the target pad. @target must be unlinked.
1389 * Will ref the target.
1391 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
1394 gst_ghost_pad_new (const gchar * name, GstPad * target)
1398 g_return_val_if_fail (GST_IS_PAD (target), NULL);
1399 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
1401 GST_LOG ("name:%s, target:%s:%s", GST_STR_NULL (name),
1402 GST_DEBUG_PAD_NAME (target));
1404 if ((ret = gst_ghost_pad_new_no_target (name, GST_PAD_DIRECTION (target))))
1405 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
1406 goto set_target_failed;
1413 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
1414 GST_DEBUG_PAD_NAME (target));
1415 gst_object_unref (ret);
1421 * gst_ghost_pad_new_from_template:
1422 * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
1423 * @target: (transfer none): the pad to ghost.
1424 * @templ: (transfer none): the #GstPadTemplate to use on the ghostpad.
1426 * Create a new ghostpad with @target as the target. The direction will be taken
1427 * from the target pad. The template used on the ghostpad will be @template.
1429 * Will ref the target.
1431 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
1437 gst_ghost_pad_new_from_template (const gchar * name, GstPad * target,
1438 GstPadTemplate * templ)
1442 g_return_val_if_fail (GST_IS_PAD (target), NULL);
1443 g_return_val_if_fail (!gst_pad_is_linked (target), NULL);
1444 g_return_val_if_fail (templ != NULL, NULL);
1445 g_return_val_if_fail (GST_PAD_TEMPLATE_DIRECTION (templ) ==
1446 GST_PAD_DIRECTION (target), NULL);
1448 GST_LOG ("name:%s, target:%s:%s, templ:%p", GST_STR_NULL (name),
1449 GST_DEBUG_PAD_NAME (target), templ);
1451 if ((ret = gst_ghost_pad_new_full (name, GST_PAD_DIRECTION (target), templ)))
1452 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (ret), target))
1453 goto set_target_failed;
1460 GST_WARNING_OBJECT (ret, "failed to set target %s:%s",
1461 GST_DEBUG_PAD_NAME (target));
1462 gst_object_unref (ret);
1468 * gst_ghost_pad_new_no_target_from_template:
1469 * @name: (allow-none): the name of the new pad, or NULL to assign a default name
1470 * @templ: (transfer none): the #GstPadTemplate to create the ghostpad from.
1472 * Create a new ghostpad based on @templ, without setting a target. The
1473 * direction will be taken from the @templ.
1475 * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
1480 gst_ghost_pad_new_no_target_from_template (const gchar * name,
1481 GstPadTemplate * templ)
1485 g_return_val_if_fail (templ != NULL, NULL);
1488 gst_ghost_pad_new_full (name, GST_PAD_TEMPLATE_DIRECTION (templ), templ);
1494 * gst_ghost_pad_get_target:
1495 * @gpad: the #GstGhostPad
1497 * Get the target pad of @gpad. Unref target pad after usage.
1499 * Returns: (transfer full): the target #GstPad, can be NULL if the ghostpad
1500 * has no target set. Unref target pad after usage.
1503 gst_ghost_pad_get_target (GstGhostPad * gpad)
1507 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), NULL);
1509 ret = gst_proxy_pad_get_target (GST_PAD_CAST (gpad));
1511 GST_DEBUG_OBJECT (gpad, "get target %s:%s", GST_DEBUG_PAD_NAME (ret));
1517 * gst_ghost_pad_set_target:
1518 * @gpad: the #GstGhostPad
1519 * @newtarget: (transfer none) (allow-none): the new pad target
1521 * Set the new target of the ghostpad @gpad. Any existing target
1522 * is unlinked and links to the new target are established. if @newtarget is
1523 * NULL the target will be cleared.
1525 * Returns: (transfer full): TRUE if the new target could be set. This function
1526 * can return FALSE when the internal pads could not be linked.
1529 gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
1534 GstPadLinkReturn lret;
1536 g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
1537 g_return_val_if_fail (GST_PAD_CAST (gpad) != newtarget, FALSE);
1538 g_return_val_if_fail (newtarget != GST_PROXY_PAD_INTERNAL (gpad), FALSE);
1540 /* no need for locking, the internal pad's lifecycle is directly linked to the
1542 internal = GST_PROXY_PAD_INTERNAL (gpad);
1545 GST_DEBUG_OBJECT (gpad, "set target %s:%s", GST_DEBUG_PAD_NAME (newtarget));
1547 GST_DEBUG_OBJECT (gpad, "clearing target");
1549 /* clear old target */
1550 GST_PROXY_LOCK (gpad);
1551 if ((oldtarget = GST_PROXY_PAD_TARGET (gpad))) {
1552 if (GST_PAD_IS_SRC (oldtarget)) {
1553 g_signal_handlers_disconnect_by_func (oldtarget,
1554 (gpointer) on_src_target_notify, NULL);
1557 GST_PROXY_PAD_RETARGET (internal) = TRUE;
1559 /* unlink internal pad */
1560 if (GST_PAD_IS_SRC (internal))
1561 gst_pad_unlink (internal, oldtarget);
1563 gst_pad_unlink (oldtarget, internal);
1565 GST_PROXY_PAD_RETARGET (internal) = FALSE;
1568 result = gst_proxy_pad_set_target_unlocked (GST_PAD_CAST (gpad), newtarget);
1569 GST_PROXY_UNLOCK (gpad);
1571 if (result && newtarget) {
1572 if (GST_PAD_IS_SRC (newtarget)) {
1573 g_signal_connect (newtarget, "notify::caps",
1574 G_CALLBACK (on_src_target_notify), NULL);
1577 /* and link to internal pad without any checks */
1578 GST_DEBUG_OBJECT (gpad, "connecting internal pad to target");
1580 if (GST_PAD_IS_SRC (internal))
1582 gst_pad_link_full (internal, newtarget, GST_PAD_LINK_CHECK_NOTHING);
1585 gst_pad_link_full (newtarget, internal, GST_PAD_LINK_CHECK_NOTHING);
1587 if (lret != GST_PAD_LINK_OK)
1596 GST_WARNING_OBJECT (gpad, "could not link internal and target, reason:%d",
1598 /* and unset target again */
1599 GST_PROXY_LOCK (gpad);
1600 gst_proxy_pad_set_target_unlocked (GST_PAD_CAST (gpad), NULL);
1601 GST_PROXY_UNLOCK (gpad);