Skip to content
Snippets Groups Projects
  • Volker Rümelin's avatar
    401dcf05
    dsoundaudio: replace GetForegroundWindow() · 401dcf05
    Volker Rümelin authored
    
    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: default avatarVolker 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: default avatarGerd Hoffmann <kraxel@redhat.com>
    401dcf05
    History
    dsoundaudio: replace GetForegroundWindow()
    Volker Rümelin authored
    
    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: default avatarVolker 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: default avatarGerd Hoffmann <kraxel@redhat.com>