gst: Don't pass miniobjects to GST_DEBUG_OBJECT() and similar macros
[platform/upstream/gstreamer.git] / gst / gstghostpad.c
index f96fbd8..ffbe650 100644 (file)
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 /**
  * SECTION:gstghostpad
+ * @title: GstGhostPad
  * @short_description: Pseudo link pads
  * @see_also: #GstPad
  *
@@ -40,8 +41,6 @@
  * association later on.
  *
  * Note that GhostPads add overhead to the data processing of a pipeline.
- *
- * Last reviewed on 2005-11-18 (0.9.5)
  */
 
 #include "gst_private.h"
 #define GST_PROXY_PAD_TARGET(pad)       (GST_PAD_PEER (GST_PROXY_PAD_INTERNAL (pad)))
 #define GST_PROXY_PAD_INTERNAL(pad)     (GST_PROXY_PAD_PRIVATE (pad)->internal)
 
+#define GST_PROXY_PAD_ACQUIRE_INTERNAL(pad, internal, retval)           \
+  internal =                                                            \
+      GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD_CAST (pad))); \
+  if (internal == NULL)                                                 \
+    return retval;
+
+#define GST_PROXY_PAD_RELEASE_INTERNAL(internal) gst_object_unref (internal);
+
 struct _GstProxyPadPrivate
 {
   GstPad *internal;
 };
 
-G_DEFINE_TYPE (GstProxyPad, gst_proxy_pad, GST_TYPE_PAD);
+G_DEFINE_TYPE_WITH_PRIVATE (GstProxyPad, gst_proxy_pad, GST_TYPE_PAD);
 
 static GstPad *gst_proxy_pad_get_target (GstPad * pad);
 
 /**
- * gst_proxy_pad_query_type_default:
- * @pad: a #GstPad.
- *
- * Invoke the default query type handler of the proxy pad.
- *
- * Returns: (transfer none) (array zero-terminated=1): a zero-terminated array
- *     of #GstQueryType.
- *
- * Since: 0.10.35
- */
-const GstQueryType *
-gst_proxy_pad_query_type_default (GstPad * pad)
-{
-  GstPad *target;
-  const GstQueryType *res = NULL;
-
-  g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
-
-  if (!(target = gst_proxy_pad_get_target (pad)))
-    goto no_target;
-
-  res = gst_pad_get_query_types (target);
-  gst_object_unref (target);
-
-  return res;
-
-  /* ERRORS */
-no_target:
-  {
-    GST_DEBUG_OBJECT (pad, "no target pad");
-    return FALSE;
-  }
-}
-
-/**
- * gst_proxy_pad_event_default:
- * @pad: a #GstPad to push the event to.
- * @event: (transfer full): the #GstEvent to send to the pad.
- *
- * Invoke the default event of the proxy pad.
- *
- * Returns: TRUE if the event was handled.
- *
- * Since: 0.10.35
- */
-gboolean
-gst_proxy_pad_event_default (GstPad * pad, GstEvent * event)
-{
-  gboolean res;
-  GstPad *internal;
-
-  g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
-  g_return_val_if_fail (GST_IS_EVENT (event), FALSE);
-
-  internal = GST_PROXY_PAD_INTERNAL (pad);
-  res = gst_pad_push_event (internal, event);
-
-  return res;
-}
-
-/**
- * gst_proxy_pad_query_default:
- * @pad: a #GstPad to invoke the default query on.
- * @query: (transfer none): the #GstQuery to perform.
- *
- * Invoke the default query function of the proxy pad.
- *
- * Returns: TRUE if the query could be performed.
- *
- * Since: 0.10.35
- */
-gboolean
-gst_proxy_pad_query_default (GstPad * pad, GstQuery * query)
-{
-  gboolean res;
-  GstPad *target;
-
-  g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
-  g_return_val_if_fail (GST_IS_QUERY (query), FALSE);
-
-  if (!(target = gst_proxy_pad_get_target (pad)))
-    goto no_target;
-
-  res = gst_pad_query (target, query);
-  gst_object_unref (target);
-
-  return res;
-
-  /* ERRORS */
-no_target:
-  {
-    GST_DEBUG_OBJECT (pad, "no target pad");
-    return FALSE;
-  }
-}
-
-/**
- * gst_proyx_pad_iterate_internal_links_default:
+ * gst_proxy_pad_iterate_internal_links_default:
  * @pad: the #GstPad to get the internal links of.
+ * @parent: (allow-none): the parent of @pad or %NULL
  *
  * Invoke the default iterate internal links function of the proxy pad.
  *
- * Returns: a #GstIterator of #GstPad, or NULL if @pad has no parent. Unref each
- * returned pad with gst_object_unref().
- *
- * Since: 0.10.35
+ * Returns: (nullable): a #GstIterator of #GstPad, or %NULL if @pad
+ * has no parent. Unref each returned pad with gst_object_unref().
  */
 GstIterator *
