summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2010-04-20 15:42:30 +0200
committerBenjamin Otte <otte@redhat.com>2010-04-20 15:42:30 +0200
commitb368cf710f261ea9c60bd33a6cddd98d24db9c7d (patch)
treea931156e36c3fc9bd398ad391078ac5df9023a48
parent16232047ea0fbc396d2c1cb0bd3bc2ba0c226077 (diff)
Modify API for expanding with types.
There's now gst_cairo_caps_expand_for_surface_types(). This function does the right thing and allows the following pipeline to work: . ! video/x-cairo,surface-type=18 ! cairoxconvert ! video/x-raw-yuv ! . which previously did not work.
-rw-r--r--docs/libs/gst-plugins-cairo-libs-sections.txt2
-rw-r--r--ext/xlib/gstcairoxconvert.c5
-rw-r--r--gst-libs/gst/cairo/gstcairocaps.c88
3 files changed, 61 insertions, 34 deletions
diff --git a/docs/libs/gst-plugins-cairo-libs-sections.txt b/docs/libs/gst-plugins-cairo-libs-sections.txt
index 5099cce..857a418 100644
--- a/docs/libs/gst-plugins-cairo-libs-sections.txt
+++ b/docs/libs/gst-plugins-cairo-libs-sections.txt
@@ -5,7 +5,7 @@ GstCairoFormat
gst_cairo_caps_any
gst_cairo_caps_default
gst_cairo_caps_expand
-gst_cairo_caps_expand_surface_types
+gst_cairo_caps_expand_for_surface_types
gst_cairo_pad_template_new_any
gst_cairo_pad_template_new_default
gst_cairo_format_new
diff --git a/ext/xlib/gstcairoxconvert.c b/ext/xlib/gstcairoxconvert.c
index c33fc76..6e69b80 100644
--- a/ext/xlib/gstcairoxconvert.c
+++ b/ext/xlib/gstcairoxconvert.c
@@ -48,9 +48,8 @@ gst_cairo_x_convert_transform_caps (GstBaseTransform * btrans,
GstCaps *cairo, *expand, *result;
cairo = gst_caps_from_string ("video/x-cairo");
- expand = gst_cairo_caps_expand (caps, GST_CAIRO_FORMAT_FORMAT);
- expand = gst_cairo_caps_expand_surface_types (expand,
- gst_cairo_x_target_get_supported_types ());
+ expand = gst_cairo_caps_expand_for_surface_types (caps,
+ GST_CAIRO_FORMAT_FORMAT, gst_cairo_x_target_get_supported_types ());
result = gst_caps_intersect (cairo, expand);
/* must exist, we just expanded to make sure */
diff --git a/gst-libs/gst/cairo/gstcairocaps.c b/gst-libs/gst/cairo/gstcairocaps.c
index 90a6a8d..7cfe50d 100644
--- a/gst-libs/gst/cairo/gstcairocaps.c
+++ b/gst-libs/gst/cairo/gstcairocaps.c
@@ -109,37 +109,32 @@ gst_cairo_value_init_from_surface_types (GValue * value,
}
static GstCaps *
-gst_cairo_caps_expand_surface_types_by_value (GstCaps * caps,
- const GValue * value)
+gst_cairo_caps_set_surface_types_by_value (GstCaps * caps,
+ const GValue * value, gboolean expand)
{
guint i;
for (i = 0; i < gst_caps_get_size (caps); i++) {
GstStructure *check = gst_caps_get_structure (caps, i);
- GValue unioned = { 0, };
if (!gst_cairo_structure_is_native (check))
continue;
- gst_value_union (&unioned, gst_structure_get_value (check, "surface-type"),
- value);
- gst_structure_set_value (check, "surface-type", &unioned);
- g_value_unset (&unioned);
+ if (expand) {
+ GValue unioned = { 0, };
+ gst_value_union (&unioned,
+ gst_structure_get_value (check, "surface-type"), value);
+ gst_structure_set_value (check, "surface-type", &unioned);
+ g_value_unset (&unioned);
+ } else {
+ gst_structure_set_value (check, "surface-type", value);
+ }
}
return caps;
}
-/**
- * gst_cairo_caps_expand_surface_types:
- * @caps: caps to expand. This function takes a reference to the caps.
- * @types: The supported types to add to @caps.
- *
- * Modifies all native caps to also include the given surface @types.
- *
- * Returns: The expanded caps.
- **/
-GstCaps *
+static GstCaps *
gst_cairo_caps_expand_surface_types (GstCaps * caps,
const cairo_surface_type_t * types)
{
@@ -149,7 +144,7 @@ gst_cairo_caps_expand_surface_types (GstCaps * caps,
caps = gst_caps_make_writable (caps);
gst_cairo_value_init_from_surface_types (&value, types);
- gst_cairo_caps_expand_surface_types_by_value (caps, &value);
+ gst_cairo_caps_set_surface_types_by_value (caps, &value, TRUE);
g_value_unset (&value);
return caps;
@@ -180,16 +175,11 @@ gst_cairo_caps_default (const cairo_surface_type_t * types)
if (g_once_init_enter (&default_)) {
GstCaps *caps = gst_caps_make_writable (gst_cairo_caps_any ());
- guint i;
-
- for (i = 0; i < gst_caps_get_size (caps); i++) {
- GstStructure *check = gst_caps_get_structure (caps, i);
+ GValue value = { 0, };
- if (!gst_cairo_structure_is_native (check))
- continue;
-
- gst_structure_set (check, "surface-type", G_TYPE_INT, 0, NULL);
- }
+ g_value_init (&value, G_TYPE_INT);
+ caps = gst_cairo_caps_set_surface_types_by_value (caps, &value, FALSE);
+ g_value_unset (&value);
g_once_init_leave (&default_, GPOINTER_TO_SIZE (caps));
}
@@ -217,11 +207,36 @@ gst_cairo_caps_default (const cairo_surface_type_t * types)
GstCaps *
gst_cairo_caps_expand (const GstCaps * caps, GstCairoFormatOption expand)
{
+ g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
+
+ return gst_cairo_caps_expand_for_surface_types (caps, expand, NULL);
+}
+
+/**
+ * gst_cairo_caps_expand_for_surface_types:
+ * @caps: a valid cairo caps to expand
+ * @expand: parts of the caps that should be expanded
+ * @types: An array of all supported types ending with
+ * %CAIRO_SURFACE_TYPE_IMAGE or %NULL for just the default type.
+ *
+ * This function is a special version of gst_cairo_caps_expand() that
+ * when @expand includes %GST_CAIRO_FORMAT_FORMAT expands to all of the
+ * @types given instead of just the default.
+ *
+ * Returns: a new caps with the expanded fields.
+ **/
+GstCaps *
+gst_cairo_caps_expand_for_surface_types (const GstCaps * caps,
+ GstCairoFormatOption expand, const cairo_surface_type_t * types)
+{
GstCaps *expanded;
+ GValue surfaces_value = { 0, };
guint i;
g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
+ gst_cairo_value_init_from_surface_types (&surfaces_value, types);
+
/* start with a copy of the current caps - we prefer unchanged caps */
expanded = gst_caps_copy (caps);
@@ -230,10 +245,21 @@ gst_cairo_caps_expand (const GstCaps * caps, GstCairoFormatOption expand)
GstCaps *copy;
if (expand & GST_CAIRO_FORMAT_FORMAT) {
- copy = gst_caps_make_writable (gst_cairo_caps_default (NULL));
if (gst_cairo_structure_is_native (expand_me)) {
- copy = gst_cairo_caps_expand_surface_types_by_value (copy,
- gst_structure_get_value (expand_me, "surface-type"));
+ GValue intersect = { 0, };
+ const GValue *structure_types;
+
+ structure_types = gst_structure_get_value (expand_me, "surface-type");
+ if (gst_value_intersect (&intersect, structure_types, &surfaces_value)) {
+ copy = gst_caps_make_writable (gst_cairo_caps_default (types));
+ copy = gst_cairo_caps_set_surface_types_by_value (copy,
+ structure_types, TRUE);
+ g_value_unset (&intersect);
+ } else {
+ copy = gst_caps_copy_nth (caps, i);
+ }
+ } else {
+ copy = gst_caps_make_writable (gst_cairo_caps_default (types));
}
} else {
copy = gst_caps_copy_nth (caps, i);
@@ -279,5 +305,7 @@ gst_cairo_caps_expand (const GstCaps * caps, GstCairoFormatOption expand)
gst_caps_append (expanded, copy);
}
+ g_value_unset (&surfaces_value);
+
return expanded;
}