qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] DirectSound fixes for 5.0
@ 2020-04-05  7:47 Volker Rümelin
  2020-04-05  7:50 ` [PATCH v2 1/3] dsoundaudio: fix never-ending playback loop Volker Rümelin
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Volker Rümelin @ 2020-04-05  7:47 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: QEMU, Zoltán Kővágó

Three audio fixes for DirectSound on Windows. They were tested
on a Windows 10 Home system with HAXM accelerator.

v2:
- "dsoundaudio: fix never-ending playback loop"
  The commit message and the changed code was wrong.

Volker Rümelin (3):
  dsoundaudio: fix never-ending playback loop
  dsoundaudio: fix "Could not lock capture buffer" warning
  dsoundaudio: dsound_get_buffer_in should honor *size

 audio/audio.c       | 12 +++++-------
 audio/dsoundaudio.c |  9 +++++++--
 2 files changed, 12 insertions(+), 9 deletions(-)

-- 
2.16.4



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/3] dsoundaudio: fix never-ending playback loop
  2020-04-05  7:47 [PATCH v2 0/3] DirectSound fixes for 5.0 Volker Rümelin
@ 2020-04-05  7:50 ` Volker Rümelin
  2020-04-05  7:50 ` [PATCH v2 2/3] dsoundaudio: fix "Could not lock capture buffer" warning Volker Rümelin
  2020-04-05  7:50 ` [PATCH v2 3/3] dsoundaudio: dsound_get_buffer_in should honor *size Volker Rümelin
  2 siblings, 0 replies; 4+ messages in thread
From: Volker Rümelin @ 2020-04-05  7:50 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: QEMU, Zoltán Kővágó

Currently the DirectSound backend fails to stop audio playback
in dsound_enable_out(). To detect a lost buffer condition
dsound_get_status_out() incorrectly uses the error code
DSERR_BUFFERLOST instead of flag DSBSTATUS_BUFFERLOST as a mask
and returns with an error. As a result dsound_enable_out()
returns early and doesn't stop playback.

To reproduce the bug start qemu on a Windows host with
-soundhw pcspk -audiodev dsound,id=audio0. On the guest
FreeDOS 1.2 command line enter beep. The image Day 1 - F-Bird
from the QEMU Advent Calendar 2018 shows the bug as well.

Buglink: https://bugs.launchpad.net/qemu/+bug/1699628
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
 audio/dsoundaudio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index bd57082a8d..9e621c8899 100644
--- a/audio/dsoundaudio.c
+++ b/audio/dsoundaudio.c
@@ -279,7 +279,7 @@ static int dsound_get_status_out (LPDIRECTSOUNDBUFFER dsb, DWORD *statusp,
         return -1;
     }
 