-gst_proxy_pad_iterate_internal_links_default (GstPad * pad)
+gst_proxy_pad_iterate_internal_links_default (GstPad * pad, GstObject * parent)
 {
   GstIterator *res = NULL;
   GstPad *internal;
@@ -183,9 +92,10 @@ gst_proxy_pad_iterate_internal_links_default (GstPad * pad)
 
   g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
 
-  internal = GST_PROXY_PAD_INTERNAL (pad);
+  GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, NULL);
+
   g_value_init (&v, GST_TYPE_PAD);
-  g_value_set_object (&v, internal);
+  g_value_take_object (&v, internal);
   res = gst_iterator_new_single (GST_TYPE_PAD, &v);
   g_value_unset (&v);
 
@@ -195,17 +105,17 @@ gst_proxy_pad_iterate_internal_links_default (GstPad * pad)
 /**
  * gst_proxy_pad_chain_default:
  * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
+ * @parent: (allow-none): the parent of @pad or %NULL
  * @buffer: (transfer full): the #GstBuffer to send, return GST_FLOW_ERROR
  *     if not.
  *
  * Invoke the default chain function of the proxy pad.
  *
  * Returns: a #GstFlowReturn from the pad.
- *
- * Since: 0.10.35
  */
 GstFlowReturn
-gst_proxy_pad_chain_default (GstPad * pad, GstBuffer * buffer)
+gst_proxy_pad_chain_default (GstPad * pad, GstObject * parent,
+    GstBuffer * buffer)
 {
   GstFlowReturn res;
   GstPad *internal;
@@ -213,8 +123,9 @@ gst_proxy_pad_chain_default (GstPad * pad, GstBuffer * buffer)
   g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
   g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
 
-  internal = GST_PROXY_PAD_INTERNAL (pad);
+  GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
   res = gst_pad_push (internal, buffer);
+  GST_PROXY_PAD_RELEASE_INTERNAL (internal);
 
   return res;
 }
@@ -222,17 +133,17 @@ gst_proxy_pad_chain_default (GstPad * pad, GstBuffer * buffer)
 /**
  * gst_proxy_pad_chain_list_default:
  * @pad: a sink #GstPad, returns GST_FLOW_ERROR if not.
+ * @parent: (allow-none): the parent of @pad or %NULL
  * @list: (transfer full): the #GstBufferList to send, return GST_FLOW_ERROR
  *     if not.
  *
  * Invoke the default chain list function of the proxy pad.
  *
  * Returns: a #GstFlowReturn from the pad.
- *
- * Since: 0.10.35
  */
 GstFlowReturn
-gst_proxy_pad_chain_list_default (GstPad * pad, GstBufferList * list)
+gst_proxy_pad_chain_list_default (GstPad * pad, GstObject * parent,
+    GstBufferList * list)
 {
   GstFlowReturn res;
   GstPad *internal;
@@ -240,15 +151,17 @@ gst_proxy_pad_chain_list_default (GstPad * pad, GstBufferList * list)
   g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
   g_return_val_if_fail (GST_IS_BUFFER_LIST (list), GST_FLOW_ERROR);
 
-  internal = GST_PROXY_PAD_INTERNAL (pad);
+  GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
   res = gst_pad_push_list (internal, list);
+  GST_PROXY_PAD_RELEASE_INTERNAL (internal);
 
   return res;
 }
 
 /**
- * gst_proxy_pad_get_range_default:
+ * gst_proxy_pad_getrange_default:
  * @pad: a src #GstPad, returns #GST_FLOW_ERROR if not.
+ * @parent: the parent of @pad
  * @offset: The start offset of the buffer
  * @size: The length of the buffer
  * @buffer: (out callee-allocates): a pointer to hold the #GstBuffer,
@@ -257,12 +170,10 @@ gst_proxy_pad_chain_list_default (GstPad * pad, GstBufferList * list)
  * Invoke the default getrange function of the proxy pad.
  *
  * Returns: a #GstFlowReturn from the pad.
- *
- * Since: 0.10.35
  */
 GstFlowReturn
-gst_proxy_pad_getrange_default (GstPad * pad, guint64 offset, guint size,
-    GstBuffer ** buffer)
+gst_proxy_pad_getrange_default (GstPad * pad, GstObject * parent,
+    guint64 offset, guint size, GstBuffer ** buffer)
 {
   GstFlowReturn res;
   GstPad *internal;
@@ -270,167 +181,20 @@ gst_proxy_pad_getrange_default (GstPad * pad, guint64 offset, guint size,
   g_return_val_if_fail (GST_IS_PROXY_PAD (pad), GST_FLOW_ERROR);
   g_return_val_if_fail (buffer != NULL, GST_FLOW_ERROR);
 
-  internal = GST_PROXY_PAD_INTERNAL (pad);
+  GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, internal, GST_FLOW_NOT_LINKED);
   res = gst_pad_pull_range (internal, offset, size, buffer);
+  GST_PROXY_PAD_RELEASE_INTERNAL (internal);
 
   return res;
 }
 
