v4l2object: Workaround bad TRY_FMT colorimetry implementation

libv4l2 reset the colorpace to 0 and does not do any request to the
driver. This yields an invalid colorspace which currently cause a
negotiation failure. This workaround by ignoring bad values during the
TRY_FMT step.
This commit is contained in:
Nicolas Dufresne 2019-11-18 13:27:42 -05:00 committed by Nicolas Dufresne
parent a6e28ca268
commit 23089e9cc3

View file

@ -3291,6 +3291,7 @@ gst_v4l2_object_set_format_full (GstV4l2Object * v4l2object, GstCaps * caps,
enum v4l2_ycbcr_encoding matrix = 0;
enum v4l2_xfer_func transfer = 0;
GstStructure *s;
gboolean disable_colorimetry = FALSE;
g_return_val_if_fail (!v4l2object->skip_try_fmt_probes ||
gst_caps_is_writable (caps), FALSE);
@ -3623,17 +3624,24 @@ gst_v4l2_object_set_format_full (GstV4l2Object * v4l2object, GstCaps * caps,
goto invalid_field;
}
gst_v4l2_object_get_colorspace (&format, &info.colorimetry);
if (gst_structure_has_field (s, "colorimetry")) {
if (!gst_v4l2_video_colorimetry_matches (&info.colorimetry,
gst_structure_get_string (s, "colorimetry")))
goto invalid_colorimetry;
if (gst_v4l2_object_get_colorspace (&format, &info.colorimetry)) {
if (gst_structure_has_field (s, "colorimetry")) {
if (!gst_v4l2_video_colorimetry_matches (&info.colorimetry,
gst_structure_get_string (s, "colorimetry")))
goto invalid_colorimetry;
}
} else {
/* The driver (or libv4l2) is miss-behaving, just ignore colorimetry from
* the TRY_FMT */
disable_colorimetry = TRUE;
if (gst_structure_has_field (s, "colorimetry"))
gst_structure_remove_field (s, "colorimetry");
}
/* In case we have skipped the try_fmt probes, we'll need to set the
* colorimetry and interlace-mode back into the caps. */
if (v4l2object->skip_try_fmt_probes) {
if (!gst_structure_has_field (s, "colorimetry")) {
if (!disable_colorimetry && !gst_structure_has_field (s, "colorimetry")) {
gchar *str = gst_video_colorimetry_to_string (&info.colorimetry);
gst_structure_set (s, "colorimetry", G_TYPE_STRING, str, NULL);
g_free (str);