Skip to contentSkip to conversation

audio/pwaudio.c: Add Pipewire audio backend for QEMU

PATCH Superseded Dorinda Bassey 6 participants 15 messages Feb 15, 2023 – Feb 16, 2023 Arm/Amlogic Meson SoC support

v1 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 audio/pwaudio.c: Add Pipewire audio backend for QEMU

This commit adds a new audiodev backend to allow QEMU to use Pipewire as both an audio sink and source. This backend is available on most systems.

Added Pipewire entry points for QEMU Pipewire audio backend
Added wrappers for QEMU Pipewire audio backend in qpw_pcm_ops()
qpw_write function returns the current state of the stream to pwaudio and Writes some data to the server for playback streams using pipewire spa_ringbuffer implementation.
qpw_read function returns the current state of the stream to pwaudio and Reads some data from the server for capture streams using pipewire spa_ringbuffer implementation.
These functions qpw_write and qpw_read are called during playback and capture.
Added some functions that convert pw audio formats to QEMU audio format and vice versa which would be needed in the pipewire audio sink and source functions qpw_init_in() & qpw_init_out(). These methods that implement playback and recording will create streams for playback and capture that will start processing and will result in the on_process callbacks to be called. Built a connection to the Pipewire sound system server in the qpw_audio_init() method.

---
 audio/audio.c                 |   3 +
 audio/audio_template.h        |   4 +
 audio/meson.build             |   1 +
 audio/pwaudio.c               | 816 ++++++++++++++++++++++++++++++++++
 meson.build                   |   7 +
 meson_options.txt             |   4 +-
 qapi/audio.json               |  45 ++
 qemu-options.hx               |  17 +
 scripts/meson-buildoptions.sh |   8 +-
 9 files changed, 902 insertions(+), 3 deletions(-)
 create mode 100644 audio/pwaudio.c
audio/audio.c +3 -0
index 4290309d18..ed8616d56d 100644
@@ -2069,6 +2069,9 @@ void audio_create_pdos(Audiodev *dev)
 #ifdef CONFIG_AUDIO_PA
         CASE(PA, pa, Pa);
 #endif
+#ifdef CONFIG_AUDIO_PA
+        CASE(PW, pw, Pw);
+#endif
 #ifdef CONFIG_AUDIO_SDL
         CASE(SDL, sdl, Sdl);
 #endif
audio/audio_template.h +4 -0
index 42b4712acb..18d1ab0a77 100644
@@ -355,6 +355,10 @@ AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)(Audiodev *dev)
     case AUDIODEV_DRIVER_PA:
         return qapi_AudiodevPaPerDirectionOptions_base(dev->u.pa.TYPE);
 #endif
+#ifdef CONFIG_AUDIO_PW
+    case AUDIODEV_DRIVER_PW:
+        return qapi_AudiodevPwPerDirectionOptions_base(dev->u.pw.TYPE);
+#endif
 #ifdef CONFIG_AUDIO_SDL
     case AUDIODEV_DRIVER_SDL:
         return qapi_AudiodevSdlPerDirectionOptions_base(dev->u.sdl.TYPE);
audio/meson.build +1 -0
index 0722224ba9..309bdfd228 100644
@@ -19,6 +19,7 @@ foreach m : [
   ['sdl', sdl, files('sdlaudio.c')],
   ['jack', jack, files('jackaudio.c')],
   ['sndio', sndio, files('sndioaudio.c')],
+  ['pw', pipewire, files('pwaudio.c')],
   ['spice', spice, files('spiceaudio.c')]
 ]
   if m[1].found()
audio/pwaudio.c new file +816 -0

816 lines not on this page · raw message

meson.build +7 -0
index c626ccfa82..785b30e305 100644
@@ -734,6 +734,11 @@ if not get_option('jack').auto() or have_system
   jack = dependency('jack', required: get_option('jack'),
                     method: 'pkg-config', kwargs: static_kwargs)
 endif
+pipewire = not_found
+if not get_option('pw').auto() or (targetos == 'linux' and have_system)
+  pipewire = dependency('libpipewire-0.3', required: get_option('pw'),
+                    method: 'pkg-config', kwargs: static_kwargs)
+endif
 sndio = not_found
 if not get_option('sndio').auto() or have_system
   sndio = dependency('sndio', required: get_option('sndio'),
@@ -1667,6 +1672,7 @@ if have_system
     'jack': jack.found(),
     'oss': oss.found(),
     'pa': pulse.found(),
+    'pw': pipewire.found(),
     'sdl': sdl.found(),
     'sndio': sndio.found(),
   }
@@ -3940,6 +3946,7 @@ endif
 if targetos == 'linux'
   summary_info += {'ALSA support':    alsa}
   summary_info += {'PulseAudio support': pulse}
+  summary_info += {'Pipewire support':   pipewire}
 endif
 summary_info += {'JACK support':      jack}
 summary_info += {'brlapi support':    brlapi}
