Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp440757lqb; Tue, 28 May 2024 23:19:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXb9l7FiPyqmHHhI452k0/ImHOsrMg3y57s0UHXeulO5Wbe1w39HhjRQUOjnQvhdYZrBZy9BQcwdURHilVy+tWn/wbR4V/k4bDbFmzaig== X-Google-Smtp-Source: AGHT+IGTIcHbNaPC+oyvswgX5wCKxIbDjSlV39B+rIAraZCSf1mCpx+NE2KuTvMD5VN+ZACzfM7d X-Received: by 2002:a05:6a20:a127:b0:1b0:58e:1b9a with SMTP id adf61e73a8af0-1b259a01ad6mr2096016637.4.1716963592400; Tue, 28 May 2024 23:19:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716963592; cv=pass; d=google.com; s=arc-20160816; b=oxLCV6Tun6cVtpdisxyyRLnyRkPcQlCzeTU4GOCc1DF9EA42I1BNGFQMBZZ8aXPK34 QMSXXxEJozdlvduC0QjU/6t4AIbCexF9Sp4u7HP68QvnT1mQz3g8qlAcieIhckbZ8TiQ iBzA0Le7Zc/J0/qIlKyFOH6bvfPCT3+yy+89XI/hlJV419tGMwP7SD7YR4QGc5FUcqFA hDO+vz6ELPYT0tDJXXwxwTstRb32tsKwgfxKE9gMW5tV0gLUJ4w7yTQtF8tgYXNpjztq 78OGsoeBev1aaNQGDIpCRdbRvCToIUtf84J3yR+CjiILw9XtviEgAHPnzMDua0ZCnFln CfyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=4fK2YCNC3izJsF1MvF0HgktiFwQJjQP30j11830xzgU=; fh=HIrtJ7RH2aKp3HoisyHMvvUOwJth2K2UxIX5T9G2RN8=; b=TlzQC1YvwWkm7PTlBSSYYNgLatFqr9zKvxRtB/1Ar1AEJODqSQSEasY+TOeObFP9A+ r/5MP6ewhDDmkA98QSgSRwLs/+ddN/psTjl9p8Ye4mETc0ybYBL3jLz/6SrCA0O67vwF s/QDnO1N1F8RiA4EJVBqn/PjgdRrsKJ0piUiTLRnyS40KVL1lWm3D9SxULQ3V5vDENNU zwVbQ7NvukhheB+OVn7zFSVZ1M3lLC/Q6K5fmWI6VQn7DTH8RDHM96NbByAS5ocjou3M EKMNcf+BiXx3/1sj1A0YGK+pdOxDH2HO5X/ENSO4jx1U6MVPpeaIog99dsRpfktYMirP pvWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cuSxQGjE; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-193502-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193502-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-688e1e9655fsi8370568a12.666.2024.05.28.23.19.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 23:19:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-193502-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cuSxQGjE; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-193502-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-193502-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0AFA42829F9 for ; Wed, 29 May 2024 06:19:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A42C115B124; Wed, 29 May 2024 06:19:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="cuSxQGjE" Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 226802208E for ; Wed, 29 May 2024 06:19:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716963575; cv=none; b=ScJRioCwV43C9kVNPWpiqZBp5Zib7xFr2PaDLgmeNBRF6UNi3dduzIe/H50LrN/Uur2EkyLFY9c2QthIjte1MNKlr+zj8e2/3VF6S008pEYgqn4duPsTZOnCAd8M4cZJpM4aM4xJ5WumlyTcB624zWrFjVYU+Z/96fnwrmxRnJo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716963575; c=relaxed/simple; bh=5q25FCkx6/PUWxR9ImTBgVgAd5dorLXR5yzR77dfnNI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ee1MqRWjf35Tdt4FcBGcIyTq1R8yLcZjO4moy45JlR1NVhXjmT4ImkG4HIUnFYhHOdyDrLjGqCariOTYo6pM2TGDUqx3ldE8rCsQSK3tNvpgDNUrXKfOmoVI2GKlxODWlcRD+Exv8y8Tc+y5L6cPKwIYvnyZegeESFcJYW2/c/I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=cuSxQGjE; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6f4ed9dc7beso420754b3a.1 for ; Tue, 28 May 2024 23:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1716963573; x=1717568373; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=4fK2YCNC3izJsF1MvF0HgktiFwQJjQP30j11830xzgU=; b=cuSxQGjEsgVPNxqgS4cZLpwLiwxNiFD9UYP7y05tCuqs+esWy8jnxwFikSiHskG9Nd ePRl8hUylWIcZR5BqQfTw3hxOLd+aqga4PIPbzi4GCvP70cnRRLaDVLm1KI2PGO2xc5K nWk5ndjndPEZtzbg6FvZPGMRGfWz9vtE2dDV8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716963573; x=1717568373; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=4fK2YCNC3izJsF1MvF0HgktiFwQJjQP30j11830xzgU=; b=NBB1HDtcJiHiuI3Q6t9g5WLy7CYBCeSoxbn2ztHehhOaDv3coN2cdEHfhgOsIvqJ0n ZhP/UQrjCUQ2v1Og9COeegkC3fcYr8Ro19O1Vj7Dz2oYFvqJalrPmV5eonj6GkhMylRe eyo0TEvtVH4ck+N3v9z8bgqsfu5ioXfFZ8BXifL4Wqqu8b7cn8oZXYt+GBCeCqz6aQTO Pl9eOUpcoVLsAKuShp5fJH9/Locnuy/CdgJq+qmo2NLdTcVHhIXFkNIOBkJ2n1VApd9S 3T5zaWVDk1uiE1YH5dLtf8EHnX+ezdjmoAgCQ/aEffBHEeFbyB1TuOAgihiUnkZu5r1K O25A== X-Forwarded-Encrypted: i=1; AJvYcCWGW1BPJVEeAlFY5cPesPz+BcRmi3+FWR2sizhFX7nR0QPGfMg3qvfo4dTvtDsKYmAT43xasX+K83R7bN3obMlarqoob1I+l6qSBBYE X-Gm-Message-State: AOJu0YzpPmpYNufL/RABsZAZVf/Ox1XhGPUt4hE4pKuT5GuuY/Iq1lZw OoJre6xqiuefZc7C6jkIEMtbUWzlZqUrZMlRK7T3kjuAye2zY9fELa1aAeCQ9Q== X-Received: by 2002:a05:6a00:2d1a:b0:701:98c4:48a9 with SMTP id d2e1a72fcca58-702029f430dmr2204645b3a.5.1716963573249; Tue, 28 May 2024 23:19:33 -0700 (PDT) Received: from chromium.org (174.71.80.34.bc.googleusercontent.com. [34.80.71.174]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-68221891986sm8415793a12.22.2024.05.28.23.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 23:19:32 -0700 (PDT) Date: Wed, 29 May 2024 15:19:30 +0900 From: Tomasz Figa To: Ricardo Ribalda Cc: Laurent Pinchart , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, "hn.chen" , Hans Verkuil , Sergey Senozhatsky Subject: Re: [PATCH v10 2/6] media: uvcvideo: Ignore empty TS packets Message-ID: References: <20240323-resend-hwtimestamp-v10-0-b08e590d97c7@chromium.org> <20240323-resend-hwtimestamp-v10-2-b08e590d97c7@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240323-resend-hwtimestamp-v10-2-b08e590d97c7@chromium.org> On Sat, Mar 23, 2024 at 10:48:03AM +0000, Ricardo Ribalda wrote: > 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." > > Some SunplusIT devices send, e.g., > > 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 > > While the UVC specification meant that the first two packets shouldn't > have had the SCR bit set in the header. > > 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 > Reviewed-by: Sergey Senozhatsky > Reviewed-by: Laurent Pinchart > Signed-off-by: Ricardo Ribalda > --- > drivers/media/usb/uvc/uvc_video.c | 31 ++++++++++++++++++++++++++++++- > 1 file changed, 30 insertions(+), 1 deletion(-) > Reviewed-by: Tomasz Figa Best regards, Tomasz > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c > index 659c9e9880a99..b2e70fcf4eb4c 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,34 @@ 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]); > + > + /* > + * STC (Source Time Clock) is the clock used by the camera. The UVC 1.5 > + * standard states that it "must be captured when the first video data > + * of a video frame is put on the USB bus". This is generally understood > + * as requiring devices to clear the payload header's SCR bit before > + * the first packet containing video data. > + * > + * Most vendors follow that interpretation, but some (namely SunplusIT > + * on some devices) always set the `UVC_STREAM_SCR` bit, fill the SCR > + * field with 0's,and expect that the driver only processes the SCR if > + * there is data in the packet. > + * > + * Ignore all the hardware timestamp information if we haven't received > + * any data for this frame yet, the packet contains no data, and both > + * STC and SOF are zero. This heuristics should be safe on compliant > + * devices. This should be safe with compliant devices, as in the very > + * unlikely case where a UVC 1.1 device would send timing information > + * only before the first packet containing data, and both STC and SOF > + * happen to be zero for a particular frame, we would only miss one > + * clock sample from many and the clock recovery algorithm wouldn't > + * suffer from this condition. > + */ > + 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 +593,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; > > -- > 2.44.0.396.g6e790dbe36-goog > >