We're hiring!
*

Integrating libcamera into PipeWire

Raghavendra Rao avatar

Raghavendra Rao
September 11, 2020

Share this post:

Reading time:

Earlier this year, my colleagues Julian Bouzas and George Kiagiadakis wrote about PipeWire and Wireplumber, the PipeWire session manager. Since then, PipeWire has continued to evolve with the recent integration of libcamera, a library to support complex cameras. In this blog post, I'll explain why libcamera exists, what it does, and how we integrated it in PipeWire.

libcamera

Cameras are complex devices which require heavy hardware image processing. The complexity in the userspace camera application development originates with the evolution of complex hardware. libcamera addresses this problem and offers ease of camera application development. libcamera can be described as a full camera stack library in the userspace to provide the feature that do not belong in the kernel.

The core of libcamera framework exposes kernel driver APIs to userspace while the libcamera application layer abstracts the developer from complex hardware usage. libcamera supports multiple video streams from a single device. In real time use cases such as video conferencing, we may need to preview streams with different resolutions than what we tend to stream over the network. It is natural that we would like to display the live streaming simaultaneously while we capture the video with different resolutions. libcamera offers a perfect solution to fulfill these requirements.

Having said that, what if we'd like to stream a camera device data using different applications simaultaneously? Well, PipeWire answers this question. Besides acting as an interface between hardware devices and applications, PipeWire eases the sharing of hardware devices between applications. Moreover, integration of libcamera into PipeWire brings all the abilities offered by libcamera into PipeWire. With this, PipeWire can become a first class user of modern cameras.

PipeWire-libcamera interworking

As camera application development through v4l becomes more and more complex, Collabora decided to tackle this by integrating libcamera into PipeWire to offer all the evolutions coming from both the frameworks.

The integration work has been merged into PipeWire master.

Give it a try!

Please follow the steps below to try libcamera in PipeWire.

  1. Make sure that the linux kernel version is 5.0.0 or above.
  2. Make sure that the system user is added to video group to access /dev/media*. You can run the command sudo adduser `whoami` video and restart the session.
  3. Make sure that meson build package is installed in your system.
  4. Make sure that sdl2 package is installed in your system.
  5. Make sure that libdrm package is installed in your system.
  6. Follow Getting libcamera to obtain the source and install it. You can also use the commands below to build and install.
    meson --prefix <path/to/install dir> --buildtype=plain build
    cd build
    ninja -C . install
    
  7. Follow Getting PipeWire to obtain the source. Configure with meson and install it. Use the following commands:
    meson --prefix <path/to/install dir> -Dlibcamera=true build
    cd build
    ninja -C . install
    
  8. Now you can test libcamera spa plugin. Run the command "./build/spa/examples/local-libcamera" from the PipeWire directory. You should be able to see the camera captured data being rendered.

We will be blogging more about this integration work and improvements to be made in the future, explaining the motivation and further progress we make. Stay tuned!

Comments (6)

  1. Rogan Dawes:
    Sep 14, 2020 at 05:04 PM

    Is this something that could easily be exported as a remote desktop using VNC? Given the availability of cheap HDMI input dongles that appear as a UVC camera, it would be neat to be able to expose them using a regular "remote desktop" protocol. I guess an input filter would be required to receive the keystrokes and mouse movements, of course. Those could then be emitted using a HID Gadget and ConfigFS or similar.
    I did look at doing this with Xvncserver, but the rawfb support was a bit tricky to figure out, and I never got that working.

    Reply to this comment

    Reply to this comment

    1. Raghavendra:
      Sep 15, 2020 at 06:57 PM

      Hello Rogan Dawes,

      Thank you for your response.

      The idea behind the integration of libcamera was to ease the Camera application development with modern cameras and bring all the capabilities of libcamera to PipeWire.

      It is interesting to note that PipeWire already supports remote desktop sharing with wayland, gnome-remote-desktop and browsers such as firefox, chrome etc. PipeWire acts as interface between the Application and hardware to share the media via "dmabuf" buffers. Applications such as VNC/RDP can connect to PipeWire creating sink nodes to consume the Video frames captured by source nodes such as libcamera node, in this case.

      gnome-remote-desktop daemon enables GNOME to offer remote desktop sharing using VNC with PipeWire. This daemon supports GNOME on X as well as GNOME on Wayland. If you have got ubuntu installed then you may want to recompile mutter with remote desktop option enabled to make it work on ubuntu.

      Thanks,
      Raghavendra

      Reply to this comment

      Reply to this comment

  2. Andrew Zhukov:
    Jan 26, 2021 at 12:57 PM

    Can't get it work with latest libcamera and pipewire. Seems like pipewire uses old libcamera version...

    Reply to this comment

    Reply to this comment

    1. Raghavendra Rao:
      Feb 03, 2021 at 11:48 AM

      Hello Andrew Zhukov,

      Thanks for your message.

      The issue has been fixed and the fix has been merged into pipewire master. You can now check with pipewire master branch,

      Thanks,
      Raghavendra Rao

      Reply to this comment

      Reply to this comment

  3. Rogan Dawes:
    Jun 15, 2022 at 08:40 AM

    Thanks for your previous response. Unfortunately, I never managed to get it working. :-(

    Any thoughts of implementing PipeWire support in uvc-gadget? That would allow a complete video processing pipeline to be exposed to a host computer as a simple webcam. While there are existing projects that expose e.g. a Raspberry Pi camera as a webcam (e.g. https://github.com/showmewebcam/showmewebcam), there are more and more AI-enabled cameras that could benefit from a standardised interface to implement their processing of the stream before it gets to the host. I'm thinking that PipeWire is a pretty good candidate to be this standardised interface?

    Reply to this comment

    Reply to this comment

    1. Raghavendra Rao:
      Jun 16, 2022 at 11:38 AM

      Hello Rogan Dawes,

      Thanks for your message.

      This is an interesting idea, it seems. We would certainly look into it and get back on this.

      Thanks,
      Raghavendra Rao

      Reply to this comment

      Reply to this comment


Add a Comment






Allowed tags: <b><i><br>Add a new comment:


Search the newsroom

Latest Blog Posts

MLfix to quickly fix datasets

08/06/2023

Contrary to traditional software development, data is more important than code in machine learning. Building a high-performing model requires…

USB 3.0 preliminary support in U-boot for Radxa Rock-5B

31/05/2023

A while back I presented USB 2.0 host support that was added to U-boot for the Radxa Rock-5B RK3588 Rockchip board. This time, USB 3.0 was…

Radxa Rock-5B PCIe and RTL8125B networking in U-boot

18/05/2023

Work continues on the Radxa ROCK5B RK388, as PCIe and RTL8125B networking support in U-boot have now been added. Publishing code as Open…

Introducing Multiview for NVK

03/05/2023

NVK, an open-source Vulkan driver for NVIDIA hardware that is part of Mesa, now supports the Vulkan extension VK_KHR_multiview.

Adding bootloader support for USB 2.0 Host for Radxa ROCK 5B RK3588

27/04/2023

The beauty of Open Source is that we can reuse code written by many other people, keep their authorship, and credit them for their work,…

Meson & VSCode: Develop your project in a modern IDE

18/04/2023

Want to develop your Meson project in a modern IDE? Make sure to install Meson VSCode extension which is now fully functional with the recent…

Open Since 2005 logo

We use cookies on this website to ensure that you get the best experience. By continuing to use this website you are consenting to the use of these cookies. To find out more please follow this link.

Collabora Ltd © 2005-2023. All rights reserved. Privacy Notice. Sitemap.