From e4a308a5451e418c9e885874382e34117cfbe50d Mon Sep 17 00:00:00 2001 From: "Joshua M. Doe" Date: Thu, 16 Nov 2017 08:27:08 -0500 Subject: [PATCH] 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. --- sys/bitflow/gstbitflowsrc.c | 15 ++++++++------- sys/edt/gstedtpdvsink.c | 8 ++++---- sys/edt/gstedtpdvsrc.c | 14 +++++++------- sys/idsueye/gstidsueyesrc.c | 4 +--- sys/imperx/gstframelinksrc.c | 22 +++++++++++++--------- sys/matrox/gstmatroxsrc.c | 1 - sys/niimaq/gstniimaq.c | 15 +++++++++------ sys/phoenix/gstphoenixsrc.c | 5 +---- sys/pixci/gstpixcisrc.c | 18 +++++++++++------- sys/sapera/gstsaperasrc.cpp | 4 +--- 10 files changed, 55 insertions(+), 51 deletions(-) diff --git a/sys/bitflow/gstbitflowsrc.c b/sys/bitflow/gstbitflowsrc.c index 9ff6981..b0efb8e 100644 --- a/sys/bitflow/gstbitflowsrc.c +++ b/sys/bitflow/gstbitflowsrc.c @@ -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 */ diff --git a/sys/edt/gstedtpdvsink.c b/sys/edt/gstedtpdvsink.c index 682454e..0c46edf 100644 --- a/sys/edt/gstedtpdvsink.c +++ b/sys/edt/gstedtpdvsink.c @@ -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); diff --git a/sys/edt/gstedtpdvsrc.c b/sys/edt/gstedtpdvsrc.c index 2bee32f..7d7f5b6 100644 --- a/sys/edt/gstedtpdvsrc.c +++ b/sys/edt/gstedtpdvsrc.c @@ -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, diff --git a/sys/idsueye/gstidsueyesrc.c b/sys/idsueye/gstidsueyesrc.c index 2e08358..9ad165a 100644 --- a/sys/idsueye/gstidsueyesrc.c +++ b/sys/idsueye/gstidsueyesrc.c @@ -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) { diff --git a/sys/imperx/gstframelinksrc.c b/sys/imperx/gstframelinksrc.c index dfab9ce..f6d6810 100644 --- a/sys/imperx/gstframelinksrc.c +++ b/sys/imperx/gstframelinksrc.c @@ -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, diff --git a/sys/matrox/gstmatroxsrc.c b/sys/matrox/gstmatroxsrc.c index 1ccde33..5ee0898 100644 --- a/sys/matrox/gstmatroxsrc.c +++ b/sys/matrox/gstmatroxsrc.c @@ -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); diff --git a/sys/niimaq/gstniimaq.c b/sys/niimaq/gstniimaq.c index b23f189..3570233 100644 --- a/sys/niimaq/gstniimaq.c +++ b/sys/niimaq/gstniimaq.c @@ -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 */ diff --git a/sys/phoenix/gstphoenixsrc.c b/sys/phoenix/gstphoenixsrc.c index 5614fbf..bec184e 100644 --- a/sys/phoenix/gstphoenixsrc.c +++ b/sys/phoenix/gstphoenixsrc.c @@ -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) { diff --git a/sys/pixci/gstpixcisrc.c b/sys/pixci/gstpixcisrc.c index c5f8008..b93cdd1 100644 --- a/sys/pixci/gstpixcisrc.c +++ b/sys/pixci/gstpixcisrc.c @@ -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 */ diff --git a/sys/sapera/gstsaperasrc.cpp b/sys/sapera/gstsaperasrc.cpp index 2046088..a20cb96 100644 --- a/sys/sapera/gstsaperasrc.cpp +++ b/sys/sapera/gstsaperasrc.cpp @@ -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;