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

Add support for v4l2loopback device #346

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wuhanstudio
Copy link

Hi,

In continuation to the conversation at #280.

This PR adds support for v4l2loopback devices simply by changing NB_BUFFER to 1. It seems like the reason input_uvc does not work is because it uses 4 buffers, while v4l2loopback devices only support 1.

This PR is definitely not a good solution, but a simple workaround. It's much better if we can add a parameter for the number of buffers. What do you think?

I agree with you that:

It does seem strange to create a whole other plugin to get around some bug or missing implementation in v4l2loopback

To reproduce, first, we create two virtual cameras (v4l2loopback devices) from one HD camera:

$ sudo modprobe v4l2loopback video_nr="40,41"
$ git clone https://github.com/wuhanstudio/v4l2loop_clone
$ cd v4l2loop_clone && make
$  ./v4l2loop_clone /dev/video0 /dev/video40 /dev/video41

Now, we can stream the video using mjpg-streamer:

$ git clone https://github.com/wuhanstudio/mjpg-streamer
$ cd mjpg-streamer/mjpg-streamer-experimental/ && make
$ ./mjpg_streamer -i "./input_uvc.so  -r 640x480 -d /dev/video40"  -o "./output_http.so -w ./www"

@jacksonliam
Copy link
Owner

Interesting discovery. I wonder if there's any way to query the v4l2 device to find out how many buffers it supports.
One seems a touch low though. I'd have thought you'd want to double buffer minimum.

@wuhanstudio
Copy link
Author

wuhanstudio commented Mar 15, 2022

Interesting discovery. I wonder if there's any way to query the v4l2 device to find out how many buffers it supports. One seems a touch low though. I'd have thought you'd want to double buffer minimum.

The max number of buffers for v4l2loopback is 2 which is hard-coded according to:

#define V4L2LOOPBACK_DEFAULT_MAX_BUFFERS 2

https://github.com/umlaeute/v4l2loopback/blob/2199283ee936b9930038552b7a0890ec1736e7a2/v4l2loopback.c#L216

  • If we can add an option for input_uvc plugin so that we can set NB_BUFFER, this plugin should work with v4l2loopback devices.
  • Or we may simply set #define NB_BUFFER 2 by default.

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.

2 participants