-    if (*statusp & DSERR_BUFFERLOST) {
+    if (*statusp & DSBSTATUS_BUFFERLOST) {
         dsound_restore_out(dsb, s);
         return -1;
     }
-- 
2.16.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/3] dsoundaudio: fix "Could not lock capture buffer" warning
  2020-04-05  7:47 [PATCH v2 0/3] DirectSound fixes for 5.0 Volker Rümelin
  2020-04-05  7:50 ` [PATCH v2 1/3] dsoundaudio: fix never-ending playback loop Volker Rümelin
@ 2020-04-05  7:50 ` Volker Rümelin
  2020-04-05  7:50 ` [PATCH v2 3/3] dsoundaudio: dsound_get_buffer_in should honor *size Volker Rümelin
  2 siblings, 0 replies; 4+ messages in thread
From: Volker Rümelin @ 2020-04-05  7:50 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: QEMU, Zoltán Kővágó

IDirectSoundCaptureBuffer_Lock() fails on Windows when called
with len = 0. Return early from dsound_get_buffer_in() in this
case.

To reproduce the warning start a linux guest. In the guest
start Audacity and you will see a lot of "Could not lock
capture buffer" warnings.

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
 audio/dsoundaudio.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index 9e621c8899..a08d519cae 100644
--- a/audio/dsoundaudio.c
+++ b/audio/dsoundaudio.c
@@ -542,6 +542,11 @@ static void *dsound_get_buffer_in(HWVoiceIn *hw, size_t *size)
     req_size = audio_ring_dist(cpos, hw->pos_emul, hw->size_emul);
     req_size = MIN(req_size, hw->size_emul - hw->pos_emul);
 
+    if (req_size == 0) {
+        *size = 0;
+        return NULL;
+    }
+
     err = dsound_lock_in(dscb, &hw->info, hw->pos_emul, req_size, &ret, NULL,
                          &act_size, NULL, false, ds->s);
     if (err) {
-- 
2.16.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 3/3] dsoundaudio: dsound_get_buffer_in should honor *size
  2020-04-05  7:47 [PATCH v2 0/3] DirectSound fixes for 5.0 Volker Rümelin
  2020-04-05  7:50 ` [PATCH v2 1/3] dsoundaudio: fix never-ending playback loop Volker Rümelin
  2020-04-05  7:50 ` [PATCH v2 2/3] dsoundaudio: fix "Could not lock capture buffer" warning Volker Rümelin
@ 2020-04-05  7:50 ` Volker Rümelin
  2 siblings, 0 replies; 4+ messages in thread
From: Volker Rümelin @ 2020-04-05  7:50 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: QEMU, Zoltán Kővágó

This patch prevents an underflow of variable samples in function
audio_pcm_hw_run_in(). See commit 599eac4e5a "audio:
audio_generic_get_buffer_in should honor *size". This time the
while loop in audio_pcm_hw_run_in() will terminate nevertheless,
because it seems the recording stream in Windows is always rate
limited.

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
 audio/audio.c       | 12 +++++-------
 audio/dsoundaudio.c |  2 +-
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index 9ac9a20c41..7a9e680355 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1491,15 +1491,13 @@ size_t audio_generic_write(HWVoiceOut *hw, void *buf, size_t size)
 
 size_t audio_generic_read(HWVoiceIn *hw, void *buf, size_t size)
 {
-    size_t src_size, copy_size;
-    void *src = hw->pcm_ops->get_buffer_in(hw, &src_size);
-    copy_size = MIN(size, src_size);
+    void *src = hw->pcm_ops->get_buffer_in(hw, &size);
 
-    memcpy(buf, src, copy_size);
-    hw->pcm_ops->put_buffer_in(hw, src, copy_size);
-    return copy_size;
-}
+    memcpy(buf, src, size);
+    hw->pcm_ops->put_buffer_in(hw, src, size);
 
+    return size;
+}
 
 static int audio_driver_init(AudioState *s, struct audio_driver *drv,
                              bool msg, Audiodev *dev)
diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index a08d519cae..4cdf19ab67 100644
--- a/audio/dsoundaudio.c
+++ b/audio/dsoundaudio.c
@@ -540,7 +540,7 @@ static void *dsound_get_buffer_in(HWVoiceIn *hw, size_t *size)
     }
 
     req_size = audio_ring_dist(cpos, hw->pos_emul, hw->size_emul);
-    req_size = MIN(req_size, hw->size_emul - hw->pos_emul);
+    req_size = MIN(*size, MIN(req_size, hw->size_emul - hw->pos_emul));
 
     if (req_size == 0) {
         *size = 0;
-- 
2.16.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-04-05  7:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-05  7:47 [PATCH v2 0/3] DirectSound fixes for 5.0 Volker Rümelin
2020-04-05  7:50 ` [PATCH v2 1/3] dsoundaudio: fix never-ending playback loop Volker Rümelin
2020-04-05  7:50 ` [PATCH v2 2/3] dsoundaudio: fix "Could not lock capture buffer" warning Volker Rümelin
2020-04-05  7:50 ` [PATCH v2 3/3] dsoundaudio: dsound_get_buffer_in should honor *size Volker Rümelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).