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

Allow repeat REQBUF when buffers not mapped #599

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stephematician
Copy link
Contributor

@stephematician stephematician commented Oct 22, 2024

Allow repeated VIDIOC_REQBUF when no buffers are mapped (fix #598) by:

  1. Setting ready_for_output back to 1 in vidioc_streamoff.
  2. Checking that buffers are not mapped in vidioc_reqbufs when ready-for-output is true.

I hope I haven't messed up the logic for dev->ready_for_output. The comments suggest:

set to true when no writer is currently attached

More precisely, it looked to me like it was initialised as true and set to false (only) once vidioc_streamon is called - i.e. when the output process is started in streaming (memory mapping) I/O. Thus it should be safe to return it to true once vidioc_streamoff is called.

I contemplated whether I also needed to add a check that the opener is assigned WRITER type in stream-off, but have left it out for now, e.g.:

--- a/v4l2loopback.c
+++ b/v4l2loopback.c
@@ -1964,7 +1964,8 @@ static int vidioc_streamoff(struct file *file, void *fh,
        case V4L2_BUF_TYPE_VIDEO_OUTPUT:
                if (dev->ready_for_capture > 0)
                        dev->ready_for_capture--;
-                dev->ready_for_output = 1;
+                if (opener->type == WRITER)
+                        dev->ready_for_output = 1;
                return 0;

@stephematician
Copy link
Contributor Author

stephematician commented Nov 8, 2024

I added the test of opener->type when setting ready-for-output (and decrementing ready-for-capture) in STREAMOFF.

I wouldn't mind some feedback about what the expected behaviour of ready-for-output and ready-for-capture are in order to tidy up the logic. Otherwise, happy to leave things as they are.

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.

Allow REQBUF to change number of buffers
1 participant