diff mbox series

[20/23] dsoundaudio: replace GetForegroundWindow()

Message ID 20210110100239.27588-20-vr_qemu@t-online.de
State New
Headers show
Series next round of audio patches | expand

Commit Message

Volker RĂ¼melin Jan. 10, 2021, 10:02 a.m. UTC
GetForegroundWindow() doesn't necessarily return the own window
handle. It just returns a handle to the currently active window
and can even return NULL. At the time dsound_open() gets called
the active window is most likely the shell window and not the
QEMU window.

Replace GetForegroundWindow() with GetDesktopWindow() which
always returns a valid window handle, and at the same time
replace the DirectSound buffer flag DSBCAPS_STICKYFOCUS with
DSBCAPS_GLOBALFOCUS where Windows only expects a valid window
handle for DirectSound function SetCooperativeLevel(). The
Microsoft online docs for IDirectSound::SetCooperativeLevel
recommend this in the remarks.

This fixes a bug where you can't hear sound from the guest.

To reproduce start qemu with -machine pcspk-audiodev=audio0
-device intel-hda -device hda-duplex,audiodev=audio0
-audiodev dsound,id=audio0,out.mixing-engine=off
from a shell and start audio playback with the hda device in the
guest. The guest will be silent. To hear guest audio you have to
activate the shell window once.

Signed-off-by: Volker RĂ¼melin <vr_qemu@t-online.de>
 audio/dsound_template.h | 2 +-
 audio/dsoundaudio.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff mbox series


diff --git a/audio/dsound_template.h b/audio/dsound_template.h
index 9c5ce625ab..0678f2de38 100644
--- a/audio/dsound_template.h
+++ b/audio/dsound_template.h
@@ -205,7 +205,7 @@  static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,
     hr = IDirectSound_CreateSoundBuffer (
diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index 4cdf19ab67..0fbdf770ac 100644
--- a/audio/dsoundaudio.c
+++ b/audio/dsoundaudio.c
@@ -347,7 +347,7 @@  static int dsound_open (dsound *s)
     HRESULT hr;
     HWND hwnd;
-    hwnd = GetForegroundWindow ();
+    hwnd = GetDesktopWindow();
     hr = IDirectSound_SetCooperativeLevel (