[PATCH v1 6/8] media: uvcvideo: Allow hw clock updates with buffers not full

From: Ricardo Ribalda
Date: Tue Sep 20 2022 - 10:09:18 EST


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.

Signed-off-by: Ricardo Ribalda <ribalda@xxxxxxxxxxxx>

diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index 75c32e232f5d..7c7fb478aef7 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -742,10 +742,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];
last = &clock->samples[(clock->head - 1) % clock->size];

/* First step, PTS to SOF conversion. */

--
b4 0.11.0-dev-d93f8