From cd1d72deb2dd21d06148318ad7a1f70a3df4f949 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Tue, 30 Dec 2003 04:59:48 +0000 Subject: [PATCH] gst/gstcaps.*: Add simplify function Original commit message from CVS: * gst/gstcaps.c: (gst_caps_normalize), (simplify_foreach), (gst_caps_structure_simplify), (gst_caps_simplify): * gst/gstcaps.h: Add simplify function * gst/gstpad.c: (gst_pad_link_try), (gst_pad_try_set_caps), (gst_pad_perform_negotiate), (gst_pad_is_negotiated): * gst/gstpad.h: Copy over srcnotify, sinknotify when calling old pad_link functions. Add new is_negotiated() function. * gst/gststructure.c: (gst_structure_copy): Fix an incredibly stupid bug that should have been noticed weeks ago. _copy() returned the argument, not the new copy. --- ChangeLog | 15 +++++++++++++ gst/gstcaps.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++ gst/gstcaps.h | 1 + gst/gstpad.c | 28 +++++++++++++++++++++-- gst/gstpad.h | 1 + gst/gststructure.c | 4 +--- 6 files changed, 100 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 73aa944cfb..0798135fb3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2003-12-29 David Schleef + + * gst/gstcaps.c: (gst_caps_normalize), (simplify_foreach), + (gst_caps_structure_simplify), (gst_caps_simplify): + * gst/gstcaps.h: + Add simplify function + * gst/gstpad.c: (gst_pad_link_try), (gst_pad_try_set_caps), + (gst_pad_perform_negotiate), (gst_pad_is_negotiated): + * gst/gstpad.h: + Copy over srcnotify, sinknotify when calling old pad_link + functions. Add new is_negotiated() function. + * gst/gststructure.c: (gst_structure_copy): + Fix an incredibly stupid bug that should have been noticed + weeks ago. _copy() returned the argument, not the new copy. + 2003-12-27 Benjamin Otte * gst/gstcaps.c: (gst_caps_append): diff --git a/gst/gstcaps.c b/gst/gstcaps.c index c61ded6d58..f79edf0bff 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -568,10 +568,66 @@ GstCaps *gst_caps_union (const GstCaps *caps1, const GstCaps *caps2) GstCaps *gst_caps_normalize (const GstCaps *caps) { + g_critical ("unimplemented"); return NULL; } +static gboolean +simplify_foreach (GQuark field_id, GValue *value, gpointer user_data) +{ + GstStructure *s2 = (GstStructure *) user_data; + const GValue *v2; + + v2 = gst_structure_id_get_value (s2, field_id); + if (v2 == NULL) return FALSE; + + if (gst_value_compare (value, v2) == GST_VALUE_EQUAL) return TRUE; + return FALSE; +} + +static gboolean +gst_caps_structure_simplify (GstStructure *struct1, const GstStructure *struct2) +{ + /* FIXME this is just a simple compare. Better would be to merge + * the two structures */ + if (struct1->name != struct2->name) return FALSE; + if (struct1->fields->len != struct2->fields->len) return FALSE; + + return gst_structure_foreach (struct1, simplify_foreach, (void *)struct2); +} + +GstCaps *gst_caps_simplify (const GstCaps *caps) +{ + int i; + int j; + GstCaps *newcaps; + GstStructure *structure; + GstStructure *struct2; + + if (gst_caps_get_size (caps) < 2) { + return gst_caps_copy (caps); + } + + newcaps = gst_caps_new_empty (); + + for(i=0;isrcnotify = link->srcnotify; + oldlink->sinknotify = link->sinknotify; if (oldlink && oldlink->caps && !gst_pad_link_call_link_functions (oldlink)) g_warning ("pads don't accept old caps. We assume they did though"); gst_pad_link_free (link); @@ -1257,6 +1259,7 @@ GstPadLinkReturn gst_pad_try_set_caps (GstPad *pad, const GstCaps *caps) { GstPadLink *link; + GstPadLinkReturn ret; g_return_val_if_fail (pad != NULL, GST_PAD_LINK_REFUSED); g_return_val_if_fail (GST_IS_PAD (pad), GST_PAD_LINK_REFUSED); @@ -1306,7 +1309,9 @@ gst_pad_try_set_caps (GstPad *pad, const GstCaps *caps) link->sinknotify = FALSE; } - return gst_pad_link_try (link); + ret = gst_pad_link_try (link); + + return ret; } @@ -1829,7 +1834,7 @@ _gst_pad_default_fixate_func (GstPad *pad, GstCaps *caps, gpointer unused) gboolean gst_pad_perform_negotiate (GstPad *srcpad, GstPad *sinkpad) { - return gst_pad_renegotiate (srcpad) >= 0; + return GST_PAD_LINK_SUCCESSFUL (gst_pad_renegotiate (srcpad)); } void @@ -2020,6 +2025,25 @@ gst_pad_proxy_link (GstPad *pad, const GstCaps *caps) return gst_pad_try_set_caps (pad, caps); } +/** + * gst_pad_is_negotiated: + * @pad: a #GstPad to get the negotiation status of + * + * Returns: TRUE if the pad has successfully negotiated caps. + */ +gboolean +gst_pad_is_negotiated (GstPad *pad) +{ + g_return_val_if_fail (GST_IS_PAD (pad), FALSE); + + if (!GST_PAD_REALIZE (pad)) + return FALSE; + if (!GST_RPAD_LINK (pad)) + return FALSE; + + return (GST_RPAD_LINK (pad)->caps != NULL); +} + /** * gst_pad_get_negotiated_caps: * @pad: a #GstPad to get the negotiated capabilites of diff --git a/gst/gstpad.h b/gst/gstpad.h index 935ba42aa7..be89fe8b30 100644 --- a/gst/gstpad.h +++ b/gst/gstpad.h @@ -402,6 +402,7 @@ GstPad* gst_pad_get_peer (GstPad *pad); /* capsnego functions */ G_CONST_RETURN GstCaps* gst_pad_get_negotiated_caps (GstPad *pad); +gboolean gst_pad_is_negotiated (GstPad *pad); GstCaps* gst_pad_get_caps (GstPad *pad); G_CONST_RETURN GstCaps* gst_pad_get_pad_template_caps (GstPad *pad); GstPadLinkReturn gst_pad_try_set_caps (GstPad *pad, const GstCaps *caps); diff --git a/gst/gststructure.c b/gst/gststructure.c index 30cf7780a5..cad19f0487 100644 --- a/gst/gststructure.c +++ b/gst/gststructure.c @@ -211,8 +211,6 @@ GstStructure *gst_structure_copy(GstStructure *structure) g_return_val_if_fail(structure != NULL, NULL); new_structure = gst_structure_empty_new(g_quark_to_string(structure->name)); - new_structure->fields = g_array_set_size(new_structure->fields, - structure->fields->len); new_structure->name = structure->name; for(i=0;ifields->len;i++){ @@ -225,7 +223,7 @@ GstStructure *gst_structure_copy(GstStructure *structure) g_array_append_val(new_structure->fields, new_field); } - return structure; + return new_structure; } /**