miniobjects: pass copy, dispose and free function to gst_mini_object_init()
[platform/upstream/gstreamer.git] / gst / gstcaps.c
index 767a2f4..f494098 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
@@ -181,23 +177,21 @@ _gst_caps_free (GstCaps * caps)
   g_ptr_array_free (GST_CAPS_ARRAY (caps), TRUE);
 
 #ifdef DEBUG_REFCOUNT
-  GST_CAT_LOG (GST_CAT_CAPS, "freeing caps %p", caps);
+  GST_CAT_TRACE (GST_CAT_CAPS, "freeing caps %p", caps);
 #endif
-  g_slice_free1 (GST_MINI_OBJECT_SIZE (caps), caps);
+  g_slice_free1 (sizeof (GstCapsImpl), caps);
 }
 
 static void
-gst_caps_init (GstCaps * caps, gsize size)
+gst_caps_init (GstCaps * caps)
 {
-  gst_mini_object_init (GST_MINI_OBJECT_CAST (caps), _gst_caps_type, size);
-
-  caps->mini_object.copy = (GstMiniObjectCopyFunction) _gst_caps_copy;
-  caps->mini_object.dispose = NULL;
-  caps->mini_object.free = (GstMiniObjectFreeFunction) _gst_caps_free;
+  gst_mini_object_init (GST_MINI_OBJECT_CAST (caps), _gst_caps_type,
+      (GstMiniObjectCopyFunction) _gst_caps_copy, NULL,
+      (GstMiniObjectFreeFunction) _gst_caps_free);
 
   /* 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 ();
@@ -220,7 +214,7 @@ gst_caps_new_empty (void)
 
   caps = (GstCaps *) g_slice_new (GstCapsImpl);
 
-  gst_caps_init (caps, sizeof (GstCapsImpl));
+  gst_caps_init (caps);
 
 #ifdef DEBUG_REFCOUNT
   GST_CAT_TRACE (GST_CAT_CAPS, "created caps %p", caps);
@@ -447,7 +441,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
@@ -1041,8 +1035,6 @@ gst_caps_is_subset_structure (const GstCaps * caps,
  * <note>This function does not work reliably if optional properties for caps
  * are included on one caps and omitted on the other.</note>
  *
- * This function deals correctly with passing NULL for any of the caps.
- *
  * Returns: TRUE if both caps are equal.
  */
 gboolean
@@ -1067,8 +1059,6 @@ gst_caps_is_equal (const GstCaps * caps1, const GstCaps * caps2)
  *
  * Checks if the given caps are exactly the same set of caps.
  *
- * This function deals correctly with passing NULL for any of the caps.
- *
  * Returns: TRUE if both caps are strictly equal.
  *
  * Since: 0.10.36
@@ -1137,7 +1127,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 +1199,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,90 +1482,12 @@ 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
 {
   GstCaps *caps;
   GstStructure *structure;
-  gboolean writable;
 }
 NormalizeForeach;
 
@@ -1593,10 +1505,6 @@ gst_caps_normalize_foreach (GQuark field_id, const GValue * value, gpointer ptr)
       GstStructure *structure = gst_structure_copy (nf->structure);
 
       gst_structure_id_set_value (structure, field_id, v);
-      if (G_UNLIKELY (!nf->writable)) {
-        nf->caps = gst_caps_make_writable (nf->caps);
-        nf->writable = TRUE;
-      }
       gst_caps_append_structure_unchecked (nf->caps, structure);
     }
 
@@ -1629,8 +1537,9 @@ gst_caps_normalize (GstCaps * caps)
 
   g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
 
+  caps = gst_caps_make_writable (caps);
+
   nf.caps = caps;
-  nf.writable = FALSE;
 
   for (i = 0; i < gst_caps_get_size (nf.caps); i++) {
     nf.structure = gst_caps_get_structure_unchecked (nf.caps, i);
@@ -1768,6 +1677,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 *
@@ -1855,7 +1766,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.
  */