Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3777982pxv; Mon, 19 Jul 2021 08:31:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKIP1BgHZn+pOoF6rDcRwnoHg8ij1gV7C88iTf+uas1NjWNPb2Lht6P5WaA0tPx7U7nBQw X-Received: by 2002:a05:6402:270d:: with SMTP id y13mr35389602edd.66.1626708686826; Mon, 19 Jul 2021 08:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626708686; cv=none; d=google.com; s=arc-20160816; b=KRHRYol0POElEWcizfhngRQUOwvXB5im/YmMOJ4ba13G1x+fBAHQPC9ZoHhElbBqM3 OzKx3o0LlHsuDyRw9l3nEB96WES70NTVNKoaxLG3pysrRfWwxx20V0UhCLKdlkYtbOuQ X9HCRY+CQjwrIEnDQVuAZs7SWTOSdi676vKO7ok3olHZ3MstZbVxBBaAkAYbpgHYaUWd 4A8+t2hlxAv+nYSANz0pa+cQ3f1AQOAcpoKf9OkqSHlVpxrRcv0GmOqr0ICEw9cmxY5n Jdro2eK/2/RnT7637jaYQsqy6CpH5JyL+ufniA6lTptKweTzGt/1oqA8amOdoFErQsb9 Pg9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IRVaDzzXUgoyGBsqxup0hMha+V0H4ydkMlaWsgxgo3Q=; b=jEZyBO5041w+5ZOZ+Wnz4OHD8Lh6b3NHLU+jrd5Mn/CPlHFPgfsZ9MaB3wj6eU182U +7AWgH1vhz94ngY+KY9eiehbh+3iQN4MKP6xeryZgo5b71yowo34FUUd74tltzXB8LZz eB0GnAcJosK6BHpbUwfk2lHFbNe9i2Hamn/DgCWLUCaBWX5gJb/tUZgwb2VzAsbwXbpU 8CCviaUzph7SRiUSA6ErG4ONUvHrAB1SKhEAXkJvgRCQkFxdU9hb1sDCaPGAoP2/viWW I1iNANS9STbLfzIL6qsoF+rseMQbxWPWKkmztDDA7Ar0VMTxi2ZjUFS3Zty9KugL/l3s G8AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RiF9dCcB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p25si21246360ejb.86.2021.07.19.08.31.04; Mon, 19 Jul 2021 08:31:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RiF9dCcB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245579AbhGSOrZ (ORCPT + 99 others); Mon, 19 Jul 2021 10:47:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:46038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245331AbhGSOcK (ORCPT ); Mon, 19 Jul 2021 10:32:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2A7306121F; Mon, 19 Jul 2021 15:12:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626707555; bh=V55OotZTM1O2aMmV9536ILQb5yI1FsYwaTgVcTdi8rk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RiF9dCcBWvKpIpXN7ebI+zzI/l6fjcuSmnTTDnrLN0fdVQaXASj/ShPrWUYa80Rve uNN8o3IA84zuAyiA4c4a91xXJ3rQOvioZIIGMymjK/SFIv65TIghA3/7x6x/DCOIl7 H3hJq5NAS8U1Z+6Z16TRSSsRVC9kkbz4QHNsjR7U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Benjamin Drung , Laurent Pinchart , Mauro Carvalho Chehab Subject: [PATCH 4.9 177/245] media: uvcvideo: Fix pixel format change for Elgato Cam Link 4K Date: Mon, 19 Jul 2021 16:51:59 +0200 Message-Id: <20210719144946.121113484@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.288257948@linuxfoundation.org> References: <20210719144940.288257948@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Benjamin Drung commit 4c6e0976295add7f0ed94d276c04a3d6f1ea8f83 upstream. The Elgato Cam Link 4K HDMI video capture card reports to support three different pixel formats, where the first format depends on the connected HDMI device. ``` $ v4l2-ctl -d /dev/video0 --list-formats-ext ioctl: VIDIOC_ENUM_FMT Type: Video Capture [0]: 'NV12' (Y/CbCr 4:2:0) Size: Discrete 3840x2160 Interval: Discrete 0.033s (29.970 fps) [1]: 'NV12' (Y/CbCr 4:2:0) Size: Discrete 3840x2160 Interval: Discrete 0.033s (29.970 fps) [2]: 'YU12' (Planar YUV 4:2:0) Size: Discrete 3840x2160 Interval: Discrete 0.033s (29.970 fps) ``` Changing the pixel format to anything besides the first pixel format does not work: ``` $ v4l2-ctl -d /dev/video0 --try-fmt-video pixelformat=YU12 Format Video Capture: Width/Height : 3840/2160 Pixel Format : 'NV12' (Y/CbCr 4:2:0) Field : None Bytes per Line : 3840 Size Image : 12441600 Colorspace : sRGB Transfer Function : Rec. 709 YCbCr/HSV Encoding: Rec. 709 Quantization : Default (maps to Limited Range) Flags : ``` User space applications like VLC might show an error message on the terminal in that case: ``` libv4l2: error set_fmt gave us a different result than try_fmt! ``` Depending on the error handling of the user space applications, they might display a distorted video, because they use the wrong pixel format for decoding the stream. The Elgato Cam Link 4K responds to the USB video probe VS_PROBE_CONTROL/VS_COMMIT_CONTROL with a malformed data structure: The second byte contains bFormatIndex (instead of being the second byte of bmHint). The first byte is always zero. The third byte is always 1. The firmware bug was reported to Elgato on 2020-12-01 and it was forwarded by the support team to the developers as feature request. There is no firmware update available since then. The latest firmware for Elgato Cam Link 4K as of 2021-03-23 has MCU 20.02.19 and FPGA 67. Therefore correct the malformed data structure for this device. The change was successfully tested with VLC, OBS, and Chromium using different pixel formats (YUYV, NV12, YU12), resolutions (3840x2160, 1920x1080), and frame rates (29.970 and 59.940 fps). Cc: stable@vger.kernel.org Signed-off-by: Benjamin Drung Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Greg Kroah-Hartman --- drivers/media/usb/uvc/uvc_video.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -89,10 +89,37 @@ int uvc_query_ctrl(struct uvc_device *de static void uvc_fixup_video_ctrl(struct uvc_streaming *stream, struct uvc_streaming_control *ctrl) { + static const struct usb_device_id elgato_cam_link_4k = { + USB_DEVICE(0x0fd9, 0x0066) + }; struct uvc_format *format = NULL; struct uvc_frame *frame = NULL; unsigned int i; + /* + * The response of the Elgato Cam Link 4K is incorrect: The second byte + * contains bFormatIndex (instead of being the second byte of bmHint). + * The first byte is always zero. The third byte is always 1. + * + * The UVC 1.5 class specification defines the first five bits in the + * bmHint bitfield. The remaining bits are reserved and should be zero. + * Therefore a valid bmHint will be less than 32. + * + * Latest Elgato Cam Link 4K firmware as of 2021-03-23 needs this fix. + * MCU: 20.02.19, FPGA: 67 + */ + if (usb_match_one_id(stream->dev->intf, &elgato_cam_link_4k) && + ctrl->bmHint > 255) { + u8 corrected_format_index = ctrl->bmHint >> 8; + + /* uvc_dbg(stream->dev, VIDEO, + "Correct USB video probe response from {bmHint: 0x%04x, bFormatIndex: %u} to {bmHint: 0x%04x, bFormatIndex: %u}\n", + ctrl->bmHint, ctrl->bFormatIndex, + 1, corrected_format_index); */ + ctrl->bmHint = 1; + ctrl->bFormatIndex = corrected_format_index; + } + for (i = 0; i < stream->nformats; ++i) { if (stream->format[i].index == ctrl->bFormatIndex) { format = &stream->format[i];