Skip to contentSkip to conversation

Audio 20210617 patches

GIT PULL Applied Gerd Hoffmann 3 participants 10 messages Jun 17, 2021 – Jun 18, 2021 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

The following changes since commit 38848ce565849e5b867a5e08022b3c755039c11a:

Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20210616' into staging (2021-06-16 17:02:30 +0100)

are available in the Git repository at:

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

for you to fetch changes up to 986bdbc6a29c4d7ef125299c5013783e30dc2cae:

coreaudio: Fix output stream format settings (2021-06-17 12:00:26 +0200)

----------------------------------------------------------------
audio: bugfix collection.

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

Akihiko Odaki (2):
audio: Fix format specifications of debug logs
coreaudio: Fix output stream format settings

Philippe Mathieu-Daudé (1):
hw/audio/sb16: Avoid assertion by restricting I/O sampling rate range

Volker Rümelin (4):
alsaaudio: remove #ifdef DEBUG to avoid bit rot
paaudio: remove unused stream flags
audio: move code to audio/audio.c
jackaudio: avoid that the client name contains the word (NULL)

 audio/audio_int.h            |  2 ++
 audio/alsaaudio.c            | 10 +++----
 audio/audio.c                | 15 ++++++++---
 audio/coreaudio.c            | 48 +++++++++------------------------
 audio/jackaudio.c            |  3 +--
 audio/paaudio.c              | 10 ++-----
 hw/audio/sb16.c              | 14 ++++++++++
 tests/qtest/fuzz-sb16-test.c | 52 ++++++++++++++++++++++++++++++++++++
 MAINTAINERS                  |  1 +
 tests/qtest/meson.build      |  1 +
 10 files changed, 102 insertions(+), 54 deletions(-)
 create mode 100644 tests/qtest/fuzz-sb16-test.c
Signature · 1 line
2.31.1
#1 lore raw

[PULL 3/7] audio: move code to audio/audio.c

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

Move the code to generate the pa_context_new() application name argument to a function in audio/audio.c. The new function audio_application_name() will also be used in the jackaudio backend.

Message-Id: <[email protected]>

---
 audio/audio_int.h | 2 ++
 audio/audio.c     | 9 +++++++++
 audio/paaudio.c   | 5 +----
 3 files changed, 12 insertions(+), 4 deletions(-)
audio/audio_int.h +2 -0
index 06f0913835b0..6d685e24a388 100644
@@ -243,6 +243,8 @@ void *audio_calloc (const char *funcname, int nmemb, size_t size);
 
 void audio_run(AudioState *s, const char *msg);
 
+const char *audio_application_name(void);
+
 typedef struct RateCtl {
     int64_t start_ticks;
     int64_t bytes_sent;
audio/audio.c +9 -0
index 534278edfed2..052ca6cb789b 100644
@@ -32,6 +32,7 @@
 #include "qapi/qapi-visit-audio.h"
 #include "qemu/cutils.h"
 #include "qemu/module.h"
+#include "qemu-common.h"
 #include "sysemu/replay.h"
 #include "sysemu/runstate.h"
 #include "ui/qemu-spice.h"
@@ -2172,6 +2173,14 @@ const char *audio_get_id(QEMUSoundCard *card)
     }
 }
 
+const char *audio_application_name(void)
+{
+    const char *vm_name;
+
+    vm_name = qemu_get_vm_name();
+    return vm_name ? vm_name : "qemu";
+}
+
 void audio_rate_start(RateCtl *rate)
 {
     memset(rate, 0, sizeof(RateCtl));
audio/paaudio.c +1 -4
index 14b4269c5500..75401d53910a 100644
@@ -2,7 +2,6 @@
 
 #include "qemu/osdep.h"
 #include "qemu/module.h"
-#include "qemu-common.h"
 #include "audio.h"
 #include "qapi/opts-visitor.h"
 
@@ -753,7 +752,6 @@ static int qpa_validate_per_direction_opts(Audiodev *dev,
 /* common */
 static void *qpa_conn_init(const char *server)
 {
-    const char *vm_name;
     PAConnection *c = g_malloc0(sizeof(PAConnection));
     QTAILQ_INSERT_TAIL(&pa_conns, c, list);
 
@@ -762,9 +760,8 @@ static void *qpa_conn_init(const char *server)
         goto fail;
     }
 
-    vm_name = qemu_get_vm_name();
     c->context = pa_context_new(pa_threaded_mainloop_get_api(c->mainloop),
-                                vm_name ? vm_name : "qemu");
+                                audio_application_name());
     if (!c->context) {
         goto fail;
     }
Signature · 1 line
2.31.1
#2 lore raw

[PULL 6/7] audio: Fix format specifications of debug logs

In reply to Gerd Hoffmann

From: Akihiko Odaki <[email protected]>

Message-id: [email protected]
Message-Id: <[email protected]>

---
 audio/audio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
audio/audio.c +3 -3
index 052ca6cb789b..59453ef85673 100644
@@ -705,7 +705,7 @@ static size_t audio_pcm_sw_write(SWVoiceOut *sw, void *buf, size_t size)
 
     if (live == hwsamples) {
 #ifdef DEBUG_OUT
-        dolog ("%s is full %d\n", sw->name, live);
+        dolog ("%s is full %zu\n", sw->name, live);
 #endif
         return 0;
     }
@@ -995,7 +995,7 @@ static size_t audio_get_avail (SWVoiceIn *sw)
     }
 
     ldebug (
-        "%s: get_avail live %d ret %" PRId64 "\n",
+        "%s: get_avail live %zu ret %" PRId64 "\n",
         SW_NAME (sw),
         live, (((int64_t) live << 32) / sw->ratio) * sw->info.bytes_per_frame
         );
