Skip to content

Commit

Permalink
dsoundaudio: replace GetForegroundWindow()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Message-id: [email protected]
Message-Id: <[email protected]>
Signed-off-by: Gerd Hoffmann <[email protected]>
  • Loading branch information
Volker Rümelin authored and kraxel committed Jan 15, 2021
1 parent d9a8b27 commit 401dcf0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion audio/dsound_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,
NULL
);
#else
bd.dwFlags = DSBCAPS_STICKYFOCUS | DSBCAPS_GETCURRENTPOSITION2;
bd.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2;
hr = IDirectSound_CreateSoundBuffer (
s->dsound,
&bd,
Expand Down
2 changes: 1 addition & 1 deletion audio/dsoundaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static int dsound_open (dsound *s)
HRESULT hr;
HWND hwnd;

hwnd = GetForegroundWindow ();
hwnd = GetDesktopWindow();
hr = IDirectSound_SetCooperativeLevel (
s->dsound,
hwnd,
Expand Down

0 comments on commit 401dcf0

Please sign in to comment.