Skip to contentSkip to conversation

Audio 20200526 patches

GIT PULL Applied Gerd Hoffmann 3 participants 12 messages May 26, 2020 – May 27, 2020

lore
Share & tools
lore
#0 lore raw

The following changes since commit fea8f3ed739536fca027cf56af7f5576f37ef9cd:

Merge remote-tracking branch 'remotes/philmd-gitlab/tags/pflash-next-20200522' into staging (2020-05-22 18:54:47 +0100)

are available in the Git repository at:

git://git.kraxel.org/qemu tags/audio-20200526-pull-request

for you to fetch changes up to b3b8a1fea6ed5004bbad2f70833caee70402bf02:

hw/mips/mips_fulong2e: Remove unused 'audio/audio.h' include (2020-05-26 08:46:14 +0200)

----------------------------------------------------------------
audio: add JACK client audiodev.
audio: bugfixes and cleanups.

----------------------------------------------------------------

Bruce Rogers (1):
audio: fix wavcapture segfault

Geoffrey McRae (1):
audio/jack: add JACK client audiodev

Philippe Mathieu-Daudé (4):
hw/audio/gus: Use AUDIO_HOST_ENDIANNESS definition from

    'audio/audio.h'

audio: Let audio_sample_to_uint64() use const samples argument
audio: Let capture_callback handler use const buffer argument hw/mips/mips_fulong2e: Remove unused 'audio/audio.h' include

Prasad J Pandit (1):
es1370: check total frame count against current frame

Volker Rümelin (1):
audio/mixeng: fix clang 10+ warning

 configure               |  17 +
 audio/audio.h           |   4 +-
 audio/audio_template.h  |   2 +
 audio/audio.c           |   5 +-
 audio/jackaudio.c       | 667 ++++++++++++++++++++++++++++++++++++++++
 audio/mixeng.c          |   9 +-
 audio/wavcapture.c      |   2 +-
 hw/audio/es1370.c       |   7 +-
 hw/audio/gus.c          |   8 +-
 hw/mips/mips_fulong2e.c |   1 -
 ui/vnc.c                |   2 +-
 audio/Makefile.objs     |   5 +
 qapi/audio.json         |  56 +++-
 13 files changed, 763 insertions(+), 22 deletions(-)
 create mode 100644 audio/jackaudio.c
Signature · 1 line
2.18.4
#1 lore raw

[PULL 5/8] audio: fix wavcapture segfault

From: Bruce Rogers <[email protected]>

Commit 571a8c522e caused the HMP wavcapture command to segfault when processing audio data in audio_pcm_sw_write(), where a NULL sw->hw->pcm_ops is dereferenced. This fix checks that the pointer is valid before dereferincing it. A similar fix is also made in the parallel function audio_pcm_sw_read().

Fixes 571a8c522e (audio: split ctl_* functions into enable_* and

volume_*)

Message-id: [email protected]

---
 audio/audio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
audio/audio.c +2 -2
index 95d9fb16caa5..ce8c6dec5f47 100644
@@ -649,7 +649,7 @@ static size_t audio_pcm_sw_read(SWVoiceIn *sw, void *buf, size_t size)
         total += isamp;
     }
 
-    if (!hw->pcm_ops->volume_in) {
+    if (hw->pcm_ops && !hw->pcm_ops->volume_in) {
         mixeng_volume (sw->buf, ret, &sw->vol);
     }
 
@@ -736,7 +736,7 @@ static size_t audio_pcm_sw_write(SWVoiceOut *sw, void *buf, size_t size)
     if (swlim) {
         sw->conv (sw->buf, buf, swlim);
 
-        if (!sw->hw->pcm_ops->volume_out) {
+        if (sw->hw->pcm_ops && !sw->hw->pcm_ops->volume_out) {
             mixeng_volume (sw->buf, swlim, &sw->vol);
         }
     }
Signature · 1 line
2.18.4
#2 lore raw

[PULL 1/8] es1370: check total frame count against current frame

In reply to Gerd Hoffmann

From: Prasad J Pandit <[email protected]>

A guest user may set channel frame count via es1370_write() such that, in es1370_transfer_audio(), total frame count 'size' is lesser than the number of frames that are processed 'cnt'.

    int cnt = d->frame_cnt >> 16;
    int size = d->frame_cnt & 0xffff;

if (size < cnt), it results in incorrect calculations leading to OOB access issue(s). Add check to avoid it.

Message-id: [email protected]

---
 hw/audio/es1370.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
hw/audio/es1370.c +5 -2
index 89c4dabcd44f..5f8a83ff5624 100644
@@ -643,6 +643,9 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel,
     int csc_bytes = (csc + 1) << d->shift;
     int cnt = d->frame_cnt >> 16;
     int size = d->frame_cnt & 0xffff;
+    if (size < cnt) {
+        return;
+    }
     int left = ((size - cnt + 1) << 2) + d->leftover;
     int transferred = 0;
     int temp = MIN (max, MIN (left, csc_bytes));
@@ -651,7 +654,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel,
     addr += (cnt << 2) + d->leftover;
 
     if (index == ADC_CHANNEL) {
-        while (temp) {
+        while (temp > 0) {
             int acquired, to_copy;
 
             to_copy = MIN ((size_t) temp, sizeof (tmpbuf));
@@ -669,7 +672,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel,
     else {
         SWVoiceOut *voice = s->dac_voice[index];
 
-        while (temp) {
+        while (temp > 0) {
             int copied, to_copy;
 
             to_copy = MIN ((size_t) temp, sizeof (tmpbuf));
Signature · 1 line
2.18.4
#3 lore raw

[PULL 8/8] hw/mips/mips_fulong2e: Remove unused 'audio/audio.h' include

In reply to Gerd Hoffmann

From: Philippe Mathieu-Daudé <[email protected]>

The Fuloong machine never had to use "audio/audio.h", remove it.

Message-id: [email protected]

---
 hw/mips/mips_fulong2e.c | 1 -
 1 file changed, 1 deletion(-)
hw/mips/mips_fulong2e.c +0 -1
index ef02d54b335c..05b9efa516cf 100644
@@ -33,7 +33,6 @@
 #include "hw/mips/mips.h"
 #include "hw/mips/cpudevs.h"
 #include "hw/pci/pci.h"
-#include "audio/audio.h"
 #include "qemu/log.h"
 #include "hw/loader.h"
 #include "hw/ide/pci.h"
Signature · 1 line
2.18.4
#4 lore raw

[PULL 7/8] audio: Let capture_callback handler use const buffer argument

In reply to Gerd Hoffmann

From: Philippe Mathieu-Daudé <[email protected]>

The buffer is the captured input to pass to backends. As we should not modify it, mark the argument const.

Message-Id: <[email protected]>

---
 audio/audio.h      | 2 +-
 audio/wavcapture.c | 2 +-
 ui/vnc.c           | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
audio/audio.h +1 -1
index f27a12298fe5..b883ebfb1f8e 100644
@@ -60,7 +60,7 @@ typedef enum {
 
 struct audio_capture_ops {
     void (*notify) (void *opaque, audcnotification_e cmd);
-    void (*capture) (void *opaque, void *buf, int size);
+    void (*capture) (void *opaque, const void *buf, int size);
     void (*destroy) (void *opaque);
 };
 
audio/wavcapture.c +1 -1
index 8d7ce2eda145..17e87ed6f45e 100644
@@ -71,7 +71,7 @@ static void wav_destroy (void *opaque)
     g_free (wav->path);
 }
 
-static void wav_capture (void *opaque, void *buf, int size)
+static void wav_capture(void *opaque, const void *buf, int size)
 {
     WAVState *wav = opaque;
 
ui/vnc.c +1 -1
index 1d7138a3a073..12a12714e129 100644
@@ -1177,7 +1177,7 @@ static void audio_capture_destroy(void *opaque)
 {
 }
 
-static void audio_capture(void *opaque, void *buf, int size)
+static void audio_capture(void *opaque, const void *buf, int size)
 {
     VncState *vs = opaque;
 
Signature · 1 line
2.18.4
#5 lore raw

[PULL 2/8] hw/audio/gus: Use AUDIO_HOST_ENDIANNESS definition from 'audio/audio.h'

In reply to Gerd Hoffmann

From: Philippe Mathieu-Daudé <[email protected]>

Use the generic AUDIO_HOST_ENDIANNESS definition instead of a custom one.

Message-id: [email protected]

---
 hw/audio/gus.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
hw/audio/gus.c +1 -7
index eb4a803fb53b..c8df2bde6b32 100644
@@ -41,12 +41,6 @@
 #define ldebug(...)
 #endif
 
-#ifdef HOST_WORDS_BIGENDIAN
-#define GUS_ENDIANNESS 1
-#else
-#define GUS_ENDIANNESS 0
-#endif
-
 #define TYPE_GUS "gus"
 #define GUS(obj) OBJECT_CHECK (GUSState, (obj), TYPE_GUS)
 
@@ -256,7 +250,7 @@ static void gus_realizefn (DeviceState *dev, Error **errp)
     as.freq = s->freq;
     as.nchannels = 2;
     as.fmt = AUDIO_FORMAT_S16;
-    as.endianness = GUS_ENDIANNESS;
+    as.endianness = AUDIO_HOST_ENDIANNESS;
 
     s->voice = AUD_open_out (
         &s->card,
Signature · 1 line
2.18.4
#6 lore raw

[PULL 3/8] audio/jack: add JACK client audiodev

In reply to Gerd Hoffmann

From: Geoffrey McRae <[email protected]>

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

Message-Id: <[email protected]>

---
 configure              |  17 ++
 audio/audio_template.h |   2 +
 audio/audio.c          |   1 +
 audio/jackaudio.c      | 667 +++++++++++++++++++++++++++++++++++++++++
 audio/Makefile.objs    |   5 +
 qapi/audio.json        |  56 +++-
 6 files changed, 746 insertions(+), 2 deletions(-)
 create mode 100644 audio/jackaudio.c
configure +17 -0
index 2fc05c4465cb..b969dee675bb 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
audio/audio_template.h +2 -0
index 7013d3041f91..8dd48ce14e9d 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/audio.c +1 -0
index 7a9e6803558b..95d9fb16caa5 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/jackaudio.c new file +667 -0

667 lines not on this page · raw message

audio/Makefile.objs +5 -0
index d7490a379f3e..b4a4c11f3122 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)
qapi/audio.json +54 -2

77 lines not on this page · raw message

Signature · 1 line
2.18.4
#7 lore raw

[PULL 4/8] audio/mixeng: fix clang 10+ warning

In reply to Gerd Hoffmann

From: Volker Rümelin <[email protected]>

The code in CONV_NATURAL_FLOAT() and CLIP_NATURAL_FLOAT() seems to use the constant 2^31-0.5 to convert float to integer and back. But the float type lacks the required precision and the constant used for the conversion is 2^31. This is equiva- lent to a [-1.f, 1.f] <-> [INT32_MIN, INT32_MAX + 1] mapping.

This patch explicitly writes down the used constant. The compiler generated code doesn't change.

The constant 2^31 has an exact float representation and the clang 10 compiler stops complaining about an implicit int to float conversion with a changed value.

A few notes:
- The conversion of 1.f to INT32_MAX + 1 doesn't overflow. The type of the destination variable is int64_t.
- At a later stage one of the clip_* functions in audio/mixeng_template.h limits INT32_MAX + 1 to the integer range.
- The clip_natural_float_* functions in audio/mixeng.c convert INT32_MAX and INT32_MAX + 1 to 1.f.

Message-id: [email protected]

---
 audio/mixeng.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
audio/mixeng.c +3 -2
index 739a500449ce..924dcb858af5 100644
@@ -271,11 +271,12 @@ f_sample *mixeng_clip[2][2][2][3] = {
 #define CONV_NATURAL_FLOAT(x) (x)
 #define CLIP_NATURAL_FLOAT(x) (x)
 #else
-static const float float_scale = UINT_MAX / 2.f;
+/* macros to map [-1.f, 1.f] <-> [INT32_MIN, INT32_MAX + 1] */
+static const float float_scale = (int64_t)INT32_MAX + 1;
 #define CONV_NATURAL_FLOAT(x) ((x) * float_scale)
 
 #ifdef RECIPROCAL
-static const float float_scale_reciprocal = 2.f / UINT_MAX;
+static const float float_scale_reciprocal = 1.f / ((int64_t)INT32_MAX + 1);
 #define CLIP_NATURAL_FLOAT(x) ((x) * float_scale_reciprocal)
 #else
 #define CLIP_NATURAL_FLOAT(x) ((x) / float_scale)
Signature · 1 line
2.18.4
#8 lore raw

[PULL 6/8] audio: Let audio_sample_to_uint64() use const samples argument

In reply to Gerd Hoffmann

From: Philippe Mathieu-Daudé <[email protected]>

The samples are the input to convert to u64. As we should not modify them, mark the argument const.

Message-Id: <[email protected]>

---
 audio/audio.h  | 2 +-
 audio/mixeng.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
audio/audio.h +1 -1
index 0db3c7dd5e06..f27a12298fe5 100644
@@ -163,7 +163,7 @@ int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
 bool audio_is_cleaning_up(void);
 void audio_cleanup(void);
 
-void audio_sample_to_uint64(void *samples, int pos,
+void audio_sample_to_uint64(const void *samples, int pos,
                             uint64_t *left, uint64_t *right);
 void audio_sample_from_uint64(void *samples, int pos,
                             uint64_t left, uint64_t right);
audio/mixeng.c +2 -2
index 924dcb858af5..f27deb165b67 100644
@@ -339,10 +339,10 @@ f_sample *mixeng_clip_float[2] = {
     clip_natural_float_from_stereo,
 };
 
-void audio_sample_to_uint64(void *samples, int pos,
+void audio_sample_to_uint64(const void *samples, int pos,
                             uint64_t *left, uint64_t *right)
 {
-    struct st_sample *sample = samples;
+    const struct st_sample *sample = samples;
     sample += pos;
 #ifdef FLOAT_MIXENG
     error_report(
Signature · 1 line
2.18.4
#9 lore raw
In reply to Gerd Hoffmann
Quoted 11 lines · Gerd Hoffmann

The following changes since commit fea8f3ed739536fca027cf56af7f5576f37ef9cd:

Merge remote-tracking branch 'remotes/philmd-gitlab/tags/pflash-next-20200522' into staging (2020-05-22 18:54:47 +0100)

are available in the Git repository at:

git://git.kraxel.org/qemu tags/audio-20200526-pull-request

for you to fetch changes up to b3b8a1fea6ed5004bbad2f70833caee70402bf02:

Quoted 7 lines

hw/mips/mips_fulong2e: Remove unused 'audio/audio.h' include (2020-05-26 08:46:14 +0200)

----------------------------------------------------------------
audio: add JACK client audiodev.
audio: bugfixes and cleanups.

----------------------------------------------------------------

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.1
for any user-visible changes.

-- PMM

#10 lore raw
In reply to Gerd Hoffmann
Quoted 10 lines · Gerd Hoffmann

The following changes since commit fea8f3ed739536fca027cf56af7f5576f37ef9cd:

Merge remote-tracking branch 'remotes/philmd-gitlab/tags/pflash-next-20200522' into staging (2020-05-22 18:54:47 +0100)

are available in the Git repository at:

git://git.kraxel.org/qemu tags/audio-20200526-pull-request

for you to fetch changes up to b3b8a1fea6ed5004bbad2f70833caee70402bf02:

Quoted 7 lines

hw/mips/mips_fulong2e: Remove unused 'audio/audio.h' include (2020-05-26 08:46:14 +0200)

----------------------------------------------------------------
audio: add JACK client audiodev.
audio: bugfixes and cleanups.

----------------------------------------------------------------

$ qemu-system-aarch64 -S -accel qtest -display none -M akita -monitor stdio
(qemu) qemu-system-aarch64: /work/armbru/qemu/audio/paaudio.c:779: qpa_audio_init: Assertion `dev->driver == AUDIODEV_DRIVER_PA' failed.

Same for 40p, akita, borzoi, cheetah, integratorcp, milkymist, musicpal, n800, n810, realview-eb, realview-eb-mpcore, realview-pb-a8, realview-pbx-a9, spitz, terrier, versatileab, versatilepb, vexpress-a15, vexpress-a9, xlnx-zcu102, z2.

git-bisect blames commit 2e44570321 "audio/jack: add JACK client audiodev".

#11 lore raw
Quoted 14 lines · Markus Armbruster
Quoted 12 lines · Gerd Hoffmann

The following changes since commit fea8f3ed739536fca027cf56af7f5576f37ef9cd:

Merge remote-tracking branch 'remotes/philmd-gitlab/tags/pflash-next-20200522' into staging (2020-05-22 18:54:47 +0100)

are available in the Git repository at:

git://git.kraxel.org/qemu tags/audio-20200526-pull-request

for you to fetch changes up to b3b8a1fea6ed5004bbad2f70833caee70402bf02:

hw/mips/mips_fulong2e: Remove unused 'audio/audio.h' include (2020-05-26 08:46:14 +0200)

Quoted 8 lines
Quoted 5 lines

----------------------------------------------------------------
audio: add JACK client audiodev.
audio: bugfixes and cleanups.

----------------------------------------------------------------

$ qemu-system-aarch64 -S -accel qtest -display none -M akita -monitor stdio
(qemu) qemu-system-aarch64: /work/armbru/qemu/audio/paaudio.c:779: qpa_audio_init: Assertion `dev->driver == AUDIODEV_DRIVER_PA' failed.

Hmm, seems to be a dependency issue in our build system. rm -rf $builddir, rebuild, try again, assert gone.

take care,
Gerd