@@ -1022,7 +1022,7 @@ static size_t audio_get_free(SWVoiceOut *sw)
     dead = sw->hw->mix_buf->size - live;
 
 #ifdef DEBUG_OUT
-    dolog ("%s: get_free live %d dead %d ret %" PRId64 "\n",
+    dolog ("%s: get_free live %zu dead %zu ret %" PRId64 "\n",
            SW_NAME (sw),
            live, dead, (((int64_t) dead << 32) / sw->ratio) *
            sw->info.bytes_per_frame);
Signature · 1 line
2.31.1
#3 lore raw

[PULL 7/7] coreaudio: Fix output stream format settings

In reply to Gerd Hoffmann

From: Akihiko Odaki <[email protected]>

Before commit 7d6948cd98cf5ad8a3458a4ce7fdbcb79bcd1212, it was coded to retrieve the initial output stream format settings, modify the frame rate, and set again. However, I removed a frame rate modification code by mistake in the commit. It also assumes the initial output stream format is consistent with what QEMU expects, but that expectation is not in the code, which makes it harder to understand and will lead to breakage if the initial settings change.

This change explicitly sets all of the output stream settings to solve these problems.

Message-Id: <[email protected]>

---
 audio/coreaudio.c | 48 +++++++++++++----------------------------------
 1 file changed, 13 insertions(+), 35 deletions(-)
audio/coreaudio.c +13 -35
index 578ec9b8b2e6..f570e1ee60ef 100644
@@ -39,7 +39,6 @@ typedef struct coreaudioVoiceOut {
     int frameSizeSetting;
     uint32_t bufferCount;
     UInt32 audioDevicePropertyBufferFrameSize;
-    AudioStreamBasicDescription outputStreamBasicDescription;
     AudioDeviceIOProcID ioprocid;
     bool enabled;
 } coreaudioVoiceOut;
@@ -114,24 +113,6 @@ static OSStatus coreaudio_set_framesize(AudioDeviceID id, UInt32 *framesize)
                                       framesize);
 }
 
