[vlc-commits] [Git][videolan/vlc][master] v4l2: access: wait for the frame instead of dropping it
Steve Lhomme (@robUx4)
gitlab at videolan.org
Wed Aug 26 07:31:58 UTC 2026
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
34846487 by Alexandre Janniaux at 2026-08-26T07:17:39+00:00
v4l2: access: wait for the frame instead of dropping it
AccessPoll() is returning the same kind of result as poll(), meaning:
* +1 if a frame is available
* -1 in case of error
Since we were checking `if (AccessPoll(access))` in the caller, it was
already read as a failure. The frame that just became available is
dropped, and the core would re-trigger the demux calling `AccessPoll()`
again. So the wait never waits and no frame is ever read, leading to a
busy loop.
The code was correct in cfb23eb2deff866f6ae47c6ce90473ffaf79af6a when it
was written since it used VLC_SUCCESS-like convention, but the refactor
in 57d784d7a7e8272d81a6f1847e0593c802f458f9 to remove the polling timer
actually broke it by reverting the semantic (here, returning value from
poll() directly means success is 1) without changing the call sites.
It only affects v4l2c:// and not v4l2:// since the latter one was
checking against -1 directly.
Reproduced on an Logitech USB camera (046d:0825) with:
vlc -vv --v4l2-chroma=MJPG v4l2c:///dev/video2
The video was not playing before and is playing after this commit.
- - - - -
1 changed file:
- modules/access/v4l2/access.c
Changes:
=====================================
modules/access/v4l2/access.c
=====================================
@@ -47,7 +47,12 @@ typedef struct
vlc_v4l2_ctrl_t *controls;
} access_sys_t;
-/* Wait for data */
+/**
+ * Wait for data
+ *
+ * \retval 1 when a frame is ready
+ * \retval -1 when the wait was cancelled or failed
+ */
static int AccessPoll(stream_t *access)
{
access_sys_t *sys = access->p_sys;
@@ -63,7 +68,7 @@ static block_t *MMapBlock(stream_t *access, bool *restrict eof)
{
access_sys_t *sys = access->p_sys;
- if (AccessPoll(access))
+ if (AccessPoll(access) < 0)
return NULL;
block_t *block = GrabVideo(VLC_OBJECT(access), sys->pool);
@@ -80,7 +85,7 @@ static block_t *ReadBlock(stream_t *access, bool *restrict eof)
{
access_sys_t *sys = access->p_sys;
- if (AccessPoll(access))
+ if (AccessPoll(access) < 0)
return NULL;
block_t *block = block_Alloc(sys->blocksize);
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/348464878bd258293b464098ecc997adef57e016
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/348464878bd258293b464098ecc997adef57e016
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help
More information about the vlc-commits
mailing list