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 REQBUF to change number of buffers #598

Open
stephematician opened this issue Oct 18, 2024 · 1 comment · May be fixed by #599
Open

Allow REQBUF to change number of buffers #598

stephematician opened this issue Oct 18, 2024 · 1 comment · May be fixed by #599
Assignees
Labels
needs triage new issues

Comments

@stephematician
Copy link
Contributor

According to the V4L API (https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/vidioc-reqbufs.html):

Applications can call ioctl VIDIOC_REQBUFS again to change the number of buffers. Note that if
any buffers are still mapped or exported via DMABUF, then ioctl VIDIOC_REQBUFS can only succeed
if the V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS capability is set. Otherwise ioctl VIDIOC_REQBUFS
will return the EBUSY error code. If V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS is set, then these
buffers are orphaned and will be freed when they are unmapped or when the exported DMABUF fds
are closed. A count value of zero frees or orphans all buffers, after aborting or finishing any
DMA in progress, an implicit VIDIOC_STREAMOFF.

So - if there hasn't been any call to mmap (or munmap has been called on all buffers), shouldn't it be possible to call REQBUF to change the number of buffers?

@stephematician
Copy link
Contributor Author

stephematician commented Oct 20, 2024

Is it as simple as this?

diff --git a/v4l2loopback.c b/v4l2loopback.c
index 25cb1be..4bba805 100644
--- a/v4l2loopback.c
+++ b/v4l2loopback.c
@@ -1959,6 +1959,7 @@ 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;
                return 0;
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
                if (opener->type == READER) {

This is assuming that only one process should be able to streamoff when writing memory mapped I/O.

@stephematician stephematician linked a pull request Oct 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage new issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants