Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp276296lqp; Wed, 12 Jun 2024 00:47:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWZ8A6pbRYexDl5yDLMhdaCDjmMmfe0tCUqFPsSavFMoyC4k727vZzahp/HICsp5Qe6zsGymFPOfbJbkg77f5iyo0nPWHH+YtU/GSy8jg== X-Google-Smtp-Source: AGHT+IHjfgPIRzrLojxNWxD5s9q+OiGoyhYTJHAnCKYP3NYDdNVL9H8WMsE4GhXY0zYGcg5xEPgq X-Received: by 2002:a05:6214:2f85:b0:6b0:7b29:da92 with SMTP id 6a1803df08f44-6b1a64903f1mr11817216d6.36.1718178476478; Wed, 12 Jun 2024 00:47:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718178476; cv=pass; d=google.com; s=arc-20160816; b=0y1GiX77m+hdLVmEqRAaQbVLoKObmedgSGSe/fL9CPVw25AfH52e9d9k0PfIV5YhW0 nsM6ebxlUP2AZQfx6lKRReScQwXkfMLTfJS6yMkoHrb7UJ6N5VZnyjpNIgU1Sr1IjzVH xvSU1tzUmZnHAzHfvnOCIobLOjRuu5jDyGVIZSR/Xga2vaY3K0tktd46A2TZSt9s5EVG 5Vmf4Xr22LrV0FbN8zB312p5UW7ZXWK5dBdGyhVQn7XRIDkH7PeeSYtP0qO7sK6udDnb PqR5MZ+D4Vagjp5u4YsgJv/kn93lRDN8dc7G2Qxx3hqhdX6Z4P03/WcrITwhZXbfWfN1 FCgw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=nLdTXN9lYe0a3EsiIXNNLenN6Ja+aPhpUeSTY7jocuk=; fh=B+/GlGMjp1226gxw6SlQnlgnjn+qiAALGuBn2tZdZHg=; b=Dr35YXbH7yyDNAXrOzyacMfVJkqHiwIPEPGK+qXACSizVRVNx6iaE2viCkMCdeVwHA j/2SggpE4M7/MuGs3UjqrRk5/IGEZ1gH0h+W5JpP8tFPcgDq3r3bAHrkejiV4jLXhvy6 U220ITb+AMcw8MqLlz3s9oPi4NyCi9WFoe18d0jMmf0nuZLayQfAi/O3mvZ5yRNjt+Js IRyduvlFoP60QxdWOjBv6P01PASr35yVIJBDFRKVZlc48tY+IuFbyoa+p97DEiINnRxw wFuFQqoHvBV9lFTzAbTpLwMvaBVlylQAqInLflOzGV1gdJAmuDJGQocp/o4EiLjVqYRU 6VlQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jaX7PZYR; 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-211098-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211098-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6b086125912si50418596d6.103.2024.06.12.00.47.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 00:47:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211098-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jaX7PZYR; 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-211098-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211098-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 273C91C213F8 for ; Wed, 12 Jun 2024 07:47:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4186616C69A; Wed, 12 Jun 2024 07:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jaX7PZYR" Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 39A9817C9 for ; Wed, 12 Jun 2024 07:47:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718178467; cv=none; b=sYHfemYh8JxEtGYxEi8e+mnzD1OBJIZAvPrDhsM4jn2oLyEl6QoViOrk1FDt5Rjy14XehZmHyp9i1hcrDYFtBokdX62aJJEbnwnKzbYrM0ylJBKBiMFZ+KbathLFgVqrv8IAtAGjwUAawf8BdBAQoKOyVKGc/iECS7kxJj4cvIM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718178467; c=relaxed/simple; bh=+tl9JMqUu0n+y7TzF8Ko462bpmGnHN5qKwZIJDCVbU4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=CA0mFnT5lIB5pN4+//FeqNbC/TFnZlRXB2FjRAWRZifDZxHKwoSJACcCi2WgXQcnwVcSYa0sUwZnpLEVxgRBrOCSsBVPG+vX6Uo935XpLo46kkR/5M/3GpZifsMByfUMOdW0mZfp4fctt6jehv13/+6o1CtMuuOZoauUyev3SUI= 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=jaX7PZYR; arc=none smtp.client-ip=209.85.167.44 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-lf1-f44.google.com with SMTP id 2adb3069b0e04-52bc1261f45so5073132e87.0 for ; Wed, 12 Jun 2024 00:47:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1718178462; x=1718783262; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=nLdTXN9lYe0a3EsiIXNNLenN6Ja+aPhpUeSTY7jocuk=; b=jaX7PZYRr2Ktc3Ao3BIi5Xw92yLS37DI6+uEJaGmMpRlJAq0rlzzQfEkYluwOigUZo j87gsAzAHn23OYO806EyzIKT4Tt4J2oK92yqFryng0egZASs/v2kJDGwBwgJjDMOAI0q jNLKX1q+33hZhm7wzh6HtahzUy/Etur6kTZew= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718178462; x=1718783262; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nLdTXN9lYe0a3EsiIXNNLenN6Ja+aPhpUeSTY7jocuk=; b=T9i6fI2UlPAjx0Thnh8xYvNpeRjXeaVKlTczHbhPv+4Y6wGHiXozetejneHZxa3nzS cKgv+M4Hu03ldg11nBes77dAEW6aErDOZ3lCbahn4bu2yKmz/hUhsTIMYrd8FP51ujWa ZyCBkGAYhPuoRXiGhAdfQBI5bBrZVL5MtjYPvrzbRLLUOXOVgmzf7efeB/J5jYIxizZE J3KU/N/K8Esq2M8W+7JJRj5p+7kzsDiOTLVhn0N+/8zXnCjm+ulrPNog2BMoeGSueKWp 7bGN9cYBhIVARW1fcDjlh7PZdaYmrOrdShCwM9/sXlb/79xe5rH16P0eD0AbYIxOmnxx kDBw== X-Forwarded-Encrypted: i=1; AJvYcCVtJE4sHza+oxX9fxKBkgX+E1yTO7Pl4lrZbfMdakLI4ddvxMw7mJ1LzA4WTIbzAVULZLykrtp31JV8JqHzA6/2d/cHmnv7dGFXNsw0 X-Gm-Message-State: AOJu0YwEvSalKSy7oqU8qPuFwUgVKW2Kqjw0dZA3J18Mp+MzTkPVthvk z2wMc1icBANSWoPuQurDdFhKk2urLJI1daS7r0BDadBOV03CLagAikXGmumGkaRDk26UiNjbnTn xTLyd X-Received: by 2002:a19:ca0d:0:b0:52b:bd9f:d8ef with SMTP id 2adb3069b0e04-52c9a4053dfmr528385e87.60.1718178462118; Wed, 12 Jun 2024 00:47:42 -0700 (PDT) Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com. [209.85.167.54]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52bb41e2054sm2374798e87.49.2024.06.12.00.47.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Jun 2024 00:47:41 -0700 (PDT) Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-52bc1261f45so5073117e87.0 for ; Wed, 12 Jun 2024 00:47:41 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCUzlOraT+7pFJj6uwDAj9wHzUqY2FOvMRTQeU9zXyMZkEIT/pC8oRwSQR9V0CfZL/KEwK/dKW424D7uol5IYAv3wze3AZ364vyZAJzA X-Received: by 2002:a05:6512:61b:b0:52b:ce2f:5d11 with SMTP id 2adb3069b0e04-52c9a3c6eb8mr505332e87.25.1718178461142; Wed, 12 Jun 2024 00:47:41 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240323-resend-hwtimestamp-v10-0-b08e590d97c7@chromium.org> <20240323-resend-hwtimestamp-v10-4-b08e590d97c7@chromium.org> <4kck7oedsnj6kfiv7ykwsjg35qodg5bdktu5t5w3xtg2xuscto@2yh6kfdqwimc> <20240610114306.GR18479@pendragon.ideasonboard.com> <20240612074342.GA28989@pendragon.ideasonboard.com> In-Reply-To: <20240612074342.GA28989@pendragon.ideasonboard.com> From: Ricardo Ribalda Date: Wed, 12 Jun 2024 09:47:26 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v10 4/6] media: uvcvideo: Allow hw clock updates with buffers not full To: Laurent Pinchart Cc: Tomasz Figa , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, "hn.chen" , Hans Verkuil , Sergey Senozhatsky Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, 12 Jun 2024 at 09:44, Laurent Pinchart wrote: > > On Wed, Jun 12, 2024 at 12:28:56PM +0900, Tomasz Figa wrote: > > On Mon, Jun 10, 2024 at 8:43=E2=80=AFPM Laurent Pinchart wrote: > > > On Wed, May 29, 2024 at 05:03:08PM +0900, Tomasz Figa wrote: > > > > On Sat, Mar 23, 2024 at 10:48:05AM +0000, Ricardo Ribalda wrote: > > > > > With UVC 1.5 we get as little as one clock sample per frame. Whic= h means > > > > > that it takes 32 frames to move from the software timestamp to th= e > > > > > hardware timestamp method. > > > > > > > > > > This results in abrupt changes in the timestamping after 32 frame= s (~1 > > > > > second), resulting in noticeable artifacts when used for encoding= . > > > > > > > > > > With this patch we modify the update algorithm to work with whate= ver > > > > > amount of values are available. > > > > > > > > > > Tested-by: HungNien Chen > > > > > Reviewed-by: Sergey Senozhatsky > > > > > Reviewed-by: Laurent Pinchart > > > > > Signed-off-by: Ricardo Ribalda > > > > > --- > > > > > drivers/media/usb/uvc/uvc_video.c | 16 ++++++++++++++-- > > > > > 1 file changed, 14 insertions(+), 2 deletions(-) > > > > > > > > > > diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/us= b/uvc/uvc_video.c > > > > > index d6ca383f643e3..af25b9f1b53fe 100644 > > > > > --- a/drivers/media/usb/uvc/uvc_video.c > > > > > +++ b/drivers/media/usb/uvc/uvc_video.c > > > > > @@ -768,10 +768,10 @@ void uvc_video_clock_update(struct uvc_stre= aming *stream, > > > > > > > > > > spin_lock_irqsave(&clock->lock, flags); > > > > > > > > > > - if (clock->count < clock->size) > > > > > + if (clock->count < 2) > > > > > goto done; > > > > > > > > > > - first =3D &clock->samples[clock->head]; > > > > > + first =3D &clock->samples[(clock->head - clock->count + clock= ->size) % clock->size]; > > > > > last =3D &clock->samples[(clock->head - 1 + clock->size) % cl= ock->size]; > > > > > > > > > > /* First step, PTS to SOF conversion. */ > > > > > @@ -786,6 +786,18 @@ void uvc_video_clock_update(struct uvc_strea= ming *stream, > > > > > if (y2 < y1) > > > > > y2 +=3D 2048 << 16; > > > > > > > > > > + /* > > > > > + * Have at least 1/4 of a second of timestamps before we > > > > > + * try to do any calculation. Otherwise we do not have enough > > > > > + * precision. This value was determined by running Android CT= S > > > > > + * on different devices. > > > > > + * > > > > > + * dev_sof runs at 1KHz, and we have a fixed point precision = of > > > > > + * 16 bits. > > > > > + */ > > > > > + if ((y2 - y1) < ((1000 / 4) << 16)) > > > > > + goto done; > > > > > > > > Not a comment for this patch directly, but... > > > > > > > > This kind of makes me wonder if we don't want to have some document= ation > > > > that specifies what the userspace can expect from the timestamps, s= o > > > > that this isn't changed randomly in the future breaking what was fi= xed > > > > by this patch. > > > > > > I think timestamp handling should really be moved to userspace. It wi= ll > > > be easier to handle with floating-point arithmetic there. That would > > > have been difficult to manage for applications a while ago, but now t= hat > > > we have libcamera, we could implement it there. This isn't high on my > > > todo list though. > > > > While indeed that would probably be a better way to handle the complex > > logic if we designed the driver today, we already have userspace that > > expects the timestamps to be handled correctly in the kernel. I > > suspect moving it to the userspace would require some core V4L2 > > changes to define a new timestamp handling mode, where multiple raw > > hardware timestamps are exposed to the userspace, instead of the high > > level system monotonic one. > > The uvcvideo driver already supports exposing the packet headers to > userspace through a metadata capture device, so I think we have all the > components we need. The only missing thing would be the implementation > in libcamera :-) We would still have to duplicate the quirk information in libcamera and the kernel. > > -- > Regards, > > Laurent Pinchart -- Ricardo Ribalda