Skip to content

Add support for v4l2loopback device#346

Open
wuhanstudio wants to merge 1 commit intojacksonliam:masterfrom
wuhanstudio:v4l2loop
Open

Add support for v4l2loopback device#346
wuhanstudio wants to merge 1 commit intojacksonliam:masterfrom
wuhanstudio:v4l2loop

Conversation

@wuhanstudio
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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