Multimedia processing graphs
Find a file
Barnabás Pőcze 882737b077 pipewire: module-link-factory: cancel async work in link's destroy event
When a link enters the "ERROR" state, it is scheduled for destruction in
`module-link-factory.c:link_state_changed()`, which queues `destroy_link()`
to be executed on the context's work queue.

However, if the link is destroyed by means of `pw_impl_link_destroy()`
directly after that, then `link_destroy()` unregisters the associated
`pw_global`'s event hook, resulting in `global_destroy()` not being called
when `pw_impl_link_destroy()` proceeds to call `pw_global_destroy()` some
time later. This causes the scheduled async work to not be cancelled. When
it runs later, it will trigger a use-after-free since the `link_data` object
is directly tied to the `pw_impl_link` object.

For example, if the link is destroyed when the client disconnects:

==259313==ERROR: AddressSanitizer: heap-use-after-free on address 0x7ce753028af0 at pc 0x7f475354a565 bp 0x7ffd71501930 sp 0x7ffd71501920
READ of size 8 at 0x7ce753028af0 thread T0
    #0 0x7f475354a564 in destroy_link ../src/modules/module-link-factory.c:253
    #1 0x7f475575a234 in process_work_queue ../src/pipewire/work-queue.c:67
    #2 0x7b47504e7f24 in source_event_func ../spa/plugins/support/loop.c:1011
    [...]

0x7ce753028af0 is located 1136 bytes inside of 1208-byte region [0x7ce753028680,0x7ce753028b38)
freed by thread T0 here:
    #0 0x7f475631f79d in free /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:51
    #1 0x7f4755594a44 in pw_impl_link_destroy ../src/pipewire/impl-link.c:1742
    #2 0x7f475569dc11 in do_destroy_link ../src/pipewire/impl-port.c:1386
    #3 0x7f47556a428b in pw_impl_port_for_each_link ../src/pipewire/impl-port.c:1673
    #4 0x7f475569dc3e in pw_impl_port_unlink ../src/pipewire/impl-port.c:1392
    #5 0x7f47556a02d8 in pw_impl_port_destroy ../src/pipewire/impl-port.c:1453
    #6 0x7f4755634f79 in pw_impl_node_destroy ../src/pipewire/impl-node.c:2447
    #7 0x7b474f722ba8 in client_node_resource_destroy ../src/modules/module-client-node/client-node.c:1253
    #8 0x7f47556d7c6c in pw_resource_destroy ../src/pipewire/resource.c:325
    #9 0x7f475545f07d in destroy_resource ../src/pipewire/impl-client.c:627
    #10 0x7f47554550cd in pw_map_for_each ../src/pipewire/map.h:222
    #11 0x7f4755460aa4 in pw_impl_client_destroy ../src/pipewire/impl-client.c:681
    #12 0x7b474fb0658b in handle_client_error ../src/modules/module-protocol-native.c:471
    [...]

Fix this by cancelling the work queue item in `link_destroy()`, which should
always run, regardless of the ordering of events.

