fix caps to avoid videoconvert bug in 1.8 which corrupts data

Previous way of creating caps left invalid colorimetry field 0:0:0:0,
which combined with a bug present in GStreamer 1.8 led to GRAY16_LE data
being corrupted when converted to GRAY16_BE (or vice versa). Current
method will properly initialize colorimetry field, avoiding this problem
in 1.8.
This commit is contained in:
Joshua M. Doe 2017-11-16 08:27:08 -05:00
parent f76390323f
commit e4a308a545
10 changed files with 55 additions and 51 deletions

View File

@ -359,20 +359,21 @@ gst_bitflowsrc_start (GstBaseSrc * bsrc)
} }
gst_video_info_init (&vinfo); gst_video_info_init (&vinfo);
vinfo.width = width;
vinfo.height = height;
if (bpp <= 8) { if (bpp <= 8) {
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY8); gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY8, width, height);
src->caps = gst_video_info_to_caps (&vinfo); src->caps = gst_video_info_to_caps (&vinfo);
} else if (bpp > 8 && bpp <= 16) { } else if (bpp > 8 && bpp <= 16) {
GValue val = G_VALUE_INIT; GValue val = G_VALUE_INIT;
GstStructure *s; GstStructure *s;
if (G_BYTE_ORDER == G_LITTLE_ENDIAN) if (G_BYTE_ORDER == G_LITTLE_ENDIAN) {
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_LE); gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY16_LE, width,
else if (G_BYTE_ORDER == G_BIG_ENDIAN) height);
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_BE); } else if (G_BYTE_ORDER == G_BIG_ENDIAN) {
gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY16_BE, width,
height);
}
src->caps = gst_video_info_to_caps (&vinfo); src->caps = gst_video_info_to_caps (&vinfo);
/* set bpp, extra info for GRAY16 so elements can scale properly */ /* set bpp, extra info for GRAY16 so elements can scale properly */

View File

@ -219,7 +219,7 @@ GstCaps *
gst_edt_pdv_sink_get_caps (GstBaseSink * basesink, GstCaps * filter_caps) gst_edt_pdv_sink_get_caps (GstBaseSink * basesink, GstCaps * filter_caps)
{ {
GstEdtPdvSink *pdvsink = GST_EDT_PDV_SINK (basesink); GstEdtPdvSink *pdvsink = GST_EDT_PDV_SINK (basesink);
gint depth; gint width, height, depth;
GstVideoFormat format; GstVideoFormat format;
GstVideoInfo vinfo; GstVideoInfo vinfo;
@ -229,8 +229,8 @@ gst_edt_pdv_sink_get_caps (GstBaseSink * basesink, GstCaps * filter_caps)
} }
gst_video_info_init (&vinfo); gst_video_info_init (&vinfo);
vinfo.width = pdv_get_width (pdvsink->dev); width = pdv_get_width (pdvsink->dev);
vinfo.height = pdv_get_height (pdvsink->dev); height = pdv_get_height (pdvsink->dev);
depth = pdv_get_depth (pdvsink->dev); depth = pdv_get_depth (pdvsink->dev);
switch (depth) { switch (depth) {
@ -244,7 +244,7 @@ gst_edt_pdv_sink_get_caps (GstBaseSink * basesink, GstCaps * filter_caps)
default: default:
format = GST_VIDEO_FORMAT_UNKNOWN; format = GST_VIDEO_FORMAT_UNKNOWN;
} }
vinfo.finfo = gst_video_format_get_info (format); gst_video_info_set_format (&vinfo, format, width, height);
/* TODO: handle filter_caps */ /* TODO: handle filter_caps */
return gst_video_info_to_caps (&vinfo); return gst_video_info_to_caps (&vinfo);

View File

@ -345,26 +345,26 @@ gst_edt_pdv_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
if (src->dev == NULL) { if (src->dev == NULL) {
caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src));
} else { } else {
gint depth; gint width, height, depth;
GstVideoInfo vinfo; GstVideoInfo vinfo;
/* Create video info */ /* Create video info */
gst_video_info_init (&vinfo); gst_video_info_init (&vinfo);
vinfo.width = pdv_get_width (src->dev); width = pdv_get_width (src->dev);
vinfo.height = pdv_get_height (src->dev); height = pdv_get_height (src->dev);
depth = pdv_get_depth (src->dev); depth = pdv_get_depth (src->dev);
if (depth <= 8) { if (depth <= 8) {
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY8); gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY8, width, height);
caps = gst_video_info_to_caps (&vinfo); caps = gst_video_info_to_caps (&vinfo);
} else if (depth <= 16) { } else if (depth <= 16) {
GValue val = G_VALUE_INIT; GValue val = G_VALUE_INIT;
GstStructure *s; GstStructure *s;
/* TODO: check endianness */ /* TODO: check endianness */
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_LE); gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY16_LE, width,
height);
caps = gst_video_info_to_caps (&vinfo); caps = gst_video_info_to_caps (&vinfo);
/* set bpp, extra info for GRAY16 so elements can scale properly */ /* set bpp, extra info for GRAY16 so elements can scale properly */
@ -374,7 +374,7 @@ gst_edt_pdv_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
gst_structure_set_value (s, "bpp", &val); gst_structure_set_value (s, "bpp", &val);
g_value_unset (&val); g_value_unset (&val);
} else if (depth == 24) { } else if (depth == 24) {
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_RGB); gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_RGB, width, height);
caps = gst_video_info_to_caps (&vinfo); caps = gst_video_info_to_caps (&vinfo);
} else { } else {
GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE, GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE,

View File

@ -339,10 +339,8 @@ gst_idsueyesrc_set_caps_from_camera (GstIdsueyeSrc * src)
src->height = imageSize.s32Height; src->height = imageSize.s32Height;
gst_video_info_init (&vinfo); gst_video_info_init (&vinfo);
vinfo.width = src->width;
vinfo.height = src->height;
vinfo.finfo = gst_video_format_get_info (videoFormat); gst_video_info_set_format (&vinfo, videoFormat, src->width, src->height);
src->caps = gst_video_info_to_caps (&vinfo); src->caps = gst_video_info_to_caps (&vinfo);
if (videoFormat == GST_VIDEO_FORMAT_GRAY16_BE) { if (videoFormat == GST_VIDEO_FORMAT_GRAY16_BE) {

View File

@ -403,19 +403,20 @@ gst_framelinksrc_start (GstBaseSrc * bsrc)
} }
gst_video_info_init (&vinfo); gst_video_info_init (&vinfo);
vinfo.width = ci->Width;
vinfo.height = ci->Height;
ci->BitDepth = ci->BitDepth; ci->BitDepth = ci->BitDepth;
if (ci->BitDepth <= 8) { if (ci->BitDepth <= 8) {
GstVideoFormat format;
if (src->pixInfo.BayerPattern == 0) { if (src->pixInfo.BayerPattern == 0) {
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY8); format = GST_VIDEO_FORMAT_GRAY8;
} else if (src->pixInfo.BayerPattern == 1 || src->pixInfo.BayerPattern == 2) { } else if (src->pixInfo.BayerPattern == 1 || src->pixInfo.BayerPattern == 2) {
/* Bayer and TRUESENSE will be demosaiced by Imperx into BGRA */ /* Bayer and TRUESENSE will be demosaiced by Imperx into BGRA */
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_BGRA); format = GST_VIDEO_FORMAT_BGRA;
} }
gst_video_info_set_format (&vinfo, format, ci->Width, ci->Height);
src->caps = gst_video_info_to_caps (&vinfo); src->caps = gst_video_info_to_caps (&vinfo);
} else if (ci->BitDepth > 8 && ci->BitDepth <= 16) { } else if (ci->BitDepth > 8 && ci->BitDepth <= 16) {
GstVideoFormat format;
GValue val = G_VALUE_INIT; GValue val = G_VALUE_INIT;
GstStructure *s; GstStructure *s;
@ -425,10 +426,12 @@ gst_framelinksrc_start (GstBaseSrc * bsrc)
return FALSE; return FALSE;
} }
if (G_BYTE_ORDER == G_LITTLE_ENDIAN) if (G_BYTE_ORDER == G_LITTLE_ENDIAN) {
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_LE); format = GST_VIDEO_FORMAT_GRAY16_LE;
else if (G_BYTE_ORDER == G_BIG_ENDIAN) } else if (G_BYTE_ORDER == G_BIG_ENDIAN) {
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_BE); format = GST_VIDEO_FORMAT_GRAY16_BE;
}
gst_video_info_set_format (&vinfo, format, ci->Width, ci->Height);
src->caps = gst_video_info_to_caps (&vinfo); src->caps = gst_video_info_to_caps (&vinfo);
/* set bpp, extra info for GRAY16 so elements can scale properly */ /* set bpp, extra info for GRAY16 so elements can scale properly */
@ -438,7 +441,8 @@ gst_framelinksrc_start (GstBaseSrc * bsrc)
gst_structure_set_value (s, "bpp", &val); gst_structure_set_value (s, "bpp", &val);
g_value_unset (&val); g_value_unset (&val);
} else if (ci->BitDepth == 24) { } else if (ci->BitDepth == 24) {
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_BGRA); gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_BGRA, ci->Width,
ci->Height);
src->caps = gst_video_info_to_caps (&vinfo); src->caps = gst_video_info_to_caps (&vinfo);
} else { } else {
GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE, GST_ELEMENT_ERROR (src, STREAM, WRONG_TYPE,

View File

@ -544,7 +544,6 @@ gst_matroxsrc_start (GstBaseSrc * bsrc)
/* note that we abuse formats with Bayer */ /* note that we abuse formats with Bayer */
gst_video_info_set_format (&vinfo, src->video_format, width, height); gst_video_info_set_format (&vinfo, src->video_format, width, height);
vinfo.finfo = gst_video_format_get_info (src->video_format);
if (!src->caps) { if (!src->caps) {
src->caps = gst_video_info_to_caps (&vinfo); src->caps = gst_video_info_to_caps (&vinfo);

View File

@ -623,8 +623,9 @@ gst_niimaqsrc_get_cam_caps (GstNiImaqSrc * src)
GstCaps *gcaps = NULL; GstCaps *gcaps = NULL;
Int32 rval; Int32 rval;
uInt32 val; uInt32 val;
gint depth, bpp; gint width, height, depth, bpp;
GstVideoInfo vinfo; GstVideoInfo vinfo;
GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
if (!src->iid) { if (!src->iid) {
GST_ELEMENT_ERROR (src, RESOURCE, FAILED, GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
@ -643,10 +644,10 @@ gst_niimaqsrc_get_cam_caps (GstNiImaqSrc * src)
depth = val * 8; depth = val * 8;
rval &= imgGetAttribute (src->iid, IMG_ATTR_ROI_WIDTH, &val); rval &= imgGetAttribute (src->iid, IMG_ATTR_ROI_WIDTH, &val);
gst_niimaqsrc_report_imaq_error (rval); gst_niimaqsrc_report_imaq_error (rval);
vinfo.width = val; width = val;
rval &= imgGetAttribute (src->iid, IMG_ATTR_ROI_HEIGHT, &val); rval &= imgGetAttribute (src->iid, IMG_ATTR_ROI_HEIGHT, &val);
gst_niimaqsrc_report_imaq_error (rval); gst_niimaqsrc_report_imaq_error (rval);
vinfo.height = val; height = val;
if (rval) { if (rval) {
GST_ELEMENT_ERROR (src, STREAM, FAILED, GST_ELEMENT_ERROR (src, STREAM, FAILED,
@ -656,16 +657,18 @@ gst_niimaqsrc_get_cam_caps (GstNiImaqSrc * src)
} }
if (depth == 8) if (depth == 8)
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY8); format = GST_VIDEO_FORMAT_GRAY8;
else if (depth == 16) else if (depth == 16)
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_LE); format = GST_VIDEO_FORMAT_GRAY16_LE;
else if (depth == 32) else if (depth == 32)
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_BGRA); format = GST_VIDEO_FORMAT_BGRA;
else { else {
GST_ERROR_OBJECT (src, "Depth %d (%d-bit) not supported yet", depth, bpp); GST_ERROR_OBJECT (src, "Depth %d (%d-bit) not supported yet", depth, bpp);
goto error; goto error;
} }
gst_video_info_set_format (&vinfo, format, width, height);
vinfo.fps_n = 30; vinfo.fps_n = 30;
vinfo.fps_d = 1; vinfo.fps_d = 1;
/* hard code framerate and par as IMAQ doesn't tell us anything about it */ /* hard code framerate and par as IMAQ doesn't tell us anything about it */

View File

@ -683,10 +683,7 @@ gst_phoenixsrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
"framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL); "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL);
} }
} else if (videoFormat != GST_VIDEO_FORMAT_UNKNOWN) { } else if (videoFormat != GST_VIDEO_FORMAT_UNKNOWN) {
vinfo.finfo = gst_video_format_get_info (videoFormat); gst_video_info_set_format (&vinfo, videoFormat, width, height);
vinfo.width = width;
vinfo.height = height;
caps = gst_video_info_to_caps (&vinfo); caps = gst_video_info_to_caps (&vinfo);
if (is_gray16) { if (is_gray16) {

View File

@ -567,6 +567,7 @@ gst_pixcisrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
{ {
GstPixciSrc *src = GST_PIXCI_SRC (bsrc); GstPixciSrc *src = GST_PIXCI_SRC (bsrc);
GstCaps *caps; GstCaps *caps;
gint width, height;
if (!src->pixci_open) { if (!src->pixci_open) {
caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src)); caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src));
@ -578,8 +579,8 @@ gst_pixcisrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
/* Create video info */ /* Create video info */
gst_video_info_init (&vinfo); gst_video_info_init (&vinfo);
vinfo.width = pxd_imageXdim (); width = pxd_imageXdim ();
vinfo.height = pxd_imageYdim (); height = pxd_imageYdim ();
par = pxd_imageAspectRatio (); par = pxd_imageAspectRatio ();
if (par != 0) { if (par != 0) {
@ -591,17 +592,20 @@ gst_pixcisrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
components = pxd_imageCdim (); components = pxd_imageCdim ();
if (components == 1 && bits_per_component <= 8) { if (components == 1 && bits_per_component <= 8) {
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY8); gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY8, width, height);
caps = gst_video_info_to_caps (&vinfo); caps = gst_video_info_to_caps (&vinfo);
} else if (components == 1 && } else if (components == 1 &&
bits_per_component > 8 && bits_per_component <= 16) { bits_per_component > 8 && bits_per_component <= 16) {
GValue val = G_VALUE_INIT; GValue val = G_VALUE_INIT;
GstStructure *s; GstStructure *s;
if (G_BYTE_ORDER == G_LITTLE_ENDIAN) if (G_BYTE_ORDER == G_LITTLE_ENDIAN) {
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_LE); gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY16_LE, width,
else if (G_BYTE_ORDER == G_BIG_ENDIAN) height);
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_BE); } else if (G_BYTE_ORDER == G_BIG_ENDIAN) {
gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY16_BE, width,
height);
}
caps = gst_video_info_to_caps (&vinfo); caps = gst_video_info_to_caps (&vinfo);
/* set bpp, extra info for GRAY16 so elements can scale properly */ /* set bpp, extra info for GRAY16 so elements can scale properly */

View File

@ -645,9 +645,7 @@ gst_saperasrc_start (GstBaseSrc * bsrc)
} }
gst_video_info_init (&vinfo); gst_video_info_init (&vinfo);
vinfo.width = src->sap_buffers->GetWidth (); gst_video_info_set_format (&vinfo, gst_format, src->sap_buffers->GetWidth (), src->sap_buffers->GetHeight ());
vinfo.height = src->sap_buffers->GetHeight ();
vinfo.finfo = gst_video_format_get_info (gst_format);
src->caps = gst_video_info_to_caps (&vinfo); src->caps = gst_video_info_to_caps (&vinfo);
src->width = vinfo.width; src->width = vinfo.width;