Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make VirtualCam work with Flatpak #4552

Merged

Conversation

GeorgesStavracas
Copy link
Member

@GeorgesStavracas GeorgesStavracas commented Apr 18, 2021

Description

It is not possible to run host system executables like modinfo, pkexec, and modprobe inside a Flatpak sandbox. However, Flatpak provides a way to run command on the host system: the flatpak-spawn executable.

flatpak-spawn is a tiny helper that, when executed with the '--host' parameter, talks to the org.freedesktop.Flatpak D-Bus interface to run and retrieve the return value of the executable. This provides OBS Studio a way to escape this sandbox limitation without opening large holes in the sandbox.

Make v4l2's implementation of VirtualCam run system commands using flatpak-spawn when inside a Flatpak sandbox. The detection of the sandbox is done by checking the existence of the /.flatpak-info file, which is created by Flatpak itself, and only exists inside the sandbox. If OBS Studio is not running inside a Flatpak sandbox, run the exact same command it used to run before this commit.

Add the permission to talk to the org.freedesktop.Flatpak D-Bus interface to the Flatpak manifest, so we can run flatpak-spawn with the '--host' parameter.

Notice that the same constraints apply with and without Flatpak: the host system needs to have the v4l2loopback kernel module available for the v4l2 implementation of VirtualCam to work.

Motivation and Context

VirtualCam is an important feature, and making it work properly with Flatpak will impact many (dozens of thousands, according to Flathub) users. It also gets us closer to complete feature-parity between Flatpak and host system OBS Studio.

How Has This Been Tested?

  • Have v4l2loopback installed on your host system
  • Run this PR of OBS Studio using Flatpak (the Flatpak CI workflow artifact is enough)
  • Try to create and feed a VirtualCam

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

It is not possible to run host system executables like modinfo, pkexec,
and modprobe inside a Flatpak sandbox. However, Flatpak provides a way
to run command on the host system: the flatpak-spawn executable.

flatpak-spawn is a tiny helper that, when executed with the '--host'
parameter, talks to the org.freedesktop.Flatpak D-Bus interface to run
and retrieve the return value of the executable. This provides OBS Studio
a way to escape this sandbox limitation without opening large holes in
the sandbox.

Make v4l2's implementation of VirtualCam run system commands using
flatpak-spawn when inside a Flatpak sandbox. The detection of the sandbox
is done by checking the existence of the /.flatpak-info file, which is
created by Flatpak itself, and only exists inside the sandbox. If OBS
Studio is not running inside a Flatpak sandbox, run the exact same command
it used to run before this commit.

Add the permission to talk to the org.freedesktop.Flatpak D-Bus interface
to the Flatpak manifest, so we can run flatpak-spawn with the '--host'
parameter.

Notice that the same constraints apply with and without Flatpak: the host
system needs to have the v4l2loopback kernel module available for the v4l2
implementation of VirtualCam to work.
@WizardCM WizardCM added the Bug Fix Non-breaking change which fixes an issue label Apr 18, 2021
@jp9000 jp9000 merged commit 7a87777 into obsproject:master Apr 19, 2021
@jp9000
Copy link
Member

jp9000 commented Apr 19, 2021

EZ Clap

@David-Else
Copy link

@GeorgesStavracas I am trying to get the virtual camera working on OBS 29 flatpak version using Xorg, I have v4l2loopback installed on RHEL 9.1:

Installed Packages
Name         : v4l2loopback
Version      : 0.12.7
Release      : 2.el9

I am asked for authentication when trying to start the virtual camera:
Screenshot from 2023-01-09 17-11-57

and after entering it I don't seem to have any virtual camera, it used to be picked up in Signal Messenger (ages ago, sorry I don't remember which version of OBS), but now it is not. The Start Virtual Camera box is not highlighted, there is no Stop Virtual Camera
Screenshot from 2023-01-09 17-12-22

I looked in the OBS logs and there seems no mention of it. Could this be a sandboxing problem? Could you advise me how to find the problem and find out if it is a bug?

Thanks!

@Pappmann
Copy link

@GeorgesStavracas I am trying to get the virtual camera working on OBS 29 flatpak version using Xorg, I have v4l2loopback installed on RHEL 9.1:

Installed Packages
Name         : v4l2loopback
Version      : 0.12.7
Release      : 2.el9

I am asked for authentication when trying to start the virtual camera: Screenshot from 2023-01-09 17-11-57

and after entering it I don't seem to have any virtual camera, it used to be picked up in Signal Messenger (ages ago, sorry I don't remember which version of OBS), but now it is not. The Start Virtual Camera box is not highlighted, there is no Stop Virtual Camera Screenshot from 2023-01-09 17-12-22

I looked in the OBS logs and there seems no mention of it. Could this be a sandboxing problem? Could you advise me how to find the problem and find out if it is a bug?

Thanks!

the same with fedora 37 and flatpak.

@David-Else
Copy link

I found the error by running OBS on the terminal, it was:

modprobe: ERROR: could not insert 'v4l2loopback': Key was rejected by service

I solved the problem by turning off secure boot in my BIOS, it seems a crazy fix, but it is explained here: https://discussion.fedoraproject.org/t/modprobe-error-could-not-insert-v4l2loopback-key-was-rejected-by-service/62084/7

Now it works perfectly. I am on AlmaLinux 9.1 using:


Name         : v4l2loopback
Version      : 0.12.7
Release      : 2.el9
Architecture : noarch
Size         : 37 k
Source       : v4l2loopback-0.12.7-2.el9.src.rpm
Repository   : @System
From repo    : rpmfusion-free-updates
Summary      : Utils for V4L2 loopback devices
URL          : https://github.com/umlaeute/v4l2loopback
License      : GPLv2+
Description  : This allows you to create "virtual video devices". Normal (v4l2)
             : applications will read these devices as if they were ordinary video
             : devices, but the video will not be read from e.g. a capture card but
             : instead it is generated by another application.
             : 
             : This package contains the utilties for v4l2loopback.

@tsilvs
Copy link

tsilvs commented Jun 7, 2024

$> flatpak run com.obsproject.Studio --version
OBS Studio - 30.1.2

Can't use Virtual Camera.

OBS Flatpak UI

OS: Fedora Silverblue 39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Fix Non-breaking change which fixes an issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants