Skip to content

Pipewire

Kieran Bingham edited this page Apr 16, 2023 · 2 revisions

Pipewire

By default libcamera may be a lower priority than V4L2 which can prevent cameras from being identified.

The priorities can be changed with something like the following in /etc/wireplumber/main.lua.d/99-libcamera-config.lua:

table.insert(libcamera_monitor.rules, {
  matches = {
    {
      { "node.name", "matches", "libcamera_input.*" },
    },
  },
  apply_properties = {
    ["priority.session"] = 1000,
  },
})

Logging libcamera with Pipewire

When pipewire has loaded libcamera, we need to be able to set an environment variable in pipewires environment to control the logging for libcamera.

PipeWire is often a system service, started with SystemD. If you're using the wireplumber session manager:

  $ systemctl --user edit wireplumber

then add

  [Service]
  Environment='LIBCAMERA_LOG_LEVELS=*:0' 'LIBCAMERA_LOG_FILE=/tmp/libcamera.log'

and save and exit then

  $ systemctl --user restart wireplumber

Adjust the LIBCAMERA_LOG_FILE location as desired. With *:0 this will be full logging and could be very verbose.

systemctl --user status wireplumber.service should return that it's working.

Pipewire libcamera demo

These are /my/ notes for building the Pi/IPU3 Pipewire<->libcamera demo at ELCE Dublin 2022. If you're reading these, then they are really raw, and require various bits of machinery and patches that aren't yet easy to document.

Sources:

  • Chromium
    • github.com:libcamera-org/chromium.git
    • Branch elce-demo
  • WebRTC
    • github.com:libcamera-org/libwebrtc.git
    • Branch elce-demo

Raspberry Pi:

Install libcamera

Detailed elsewhere, make sure this is done before pipewire

  • libcamera IPU3 limited to only support a single camera (Small issues on multicam support with pipewire/acquire/configure)

Install pipewire

  • Build and install the latest pipewire, with a systemd service to run on boot.

    prefix                                  : /usr
    session-managers                        : wireplumber
    systemd                                 : enabled


meson builddir -Dprefix=/usr -Dsystemd=enabled -Dsession-managers=wireplumber
ninja -C builddir
sudo ninja -C builddir install
sudo reboot

Make sure you use wireplumber!

Build chromium (not on the RPi)

Start a clean checkout of Chromium to be sure. (What's a few 'more' gigabytes anyway)

(This relies upon internal scripts provided by RPi). sudo apt-get install libarchive-tools (Needed for bsdtar) ?

Hack out the google api keys for the genargs scripts

  • Check gn args : "rtc_use_pipewire=true rtc_link_pipewire=true" (and also use_glib=true, enable_nacl=false)
    • is_debug=false --- Prevents building a 100GB output directory.

patchmake.sh --builddeps v104.0.5112.27_libcamera_1.3.patch

autoninja -C out/armv7-bullseye-ozone-rel chrome

... wait 1.5 hours ...

Build the deb files to send to the device: autoninja -C out/armv7-bullseye-ozone-rel "chrome/installer/linux:beta_deb" autoninja -C out/arm64-bullseye-ozone-rel/ "chrome/installer/linux:beta_deb"

scp to device and install with dpkg -i

Pipewire testing

gst-launch-1.0 pipewiresink

builddir/src/examples/video-play

Disable V4L2 support. It brings up unusable devices so lets simplify. Disable any current pipewire socket

systemctl --user pipewire.socket disable

Enable libcamera instead of V4L2

Add subprojects/wireplumber/src/config/main.lua.d/80-libcamera.lua:

v4l2_monitor.enabled = false
wpctl status


Run pipewire uninstalled

./pw-uninstalled.sh -b ./build

cd build

make run

sudo apt-get install gstreamer1.0-gl

Start a camera client

gst-launch-1.0 -v pipewiresrc ! video/x-raw,colorimetry=bt709,format=NV12,width=1280,height=720,framerate=30/1 ! glimagesink

gst-launch-1.0 -v pipewiresrc ! glimagesink

gst-launch-1.0 -v pipewiresrc ! videoconvert ! ximagesink

Set up a stream running of desired configuration with gst-launch. then run chromium-beta, and join the video call. Format negotiations are all broken :-( WebRTC is calculating NV12 buffer sizes incorrectly. And format support isn't as much as it should/could be in webrtc...

So much to do.