From 8f8aaf83f484bdd0420183f03fb303c1b1acf0df Mon Sep 17 00:00:00 2001 From: David Schleef Date: Wed, 31 Dec 2003 08:06:49 +0000 Subject: [PATCH] Add functions useful default pad_link and fixate functions. Original commit message from CVS: Add functions useful default pad_link and fixate functions. --- ChangeLog | 6 ++++ gst/gstpad.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ gst/gstpad.h | 4 +++ 3 files changed, 95 insertions(+) diff --git a/ChangeLog b/ChangeLog index 556cac75f6..90fe9c8cc3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-12-31 David Schleef + + * gst/gstpad.c: (gst_pad_proxy_pad_link), (gst_pad_proxy_fixate): + * gst/gstpad.h: Add functions that are useful as default pad + link and fixate functions for elements. + 2003-12-30 David Schleef * gst/gstpad.c: (gst_pad_link_try): diff --git a/gst/gstpad.c b/gst/gstpad.c index 2dedd5d17b..eb2c57c9e2 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -2013,6 +2013,91 @@ gst_pad_proxy_getcaps (GstPad *pad) return caps; } +/** + * gst_pad_proxy_pad_link: + * @pad: a #GstPad to proxy. + * + * Calls gst_pad_try_set_caps() for every other pad belonging to the + * same element as @pad. If gst_pad_try_set_caps() fails on any pad, + * the proxy link fails. + * + * Returns: GST_PAD_LINK_OK if sucessful + */ +GstPadLinkReturn +gst_pad_proxy_pad_link (GstPad *pad, const GstCaps *caps) +{ + GstElement *element; + const GList *pads; + GstPadLinkReturn ret; + + GST_DEBUG ("proxying pad link for %s:%s\n", GST_DEBUG_PAD_NAME (pad)); + + element = gst_pad_get_parent (pad); + + pads = gst_element_get_pad_list (element); + + while (pads) { + GstPad *otherpad = GST_PAD (pads->data); + + if (otherpad != pad) { + ret = gst_pad_try_set_caps (otherpad, caps); + if (GST_PAD_LINK_FAILED (ret)) { + return ret; + } + } + pads = g_list_next (pads); + } + + return GST_PAD_LINK_OK; +} + +/** + * gst_pad_proxy_fixate: + * @pad: a #GstPad to proxy. + * + * Implements a default fixate function based on the caps set on the other + * pads in the element. This function should only be used if every pad + * has the same pad template caps. + * + * Returns: a fixated caps, or NULL if caps cannot be fixed + */ +GstCaps * +gst_pad_proxy_fixate (GstPad *pad, const GstCaps *caps, gpointer unused) +{ + GstElement *element; + const GList *pads; + const GstCaps *othercaps; + + GST_DEBUG ("proxying fixate for %s:%s\n", GST_DEBUG_PAD_NAME (pad)); + + element = gst_pad_get_parent (pad); + + pads = gst_element_get_pad_list (element); + + while (pads) { + GstPad *otherpad = GST_PAD (pads->data); + + /* FIXME check that each pad has the same pad template caps */ + + if (otherpad != pad) { + othercaps = gst_pad_get_negotiated_caps (otherpad); + + if (othercaps) { + GstCaps *icaps; + icaps = gst_caps_intersect (othercaps, caps); + if (!gst_caps_is_empty (icaps)) { + return icaps; + } else { + gst_caps_free (icaps); + } + } + } + pads = g_list_next (pads); + } + + return NULL; +} + /** * gst_pad_proxy_link: * @pad: a #GstPad to proxy to. diff --git a/gst/gstpad.h b/gst/gstpad.h index be89fe8b30..cf136be567 100644 --- a/gst/gstpad.h +++ b/gst/gstpad.h @@ -411,7 +411,11 @@ gboolean gst_pad_check_compatibility (GstPad *srcpad, GstPad *sinkpad); void gst_pad_set_getcaps_function (GstPad *pad, GstPadGetCapsFunction getcaps); void gst_pad_set_fixate_function (GstPad *pad, GstPadFixateFunction fixate); GstCaps * gst_pad_proxy_getcaps (GstPad *pad); +GstPadLinkReturn gst_pad_proxy_pad_link (GstPad *pad, const GstCaps *caps); +GstCaps * gst_pad_proxy_fixate (GstPad *pad, const GstCaps *caps, gpointer unused); +#ifndef GST_DISABLE_DEPRECATED GstPadLinkReturn gst_pad_proxy_link (GstPad *pad, const GstCaps *caps); +#endif gboolean gst_pad_relink_filtered (GstPad *srcpad, GstPad *sinkpad, const GstCaps *filtercaps); #ifndef GST_DISABLE_DEPRECATED gboolean gst_pad_perform_negotiate (GstPad *srcpad, GstPad *sinkpad);