From a216426bb60fcbda83fc28a8e2073964c51bfd8e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 6 May 2011 15:16:09 +0200 Subject: [PATCH] ghostpad: API: Expose gst_proxy_pad_get_internal() 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 | 6 ++++++ gst/gstghostpad.c | 27 +++++++++++++++++++++------ gst/gstghostpad.h | 2 ++ tests/check/gst/gstghostpad.c | 10 +++++++++- win32/common/libgstreamer.def | 1 + 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt index e1eba92..6b4bcb4 100644 --- a/docs/gst/gstreamer-sections.txt +++ b/docs/gst/gstreamer-sections.txt @@ -902,14 +902,20 @@ gst_format_get_type
gstghostpad GstGhostPad +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 GstGhostPadClass GST_GHOST_PAD diff --git a/gst/gstghostpad.c b/gst/gstghostpad.c index 313759d..0a62052 100644 --- a/gst/gstghostpad.c +++ b/gst/gstghostpad.c @@ -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 diff --git a/gst/gstghostpad.h b/gst/gstghostpad.h index f492a74..b9ef0dc 100644 --- a/gst/gstghostpad.h +++ b/gst/gstghostpad.h @@ -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)) diff --git a/tests/check/gst/gstghostpad.c b/tests/check/gst/gstghostpad.c index b78538a..332f654 100644 --- a/tests/check/gst/gstghostpad.c +++ b/tests/check/gst/gstghostpad.c @@ -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); diff --git a/win32/common/libgstreamer.def b/win32/common/libgstreamer.def index ca4154d..e0e98e9 100644 --- a/win32/common/libgstreamer.def +++ b/win32/common/libgstreamer.def @@ -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 -- 2.7.4