Ubuntu port of v4l2loopback doesn't behave the same as official port (v0.12.5)

Bug #1946660 reported by Brett D
172
This bug affects 40 people
Affects Status Importance Assigned to Milestone
v4l2loopback (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

Apps like OBS, which use v4l2loopback to create virtual cameras, have started losing their ability to create virtual cameras. In the case of OBS, it's able to create a camera one time. When the camera or app is "shutdown" the camera is unable to be created again unless a user manually removes the modprobe rule with "sudo modprobe -r v4l2loopback"

Ubuntu 20.04 comes with "0.12.5-1ubuntu1". That version seems to exhibit this behavior.

If you "downgrade" to "0.12.5-1" from https://packages.ubuntu.com/groovy/all/v4l2loopback-dkms/download the problem is gone.

The author of v4l2loopback indicates this "is a problem with Ubuntu specific modifications" and it should be reported here.

This is documented here:
https://github.com/umlaeute/v4l2loopback/issues/404
https://github.com/obsproject/obs-studio/issues/4808

ProblemType: Bug
DistroRelease: Ubuntu 21.04
Package: v4l2loopback-dkms 0.12.5-1ubuntu1
ProcVersionSignature: Ubuntu 5.11.0-37.41-generic 5.11.22
Uname: Linux 5.11.0-37-generic x86_64
ApportVersion: 2.20.11-0ubuntu65.3
Architecture: amd64
CasperMD5CheckResult: unknown
CurrentDesktop: ubuntu:GNOME
Date: Mon Oct 11 08:50:33 2021
InstallationDate: Installed on 2020-05-01 (527 days ago)
InstallationMedia: Ubuntu 20.04 LTS "Focal Fossa" - Release amd64 (20200423)
PackageArchitecture: all
ProcEnviron:
 TERM=xterm-256color
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: v4l2loopback
UpgradeStatus: Upgraded to hirsute on 2021-06-03 (130 days ago)

Revision history for this message
Brett D (brettface) wrote :
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in v4l2loopback (Ubuntu):
status: New → Confirmed
Revision history for this message
Boris Erdmann (boris-erdmann) wrote :

This bug is still present in v4l2loopback-dkms_0.12.5-1ubuntu3 on impish.

Revision history for this message
Bruce Lerner (1-bruce) wrote :

This bug affects me.

Revision history for this message
Mark Junker (fubar-coder-k) wrote :

This bug affects me.

Revision history for this message
Boris Erdmann (boris-erdmann) wrote :

To those who just wrote "This bug affects me": Please log in and follow this link:
https://bugs.launchpad.net/ubuntu/+source/v4l2loopback/+bug/1946660/+affectsmetoo

Revision history for this message
Israel Teixeira de Andrade (israeltandrade) wrote :

This bug affects me.

Revision history for this message
You-Sheng Yang (vicamo) wrote (last edit ):

The first open has:
```
[17047.368576] v4l2-loopback[1992]: opened dev:00000000c093a43d with image:0000000000000000
[17047.368577] /var/lib/dkms/v4l2loopback/0.12.5/build/v4l2loopback.c:1993[v4l2_loopback_open]
[17047.368582] video10: VIDIOC_QUERYCAP: driver=v4l2 loopback, card=OBS Video Source, bus=platform:v4l2loopback-000, version=0x00050f07, capabilities=0x
85200002, device_caps=0x05200002
```

The second open has:
```
[17091.427287] /var/lib/dkms/v4l2loopback/0.12.5/build/v4l2loopback.c:1964[v4l2_loopback_open]
[17091.427292] v4l2-loopback[1992]: opened dev:00000000c093a43d with image:0000000000000000
[17091.427293] /var/lib/dkms/v4l2loopback/0.12.5/build/v4l2loopback.c:1993[v4l2_loopback_open]
[17091.427297] video10: VIDIOC_QUERYCAP: driver=v4l2 loopback, card=OBS Video Source, bus=platform:v4l2loopback-000, version=0x00050f07, capabilities=0x85200000, device_caps=0x05200000
[17091.427304] video10: VIDIOC_G_FMT: error -22: type=vid-out, width=4294966992, height=4294967295, pixelformat=.... little-endian (0x00000000), field=any, bytesperline=1401200640, sizeimage=4288352138, colorspace=-744513136, flags=0xfffffed0, ycbcr_enc=0, quantization=0, xfer_func=0
```

As indicated in the capabilities field returned from the VIDIOC_QUERYCAP call, 0x85200000 means no V4L2_CAP_VIDEO_CAPTURE(0x01) neither V4L2_CAP_VIDEO_OUTPUT(0x02) is set. And since it reports neither, kernel `check_fmt` in "drivers/media/v4l2-core/v4l2-ioctl.c" will evaluate variable is_vid to false, and therefore returns -EINVAL at the next `VIDIOC_G_FMT` call with type=`V4L2_BUF_TYPE_VIDEO_OUTPUT`.

This is a direct result from https://github.com/umlaeute/v4l2loopback/commit/9a77eb6 merged in https://github.com/umlaeute/v4l2loopback/pull/415.

Revision history for this message
You-Sheng Yang (vicamo) wrote :

Per inspection result from above comment, the behavior is actually a bug in the upstream v4l2loopback source, function v4l2_loopback_write:

  /* there's at least one writer, so don'stop announcing output capabilities */
  dev->ready_for_output = 0;

Which set `dev->ready_for_output` to zero without correcting its `dev->type`.

Revision history for this message
You-Sheng Yang (vicamo) wrote :

Continue discuss on upstream issue https://github.com/umlaeute/v4l2loopback/issues/404. Stay tuned.

Revision history for this message
Mark Tompkins (mets5273) wrote :

The issue persists into 22.04

Revision history for this message
Martin Wimpress  (flexiondotorg) wrote (last edit ):

For Ubuntu users, I've made a PPA containing builds of `v4l2loopback` for 20.04 (Focal), 21.10 (Impish), 22.04 (Jammy), 22.10 (Kinetic) that includes backports of the following patches:

 🩹 https://github.com/umlaeute/v4l2loopback/pull/477
 🩹 https://github.com/umlaeute/v4l2loopback/pull/485

The patch above fixes the ability to start/stop the Virtual Camera in OBS many times. It "works for me"™

The PPA is here:

 📦 https://launchpad.net/~flexiondotorg/+archive/ubuntu/v4l2loopback

Feedback welcome. If this fix works widely, I'll work towards landing in the official packages for Ubuntu.

Revision history for this message
Boris Erdmann (boris-erdmann) wrote :

Martin,

thanks a lot for providing that. I would like to confirm that it works now, but I was on the downgraded original version 0.12.5-1 before and replacing it with your package leaves me with

$ find /lib/modules/ | grep v4l2loopback.ko
/lib/modules/5.15.0-40-generic/kernel/v4l2loopback/v4l2loopback.ko
/lib/modules/5.15.0-41-generic/kernel/v4l2loopback/v4l2loopback.ko
/lib/modules/5.15.0-40-lowlatency/kernel/v4l2loopback/v4l2loopback.ko
/lib/modules/5.15.0-41-lowlatency/kernel/v4l2loopback/v4l2loopback.ko
/lib/modules/5.15.0-41-lowlatency/updates/dkms/v4l2loopback.ko

How can I be sure that the new module is actually loaded (given that I am currently running 5.15.0-41-lowlatency)? You can also see that the new module was built only for the kernel running at install time.

Revision history for this message
Brandon Whaley (redkrieg) wrote :

Martin's PPA version works for me on Jammy. See if your srcversion matches mine maybe?

redkrieg@cortex-1:~$ modinfo v4l2loopback
filename: /lib/modules/5.17.15-76051715-generic/extra/v4l2loopback.ko
license: GPL
author: Vasily Levin, IOhannes m zmoelnig <email address hidden>,Stefan Diewald,Anton Novikovet al.
description: V4L2 loopback video device
srcversion: B6031838219D91DE046F379
depends: videodev
retpoline: Y
name: v4l2loopback
vermagic: 5.17.15-76051715-generic SMP preempt mod_unload modversions
parm: debug:debugging level (higher values == more verbose) (int)
parm: max_buffers:how many buffers should be allocated (int)
parm: max_openers:how many users can open loopback device (int)
parm: devices:how many devices should be created (int)
parm: video_nr:video device numbers (-1=auto, 0=/dev/video0, etc.) (array of int)
parm: card_label:card labels for every device (array of charp)
parm: exclusive_caps:whether to announce OUTPUT/CAPTURE capabilities exclusively or not (array of bool)
parm: max_width:maximum frame width (int)
parm: max_height:maximum frame height (int)
redkrieg@cortex-1:~$ ls -hal /lib/modules/5.17.15-76051715-generic/extra/v4l2loopback.ko
-rw-r--r-- 1 root root 91K Jul 15 10:09 /lib/modules/5.17.15-76051715-generic/extra/v4l2loopback.ko

Revision history for this message
Fabien Gagné (fabiengagne) wrote :

I confirm that the issue is in Kubuntu 22.04 LTS as well.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.