meson_options.txt +3 -1
index e5f199119e..f42605a8ac 100644
@@ -21,7 +21,7 @@ option('tls_priority', type : 'string', value : 'NORMAL',
 option('default_devices', type : 'boolean', value : true,
        description: 'Include a default selection of devices in emulators')
 option('audio_drv_list', type: 'array', value: ['default'],
-       choices: ['alsa', 'coreaudio', 'default', 'dsound', 'jack', 'oss', 'pa', 'sdl', 'sndio'],
+       choices: ['alsa', 'coreaudio', 'default', 'dsound', 'jack', 'oss', 'pa', 'pw', 'sdl', 'sndio'],
        description: 'Set audio driver list')
 option('block_drv_rw_whitelist', type : 'string', value : '',
        description: 'set block driver read-write whitelist (by default affects only QEMU, not tools like qemu-img)')
@@ -253,6 +253,8 @@ option('oss', type: 'feature', value: 'auto',
        description: 'OSS sound support')
 option('pa', type: 'feature', value: 'auto',
        description: 'PulseAudio sound support')
+option('pw', type: 'feature', value: 'auto',
+       description: 'Pipewire sound support')
 option('sndio', type: 'feature', value: 'auto',
        description: 'sndio sound support')
 
qapi/audio.json +45 -0

63 lines not on this page · raw message

qemu-options.hx +17 -0
index 88e93c6103..4fc73af804 100644
@@ -779,6 +779,11 @@ DEF("audiodev", HAS_ARG, QEMU_OPTION_audiodev,
     "                in|out.name= source/sink device name\n"
     "                in|out.latency= desired latency in microseconds\n"
 #endif
+#ifdef CONFIG_AUDIO_PW
+    "-audiodev pw,id=id[,prop[=value][,...]]\n"
+    "                in|out.name= source/sink device name\n"
+    "                latency= desired latency in microseconds\n"
+#endif
 #ifdef CONFIG_AUDIO_SDL
     "-audiodev sdl,id=id[,prop[=value][,...]]\n"
     "                in|out.buffer-count= number of buffers\n"
@@ -942,6 +947,18 @@ SRST
         Desired latency in microseconds. The PulseAudio server will try
         to honor this value but actual latencies may be lower or higher.
 
+``-audiodev pw,id=id[,prop[=value][,...]]``
+    Creates a backend using Pipewire. This backend is available on
+    most systems.
+
+    Pipewire specific options are:
+
+    ``latency=latency``
+        Add extra latency to playback in microseconds
+
+    ``in|out.name=sink``
+        Use the specified source/sink for recording/playback.
+
 ``-audiodev sdl,id=id[,prop[=value][,...]]``
     Creates a backend using SDL. This backend is available on most
     systems, but you should use your platform's native backend if
scripts/meson-buildoptions.sh +6 -2
index c2982ea087..d6f741f574 100644
@@ -1,7 +1,8 @@
 # This file is generated by meson-buildoptions.py, do not edit!
 meson_options_help() {
-  printf "%s\n" '  --audio-drv-list=CHOICES Set audio driver list [default] (choices: alsa/co'
-  printf "%s\n" '                           reaudio/default/dsound/jack/oss/pa/sdl/sndio)'
+  printf "%s\n" '  --audio-drv-list=CHOICES Set audio driver list [default] (choices: al'
+  printf "%s\n" '                           sa/coreaudio/default/dsound/jack/'
+  printf "%s\n" '                           oss/pa/pw/sdl/sndio)'
   printf "%s\n" '  --block-drv-ro-whitelist=VALUE'
   printf "%s\n" '                           set block driver read-only whitelist (by default'
   printf "%s\n" '                           affects only QEMU, not tools like qemu-img)'
@@ -136,6 +137,7 @@ meson_options_help() {
   printf "%s\n" '  parallels       parallels image format support'
   printf "%s\n" '  png             PNG support with libpng'
   printf "%s\n" '  pvrdma          Enable PVRDMA support'
+  printf "%s\n" '  pw              Pipewire sound support'
   printf "%s\n" '  qcow1           qcow1 image format support'
   printf "%s\n" '  qed             qed image format support'
   printf "%s\n" '  qga-vss         build QGA VSS support (broken with MinGW)'
@@ -374,6 +376,8 @@ _meson_option_parse() {
     --disable-profiler) printf "%s" -Dprofiler=false ;;
     --enable-pvrdma) printf "%s" -Dpvrdma=enabled ;;
     --disable-pvrdma) printf "%s" -Dpvrdma=disabled ;;
+    --enable-pw) printf "%s" -Dpw=enabled ;;
+    --disable-pw) printf "%s" -Dpw=disabled ;;
     --enable-qcow1) printf "%s" -Dqcow1=enabled ;;
     --disable-qcow1) printf "%s" -Dqcow1=disabled ;;
     --enable-qed) printf "%s" -Dqed=enabled ;;
Signature · 1 line
2.39.1
#1 lore raw
Quoted 9 lines · Dorinda Bassey

This commit adds a new audiodev backend to allow QEMU to use Pipewire as both an audio sink and source. This backend is available on most systems.

Added Pipewire entry points for QEMU Pipewire audio backend
Added wrappers for QEMU Pipewire audio backend in qpw_pcm_ops()
qpw_write function returns the current state of the stream to pwaudio and Writes some data to the server for playback streams using pipewire spa_ringbuffer implementation.
qpw_read function returns the current state of the stream to pwaudio and Reads some data from the server for capture streams using pipewire spa_ringbuffer implementation.
These functions qpw_write and qpw_read are called during playback and capture.
Added some functions that convert pw audio formats to QEMU audio format and vice versa which would be needed in the pipewire audio sink and source functions qpw_init_in() & qpw_init_out(). These methods that implement playback and recording will create streams for playback and capture that will start processing and will result in the on_process callbacks to be called. Built a connection to the Pipewire sound system server in the qpw_audio_init() method.

Can you ensure the commit message text is line wrapped at approx 72 characters.

audio/pwaudio.c line 4

