From mboxrd@z Thu Jan 1 00:00:00 1970 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 7910A38887B for ; Tue, 12 May 2026 12:31:10 +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=1778589075; cv=none; b=Hi2SipUowdnP4ERIqlnNLTaPCek7uyYv12+MQg7tCBwnarzUFv5dY01QL6RAhRrC9Ma9fLTQTr3SSAP7mlgBjixV7wt578XIGF80AUGdKfGHyF5b5NApUZtcwljj8H5Do9j1GstvGS9/edLaJityoiSRJd96kgqDgl1Gl+H6PTM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778589075; c=relaxed/simple; bh=PyPstSDPnSS7go2Eeoifto3b0yR6kerSh2wHnfrgQC8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nGi8JMORYbCj9SRB2hHLi2ZHZjrWj4PAUys89XWp1Cv0Lr1t2yPl/RPy4x+iKiIMC2mhSYatJPPKlxHAiiFLU0mPF8FIeIuB+b7RBLrtnx57qfFrNienLtx/krJaAOav2cqa1k0x65v6ui12YVROeEy6C6o7g7Ak2m6sqTbNB2o= 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=DWKZPVYu; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="DWKZPVYu" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-5a62f43b76aso4717817e87.3 for ; Tue, 12 May 2026 05:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1778589066; x=1779193866; 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=tn8yR9axPkcG+PDvfr1W0s/qaLqZqhB6pcQAbzPTKls=; b=DWKZPVYuipI5YjoJWvErpuVrVH+RQ3HKWEZlL9o7QygdYY5/0lmuC2NIbFa0yUPuSg R9TdzCaeKAodbc5z8Z4KXXZ+OTkSCHNgjw45kLDh2ze19sH+vNmd4M7sY1+S1wUAI7vQ 9diag2lx/ra+l5UoEApLcJP02XDCDhTzhzkDU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778589066; x=1779193866; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=tn8yR9axPkcG+PDvfr1W0s/qaLqZqhB6pcQAbzPTKls=; b=M2OJ2f/lKNZc0ORxxcRqTxkFidgjQwlyNydd0tUUnP7veePXSVFCneYHueIzEYeXKG /FoXQ44myNtzMebKxoPx4Ttx/9wS6OtAqeTmis6H0wSh7rvysmtpfyN95rKPLBm3IIeZ yKC3KH1XFh1PsoU9ABm2h6ERfiiogfUtfsGSmt9ddK1IpBCcHG79IpNjwa/YHSgQq210 jP0iWgjYV7z6xPc8rLPICJAsCrikBRne22X4kOIlZOH9OZvV9uJ4AhM4t7Ef03r4y4LV mySPbc3bYXr6SQxVzItLcGXBm3DmD7DTrU445ATr9izAnkG7AGmZ3IFIMZrgmEwCzsOS LPpA== X-Forwarded-Encrypted: i=1; AFNElJ8LeLzdEZbyhVwgkBQJmG0AL7WOnh82TEk2ISDr595YT4QgFYumqcwrdV8EyO14f9JzIt/AaAot8pPGoJA=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/+RoJeQKvuipgpq0vamU/2xsmgoqiZK/65b7y8k18tjwUwgeH Qnks+m4ksM5hsggm1008OB0gYIA/7t4YDC2vX8GksZ7RaTH7TLSo62SzSZEHCUjsmg== X-Gm-Gg: Acq92OEjtHUaEdggnxAuVsT3nm3SLOqDEcAN72BW4NIbM27/RW9lYQ90sjC02frGHal VHm7vbQKe4QMzuizonGHtC3s0hWops85nD0ybdHBMFkdKh2c6qluB6cZGX3bkAIKPKXjqK2G/9F gSuQzeaer+/ZqdQZ4A3s9h6O5yM27GWM3R1g5D/d2grd9MWzGa+dlgyKA1r/68BW3qW7gIAJNKU TrF6Uq++be9eYksc+9dcX8tIsjIgk6vRrM9UPg4/0Sp9ttDjbHas5EJ8eEhUvSWWkiEMpEGs5OM ZUzFJ3PluRGajhgb733JJJbzd6z4YAgP1dOmazvsplDgR7g/kS9/HY8yVAOmQ7r7nb7khuYCtV+ 0tD9f+VqoykyIOZRqoR1oMDhe4r/nk20W5GMDvfrWTxTQ0EMYl8LvPNncB1f5p+sa9CZS/ftfJt onVKGZrUYXwcJITknd7lYiYFFsn6Lm/9IXNifwCwJmdKTyJr3SNb8lUm9lCrpCsvZ/e4afPahSS Q== X-Received: by 2002:a05:6512:23aa:b0:5a8:9135:128a with SMTP id 2adb3069b0e04-5a891351b9bmr7594663e87.15.1778589065945; Tue, 12 May 2026 05:31:05 -0700 (PDT) Received: from ribalda.c.googlers.com (11.36.88.34.bc.googleusercontent.com. [34.88.36.11]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5a8c66facc2sm1861344e87.22.2026.05.12.05.31.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 05:31:04 -0700 (PDT) From: Ricardo Ribalda Date: Tue, 12 May 2026 12:30:56 +0000 Subject: [PATCH v2 2/5] media: uvcvideo: Use hw timestaming if the clock buffer is 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: <20260512-uvc-hwtimestamp-v2-2-3c2905c733bb@chromium.org> References: <20260512-uvc-hwtimestamp-v2-0-3c2905c733bb@chromium.org> In-Reply-To: <20260512-uvc-hwtimestamp-v2-0-3c2905c733bb@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Tomasz Figa , Sergey Senozhatsky Cc: Yunke Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , stable@vger.kernel.org, Hans de Goede X-Mailer: b4 0.14.3 In some situations, even with a full clock buffer, it does not contain 250msec of data. This results in the driver jumping back from software to hardware timestapsing creating a nasty artifact in the video. If the clock buffer is full, use it to calculate the timestamp instead of defaulting to software stamps, the reduced accuracy is less visible than jumping from one timestamping mechanism to the other. Fixes: 6243c83be6ee8 ("media: uvcvideo: Allow hw clock updates with buffers not full") Cc: stable@vger.kernel.org Reviewed-by: Hans de Goede Tested-by: Yunke Cao Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_video.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index cbf67c17a49a..19a2880e0dc9 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -834,15 +834,22 @@ void uvc_video_clock_update(struct uvc_streaming *stream, 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. + * If the buffer is not full, we want to gather at least 1/4th of + * timestamps before using HW timestamping. We do this to avoid jitter + * on the initial frames. + * + * If the buffer is full we would use it regardless of how much data + * it represents. This could be solved with an infinite big circular + * buffer, but RAM is expensive these days, specially the infinitely + * big. + * + * The value of 1/4th of a second was determined by running Android's + * 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)) + if (clock->size != clock->count && (y2 - y1) < ((1000 / 4) << 16)) goto done; y = (u64)(y2 - y1) * (1ULL << 31) + (u64)y1 * (u64)x2 -- 2.54.0.563.g4f69b47b94-goog