-/**
- * gst_proxy_pad_getcaps_default:
- * @pad: a #GstPad to get the capabilities of.
- * @filter: a #GstCaps filter.
- *
- * Invoke the default getcaps function of the proxy pad.
- *
- * Returns: (transfer full): the caps of the pad with incremented ref-count
- *
- * Since: 0.10.35
- */
-GstCaps *
-gst_proxy_pad_getcaps_default (GstPad * pad, GstCaps * filter)
-{
-  GstPad *target;
-  GstCaps *res;
-  GstPadTemplate *templ;
-
-  g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
-
-  templ = GST_PAD_PAD_TEMPLATE (pad);
-  target = gst_proxy_pad_get_target (pad);
-  if (target) {
-    /* if we have a real target, proxy the call */
-    res = gst_pad_get_caps (target, filter);
-
-    GST_DEBUG_OBJECT (pad, "get caps of target %s:%s : %" GST_PTR_FORMAT,
-        GST_DEBUG_PAD_NAME (target), res);
-
-    gst_object_unref (target);
-
-    /* filter against the template */
-    if (templ && res) {
-      GstCaps *filt, *tmp;
-
-      filt = GST_PAD_TEMPLATE_CAPS (templ);
-      if (filt) {
-        tmp = gst_caps_intersect_full (res, filt, GST_CAPS_INTERSECT_FIRST);
-        gst_caps_unref (res);
-        res = tmp;
-        GST_DEBUG_OBJECT (pad,
-            "filtered against template gives %" GST_PTR_FORMAT, res);
-      }
-    }
-  } else {
-    /* else, if we have a template, use its caps. */
-    if (templ) {
-      res = GST_PAD_TEMPLATE_CAPS (templ);
-      GST_DEBUG_OBJECT (pad,
-          "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, res,
-          res);
-      res = gst_caps_ref (res);
-
-      if (filter) {
-        GstCaps *intersection =
-            gst_caps_intersect_full (filter, res, GST_CAPS_INTERSECT_FIRST);
-
-        gst_caps_unref (res);
-        res = intersection;
-      }
-
-      goto done;
-    }
-
-    /* If there's a filter, return that */
-    if (filter != NULL) {
-      res = gst_caps_ref (filter);
-      goto done;
-    }
-
-    /* last resort, any caps */
-    GST_DEBUG_OBJECT (pad, "pad has no template, returning ANY");
-    res = gst_caps_new_any ();
-  }
-
-done:
-  return res;
-}
-
-/**
- * gst_proxy_pad_acceptcaps_default:
- * @pad: a #GstPad to check
- * @caps: a #GstCaps to check on the pad
- *
- * Invoke the default acceptcaps function of the proxy pad.
- *
- * Returns: TRUE if the pad can accept the caps.
- *
- * Since: 0.10.35
- */
-gboolean
-gst_proxy_pad_acceptcaps_default (GstPad * pad, GstCaps * caps)
-{
-  GstPad *target;
-  gboolean res;
-
-  g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
-  g_return_val_if_fail (caps == NULL || GST_IS_CAPS (caps), FALSE);
-
-  target = gst_proxy_pad_get_target (pad);
-  if (target) {
-    res = gst_pad_accept_caps (target, caps);
-    gst_object_unref (target);
-  } else {
-    GST_DEBUG_OBJECT (pad, "no target");
-    /* We don't have a target, we return TRUE and we assume that any future
-     * target will be able to deal with any configured caps. */
-    res = TRUE;
-  }
-
-  return res;
-}
-
-/**
- * gst_proxy_pad_fixatecaps_default:
- * @pad: a  #GstPad to fixate
- * @caps: the  #GstCaps to fixate
- *
- * Invoke the default fixatecaps function of the proxy pad.
- *
- * Since: 0.10.35
- */
-void
-gst_proxy_pad_fixatecaps_default (GstPad * pad, GstCaps * caps)
-{
-  GstPad *target;
-
-  g_return_if_fail (GST_IS_PROXY_PAD (pad));
-  g_return_if_fail (GST_IS_CAPS (caps));
-
-  if (!(target = gst_proxy_pad_get_target (pad)))
-    goto no_target;
-
-  gst_pad_fixate_caps (target, caps);
-  gst_object_unref (target);
-
-  return;
-
-  /* ERRORS */
-no_target:
-  {
-    GST_DEBUG_OBJECT (pad, "no target");
-    return;
-  }
-}
-
 static GstPad *
 gst_proxy_pad_get_target (GstPad * pad)
 {
   GstPad *target;
 
   GST_OBJECT_LOCK (pad);
-  target = GST_PROXY_PAD_TARGET (pad);
-  if (target)
-    gst_object_ref (target);
+  target = gst_pad_get_peer (GST_PROXY_PAD_INTERNAL (pad));
   GST_OBJECT_UNLOCK (pad);
 
   return target;
@@ -445,10 +209,8 @@ gst_proxy_pad_get_target (GstPad * pad)
  * The internal pad of a #GstGhostPad is the internally used
  * pad of opposite direction, which is used to link to the target.
  *
- * Returns: (transfer full): the target #GstProxyPad, can be NULL.
- * Unref target pad after usage.
- *
- * Since: 0.10.35
+ * Returns: (transfer full) (nullable): the target #GstProxyPad, can
+ * be %NULL.  Unref target pad after usage.
  */
 GstProxyPad *
 gst_proxy_pad_get_internal (GstProxyPad * pad)
@@ -466,35 +228,11 @@ gst_proxy_pad_get_internal (GstProxyPad * pad)
   return GST_PROXY_PAD_CAST (internal);
 }
 
