summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Kost <ensonic@users.sourceforge.net>2006-08-21 14:54:31 +0000
committerStefan Kost <ensonic@users.sourceforge.net>2006-08-21 14:54:31 +0000
commit38d2d33f22361778bcfe4d2f48510a7e491059c0 (patch)
tree63742d63943607b3fd3e92f23da4de7870f7fb23
parent9c590b226e5afd68b3f8f2d89086b66667b9cdc4 (diff)
API: Add gst_caps_merge() and use it in basetransform, fixes #345444 in a better way
Original commit message from CVS: * docs/gst/gstreamer-sections.txt: * gst/gstcaps.c: (gst_structure_is_equal_foreach), (gst_caps_merge): * gst/gstcaps.h: * libs/gst/base/gstbasetransform.c: (gst_base_transform_transform_caps): API: Add gst_caps_merge() and use it in basetransform, fixes #345444 in a better way
-rw-r--r--ChangeLog11
-rw-r--r--docs/gst/gstreamer-sections.txt2
-rw-r--r--gst/gstcaps.c96
-rw-r--r--gst/gstcaps.h114
-rw-r--r--libs/gst/base/gstbasetransform.c10
5 files changed, 139 insertions, 94 deletions
diff --git a/ChangeLog b/ChangeLog
index de40801ee..9cace968c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2006-08-21 Stefan Kost <ensonic@users.sf.net>
+
+ * docs/gst/gstreamer-sections.txt:
+ * gst/gstcaps.c: (gst_structure_is_equal_foreach),
+ (gst_caps_merge):
+ * gst/gstcaps.h:
+ * libs/gst/base/gstbasetransform.c:
+ (gst_base_transform_transform_caps):
+ API: Add gst_caps_merge() and use it in basetransform, fixes #345444
+ in a better way
+
2006-08-21 Edward Hervey <edward@fluendo.com>
* gst/gstxml.c: (gst_xml_class_init), (gst_xml_dispose):
diff --git a/docs/gst/gstreamer-sections.txt b/docs/gst/gstreamer-sections.txt
index 0d5bd9668..ea691f941 100644
--- a/docs/gst/gstreamer-sections.txt
+++ b/docs/gst/gstreamer-sections.txt
@@ -220,7 +220,9 @@ gst_caps_copy
gst_caps_copy_nth
gst_static_caps_get
gst_caps_append
+gst_caps_merge
gst_caps_append_structure
+gst_caps_remove_structure
gst_caps_get_size
gst_caps_get_structure
gst_caps_set_simple
diff --git a/gst/gstcaps.c b/gst/gstcaps.c
index 78922bd05..7b3720ecd 100644
--- a/gst/gstcaps.c
+++ b/gst/gstcaps.c
@@ -464,6 +464,22 @@ gst_caps_remove_and_get_structure (GstCaps * caps, guint idx)
return s;
}
+static gboolean
+gst_structure_is_equal_foreach (GQuark field_id, const GValue * val2,
+ gpointer data)
+{
+ GstStructure *struct1 = (GstStructure *) data;
+ const GValue *val1 = gst_structure_id_get_value (struct1, field_id);
+
+ if (val1 == NULL)
+ return FALSE;
+ if (gst_value_compare (val1, val2) == GST_VALUE_EQUAL) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/**
* gst_caps_append:
* @caps1: the #GstCaps that will be appended to
@@ -506,6 +522,51 @@ gst_caps_append (GstCaps * caps1, GstCaps * caps2)
}
/**
+ * gst_caps_merge:
+ * @caps1: the #GstCaps that will take the new entries
+ * @caps2: the #GstCaps to merge in
+ *
+ * Appends the structures contained in @caps2 to @caps1 if they are not yet in
+ * @caps1. The structures in @caps2 are not copied -- they are transferred to
+ * @caps1, and then @caps2 is freed.
+ * If either caps is ANY, the resulting caps will be ANY.
+ */
+void
+gst_caps_merge (GstCaps * caps1, GstCaps * caps2)
+{
+ GstStructure *structure;
+ int i;
+
+ g_return_if_fail (GST_IS_CAPS (caps1));
+ g_return_if_fail (GST_IS_CAPS (caps2));
+ g_return_if_fail (IS_WRITABLE (caps1));
+ g_return_if_fail (IS_WRITABLE (caps2));
+
+#ifdef USE_POISONING
+ CAPS_POISON (caps2);
+#endif
+ if (gst_caps_is_any (caps1) || gst_caps_is_any (caps2)) {
+ /* FIXME: this leaks */
+ caps1->flags |= GST_CAPS_FLAGS_ANY;
+ for (i = caps2->structs->len - 1; i >= 0; i--) {
+ structure = gst_caps_remove_and_get_structure (caps2, i);
+ gst_structure_free (structure);
+ }
+ } else {
+ GstCaps *com = gst_caps_intersect (caps1, caps2);
+ GstCaps *add = gst_caps_subtract (caps2, com);
+
+ /*
+ GST_DEBUG ("common : %d", gst_caps_get_size (com));
+ GST_DEBUG ("adding : %d", gst_caps_get_size (add));
+ */
+ gst_caps_append (caps1, add);
+ gst_caps_unref (com);
+ }
+ gst_caps_unref (caps2); /* guaranteed to free it */
+}
+
+/**
* gst_caps_append_structure:
* @caps: the #GstCaps that will be appended to
* @structure: the #GstStructure to append
@@ -531,7 +592,7 @@ gst_caps_append_structure (GstCaps * caps, GstStructure * structure)
}
}
-/*
+/**
* gst_caps_remove_structure:
* @caps: the #GstCaps to remove from
* @idx: Index of the structure to remove
@@ -553,23 +614,6 @@ gst_caps_remove_structure (GstCaps * caps, guint idx)
}
/**
- * gst_caps_split_one:
- * @caps: a #GstCaps
- *
- * This function is not implemented.
- *
- * Returns: NULL
- */
-GstCaps *
-gst_caps_split_one (GstCaps * caps)
-{
- /* FIXME */
- g_critical ("unimplemented");
-
- return NULL;
-}
-
-/**
* gst_caps_get_size:
* @caps: a #GstCaps
*
@@ -779,22 +823,6 @@ gst_caps_is_fixed (const GstCaps * caps)
return gst_structure_foreach (structure, gst_caps_is_fixed_foreach, NULL);
}
-static gboolean
-gst_structure_is_equal_foreach (GQuark field_id, const GValue * val2,
- gpointer data)
-{
- GstStructure *struct1 = (GstStructure *) data;
- const GValue *val1 = gst_structure_id_get_value (struct1, field_id);
-
- if (val1 == NULL)
- return FALSE;
- if (gst_value_compare (val1, val2) == GST_VALUE_EQUAL) {
- return TRUE;
- }
-
- return FALSE;
-}
-
/**
* gst_caps_is_equal_fixed:
* @caps1: the #GstCaps to test
diff --git a/gst/gstcaps.h b/gst/gstcaps.h
index 9756e2b88..668dfc704 100644
--- a/gst/gstcaps.h
+++ b/gst/gstcaps.h
@@ -172,77 +172,79 @@ struct _GstStaticCaps {
gpointer _gst_reserved[GST_PADDING];
};
-GType gst_caps_get_type (void);
-GstCaps * gst_caps_new_empty (void);
-GstCaps * gst_caps_new_any (void);
-GstCaps * gst_caps_new_simple (const char *media_type,
- const char *fieldname,
- ...);
-GstCaps * gst_caps_new_full (GstStructure *struct1,
- ...);
-GstCaps * gst_caps_new_full_valist (GstStructure *structure,
- va_list var_args);
+GType gst_caps_get_type (void);
+GstCaps * gst_caps_new_empty (void);
+GstCaps * gst_caps_new_any (void);
+GstCaps * gst_caps_new_simple (const char *media_type,
+ const char *fieldname,
+ ...);
+GstCaps * gst_caps_new_full (GstStructure *struct1, ...);
+GstCaps * gst_caps_new_full_valist (GstStructure *structure,
+ va_list var_args);
/* reference counting */
-GstCaps * gst_caps_ref (GstCaps* caps);
-GstCaps * gst_caps_copy (const GstCaps * caps);
-GstCaps * gst_caps_make_writable (GstCaps *caps);
-void gst_caps_unref (GstCaps* caps);
+GstCaps * gst_caps_ref (GstCaps* caps);
+GstCaps * gst_caps_copy (const GstCaps * caps);
+GstCaps * gst_caps_make_writable (GstCaps *caps);
+void gst_caps_unref (GstCaps* caps);
-GType gst_static_caps_get_type (void);
-GstCaps * gst_static_caps_get (GstStaticCaps *static_caps);
+GType gst_static_caps_get_type (void);
+GstCaps * gst_static_caps_get (GstStaticCaps *static_caps);
/* manipulation */
-void gst_caps_append (GstCaps *caps1,
- GstCaps *caps2);
-void gst_caps_append_structure (GstCaps *caps,
- GstStructure *structure);
-guint gst_caps_get_size (const GstCaps *caps);
-GstStructure * gst_caps_get_structure (const GstCaps *caps,
- guint index);
-GstCaps * gst_caps_copy_nth (const GstCaps * caps, guint nth);
-void gst_caps_truncate (GstCaps * caps);
-void gst_caps_set_simple (GstCaps *caps,
- char *field, ...) G_GNUC_NULL_TERMINATED;
-void gst_caps_set_simple_valist (GstCaps *caps,
- char *field,
- va_list varargs);
+void gst_caps_append (GstCaps *caps1,
+ GstCaps *caps2);
+void gst_caps_merge (GstCaps *caps1,
+ GstCaps *caps2);
+void gst_caps_append_structure (GstCaps *caps,
+ GstStructure *structure);
+void gst_caps_remove_structure (GstCaps * caps, guint idx);
+guint gst_caps_get_size (const GstCaps *caps);
+GstStructure * gst_caps_get_structure (const GstCaps *caps,
+ guint index);
+GstCaps * gst_caps_copy_nth (const GstCaps * caps, guint nth);
+void gst_caps_truncate (GstCaps * caps);
+void gst_caps_set_simple (GstCaps *caps,
+ char *field, ...) G_GNUC_NULL_TERMINATED;
+void gst_caps_set_simple_valist (GstCaps *caps,
+ char *field,
+ va_list varargs);
/* tests */
-gboolean gst_caps_is_any (const GstCaps *caps);
-gboolean gst_caps_is_empty (const GstCaps *caps);
-gboolean gst_caps_is_fixed (const GstCaps *caps);
-gboolean gst_caps_is_always_compatible (const GstCaps *caps1,
- const GstCaps *caps2);
-gboolean gst_caps_is_subset (const GstCaps *subset,
- const GstCaps *superset);
-gboolean gst_caps_is_equal (const GstCaps *caps1,
- const GstCaps *caps2);
-gboolean gst_caps_is_equal_fixed (const GstCaps * caps1,
- const GstCaps * caps2);
+gboolean gst_caps_is_any (const GstCaps *caps);
+gboolean gst_caps_is_empty (const GstCaps *caps);
+gboolean gst_caps_is_fixed (const GstCaps *caps);
+gboolean gst_caps_is_always_compatible (const GstCaps *caps1,
+ const GstCaps *caps2);
+gboolean gst_caps_is_subset (const GstCaps *subset,
+ const GstCaps *superset);
+gboolean gst_caps_is_equal (const GstCaps *caps1,
+ const GstCaps *caps2);
+gboolean gst_caps_is_equal_fixed (const GstCaps * caps1,
+ const GstCaps * caps2);
/* operations */
-GstCaps * gst_caps_intersect (const GstCaps *caps1,
- const GstCaps *caps2);
-GstCaps * gst_caps_subtract (const GstCaps *minuend,
- const GstCaps *subtrahend);
-GstCaps * gst_caps_union (const GstCaps *caps1,
- const GstCaps *caps2);
-GstCaps * gst_caps_normalize (const GstCaps *caps);
-gboolean gst_caps_do_simplify (GstCaps *caps);
+GstCaps * gst_caps_intersect (const GstCaps *caps1,
+ const GstCaps *caps2);
+GstCaps * gst_caps_subtract (const GstCaps *minuend,
+ const GstCaps *subtrahend);
+GstCaps * gst_caps_union (const GstCaps *caps1,
+ const GstCaps *caps2);
+GstCaps * gst_caps_normalize (const GstCaps *caps);
+gboolean gst_caps_do_simplify (GstCaps *caps);
#ifndef GST_DISABLE_LOADSAVE
-xmlNodePtr gst_caps_save_thyself (const GstCaps *caps,
- xmlNodePtr parent);
-GstCaps * gst_caps_load_thyself (xmlNodePtr parent);
+xmlNodePtr gst_caps_save_thyself (const GstCaps *caps,
+ xmlNodePtr parent);
+GstCaps * gst_caps_load_thyself (xmlNodePtr parent);
#endif
/* utility */
-void gst_caps_replace (GstCaps **caps,
- GstCaps *newcaps);
-gchar * gst_caps_to_string (const GstCaps *caps);
-GstCaps * gst_caps_from_string (const gchar *string);
+void gst_caps_replace (GstCaps **caps,
+ GstCaps *newcaps);
+gchar * gst_caps_to_string (const GstCaps *caps);
+GstCaps * gst_caps_from_string (const gchar *string);
G_END_DECLS
diff --git a/libs/gst/base/gstbasetransform.c b/libs/gst/base/gstbasetransform.c
index 2d2b014e3..48c1d6819 100644
--- a/libs/gst/base/gstbasetransform.c
+++ b/libs/gst/base/gstbasetransform.c
@@ -456,12 +456,14 @@ gst_base_transform_transform_caps (GstBaseTransform * trans,
/* FIXME: here we need to only append those structures, that are not yet
* in there */
temp = gst_caps_make_writable (temp);
- gst_caps_append (ret, temp);
+ /*gst_caps_append (ret, temp); */
+ gst_caps_merge (ret, temp);
}
- /* for now simplify caps */
GST_DEBUG_OBJECT (trans, "merged: (%d)", gst_caps_get_size (ret));
- gst_caps_do_simplify (ret);
- GST_DEBUG_OBJECT (trans, "simplified: (%d)", gst_caps_get_size (ret));
+ /* now simplify caps
+ gst_caps_do_simplify (ret);
+ GST_DEBUG_OBJECT (trans, "simplified: (%d)", gst_caps_get_size (ret));
+ */
}
} else {
/* else use the identity transform */