Skip to content

Pipewire

Federico Di Pierro edited this page Jan 6, 2022 · 1 revision

Pipewire

Clightd 5.5 showcases a Pipewire sensor to support webcam frames capture using libpipewire.
Its support is marked as experimental and it is not built by default.
Pipewire sensor has higher priority than Camera because it should work even if other applications are also using the webcam.

Main issues

  • libpipewire is not able to capture frames from webcam when the webcam itself is already in use, nor any error is returned; the pipewire capture loop just freezes.
    To workaround this issue, Clightd forces a 2s timeout to the Pipewire capture, returning EIO error if no frame could be captured.
  • libpipewire does not support setting camera controls (thus, no default settings or setting string support); unfortunately libpipewire v4l2 plugin still does not support this, thus Clightd is out of luck.
    The latter problem is the main reason why Pipewire plugin is not built by default, as it would be a regression for existing users.

Env variable

As Pipewire runs as an user session daemon, Clightd needs to set an env variable to be able to access the user session pipewire socket.
For doing so, it uses the caller XDG_RUNTIME_DIR env variable (/run/user/$uid/).
Unfortunately though, Clightd also starts a monitor for new devices as soon as it starts, to send "Sensor.Changed" signals when any new device is found.
At that moment, Clightd has no caller, thus it does not know which XDG_RUNTIME_DIR it should use.
A CLIGHTD_PIPEWIRE_RUNTIME_DIR env variable was added to let Clightd know which XDG_RUNTIME_DIR it should start the Pipewire monitor on.
The new env variable is found in clightd.service and can be easily customized:

Environment=CLIGHTD_PIPEWIRE_RUNTIME_DIR=/run/user/1000/

Another thing to note is to avoid enabling Clightd.service, instead letting dbus-socket activation doing its work starting Clightd when the first application calls its API.
This is to avoid situations where Clightd starts before the user session is even created and /run/user/$uid folder or the pipewire socket are non existent.

Clone this wiki locally