Closed bnordgren closed 3 years ago
Aha!
This is how OBS determines whether the v4l2loopback module is loaded:
static bool v4l2loopback_installed()
{
bool loaded = false;
int ret = system("modinfo v4l2loopback >/dev/null 2>&1");
if (ret == 0)
loaded = true;
return loaded;
}
This detection method fails inside the flatpak not because the kernel module is missing, but because there's no modinfo
command inside the flatpak. Any chance you could coordinate with OBS to determine whether modinfo
should be added to the flatpak or whether the test should be changed to something like grep v4l2loopback /proc/modules
? (i.e. What implications does the latter solution have for which versions of the linux kernel are supported?)
So, I think the missing *.so libraries still need to be included in the flatpak.
There seems to be a lot of discussion of possibilities in that other issue, most of which assume that OBS is not running in a sandbox...or at least is running in an environment (sandbox or no) which has the ability to introspect the state of kernel modules with modinfo
. I did not see a decision made as to the future direction.
One person raises the issue that there are two tests, one to determine the presence of the module (loaded or not) and the other to try and load it. Is it even possible to load kernel modules within a flatpak, or does that require special permission? Seems like even in a non-sandboxed environment you'd have to run the application as root for it to actually load a kernel module...
Is there any possibility of packaging the current version of OBS with a shim script (and the missing libraries) so that the current upstream version will work? Even a simple modinfo
bash script in the $PATH
which contains the above grep command could provide the environmental support that OBS assumes is available. It doesn't have to be a generic replacement for modinfo, it just has to perform that one function.. Future packaging efforts could react to whatever decisions the upstream makes.
I believe I can outline a draft resolution to this ticket now. The following mimics the non-sandboxed functionality. Let me know if I missed anything below. It's also conceivable that the modinfo
script below could be simplified using one of the suggestions in https://github.com/obsproject/obs-studio/issues/3845, eliminating also the need to flatpak-spawn anything or specify the KERNEL_MOD_COMPILE_DIR
variable.
For the moment, I will still have to uninstall the flatpak and layer the obs-studio package from rpmfusion.
/app/lib/ndi/obs-ndi.so
/app/lib/v4l2sink/v4l2sink.so
place the following shim script in /app/bin/modinfo
:
#!/bin/bash
flatpak-spawn --host modinfo $KERNEL_MOD_COMPILE_DIR/v4l2loopback.ko
flatpak-spawn
add "talk" permission so flatpak-spawn --host
works. (--talk-name=org.freedesktop.Flatpak
)
Users will need to
KERNEL_MOD_COMPILE_DIR
environment variable to this flatpak as an override.One more update. After tinkering with the package from rpmfusion updates testing (OBS 26.1.0) on my Fedora Silverblue 33 host, I was finally able to get it to work. Note that the system's modinfo
utility didn't work either (because OBS doesn't specify a file, and therefore modinfo
looks in /lib/modules
...) I modified my modinfo
script in $HOME/bin
to:
#!/bin/bash
#flatpak-spawn --host modinfo $KERNEL_MOD_COMPILE_DIR/v4l2loopback.ko
grep v4l2loopback /proc/modules
And I start OBS on the host with: QT_QPA_PLATFORM=xcb PATH=$HOME/bin:$PATH /usr/bin/obs
I think the implications of this experiment for flatpak packaging are:
modinfo
in /app/bin
; andI think that simplifies things greatly...
Has any progress been made with this? Wondering if it's worth hacking this together.
OBS Studio 27, which will be released soon, will have a Flatpak-friendly implementation of VirtualCam (see obsproject/obs-studio#4552). No workarounds needed. The same contraints apply though: you'll need to have v4l2loopback on your host system.
I'll go ahead and close this since it's being tracked upstream, and there's nothing else to do besides waiting for the release to happen :slightly_smiling_face:
On fedora silverblue 33 (basecommit 56c8ba8529da528d68252247fbfa0c0c4ec2361f442fa4eda3ee9bd5a94e1ff7)
I compiled v4l2loopback in a toolbox and manually
insmod
ed it. I now have a /dev/video2.Started a shiny new OBS Studio 26.1.0 from flatpak and there's no "start virtual camera" button. As described on #65, I looked at the currrent logs to find:
Entering the running flatpak and listing the contents of /app/lib/obs-plugins shows that both things it's complaining about are symlinks which did not make it to the flatpak packaging... So that's one thing that needs to be addressed...
Moving on, an indication that the loopback device is functional and available inside the flatpak:
I just don't know what criteria OBS is using to decide that v4l2loopback isn't installed. The v4l2 sink plugin is missing from the flatpak, but that appears to be a separate issue, as the log file doesn't emit that error until well after it complains that loopback support is missing.
By the way, you can probably close #65 as moot now, and #91 has a rather hypothetical "probably won't work until the advent of this pending PipeWire technology", which seems a little wrong given that #65 got it to work manually...somehow...