Skip to contentSkip to conversation

audio/jack: add JACK client audiodev

PATCH Superseded Geoffrey McRae 2 participants 3 messages Apr 29, 2020

v3 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 audio/jack: add JACK client audiodev

This commit adds a new audiodev backend to allow QEMU to use JACK as both an audio sink and source.

---
 audio/Makefile.objs    |   5 +
 audio/audio.c          |   1 +
 audio/audio_template.h |   2 +
 audio/jackaudio.c      | 615 +++++++++++++++++++++++++++++++++++++++++
 configure              |  17 ++
 qapi/audio.json        |  50 +++-
 6 files changed, 688 insertions(+), 2 deletions(-)
 create mode 100644 audio/jackaudio.c
audio/Makefile.objs +5 -0
index d7490a379f..b4a4c11f31 100644
@@ -28,3 +28,8 @@ common-obj-$(CONFIG_AUDIO_SDL) += sdl.mo
 sdl.mo-objs = sdlaudio.o
 sdl.mo-cflags := $(SDL_CFLAGS)
 sdl.mo-libs := $(SDL_LIBS)
+
+# jack module
+common-obj-$(CONFIG_AUDIO_JACK) += jack.mo
+jack.mo-objs = jackaudio.o
+jack.mo-libs := $(JACK_LIBS)
audio/audio.c +1 -0
index 7a9e680355..95d9fb16ca 100644
@@ -1969,6 +1969,7 @@ void audio_create_pdos(Audiodev *dev)
         CASE(ALSA, alsa, Alsa);
         CASE(COREAUDIO, coreaudio, Coreaudio);
         CASE(DSOUND, dsound, );
+        CASE(JACK, jack, Jack);
         CASE(OSS, oss, Oss);
         CASE(PA, pa, Pa);
         CASE(SDL, sdl, );
audio/audio_template.h +2 -0
index 7013d3041f..8dd48ce14e 100644
@@ -330,6 +330,8 @@ AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)(Audiodev *dev)
             dev->u.coreaudio.TYPE);
     case AUDIODEV_DRIVER_DSOUND:
         return dev->u.dsound.TYPE;
+    case AUDIODEV_DRIVER_JACK:
+        return qapi_AudiodevJackPerDirectionOptions_base(dev->u.jack.TYPE);
     case AUDIODEV_DRIVER_OSS:
         return qapi_AudiodevOssPerDirectionOptions_base(dev->u.oss.TYPE);
     case AUDIODEV_DRIVER_PA:
audio/jackaudio.c new file +615 -0

615 lines not on this page · raw message

configure +17 -0
index 23b5e93752..004502c775 100755
@@ -3629,6 +3629,22 @@ for drv in $audio_drv_list; do
       oss_libs="$oss_lib"
     ;;
 
+    jack | try-jack)
+    if $pkg_config jack --exists; then
+        jack_libs=$($pkg_config jack --libs)
+        if test "$drv" = "try-jack"; then
+            audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-jack/jack/')
+        fi
+    else
+        if test "$drv" = "try-jack"; then
+            audio_drv_list=$(echo "$audio_drv_list" | sed -e 's/try-jack//')
+        else
+            error_exit "$drv check failed" \
+                "Make sure to have the $drv libs and headers installed."
+        fi
+    fi
+    ;;
+
     *)
     echo "$audio_possible_drivers" | grep -q "\<$drv\>" || {
         error_exit "Unknown driver '$drv' selected" \
@@ -6904,6 +6920,7 @@ echo "PULSE_LIBS=$pulse_libs" >> $config_host_mak
 echo "COREAUDIO_LIBS=$coreaudio_libs" >> $config_host_mak
 echo "DSOUND_LIBS=$dsound_libs" >> $config_host_mak
 echo "OSS_LIBS=$oss_libs" >> $config_host_mak
+echo "JACK_LIBS=$jack_libs" >> $config_host_mak
 if test "$audio_win_int" = "yes" ; then
   echo "CONFIG_AUDIO_WIN_INT=y" >> $config_host_mak
 fi
qapi/audio.json +48 -2

68 lines not on this page · raw message

Signature · 1 line
2.20.1
#1 lore raw
Quoted 11 lines · Geoffrey McRae

This commit adds a new audiodev backend to allow QEMU to use JACK as both an audio sink and source.

---
  audio/Makefile.objs    |   5 +
  audio/audio.c          |   1 +
  audio/audio_template.h |   2 +
  audio/jackaudio.c      | 615 +++++++++++++++++++++++++++++++++++++++++
  configure              |  17 ++
  qapi/audio.json        |  50 +++-

Focusing just on UI:

Quoted 4 lines

+++ b/qapi/audio.json

qapi/audio.json +0 -0
@@ -152,6 +152,51 @@
      '*out':     'AudiodevPerDirectionOptions',
      '*latency': 'uint32' } }

qapi/audio.json line 163

Quoted 10 lines
qapi/audio.json +9 -0
 
+##
+# @AudiodevJackPerDirectionOptions:
+#
+# Options of the JACK backend that are used for both playback and
+# recording.
+#
+# @server_name: select from among several possible concurrent server instances.
+# If unspecified, use "default" unless $JACK_DEFAULT_SERVER is defined in the
+# process environment.

Our convention is to prefer '-' over '_' except in cases of pre-existing consistency. This should be 'server-name' unless you have an example of what we have to be consistent with.

qapi/audio.json line 172

Quoted 9 lines
qapi/audio.json +9 -0
+#
+# @client_name: the client name to use. The server will modify this name to
+# create a unique variant, if needed unless @exact_name is true.
+#
+# @start_server: set to true to start a jack server instance if one is not
+# present.
+#
+# @exact_name: use the exact name requested otherwise JACK automatically
+# generates a unique one, if needed.

