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);
vinfo.width = width;
vinfo.height = height;
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);
} else if (bpp > 8 && bpp <= 16) {
GValue val = G_VALUE_INIT;
GstStructure *s;
if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_LE);
else if (G_BYTE_ORDER == G_BIG_ENDIAN)
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_BE);
if (G_BYTE_ORDER == G_LITTLE_ENDIAN) {
gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY16_LE, width,
height);
} 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);
/* 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)
{
GstEdtPdvSink *pdvsink = GST_EDT_PDV_SINK (basesink);
gint depth;
gint width, height, depth;
GstVideoFormat format;
GstVideoInfo vinfo;
@ -229,8 +229,8 @@ gst_edt_pdv_sink_get_caps (GstBaseSink * basesink, GstCaps * filter_caps)
}
gst_video_info_init (&vinfo);
vinfo.width = pdv_get_width (pdvsink->dev);
vinfo.height = pdv_get_height (pdvsink->dev);
width = pdv_get_width (pdvsink->dev);
height = pdv_get_height (pdvsink->dev);
depth = pdv_get_depth (pdvsink->dev);
switch (depth) {
@ -244,7 +244,7 @@ gst_edt_pdv_sink_get_caps (GstBaseSink * basesink, GstCaps * filter_caps)
default:
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 */
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) {
caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (src));
} else {
gint depth;
gint width, height, depth;
GstVideoInfo vinfo;
/* Create video info */
gst_video_info_init (&vinfo);
vinfo.width = pdv_get_width (src->dev);
vinfo.height = pdv_get_height (src->dev);
width = pdv_get_width (src->dev);
height = pdv_get_height (src->dev);
depth = pdv_get_depth (src->dev);
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);
} else if (depth <= 16) {
GValue val = G_VALUE_INIT;
GstStructure *s;
/* 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);
/* 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);
g_value_unset (&val);
} 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);
} else {
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;
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);
if (videoFormat == GST_VIDEO_FORMAT_GRAY16_BE) {

View File

@ -403,19 +403,20 @@ gst_framelinksrc_start (GstBaseSrc * bsrc)
}
gst_video_info_init (&vinfo);
vinfo.width = ci->Width;
vinfo.height = ci->Height;
ci->BitDepth = ci->BitDepth;
if (ci->BitDepth <= 8) {
GstVideoFormat format;
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) {
/* 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);
} else if (ci->BitDepth > 8 && ci->BitDepth <= 16) {
GstVideoFormat format;
GValue val = G_VALUE_INIT;
GstStructure *s;
@ -425,10 +426,12 @@ gst_framelinksrc_start (GstBaseSrc * bsrc)
return FALSE;
}
if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_LE);
else if (G_BYTE_ORDER == G_BIG_ENDIAN)
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_BE);
if (G_BYTE_ORDER == G_LITTLE_ENDIAN) {
format = GST_VIDEO_FORMAT_GRAY16_LE;
} else if (G_BYTE_ORDER == G_BIG_ENDIAN) {
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);
/* 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);
g_value_unset (&val);
} 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);
} else {
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 */
gst_video_info_set_format (&vinfo, src->video_format, width, height);
vinfo.finfo = gst_video_format_get_info (src->video_format);
if (!src->caps) {
src->caps = gst_video_info_to_caps (&vinfo);

View File

@ -623,8 +623,9 @@ gst_niimaqsrc_get_cam_caps (GstNiImaqSrc * src)
GstCaps *gcaps = NULL;
Int32 rval;
uInt32 val;
gint depth, bpp;
gint width, height, depth, bpp;
GstVideoInfo vinfo;
GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
if (!src->iid) {
GST_ELEMENT_ERROR (src, RESOURCE, FAILED,
@ -643,10 +644,10 @@ gst_niimaqsrc_get_cam_caps (GstNiImaqSrc * src)
depth = val * 8;
rval &= imgGetAttribute (src->iid, IMG_ATTR_ROI_WIDTH, &val);
gst_niimaqsrc_report_imaq_error (rval);
vinfo.width = val;
width = val;
rval &= imgGetAttribute (src->iid, IMG_ATTR_ROI_HEIGHT, &val);
gst_niimaqsrc_report_imaq_error (rval);
vinfo.height = val;
height = val;
if (rval) {
GST_ELEMENT_ERROR (src, STREAM, FAILED,
@ -656,16 +657,18 @@ gst_niimaqsrc_get_cam_caps (GstNiImaqSrc * src)
}
if (depth == 8)
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY8);
format = GST_VIDEO_FORMAT_GRAY8;
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)
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_BGRA);
format = GST_VIDEO_FORMAT_BGRA;
else {
GST_ERROR_OBJECT (src, "Depth %d (%d-bit) not supported yet", depth, bpp);
goto error;
}
gst_video_info_set_format (&vinfo, format, width, height);
vinfo.fps_n = 30;
vinfo.fps_d = 1;
/* 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);
}
} else if (videoFormat != GST_VIDEO_FORMAT_UNKNOWN) {
vinfo.finfo = gst_video_format_get_info (videoFormat);
vinfo.width = width;
vinfo.height = height;
gst_video_info_set_format (&vinfo, videoFormat, width, height);
caps = gst_video_info_to_caps (&vinfo);
if (is_gray16) {

View File

@ -567,6 +567,7 @@ gst_pixcisrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
{
GstPixciSrc *src = GST_PIXCI_SRC (bsrc);
GstCaps *caps;
gint width, height;
if (!src->pixci_open) {
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 */
gst_video_info_init (&vinfo);
vinfo.width = pxd_imageXdim ();
vinfo.height = pxd_imageYdim ();
width = pxd_imageXdim ();
height = pxd_imageYdim ();
par = pxd_imageAspectRatio ();
if (par != 0) {
@ -591,17 +592,20 @@ gst_pixcisrc_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
components = pxd_imageCdim ();
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);
} else if (components == 1 &&
bits_per_component > 8 && bits_per_component <= 16) {
GValue val = G_VALUE_INIT;
GstStructure *s;
if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_LE);
else if (G_BYTE_ORDER == G_BIG_ENDIAN)
vinfo.finfo = gst_video_format_get_info (GST_VIDEO_FORMAT_GRAY16_BE);
if (G_BYTE_ORDER == G_LITTLE_ENDIAN) {
gst_video_info_set_format (&vinfo, GST_VIDEO_FORMAT_GRAY16_LE, width,
height);
} 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);
/* 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);
vinfo.width = src->sap_buffers->GetWidth ();
vinfo.height = src->sap_buffers->GetHeight ();
vinfo.finfo = gst_video_format_get_info (gst_format);
gst_video_info_set_format (&vinfo, gst_format, src->sap_buffers->GetWidth (), src->sap_buffers->GetHeight ());
src->caps = gst_video_info_to_caps (&vinfo);
src->width = vinfo.width;