-/**
- * gst_proxy_pad_unlink_default:
- * @pad: a #GstPad to unlink
- *
- * Invoke the default unlink function of the proxy pad.
- *
- * Since: 0.10.35
- */
-void
-gst_proxy_pad_unlink_default (GstPad * pad)
-{
-  /* nothing to do anymore */
-  GST_DEBUG_OBJECT (pad, "pad is unlinked");
-}
-
 static void
 gst_proxy_pad_class_init (GstProxyPadClass * klass)
 {
-  g_type_class_add_private (klass, sizeof (GstProxyPadPrivate));
-
   /* Register common function pointer descriptions */
-  GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_query_type_default);
-  GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_event_default);
-  GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_query_default);
   GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_iterate_internal_links_default);
-  GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getcaps_default);
-  GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_acceptcaps_default);
-  GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_fixatecaps_default);
-  GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_unlink_default);
   GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_default);
   GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_chain_list_default);
   GST_DEBUG_REGISTER_FUNCPTR (gst_proxy_pad_getrange_default);
@@ -505,19 +243,14 @@ gst_proxy_pad_init (GstProxyPad * ppad)
 {
   GstPad *pad = (GstPad *) ppad;
 
-  GST_PROXY_PAD_PRIVATE (ppad) = G_TYPE_INSTANCE_GET_PRIVATE (ppad,
-      GST_TYPE_PROXY_PAD, GstProxyPadPrivate);
+  GST_PROXY_PAD_PRIVATE (ppad) = gst_proxy_pad_get_instance_private (ppad);
 
-  gst_pad_set_query_type_function (pad, gst_proxy_pad_query_type_default);
-  gst_pad_set_event_function (pad, gst_proxy_pad_event_default);
-  gst_pad_set_query_function (pad, gst_proxy_pad_query_default);
   gst_pad_set_iterate_internal_links_function (pad,
       gst_proxy_pad_iterate_internal_links_default);
 
-  gst_pad_set_getcaps_function (pad, gst_proxy_pad_getcaps_default);
-  gst_pad_set_acceptcaps_function (pad, gst_proxy_pad_acceptcaps_default);
-  gst_pad_set_fixatecaps_function (pad, gst_proxy_pad_fixatecaps_default);
-  gst_pad_set_unlink_function (pad, gst_proxy_pad_unlink_default);
+  GST_PAD_SET_PROXY_CAPS (pad);
+  GST_PAD_SET_PROXY_SCHEDULING (pad);
+  GST_PAD_SET_PROXY_ALLOCATION (pad);
 }
 
 
@@ -534,61 +267,36 @@ struct _GstGhostPadPrivate
   gboolean constructed;
 };
 
-G_DEFINE_TYPE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
+G_DEFINE_TYPE_WITH_PRIVATE (GstGhostPad, gst_ghost_pad, GST_TYPE_PROXY_PAD);
 
 static void gst_ghost_pad_dispose (GObject * object);
 
-/**
- * gst_ghost_pad_internal_activate_push_default:
- * @pad: the #GstPad to activate or deactivate.
- * @active: whether the pad should be active or not.
- *
- * Invoke the default activate push function of a proxy pad that is
- * owned by a ghost pad.
- *
- * Returns: %TRUE if the operation was successful.
- *
- * Since: 0.10.35
- */
-gboolean
-gst_ghost_pad_internal_activate_push_default (GstPad * pad, gboolean active)
+static gboolean
+gst_ghost_pad_internal_activate_push_default (GstPad * pad, GstObject * parent,
+    gboolean active)
 {
   gboolean ret;
   GstPad *other;
 
-  g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
-
   GST_LOG_OBJECT (pad, "%sactivate push on %s:%s, we're ok",
       (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
 
   /* in both cases (SRC and SINK) we activate just the internal pad. The targets
    * will be activated later (or already in case of a ghost sinkpad). */
-  other = GST_PROXY_PAD_INTERNAL (pad);
-  ret = gst_pad_activate_push (other, active);
+  GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
+  ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
+  GST_PROXY_PAD_RELEASE_INTERNAL (other);
 
   return ret;
 }
 
-/**
- * gst_ghost_pad_internal_activate_pull_default:
- * @pad: the #GstPad to activate or deactivate.
- * @active: whether the pad should be active or not.
- *
- * Invoke the default activate pull function of a proxy pad that is
- * owned by a ghost pad.
- *
- * Returns: %TRUE if the operation was successful.
- *
- * Since: 0.10.35
- */
-gboolean
-gst_ghost_pad_internal_activate_pull_default (GstPad * pad, gboolean active)
+static gboolean
+gst_ghost_pad_internal_activate_pull_default (GstPad * pad, GstObject * parent,
+    gboolean active)
 {
   gboolean ret;
   GstPad *other;
 
-  g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
-
   GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
       GST_DEBUG_PAD_NAME (pad));
 
@@ -599,36 +307,65 @@ gst_ghost_pad_internal_activate_pull_default (GstPad * pad, gboolean active)
      * which will trigger gst_ghost_pad_activate_pull_default, which propagates even
      * further upstream */
     GST_LOG_OBJECT (pad, "pad is src, activate internal");
-    other = GST_PROXY_PAD_INTERNAL (pad);
-    ret = gst_pad_activate_pull (other, active);
+    GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
+    ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
+    GST_PROXY_PAD_RELEASE_INTERNAL (other);
   } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
     /* We are SINK, the ghostpad is SRC, we propagate the activation upstream
      * since we hold a pointer to the upstream peer. */
     GST_LOG_OBJECT (pad, "activating peer");
-    ret = gst_pad_activate_pull (other, active);
+    ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
     gst_object_unref (other);
-  } else {
+  } else if (active) {
     /* this is failure, we can't activate pull if there is no peer */
     GST_LOG_OBJECT (pad, "not src and no peer, failing");
     ret = FALSE;
+  } else {
+    GST_LOG_OBJECT (pad, "deactivating pull, with no peer - allowing");
+    ret = TRUE;
   }
 
   return ret;
 }
 
 /**
- * gst_ghost_pad_activate_push_default:
+ * gst_ghost_pad_internal_activate_mode_default:
  * @pad: the #GstPad to activate or deactivate.
+ * @parent: (allow-none): the parent of @pad or %NULL
+ * @mode: the requested activation mode
  * @active: whether the pad should be active or not.
  *
- * Invoke the default activate push function of a ghost pad.
+ * Invoke the default activate mode function of a proxy pad that is
+ * owned by a ghost pad.
  *
  * Returns: %TRUE if the operation was successful.
- *
- * Since: 0.10.35
  */
 gboolean
