From f9bac4889c1015ebcea988fd7e2067668171bbc7 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Sat, 30 Mar 2024 13:57:43 +0100 Subject: [PATCH] v4l2: Drop the first frame after camera startup A quite big number of UVC cameras - due to firmware or kernel driver issues - have bad timestamps of the first frame, confusing clients like pipewiresrc. Drop the first frame, as this seems to be the most reliable workaround for the time being. Closes https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/3910 --- spa/plugins/v4l2/v4l2-utils.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c index 3dcc6f293..ab9d3aec9 100644 --- a/spa/plugins/v4l2/v4l2-utils.c +++ b/spa/plugins/v4l2/v4l2-utils.c @@ -1369,6 +1369,11 @@ static int mmap_read(struct impl *this) if (xioctl(dev->fd, VIDIOC_DQBUF, &buf) < 0) return -errno; + /* Drop the first frame in order to work around common firmware + * timestamp issues */ + if (buf.sequence == 0) + return 0; + pts = SPA_TIMEVAL_TO_NSEC(&buf.timestamp); spa_log_trace(this->log, "v4l2 %p: have output %d", this, buf.index);