mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-01 06:01:04 +00:00
colorspace: fix caps negotiation
This commit is contained in:
parent
edf33ec985
commit
b94f979317
1 changed files with 29 additions and 63 deletions
|
@ -133,50 +133,39 @@ static GstCaps *
|
||||||
gst_csp_caps_remove_format_info (GstCaps * caps)
|
gst_csp_caps_remove_format_info (GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstStructure *yuvst, *rgbst, *grayst;
|
GstStructure *yuvst, *rgbst, *grayst;
|
||||||
|
gint i, n;
|
||||||
|
GstCaps *res;
|
||||||
|
|
||||||
/* We know there's only one structure since we're given simple caps */
|
res = gst_caps_new_empty ();
|
||||||
caps = gst_caps_copy (caps);
|
|
||||||
|
|
||||||
yuvst = gst_caps_get_structure (caps, 0);
|
n = gst_caps_get_size (caps);
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
yuvst = gst_caps_get_structure (caps, i);
|
||||||
|
|
||||||
gst_structure_set_name (yuvst, "video/x-raw-yuv");
|
/* If this is already expressed by the existing caps
|
||||||
gst_structure_remove_fields (yuvst, "format", "endianness", "depth",
|
* skip this structure */
|
||||||
"bpp", "red_mask", "green_mask", "blue_mask", "alpha_mask",
|
if (i > 0 && gst_caps_is_subset_structure (res, yuvst))
|
||||||
"palette_data", "color-matrix", NULL);
|
continue;
|
||||||
|
|
||||||
rgbst = gst_structure_copy (yuvst);
|
yuvst = gst_structure_copy (yuvst);
|
||||||
gst_structure_set_name (rgbst, "video/x-raw-rgb");
|
gst_structure_set_name (yuvst, "video/x-raw-yuv");
|
||||||
gst_structure_remove_fields (rgbst, "color-matrix", "chroma-site", NULL);
|
gst_structure_remove_fields (yuvst, "format", "endianness", "depth",
|
||||||
|
"bpp", "red_mask", "green_mask", "blue_mask", "alpha_mask",
|
||||||
|
"palette_data", NULL);
|
||||||
|
|
||||||
grayst = gst_structure_copy (rgbst);
|
rgbst = gst_structure_copy (yuvst);
|
||||||
gst_structure_set_name (grayst, "video/x-raw-gray");
|
gst_structure_set_name (rgbst, "video/x-raw-rgb");
|
||||||
|
gst_structure_remove_fields (rgbst, "color-matrix", "chroma-site", NULL);
|
||||||
|
|
||||||
gst_caps_append_structure (caps, rgbst);
|
grayst = gst_structure_copy (rgbst);
|
||||||
gst_caps_append_structure (caps, grayst);
|
gst_structure_set_name (grayst, "video/x-raw-gray");
|
||||||
|
|
||||||
return caps;
|
gst_caps_append_structure (res, yuvst);
|
||||||
}
|
gst_caps_append_structure (res, rgbst);
|
||||||
|
gst_caps_append_structure (res, grayst);
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_csp_structure_is_alpha (GstStructure * s)
|
|
||||||
{
|
|
||||||
GQuark name;
|
|
||||||
|
|
||||||
name = gst_structure_get_name_id (s);
|
|
||||||
|
|
||||||
if (name == _QRAWRGB) {
|
|
||||||
return gst_structure_id_has_field (s, _QALPHAMASK);
|
|
||||||
} else if (name == _QRAWYUV) {
|
|
||||||
guint32 fourcc;
|
|
||||||
|
|
||||||
if (!gst_structure_get_fourcc (s, "format", &fourcc))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
return (fourcc == GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The caps can be transformed into any other caps with format info removed.
|
/* The caps can be transformed into any other caps with format info removed.
|
||||||
|
@ -189,42 +178,20 @@ gst_csp_transform_caps (GstBaseTransform * btrans,
|
||||||
GstCaps *template;
|
GstCaps *template;
|
||||||
GstCaps *tmp, *tmp2;
|
GstCaps *tmp, *tmp2;
|
||||||
GstCaps *result;
|
GstCaps *result;
|
||||||
GstStructure *s;
|
|
||||||
GstCaps *alpha, *non_alpha;
|
|
||||||
|
|
||||||
template = gst_static_pad_template_get_caps (&gst_csp_src_template);
|
template = gst_static_pad_template_get_caps (&gst_csp_src_template);
|
||||||
result = gst_caps_copy (caps);
|
result = gst_caps_copy (caps);
|
||||||
|
|
||||||
/* Get all possible caps that we can transform to */
|
/* Get all possible caps that we can transform to */
|
||||||
tmp = gst_csp_caps_remove_format_info (caps);
|
tmp = gst_csp_caps_remove_format_info (caps);
|
||||||
tmp2 = gst_caps_intersect (tmp, template);
|
|
||||||
gst_caps_unref (tmp);
|
|
||||||
tmp = tmp2;
|
|
||||||
|
|
||||||
/* Now move alpha formats to the beginning if caps is an alpha format
|
if (filter) {
|
||||||
* or at the end if caps is no alpha format */
|
tmp2 = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
|
||||||
alpha = gst_caps_new_empty ();
|
gst_caps_unref (tmp);
|
||||||
non_alpha = gst_caps_new_empty ();
|
tmp = tmp2;
|
||||||
|
|
||||||
while ((s = gst_caps_steal_structure (tmp, 0))) {
|
|
||||||
if (gst_csp_structure_is_alpha (s))
|
|
||||||
gst_caps_append_structure (alpha, s);
|
|
||||||
else
|
|
||||||
gst_caps_append_structure (non_alpha, s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s = gst_caps_get_structure (caps, 0);
|
result = tmp;
|
||||||
gst_caps_unref (tmp);
|
|
||||||
|
|
||||||
if (gst_csp_structure_is_alpha (s)) {
|
|
||||||
gst_caps_append (alpha, non_alpha);
|
|
||||||
tmp = alpha;
|
|
||||||
} else {
|
|
||||||
gst_caps_append (non_alpha, alpha);
|
|
||||||
tmp = non_alpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_caps_append (result, tmp);
|
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (btrans, "transformed %" GST_PTR_FORMAT " into %"
|
GST_DEBUG_OBJECT (btrans, "transformed %" GST_PTR_FORMAT " into %"
|
||||||
GST_PTR_FORMAT, caps, result);
|
GST_PTR_FORMAT, caps, result);
|
||||||
|
@ -463,7 +430,6 @@ gst_csp_class_init (GstCspClass * klass)
|
||||||
g_param_spec_enum ("dither", "Dither", "Apply dithering while converting",
|
g_param_spec_enum ("dither", "Dither", "Apply dithering while converting",
|
||||||
dither_method_get_type (), DITHER_NONE,
|
dither_method_get_type (), DITHER_NONE,
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in a new issue