bayer: fix _transform_caps method to preserve fields in given caps

https://bugzilla.gnome.org/show_bug.cgi?id=758717
This commit is contained in:
Joan Pau Beltran 2016-10-11 18:48:06 +02:00 committed by Nicolas Dufresne
parent 312c8c9f7c
commit 32b356b2c5
2 changed files with 47 additions and 60 deletions

View file

@ -286,42 +286,35 @@ static GstCaps *
gst_bayer2rgb_transform_caps (GstBaseTransform * base, gst_bayer2rgb_transform_caps (GstBaseTransform * base,
GstPadDirection direction, GstCaps * caps, GstCaps * filter) GstPadDirection direction, GstCaps * caps, GstCaps * filter)
{ {
GstBayer2RGB *bayer2rgb;
GstCaps *res_caps, *tmp_caps;
GstStructure *structure; GstStructure *structure;
GstCaps *newcaps; guint i, caps_size;
GstStructure *newstruct;
GST_DEBUG_OBJECT (base, "transforming caps from %" GST_PTR_FORMAT, caps); bayer2rgb = GST_BAYER2RGB (base);
structure = gst_caps_get_structure (caps, 0); res_caps = gst_caps_copy (caps);
caps_size = gst_caps_get_size (res_caps);
if (direction == GST_PAD_SRC) { for (i = 0; i < caps_size; i++) {
newcaps = gst_caps_from_string ("video/x-bayer," structure = gst_caps_get_structure (res_caps, i);
"format=(string){bggr,grbg,gbrg,rggb}"); if (direction == GST_PAD_SINK) {
} else { gst_structure_set_name (structure, "video/x-raw");
newcaps = gst_caps_new_empty_simple ("video/x-raw"); gst_structure_remove_field (structure, "format");
} else {
gst_structure_set_name (structure, "video/x-bayer");
gst_structure_remove_fields (structure, "format", "colorimetry",
"chroma-site", NULL);
}
} }
newstruct = gst_caps_get_structure (newcaps, 0); if (filter) {
tmp_caps = res_caps;
gst_structure_set_value (newstruct, "width", res_caps =
gst_structure_get_value (structure, "width")); gst_caps_intersect_full (filter, tmp_caps, GST_CAPS_INTERSECT_FIRST);
gst_structure_set_value (newstruct, "height", gst_caps_unref (tmp_caps);
gst_structure_get_value (structure, "height"));
gst_structure_set_value (newstruct, "framerate",
gst_structure_get_value (structure, "framerate"));
if (filter != NULL) {
GstCaps *icaps;
GST_DEBUG_OBJECT (base, " filter %" GST_PTR_FORMAT, filter);
icaps = gst_caps_intersect_full (filter, newcaps, GST_CAPS_INTERSECT_FIRST);
gst_caps_unref (newcaps);
newcaps = icaps;
} }
GST_DEBUG_OBJECT (bayer2rgb, "transformed %" GST_PTR_FORMAT " into %"
GST_DEBUG_OBJECT (base, " into %" GST_PTR_FORMAT, newcaps); GST_PTR_FORMAT, caps, res_caps);
return res_caps;
return newcaps;
} }
static gboolean static gboolean

View file

@ -126,41 +126,35 @@ static GstCaps *
gst_rgb2bayer_transform_caps (GstBaseTransform * trans, gst_rgb2bayer_transform_caps (GstBaseTransform * trans,
GstPadDirection direction, GstCaps * caps, GstCaps * filter) GstPadDirection direction, GstCaps * caps, GstCaps * filter)
{ {
GstRGB2Bayer *rgb2bayer;
GstCaps *res_caps, *tmp_caps;
GstStructure *structure; GstStructure *structure;
GstStructure *new_structure; guint i, caps_size;
GstCaps *newcaps;
const GValue *value;
GST_DEBUG_OBJECT (trans, "transforming caps (from) %" GST_PTR_FORMAT, caps); rgb2bayer = GST_RGB_2_BAYER (trans);
structure = gst_caps_get_structure (caps, 0); res_caps = gst_caps_copy (caps);
caps_size = gst_caps_get_size (res_caps);
if (direction == GST_PAD_SRC) { for (i = 0; i < caps_size; i++) {
newcaps = gst_caps_new_empty_simple ("video/x-raw"); structure = gst_caps_get_structure (res_caps, i);
} else { if (direction == GST_PAD_SRC) {
newcaps = gst_caps_new_empty_simple ("video/x-bayer"); gst_structure_set_name (structure, "video/x-raw");
gst_structure_remove_field (structure, "format");
} else {
gst_structure_set_name (structure, "video/x-bayer");
gst_structure_remove_fields (structure, "format", "colorimetry",
"chroma-site", NULL);
}
} }
new_structure = gst_caps_get_structure (newcaps, 0);
value = gst_structure_get_value (structure, "width");
gst_structure_set_value (new_structure, "width", value);
value = gst_structure_get_value (structure, "height");
gst_structure_set_value (new_structure, "height", value);
value = gst_structure_get_value (structure, "framerate");
gst_structure_set_value (new_structure, "framerate", value);
GST_DEBUG_OBJECT (trans, "transforming caps (into) %" GST_PTR_FORMAT,
newcaps);
if (filter) { if (filter) {
GstCaps *tmpcaps = newcaps; tmp_caps = res_caps;
newcaps = gst_caps_intersect (newcaps, filter); res_caps =
gst_caps_unref (tmpcaps); gst_caps_intersect_full (filter, tmp_caps, GST_CAPS_INTERSECT_FIRST);
gst_caps_unref (tmp_caps);
} }
GST_DEBUG_OBJECT (rgb2bayer, "transformed %" GST_PTR_FORMAT " into %"
return newcaps; GST_PTR_FORMAT, caps, res_caps);
return res_caps;
} }
static gboolean static gboolean