Merge remote-tracking branch 'origin/0.10'
[platform/upstream/gstreamer.git] / gst / gstcaps.c
index 2d9c6ae..57f8ae6 100644 (file)
@@ -20,9 +20,9 @@
 /**
  * SECTION:gstcaps
  * @short_description: Structure describing sets of media formats
- * @see_also: #GstStructure
+ * @see_also: #GstStructure, #GstMiniObject
  *
- * Caps (capabilities) are lighweight refcounted objects describing media types.
+ * Caps (capabilities) are lightweight refcounted objects describing media types.
  * They are composed of an array of #GstStructure.
  *
  * Caps are exposed on #GstPadTemplate to describe all possible types a
  * function. This function describes the possible types that the pad can
  * handle or produce at runtime.
  *
- * Caps are also attached to buffers to describe to content of the data
- * pointed to by the buffer with gst_buffer_set_caps(). Caps attached to
- * a #GstBuffer allow for format negotiation upstream and downstream.
- *
  * A #GstCaps can be constructed with the following code fragment:
  *
  * <example>
  * </example>
  *
  * A #GstCaps is fixed when it has no properties with ranges or lists. Use
- * gst_caps_is_fixed() to test for fixed caps. Only fixed caps can be
- * set on a #GstPad or #GstBuffer.
+ * gst_caps_is_fixed() to test for fixed caps. Fixed caps can be used in a
+ * caps event to notify downstream elements of the current media type.
  *
  * Various methods exist to work with the media types such as subtracting
  * or intersecting.
  *
- * Last reviewed on 2007-02-13 (0.10.10)
+ * Last reviewed on 2011-03-28 (0.11.3)
  */
 
 #ifdef HAVE_CONFIG_H
@@ -197,7 +193,7 @@ gst_caps_init (GstCaps * caps, gsize size)
 
   /* the 32 has been determined by logging caps sizes in _gst_caps_free
    * but g_ptr_array uses 16 anyway if it expands once, so this does not help
-   * in practise
+   * in practice
    * GST_CAPS_ARRAY (caps) = g_ptr_array_sized_new (32);
    */
   GST_CAPS_ARRAY (caps) = g_ptr_array_new ();
@@ -447,7 +443,7 @@ gst_caps_remove_and_get_structure (GstCaps * caps, guint idx)
  * @caps: the #GstCaps to retrieve from
  * @index: Index of the structure to retrieve
  *
- * Retrieves the stucture with the given index from the list of structures
+ * Retrieves the structure with the given index from the list of structures
  * contained in @caps. The caller becomes the owner of the returned structure.
  *
  * Returns: (transfer full): a pointer to the #GstStructure corresponding
@@ -1137,7 +1133,7 @@ gst_caps_can_intersect (const GstCaps * caps1, const GstCaps * caps2)
    * much better than a simple loop.
    *
    * This algorithm zigzags over the caps structures as demonstrated in
-   * the folowing matrix:
+   * the following matrix:
    *
    *          caps1                              0  1  2  3
    *       +-------------     total distance:  +-------------
@@ -1209,7 +1205,7 @@ gst_caps_intersect_zig_zag (GstCaps * caps1, GstCaps * caps2)
    * much better than a simple loop.
    *
    * This algorithm zigzags over the caps structures as demonstrated in
-   * the folowing matrix:
+   * the following matrix:
    *
    *          caps1
    *       +-------------
@@ -1492,83 +1488,6 @@ gst_caps_subtract (GstCaps * minuend, GstCaps * subtrahend)
   return dest;
 }
 