-static OSStatus coreaudio_get_streamformat(AudioDeviceID id,
-                                           AudioStreamBasicDescription *d)
-{
-    UInt32 size = sizeof(*d);
-    AudioObjectPropertyAddress addr = {
-        kAudioDevicePropertyStreamFormat,
-        kAudioDevicePropertyScopeOutput,
-        kAudioObjectPropertyElementMaster
-    };
-
-    return AudioObjectGetPropertyData(id,
-                                      &addr,
-                                      0,
-                                      NULL,
-                                      &size,
-                                      d);
-}
-
 static OSStatus coreaudio_set_streamformat(AudioDeviceID id,
                                            AudioStreamBasicDescription *d)
 {
@@ -373,6 +354,17 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
     OSStatus status;
     AudioValueRange frameRange;
 
+    AudioStreamBasicDescription streamBasicDescription = {
+        .mBitsPerChannel = core->hw.info.bits,
+        .mBytesPerFrame = core->hw.info.bytes_per_frame,
+        .mBytesPerPacket = core->hw.info.bytes_per_frame,
+        .mChannelsPerFrame = core->hw.info.nchannels,
+        .mFormatFlags = kLinearPCMFormatFlagIsFloat,
+        .mFormatID = kAudioFormatLinearPCM,
+        .mFramesPerPacket = 1,
+        .mSampleRate = core->hw.info.freq
+    };
+
     status = coreaudio_get_voice(&core->outputDeviceID);
     if (status != kAudioHardwareNoError) {
         coreaudio_playback_logerr (status,
@@ -432,29 +424,16 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
     }
     core->hw.samples = core->bufferCount * core->audioDevicePropertyBufferFrameSize;
 
-    /* get StreamFormat */
-    status = coreaudio_get_streamformat(core->outputDeviceID,
-                                        &core->outputStreamBasicDescription);
-    if (status == kAudioHardwareBadObjectError) {
-        return 0;
-    }
-    if (status != kAudioHardwareNoError) {
-        coreaudio_playback_logerr (status,
-                                    "Could not get Device Stream properties\n");
-        core->outputDeviceID = kAudioDeviceUnknown;
-        return status;
-    }
-
     /* set Samplerate */
     status = coreaudio_set_streamformat(core->outputDeviceID,
-                                        &core->outputStreamBasicDescription);
+                                        &streamBasicDescription);
     if (status == kAudioHardwareBadObjectError) {
         return 0;
     }
     if (status != kAudioHardwareNoError) {
         coreaudio_playback_logerr (status,
                                    "Could not set samplerate %lf\n",
-                                   core->outputStreamBasicDescription.mSampleRate);
+                                   streamBasicDescription.mSampleRate);
         core->outputDeviceID = kAudioDeviceUnknown;
         return status;
     }
@@ -598,7 +577,6 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
         qapi_AudiodevCoreaudioPerDirectionOptions_base(cpdo), as, 11610);
 
     core->bufferCount = cpdo->has_buffer_count ? cpdo->buffer_count : 4;
-    core->outputStreamBasicDescription.mSampleRate = (Float64) as->freq;
 
     status = AudioObjectAddPropertyListener(kAudioObjectSystemObject,
                                             &voice_addr, handle_voice_change,
Signature · 1 line
2.31.1
#4 lore raw

[PULL 5/7] hw/audio/sb16: Avoid assertion by restricting I/O sampling rate range

In reply to Gerd Hoffmann

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

While the SB16 seems to work up to 48000 Hz, the "Sound Blaster Series Hardware Programming Guide" limit the sampling range from 4000 Hz to 44100 Hz (Section 3-9, 3-10: Digitized Sound I/O Programming, tables 3-2 and 3-3).

Later, section 6-15 (DSP Commands) is more specific regarding the 41h / 42h registers (Set digitized sound output sampling rate):

Valid sampling rates range from 5000 to 45000 Hz inclusive.

There is no comment regarding error handling if the register is filled with an out-of-range value. (See also section 3-28 "8-bit or 16-bit Auto-initialize Transfer"). Assume limits are enforced in hardware.

This fixes triggering an assertion in audio_calloc():

#1 abort
#2 audio_bug audio/audio.c:119:9
#3 audio_calloc audio/audio.c:154:9
#4 audio_pcm_sw_alloc_resources_out audio/audio_template.h:116:15 #5 audio_pcm_sw_init_out audio/audio_template.h:175:11 #6 audio_pcm_create_voice_pair_out audio/audio_template.h:410:9 #7 AUD_open_out audio/audio_template.h:503:14
#8 continue_dma8 hw/audio/sb16.c:216:20
#9 dma_cmd8 hw/audio/sb16.c:276:5
#10 command hw/audio/sb16.c:0
#11 dsp_write hw/audio/sb16.c:949:13
#12 portio_write softmmu/ioport.c:205:13
#13 memory_region_write_accessor softmmu/memory.c:491:5 #14 access_with_adjusted_size softmmu/memory.c:552:18 #15 memory_region_dispatch_write softmmu/memory.c:0:13 #16 flatview_write_continue softmmu/physmem.c:2759:23 #17 flatview_write softmmu/physmem.c:2799:14
#18 address_space_write softmmu/physmem.c:2891:18
#19 cpu_outw softmmu/ioport.c:70:5

[*] http://www.baudline.com/solutions/full_duplex/sb16_pci/index.html

OSS-Fuzz Report: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29174

Message-Id: <[email protected]>

---
 hw/audio/sb16.c              | 14 ++++++++++
 tests/qtest/fuzz-sb16-test.c | 52 ++++++++++++++++++++++++++++++++++++
 MAINTAINERS                  |  1 +
 tests/qtest/meson.build      |  1 +
 4 files changed, 68 insertions(+)
 create mode 100644 tests/qtest/fuzz-sb16-test.c
hw/audio/sb16.c +14 -0
index 8b2070041025..5cf121fe3639 100644
@@ -115,6 +115,9 @@ struct SB16State {
     PortioList portio_list;
 };
 
+#define SAMPLE_RATE_MIN 5000
+#define SAMPLE_RATE_MAX 45000
+
 static void SB_audio_callback (void *opaque, int free);
 
 static int magic_of_irq (int irq)
@@ -241,6 +244,17 @@ static void dma_cmd8 (SB16State *s, int mask, int dma_len)
         int tmp = (256 - s->time_const);
         s->freq = (1000000 + (tmp / 2)) / tmp;
     }
