Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4159198pxv; Mon, 19 Jul 2021 18:49:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyoEPoTFIYNFzw0+AK1BHpvq6lXSh7UbYKa8mzHn3+PRCWjPjfmdseL2fCFiyLTzuflKeU X-Received: by 2002:a17:906:17c5:: with SMTP id u5mr30498942eje.326.1626745760538; Mon, 19 Jul 2021 18:49:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626745760; cv=none; d=google.com; s=arc-20160816; b=ADepLhGnRag2KgTFrppHoXhNSPKGeiG0fcF9UqYivDjLDrZb56QU42t/hp5TzoGEO9 6fTbIx+Bns1bz/rYO4UoqntCmZwlUJ5D4VD6ziZHjwkakh+qff24oLjxPm6ozILPYDa4 duPwlgKWXX6caME9IhWkZHgQ8BGVcUw26sAVsBLHRho+I538If4JptwoXs24FFpVHFCh lL8ucW1+TamPiHhygYft3CANGQDEL0eSQXJwTDHCpQ4JcphXfmldmJQTA1CO1s12Y0Ty YG83tTfClLVs3icE3wCbpVB+ttK/mle6pR5es+oyV7uNEQSCwJx4t3yt5rjEmI5BLW0I hUBA== 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=Xqlkt84e6bSdtCvvbupsHRulRNWFJ1vnrKUg9yaSbmGSYSMHmMKw/Zoz/my1ldxws/ f2R/5vHk6/4B8kYGwlU5xFa8fuSIicC0MZS3nL0ugDe/Z7KPatbLK+N1PFaUj6nneD8i N9uNilHb8SH7qsVgU0TZmXm8RyMGjjNJTUn7V9Jcy4nuItuXH3P44A76WmSy1Y/0MZI8 bFb3ztKoZllnplU5Yd0bFbQ7qkUrDuqyS4ChxDkww9vglnDPtqV4rcZbT368VOgxjRR/ TEaDu8rsZl76M5NErKfTMb7YNwvcp1cSoov5Htsg4zxV6Bup+4NWiGmfKJf6y0205Nut JsJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=STinYalF; 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 d5si21889528edv.70.2021.07.19.18.48.58; Mon, 19 Jul 2021 18:49:20 -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=STinYalF; 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 S1345434AbhGSPJV (ORCPT + 99 others); Mon, 19 Jul 2021 11:09:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:40440 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245139AbhGSOr3 (ORCPT ); Mon, 19 Jul 2021 10:47:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A5B6E61363; Mon, 19 Jul 2021 15:23:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626708217; bh=V55OotZTM1O2aMmV9536ILQb5yI1FsYwaTgVcTdi8rk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=STinYalFxUKg19BM2uICZ7r/lN37WeH6VrZ1tqHSx1hzo5lQDiNAcrhrMELZDRsPQ CqRmodaZ4V6RtvO0JL2sbNYcy73ZfNFMN5V3nkusfJw8iXNFfvtjBjjLlo67qWzmrS VYpHbyk3/WuGl/43hNlNAY1vjwIX/+1i7IEXtoPI= 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.14 227/315] media: uvcvideo: Fix pixel format change for Elgato Cam Link 4K Date: Mon, 19 Jul 2021 16:51:56 +0200 Message-Id: <20210719144950.890006757@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144942.861561397@linuxfoundation.org> References: <20210719144942.861561397@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];