gst/gstcaps.*: Add simplify function
authorDavid Schleef <ds@schleef.org>
Tue, 30 Dec 2003 04:59:48 +0000 (04:59 +0000)
committerDavid Schleef <ds@schleef.org>
Tue, 30 Dec 2003 04:59:48 +0000 (04:59 +0000)
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
gst/gstcaps.c
gst/gstcaps.h
gst/gstpad.c
gst/gstpad.h
gst/gststructure.c

index 73aa944..0798135 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2003-12-29  David Schleef  <ds@schleef.org>
+
+       * 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  <in7y118@public.uni-hamburg.de>
 
        * gst/gstcaps.c: (gst_caps_append):
index c61ded6..f79edf0 100644 (file)
@@ -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;i<gst_caps_get_size (caps);i++){
+    structure = gst_caps_get_structure (caps, i);
+
+    for(j=0;j<gst_caps_get_size (newcaps);j++){
+      struct2 = gst_caps_get_structure (caps, i);
+      if (gst_caps_structure_simplify (struct2, structure)) {
+        break;
+      }
+    }
+    if (j==gst_caps_get_size (newcaps)) {
+      gst_caps_append_structure (newcaps, gst_structure_copy(structure));
+    }
+  }
+
+  return newcaps;
+}
+
 #ifndef GST_DISABLE_LOADSAVE
 xmlNodePtr gst_caps_save_thyself (const GstCaps *caps, xmlNodePtr parent)
 {
index 8cabeb6..a7c14fe 100644 (file)
@@ -101,6 +101,7 @@ gboolean gst_caps_is_always_compatible (const GstCaps *caps1,
 GstCaps *gst_caps_intersect (const GstCaps *caps1, const GstCaps *caps2);
 GstCaps *gst_caps_union (const GstCaps *caps1, const GstCaps *caps2);
 GstCaps *gst_caps_normalize (const GstCaps *caps);
+GstCaps *gst_caps_simplify (const GstCaps *caps);
 
 #ifndef GST_DISABLE_LOADSAVE
 xmlNodePtr gst_caps_save_thyself (const GstCaps *caps, xmlNodePtr parent);
index d197d80..caa68bd 100644 (file)
@@ -1205,6 +1205,8 @@ gst_pad_link_try (GstPadLink *link)
   
   ret = gst_pad_link_negotiate (link); 
   if (ret == GST_PAD_LINK_REFUSED) {
+    oldlink->srcnotify = 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
@@ -2021,6 +2026,25 @@ gst_pad_proxy_link (GstPad *pad, const GstCaps *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
  *
index 935ba42..be89fe8 100644 (file)
@@ -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);
index 30cf778..cad19f0 100644 (file)
@@ -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;i<structure->fields->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;
 }
 
 /**