Quoted 10 lines
audio/pwaudio.c new file +4 -0
new file mode 100644
index 0000000000..89040ac99e
@@ -0,0 +1,816 @@
+/*
+ * QEMU Pipewire audio driver
+ *
+ * Copyright (c) 2023, Red Hat Inc, Dorinda Bassey <[email protected]>

Just to confirm, you are claiming both copyright ownership for Red Hat *and* personal copyright ownership ?

I ask because most of the time the employer will have exclusive copyright ownership for anything created in the course of employment. A few countries have local law, however, that fineses this allowing employees to retain copyright, or if you developed stuff outside of work context.

Quoted 12 lines
audio/pwaudio.c new file +12 -0
+
+#include "qemu/osdep.h"
+#include "qemu/module.h"
+#include "audio.h"
+#include <errno.h>
+#include <spa/param/audio/format-utils.h>
+#include <spa/utils/ringbuffer.h>
+#include <spa/utils/result.h>
+
+#include <pipewire/pipewire.h>
+
+#define AUDIO_CAP "pipewire"

audio/pwaudio.c line 45

Quoted 10 lines
audio/pwaudio.c new file +10 -0
+#define RINGBUFFER_SIZE    (1u << 22)
+#define RINGBUFFER_MASK    (RINGBUFFER_SIZE - 1)
+#define BUFFER_SAMPLES    128
+
+#include "audio_int.h"
+
+enum {
+  MODE_SINK,
+  MODE_SOURCE
+};

As a style point, QEMU standard is for 4-space indents in C code.

meson_options.txt option('tls_priority', type : 'string', value : 'NORMAL', · line 24

Quoted 10 lines
meson_options.txt +1 -1
index e5f199119e..f42605a8ac 100644
@@ -21,7 +21,7 @@ option('tls_priority', type : 'string', value : 'NORMAL',
 option('default_devices', type : 'boolean', value : true,
        description: 'Include a default selection of devices in emulators')
 option('audio_drv_list', type: 'array', value: ['default'],
-       choices: ['alsa', 'coreaudio', 'default', 'dsound', 'jack', 'oss', 'pa', 'sdl', 'sndio'],
+       choices: ['alsa', 'coreaudio', 'default', 'dsound', 'jack', 'oss', 'pa', 'pw', 'sdl', 'sndio'],

I appreciate you probably just followed the example of pulseaudio, abbreviated to 'pa', but I'm not a fan of the existing usage there. So lets be more verbose and say 'pipewire' so users are clear on what this is.

Quoted 32 lines
meson_options.txt +2 -0
        description: 'Set audio driver list')
 option('block_drv_rw_whitelist', type : 'string', value : '',
        description: 'set block driver read-write whitelist (by default affects only QEMU, not tools like qemu-img)')
@@ -253,6 +253,8 @@ option('oss', type: 'feature', value: 'auto',
        description: 'OSS sound support')
 option('pa', type: 'feature', value: 'auto',
        description: 'PulseAudio sound support')
+option('pw', type: 'feature', value: 'auto',
+       description: 'Pipewire sound support')
 option('sndio', type: 'feature', value: 'auto',
        description: 'sndio sound support')
 
qapi/audio.json +11 -0
index 4e54c00f51..6c17d08ab8 100644
@@ -324,6 +324,48 @@
     '*out':    'AudiodevPaPerDirectionOptions',
     '*server': 'str' } }
 
+##
+# @AudiodevPwPerDirectionOptions:
+#
+# Options of the Pipewire backend that are used for both playback and
+# recording.
+#
+# @name: name of the sink/source to use
+#
+# @stream-name: name of the Pipewire stream created by qemu.  Can be
+#               used to identify the stream in Pipewire when you
+#               create multiple Pipewire devices or run multiple qemu

qapi/audio.json line 347

Quoted 10 lines
qapi/audio.json +10 -0
+#               instances (default: audiodev's id, since 7.1)
+#
+#
+# Since: 7.2
+##
+{ 'struct': 'AudiodevPwPerDirectionOptions',
+  'base': 'AudiodevPerDirectionOptions',
+  'data': {
+    '*name': 'str',
+    '*stream-name': 'str' } }

I tend to think we could afford to say "Pipewire" instead of "Pw" in the data types too.

Quoted 46 lines
qapi/audio.json +24 -0
+
+##
+# @AudiodevPwOptions:
+#
+# Options of the Pipewire audio backend.
+#
+# @in: options of the capture stream
+#
+# @out: options of the playback stream
+#
+# @latency: add latency to playback in microseconds
+#           (default 44100)
+#
+# Since: 7.2
+##
+{ 'struct': 'AudiodevPwOptions',
+  'data': {
+    '*in':     'AudiodevPwPerDirectionOptions',
+    '*out':    'AudiodevPwPerDirectionOptions',
+    '*latency': 'uint32' } }
+
 ##
 # @AudiodevSdlPerDirectionOptions:
 #
@@ -416,6 +458,7 @@
             { 'name': 'jack', 'if': 'CONFIG_AUDIO_JACK' },
             { 'name': 'oss', 'if': 'CONFIG_AUDIO_OSS' },
             { 'name': 'pa', 'if': 'CONFIG_AUDIO_PA' },
+            { 'name': 'pw', 'if': 'CONFIG_AUDIO_PW' },
             { 'name': 'sdl', 'if': 'CONFIG_AUDIO_SDL' },
             { 'name': 'sndio', 'if': 'CONFIG_AUDIO_SNDIO' },
             { 'name': 'spice', 'if': 'CONFIG_SPICE' },
@@ -456,6 +499,8 @@
                    'if': 'CONFIG_AUDIO_OSS' },
     'pa':        { 'type': 'AudiodevPaOptions',
                    'if': 'CONFIG_AUDIO_PA' },
+    'pw':        { 'type': 'AudiodevPwOptions',
+                   'if': 'CONFIG_AUDIO_PW' },
     'sdl':       { 'type': 'AudiodevSdlOptions',
                    'if': 'CONFIG_AUDIO_SDL' },
     'sndio':     { 'type': 'AudiodevSndioOptions',
qemu-options.hx +0 -0
index 88e93c6103..4fc73af804 100644

qemu-options.hx DEF("audiodev", HAS_ARG, QEMU_OPTION_audiodev, · line 786

Quoted 8 lines
qemu-options.hx +5 -0
@@ -779,6 +779,11 @@ DEF("audiodev", HAS_ARG, QEMU_OPTION_audiodev,
     "                in|out.name= source/sink device name\n"
     "                in|out.latency= desired latency in microseconds\n"
 #endif
+#ifdef CONFIG_AUDIO_PW
+    "-audiodev pw,id=id[,prop[=value][,...]]\n"
+    "                in|out.name= source/sink device name\n"
+    "                latency= desired latency in microseconds\n"
+#endif

Again, lets call the driver 'pipewire' rather than just 'pw'

Quoted 12 lines
qemu-options.hx +5 -0
 #ifdef CONFIG_AUDIO_SDL
     "-audiodev sdl,id=id[,prop[=value][,...]]\n"
     "                in|out.buffer-count= number of buffers\n"
@@ -942,6 +947,18 @@ SRST
         Desired latency in microseconds. The PulseAudio server will try
         to honor this value but actual latencies may be lower or higher.
 
+``-audiodev pw,id=id[,prop[=value][,...]]``
+    Creates a backend using Pipewire. This backend is available on
+    most systems.
+
+    Pipewire specific options are:

qemu-options.hx SRST · line 964

Quoted 10 lines
qemu-options.hx +7 -0
+
+    ``latency=latency``
+        Add extra latency to playback in microseconds
+
+    ``in|out.name=sink``
+        Use the specified source/sink for recording/playback.
+
 ``-audiodev sdl,id=id[,prop[=value][,...]]``
     Creates a backend using SDL. This backend is available on most
     systems, but you should use your platform's native backend if

I'll leave actual review of the backend functionality to someone else who is familiar with the audio subsystem.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#2 lore raw
Quoted 4 lines

Can you ensure the commit message text is line wrapped at approx 72 characters.

Noted, Thanks.

Just to confirm, you are claiming both copyright ownership for Red Hat

Quoted 2 lines

*and* personal copyright ownership ?

I just made some enquiry and given that this was developed inside of work
context I would use copyright ownership for Red Hat and author: Dorinda Bassey

As a style point, QEMU standard is for 4-space indents in

Quoted 2 lines

C code.

noted

I appreciate you probably just followed the example of pulseaudio,

Quoted 5 lines

abbreviated
to 'pa', but I'm not a fan of the existing usage there. So lets be more verbose
and say 'pipewire' so users are clear on what this is.

I agree, although pipewire seems to be lengthy but I don't mind using it.

Regards,
Dorinda.

Quoted 234 lines · Daniel P. Berrangé
Quoted 1 line · Dorinda Bassey

This commit adds a new audiodev backend to allow QEMU to use Pipewire as

both an audio sink and source. This backend is available on most systems.

Quoted 4 lines

Added Pipewire entry points for QEMU Pipewire audio backend Added wrappers for QEMU Pipewire audio backend in qpw_pcm_ops() qpw_write function returns the current state of the stream to pwaudio

and Writes some data to the server for playback streams using pipewire spa_ringbuffer implementation.

Quoted 1 line

qpw_read function returns the current state of the stream to pwaudio and

Reads some data from the server for capture streams using pipewire spa_ringbuffer implementation.

Quoted 1 line

These functions qpw_write and qpw_read are called during playback and

capture.

Quoted 1 line

Added some functions that convert pw audio formats to QEMU audio format

and vice versa which would be needed in the pipewire audio sink and source functions qpw_init_in() & qpw_init_out(). These methods that implement playback and recording will create streams for playback and capture that will start processing and will result in the on_process callbacks to be called.

Quoted 1 line

Built a connection to the Pipewire sound system server in the

qpw_audio_init() method.

Can you ensure the commit message text is line wrapped at approx 72 characters.

audio/pwaudio.c line 4

Quoted 10 lines
audio/pwaudio.c new file +4 -0
new file mode 100644
index 0000000000..89040ac99e
@@ -0,0 +1,816 @@
+/*
+ * QEMU Pipewire audio driver
+ *
+ * Copyright (c) 2023, Red Hat Inc, Dorinda Bassey <[email protected]>

Just to confirm, you are claiming both copyright ownership for Red Hat *and* personal copyright ownership ?

I ask because most of the time the employer will have exclusive copyright ownership for anything created in the course of employment. A few countries have local law, however, that fineses this allowing employees to retain copyright, or if you developed stuff outside of work context.

Quoted 12 lines
audio/pwaudio.c new file +12 -0
+
+#include "qemu/osdep.h"
+#include "qemu/module.h"
+#include "audio.h"
+#include <errno.h>
+#include <spa/param/audio/format-utils.h>
+#include <spa/utils/ringbuffer.h>
+#include <spa/utils/result.h>
+
+#include <pipewire/pipewire.h>
+
+#define AUDIO_CAP "pipewire"

audio/pwaudio.c line 45

Quoted 10 lines
audio/pwaudio.c new file +10 -0
+#define RINGBUFFER_SIZE    (1u << 22)
+#define RINGBUFFER_MASK    (RINGBUFFER_SIZE - 1)
+#define BUFFER_SAMPLES    128
+
+#include "audio_int.h"
+
+enum {
+  MODE_SINK,
+  MODE_SOURCE
+};

As a style point, QEMU standard is for 4-space indents in C code.

meson_options.txt option('tls_priority', type : 'string', value :

Quoted 5 lines
meson_options.txt +0 -0
index e5f199119e..f42605a8ac 100644
@@ -21,7 +21,7 @@ option('tls_priority', type : 'string', value :

'NORMAL',

meson_options.txt option('tls_priority', type : 'string', value : · line 22

Quoted 2 lines
meson_options.txt +0 -0
 option('default_devices', type : 'boolean', value : true,
        description: 'Include a default selection of devices in

emulators')

meson_options.txt option('tls_priority', type : 'string', value : · line 24

Quoted 2 lines
meson_options.txt +0 -1
 option('audio_drv_list', type: 'array', value: ['default'],
-       choices: ['alsa', 'coreaudio', 'default', 'dsound', 'jack',

'oss', 'pa', 'sdl', 'sndio'],

meson_options.txt option('tls_priority', type : 'string', value : · line 24

Quoted 1 line
meson_options.txt +1 -0
+       choices: ['alsa', 'coreaudio', 'default', 'dsound', 'jack',

'oss', 'pa', 'pw', 'sdl', 'sndio'],

I appreciate you probably just followed the example of pulseaudio, abbreviated
to 'pa', but I'm not a fan of the existing usage there. So lets be more verbose
and say 'pipewire' so users are clear on what this is.

meson_options.txt option('tls_priority', type : 'string', value : 'NORMAL',

Quoted 3 lines
meson_options.txt +0 -0
        description: 'Set audio driver list')
 option('block_drv_rw_whitelist', type : 'string', value : '',
        description: 'set block driver read-write whitelist (by default

affects only QEMU, not tools like qemu-img)')

Quoted 29 lines
meson_options.txt +2 -0
@@ -253,6 +253,8 @@ option('oss', type: 'feature', value: 'auto',
        description: 'OSS sound support')
 option('pa', type: 'feature', value: 'auto',
        description: 'PulseAudio sound support')
+option('pw', type: 'feature', value: 'auto',
+       description: 'Pipewire sound support')
 option('sndio', type: 'feature', value: 'auto',
        description: 'sndio sound support')
 
qapi/audio.json +11 -0
index 4e54c00f51..6c17d08ab8 100644
@@ -324,6 +324,48 @@
     '*out':    'AudiodevPaPerDirectionOptions',
     '*server': 'str' } }
 
+##
+# @AudiodevPwPerDirectionOptions:
+#
+# Options of the Pipewire backend that are used for both playback and
+# recording.
+#
+# @name: name of the sink/source to use
+#
+# @stream-name: name of the Pipewire stream created by qemu.  Can be
+#               used to identify the stream in Pipewire when you
+#               create multiple Pipewire devices or run multiple qemu

qapi/audio.json line 347

Quoted 10 lines
qapi/audio.json +10 -0
+#               instances (default: audiodev's id, since 7.1)
+#
+#
+# Since: 7.2
+##
+{ 'struct': 'AudiodevPwPerDirectionOptions',
+  'base': 'AudiodevPerDirectionOptions',
+  'data': {
+    '*name': 'str',
+    '*stream-name': 'str' } }

I tend to think we could afford to say "Pipewire" instead of "Pw" in the data types too.

Quoted 46 lines
qapi/audio.json +24 -0
+
+##
+# @AudiodevPwOptions:
+#
+# Options of the Pipewire audio backend.
+#
+# @in: options of the capture stream
+#
+# @out: options of the playback stream
+#
+# @latency: add latency to playback in microseconds
+#           (default 44100)
+#
+# Since: 7.2
+##
+{ 'struct': 'AudiodevPwOptions',
+  'data': {
+    '*in':     'AudiodevPwPerDirectionOptions',
+    '*out':    'AudiodevPwPerDirectionOptions',
+    '*latency': 'uint32' } }
+
 ##
 # @AudiodevSdlPerDirectionOptions:
 #
@@ -416,6 +458,7 @@
             { 'name': 'jack', 'if': 'CONFIG_AUDIO_JACK' },
             { 'name': 'oss', 'if': 'CONFIG_AUDIO_OSS' },
             { 'name': 'pa', 'if': 'CONFIG_AUDIO_PA' },
+            { 'name': 'pw', 'if': 'CONFIG_AUDIO_PW' },
             { 'name': 'sdl', 'if': 'CONFIG_AUDIO_SDL' },
             { 'name': 'sndio', 'if': 'CONFIG_AUDIO_SNDIO' },
             { 'name': 'spice', 'if': 'CONFIG_SPICE' },
@@ -456,6 +499,8 @@
                    'if': 'CONFIG_AUDIO_OSS' },
     'pa':        { 'type': 'AudiodevPaOptions',
                    'if': 'CONFIG_AUDIO_PA' },
+    'pw':        { 'type': 'AudiodevPwOptions',
+                   'if': 'CONFIG_AUDIO_PW' },
     'sdl':       { 'type': 'AudiodevSdlOptions',
                    'if': 'CONFIG_AUDIO_SDL' },
     'sndio':     { 'type': 'AudiodevSndioOptions',
qemu-options.hx +0 -0
index 88e93c6103..4fc73af804 100644

qemu-options.hx DEF("audiodev", HAS_ARG, QEMU_OPTION_audiodev, · line 786

Quoted 8 lines
qemu-options.hx +5 -0
@@ -779,6 +779,11 @@ DEF("audiodev", HAS_ARG, QEMU_OPTION_audiodev,
     "                in|out.name= source/sink device name\n"
     "                in|out.latency= desired latency in microseconds\n"
 #endif
+#ifdef CONFIG_AUDIO_PW
+    "-audiodev pw,id=id[,prop[=value][,...]]\n"
+    "                in|out.name= source/sink device name\n"
+    "                latency= desired latency in microseconds\n"
+#endif

Again, lets call the driver 'pipewire' rather than just 'pw'

Quoted 12 lines
qemu-options.hx +5 -0
 #ifdef CONFIG_AUDIO_SDL
     "-audiodev sdl,id=id[,prop[=value][,...]]\n"
     "                in|out.buffer-count= number of buffers\n"
@@ -942,6 +947,18 @@ SRST
         Desired latency in microseconds. The PulseAudio server will try
         to honor this value but actual latencies may be lower or higher.
 
+``-audiodev pw,id=id[,prop[=value][,...]]``
+    Creates a backend using Pipewire. This backend is available on
+    most systems.
+
+    Pipewire specific options are:

qemu-options.hx SRST · line 964

Quoted 10 lines
qemu-options.hx +7 -0
+
+    ``latency=latency``
+        Add extra latency to playback in microseconds
+
+    ``in|out.name=sink``
+        Use the specified source/sink for recording/playback.
+
 ``-audiodev sdl,id=id[,prop[=value][,...]]``
     Creates a backend using SDL. This backend is available on most
     systems, but you should use your platform's native backend if

I'll leave actual review of the backend functionality to someone else who is familiar with the audio subsystem.

With regards,
Daniel
--
|: https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o-
https://fstop138.berrange.com :|
|: https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|

#3 lore raw
In reply to Daniel P. Berrangé

15.02.2023 14:26, Daniel P. Berrangé пишет:
..

Quoted 6 lines

meson_options.txt option('tls_priority', type : 'string', value : 'NORMAL', · line 24

Quoted 2 lines
meson_options.txt +1 -1
-       choices: ['alsa', 'coreaudio', 'default', 'dsound', 'jack', 'oss', 'pa', 'sdl', 'sndio'],
+       choices: ['alsa', 'coreaudio', 'default', 'dsound', 'jack', 'oss', 'pa', 'pw', 'sdl', 'sndio'],

I appreciate you probably just followed the example of pulseaudio, abbreviated to 'pa', but I'm not a fan of the existing usage there. So lets be more verbose and say 'pipewire' so users are clear on what this is.

I'd vote for "pw" here, it is a quite well-known acronym. It is not because "pa" is used in qemu, it is because "pa" and now "pw" is used everywhere in context of linux sound.

But if there's no need to type it manually every time, it can be "pipewire" too.

/mjt

#4 lore raw
Quoted 5 lines · Michael Tokarev

15.02.2023 14:26, Daniel P. Berrangé пишет:
..

Quoted 3 lines
Quoted 2 lines
meson_options.txt +1 -1
-       choices: ['alsa', 'coreaudio', 'default', 'dsound', 'jack', 'oss', 'pa', 'sdl', 'sndio'],
+       choices: ['alsa', 'coreaudio', 'default', 'dsound', 'jack', 'oss', 'pa', 'pw', 'sdl', 'sndio'],
Quoted 7 lines
Quoted 3 lines

I appreciate you probably just followed the example of pulseaudio, abbreviated to 'pa', but I'm not a fan of the existing usage there. So lets be more verbose and say 'pipewire' so users are clear on what this is.

I'd vote for "pw" here, it is a quite well-known acronym. It is not because "pa" is used in qemu, it is because "pa" and now "pw" is used everywhere in context of linux sound.

I don't see 'pw' as well known. The package is 'pipewire', the processes are 'pipewire', the config files are 'pipewire'. The 'pw' abbreviation is too short to be meaningful unless you are already familiar with pipewire.

Quoted 2 lines

But if there's no need to type it manually every time, it can be "pipewire" too.

"pipewire" is not exactly a long word to begin with, and saving a couple of letters to abbreviate it isn't going to make a difference in the context of QEMU's command line.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#5 lore raw
In reply to Dorinda Bassey

Hi

Quoted 3 lines · Dorinda Bassey

This commit adds a new audiodev backend to allow QEMU to use Pipewire as both an audio sink and source. This backend is available on most systems.

Hmm, I would rather have less audio (and ui) backends in QEMU. (for audio, if I could introduce and keep only one, that would be
GStreamer: to remove the others..)

What is the main advantage compared to using the ALSA backend? (I assume pipewire depends on ALSA anyway on Linux)

Signature · 1 line
Marc-André Lureau
#6 lore raw
Quoted 5 lines · CET Marc-André Lureau

Hi

Quoted 2 lines · Dorinda Bassey

This commit adds a new audiodev backend to allow QEMU to use Pipewire as

both an audio sink and source. This backend is available on most systems.

Quoted 8 lines
Quoted 1 line

Hmm, I would rather have less audio (and ui) backends in QEMU. (for audio, if I could introduce and keep only one, that would be
GStreamer: to remove the others..)

What is the main advantage compared to using the ALSA backend? (I assume pipewire depends on ALSA anyway on Linux)

I think it does make sense to add Pipewire. Apparently it gains popularity.

The main advantage of Pipewire is its interoperability: It allows you to connect apps with each other that only support a specific audio system. Say one app that only supports JACK, another app that only supports PulseAudio, another that only supports ALSA and so on. So it tries to provide a universal plug on a system for all.

Best regards,
Christian Schoenebeck

#7 lore raw

Hi

Quoted 10 lines · Christian Schoenebeck
Quoted 5 lines · CET Marc-André Lureau

Hi

Quoted 2 lines · Dorinda Bassey

This commit adds a new audiodev backend to allow QEMU to use Pipewire as

both an audio sink and source. This backend is available on most systems.

Quoted 2 lines
Quoted 1 line
Quoted 8 lines
Quoted 6 lines

Hmm, I would rather have less audio (and ui) backends in QEMU. (for audio, if I could introduce and keep only one, that would be
GStreamer: to remove the others..)

What is the main advantage compared to using the ALSA backend? (I assume pipewire depends on ALSA anyway on Linux)

I think it does make sense to add Pipewire. Apparently it gains popularity.

My point is that pipewire has ALSA plugin (and also pulseaudio compat library etc). So why add another back in QEMU?

Quoted 10 lines

The main advantage of Pipewire is its interoperability: It allows you to connect apps with each other that only support a specific audio system. Say one app that only supports JACK, another app that only supports PulseAudio, another that only supports ALSA and so on. So it tries to provide a universal plug on a system for all.

Best regards,
Christian Schoenebeck

Signature · 1 line
Marc-André Lureau
#8 lore raw
Quoted 18 lines · Marc-André Lureau

Hi

Quoted 14 lines · Christian Schoenebeck
Quoted 5 lines · CET Marc-André Lureau

Hi

Quoted 2 lines · Dorinda Bassey

This commit adds a new audiodev backend to allow QEMU to use Pipewire as

both an audio sink and source. This backend is available on most systems.

Quoted 6 lines
Quoted 1 line

Hmm, I would rather have less audio (and ui) backends in QEMU. (for audio, if I could introduce and keep only one, that would be
GStreamer: to remove the others..)

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

What is the main advantage compared to using the ALSA backend? (I assume pipewire depends on ALSA anyway on Linux)

I think it does make sense to add Pipewire. Apparently it gains popularity.

My point is that pipewire has ALSA plugin (and also pulseaudio compat library etc). So why add another back in QEMU?

Every layer in the stack has potential to impact the audio quality. Even if its possible to wire up QEMU to pipewire via ALA/pulseaudio, it wouldn't surprise me if its more reliable (in terms of avoiding glitches/latency) to natively speak pipewire

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#9 lore raw
In reply to Marc-André Lureau
Quoted 4 lines

My point is that pipewire has ALSA plugin (and also pulseaudio compat library etc). So why add another back in QEMU?

Good question. Well the pulseaudio compatibility layer adds to the runtime overhead and dependency, dropping the usage of pw-pulse daemon as a runtime dependency would reduce footprint. For ALSA, it's a native layer and you do not want clients talking to ALSA directly if they need to share resources with other processes.

Regards,
Dorinda.

Quoted 48 lines · Marc-André Lureau

Hi

Quoted 5 lines · Christian Schoenebeck
Quoted 3 lines · CET Marc-André Lureau

Hi

On Wed, Feb 15, 2023 at 12:51 PM Dorinda Bassey <[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines

This commit adds a new audiodev backend to allow QEMU to use

Pipewire as

Quoted 11 lines

both an audio sink and source. This backend is available on most systems.

Quoted 8 lines
Quoted 1 line

Hmm, I would rather have less audio (and ui) backends in QEMU. (for audio, if I could introduce and keep only one, that would be
GStreamer: to remove the others..)

What is the main advantage compared to using the ALSA backend? (I assume pipewire depends on ALSA anyway on Linux)

I think it does make sense to add Pipewire. Apparently it gains

popularity.

My point is that pipewire has ALSA plugin (and also pulseaudio compat library etc). So why add another back in QEMU?

Quoted 2 lines

The main advantage of Pipewire is its interoperability: It allows you to connect apps with each other that only support a specific audio system.

Say

Quoted 1 line

one app that only supports JACK, another app that only supports

PulseAudio,

Quoted 1 line

another that only supports ALSA and so on. So it tries to provide a

universal

Quoted 6 lines

plug on a system for all.

Best regards,
Christian Schoenebeck

--
Marc-André Lureau

#10 lore raw
Quoted 7 lines · Dorinda Bassey
Quoted 4 lines

My point is that pipewire has ALSA plugin (and also pulseaudio compat library etc). So why add another back in QEMU?

Good question. Well the pulseaudio compatibility layer adds to the runtime overhead and dependency, dropping the usage of pw-pulse daemon as a runtime dependency would reduce footprint.

Oh, pulseaudio compatibility goes through another daemon. That is IMHO enough reason for a native pipewire backend, to avoid that overhead and specifically reduce latency.

(this and other good reasons should be added to the commit message).

take care,
Gerd

#11 lore raw
In reply to Christian Schoenebeck
Quoted 10 lines
Quoted 2 lines

What is the main advantage compared to using the ALSA backend? (I assume pipewire depends on ALSA anyway on Linux)

I think it does make sense to add Pipewire. Apparently it gains popularity.

The main advantage of Pipewire is its interoperability: It allows you to connect apps with each other that only support a specific audio system. Say one app that only supports JACK, another app that only supports PulseAudio, another that only supports ALSA and so on. So it tries to provide a universal plug on a system for all.

We already have support for pulse, jack and alsa in qemu, so there are already three different ways to talk to pipewire. So the question whenever adding yet another way makes sense is valid IMHO.

Are there any additional features available when using the pipewire protocol instead of pulseaudio or jack?

Are there any plans beyond audio? pipewire does video too and gnome screen sharing uses that. Is it maybe possible to wire up the qemu vga display and have pipewire send out qemu sound+display as video stream?

take care,
Gerd

#12 lore raw
Quoted 3 lines

Are there any additional features available when using the pipewire protocol instead of pulseaudio or jack?

yes, Pipewire supports both use cases, It is more or less a hybrid between pulseaudio and jack.
Pipewire uses a much more accurate timing model for timer based scheduling. Pipewire provides highly optimized audio processing paths. Pipewire uses ACP(copy of PulseAudio card profiles), UCM devices, profiles, ports, soft/hw volumes, jack detection, it supports ALSA API and UCM profiles.

Are there any plans beyond audio? pipewire does video too and gnome

Quoted 3 lines

screen sharing uses that. Is it maybe possible to wire up the qemu vga display and have pipewire send out qemu sound+display as video stream?

I don't know but It's worth considering.

Regards,
Dorinda.

Quoted 30 lines · Gerd Hoffmann
Quoted 4 lines
Quoted 2 lines

What is the main advantage compared to using the ALSA backend? (I assume pipewire depends on ALSA anyway on Linux)

I think it does make sense to add Pipewire. Apparently it gains

popularity.

Quoted 3 lines

The main advantage of Pipewire is its interoperability: It allows you to connect apps with each other that only support a specific audio system.

Say

Quoted 1 line

one app that only supports JACK, another app that only supports

PulseAudio,

Quoted 1 line

another that only supports ALSA and so on. So it tries to provide a

universal

Quoted 1 line

plug on a system for all.

We already have support for pulse, jack and alsa in qemu, so there are already three different ways to talk to pipewire. So the question whenever adding yet another way makes sense is valid IMHO.

Are there any additional features available when using the pipewire protocol instead of pulseaudio or jack?

Are there any plans beyond audio? pipewire does video too and gnome screen sharing uses that. Is it maybe possible to wire up the qemu vga display and have pipewire send out qemu sound+display as video stream?

take care,
Gerd

#13 lore raw
In reply to Marc-André Lureau
Quoted 10 lines · Marc-André Lureau

Hi

Quoted 3 lines · Dorinda Bassey

This commit adds a new audiodev backend to allow QEMU to use Pipewire as both an audio sink and source. This backend is available on most systems.

Hmm, I would rather have less audio (and ui) backends in QEMU. (for audio, if I could introduce and keep only one, that would be
GStreamer: to remove the others..)

Even if we take this patch, and don't have a gstreamer impl, it feels like we've scope for cutting down the backends.

The 'oss' driver for example ? On Linux that's long obsolete, with alsa or one of the higher level APIs available. OSS was also use on freebsd, but IIUC, sndio is better choice there now too ? Deprecate (and later remove) 'oss' now ?

The 'sdl' driver is setup in meson.build as our lowest priority impl, we'll pick any other driver ahead of sdl. Is there any compelling reason why we must give users the option of 'sdl' for audio when we have soo many other choices available ? Even if using SDL for graphics, it seems like we can use any other backend for audio. Deprecate (and later remove) 'sdl' for audio ?

IIUC, pipewire is positioned to replace pulseaudio. So if we take a pipewire backend, once pipewire is available in enough distros we could deprecate the pulseaudio backend and eventually remove it. Maybe the same applies for 'jack' ?

IOW, could we get to

- Windows: dsound
- MacOS: coreaudio
- (Open|Net|Free)BSD: sndio
- Linux: alsa/pipewire

?

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#14 lore raw
Quoted 12 lines · CET Daniel P. Berrangé
Quoted 10 lines · Marc-André Lureau

Hi

Quoted 3 lines · Dorinda Bassey

This commit adds a new audiodev backend to allow QEMU to use Pipewire as both an audio sink and source. This backend is available on most systems.

Hmm, I would rather have less audio (and ui) backends in QEMU. (for audio, if I could introduce and keep only one, that would be
GStreamer: to remove the others..)

Quoted 7 lines

Even if we take this patch, and don't have a gstreamer impl, it feels like we've scope for cutting down the backends.

The 'oss' driver for example ? On Linux that's long obsolete, with alsa or one of the higher level APIs available. OSS was also use on freebsd, but IIUC, sndio is better choice there now too ? Deprecate (and later remove) 'oss' now ?

There is indeed little reason to still use OSS nowadays IMO. At least marking OSS as deprecated would not hurt.

Quoted 8 lines

The 'sdl' driver is setup in meson.build as our lowest priority impl, we'll pick any other driver ahead of sdl. Is there any compelling reason why we must give users the option of 'sdl' for audio when we have soo many other choices available ? Even if using SDL for graphics, it seems like we can use any other backend for audio. Deprecate (and later remove) 'sdl' for audio ?

Quoted 4 lines

IIUC, pipewire is positioned to replace pulseaudio. So if we take a pipewire backend, once pipewire is available in enough distros we could deprecate the pulseaudio backend and eventually remove it. Maybe the same applies for 'jack' ?

AFAIK Pipewire is Linux only, whereas PulseAudio and JACK are available for Windows and macOS, too. And in it's current version (provided QEMU Pipewire patch), I don't see it as a full replacement for the JACK driver yet.

Quoted 12 lines

IOW, could we get to

- Windows: dsound
- MacOS: coreaudio
- (Open|Net|Free)BSD: sndio
- Linux: alsa/pipewire

?

With regards,
Daniel