Fixes #4691
2025-08-20 23:21:26 +02:00
.gitlab ci: cross compile on debian 13 to multiple architectures 2025-08-13 07:14:33 +00:00
doc doc: spa: Fix offset in driver documentation 2025-08-05 17:54:56 +00:00
include/valgrind Fix typos 2024-05-22 09:19:34 +02:00
pipewire-alsa alsa: unlock pending drain in drop 2025-06-02 19:14:45 +02:00
pipewire-jack jack: emit port_rename callbacks 2025-08-20 11:39:30 +02:00
pipewire-v4l2 pod: check that choices are not empty 2025-07-15 10:13:18 +02:00
po Updated Slovenian (sl.po) 2025-08-20 14:03:35 +00:00
spa spa: Make spa_pod_parser_pop return int again 2025-08-20 08:04:21 +00:00
src pipewire: module-link-factory: cancel async work in link's destroy event 2025-08-20 23:21:26 +02:00
subprojects meson: Bump webrtc-audio-processing to v2.1 2025-01-23 11:57:11 -05:00
test control: improve UMP to Midi conversiom 2025-08-19 18:33:59 +02:00
.codespell-ignore .codespell-ignore: update to current codebase 2021-10-07 15:26:18 +00:00
.editorconfig editorconfig: add xml files for the man pages 2021-05-20 07:34:17 +00:00
.gitattributes gitattributes: mark test/data/*.txt as text files 2024-05-05 15:17:39 +03:00
.gitignore aec-webrtc: Bump to webrtc-audio-processing-1 2023-09-06 09:31:06 +00:00
.gitlab-ci.yml ci: cross compile on debian 13 to multiple architectures 2025-08-13 07:14:33 +00:00
autogen.sh Replace Pipewire with PipeWire for consistency 2021-07-14 16:56:54 +10:00
CODE_OF_CONDUCT.md Add a code of coduct 2019-11-08 13:57:36 +05:30
COPYING Relicense as MIT/X11 2018-11-05 17:48:52 +01:00
INSTALL.md INSTALL.md: Add WIREPLUMBER_DEBUG env variable 2024-01-01 18:30:19 +00:00
LICENSE 0.3.28 2021-05-19 10:11:36 +02:00
Makefile.in Makefile: Fix up shell/run rules 2025-04-18 14:05:12 -04:00
meson.build pwtest: is_debugger_attached(): rework test 2025-08-13 07:14:33 +00:00
meson_options.txt meson.build: rework systemd related options 2025-07-18 09:46:17 +00:00
NEWS 1.4.0 2025-03-06 13:11:38 +01:00
pw-uninstalled.sh Don't log to systemd during development 2025-04-18 12:28:23 -04:00
README.md env: PIPEWIRE_QUANTUM now uses FORCE_RATE and FORCE_QUANTUM 2023-10-10 15:10:19 +02:00
template.test.in Optionally install examples and tests 2020-06-16 17:58:02 +00:00

PipeWire

PipeWire is a server and user space API to deal with multimedia pipelines. This includes:

  • Making available sources of video (such as from a capture devices or application provided streams) and multiplexing this with clients.
  • Accessing sources of video for consumption.
  • Generating graphs for audio and video processing.

Nodes in the graph can be implemented as separate processes, communicating with sockets and exchanging multimedia content using fd passing.

Building and installation

The preferred way to install PipeWire is to install it with your distribution package system. This ensures PipeWire is integrated into the rest of your system for the best experience.

If you want to build and install PipeWire yourself, refer to install for instructions.

Usage

The most important purpose of PipeWire is to run your favorite apps.

Some applications use the native PipeWire API, such as most compositors (gnome-shell, wayland, ...) to implement screen sharing. These apps will just work automatically.

Most audio applications can use either ALSA, JACK or PulseAudio as a backend. PipeWire provides support for all 3 backends. Depending on how your distribution has configured things this should just work automatically or with the provided scripts shown below.

PipeWire can use environment variables to control the behaviour of applications:

  • PIPEWIRE_DEBUG=<level> to increase the debug level (or use one of XEWIDT for none, error, warnings, info, debug, or trace, respectively).
  • PIPEWIRE_LOG=<filename> to redirect log to filename
  • PIPEWIRE_LOG_SYSTEMD=false to disable logging to systemd journal
  • PIPEWIRE_LATENCY=<num/denom> to configure latency as a fraction. 10/1000 configures a 10ms latency. Usually this is expressed as a fraction of the samplerate, like 256/48000, which uses 256 samples at a samplerate of 48KHz for a latency of 5.33ms. This function does not attempt to configure the samplerate.
  • PIPEWIRE_RATE=<num/denom> to configure a rate for the graph.
  • PIPEWIRE_QUANTUM=<num/denom> to configure latency as a fraction and a samplerate. This function will force the graph samplerate to denom and force the specified num as the buffer size.
  • PIPEWIRE_NODE=<id> to request a link to the specified node. The id can be a node.name or object.serial of the target node.

Using tools

pw-cat can be used to play and record audio and midi. Use pw-cat -h to get some more help. There are some aliases like pw-play and pw-record to make things easier:

$ pw-play /home/wim/data/01.\ Firepower.wav

Running JACK applications

Depending on how the system was configured, you can either run PipeWire and JACK side-by-side or have PipeWire take over the functionality of JACK completely.

In dual mode, JACK apps will by default use the JACK server. To direct a JACK app to PipeWire, you can use the pw-jack script like this:

$ pw-jack <appname>

If you replaced JACK with PipeWire completely, pw-jack does not have any effect and can be omitted.

JACK applications will automatically use the buffer-size chosen by the server. You can force a maximum buffer size (latency) by setting the PIPEWIRE_LATENCY environment variable like so:

PIPEWIRE_LATENCY=128/48000 jack_simple_client

Requests the jack_simple_client to run with a buffer of 128 or less samples.

Running PulseAudio applications

PipeWire can run a PulseAudio compatible replacement server. You can't use both servers at the same time. Usually your package manager will make the server conflict so that you can only install one or the other.

PulseAudio applications still use the regular PulseAudio client libraries and you don't need to do anything else than change the server implementation.

A successful swap of the server can be verified by checking the output of

pactl info

It should include the string:

...
Server Name: PulseAudio (on PipeWire 0.3.x)
...

You can use pavucontrol to change profiles and ports, change volumes or redirect streams, just like with PulseAudio.

Running ALSA applications

If the PipeWire alsa module is installed, it can be seen with

$ aplay -L

ALSA applications can then use the pipewire: device to use PipeWire as the audio system.

Running GStreamer applications

PipeWire includes 2 GStreamer elements called pipewiresrc and pipewiresink. They can be used in pipelines such as this:

$ gst-launch-1.0 pipewiresrc ! videoconvert ! autovideosink

Or to play a beeping sound:

$ gst-launch-1.0 audiotestsrc ! pipewiresink

PipeWire provides a device monitor as well so that

$ gst-device-monitor-1.0

shows the PipeWire devices and applications like cheese will automatically use the PipeWire video source when possible.

Inspecting the PipeWire state

To inspect and manipulate the PipeWire graph via GUI, you can use Helvum.

Alternatively, you can use use one of the excellent JACK tools, such as Carla, catia, qjackctl, ... However, you will not be able to see all features like the video ports.

pw-mon dumps and monitors the state of the PipeWire daemon.

pw-dot can dump a graph of the pipeline, check out the help for how to do this.

pw-top monitors the real-time status of the graph. This is handy to find out what clients are running and how much DSP resources they use.

pw-dump dumps the state of the PipeWire daemon in JSON format. This can be used to find out the properties and parameters of the objects in the PipeWire daemon.

There is a more complicated tool to inspect the state of the server with pw-cli. This tool can be used interactively or it can execute single commands like this to get the server information:

$ pw-cli info 0

Documentation

Find tutorials and design documentation here.

The (incomplete) autogenerated API docs are here.

The Wiki can be found here

Contributing

PipeWire is Free Software and is developed in the open. It is mostly licensed under the MIT license. Check LICENSE for more details about the exceptions.

Contributors are encouraged to submit merge requests or file bugs on gitlab.

Join us on IRC at #pipewire on OFTC.

We adhere to the Contributor Covenant for our code of conduct.

Donate using Liberapay.

Getting help

You can ask for help on the IRC channel (see above). You can also ask questions by raising a gitlab issue.