[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 20/30] dsoundaudio: replace GetForegroundWindow()
From: |
Gerd Hoffmann |
Subject: |
[PULL 20/30] dsoundaudio: replace GetForegroundWindow() |
Date: |
Fri, 15 Jan 2021 14:21:36 +0100 |
From: Volker RĂ¼melin <vr_qemu@t-online.de>
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>
Message-id: 9315afe5-5958-c0b4-ea1e-14769511a9d5@t-online.de
Message-Id: <20210110100239.27588-20-vr_qemu@t-online.de>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
audio/dsound_template.h | 2 +-
audio/dsoundaudio.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/audio/dsound_template.h b/audio/dsound_template.h
index 9c5ce625ab91..0678f2de38be 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,
NULL
);
#else
- bd.dwFlags = DSBCAPS_STICKYFOCUS | DSBCAPS_GETCURRENTPOSITION2;
+ bd.dwFlags = DSBCAPS_GLOBALFOCUS | DSBCAPS_GETCURRENTPOSITION2;
hr = IDirectSound_CreateSoundBuffer (
s->dsound,
&bd,
diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c
index 4cdf19ab6799..0fbdf770ac75 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 (
s->dsound,
hwnd,
--
2.29.2
- [PULL 00/30] Audio 20210115 patches, Gerd Hoffmann, 2021/01/15
- [PULL 02/30] audio: fix bit-rotted code, Gerd Hoffmann, 2021/01/15
- [PULL 01/30] sdlaudio: remove leftover SDL1.2 code, Gerd Hoffmann, 2021/01/15
- [PULL 10/30] audio: break generic buffer dependency on mixing-engine, Gerd Hoffmann, 2021/01/15
- [PULL 20/30] dsoundaudio: replace GetForegroundWindow(),
Gerd Hoffmann <=
- [PULL 11/30] sdlaudio: enable (in|out).mixing-engine=off, Gerd Hoffmann, 2021/01/15
- [PULL 08/30] audio: split pcm_ops function get_buffer_in, Gerd Hoffmann, 2021/01/15
- [PULL 18/30] paaudio: limit minreq to 75% of audio timer_rate, Gerd Hoffmann, 2021/01/15
- [PULL 03/30] sdlaudio: add -audiodev sdl,out.buffer-count option, Gerd Hoffmann, 2021/01/15
- [PULL 22/30] dsoundaudio: enable f32 audio sample format, Gerd Hoffmann, 2021/01/15
- [PULL 05/30] sdlaudio: always clear the sample buffer, Gerd Hoffmann, 2021/01/15
- [PULL 04/30] sdlaudio: don't start playback in init routine, Gerd Hoffmann, 2021/01/15
- [PULL 12/30] audio: remove remaining unused plive code, Gerd Hoffmann, 2021/01/15
- [PULL 15/30] paaudio: wait until the playback stream is ready, Gerd Hoffmann, 2021/01/15
- [PULL 21/30] dsoundaudio: rename dsound_open(), Gerd Hoffmann, 2021/01/15