From patchwork Wed Mar 8 22:45:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 66494 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp623383wrd; Wed, 8 Mar 2023 15:03:08 -0800 (PST) X-Google-Smtp-Source: AK7set8MTQzoJaVdlu+b7CjNzQeEuoPDylUGgyRTyFJrqW5Oi5GeIhaEUngHZ2aO9eZfwejCe6nD X-Received: by 2002:a05:6a20:8ba2:b0:bc:f0d2:e268 with SMTP id m34-20020a056a208ba200b000bcf0d2e268mr17582122pzh.29.1678316588271; Wed, 08 Mar 2023 15:03:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678316588; cv=none; d=google.com; s=arc-20160816; b=pTRhgdhdrxhJUy52pjSk4Y+mm7NUVkfquh3AJLFg+q8TUpXpfNesYy8Dg8xxnkhamc 4Xu6INucbzW9vS7bwGj6DD+RStfEr0Y+uuwrAOljT6cPZEeI3lLEaIeBuQ3+ENmGY6kq GNWxLcX5WhH0CsSkbRzG3PRfHE4xAgoLUffiRPBsdl/W3YkmDeiiGmRycCueEnIHhzoP RxFeuiT51FMkERrvrj4pIoAtWaFaNYgdLp3Hcl4QU0zEzK4RlQNJAItEp8+bZpMUIQDA 3S2qZRPyoxporeTqenBvbFai+Gs5nSwV5g72IvIi+uj8tt3PYj+aQcfSgyUXuG78k4rY y9Tg== 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=pTSyQnL+DX5vQdXg5c4PiHio+TOgApxxG8f6MJvLPiI=; b=bZYWj7zTrWpE8CCr8Gmf2oHhB3BgFPbLVt6upLvlCG71IggY6BNe5Bt69FHZvp55df U2b2SRqeQvf0XM6EjwAOF2Vh19k+HAIk55OlPXAm89MQU03pUdNRayhmHGoFjKLKHEDR GWBsi6KHuZZiU8RDad2IkMmMRxW7CXD1RUu5RQ8/m6C1zR3OZnyXQnk1frdf/J5v3bTm 5GQ4ZhHOEWFM97jSP+K2MZNDZpgiQ79ATO/Ls2ECIDr7Qw+9LO8ZFEn0pUxsSbteG342 N8cjb8/NsPR+AojGGerndcId/6TDBx4SwY2jqAMkCMdcarZdt+o66ALZH7B8TX/S7TZE XeXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=aHKYUKLu; 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 n127-20020a632785000000b0050017092042si16119301pgn.383.2023.03.08.15.02.44; Wed, 08 Mar 2023 15:03:08 -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=aHKYUKLu; 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 S229897AbjCHWp5 (ORCPT + 99 others); Wed, 8 Mar 2023 17:45:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229963AbjCHWps (ORCPT ); Wed, 8 Mar 2023 17:45:48 -0500 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0586596C3F for ; Wed, 8 Mar 2023 14:45:46 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id u9so72029954edd.2 for ; Wed, 08 Mar 2023 14:45:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1678315544; 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=pTSyQnL+DX5vQdXg5c4PiHio+TOgApxxG8f6MJvLPiI=; b=aHKYUKLuXlMzrYdGCOz61J90qL9YTceNNG5eun+9B2avxyk3WhtGZMGsj9MFWclpNj hU14Nm2eiSl6L7UVCQGDNPps89tyH2VO4TLrCn/i8HcOEneL9+xBTe8/UdLiXErvNWni 5J9UmjHjSU4wwcqkiH66SVdyTi8cYpRmFMfmo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678315544; 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=pTSyQnL+DX5vQdXg5c4PiHio+TOgApxxG8f6MJvLPiI=; b=2ZdXjAuaGIjxfVxZpojAOMyuhGAY+iwRfNX0quCuQSG4Sj8P2EvGQTNC/UY+1WFP7R SMHmgeAslx4+j4A42CESEjF1n9HXthzOPu7wVVC4mIDazYeGCfx5Yu++2JwDpe2IWo43 9gzi7vvKsWAFOKAe6DRbOrnthfF7A0x/x8lidjQZKAay7TswWSltgMSHHfWxGHMxyEb3 O3ugXvZYqTklPQcwjh0OYuuKIegCeCj1mv315u6qX1BYeGHSPS7kMTdXFtajFpZxOpFv jA2dEDoagnWjZuYoNSgmAXa0oZpfrVgr+WtxwzMSA6l7U1GyeZzOH78L0ZrIfWndHhio BLhw== X-Gm-Message-State: AO0yUKV2DWgVGad8HLKxEXxUSh4OVn08jFmzIJSYdREWiiZKJJcsPLuZ R9so3TswpKDFcVk+z+XPBO70Co7YK+EfEX+OPMufuQ== X-Received: by 2002:aa7:d615:0:b0:4ef:4c08:ee9c with SMTP id c21-20020aa7d615000000b004ef4c08ee9cmr6894197edr.16.1678315544539; Wed, 08 Mar 2023 14:45:44 -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 ot18-20020a170906ccd200b008e40853a712sm8040167ejb.97.2023.03.08.14.45.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Mar 2023 14:45:44 -0800 (PST) From: Ricardo Ribalda Date: Wed, 08 Mar 2023 23:45:32 +0100 Subject: [PATCH RESEND v5 1/5] media: uvc: Ignore empty TS packets MIME-Version: 1.0 Message-Id: <20220920-resend-hwtimestamp-v5-1-139d1a144614@chromium.org> References: <20220920-resend-hwtimestamp-v5-0-139d1a144614@chromium.org> In-Reply-To: <20220920-resend-hwtimestamp-v5-0-139d1a144614@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: "hn.chen" , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.11.0-dev-696ae X-Developer-Signature: v=1; a=openpgp-sha256; l=3560; i=ribalda@chromium.org; h=from:subject:message-id; bh=G1+fubIW/BdICDCrRg9jYl6ay0jxDPYdKiwuTQ04Efg=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBkCRAPK9i7+2Di2bgdLI2+yNG/beqTk3HJgXqu4Ktw sJhiwg6JAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCZAkQDwAKCRDRN9E+zzrEiPheD/ 0WvCdIkF9ILtv8vYaPC/KqHsiBh9KBOxyPVKicUUrKgjf06qw6+UqlX/Nlhhrb/GV2i8S0m9wy7wrF QKlC1PpzryKM5jTpfgLde3JXgYO6zOSVOpzJdAC2BbKxzGTAtzKRTVk/ZMhqV44KUXdcsDwZf/gdC8 tdvrB6nAha0DCxsZwoe8UAqnlTa0h19wj0Fi13avfvL89CLnANxxD0xLdzCGGejRrFvtCd7MJZ5xQD 7qRzuw3C3QU+5vmNMy4cynl8sWXHeDIUh+1ZdOViocu86a0uCNh0Qqh9VzsKJzH1lbxJkRNsCq5l2w Rd90s2fXtoAsKfvigL5YuzTEEy53mY0tgS+oYr0xTKqvs9O/bs3kKoOIBEs2N+ptDyYWo7UgMkjqeL rQqGhojFw4B17MmieJkCAquSCbxl9PIUtNBlMvAHWLYrUINJReqg66Ert4MTq+qp1VNBA0fFYYHmlz fgTl6ibUGuqLX9cXwBgOCZ6cKl3xKmcbd/tMYxo9QfhpQJ2B27oNed1LP+5io8o/mbsOCcuTq5kKko scq5UgiUsXPivemvkLGWZ/VVwsyAdXstXNc5tx+PkUOuuX+HIjxEwCPpIJ9DTAXvUtK47F9+mEht92 cIZqm7/soaiuXreg4ZG3TBuNSsp4jfaJNV2fuccxwBWSKlg9jm5JhgWt879A== 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,URIBL_BLOCKED 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759842494983889287?= X-GMAIL-MSGID: =?utf-8?q?1759842494983889287?= Some SunplusIT 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 SunplusIT and from other OEMs that rebrand SunplusIT products. So quirking based on VID:PID will be problematic. All the affected modules have the following extension unit: VideoControl Interface Descriptor: guidExtensionCode {82066163-7050-ab49-b8cc-b3855e8d221d} But the vendor plans to use that GUID in the future and fix the bug, this means that we should use heuristic to figure out the broken packets. This patch takes care of this. 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 Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_video.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index d4b023d4de7c..488c58bc9919 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -478,6 +478,7 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, ktime_t time; u16 host_sof; u16 dev_sof; + u32 dev_stc; switch (data[1] & (UVC_STREAM_PTS | UVC_STREAM_SCR)) { case UVC_STREAM_PTS | UVC_STREAM_SCR: @@ -526,6 +527,18 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, if (dev_sof == stream->clock.last_sof) return; + dev_stc = get_unaligned_le32(&data[header_size - 6]); + + /* + * Some devices make a borderline interpretation of the UVC 1.5 standard + * and sends packets with no data contain undefined timestamps. Ignore + * such packages to avoid interfering with the clock interpolation + * algorithm. + */ + if (buf && buf->bytesused == 0 && len == header_size && + dev_stc == 0 && dev_sof == 0) + return; + stream->clock.last_sof = dev_sof; host_sof = usb_get_current_frame_number(stream->dev->udev); @@ -564,7 +577,7 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf, spin_lock_irqsave(&stream->clock.lock, flags); sample = &stream->clock.samples[stream->clock.head]; - sample->dev_stc = get_unaligned_le32(&data[header_size - 6]); + sample->dev_stc = dev_stc; sample->dev_sof = dev_sof; sample->host_sof = host_sof; sample->host_time = time;