Message ID | 20220920-resend-hwtimestamp-v2-3-0d7978a817cc@chromium.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp972977wrr; Fri, 2 Dec 2022 09:08:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf5d2OC4aDMbA+ogGL1/kSkI6EZPcL8ip3zC2r85DXnPD+nWHeSda1mXfqOslqjdz8igCr1O X-Received: by 2002:aa7:820e:0:b0:573:ab15:1d6f with SMTP id k14-20020aa7820e000000b00573ab151d6fmr59449965pfi.9.1670000933177; Fri, 02 Dec 2022 09:08:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670000933; cv=none; d=google.com; s=arc-20160816; b=Hq/Xx5D/V0IroDdqNw/HAy1yG9Cz5vEIhPBl8reZgm2jANWGSeHL4vzM6ob3jWuAnf TIQBNtK+vmBztwugb+WsxIC+KhYMP/vYmXgaqfmU83uJmR5045bCe6giAjlDO6FS/zYE 0UBl8Gt8sYukPDs7RBJ14ttuFKlh1R++t8jwIXUGZJ1nUCILb+H9QR7X6Z9MAXQP1r1J wM6eIwQQy3mJBpk1TxMj64nGWYwkWPGLg+1T1t4IU7cQFzgr3XEBKhcpbs3Y0zB+3vHi JfQNU3JCc56YrvlsU570Xosh5KgOyhx8zYNHQzfI8trA1lHeT7QosECo+XveNRqFQg40 ZGhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=z1b0nTFpIaI5p5ZE8W0YvdyyzRVBuMuYrq9RTuFJCfc=; b=zjZ0UA8ZM6yi9mvLJ+nH6Xg3aQjuf6gEHUD7ojkKyY7OitDq6WBjvGgAjMZTxOv4JF zf0U3mIcIyzgLrE7uj+4VvOWbD2NLw3qtBRuH6NdkPcSzYZ3UdOvyZCh4GG67N7YBsea t0NyiIs+RpzidmWXG6E7jsjeaUUxMky60u7XSfG7kWuPBMtIosug7SAkJNEwc5IBHqTT QyweY6D12kM2toUCO3X1A+GAvs5A+wEHHL2FZUDqjDaqbacoSWjqZG+35rOdeL3eHjQJ JZQbrwqHePGNjbT7tBkch1WNMsXcEFT3scDPVWhmY3ox0GBbGEil+LeidfPFByfibgld harw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OUpjWGMv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k29-20020a634b5d000000b004786a8301c3si7077232pgl.586.2022.12.02.09.08.37; Fri, 02 Dec 2022 09:08:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OUpjWGMv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234324AbiLBRDh (ORCPT <rfc822;lhua1029@gmail.com> + 99 others); Fri, 2 Dec 2022 12:03:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234252AbiLBRDE (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 2 Dec 2022 12:03:04 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C91002E9 for <linux-kernel@vger.kernel.org>; Fri, 2 Dec 2022 09:03:02 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id z20so7212743edc.13 for <linux-kernel@vger.kernel.org>; Fri, 02 Dec 2022 09:03:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=z1b0nTFpIaI5p5ZE8W0YvdyyzRVBuMuYrq9RTuFJCfc=; b=OUpjWGMvZnDcLn43zLuHuWVOV3ISdEtKowFcHWm0+5fGSDDSl/v63vR/WAh0TSM7eS Qeusd0VExamLNokTueTAxfUiw2NKAtZUKgbHuVONqUIyh1fx5iNlQaSVwoWbddgN/+mW 6ejuJt/TpHkPeV9fc5sGn6ZRggfSgT700uAvw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z1b0nTFpIaI5p5ZE8W0YvdyyzRVBuMuYrq9RTuFJCfc=; b=vAiJ5m/82yuu97N2+vRGW1EM4XjnPPn9EjLufQeNpCpKzOVRCUCAkr5vpvXd6OkHPZ zUP0egPNfe4K65uxvleNQWjn5i42o6AXUgkzXbPa/dVN8kocfDpy6Xw6euPWpFGGtEEi uygEEcIwy2z5qbDcS+zYjWqt9l462gzrmgrBGeNQz96OcQ47KhBs0Z1TBWjRr/WwH2d+ UjQffUxtKfnhIOuAQMO3I5fnxRUt8dEoqOKbO7SvORr7lapHJfRdyZ1MTCErOzkNOGGR xl0ZtdwTid2m6OSx8GxQsM9y1ktW9+XfK4gQuAe4IQ9/Zy2ypzZRJCy7AMMSXeBB9kKs St3A== X-Gm-Message-State: ANoB5pnIxdoL17o9GQhl6KujnYyg4nTRZzEeetHNHrsdLJ0PrCtN5BTS QAsiPZ6VbTC3lIIdPhCaXeE4IQ== X-Received: by 2002:aa7:c78b:0:b0:467:97e4:6339 with SMTP id n11-20020aa7c78b000000b0046797e46339mr64809687eds.381.1670000582204; Fri, 02 Dec 2022 09:03:02 -0800 (PST) Received: from alco.roam.corp.google.com (80.71.134.83.ipv4.parknet.dk. [80.71.134.83]) by smtp.gmail.com with ESMTPSA id sa22-20020a170906edb600b0073d7ab84375sm3249133ejb.92.2022.12.02.09.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 09:03:01 -0800 (PST) From: Ricardo Ribalda <ribalda@chromium.org> Date: Fri, 02 Dec 2022 18:02:43 +0100 Subject: [PATCH RESEND v2 3/8] media: uvc: Create UVC_QUIRK_IGNORE_EMPTY_TS quirk MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20220920-resend-hwtimestamp-v2-3-0d7978a817cc@chromium.org> References: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v2-0-0d7978a817cc@chromium.org> To: Mauro Carvalho Chehab <mchehab@kernel.org>, Laurent Pinchart <laurent.pinchart@ideasonboard.com> Cc: "hn.chen" <hn.chen@sunplusit.com>, linux-media@vger.kernel.org, Ricardo Ribalda <ribalda@chromium.org>, linux-kernel@vger.kernel.org X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=3835; i=ribalda@chromium.org; h=from:subject:message-id; bh=ThukGURKifBgx985aH8p0USOirI+IB7ilvRGG3W5Mrw=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjii+5H1M58hm5+Na5JGlt2ZCvH5eHmrmhoH7sSZGE ZrQBkNyJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY4ovuQAKCRDRN9E+zzrEiNx8D/ 9EncS+zAdR3hdqeACRDHKENTwfJGH6NYLWeUbbnK+NyO0eNPxeX7yBx0x1KM4Ytj3mAI3Ie83n0SjU mQdL01nH1MVySAJ7UQ1Kqf8xFW32/0aaV0pRJdG4X2ehFAbtypKorgCbTd5+jht2oMZPXWF1QIU62q 79UHEHPYu0s5RSQHWGyoxQhAAFJRgX1/dCwRGHkgWspTIHnTkiy1gn21lAST2dhAchbmOBHtXTu0jM kQwbeQTBGKIQ238AkqAB+EVwqsTsj1K9IMK1o4Lnncxl+asbwHQR8dAuJVS93VkV6CLGAb2pjwUHO6 jMMzTz8knQDV57+TBY6CO8uElX7NoMXl8aKDR6fyBcRpO8FOwIQd6pQ6haBNzT4ubVGRtqeSGt3rJq 36z0wkNDQfpc3MDhnrNPkpC6D+/WO2wvCaa2DNo6v1AEHSvR9+H4gMLfjlIvMCx0amMC5ijK54cbpS 1KDy6Dpyx43o7JR+FIs5s50T8hYD6BOHsz/MVRK0KIs3gVzEWg8ZPsVCnl3phLPWHIb5R73VZ79YqY cTHXWzmnqv/n0UhiqFB2MXrgGahp1yveVgWeRE1dOUphjh9z6ygw6FOk85ImeL167C2EAN/BzL6mPk 12eAnO2y9xgOWUlzq1p9itZUg/oad21SP6Ov1SXVr0gh4iHgcvNmnBnYEOEQ== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751122898536282988?= X-GMAIL-MSGID: =?utf-8?q?1751122898536282988?= |
Series |
uvcvideo: Fixes for hw timestamping
|
|
Commit Message
Ricardo Ribalda
Dec. 2, 2022, 5:02 p.m. UTC
Some Sunplus cameras took a borderline interpretation of the UVC 1.5 standard, and fill the PTS and SCR fields with invalid data if the package does not contain data. "STC must be captured when the first video data of a video frame is put on the USB bus." Eg: buffer: 0xa7755c00 len 000012 header:0x8c stc 00000000 sof 0000 pts 00000000 buffer: 0xa7755c00 len 000012 header:0x8c stc 00000000 sof 0000 pts 00000000 buffer: 0xa7755c00 len 000668 header:0x8c stc 73779dba sof 070c pts 7376d37a This borderline/buggy interpretation has been implemented in a variety of devices, from directly Sunplus and from other OEMs that rebrand Sunplus products. Luckily we can identify the affected modules by looking at the guid of one of the extension units: VideoControl Interface Descriptor: guidExtensionCode {82066163-7050-ab49-b8cc-b3855e8d221d} This patch adds a new quirk to take care of this. Complete lsusb of one of the affected cameras: Bus 001 Device 003: ID 1bcf:2a01 Sunplus Innovation Technology Inc. Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.01 bDeviceClass 239 Miscellaneous Device bDeviceSubClass 2 ? bDeviceProtocol 1 Interface Association bMaxPacketSize0 64 idVendor 0x1bcf Sunplus Innovation Technology Inc. idProduct 0x2a01 bcdDevice 0.02 iManufacturer 1 SunplusIT Inc iProduct 2 HanChen Wise Camera iSerial 3 01.00.00 bNumConfigurations 1 Tested-by: HungNien Chen <hn.chen@sunplusit.com> Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> --- drivers/media/usb/uvc/uvc_driver.c | 11 +++++++++++ drivers/media/usb/uvc/uvc_video.c | 8 ++++++++ drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 20 insertions(+)
Comments
Hi Ricardo, Thank you for the patch. On Fri, Dec 02, 2022 at 06:02:43PM +0100, Ricardo Ribalda wrote: > Some Sunplus cameras took a borderline interpretation of the UVC 1.5 > standard, and fill the PTS and SCR fields with invalid data if the > package does not contain data. > > "STC must be captured when the first video data of a video frame is put > on the USB bus." > > Eg: > > buffer: 0xa7755c00 len 000012 header:0x8c stc 00000000 sof 0000 pts 00000000 > buffer: 0xa7755c00 len 000012 header:0x8c stc 00000000 sof 0000 pts 00000000 > buffer: 0xa7755c00 len 000668 header:0x8c stc 73779dba sof 070c pts 7376d37a > > This borderline/buggy interpretation has been implemented in a variety > of devices, from directly Sunplus and from other OEMs that rebrand > Sunplus products. > > Luckily we can identify the affected modules by looking at the guid of > one of the extension units: > > VideoControl Interface Descriptor: > guidExtensionCode {82066163-7050-ab49-b8cc-b3855e8d221d} > > This patch adds a new quirk to take care of this. > > Complete lsusb of one of the affected cameras: That's not complete (but that's fine from a commit message point of view, the full descriptors would be too long). Can you share the full descriptors for all the devices you know are affected by this ? > Bus 001 Device 003: ID 1bcf:2a01 Sunplus Innovation Technology Inc. > Device Descriptor: > bLength 18 > bDescriptorType 1 > bcdUSB 2.01 > bDeviceClass 239 Miscellaneous Device > bDeviceSubClass 2 ? > bDeviceProtocol 1 Interface Association > bMaxPacketSize0 64 > idVendor 0x1bcf Sunplus Innovation Technology Inc. > idProduct 0x2a01 > bcdDevice 0.02 > iManufacturer 1 SunplusIT Inc > iProduct 2 HanChen Wise Camera > iSerial 3 01.00.00 > bNumConfigurations 1 > > Tested-by: HungNien Chen <hn.chen@sunplusit.com> > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> > --- > drivers/media/usb/uvc/uvc_driver.c | 11 +++++++++++ > drivers/media/usb/uvc/uvc_video.c | 8 ++++++++ > drivers/media/usb/uvc/uvcvideo.h | 1 + > 3 files changed, 20 insertions(+) > > diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c > index c63ecfd4617d..80ef0f0e04b0 100644 > --- a/drivers/media/usb/uvc/uvc_driver.c > +++ b/drivers/media/usb/uvc/uvc_driver.c > @@ -1497,6 +1497,17 @@ static const struct uvc_entity_quirk { > u8 guid[16]; > u32 quirks; > } uvc_entity_quirk[] = { > + /* > + * Some SunPlus uvc 1.5 device firmware expects that packages with s/uvc/UVC/ > + * no frame data are ignored by the host. If it's two paragraphs, you need a blank line in-between. If it's a single paragraph, you must not add a line break. > + * Therefore it does not clear the PTS/SCR bits in the header, and > + * breaks the timestamp decode algorithm. > + */ > + { > + .guid = {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, > + 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1d}, > + .quirks = UVC_QUIRK_IGNORE_EMPTY_TS, > + }, > }; > > static void uvc_entity_quirks(struct uvc_device *dev) > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c > index ab56e65ca324..a5b184e71ad7 100644 > --- a/drivers/media/usb/uvc/uvc_video.c > +++ b/drivers/media/usb/uvc/uvc_video.c > @@ -500,6 +500,14 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, > if (len < header_size) > return; > > + /* > + * Ignore the hardware timestamp on frames with no data on > + * miss-behaving devices. > + */ Could you please expand this comment to explain the issue ? Having to use git blame and read the commit message to understand why the check is here isn't very convenient. > + if (stream->dev->quirks & UVC_QUIRK_IGNORE_EMPTY_TS && > + len == header_size) > + return; > + > /* > * Extract the timestamps: > * > diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h > index 24c911aeebce..f395b67fe95a 100644 > --- a/drivers/media/usb/uvc/uvcvideo.h > +++ b/drivers/media/usb/uvc/uvcvideo.h > @@ -212,6 +212,7 @@ > #define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400 > #define UVC_QUIRK_FORCE_Y8 0x00000800 > #define UVC_QUIRK_FORCE_BPP 0x00001000 > +#define UVC_QUIRK_IGNORE_EMPTY_TS 0x00002000 > > /* Format flags */ > #define UVC_FMT_FLAG_COMPRESSED 0x00000001 >
Hi Laurent This is from the one that I have access to. Maybe hn.chen (on copy) can give you a bigger list. Thanks! Bus 001 Device 003: ID 1bcf:2a01 Sunplus Innovation Technology Inc. Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.01 bDeviceClass 239 Miscellaneous Device bDeviceSubClass 2 ? bDeviceProtocol 1 Interface Association bMaxPacketSize0 64 idVendor 0x1bcf Sunplus Innovation Technology Inc. idProduct 0x2a01 bcdDevice 0.02 iManufacturer 1 SunplusIT Inc iProduct 2 HanChen Wise Camera iSerial 3 01.00.00 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 935 bNumInterfaces 4 bConfigurationValue 1 iConfiguration 0 bmAttributes 0x80 (Bus Powered) MaxPower 500mA Interface Association: bLength 8 bDescriptorType 11 bFirstInterface 0 bInterfaceCount 2 bFunctionClass 14 Video bFunctionSubClass 3 Video Interface Collection bFunctionProtocol 0 iFunction 4 HanChen Wise Camera Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 1 Video Control bInterfaceProtocol 1 iInterface 4 HanChen Wise Camera VideoControl Interface Descriptor: bLength 13 bDescriptorType 36 bDescriptorSubtype 1 (HEADER) bcdUVC 1.50 wTotalLength 111 dwClockFrequency 48.000000MHz bInCollection 1 baInterfaceNr( 0) 1 VideoControl Interface Descriptor: bLength 18 bDescriptorType 36 bDescriptorSubtype 2 (INPUT_TERMINAL) bTerminalID 1 wTerminalType 0x0201 Camera Sensor bAssocTerminal 0 iTerminal 0 wObjectiveFocalLengthMin 0 wObjectiveFocalLengthMax 0 wOcularFocalLength 0 bControlSize 3 bmControls 0x0030000e Auto-Exposure Mode Auto-Exposure Priority Exposure Time (Absolute) VideoControl Interface Descriptor: bLength 13 bDescriptorType 36 bDescriptorSubtype 5 (PROCESSING_UNIT) bUnitID 2 bSourceID 1 wMaxMultiplier 16384 bControlSize 3 bmControls 0x0000157f Brightness Contrast Hue Saturation Sharpness Gamma White Balance Temperature Backlight Compensation Power Line Frequency White Balance Temperature, Auto iProcessing 0 bmVideoStandards 0x 0 VideoControl Interface Descriptor: bLength 29 bDescriptorType 36 bDescriptorSubtype 6 (EXTENSION_UNIT) bUnitID 3 guidExtensionCode {0fb885c3-68c2-4547-90f7-8f47579d95fc} bNumControl 5 bNrPins 1 baSourceID( 0) 2 bControlSize 4 bmControls( 0) 0x1f bmControls( 1) 0x00 bmControls( 2) 0x00 bmControls( 3) 0x00 iExtension 0 VideoControl Interface Descriptor: bLength 29 bDescriptorType 36 bDescriptorSubtype 6 (EXTENSION_UNIT) bUnitID 4 guidExtensionCode {63610682-5070-49ab-b8cc-b3855e8d221d} bNumControl 20 bNrPins 1 baSourceID( 0) 3 bControlSize 4 bmControls( 0) 0xff bmControls( 1) 0xff bmControls( 2) 0x71 bmControls( 3) 0x00 iExtension 0 VideoControl Interface Descriptor: bLength 9 bDescriptorType 36 bDescriptorSubtype 3 (OUTPUT_TERMINAL) bTerminalID 5 wTerminalType 0x0101 USB Streaming bAssocTerminal 0 bSourceID 4 iTerminal 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x87 EP 7 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0010 1x 16 bytes bInterval 8 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 0 bNumEndpoints 0 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 1 iInterface 0 VideoStreaming Interface Descriptor: bLength 15 bDescriptorType 36 bDescriptorSubtype 1 (INPUT_HEADER) bNumFormats 2 wTotalLength 335 bEndPointAddress 129 bmInfo 0 bTerminalLink 5 bStillCaptureMethod 1 bTriggerSupport 0 bTriggerUsage 0 bControlSize 1 bmaControls( 0) 11 bmaControls( 1) 11 VideoStreaming Interface Descriptor: bLength 11 bDescriptorType 36 bDescriptorSubtype 6 (FORMAT_MJPEG) bFormatIndex 1 bNumFrameDescriptors 7 bFlags 1 Fixed-size samples: Yes bDefaultFrameIndex 1 bAspectRatioX 0 bAspectRatioY 0 bmInterlaceFlags 0x00 Interlaced stream or variable: No Fields per frame: 1 fields Field 1 first: No Field pattern: Field 1 only bCopyProtect 0 VideoStreaming Interface Descriptor: bLength 30 bDescriptorType 36 bDescriptorSubtype 7 (FRAME_MJPEG) bFrameIndex 1 bmCapabilities 0x01 Still image supported wWidth 1920 wHeight 1080 dwMinBitRate 995328000 dwMaxBitRate 995328000 dwMaxVideoFrameBufferSize 4147200 dwDefaultFrameInterval 333333 bFrameIntervalType 1 dwFrameInterval( 0) 333333 VideoStreaming Interface Descriptor: bLength 30 bDescriptorType 36 bDescriptorSubtype 7 (FRAME_MJPEG) bFrameIndex 2 bmCapabilities 0x01 Still image supported wWidth 1280 wHeight 720 dwMinBitRate 442368000 dwMaxBitRate 442368000 dwMaxVideoFrameBufferSize 1843200 dwDefaultFrameInterval 333333 bFrameIntervalType 1 dwFrameInterval( 0) 333333 VideoStreaming Interface Descriptor: bLength 30 bDescriptorType 36 bDescriptorSubtype 7 (FRAME_MJPEG) bFrameIndex 3 bmCapabilities 0x01 Still image supported wWidth 640 wHeight 480 dwMinBitRate 147456000 dwMaxBitRate 147456000 dwMaxVideoFrameBufferSize 614400 dwDefaultFrameInterval 333333 bFrameIntervalType 1 dwFrameInterval( 0) 333333 VideoStreaming Interface Descriptor: bLength 30 bDescriptorType 36 bDescriptorSubtype 7 (FRAME_MJPEG) bFrameIndex 4 bmCapabilities 0x01 Still image supported wWidth 640 wHeight 360 dwMinBitRate 110592000 dwMaxBitRate 110592000 dwMaxVideoFrameBufferSize 460800 dwDefaultFrameInterval 333333 bFrameIntervalType 1 dwFrameInterval( 0) 333333 VideoStreaming Interface Descriptor: bLength 30 bDescriptorType 36 bDescriptorSubtype 7 (FRAME_MJPEG) bFrameIndex 5 bmCapabilities 0x01 Still image supported wWidth 352 wHeight 288 dwMinBitRate 48660480 dwMaxBitRate 48660480 dwMaxVideoFrameBufferSize 202752 dwDefaultFrameInterval 333333 bFrameIntervalType 1 dwFrameInterval( 0) 333333 VideoStreaming Interface Descriptor: bLength 30 bDescriptorType 36 bDescriptorSubtype 7 (FRAME_MJPEG) bFrameIndex 6 bmCapabilities 0x01 Still image supported wWidth 320 wHeight 240 dwMinBitRate 36864000 dwMaxBitRate 36864000 dwMaxVideoFrameBufferSize 153600 dwDefaultFrameInterval 333333 bFrameIntervalType 1 dwFrameInterval( 0) 333333 VideoStreaming Interface Descriptor: bLength 30 bDescriptorType 36 bDescriptorSubtype 7 (FRAME_MJPEG) bFrameIndex 7 bmCapabilities 0x01 Still image supported wWidth 176 wHeight 144 dwMinBitRate 12165120 dwMaxBitRate 12165120 dwMaxVideoFrameBufferSize 50688 dwDefaultFrameInterval 333333 bFrameIntervalType 1 dwFrameInterval( 0) 333333 VideoStreaming Interface Descriptor: bLength 6 bDescriptorType 36 bDescriptorSubtype 13 (COLORFORMAT) bColorPrimaries 1 (BT.709,sRGB) bTransferCharacteristics 1 (BT.709) bMatrixCoefficients 4 (SMPTE 170M (BT.601)) VideoStreaming Interface Descriptor: bLength 27 bDescriptorType 36 bDescriptorSubtype 4 (FORMAT_UNCOMPRESSED) bFormatIndex 2 bNumFrameDescriptors 2 guidFormat {32595559-0000-0010-8000-00aa00389b71} bBitsPerPixel 16 bDefaultFrameIndex 1 bAspectRatioX 0 bAspectRatioY 0 bmInterlaceFlags 0x00 Interlaced stream or variable: No Fields per frame: 2 fields Field 1 first: No Field pattern: Field 1 only bCopyProtect 0 VideoStreaming Interface Descriptor: bLength 30 bDescriptorType 36 bDescriptorSubtype 5 (FRAME_UNCOMPRESSED) bFrameIndex 1 bmCapabilities 0x01 Still image supported wWidth 640 wHeight 480 dwMinBitRate 147456000 dwMaxBitRate 147456000 dwMaxVideoFrameBufferSize 614400 dwDefaultFrameInterval 333333 bFrameIntervalType 1 dwFrameInterval( 0) 333333 VideoStreaming Interface Descriptor: bLength 30 bDescriptorType 36 bDescriptorSubtype 5 (FRAME_UNCOMPRESSED) bFrameIndex 2 bmCapabilities 0x01 Still image supported wWidth 640 wHeight 360 dwMinBitRate 110592000 dwMaxBitRate 110592000 dwMaxVideoFrameBufferSize 460800 dwDefaultFrameInterval 333333 bFrameIntervalType 1 dwFrameInterval( 0) 333333 VideoStreaming Interface Descriptor: bLength 6 bDescriptorType 36 bDescriptorSubtype 13 (COLORFORMAT) bColorPrimaries 1 (BT.709,sRGB) bTransferCharacteristics 1 (BT.709) bMatrixCoefficients 4 (SMPTE 170M (BT.601)) Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 1 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x00c0 1x 192 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 2 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0180 1x 384 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 3 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0200 1x 512 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 4 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0280 1x 640 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 5 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0320 1x 800 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 6 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x03b0 1x 944 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 7 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0a80 2x 640 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 8 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0b20 2x 800 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 9 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0be0 2x 992 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 10 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x13c0 3x 960 bytes bInterval 1 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 11 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x13fc 3x 1020 bytes bInterval 1 Interface Association: bLength 8 bDescriptorType 11 bFirstInterface 2 bInterfaceCount 2 bFunctionClass 14 Video bFunctionSubClass 3 Video Interface Collection bFunctionProtocol 0 iFunction 11 HanChen IR Camera Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 2 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 1 Video Control bInterfaceProtocol 1 iInterface 11 HanChen IR Camera VideoControl Interface Descriptor: bLength 13 bDescriptorType 36 bDescriptorSubtype 1 (HEADER) bcdUVC 1.50 wTotalLength 111 dwClockFrequency 48.000000MHz bInCollection 1 baInterfaceNr( 0) 3 VideoControl Interface Descriptor: bLength 18 bDescriptorType 36 bDescriptorSubtype 2 (INPUT_TERMINAL) bTerminalID 1 wTerminalType 0x0201 Camera Sensor bAssocTerminal 0 iTerminal 0 wObjectiveFocalLengthMin 0 wObjectiveFocalLengthMax 0 wOcularFocalLength 0 bControlSize 3 bmControls 0x00300000 VideoControl Interface Descriptor: bLength 13 bDescriptorType 36 bDescriptorSubtype 5 (PROCESSING_UNIT) bUnitID 2 bSourceID 1 wMaxMultiplier 16384 bControlSize 3 bmControls 0x00000000 iProcessing 0 bmVideoStandards 0x 0 VideoControl Interface Descriptor: bLength 29 bDescriptorType 36 bDescriptorSubtype 6 (EXTENSION_UNIT) bUnitID 7 guidExtensionCode {0f3f95dc-2632-4c4e-92c9-a04782f43bc8} bNumControl 4 bNrPins 1 baSourceID( 0) 2 bControlSize 4 bmControls( 0) 0xe0 bmControls( 1) 0x01 bmControls( 2) 0x00 bmControls( 3) 0x00 iExtension 0 VideoControl Interface Descriptor: bLength 29 bDescriptorType 36 bDescriptorSubtype 6 (EXTENSION_UNIT) bUnitID 4 guidExtensionCode {63610682-5070-49ab-b8cc-b3855e8d221d} bNumControl 27 bNrPins 1 baSourceID( 0) 7 bControlSize 4 bmControls( 0) 0xff bmControls( 1) 0xff bmControls( 2) 0x77 bmControls( 3) 0x1f iExtension 0 VideoControl Interface Descriptor: bLength 9 bDescriptorType 36 bDescriptorSubtype 3 (OUTPUT_TERMINAL) bTerminalID 5 wTerminalType 0x0101 USB Streaming bAssocTerminal 0 bSourceID 4 iTerminal 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x84 EP 4 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0010 1x 16 bytes bInterval 8 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 3 bAlternateSetting 0 bNumEndpoints 0 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 1 iInterface 0 VideoStreaming Interface Descriptor: bLength 14 bDescriptorType 36 bDescriptorSubtype 1 (INPUT_HEADER) bNumFormats 1 wTotalLength 101 bEndPointAddress 130 bmInfo 0 bTerminalLink 5 bStillCaptureMethod 1 bTriggerSupport 0 bTriggerUsage 0 bControlSize 1 bmaControls( 0) 27 VideoStreaming Interface Descriptor: bLength 27 bDescriptorType 36 bDescriptorSubtype 4 (FORMAT_UNCOMPRESSED) bFormatIndex 1 bNumFrameDescriptors 1 guidFormat {00000032-0002-0010-8000-00aa00389b71} bBitsPerPixel 8 bDefaultFrameIndex 1 bAspectRatioX 0 bAspectRatioY 0 bmInterlaceFlags 0x00 Interlaced stream or variable: No Fields per frame: 2 fields Field 1 first: No Field pattern: Field 1 only bCopyProtect 0 VideoStreaming Interface Descriptor: bLength 54 bDescriptorType 36 bDescriptorSubtype 5 (FRAME_UNCOMPRESSED) bFrameIndex 1 bmCapabilities 0x01 Still image supported wWidth 624 wHeight 352 dwMinBitRate 52715520 dwMaxBitRate 52715520 dwMaxVideoFrameBufferSize 439296 dwDefaultFrameInterval 333333 bFrameIntervalType 7 dwFrameInterval( 0) 333333 dwFrameInterval( 1) 400000 dwFrameInterval( 2) 500000 dwFrameInterval( 3) 666666 dwFrameInterval( 4) 1000000 dwFrameInterval( 5) 1333333 dwFrameInterval( 6) 2000000 VideoStreaming Interface Descriptor: bLength 6 bDescriptorType 36 bDescriptorSubtype 13 (COLORFORMAT) bColorPrimaries 1 (BT.709,sRGB) bTransferCharacteristics 1 (BT.709) bMatrixCoefficients 4 (SMPTE 170M (BT.601)) Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 3 bAlternateSetting 1 bNumEndpoints 1 bInterfaceClass 14 Video bInterfaceSubClass 2 Video Streaming bInterfaceProtocol 1 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x82 EP 2 IN bmAttributes 5 Transfer Type Isochronous Synch Type Asynchronous Usage Type Data wMaxPacketSize 0x0a80 2x 640 bytes bInterval 1 Binary Object Store Descriptor: bLength 5 bDescriptorType 15 wTotalLength 33 bNumDeviceCaps 1 Platform Device Capability: bLength 28 bDescriptorType 16 bDevCapabilityType 5 bReserved 0 PlatformCapabilityUUID {d8dd60df-4589-4cc7-9cd2-659d9e648a9f} CapabilityData[0] 0x00 CapabilityData[1] 0x00 CapabilityData[2] 0x00 CapabilityData[3] 0x0a CapabilityData[4] 0x6a CapabilityData[5] 0x03 CapabilityData[6] 0x01 CapabilityData[7] 0x00 Device Status: 0x0000 (Bus Powered) On Fri, 30 Dec 2022 at 14:45, Laurent Pinchart <laurent.pinchart@ideasonboard.com> wrote: > > Hi Ricardo, > > Thank you for the patch. > > On Fri, Dec 02, 2022 at 06:02:43PM +0100, Ricardo Ribalda wrote: > > Some Sunplus cameras took a borderline interpretation of the UVC 1.5 > > standard, and fill the PTS and SCR fields with invalid data if the > > package does not contain data. > > > > "STC must be captured when the first video data of a video frame is put > > on the USB bus." > > > > Eg: > > > > buffer: 0xa7755c00 len 000012 header:0x8c stc 00000000 sof 0000 pts 00000000 > > buffer: 0xa7755c00 len 000012 header:0x8c stc 00000000 sof 0000 pts 00000000 > > buffer: 0xa7755c00 len 000668 header:0x8c stc 73779dba sof 070c pts 7376d37a > > > > This borderline/buggy interpretation has been implemented in a variety > > of devices, from directly Sunplus and from other OEMs that rebrand > > Sunplus products. > > > > Luckily we can identify the affected modules by looking at the guid of > > one of the extension units: > > > > VideoControl Interface Descriptor: > > guidExtensionCode {82066163-7050-ab49-b8cc-b3855e8d221d} > > > > This patch adds a new quirk to take care of this. > > > > Complete lsusb of one of the affected cameras: > > That's not complete (but that's fine from a commit message point of > view, the full descriptors would be too long). Can you share the full > descriptors for all the devices you know are affected by this ? > > > Bus 001 Device 003: ID 1bcf:2a01 Sunplus Innovation Technology Inc. > > Device Descriptor: > > bLength 18 > > bDescriptorType 1 > > bcdUSB 2.01 > > bDeviceClass 239 Miscellaneous Device > > bDeviceSubClass 2 ? > > bDeviceProtocol 1 Interface Association > > bMaxPacketSize0 64 > > idVendor 0x1bcf Sunplus Innovation Technology Inc. > > idProduct 0x2a01 > > bcdDevice 0.02 > > iManufacturer 1 SunplusIT Inc > > iProduct 2 HanChen Wise Camera > > iSerial 3 01.00.00 > > bNumConfigurations 1 > > > > Tested-by: HungNien Chen <hn.chen@sunplusit.com> > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> > > --- > > drivers/media/usb/uvc/uvc_driver.c | 11 +++++++++++ > > drivers/media/usb/uvc/uvc_video.c | 8 ++++++++ > > drivers/media/usb/uvc/uvcvideo.h | 1 + > > 3 files changed, 20 insertions(+) > > > > diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c > > index c63ecfd4617d..80ef0f0e04b0 100644 > > --- a/drivers/media/usb/uvc/uvc_driver.c > > +++ b/drivers/media/usb/uvc/uvc_driver.c > > @@ -1497,6 +1497,17 @@ static const struct uvc_entity_quirk { > > u8 guid[16]; > > u32 quirks; > > } uvc_entity_quirk[] = { > > + /* > > + * Some SunPlus uvc 1.5 device firmware expects that packages with > > s/uvc/UVC/ > > > + * no frame data are ignored by the host. > > If it's two paragraphs, you need a blank line in-between. If it's a > single paragraph, you must not add a line break. > > > + * Therefore it does not clear the PTS/SCR bits in the header, and > > + * breaks the timestamp decode algorithm. > > + */ > > + { > > + .guid = {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, > > + 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1d}, > > + .quirks = UVC_QUIRK_IGNORE_EMPTY_TS, > > + }, > > }; > > > > static void uvc_entity_quirks(struct uvc_device *dev) > > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c > > index ab56e65ca324..a5b184e71ad7 100644 > > --- a/drivers/media/usb/uvc/uvc_video.c > > +++ b/drivers/media/usb/uvc/uvc_video.c > > @@ -500,6 +500,14 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, > > if (len < header_size) > > return; > > > > + /* > > + * Ignore the hardware timestamp on frames with no data on > > + * miss-behaving devices. > > + */ > > Could you please expand this comment to explain the issue ? Having to > use git blame and read the commit message to understand why the check is > here isn't very convenient. > > > + if (stream->dev->quirks & UVC_QUIRK_IGNORE_EMPTY_TS && > > + len == header_size) > > + return; > > + > > /* > > * Extract the timestamps: > > * > > diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h > > index 24c911aeebce..f395b67fe95a 100644 > > --- a/drivers/media/usb/uvc/uvcvideo.h > > +++ b/drivers/media/usb/uvc/uvcvideo.h > > @@ -212,6 +212,7 @@ > > #define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400 > > #define UVC_QUIRK_FORCE_Y8 0x00000800 > > #define UVC_QUIRK_FORCE_BPP 0x00001000 > > +#define UVC_QUIRK_IGNORE_EMPTY_TS 0x00002000 > > > > /* Format flags */ > > #define UVC_FMT_FLAG_COMPRESSED 0x00000001 > > > > -- > Regards, > > Laurent Pinchart
Hi Ricardo, Another comment. On Fri, Dec 30, 2022 at 03:45:12PM +0200, Laurent Pinchart wrote: > On Fri, Dec 02, 2022 at 06:02:43PM +0100, Ricardo Ribalda wrote: > > Some Sunplus cameras took a borderline interpretation of the UVC 1.5 > > standard, and fill the PTS and SCR fields with invalid data if the > > package does not contain data. > > > > "STC must be captured when the first video data of a video frame is put > > on the USB bus." > > > > Eg: > > > > buffer: 0xa7755c00 len 000012 header:0x8c stc 00000000 sof 0000 pts 00000000 > > buffer: 0xa7755c00 len 000012 header:0x8c stc 00000000 sof 0000 pts 00000000 > > buffer: 0xa7755c00 len 000668 header:0x8c stc 73779dba sof 070c pts 7376d37a > > > > This borderline/buggy interpretation has been implemented in a variety > > of devices, from directly Sunplus and from other OEMs that rebrand > > Sunplus products. > > > > Luckily we can identify the affected modules by looking at the guid of > > one of the extension units: > > > > VideoControl Interface Descriptor: > > guidExtensionCode {82066163-7050-ab49-b8cc-b3855e8d221d} > > > > This patch adds a new quirk to take care of this. > > > > Complete lsusb of one of the affected cameras: > > That's not complete (but that's fine from a commit message point of > view, the full descriptors would be too long). Can you share the full > descriptors for all the devices you know are affected by this ? > > > Bus 001 Device 003: ID 1bcf:2a01 Sunplus Innovation Technology Inc. > > Device Descriptor: > > bLength 18 > > bDescriptorType 1 > > bcdUSB 2.01 > > bDeviceClass 239 Miscellaneous Device > > bDeviceSubClass 2 ? > > bDeviceProtocol 1 Interface Association > > bMaxPacketSize0 64 > > idVendor 0x1bcf Sunplus Innovation Technology Inc. > > idProduct 0x2a01 > > bcdDevice 0.02 > > iManufacturer 1 SunplusIT Inc > > iProduct 2 HanChen Wise Camera > > iSerial 3 01.00.00 > > bNumConfigurations 1 > > > > Tested-by: HungNien Chen <hn.chen@sunplusit.com> > > Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> > > --- > > drivers/media/usb/uvc/uvc_driver.c | 11 +++++++++++ > > drivers/media/usb/uvc/uvc_video.c | 8 ++++++++ > > drivers/media/usb/uvc/uvcvideo.h | 1 + > > 3 files changed, 20 insertions(+) > > > > diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c > > index c63ecfd4617d..80ef0f0e04b0 100644 > > --- a/drivers/media/usb/uvc/uvc_driver.c > > +++ b/drivers/media/usb/uvc/uvc_driver.c > > @@ -1497,6 +1497,17 @@ static const struct uvc_entity_quirk { > > u8 guid[16]; > > u32 quirks; > > } uvc_entity_quirk[] = { > > + /* > > + * Some SunPlus uvc 1.5 device firmware expects that packages with > > s/uvc/UVC/ > > > + * no frame data are ignored by the host. > > If it's two paragraphs, you need a blank line in-between. If it's a > single paragraph, you must not add a line break. > > > + * Therefore it does not clear the PTS/SCR bits in the header, and > > + * breaks the timestamp decode algorithm. > > + */ > > + { > > + .guid = {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, > > + 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1d}, > > + .quirks = UVC_QUIRK_IGNORE_EMPTY_TS, > > + }, > > }; > > > > static void uvc_entity_quirks(struct uvc_device *dev) > > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c > > index ab56e65ca324..a5b184e71ad7 100644 > > --- a/drivers/media/usb/uvc/uvc_video.c > > +++ b/drivers/media/usb/uvc/uvc_video.c > > @@ -500,6 +500,14 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, > > if (len < header_size) > > return; > > > > + /* > > + * Ignore the hardware timestamp on frames with no data on > > + * miss-behaving devices. > > + */ > > Could you please expand this comment to explain the issue ? Having to > use git blame and read the commit message to understand why the check is > here isn't very convenient. > > > + if (stream->dev->quirks & UVC_QUIRK_IGNORE_EMPTY_TS && > > + len == header_size) > > + return; Given that there may be no guarantee that the above GUID won't be used by devices that don't exhibit this problem, I'm wondering if we couldn't use a heuristics instead of a quirk. I'm thinking about something along the lines of if (buf->bytesused == 0 && len == header_size && has_scr && stc == 0 && sof == 0) This will catch suspicious SCR values (stc == 0 && sof == 0) on empty packets (len == header_size) sent before any data packet (buf->bytesused == 0), which should handle the devices you have to support, and avoid false positives (the stc == 0 && sof == 0 check is already quite restrictive, adding buf->bytesused == 0 would limit the workaround to packets before the first data packet). With this we could drop patch 2/8. > > + > > /* > > * Extract the timestamps: > > * > > diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h > > index 24c911aeebce..f395b67fe95a 100644 > > --- a/drivers/media/usb/uvc/uvcvideo.h > > +++ b/drivers/media/usb/uvc/uvcvideo.h > > @@ -212,6 +212,7 @@ > > #define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400 > > #define UVC_QUIRK_FORCE_Y8 0x00000800 > > #define UVC_QUIRK_FORCE_BPP 0x00001000 > > +#define UVC_QUIRK_IGNORE_EMPTY_TS 0x00002000 > > > > /* Format flags */ > > #define UVC_FMT_FLAG_COMPRESSED 0x00000001 > >
diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c index c63ecfd4617d..80ef0f0e04b0 100644 --- a/drivers/media/usb/uvc/uvc_driver.c +++ b/drivers/media/usb/uvc/uvc_driver.c @@ -1497,6 +1497,17 @@ static const struct uvc_entity_quirk { u8 guid[16]; u32 quirks; } uvc_entity_quirk[] = { + /* + * Some SunPlus uvc 1.5 device firmware expects that packages with + * no frame data are ignored by the host. + * Therefore it does not clear the PTS/SCR bits in the header, and + * breaks the timestamp decode algorithm. + */ + { + .guid = {0x82, 0x06, 0x61, 0x63, 0x70, 0x50, 0xab, 0x49, + 0xb8, 0xcc, 0xb3, 0x85, 0x5e, 0x8d, 0x22, 0x1d}, + .quirks = UVC_QUIRK_IGNORE_EMPTY_TS, + }, }; static void uvc_entity_quirks(struct uvc_device *dev) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index ab56e65ca324..a5b184e71ad7 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -500,6 +500,14 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, if (len < header_size) return; + /* + * Ignore the hardware timestamp on frames with no data on + * miss-behaving devices. + */ + if (stream->dev->quirks & UVC_QUIRK_IGNORE_EMPTY_TS && + len == header_size) + return; + /* * Extract the timestamps: * diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 24c911aeebce..f395b67fe95a 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -212,6 +212,7 @@ #define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400 #define UVC_QUIRK_FORCE_Y8 0x00000800 #define UVC_QUIRK_FORCE_BPP 0x00001000 +#define UVC_QUIRK_IGNORE_EMPTY_TS 0x00002000 /* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001