From patchwork Sun Apr 5 07:50:15 2020 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: 1266495 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=t-online.de 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 ozlabs.org (Postfix) with ESMTPS id 48w5Sv0Rr8z9sPF for ; Sun, 5 Apr 2020 17:50:54 +1000 (AEST) Received: from localhost ([::1]:45494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jL03Q-0004pt-8H for incoming@patchwork.ozlabs.org; Sun, 05 Apr 2020 03:50:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55772) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jL02w-0004pR-DC for qemu-devel@nongnu.org; Sun, 05 Apr 2020 03:50:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jL02u-0001G1-HQ for qemu-devel@nongnu.org; Sun, 05 Apr 2020 03:50:21 -0400 Received: from mailout05.t-online.de ([194.25.134.82]:33420) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jL02u-0001F4-Bz for qemu-devel@nongnu.org; Sun, 05 Apr 2020 03:50:20 -0400 Received: from fwd09.aul.t-online.de (fwd09.aul.t-online.de [172.20.27.151]) by mailout05.t-online.de (Postfix) with SMTP id 1F46C4264B80; Sun, 5 Apr 2020 09:50:19 +0200 (CEST) Received: from linpower.localnet (XdmDP8ZYrh-ZXOm3GMCCmNBLNZ+jZE7MUUfxOQmQjJ9IUXX3URLscVa8j-zdmtlZ8x@[93.236.147.242]) by fwd09.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1jL02s-0OvOrI0; Sun, 5 Apr 2020 09:50:18 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 8E211200463; Sun, 5 Apr 2020 09:50:17 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: Gerd Hoffmann Subject: [PATCH v2 1/3] dsoundaudio: fix never-ending playback loop Date: Sun, 5 Apr 2020 09:50:15 +0200 Message-Id: <20200405075017.9901-1-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: References: MIME-Version: 1.0 X-ID: XdmDP8ZYrh-ZXOm3GMCCmNBLNZ+jZE7MUUfxOQmQjJ9IUXX3URLscVa8j-zdmtlZ8x X-TOI-MSGID: c9bea177-c07a-4908-8339-2b1841df00e8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 194.25.134.82 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Currently the DirectSound backend fails to stop audio playback in dsound_enable_out(). To detect a lost buffer condition dsound_get_status_out() incorrectly uses the error code DSERR_BUFFERLOST instead of flag DSBSTATUS_BUFFERLOST as a mask and returns with an error. As a result dsound_enable_out() returns early and doesn't stop playback. To reproduce the bug start qemu on a Windows host with -soundhw pcspk -audiodev dsound,id=audio0. On the guest FreeDOS 1.2 command line enter beep. The image Day 1 - F-Bird from the QEMU Advent Calendar 2018 shows the bug as well. Buglink: https://bugs.launchpad.net/qemu/+bug/1699628 Signed-off-by: Volker Rümelin --- audio/dsoundaudio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c index bd57082a8d..9e621c8899 100644 --- a/audio/dsoundaudio.c +++ b/audio/dsoundaudio.c @@ -279,7 +279,7 @@ static int dsound_get_status_out (LPDIRECTSOUNDBUFFER dsb, DWORD *statusp, return -1; } - if (*statusp & DSERR_BUFFERLOST) { + if (*statusp & DSBSTATUS_BUFFERLOST) { dsound_restore_out(dsb, s); return -1; } From patchwork Sun Apr 5 07:50:16 2020 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: 1266496 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=t-online.de 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 ozlabs.org (Postfix) with ESMTPS id 48w5Sv37Vsz9sRY for ; Sun, 5 Apr 2020 17:50:55 +1000 (AEST) Received: from localhost ([::1]:45496 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jL03R-0004qx-Ch for incoming@patchwork.ozlabs.org; Sun, 05 Apr 2020 03:50:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55782) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jL02x-0004pT-6p for qemu-devel@nongnu.org; Sun, 05 Apr 2020 03:50:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jL02v-0001Gd-IM for qemu-devel@nongnu.org; Sun, 05 Apr 2020 03:50:22 -0400 Received: from mailout08.t-online.de ([194.25.134.20]:60980) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jL02v-0001Fu-Cg for qemu-devel@nongnu.org; Sun, 05 Apr 2020 03:50:21 -0400 Received: from fwd32.aul.t-online.de (fwd32.aul.t-online.de [172.20.26.144]) by mailout08.t-online.de (Postfix) with SMTP id C13C541B921F; Sun, 5 Apr 2020 09:50:20 +0200 (CEST) Received: from linpower.localnet (SrBfFuZdwhYvr51O9eLyuro6+AN6vTh4yGX0rXJBHrL8TEp4KnMl6NdfipfR85xQfv@[93.236.147.242]) by fwd32.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1jL02u-2WcS480; Sun, 5 Apr 2020 09:50:20 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 905A620061E; Sun, 5 Apr 2020 09:50:17 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: Gerd Hoffmann Subject: [PATCH v2 2/3] dsoundaudio: fix "Could not lock capture buffer" warning Date: Sun, 5 Apr 2020 09:50:16 +0200 Message-Id: <20200405075017.9901-2-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: References: MIME-Version: 1.0 X-ID: SrBfFuZdwhYvr51O9eLyuro6+AN6vTh4yGX0rXJBHrL8TEp4KnMl6NdfipfR85xQfv X-TOI-MSGID: 6c8f1f2f-5875-47db-888f-453735f739cc X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 194.25.134.20 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" IDirectSoundCaptureBuffer_Lock() fails on Windows when called with len = 0. Return early from dsound_get_buffer_in() in this case. To reproduce the warning start a linux guest. In the guest start Audacity and you will see a lot of "Could not lock capture buffer" warnings. Signed-off-by: Volker Rümelin --- audio/dsoundaudio.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c index 9e621c8899..a08d519cae 100644 --- a/audio/dsoundaudio.c +++ b/audio/dsoundaudio.c @@ -542,6 +542,11 @@ static void *dsound_get_buffer_in(HWVoiceIn *hw, size_t *size) req_size = audio_ring_dist(cpos, hw->pos_emul, hw->size_emul); req_size = MIN(req_size, hw->size_emul - hw->pos_emul); + if (req_size == 0) { + *size = 0; + return NULL; + } + err = dsound_lock_in(dscb, &hw->info, hw->pos_emul, req_size, &ret, NULL, &act_size, NULL, false, ds->s); if (err) { From patchwork Sun Apr 5 07:50:17 2020 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: 1266497 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=t-online.de 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 ozlabs.org (Postfix) with ESMTPS id 48w5VM6SHyz9sPF for ; Sun, 5 Apr 2020 17:52:11 +1000 (AEST) Received: from localhost ([::1]:45520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jL04f-0006fH-SN for incoming@patchwork.ozlabs.org; Sun, 05 Apr 2020 03:52:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55793) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jL02z-0004rN-UD for qemu-devel@nongnu.org; Sun, 05 Apr 2020 03:50:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jL02y-0001I3-5a for qemu-devel@nongnu.org; Sun, 05 Apr 2020 03:50:25 -0400 Received: from mailout02.t-online.de ([194.25.134.17]:46672) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jL02x-0001HS-Vt for qemu-devel@nongnu.org; Sun, 05 Apr 2020 03:50:24 -0400 Received: from fwd06.aul.t-online.de (fwd06.aul.t-online.de [172.20.26.150]) by mailout02.t-online.de (Postfix) with SMTP id 693B941D1EC4; Sun, 5 Apr 2020 09:50:23 +0200 (CEST) Received: from linpower.localnet (EwKzx8ZOZhTlbJzMXcWO21ZKNq9EqU63dWk9DSinWKrfwVQg47qgkUFVUIvMKLqwUi@[93.236.147.242]) by fwd06.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1jL02x-4TRWOu0; Sun, 5 Apr 2020 09:50:23 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 9124D200622; Sun, 5 Apr 2020 09:50:17 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: Gerd Hoffmann Subject: [PATCH v2 3/3] dsoundaudio: dsound_get_buffer_in should honor *size Date: Sun, 5 Apr 2020 09:50:17 +0200 Message-Id: <20200405075017.9901-3-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: References: MIME-Version: 1.0 X-ID: EwKzx8ZOZhTlbJzMXcWO21ZKNq9EqU63dWk9DSinWKrfwVQg47qgkUFVUIvMKLqwUi X-TOI-MSGID: a0fdab05-3a5b-41cd-9b51-0e05a15a05a2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 194.25.134.17 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch prevents an underflow of variable samples in function audio_pcm_hw_run_in(). See commit 599eac4e5a "audio: audio_generic_get_buffer_in should honor *size". This time the while loop in audio_pcm_hw_run_in() will terminate nevertheless, because it seems the recording stream in Windows is always rate limited. Signed-off-by: Volker Rümelin --- audio/audio.c | 12 +++++------- audio/dsoundaudio.c | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/audio/audio.c b/audio/audio.c index 9ac9a20c41..7a9e680355 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -1491,15 +1491,13 @@ size_t audio_generic_write(HWVoiceOut *hw, void *buf, size_t size) size_t audio_generic_read(HWVoiceIn *hw, void *buf, size_t size) { - size_t src_size, copy_size; - void *src = hw->pcm_ops->get_buffer_in(hw, &src_size); - copy_size = MIN(size, src_size); + void *src = hw->pcm_ops->get_buffer_in(hw, &size); - memcpy(buf, src, copy_size); - hw->pcm_ops->put_buffer_in(hw, src, copy_size); - return copy_size; -} + memcpy(buf, src, size); + hw->pcm_ops->put_buffer_in(hw, src, size); + return size; +} static int audio_driver_init(AudioState *s, struct audio_driver *drv, bool msg, Audiodev *dev) diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c index a08d519cae..4cdf19ab67 100644 --- a/audio/dsoundaudio.c +++ b/audio/dsoundaudio.c @@ -540,7 +540,7 @@ static void *dsound_get_buffer_in(HWVoiceIn *hw, size_t *size) } req_size = audio_ring_dist(cpos, hw->pos_emul, hw->size_emul); - req_size = MIN(req_size, hw->size_emul - hw->pos_emul); + req_size = MIN(*size, MIN(req_size, hw->size_emul - hw->pos_emul)); if (req_size == 0) { *size = 0;