+    if (s->freq < SAMPLE_RATE_MIN) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "sampling range too low: %d, increasing to %u\n",
+                      s->freq, SAMPLE_RATE_MIN);
+        s->freq = SAMPLE_RATE_MIN;
+    } else if (s->freq > SAMPLE_RATE_MAX) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "sampling range too high: %d, decreasing to %u\n",
+                      s->freq, SAMPLE_RATE_MAX);
+        s->freq = SAMPLE_RATE_MAX;
+    }
 
     if (dma_len != -1) {
         s->block_size = dma_len << s->fmt_stereo;
tests/qtest/fuzz-sb16-test.c new file +52 -0

52 lines not on this page · raw message

MAINTAINERS +1 -0
index 636bf2f53655..4842cc26e5ce 100644
@@ -2221,6 +2221,7 @@ F: qapi/audio.json
 F: tests/qtest/ac97-test.c
 F: tests/qtest/es1370-test.c
 F: tests/qtest/intel-hda-test.c
+F: tests/qtest/fuzz-sb16-test.c
 
 Block layer core
 M: Kevin Wolf <[email protected]>
tests/qtest/meson.build +1 -0
index c3a223a83d6a..b03e85417001 100644
@@ -20,6 +20,7 @@ slow_qtests = {
 qtests_generic = \
   (config_all_devices.has_key('CONFIG_MEGASAS_SCSI_PCI') ? ['fuzz-megasas-test'] : []) + \
   (config_all_devices.has_key('CONFIG_VIRTIO_SCSI') ? ['fuzz-virtio-scsi-test'] : []) + \
+  (config_all_devices.has_key('CONFIG_SB16') ? ['fuzz-sb16-test'] : []) + \
   [
   'cdrom-test',
   'device-introspect-test',
Signature · 1 line
2.31.1
#5 lore raw

[PULL 2/7] paaudio: remove unused stream flags

In reply to Gerd Hoffmann

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

In current code there are no calls to pa_stream_get_latency() or pa_stream_get_time() to receive latency or time information.

Remove the flags PA_STREAM_INTERPOLATE_TIMING and PA_STREAM_AUTO_TIMING_UPDATE which instruct PulseAudio to calculate this information in regular intervals.

Message-Id: <[email protected]>

---
 audio/paaudio.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
audio/paaudio.c +1 -4
index c97b22e970d8..14b4269c5500 100644
@@ -463,10 +463,7 @@ static pa_stream *qpa_simple_new (
 
     pa_stream_set_state_callback(stream, stream_state_cb, c);
 
-    flags =
-        PA_STREAM_INTERPOLATE_TIMING
-        | PA_STREAM_AUTO_TIMING_UPDATE
-        | PA_STREAM_EARLY_REQUESTS;
+    flags = PA_STREAM_EARLY_REQUESTS;
 
     if (dev) {
         /* don't move the stream if the user specified a sink/source */
Signature · 1 line
2.31.1
#6 lore raw

[PULL 1/7] alsaaudio: remove #ifdef DEBUG to avoid bit rot

In reply to Gerd Hoffmann

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

Merge the #ifdef DEBUG code with the if statement a few lines above to avoid bit rot.

Message-Id: <[email protected]>

---
 audio/alsaaudio.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
audio/alsaaudio.c +4 -6
index fcc2f62864fb..2b9789e64771 100644
@@ -34,6 +34,8 @@
 #define AUDIO_CAP "alsa"
 #include "audio_int.h"
 
+#define DEBUG_ALSA 0
+
 struct pollhlp {
     snd_pcm_t *handle;
     struct pollfd *pfds;
@@ -587,16 +589,12 @@ static int alsa_open(bool in, struct alsa_params_req *req,
 
     *handlep = handle;
 
-    if (obtfmt != req->fmt ||
-         obt->nchannels != req->nchannels ||
-         obt->freq != req->freq) {
+    if (DEBUG_ALSA || obtfmt != req->fmt ||
+        obt->nchannels != req->nchannels || obt->freq != req->freq) {
         dolog ("Audio parameters for %s\n", typ);
         alsa_dump_info(req, obt, obtfmt, apdo);
     }
 
-#ifdef DEBUG
-    alsa_dump_info(req, obt, obtfmt, apdo);
-#endif
     return 0;
 
  err:
Signature · 1 line
2.31.1
#7 lore raw

[PULL 4/7] jackaudio: avoid that the client name contains the word (NULL)

In reply to Gerd Hoffmann

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

Currently with jackaudio client name and qemu guest name unset, the JACK client names are out-(NULL) and in-(NULL). These names are user visible in the patch bay. Replace the function call to qemu_get_vm_name() with a call to audio_application_name() which replaces NULL with "qemu" to have more descriptive names.

Message-Id: <[email protected]>

---
 audio/jackaudio.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
audio/jackaudio.c +1 -2
index 3031c4e29bd4..e7de6d5433e9 100644
@@ -26,7 +26,6 @@
 #include "qemu/module.h"
 #include "qemu/atomic.h"
 #include "qemu/main-loop.h"
-#include "qemu-common.h"
 #include "audio.h"
 
 #define AUDIO_CAP "jack"
@@ -412,7 +411,7 @@ static int qjack_client_init(QJackClient *c)
 
     snprintf(client_name, sizeof(client_name), "%s-%s",
         c->out ? "out" : "in",
-        c->opt->client_name ? c->opt->client_name : qemu_get_vm_name());
+        c->opt->client_name ? c->opt->client_name : audio_application_name());
 
     if (c->opt->exact_name) {
         options |= JackUseExactName;
Signature · 1 line
2.31.1
#8 lore raw
In reply to Gerd Hoffmann
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [PULL 0/7] Audio 20210617 patches

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected]
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
a6c9846 coreaudio: Fix output stream format settings
32f3f1e audio: Fix format specifications of debug logs
b51279d hw/audio/sb16: Avoid assertion by restricting I/O sampling rate range e864a29 jackaudio: avoid that the client name contains the word (NULL) c4a86a7 audio: move code to audio/audio.c
2800db0 paaudio: remove unused stream flags
0b3fd3c alsaaudio: remove #ifdef DEBUG to avoid bit rot

=== OUTPUT BEGIN ===
1/7 Checking commit 0b3fd3ca5f98 (alsaaudio: remove #ifdef DEBUG to avoid bit rot)
2/7 Checking commit 2800db079dd3 (paaudio: remove unused stream flags)
3/7 Checking commit c4a86a755701 (audio: move code to audio/audio.c)
4/7 Checking commit e864a29cb0c2 (jackaudio: avoid that the client name contains the word (NULL)) 5/7 Checking commit b51279d277e6 (hw/audio/sb16: Avoid assertion by restricting I/O sampling rate range) 6/7 Checking commit 32f3f1e7b9c4 (audio: Fix format specifications of debug logs)
ERROR: space prohibited between function name and open parenthesis '('
#25: FILE: audio/audio.c:708:
+ dolog ("%s is full %zu\n", sw->name, live);

ERROR: space prohibited between function name and open parenthesis '(' #43: FILE: audio/audio.c:1025:
+ dolog ("%s: get_free live %zu dead %zu ret %" PRId64 "\n",

total: 2 errors, 0 warnings, 24 lines checked

Patch 6/7 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

7/7 Checking commit a6c98463e79b (coreaudio: Fix output stream format settings) === OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#9 lore raw
In reply to Gerd Hoffmann
Quoted 22 lines · Gerd Hoffmann

The following changes since commit 38848ce565849e5b867a5e08022b3c755039c11a:

Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20210616' into staging (2021-06-16 17:02:30 +0100)

are available in the Git repository at:

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

for you to fetch changes up to 986bdbc6a29c4d7ef125299c5013783e30dc2cae:

coreaudio: Fix output stream format settings (2021-06-17 12:00:26 +0200)

----------------------------------------------------------------
audio: bugfix collection.

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

Akihiko Odaki (2):
audio: Fix format specifications of debug logs
coreaudio: Fix output stream format settings

Quoted 9 lines

Philippe Mathieu-Daudé (1):
hw/audio/sb16: Avoid assertion by restricting I/O sampling rate range

Volker Rümelin (4):
alsaaudio: remove #ifdef DEBUG to avoid bit rot
paaudio: remove unused stream flags
audio: move code to audio/audio.c
jackaudio: avoid that the client name contains the word (NULL)

Applied, thanks.

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

-- PMM