-gst_ghost_pad_activate_push_default (GstPad * pad, gboolean active)
+gst_ghost_pad_internal_activate_mode_default (GstPad * pad, GstObject * parent,
+    GstPadMode mode, gboolean active)
+{
+  gboolean res;
+
+  g_return_val_if_fail (GST_IS_PROXY_PAD (pad), FALSE);
+
+  switch (mode) {
+    case GST_PAD_MODE_PULL:
+      res = gst_ghost_pad_internal_activate_pull_default (pad, parent, active);
+      break;
+    case GST_PAD_MODE_PUSH:
+      res = gst_ghost_pad_internal_activate_push_default (pad, parent, active);
+      break;
+    default:
+      GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
+      res = FALSE;
+      break;
+  }
+  return res;
+}
+
+static gboolean
+gst_ghost_pad_activate_push_default (GstPad * pad, GstObject * parent,
+    gboolean active)
 {
   gboolean ret;
   GstPad *other;
@@ -639,31 +376,20 @@ gst_ghost_pad_activate_push_default (GstPad * pad, gboolean active)
       (active ? "" : "de"), GST_DEBUG_PAD_NAME (pad));
 
   /* just activate the internal pad */
-  other = GST_PROXY_PAD_INTERNAL (pad);
-  ret = gst_pad_activate_push (other, active);
+  GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
+  ret = gst_pad_activate_mode (other, GST_PAD_MODE_PUSH, active);
+  GST_PROXY_PAD_RELEASE_INTERNAL (other);
 
   return ret;
 }
 
-/**
- * gst_ghost_pad_activate_pull_default:
- * @pad: the #GstPad to activate or deactivate.
- * @active: whether the pad should be active or not.
- *
- * Invoke the default activate pull function of a ghost pad.
- *
- * Returns: %TRUE if the operation was successful.
- *
- * Since: 0.10.35
- */
-gboolean
-gst_ghost_pad_activate_pull_default (GstPad * pad, gboolean active)
+static gboolean
+gst_ghost_pad_activate_pull_default (GstPad * pad, GstObject * parent,
+    gboolean active)
 {
   gboolean ret;
   GstPad *other;
 
-  g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
-
   GST_LOG_OBJECT (pad, "%sactivate pull on %s:%s", (active ? "" : "de"),
       GST_DEBUG_PAD_NAME (pad));
 
@@ -672,71 +398,59 @@ gst_ghost_pad_activate_pull_default (GstPad * pad, gboolean active)
      * activation function of the internal pad to propagate the activation
      * upstream */
     GST_LOG_OBJECT (pad, "pad is src, activate internal");
-    other = GST_PROXY_PAD_INTERNAL (pad);
-    ret = gst_pad_activate_pull (other, active);
+    GST_PROXY_PAD_ACQUIRE_INTERNAL (pad, other, FALSE);
+    ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
+    GST_PROXY_PAD_RELEASE_INTERNAL (other);
   } else if (G_LIKELY ((other = gst_pad_get_peer (pad)))) {
     /* We are SINK and activated by the internal pad, propagate activation
      * upstream because we hold a ref to the upstream peer */
     GST_LOG_OBJECT (pad, "activating peer");
-    ret = gst_pad_activate_pull (other, active);
+    ret = gst_pad_activate_mode (other, GST_PAD_MODE_PULL, active);
     gst_object_unref (other);
-  } else {
-    /* no peer, we fail */
-    GST_LOG_OBJECT (pad, "pad not src and no peer, failing");
+  } else if (active) {
+    /* this is failure, we can't activate pull if there is no peer */
+    GST_LOG_OBJECT (pad, "not src and no peer, failing");
     ret = FALSE;
+  } else {
+    GST_LOG_OBJECT (pad, "deactivating pull, with no peer - allowing");
+    ret = TRUE;
   }
 
   return ret;
 }
 
 /**
- * gst_ghost_pad_link_default:
- * @pad: the #GstPad to link.
- * @peer: the #GstPad peer
- *
- * Invoke the default link function of a ghost pad.
+ * gst_ghost_pad_activate_mode_default:
+ * @pad: the #GstPad to activate or deactivate.
+ * @parent: (allow-none): the parent of @pad or %NULL
+ * @mode: the requested activation mode
+ * @active: whether the pad should be active or not.
  *
- * Returns: #GstPadLinkReturn of the operation
+ * Invoke the default activate mode function of a ghost pad.
  *
- * Since: 0.10.35
+ * Returns: %TRUE if the operation was successful.
  */
