Repository navigation
linux-v4l2: Fix virtual camera start failure - #11906
Conversation
|
For clarification, is there a reason to hold on to the old behavior for older versions? If the issue is stricter requirements on the v4l2loopback side, wouldn't this just be a backwards compatible change? What breaks in the old versions with this change, or is that untested and just an attempt to not change what has been working? |
|
The existing behaviour should be kept when using loopback <= 0.13.2, otherwise there'll be regression to #4808 An alternative solution: Simply ignore any errors from STREAMON or STREAMOFF. In a way; this would be cleaner - but there is a relatively harmless issue where, say, a user has an older loopback module and STREAMON fails for a legitimate reason. In that case - presumably the next call to |
|
I just remembered I forgot to close the file pointer. Such a noob mistake! |
|
I'm mostly just confused by the presentation of what this is actually fixing. It sounds like this is actually resulting from what was a bug in v4l2loopback, and we had previously put a workaround in place for, and now that bug is fixed (in the name of better compliance, presumably) and the workaround is now causing issues. |
Yes. Sorry, I should have answered your quetion. That is exactly the issue.
Happy to change approach with this PR if needed. |
|
I'll leave the technical specifics to others to comment on, we were just a bit confused on the context around this. Makes perfect sense now, thanks! |
I can relate. It took me a ridiculously long time to get my head about the loopback module as I was updating it. Thanks for your questions! |
|
FWIW: the "simpler" fix would be to treat the failed STREAMON (or STREAMOFF) as an info/warning message and not an error; e.g. in if (ioctl(vcam->device, VIDIOC_STREAMON, &parm) < 0) {
- blog(LOG_ERROR, "Failed to start streaming on '%s' (%s)", device, strerror(errno));
- goto fail_close_device;
+ if (errno == -EINVAL) {
+ blog(LOG_INFO, "EINVAL returned from loopback STREAMON, likely an error in loopback version <= 0.13.2");
+ } else {
+ blog(LOG_ERROR, "Failed to start streaming on '%s' (%s)", device, strerror(errno));
+ goto fail_close_device;
+ }
}
blog(LOG_INFO, "Virtual camera started"); |
9b2e9c0 to
770881a
Compare
|
Somewhat tidied up; also noticed that the dimensions (and pixel format) returned by S_FMT were being ignored; which can lead to unexpected behaviour if the (virtual) device chooses a different size (or pixel format) to the request. So that's fixed now, too. |
770881a to
059f980
Compare
059f980 to
21811fb
Compare
kkartaltepe
left a comment
There was a problem hiding this comment.
First commit is fine. The 2nd commit changes a bit too much can we split it out into another PR so we can merge this one right now?
|
Sure, no problem; I didn't carefully plan the second commit - it just sort of "happened" when I had a closer look at the sequence. |
21811fb to
f61e479
Compare
74c3fa0 to
e340a44
Compare
|
Just compiled the branch in an arch linux and can confirm virtual camera works again. Thanks a lot! |
Yea we probably need to just do this to support flatpak since we cannot query modules and at least from v4l2-ctrl it looks like v4l2loopback does not actually report its version in the device query. |
Good to know. I haven't been able to figure out how to test in Flatpak (is there a guide?). I assume when you say:
you mean to say that it's not worth it to resolve this bug? Would it makes sense to do a "hybrid" of the two fixes? E.g. attempt to read the version;
This means that at least for non-flatpak; the non-compliant calls are eliminated.
Correct; most (?) devices report the kernel version; not the "out-of-tree" version - so it doesn't seem useful to us. There is also a third possibility that might be better altogether... Instead of testing the version of the loopback module - test for the fault that occurs when the STREAMON is not called in earlier versions. If the fault appears; then try the STREAMON as a potential fix. Only then declare that the device could not be opened. |
The more I think about it; the more I'd rather go in this direction. The original problem was that a virtual camera could not be (re)started; it would report no OUTPUT capability. By some quirk of the 0.12.5 loopback code; this could be avoided by calling STREAMON every time the device was opened, because this had the result that when the device was closed it would reset its capabilities correctly. Proposed solution When the loopback is opened; the OUTPUT capability is tested:
|
|
Thanks for your patience everyone; I'm the monster that broke this when fixing up v4l2loopback - but there was no other way to keep the module compliant with the kernel. I wasn't expecting an OBS PR to fall on my shoulders, too, so this has taken much longer than if someone with experience in flatpak environment development was running the lead. |
|
You have nothing to apologize for, nor has anyone else here for that matter. Software development does take time, and you are doing great work. My message was simply to offer my help if there needed to be extra work to be done, and, since this issue has sat idle waiting for reviews for the past month, it was an attempt to bring it back to the forefront. Yes, rolling releases do get breaking changes faster than other distros, but it's also an opportunity to catch them and fix them before it affects point release distros. Unfortunately, this MR has sat in review phase without much interest for long enough that point release distros are now encountering this issue as well, so a little reminder was needed. |
|
Artifact System 1:Arch Linux (up to date as of this morning) Virtual camera starts properly; both from a fresh run after a reboot, and after the module has been initialized. EDIT: Did a 2 hours stream with no issue on this build. System 2:Bazzite 42.20250417 Virtual camera starts properly; both from a fresh run after a reboot, and after the module has been initialized. I don't have a system with v0.13.2; however I can spin one up if you are lacking testers. |
RytoEX
left a comment
There was a problem hiding this comment.
Looks okay. Received approvals off-thread.
|
Is there a way to have this in flathub? |
|
@akrz this is not part of any official release yet. As you can see above, it's been added to the 31.1 milestone when the PR got merged into the master branch. You'll have to wait until that version gets released or build it yourself from source. Edit: or see below for a flatpak build, as people pointed out. It's still not "from flathub" that way, but it's definitely more accessible than building from source. |
|
@akrz you can also download the flatpak build artifact from the GitHub actions in this pull request and use that to install an alternate version locally. |
|
@JacobCallahan @akrz FWIW - navigating to artifacts always seems tricky - I find them by navigating to the |
|
Hey . Can you please form HOTFIX release because whole functionality in current moment broken . |
|
@jpVm5jYYRE1VIKL why not just run the pre-release as was previously suggested? obs-studio-flatpak-90516132a-x86_64.flatpak |
A hotfix release could get this fix into package repositories faster than waiting until the next minor version release. Sure, everyone could uninstall the obs-studio package provided by their distribution repository and install the pre-release version; then when the next release comes, uninstall the pre-release and re-install the repository package. But no one wants to go through that. |
|
I tried the artifact build but had issues with plugins (droidcam). I just removed the flatpak and went with the native fedora package that has this fix applied. I think some other distros backported this as a patch too. I'm a bit surprised that the official flatpak image of obs doesn't have this fix yet in the stable version. This broke the workflow of several users and it wasn't trivial to know what was going on. |
I'd say that unless you can build OBS, use the flatpak artefact, or are on a distribution which has a backported patch (i.e. Fedora); then roll v4l2loopback to 0.13.2 and hold it there. |
|
Garuda Linux (Arch-based) and I upgraded to aur/obs-studio-git. The v4l2loopback module no longer complains. Is there any way to do a minor point release to include just this fix? |
There are beta releases on GitHub with the fix, e.g.: https://github.com/obsproject/obs-studio/releases/tag/31.1.0-beta2 |
@p-m-j . Because nobody want to fill OS with multiply garbage packages which are in reality not needed. And nobody want to install it only to have posibility to start OBS. |
|
Just experiencing this issue now - so this is a regression that's been fixed nearly two months ago but there's still no stable release since then that includes it? How is it not a red flag when some distros are pulling in patches like this directly? |
@farnoy - I would be a little frustrated, too. I can accept a little bit of muddling around if I'm on a rolling distro, but, yes, even Debian Trixie (testing) has backported this fix. I think it's clear there won't be releases between now and 31.1 (which will have this fix). So I guess fingers crossed OBS 31.1 lands soon 🤞! |
|
Well done OBS . IN current fresh kernel not possble anymore to use old v4l2loopback-0.13.2 . So DKMS not build anymore. |
That is the reason for the LTS Kernel on a bleeding edge distro... and the fix is in the beta and target the supported platform Linux:Ubuntu and Linux:Flatpak. All other obs packages are not provided by the obs team itself. So when a distro use an incompatible dependency, they have to fix it - what some distro already did. |
The solution in your case is either; roll back the kernel (and then loopback), or use flatpak (which I note you don't want to do), or build OBS. If you don't like having development libraries sitting around on your system, you can build within a container instead (then delete the container). |
|
Thanks so much for this PR! I'm just going to share a snippet of nix code if anyone wants to use this PR before OBS 31.1 is released: programs.obs-studio.package = unstable.obs-studio.overrideAttrs (oldAttrs: {
src = pkgs.fetchFromGitHub {
owner = "obsproject";
repo = "obs-studio";
rev = "12c6febae21f369da50f09d511b54eadc1dc1342"; # https://github.com/obsproject/obs-studio/pull/11906
sha256 = "sha256-DIlAMCdve7wfbMV5YCd3qJnZ2xwJMmQD6LamGP7ECOA=";
fetchSubmodules = true;
};
version = "31.1.0-beta1";
patches = builtins.filter (
patch:
!(
builtins.baseNameOf (toString patch) == "Enable-file-access-and-universal-access-for-file-URL.patch"
)
) oldAttrs.patches;
}); |
|
Can we please get a hotfix release for this? Virtual camera has been broken for 4 months, and for 2 months it has been fixed in master but no release. How hard could it be to release a 31.0.1, instead of having each user individually go through installing the pre-release version manually. |
Skip the 'non-compliant' usage of STREAMON ioctl for V4L2 compliant v4l2loopback module
Description
When starting the virtual camera:
Motivation and Context
Fixes #11891
v4l2loopback was recently updated to have stronger compliance with V4L2 UAPI; thus, the invocation of STREAMON by OBS when no streaming I/O buffers have been negotiated (e.g. via REQBUFS) results in an error.
This is also a revision of the fix for #4808 - where it was identified that the STREAMON call would trigger the reset of the OUTPUT capability when the loopback node was closed (thus allowing the camera to be restarted).
How Has This Been Tested?
Built on Ubuntu 24.04, x64 machine, with v4l2loopback:
Starting, stopping, and re-starting the virtual camera succeeded in all versions tested.
Types of changes
Checklist: