5 https://raw.githubusercontent.com/automotive-grade-linux/docs-sources/master/docs/audio/pipewire.md
8 <!-- WARNING: This file is generated by fetch_docs.js using /home/boron/Documents/AGL/docs-webtemplate/site/_data/tocs/apis_services/master/audio-developer-guides-audio-book.yml -->
10 # PipeWire Audio System Overview
14 AGL uses the PipeWire daemon service to provide audio playback and capture
15 capabilities. PipeWire is accompanied by a secondary service, WirePlumber
16 (also referred to as the *session manager*), which provides policy management,
17 device discovery, configuration and more.
19 Applications can connect to the PipeWire service through its UNIX socket, by
20 using the *libpipewire* library as a front-end to that socket.
24 The Audio System's configuration is mainly done in the session manager.
25 The session manager is the service that dictates policy, therefore this is
26 the place to configure options such as device properties, device priorities
27 and application linking policy.
29 An extensive listing of configuration options for the session manager,
30 WirePlumber, is available in the next chapter,
31 [Session Manager Configuration](./wireplumber_configuration.md)
35 WirePlumber supports runtime configuration of devices, through the
36 `wireplumber-cli` tool. This tool supports the following sub-commands:
38 * `wireplumber-cli ls-endpoints`:
39 This lists all the known audio endpoints, including devices and applications
40 that are streaming. In front of the devices, there is a `*` (star) character
41 on the "default" device, i.e. the device that is chosen by default to link
42 applications to. The volume and mute status of the devices is also shown.
43 * `wireplumber-cli set-default [id]`:
44 Changes the default endpoint of a specific category (capture or playback,
45 determined automatically by the endpoint's type)
46 and sets it to be the endpoint with the specified `[id]`. The id is the
47 number shown in front of each endpoint's name in `ls-endpoints`.
48 * `wireplumber-cli set-volume [id] [vol]`:
49 Sets the volume of `[id]` to `[vol]`. `[vol]` must be a floating point
50 number between 0.0 (0%) and 1.0 (100%).
51 * `wireplumber-cli device-node-props`:
52 Lists all the properties of the device nodes, useful for writing `.endpoint`
53 configuration files, as discussed in the _Session Management Configuration_
56 Due to a system limitation, before running this tool on the command line,
57 you need to export the `XDG_RUNTIME_DIR` environment variable, like this:
60 export XDG_RUNTIME_DIR=/run/user/1001
65 PipeWire also ships with **/etc/pipewire/pipewire.conf**, which can be used to
66 configure which pipewire modules are being loaded in the PipeWire deamon. You
67 should normally not need to modify anything there, unless you understand what
72 ### Native API - libpipewire
74 The main entry point for applications to access the audio system is the API
75 offered by *libpipewire*. The functionality offered by *libpipewire* is vast
76 and it is beyond the scope of this document to describe it all.
78 For playback and capture, applications should use *struct pw_stream* and its
79 associated methods. There are usage examples for it in the PipeWire
80 [source code](https://gitlab.freedesktop.org/pipewire/pipewire).
82 ### Native API - GStreamer (Recommended)
84 For convenience, applications that use GStreamer can use the PipeWire GStreamer
85 elements to plug the functionality offered by *struct pw_stream* directly in
86 the GStreamer pipeline. These elements are called *pwaudiosrc* and *pwaudiosink*
90 gst-launch-1.0 audiotestsrc ! pwaudiosink
93 Through these elements, it is possible to specify the application role by setting
94 it in the *stream-properties* property of the element, as shown below:
97 gst-launch-1.0 audiotestsrc ! pwaudiosink stream-properties=p,media.role=Multimedia
103 gst_util_set_object_arg (sink, "stream-properties", "p,media.role=Multimedia");
106 When using these GStreamer elements, applications **should** handle the
107 **GST_MESSAGE_REQUEST_STATE** message on the bus and change their state accordingly.
108 This message will be sent when the *session manager* requests a change in the state
109 due to a higher priority stream taking over.
111 ### ALSA Compatibility
113 AGL offers a virtual ALSA device that redirects audio to PipeWire
114 through an ALSA PCM plugin. This device is the default one, so unless you
115 explicitly specify a device in your ALSA client application, audio will go
116 through PipeWire instead.
118 This mode has limitations, however.
119 * There is no way to specify the role of the application. WirePlumber will
120 always assume it is a "Multimedia" application
121 * There is no way for the application to be notified when another stream
122 takes over. When this happens, the audio clock will simply stop progressing and
123 the ALSA API will likely block.
125 ### Audiomixer service
128 [agl-service-audiomixer](https://git.automotivelinux.org/apps/agl-service-audiomixer/about/)
133 The PipeWire service is activated on demand, via systemd socket activation.
134 The WirePlumber service is always started and stopped together with the PipeWire
137 If you wish to manually start/stop/restart the service, you can do so by using
140 systemctl start/stop/restart pipewire@1001.service
145 When something is wrong with the audio setup, it is useful to know how to debug
148 ### PipeWire & WirePlumber
150 The PipeWire and WirePlumber daemons can be configured to be more verbose
151 by editing **/etc/pipewire/environment**
153 * Set `G_MESSAGES_DEBUG=all` to enable WirePlumber's debug output.
154 * Set `PIPEWIRE_DEBUG=n` (n=1-5) to enable PipeWire's debug output.
156 All messages will be available in the systemd journal, inspectable with
159 `PIPEWIRE_DEBUG` can be set to a value between 1 and 5, with 5 being the
160 most verbose and 1 the least verbose.
162 ### AGL applications & services (AppFW)
164 For AGL applications and services that are installed by the app framework,
165 you can set the *PIPEWIRE_DEBUG* environment variable in **/etc/afm/unit.env.d/pipewire**.
166 This will enable the debug messages that are printed by *libpipewire* and will
167 make them available also in the systemd journal.