Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1659209lqp; Sat, 23 Mar 2024 03:49:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVsUY64cxgxNDdmNG1MvEoTDH/JxdOBqmZ21sov2EYk3az6hL4ZfCl1ZORH8jMkj2VPOIZRUzvJ4trH+qqLlLRYO9EsbVc8+YrAq0eKgA== X-Google-Smtp-Source: AGHT+IFBdvg0A3U7MUrMpg0PR+wzV+Se91HQD3aEEJcVNqs0DdHZXQkxGwkj9ZQEwWuTJDaOVkYH X-Received: by 2002:a05:620a:10ab:b0:789:f7d5:806 with SMTP id h11-20020a05620a10ab00b00789f7d50806mr1904551qkk.68.1711190941914; Sat, 23 Mar 2024 03:49:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711190941; cv=pass; d=google.com; s=arc-20160816; b=J1e8UYTLKKkk5pyRaz9t5XZCiT+0uBYMzWrG3FA9jn3xdgIOCkvhaMaC9DTPzpXLYS 0PZlZZt+zpPDvzdxFgTjDTlCz6XYGPVNREe9/YEdh5SLKzpxPjLw7PmzRjmlGTvGMHLU FNbJRSMdxDUgj/vYkm2VzLaq0Fe4/hrZKOSKJFgnkuT+TsqaKkBsFSQes5wJeq84aJcC VEEv1dcModeiF9KdXqxToY0Bva990q8ICHvDel3tpzHznlo6nNO4cSUuR8OseU/iIqON 9Ki9OYpY62+NU2tMWegaYjxHUuxpbn4Nk+zbqLxBAKVeQ38A15mQYhUga7qDkG5q+1SZ KJZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=x5G2djWTL13MD8rXHjsRG2jZyEe2Cc3TE16Y80waKos=; fh=BSwFOCBLKYw5xKcHLtfPIgG14cmzWEl4hfLZpytqHwY=; b=zCw05a7bYFd+8Nra5iMYeY169Uv9Th9c9PuraRncdOiNHTE14fXezMHvfabvw+47d4 BZmouskhmmnolUL1rlGSf5z4UdmF3qgme+qPP2oqUAsWi4rI9qv0brWPaJjgh8TEwxc0 rX2s9Fo5v/LYQZFWbmiE85Sm1WHg+42KWpqAo9xcqJ3LPrQT3z1nH8z3gX/qsGoJ6E1m DuMMPIWDb1k1IsxsKHWeFZWZdLMcHMjefmvMuPDtLyFB6GhkahA26hoDPw78J2hiCc66 VgMrojhAgEfZBQC3rL3LMWziCJOyym2SFT2jYTpVCRgVYPpNMBxpeSa5hOa7YOp0njM6 cYRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HVyLjloh; 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-112303-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112303-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. [147.75.199.223]) by mx.google.com with ESMTPS id bk29-20020a05620a1a1d00b00789e7e8dae2si1551549qkb.278.2024.03.23.03.49.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 03:49:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112303-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HVyLjloh; 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-112303-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112303-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 A3BE71C20CEA for ; Sat, 23 Mar 2024 10:49:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C2333D0CD; Sat, 23 Mar 2024 10:48:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="HVyLjloh" Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (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 7ED5518E2E for ; Sat, 23 Mar 2024 10:48:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711190890; cv=none; b=otdwJ0OK+ylQ4wVUtBUHWxtcQb9qsJM8f7DvsZKq/zNnaimSv7vpiRDNms3GSUmgQxWqLT2cYSkbfa/NWO6kmQ3LtST8bIMqAH46cXT0jO5SghqoygIhHIifMMg6LI7JokGmyU+JcEZBr4jSZBTW5iDP68VL3CP44NoDO8+5afs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711190890; c=relaxed/simple; bh=OG7cqgYYJHmKhCVqrEDvi6pknnHix48HG0gMtSmw6ow=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=A2kgdR1mJYz6CQgFaVSMWByTOtMqIi/I7MT38F3/pgo6yJq3k+snfkvMPm0lknFqbzz6v1+VoWHq7av5svxc/SsGTReqi+bl7nUsPYDwKvSRtzensJLA6emMUCpgIyGCnodJ6l4hIv7D6KryVCaj0j00t9rZMppwsElRf1rINAo= 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=HVyLjloh; arc=none smtp.client-ip=209.85.160.173 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-qt1-f173.google.com with SMTP id d75a77b69052e-42ee23c64e3so13131341cf.2 for ; Sat, 23 Mar 2024 03:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1711190887; x=1711795687; darn=vger.kernel.org; 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=x5G2djWTL13MD8rXHjsRG2jZyEe2Cc3TE16Y80waKos=; b=HVyLjlohv+ScpexbtjpiuJvVNuVFz9MCsSLdi5rp+mlOigfCmYoRLwIv7zxEeUL1ZN IR2UIJ+g8k8K0t++tiwTiV+1Key+Sl0Olp38+AXzH6kVj4TDG4oABXNiS4troUX7qzYO FXRR6ZJA92tIfbmuNgFqCSR1PANDQlhfhGmDE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711190887; x=1711795687; 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=x5G2djWTL13MD8rXHjsRG2jZyEe2Cc3TE16Y80waKos=; b=lwW3iGMS0IJ7vPwCYPRi08tOor30fp+wGdrBVx0wY5jNSvEoPuL499/AC2auyIVW91 YC0A0SnHAPYBEGdtvb2YwE2W9ymlO4h5Nd4yI0iZfapW7MIT49wuDHXdBtwB+tBnRNG2 AHlI9eCZ11dD+4+SiDUWKYm8j/2bcqxZHUHBjUyUfJMoeu0eo8LjkGRPGeytXcPYoFLk PU+Wu0zfcS7xuDSdhRsb+er5YfL2ciclyWA4NRoK7+SZ7wcVNB0sdsijimF1TNWnGkUn b8InIFa+Sldy8vL1CRkBma784zInzp726yxc84Swik+0MYLyPQPtEzMV//MIemdERlNj hZvQ== X-Forwarded-Encrypted: i=1; AJvYcCVEZap/HsdiN0p9U0j3NFyFNZFwjHVXPPbXmOIkST0T4FanXRz4PNZ5dpJyAqUR0CSPltVL1z6NjerFfyrxqgtnr+nqc4vs04DMjN9M X-Gm-Message-State: AOJu0YwVDadgHDF79Ih13X214D7FCrxlNcqDmEOf85QI2c6nbolblqSD ec/JEM/7c4VMhT2F+vdz/4ZHGSvGc9ZJcLw7PVtN+Dtm8W5fmioRXubOt5c7ig== X-Received: by 2002:a05:622a:1716:b0:431:33ec:be16 with SMTP id h22-20020a05622a171600b0043133ecbe16mr2085146qtk.51.1711190887472; Sat, 23 Mar 2024 03:48:07 -0700 (PDT) Received: from denia.c.googlers.com (188.173.86.34.bc.googleusercontent.com. [34.86.173.188]) by smtp.gmail.com with ESMTPSA id gd14-20020a05622a5c0e00b0042f21fe66f7sm697213qtb.73.2024.03.23.03.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 03:48:07 -0700 (PDT) From: Ricardo Ribalda Date: Sat, 23 Mar 2024 10:48:05 +0000 Subject: [PATCH v10 4/6] media: uvcvideo: Allow hw clock updates with buffers not full 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240323-resend-hwtimestamp-v10-4-b08e590d97c7@chromium.org> References: <20240323-resend-hwtimestamp-v10-0-b08e590d97c7@chromium.org> In-Reply-To: <20240323-resend-hwtimestamp-v10-0-b08e590d97c7@chromium.org> To: Laurent Pinchart , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, "hn.chen" , Hans Verkuil , Ricardo Ribalda , Sergey Senozhatsky X-Mailer: b4 0.12.4 With UVC 1.5 we get as little as one clock sample per frame. Which means that it takes 32 frames to move from the software timestamp to the hardware timestamp method. This results in abrupt changes in the timestamping after 32 frames (~1 second), resulting in noticeable artifacts when used for encoding. With this patch we modify the update algorithm to work with whatever 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/usb/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_streaming *stream, spin_lock_irqsave(&clock->lock, flags); - if (clock->count < clock->size) + if (clock->count < 2) goto done; - first = &clock->samples[clock->head]; + first = &clock->samples[(clock->head - clock->count + clock->size) % clock->size]; last = &clock->samples[(clock->head - 1 + clock->size) % clock->size]; /* First step, PTS to SOF conversion. */ @@ -786,6 +786,18 @@ void uvc_video_clock_update(struct uvc_streaming *stream, if (y2 < y1) y2 += 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 CTS + * 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; + y = (u64)(y2 - y1) * (1ULL << 31) + (u64)y1 * (u64)x2 - (u64)y2 * (u64)x1; y = div_u64(y, x2 - x1); -- 2.44.0.396.g6e790dbe36-goog