From 778c24a58ae956710c6116651f9db63e2f5deaed Mon Sep 17 00:00:00 2001 From: David Schleef Date: Tue, 23 Dec 2003 23:19:07 +0000 Subject: [PATCH] gst/elements/: Use gst_pad_proxy_getcaps(). Original commit message from CVS: * gst/elements/gstaggregator.c: * gst/elements/gsttee.c: Use gst_pad_proxy_getcaps(). * gst/gstpad.c: * gst/gstpad.h: Add gst_pad_proxy_getcaps(), which filter elements can use as a generic getcaps implementation. Fix gst_pad_get_allowed_caps(). It just wasn't doing what was advertised. --- ChangeLog | 12 +++++++ gst/elements/gstaggregator.c | 2 ++ gst/elements/gsttee.c | 39 ++------------------ gst/gstpad.c | 61 +++++++++++++++++++++++++++----- gst/gstpad.h | 1 + plugins/elements/gstaggregator.c | 2 ++ plugins/elements/gsttee.c | 39 ++------------------ 7 files changed, 73 insertions(+), 83 deletions(-) diff --git a/ChangeLog b/ChangeLog index 49da93dd39..7c0db2fa32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2003-12-23 David Schleef + + * gst/elements/gstaggregator.c: + * gst/elements/gsttee.c: + Use gst_pad_proxy_getcaps(). + * gst/gstpad.c: + * gst/gstpad.h: + Add gst_pad_proxy_getcaps(), which filter elements can use + as a generic getcaps implementation. + Fix gst_pad_get_allowed_caps(). It just wasn't doing what + was advertised. + 2003-12-23 David Schleef * gst/gstpad.c: diff --git a/gst/elements/gstaggregator.c b/gst/elements/gstaggregator.c index a6b69a0b5b..8d3523c63c 100644 --- a/gst/elements/gstaggregator.c +++ b/gst/elements/gstaggregator.c @@ -162,6 +162,7 @@ static void gst_aggregator_init (GstAggregator *aggregator) { aggregator->srcpad = gst_pad_new ("src", GST_PAD_SRC); + gst_pad_set_getcaps_function (aggregator->srcpad, gst_pad_proxy_getcaps); gst_element_add_pad (GST_ELEMENT (aggregator), aggregator->srcpad); aggregator->numsinkpads = 0; @@ -196,6 +197,7 @@ gst_aggregator_request_new_pad (GstElement *element, GstPadTemplate *templ, cons if (!AGGREGATOR_IS_LOOP_BASED (aggregator)) { gst_pad_set_chain_function (sinkpad, gst_aggregator_chain); } + gst_pad_set_getcaps_function (sinkpad, gst_pad_proxy_getcaps); gst_element_add_pad (GST_ELEMENT (aggregator), sinkpad); aggregator->sinkpads = g_list_prepend (aggregator->sinkpads, sinkpad); diff --git a/gst/elements/gsttee.c b/gst/elements/gsttee.c index 89acedc9b7..ef16afb0f3 100644 --- a/gst/elements/gsttee.c +++ b/gst/elements/gsttee.c @@ -181,41 +181,6 @@ gst_tee_srclink (GstPad *pad, const GstCaps *caps) return gst_pad_proxy_link (tee->sinkpad, caps); } -static GstCaps* -gst_tee_getcaps (GstPad *pad) -{ - GstCaps *caps = GST_CAPS_ANY; - GstTee *tee; - const GList *pads; - - GST_DEBUG ( "gst_tee_getcaps"); - - tee = GST_TEE (gst_pad_get_parent (pad)); - - pads = gst_element_get_pad_list (GST_ELEMENT (tee)); - - while (pads) { - GstPad *srcpad = GST_PAD (pads->data); - GstPad *peer; - const GstCaps *peercaps; - GstCaps *newcaps; - - pads = g_list_next (pads); - - peer = gst_pad_get_peer(srcpad); - if(!peer){ - continue; - } - - peercaps = gst_pad_get_caps (peer); - newcaps = gst_caps_intersect (caps, peercaps); - gst_caps_free (caps); - caps = newcaps; - } - - return caps; -} - static void gst_tee_init (GstTee *tee) { @@ -223,7 +188,7 @@ gst_tee_init (GstTee *tee) gst_element_add_pad (GST_ELEMENT (tee), tee->sinkpad); gst_pad_set_chain_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_chain)); gst_pad_set_link_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_sinklink)); - gst_pad_set_getcaps_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_getcaps)); + gst_pad_set_getcaps_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps)); tee->silent = FALSE; tee->last_message = NULL; @@ -282,7 +247,7 @@ gst_tee_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar srcpad = gst_pad_new_from_template (templ, name); g_free (name); gst_pad_set_link_function (srcpad, GST_DEBUG_FUNCPTR (gst_tee_srclink)); - gst_pad_set_getcaps_function (srcpad, GST_DEBUG_FUNCPTR (gst_tee_getcaps)); + gst_pad_set_getcaps_function (srcpad, GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps)); gst_element_add_pad (GST_ELEMENT (tee), srcpad); GST_PAD_ELEMENT_PRIVATE (srcpad) = NULL; diff --git a/gst/gstpad.c b/gst/gstpad.c index e9dd4fa7de..61d294c32f 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -1739,6 +1739,47 @@ gst_pad_relink_filtered (GstPad *srcpad, GstPad *sinkpad, return FALSE; } +/** + * gst_pad_proxy_getcaps: + * @pad: a #GstPad to proxy. + * + * Calls gst_pad_get_allowed_caps() for every other pad belonging to the + * same element as @pad, and returns the intersection of the results. + * + * This function is useful as a default getcaps function for an element + * that can handle any stream format, but requires all its pads to have + * the same caps. Two such elements are tee and aggregator. + * + * Returns: the intersection of the other pads' allowed caps. + */ +GstCaps * +gst_pad_proxy_getcaps (GstPad *pad) +{ + GstElement *element; + const GList *pads; + GstCaps *caps; + + element = gst_pad_get_parent (pad); + + pads = gst_element_get_pad_list (element); + + caps = gst_caps_new_any (); + while (pads) { + GstPad *otherpad = GST_PAD (pads->data); + GstCaps *temp; + + if (otherpad != pad) { + temp = gst_caps_intersect (caps, gst_pad_get_allowed_caps (pad)); + gst_caps_free (caps); + caps = temp; + } + + pads = g_list_next (pads); + } + + return caps; +} + /** * gst_pad_proxy_link: * @pad: a #GstPad to proxy to. @@ -1928,10 +1969,11 @@ GstCaps* gst_pad_get_allowed_caps (GstPad *pad) { GstRealPad *realpad; - GstCaps *mycaps; + const GstCaps *mycaps; GstCaps *caps; - GstCaps *filtercaps; GstCaps *peercaps; + GstCaps *icaps; + GstPadLink *link; g_return_val_if_fail (pad != NULL, NULL); g_return_val_if_fail (GST_IS_PAD (pad), NULL); @@ -1941,21 +1983,22 @@ gst_pad_get_allowed_caps (GstPad *pad) GST_CAT_DEBUG (GST_CAT_PROPERTIES, "get allowed caps of %s:%s", GST_DEBUG_PAD_NAME (pad)); - mycaps = gst_pad_get_caps (pad); + mycaps = gst_pad_get_pad_template_caps (pad); if (GST_RPAD_PEER (realpad) == NULL) { - return mycaps; + return gst_caps_copy (mycaps); } peercaps = gst_pad_get_caps (GST_PAD_PEER (realpad)); caps = gst_caps_intersect (mycaps, peercaps); - gst_caps_free (mycaps); gst_caps_free (peercaps); - filtercaps = GST_RPAD_APPFILTER (realpad); - if (filtercaps) { - return gst_caps_intersect (caps, filtercaps); + link = GST_RPAD_LINK (realpad); + if (link->filtercaps) { + icaps = gst_caps_intersect (caps, link->filtercaps); + gst_caps_free (caps); + return icaps; } else { - return gst_caps_copy (caps); + return caps; } } diff --git a/gst/gstpad.h b/gst/gstpad.h index 3dd9405f66..741ea77116 100644 --- a/gst/gstpad.h +++ b/gst/gstpad.h @@ -408,6 +408,7 @@ 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_link (GstPad *pad, const GstCaps *caps); gboolean gst_pad_relink_filtered (GstPad *srcpad, GstPad *sinkpad, const GstCaps *filtercaps); gboolean gst_pad_perform_negotiate (GstPad *srcpad, GstPad *sinkpad); diff --git a/plugins/elements/gstaggregator.c b/plugins/elements/gstaggregator.c index a6b69a0b5b..8d3523c63c 100644 --- a/plugins/elements/gstaggregator.c +++ b/plugins/elements/gstaggregator.c @@ -162,6 +162,7 @@ static void gst_aggregator_init (GstAggregator *aggregator) { aggregator->srcpad = gst_pad_new ("src", GST_PAD_SRC); + gst_pad_set_getcaps_function (aggregator->srcpad, gst_pad_proxy_getcaps); gst_element_add_pad (GST_ELEMENT (aggregator), aggregator->srcpad); aggregator->numsinkpads = 0; @@ -196,6 +197,7 @@ gst_aggregator_request_new_pad (GstElement *element, GstPadTemplate *templ, cons if (!AGGREGATOR_IS_LOOP_BASED (aggregator)) { gst_pad_set_chain_function (sinkpad, gst_aggregator_chain); } + gst_pad_set_getcaps_function (sinkpad, gst_pad_proxy_getcaps); gst_element_add_pad (GST_ELEMENT (aggregator), sinkpad); aggregator->sinkpads = g_list_prepend (aggregator->sinkpads, sinkpad); diff --git a/plugins/elements/gsttee.c b/plugins/elements/gsttee.c index 89acedc9b7..ef16afb0f3 100644 --- a/plugins/elements/gsttee.c +++ b/plugins/elements/gsttee.c @@ -181,41 +181,6 @@ gst_tee_srclink (GstPad *pad, const GstCaps *caps) return gst_pad_proxy_link (tee->sinkpad, caps); } -static GstCaps* -gst_tee_getcaps (GstPad *pad) -{ - GstCaps *caps = GST_CAPS_ANY; - GstTee *tee; - const GList *pads; - - GST_DEBUG ( "gst_tee_getcaps"); - - tee = GST_TEE (gst_pad_get_parent (pad)); - - pads = gst_element_get_pad_list (GST_ELEMENT (tee)); - - while (pads) { - GstPad *srcpad = GST_PAD (pads->data); - GstPad *peer; - const GstCaps *peercaps; - GstCaps *newcaps; - - pads = g_list_next (pads); - - peer = gst_pad_get_peer(srcpad); - if(!peer){ - continue; - } - - peercaps = gst_pad_get_caps (peer); - newcaps = gst_caps_intersect (caps, peercaps); - gst_caps_free (caps); - caps = newcaps; - } - - return caps; -} - static void gst_tee_init (GstTee *tee) { @@ -223,7 +188,7 @@ gst_tee_init (GstTee *tee) gst_element_add_pad (GST_ELEMENT (tee), tee->sinkpad); gst_pad_set_chain_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_chain)); gst_pad_set_link_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_sinklink)); - gst_pad_set_getcaps_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_getcaps)); + gst_pad_set_getcaps_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps)); tee->silent = FALSE; tee->last_message = NULL; @@ -282,7 +247,7 @@ gst_tee_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar srcpad = gst_pad_new_from_template (templ, name); g_free (name); gst_pad_set_link_function (srcpad, GST_DEBUG_FUNCPTR (gst_tee_srclink)); - gst_pad_set_getcaps_function (srcpad, GST_DEBUG_FUNCPTR (gst_tee_getcaps)); + gst_pad_set_getcaps_function (srcpad, GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps)); gst_element_add_pad (GST_ELEMENT (tee), srcpad); GST_PAD_ELEMENT_PRIVATE (srcpad) = NULL;