Re: [PATCH v3 6/6] media: uvcvideo: Only do uvc_video_get_time() if needed
From: Yunke Cao
Date: Thu May 14 2026 - 05:42:07 EST
Hi Ricardo,
I tested v3 and verified that it fixes the hw timestamp for the
SunplusIT Inc 1080p FHD Camera (2b7e:c877).
Tested-by: Yunke Cao <yunkec@xxxxxxxxxx>
Best,
Yunke
On Wed, May 13, 2026 at 8:49 PM Ricardo Ribalda <ribalda@xxxxxxxxxxxx> wrote:
>
> There is no need to calculate the current time if the sample is going to
> be filtered.
>
> Move the assignment close to uvc_video_clock_add_sample().
>
> Suggested-by: Hans de Goede <hansg@xxxxxxxxxx>
> Signed-off-by: Ricardo Ribalda <ribalda@xxxxxxxxxxxx>
> ---
> drivers/media/usb/uvc/uvc_video.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
> index 6794031cd0fb..1cc86a18b2bb 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -645,8 +645,6 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf,
> if (stream->dev->quirks & UVC_QUIRK_INVALID_DEVICE_SOF)
> sample.dev_sof = sample.host_sof;
>
> - sample.host_time = uvc_video_get_time();
> -
> /*
> * The UVC specification allows device implementations that can't obtain
> * the USB frame number to keep their own frame counters as long as they
> @@ -687,6 +685,9 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf,
> (UVC_MIN_HW_TIMESTAMP_DIFF / stream->clock.size))
> return;
>
> + /* This is expensive, only do it if the sample will be added. */
> + sample.host_time = uvc_video_get_time();
> +
> uvc_video_clock_add_sample(&stream->clock, &sample);
> stream->clock.last_sof_processed = sample.dev_sof;
> }
>
> --
> 2.54.0.563.g4f69b47b94-goog
>