/**
* 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
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
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
static gboolean
gst_caps_structure_simplify (GstStructure ** result,
- const GstStructure * simplify, GstStructure * compare)
+ GstStructure * simplify, GstStructure * compare)
{
GSList *list;
UnionField field = { 0, {0,}, NULL };
/* try to union both structs */
field.compare = compare;
- if (gst_structure_foreach ((GstStructure *) simplify,
+ if (gst_structure_foreach (simplify,
gst_caps_structure_figure_out_union, &field)) {
gboolean ret = FALSE;
* 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 *
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);