-/* union operation */
-
-#if 0
-static GstStructure *
-gst_caps_structure_union (const GstStructure * struct1,
-    const GstStructure * struct2)
-{
-  int i;
-  GstStructure *dest;
-  const GstStructureField *field1;
-  const GstStructureField *field2;
-  int ret;
-
-  /* FIXME this doesn't actually work */
-
-  if (struct1->name != struct2->name)
-    return NULL;
-
-  dest = gst_structure_new_id_empty (struct1->name);
-
-  for (i = 0; i < struct1->fields->len; i++) {
-    GValue dest_value = { 0 };
-
-    field1 = GST_STRUCTURE_FIELD (struct1, i);
-    field2 = gst_structure_id_get_field (struct2, field1->name);
-
-    if (field2 == NULL) {
-      continue;
-    } else {
-      if (gst_value_union (&dest_value, &field1->value, &field2->value)) {
-        gst_structure_set_value (dest, g_quark_to_string (field1->name),
-            &dest_value);
-      } else {
-        ret = gst_value_compare (&field1->value, &field2->value);
-      }
-    }
-  }
-
-  return dest;
-}
-#endif
-
-/**
- * gst_caps_union:
- * @caps1: a #GstCaps to union
- * @caps2: a #GstCaps to union
- *
- * Creates a new #GstCaps that contains all the formats that are in
- * either @caps1 and @caps2.
- *
- * Returns: the new #GstCaps
- */
-GstCaps *
-gst_caps_union (GstCaps * caps1, GstCaps * caps2)
-{
-  GstCaps *dest1;
-
-  /* NULL pointers are no correct GstCaps */
-  g_return_val_if_fail (caps1 != NULL, NULL);
-  g_return_val_if_fail (caps2 != NULL, NULL);
-
-  if (CAPS_IS_EMPTY (caps1))
-    return gst_caps_ref (caps2);
-
-  if (CAPS_IS_EMPTY (caps2))
-    return gst_caps_ref (caps1);
-
-  if (CAPS_IS_ANY (caps1) || CAPS_IS_ANY (caps2))
-    return gst_caps_ref (caps1);
-
-  dest1 = _gst_caps_copy (caps1);
-  gst_caps_append (dest1, gst_caps_ref (caps2));
-
-  dest1 = gst_caps_simplify (dest1);
-  return dest1;
-}
-
 /* normalize/simplify operations */
 
 typedef struct _NormalizeForeach
@@ -1620,22 +1539,22 @@ GstCaps *
 gst_caps_normalize (GstCaps * caps)
 {
   NormalizeForeach nf;
-  GstCaps *newcaps;
   guint i;
 
   g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
 
-  newcaps = gst_caps_make_writable (caps);
-  nf.caps = newcaps;
+  caps = gst_caps_make_writable (caps);
 
-  for (i = 0; i < gst_caps_get_size (newcaps); i++) {
-    nf.structure = gst_caps_get_structure_unchecked (newcaps, i);
+  nf.caps = caps;
+
+  for (i = 0; i < gst_caps_get_size (nf.caps); i++) {
+    nf.structure = gst_caps_get_structure_unchecked (nf.caps, i);
 
     while (!gst_structure_foreach (nf.structure,
             gst_caps_normalize_foreach, &nf));
   }
 
-  return newcaps;
+  return nf.caps;
 }
 
 static gint
@@ -1764,6 +1683,8 @@ gst_caps_switch_structures (GstCaps * caps, GstStructure * old,
  * identical are merged.  Component structures that have values that can be
  * merged are also merged.
  *
+ * This method does not preserve the original order of @caps.
+ *
  * Returns: The simplified caps.
  */
 GstCaps *
@@ -1774,14 +1695,15 @@ gst_caps_simplify (GstCaps * caps)
 
   g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
 
-  if (gst_caps_is_fixed (caps))
+  start = GST_CAPS_LEN (caps) - 1;
+  /* one caps, already as simple as can be */
+  if (start == 0)
     return caps;
 
   caps = gst_caps_make_writable (caps);
 
   g_ptr_array_sort (GST_CAPS_ARRAY (caps), gst_caps_compare_structures);
 
-  start = GST_CAPS_LEN (caps) - 1;
   for (i = start; i >= 0; i--) {
     simplify = gst_caps_get_structure_unchecked (caps, i);
     compare = gst_caps_get_structure_unchecked (caps, start);
@@ -1850,7 +1772,7 @@ gst_caps_fixate (GstCaps * caps)
  * |[
  * GST_LOG ("caps are %" GST_PTR_FORMAT, caps);
  * ]|
- * This prints the caps in human readble form.
+ * This prints the caps in human readable form.
  *
  * Returns: (transfer full): a newly allocated string representing @caps.
  */