-GstPadLinkReturn
-gst_ghost_pad_link_default (GstPad * pad, GstPad * peer)
+gboolean
+gst_ghost_pad_activate_mode_default (GstPad * pad, GstObject * parent,
+    GstPadMode mode, gboolean active)
 {
-  GstPadLinkReturn ret;
-
-  g_return_val_if_fail (GST_IS_GHOST_PAD (pad), GST_PAD_LINK_REFUSED);
-  g_return_val_if_fail (GST_IS_PAD (peer), GST_PAD_LINK_REFUSED);
-
-  GST_DEBUG_OBJECT (pad, "linking ghostpad");
-
-  ret = GST_PAD_LINK_OK;
-  /* if we are a source pad, we should call the peer link function
-   * if the peer has one, see design docs. */
-  if (GST_PAD_IS_SRC (pad)) {
-    if (GST_PAD_LINKFUNC (peer)) {
-      ret = GST_PAD_LINKFUNC (peer) (peer, pad);
-      if (ret != GST_PAD_LINK_OK)
-        GST_DEBUG_OBJECT (pad, "linking failed");
-    }
-  }
-  return ret;
-}
+  gboolean res;
 
-/**
- * gst_ghost_pad_unlink_default:
- * @pad: the #GstPad to link.
- *
- * Invoke the default unlink function of a ghost pad.
- *
- * Since: 0.10.35
- */
-void
-gst_ghost_pad_unlink_default (GstPad * pad)
-{
-  g_return_if_fail (GST_IS_GHOST_PAD (pad));
+  g_return_val_if_fail (GST_IS_GHOST_PAD (pad), FALSE);
 
-  GST_DEBUG_OBJECT (pad, "unlinking ghostpad");
+  switch (mode) {
+    case GST_PAD_MODE_PULL:
+      res = gst_ghost_pad_activate_pull_default (pad, parent, active);
+      break;
+    case GST_PAD_MODE_PUSH:
+      res = gst_ghost_pad_activate_push_default (pad, parent, active);
+      break;
+    default:
+      GST_LOG_OBJECT (pad, "unknown activation mode %d", mode);
+      res = FALSE;
+      break;
+  }
+  return res;
 }
 
 static void
@@ -744,25 +458,19 @@ gst_ghost_pad_class_init (GstGhostPadClass * klass)
 {
   GObjectClass *gobject_class = (GObjectClass *) klass;
 
-  g_type_class_add_private (klass, sizeof (GstGhostPadPrivate));
-
   gobject_class->dispose = gst_ghost_pad_dispose;
 
   GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_pull_default);
   GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_activate_push_default);
-  GST_DEBUG_REGISTER_FUNCPTR (gst_ghost_pad_link_default);
 }
 
 static void
 gst_ghost_pad_init (GstGhostPad * pad)
 {
-  GST_GHOST_PAD_PRIVATE (pad) = G_TYPE_INSTANCE_GET_PRIVATE (pad,
-      GST_TYPE_GHOST_PAD, GstGhostPadPrivate);
+  GST_GHOST_PAD_PRIVATE (pad) = gst_ghost_pad_get_instance_private (pad);
 
-  gst_pad_set_activatepull_function (GST_PAD_CAST (pad),
-      gst_ghost_pad_activate_pull_default);
-  gst_pad_set_activatepush_function (GST_PAD_CAST (pad),
-      gst_ghost_pad_activate_push_default);
+  gst_pad_set_activatemode_function (GST_PAD_CAST (pad),
+      gst_ghost_pad_activate_mode_default);
 }
 
 static void
@@ -792,14 +500,16 @@ gst_ghost_pad_dispose (GObject * object)
 
   GST_OBJECT_LOCK (pad);
   internal = GST_PROXY_PAD_INTERNAL (pad);