Ditto for these three.

Review line 174

Quoted 2 lines
(quoted diff) +2 -0
+#
+# Since: 4.0

The earliest this will be added is 5.1, not 4.0.

Quoted 9 lines
qapi/audio.json +9 -0
+##
+{ 'struct': 'AudiodevJackPerDirectionOptions',
+  'base': 'AudiodevPerDirectionOptions',
+  'data': {
+    '*server_name':  'str',
+    '*client_name':  'str',
+    '*start_server': 'bool',
+    '*exact_name':   'bool' } }
+

qapi/audio.json line 193

Quoted 10 lines
qapi/audio.json +10 -0
+##
+# @AudiodevJackOptions:
+#
+# Options of the JACK audio backend.
+#
+# @in: options of the capture stream
+#
+# @out: options of the playback stream
+#
+# Since: 4.0

5.1

Quoted 10 lines
qapi/audio.json +6 -0
+##
+{ 'struct': 'AudiodevJackOptions',
+  'data': {
+    '*in':  'AudiodevJackPerDirectionOptions',
+    '*out': 'AudiodevJackPerDirectionOptions' } }
+
  ##
  # @AudiodevOssPerDirectionOptions:
  #

qapi/audio.json line 349

Quoted 7 lines
qapi/audio.json +2 -2
@@ -300,8 +345,8 @@
  # Since: 4.0
  ##
  { 'enum': 'AudiodevDriver',
-  'data': [ 'none', 'alsa', 'coreaudio', 'dsound', 'oss', 'pa', 'sdl',
-            'spice', 'wav' ] }
+  'data': [ 'none', 'alsa', 'coreaudio', 'dsound', 'jack', 'oss', 'pa',
+            'sdl', 'spice', 'wav' ] }

It's worth adding a doc comment that @jack was added in 5.1 (I didn't check if audio.json has an example of adding to an enum, but other .json files do)

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#2 lore raw
Quoted 27 lines · Eric Blake
Quoted 4 lines · Geoffrey McRae

This commit adds a new audiodev backend to allow QEMU to use JACK as both an audio sink and source.

Quoted 8 lines
---
  audio/Makefile.objs    |   5 +
  audio/audio.c          |   1 +
  audio/audio_template.h |   2 +
  audio/jackaudio.c      | 615 
+++++++++++++++++++++++++++++++++++++++++
  configure              |  17 ++
  qapi/audio.json        |  50 +++-

Focusing just on UI:

Quoted 11 lines

+++ b/qapi/audio.json

qapi/audio.json +6 -0
@@ -152,6 +152,51 @@
      '*out':     'AudiodevPerDirectionOptions',
      '*latency': 'uint32' } }
  +##
+# @AudiodevJackPerDirectionOptions:
+#
+# Options of the JACK backend that are used for both playback and
+# recording.
+#
+# @server_name: select from among several possible concurrent server 
Quoted 8 lines
Quoted 4 lines

instances.
+# If unspecified, use "default" unless $JACK_DEFAULT_SERVER is defined in the
+# process environment.

Our convention is to prefer '-' over '_' except in cases of pre-existing consistency. This should be 'server-name' unless you have an example of what we have to be consistent with.

No reason at all just didn't think about it, I will correct it :)

Quoted 16 lines
Quoted 11 lines
(quoted diff) +2 -0
+#
+# @client_name: the client name to use. The server will modify this 

name to

qapi/audio.json +3 -0
+# create a unique variant, if needed unless @exact_name is true.
+#
+# @start_server: set to true to start a jack server instance if one 

is not

qapi/audio.json +3 -0
+# present.
+#
+# @exact_name: use the exact name requested otherwise JACK 
Quoted 2 lines

automatically
+# generates a unique one, if needed.

Ditto for these three.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+#
+# Since: 4.0

The earliest this will be added is 5.1, not 4.0.

Yup, copy & paste error :)

Quoted 38 lines
Quoted 10 lines
qapi/audio.json +9 -0
+##
+{ 'struct': 'AudiodevJackPerDirectionOptions',
+  'base': 'AudiodevPerDirectionOptions',
+  'data': {
+    '*server_name':  'str',
+    '*client_name':  'str',
+    '*start_server': 'bool',
+    '*exact_name':   'bool' } }
+

qapi/audio.json line 193

Quoted 10 lines
qapi/audio.json +10 -0
+##
+# @AudiodevJackOptions:
+#
+# Options of the JACK audio backend.
+#
+# @in: options of the capture stream
+#
+# @out: options of the playback stream
+#
+# Since: 4.0

5.1

Quoted 15 lines
qapi/audio.json +6 -1
+##
+{ 'struct': 'AudiodevJackOptions',
+  'data': {
+    '*in':  'AudiodevJackPerDirectionOptions',
+    '*out': 'AudiodevJackPerDirectionOptions' } }
+
  ##
  # @AudiodevOssPerDirectionOptions:
  #
@@ -300,8 +345,8 @@
  # Since: 4.0
  ##
  { 'enum': 'AudiodevDriver',
-  'data': [ 'none', 'alsa', 'coreaudio', 'dsound', 'oss', 'pa', 
 'sdl',
Quoted 8 lines

qapi/audio.json line 349

Quoted 4 lines
qapi/audio.json +2 -1
-            'spice', 'wav' ] }
+  'data': [ 'none', 'alsa', 'coreaudio', 'dsound', 'jack', 'oss', 
 'pa',
+            'sdl', 'spice', 'wav' ] }

It's worth adding a doc comment that @jack was added in 5.1 (I didn't check if audio.json has an example of adding to an enum, but other .json files do)

No worries, I will see if I can figure this out.

-Geoff