umlaeute / v4l2loopback

v4l2-loopback device
GNU General Public License v2.0
3.61k stars 515 forks source link

getUserMedia returns MediaStreamTrack with readyState ended in Chromium #540

Closed aleiby closed 1 year ago

aleiby commented 1 year ago

I am loading v4l2loopback using:

insmod v4l2loopback.ko video_nr=10 card_label="test" exclusive_caps=1 max_buffers=2

If I do not use exclusive_caps=1, then Chromium fails to open the device entirely. I think max_buffers=2 is now the default, so that is unnecessary, but included just in case.

I can use ffplay to preview the video stream, however, it only displays a single frame. That frame updates to the latest if I relaunch it, but it never animates, instead gets stuck on the first frame that it displays. I suspect this is a clue.

To feed frames, I am using:

struct v4l2_format format;
memset( &format, 0, sizeof( format ) );
format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
format.fmt.pix.width = k_nWidth;
format.fmt.pix.height = k_nHeight;
format.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420;
format.fmt.pix.field = V4L2_FIELD_NONE;
ioctl( fd, VIDIOC_S_FMT, &format );

enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
ioctl( fd, VIDIOC_STREAMON, &type );

write( fd, buffer, buffer_size );

This is in a loop that sleeps for 33ms between updates, so I'm likely feeding somewhat less than 30fps.

I'm not seeing any errors in the kernel log.

Chromium is finding the video feed just fine, but readyState is always ended. Occasionally, I will get a single static image shown in browser (similar behavior to ffplay), but usually just get solid black output.

Expected Results:

umlaeute commented 1 year ago

Please try again with current main at https://github.com/umlaeute/v4l2loopback/commit/1d01a4156cd22ff25d015079cbb731078fa89ead