+  if (internal) {
+    gst_pad_set_activatemode_function (internal, NULL);
 
-  gst_pad_set_activatepull_function (internal, NULL);
-  gst_pad_set_activatepush_function (internal, NULL);
+    GST_PROXY_PAD_INTERNAL (pad) = NULL;
+    GST_PROXY_PAD_INTERNAL (internal) = NULL;
 
-  /* disposes of the internal pad, since the ghostpad is the only possible object
-   * that has a refcount on the internal pad. */
-  gst_object_unparent (GST_OBJECT_CAST (internal));
-  GST_PROXY_PAD_INTERNAL (pad) = NULL;
+    /* disposes of the internal pad, since the ghostpad is the only possible object
+     * that has a refcount on the internal pad. */
+    gst_object_unparent (GST_OBJECT_CAST (internal));
+  }
 
   GST_OBJECT_UNLOCK (pad);
 
@@ -818,8 +528,6 @@ gst_ghost_pad_dispose (GObject * object)
  * (GST_TYPE_GHOST_PAD, "direction", @dir, ..., NULL).
  *
  * Returns: %TRUE if the construction succeeds, %FALSE otherwise.
- *
- * Since: 0.10.22
  */
 gboolean
 gst_ghost_pad_construct (GstGhostPad * gpad)
@@ -829,8 +537,7 @@ gst_ghost_pad_construct (GstGhostPad * gpad)
   GstPad *pad, *internal;
 
   g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
-  g_return_val_if_fail (GST_GHOST_PAD_PRIVATE (gpad)->constructed == FALSE,
-      FALSE);
+  g_return_val_if_fail (!GST_GHOST_PAD_PRIVATE (gpad)->constructed, FALSE);
 
   g_object_get (gpad, "direction", &dir, "template", &templ, NULL);
 
@@ -846,10 +553,6 @@ gst_ghost_pad_construct (GstGhostPad * gpad)
     gst_pad_set_getrange_function (pad, gst_proxy_pad_getrange_default);
   }
 
-  /* link/unlink functions */
-  gst_pad_set_link_function (pad, gst_ghost_pad_link_default);
-  gst_pad_set_unlink_function (pad, gst_ghost_pad_unlink_default);
-
   /* INTERNAL PAD, it always exists and is child of the ghostpad */
   otherdir = (dir == GST_PAD_SRC) ? GST_PAD_SINK : GST_PAD_SRC;
   if (templ) {
@@ -893,10 +596,8 @@ gst_ghost_pad_construct (GstGhostPad * gpad)
   GST_PROXY_PAD_INTERNAL (internal) = pad;
 
   /* special activation functions for the internal pad */
-  gst_pad_set_activatepull_function (internal,
-      gst_ghost_pad_internal_activate_pull_default);
-  gst_pad_set_activatepush_function (internal,
-      gst_ghost_pad_internal_activate_push_default);
+  gst_pad_set_activatemode_function (internal,
+      gst_ghost_pad_internal_activate_mode_default);
 
   GST_OBJECT_UNLOCK (pad);
 
@@ -911,7 +612,6 @@ parent_failed:
     g_critical ("Could not set internal pad %s:%s",
         GST_DEBUG_PAD_NAME (internal));
     GST_OBJECT_UNLOCK (pad);
-    gst_object_unref (internal);
     return FALSE;
   }
 }
