Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix read_position and write_position tracking #536

Merged
merged 2 commits into from
Apr 12, 2023

Conversation

asahilina
Copy link
Contributor

This reverts a commit that tried to make those two variables wrap to avoid overflow, but which broke the whole tracking logic since the rest of the code doesn't expect that (on top of other issues). It's not obvious how to refactor the rest of the code to use wrapping buffer indices correctly.

Instead, this switches the indices to 64-bit, which should eliminate any concerns about them ever wrapping.

(I'm actually not sure how this ever worked for anyone, it completely broke v4l2loopback for me...)

Fixes: #535

This reverts commit 7c4ca0d.

The commit introduced a bug where mod_inc returned the incremented
value, while the places it is used in expected the previous value.
Additionally, the rest of the logic for tracking buffer positions does
not work when the read_position and write_position wrap around, since
they are directly compared.

In particular, in that model, it is impossible to distinguish the case
of all buffers full vs. all buffers empty, since both pointers will be
equal in both cases. So a more thorough refactor is necessary to fix
that...

Let's revert this for now, since it breaks everything as it stands.

Fixes: umlaeute#535
Signed-off-by: Asahi Lina <lina@asahilina.net>
This basically solves the same problem that 7c4ca0d tried to solve.

It is practically impossible for a 64-bit type to actually overflow (it
would take 4 billion years of 60 FPS frames), and this avoids having to
do a much more thorough refactor to switch to wrapping buffer indices
with the extra requirement of tracking buffer fullness separately.

I checked that all of the usages should promote/truncate properly: (s64)
(OP) (s32 or u32) should always promote to 64-bit, and all of the
references to read_position and write_position are either direct
comparisons or apply a modulo before storing into a smaller type, except
for one which this commit fixes.

Signed-off-by: Asahi Lina <lina@asahilina.net>
@umlaeute umlaeute merged commit 9f51281 into umlaeute:main Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gst-launch-1.0 stops at first frame
2 participants