ghostpad: API: Expose gst_proxy_pad_get_internal()
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 6 May 2011 13:16:09 +0000 (15:16 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Sat, 14 May 2011 09:39:34 +0000 (11:39 +0200)
This allows to get the internal pad of ghostpads and
proxypads without using gst_pad_iterate_internal_links()
and is much more convenient.

The internal pad of a ghostpad is the pad of the opposite direction
that is used to link to the ghostpad target.

docs/gst/gstreamer-sections.txt
gst/gstghostpad.c
gst/gstghostpad.h
tests/check/gst/gstghostpad.c
win32/common/libgstreamer.def

index e1eba92..6b4bcb4 100644 (file)
@@ -902,14 +902,20 @@ gst_format_get_type
 <SECTION>
 <FILE>gstghostpad</FILE>
 <TITLE>GstGhostPad</TITLE>
+GstProxyPad
 GstGhostPad
+
 gst_ghost_pad_new
 gst_ghost_pad_new_no_target
 gst_ghost_pad_new_from_template
 gst_ghost_pad_new_no_target_from_template
+
 gst_ghost_pad_set_target
 gst_ghost_pad_get_target
+
 gst_ghost_pad_construct
+
+gst_proxy_pad_get_internal
 <SUBSECTION Standard>
 GstGhostPadClass
 GST_GHOST_PAD
index 313759d..0a62052 100644 (file)
@@ -73,7 +73,6 @@ struct _GstProxyPadPrivate
 G_DEFINE_TYPE (GstProxyPad, gst_proxy_pad, GST_TYPE_PAD);
 
 static GstPad *gst_proxy_pad_get_target (GstPad * pad);
-static GstPad *gst_proxy_pad_get_internal (GstPad * pad);
 
 static void gst_proxy_pad_dispose (GObject * object);
 static void gst_proxy_pad_finalize (GObject * object);
@@ -108,7 +107,8 @@ static gboolean
 gst_proxy_pad_do_event (GstPad * pad, GstEvent * event)
 {
   gboolean res = FALSE;
-  GstPad *internal = gst_proxy_pad_get_internal (pad);
+  GstPad *internal =
+      GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD_CAST (pad)));
 
   if (internal) {
     res = gst_pad_push_event (internal, event);
@@ -152,7 +152,8 @@ gst_proxy_pad_do_bufferalloc (GstPad * pad, guint64 offset, guint size,
     GstCaps * caps, GstBuffer ** buf)
 {
   GstFlowReturn result = GST_FLOW_WRONG_STATE;
-  GstPad *internal = gst_proxy_pad_get_internal (pad);
+  GstPad *internal =
+      GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD_CAST (pad)));
 
   if (internal) {
     result = gst_pad_alloc_buffer (internal, offset, size, caps, buf);
@@ -364,18 +365,32 @@ gst_proxy_pad_get_target (GstPad * pad)
   return target;
 }
 
-static GstPad *
-gst_proxy_pad_get_internal (GstPad * pad)
+/**
+ * gst_proxy_pad_get_internal:
+ * @pad: the #GstProxyPad
+ *
+ * Get the internal pad of @pad. Unref target pad after usage.
+ *
+ * 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.
+ */
+GstProxyPad *
+gst_proxy_pad_get_internal (GstProxyPad * pad)
 {
   GstPad *internal;
 
+  g_return_val_if_fail (GST_IS_PROXY_PAD (pad), NULL);
+
   GST_PROXY_LOCK (pad);
   internal = GST_PROXY_PAD_INTERNAL (pad);
   if (internal)
     gst_object_ref (internal);
   GST_PROXY_UNLOCK (pad);
 
-  return internal;
+  return GST_PROXY_PAD_CAST (internal);
 }
 
 static void
index f492a74..b9ef0dc 100644 (file)
@@ -59,6 +59,8 @@ struct _GstProxyPadClass
 
 GType gst_proxy_pad_get_type (void);
 
+GstProxyPad*     gst_proxy_pad_get_internal     (GstProxyPad *pad);
+
 
 #define GST_TYPE_GHOST_PAD             (gst_ghost_pad_get_type ())
 #define GST_IS_GHOST_PAD(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_GHOST_PAD))
index b78538a..332f654 100644 (file)
@@ -255,7 +255,7 @@ GST_END_TEST;
 GST_START_TEST (test_link)
 {
   GstElement *b1, *b2, *src, *sink;
-  GstPad *srcpad, *sinkpad, *gpad;
+  GstPad *srcpad, *sinkpad, *gpad, *ppad, *tmp;
   GstPadLinkReturn ret;
 
   b1 = gst_element_factory_make ("pipeline", NULL);
@@ -278,6 +278,14 @@ GST_START_TEST (test_link)
 
   /* now setup a ghostpad */
   gpad = gst_ghost_pad_new ("sink", sinkpad);
+
+  /* Check if the internal pads are set correctly */
+  ppad = GST_PAD (gst_proxy_pad_get_internal (GST_PROXY_PAD (gpad)));
+  fail_unless (ppad == GST_PAD_PEER (sinkpad));
+  tmp = GST_PAD (gst_proxy_pad_get_internal (GST_PROXY_PAD (ppad)));
+  fail_unless (tmp == gpad);
+  gst_object_unref (tmp);
+  gst_object_unref (ppad);
   gst_object_unref (sinkpad);
   /* need to ref as _add_pad takes ownership */
   gst_object_ref (gpad);
index ca4154d..e0e98e9 100644 (file)
@@ -832,6 +832,7 @@ EXPORTS
        gst_print_element_args
        gst_print_pad_caps
        gst_progress_type_get_type
+       gst_proxy_pad_get_internal
        gst_proxy_pad_get_type
        gst_qos_type_get_type
        gst_query_add_buffering_range