@@ -921,12 +621,17 @@ gst_ghost_pad_new_full (const gchar * name, GstPadDirection dir,
     GstPadTemplate * templ)
 {
   GstGhostPad *ret;
-
   g_return_val_if_fail (dir != GST_PAD_UNKNOWN, NULL);
 
   /* OBJECT CREATION */
   if (templ) {
-    ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
+    GType pad_type =
+        GST_PAD_TEMPLATE_GTYPE (templ) ==
+        G_TYPE_NONE ? GST_TYPE_GHOST_PAD : GST_PAD_TEMPLATE_GTYPE (templ);
+
+    g_return_val_if_fail (g_type_is_a (pad_type, GST_TYPE_GHOST_PAD), NULL);
+
+    ret = g_object_new (pad_type, "name", name,
         "direction", dir, "template", templ, NULL);
   } else {
     ret = g_object_new (GST_TYPE_GHOST_PAD, "name", name,
@@ -946,7 +651,7 @@ construct_failed:
 
 /**
  * gst_ghost_pad_new_no_target:
- * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
+ * @name: (allow-none): the name of the new pad, or %NULL to assign a default name.
  * @dir: the direction of the ghostpad
  *
  * Create a new ghostpad without a target with the given direction.
@@ -955,7 +660,8 @@ construct_failed:
  *
  * The created ghostpad will not have a padtemplate.
  *
- * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
+ * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
+ * case of an error.
  */
 GstPad *
 gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
@@ -973,7 +679,7 @@ gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
 
 /**
  * gst_ghost_pad_new:
- * @name: (allow-none): the name of the new pad, or NULL to assign a default name
+ * @name: (allow-none): the name of the new pad, or %NULL to assign a default name
  * @target: (transfer none): the pad to ghost.
  *
  * Create a new ghostpad with @target as the target. The direction will be taken
@@ -981,7 +687,8 @@ gst_ghost_pad_new_no_target (const gchar * name, GstPadDirection dir)
  *
  * Will ref the target.
  *
- * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
+ * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
+ * case of an error.
  */
 GstPad *
 gst_ghost_pad_new (const gchar * name, GstPad * target)
@@ -1012,7 +719,7 @@ set_target_failed:
 
 /**
  * gst_ghost_pad_new_from_template:
- * @name: (allow-none): the name of the new pad, or NULL to assign a default name.
+ * @name: (allow-none): the name of the new pad, or %NULL to assign a default name.
  * @target: (transfer none): the pad to ghost.
  * @templ: (transfer none): the #GstPadTemplate to use on the ghostpad.
  *
@@ -1021,9 +728,8 @@ set_target_failed:
  *
  * Will ref the target.
  *
- * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
- *
- * Since: 0.10.10
+ * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
+ * case of an error.
  */
 
 GstPad *
@@ -1059,15 +765,14 @@ set_target_failed:
 
 /**
  * gst_ghost_pad_new_no_target_from_template:
- * @name: (allow-none): the name of the new pad, or NULL to assign a default name
+ * @name: (allow-none): the name of the new pad, or %NULL to assign a default name
  * @templ: (transfer none): the #GstPadTemplate to create the ghostpad from.
  *
  * Create a new ghostpad based on @templ, without setting a target. The
  * direction will be taken from the @templ.
  *
- * Returns: (transfer full): a new #GstPad, or NULL in case of an error.
- *
- * Since: 0.10.10
+ * Returns: (transfer floating) (nullable): a new #GstPad, or %NULL in
+ * case of an error.
  */
 GstPad *
 gst_ghost_pad_new_no_target_from_template (const gchar * name,
@@ -1089,8 +794,9 @@ gst_ghost_pad_new_no_target_from_template (const gchar * name,
  *
  * Get the target pad of @gpad. Unref target pad after usage.
  *
- * Returns: (transfer full): the target #GstPad, can be NULL if the ghostpad
- * has no target set. Unref target pad after usage.
+ * Returns: (transfer full) (nullable): the target #GstPad, can be
+ * %NULL if the ghostpad has no target set. Unref target pad after
+ * usage.
  */
 GstPad *
 gst_ghost_pad_get_target (GstGhostPad * gpad)
@@ -1113,10 +819,10 @@ gst_ghost_pad_get_target (GstGhostPad * gpad)
  *
  * Set the new target of the ghostpad @gpad. Any existing target
  * is unlinked and links to the new target are established. if @newtarget is
- * NULL the target will be cleared.
+ * %NULL the target will be cleared.
  *
- * Returns: (transfer full): TRUE if the new target could be set. This function
- *     can return FALSE when the internal pads could not be linked.
+ * Returns: %TRUE if the new target could be set. This function
+ *     can return %FALSE when the internal pads could not be linked.
  */
 gboolean
 gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
@@ -1127,20 +833,24 @@ gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
 
   g_return_val_if_fail (GST_IS_GHOST_PAD (gpad), FALSE);
   g_return_val_if_fail (GST_PAD_CAST (gpad) != newtarget, FALSE);
-  g_return_val_if_fail (newtarget != GST_PROXY_PAD_INTERNAL (gpad), FALSE);
 
-  /* no need for locking, the internal pad's lifecycle is directly linked to the
-   * ghostpad's */
+  GST_OBJECT_LOCK (gpad);
   internal = GST_PROXY_PAD_INTERNAL (gpad);
 
+  if (newtarget == internal) {
+    GST_OBJECT_UNLOCK (gpad);
+    GST_WARNING_OBJECT (gpad, "Target has already been set to %s:%s",
+        GST_DEBUG_PAD_NAME (newtarget));
+    return TRUE;
+  }
+
   if (newtarget)
     GST_DEBUG_OBJECT (gpad, "set target %s:%s", GST_DEBUG_PAD_NAME (newtarget));
   else
     GST_DEBUG_OBJECT (gpad, "clearing target");
 
   /* clear old target */
-  GST_OBJECT_LOCK (gpad);
-  if ((oldtarget = GST_PROXY_PAD_TARGET (gpad))) {
+  if ((oldtarget = gst_pad_get_peer (internal))) {
     GST_OBJECT_UNLOCK (gpad);
 
     /* unlink internal pad */
@@ -1148,13 +858,16 @@ gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
       gst_pad_unlink (internal, oldtarget);
     else
       gst_pad_unlink (oldtarget, internal);
+
+    gst_object_unref (oldtarget);
   } else {
     GST_OBJECT_UNLOCK (gpad);
   }
 
   if (newtarget) {
     /* and link to internal pad without any checks */
-    GST_DEBUG_OBJECT (gpad, "connecting internal pad to target");
+    GST_DEBUG_OBJECT (gpad, "connecting internal pad to target %"
+        GST_PTR_FORMAT, newtarget);
 
     if (GST_PAD_IS_SRC (internal))
       lret =
@@ -1172,8 +885,8 @@ gst_ghost_pad_set_target (GstGhostPad * gpad, GstPad * newtarget)
   /* ERRORS */
 link_failed:
   {
-    GST_WARNING_OBJECT (gpad, "could not link internal and target, reason:%d",
-        lret);
+    GST_WARNING_OBJECT (gpad, "could not link internal and target, reason:%s",
+        gst_pad_link_get_name (lret));
     return FALSE;
   }
 }