From patchwork Sun Jan 10 10:02:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Volker_R=C3=BCmelin?= X-Patchwork-Id: 12009007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD84BC433E0 for ; Sun, 10 Jan 2021 10:21:30 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5837F236F9 for ; Sun, 10 Jan 2021 10:21:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5837F236F9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=t-online.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyXqj-0005g4-2W for qemu-devel@archiver.kernel.org; Sun, 10 Jan 2021 05:21:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyXZU-0002Jw-SS for qemu-devel@nongnu.org; Sun, 10 Jan 2021 05:03:41 -0500 Received: from mailout11.t-online.de ([194.25.134.85]:43696) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyXZN-0005bv-3F for qemu-devel@nongnu.org; Sun, 10 Jan 2021 05:03:39 -0500 Received: from fwd36.aul.t-online.de (fwd36.aul.t-online.de [172.20.26.137]) by mailout11.t-online.de (Postfix) with SMTP id 7611542542EE; Sun, 10 Jan 2021 11:03:31 +0100 (CET) Received: from linpower.localnet (G0bPiEZ68haCtw5n1t2vu2C2KE5qBrRHMCpjq6qzN7UG4xmB9n0l8IWELlvgsgTgEj@[93.236.152.29]) by fwd36.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1kyXZJ-4DUxZw0; Sun, 10 Jan 2021 11:03:29 +0100 Received: by linpower.localnet (Postfix, from userid 1000) id 1268D2006C3; Sun, 10 Jan 2021 11:02:40 +0100 (CET) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: Gerd Hoffmann Subject: [PATCH 20/23] dsoundaudio: replace GetForegroundWindow() Date: Sun, 10 Jan 2021 11:02:36 +0100 Message-Id: <20210110100239.27588-20-vr_qemu@t-online.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <9315afe5-5958-c0b4-ea1e-14769511a9d5@t-online.de> References: <9315afe5-5958-c0b4-ea1e-14769511a9d5@t-online.de> MIME-Version: 1.0 X-ID: G0bPiEZ68haCtw5n1t2vu2C2KE5qBrRHMCpjq6qzN7UG4xmB9n0l8IWELlvgsgTgEj X-TOI-EXPURGATEID: 150726::1610273009-00004FB0-0A17421E/0/0 CLEAN NORMAL X-TOI-MSGID: 01c17d62-0b6f-4f4c-9b16-14ca2d3fc521 Received-SPF: none client-ip=194.25.134.85; envelope-from=volker.ruemelin@t-online.de; helo=mailout11.t-online.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: QEMU , =?utf-8?b?Wm9sdMOhbiBLxZF2w6Fnw7M=?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 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, 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 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 ( s->dsound, hwnd,