From patchwork Wed Apr 1 19:00: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: 1265316 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 48swY75Xybz9sPF for ; Thu, 2 Apr 2020 06:02:03 +1100 (AEDT) Received: from localhost ([::1]:36112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJicj-0001jc-LN for incoming@patchwork.ozlabs.org; Wed, 01 Apr 2020 15:02:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58555) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJib9-0000RW-2c for qemu-devel@nongnu.org; Wed, 01 Apr 2020 15:00:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJib7-0002R8-On for qemu-devel@nongnu.org; Wed, 01 Apr 2020 15:00:22 -0400 Received: from mailout11.t-online.de ([194.25.134.85]:47022) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJib7-0002Pp-HQ for qemu-devel@nongnu.org; Wed, 01 Apr 2020 15:00:21 -0400 Received: from fwd05.aul.t-online.de (fwd05.aul.t-online.de [172.20.27.149]) by mailout11.t-online.de (Postfix) with SMTP id 8A14A421358D; Wed, 1 Apr 2020 21:00:19 +0200 (CEST) Received: from linpower.localnet (rALmjkZE8hMODYjB4Ths8Dg1ROJWkeEYp2UEijwuIQ1eGy98fhyBR3sTOGZcZXmQN-@[93.236.147.242]) by fwd05.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1jJib4-3IemmW0; Wed, 1 Apr 2020 21:00:18 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 58307200467; Wed, 1 Apr 2020 21:00:17 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: Gerd Hoffmann Subject: [PATCH 1/3] dsoundaudio: fix never-ending playback loop Date: Wed, 1 Apr 2020 21:00:15 +0200 Message-Id: <20200401190017.5081-1-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <19cd6a5a-97b7-b684-f026-11d82e34dab9@t-online.de> References: <19cd6a5a-97b7-b684-f026-11d82e34dab9@t-online.de> MIME-Version: 1.0 X-ID: rALmjkZE8hMODYjB4Ths8Dg1ROJWkeEYp2UEijwuIQ1eGy98fhyBR3sTOGZcZXmQN- X-TOI-MSGID: 7d63d7ff-393a-48e6-b261-cf42a18260c8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 194.25.134.85 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(). The call to IDirectSoundBuffer_GetStatus() in dsound_get_status_out() returns a status word with the flag DSERR_BUFFERLOST set (probably because of a buffer underrun). The function dsound_get_status_out() correctly calls dsound_restore_out() and returns an error. This is wrong. If dsound_restore_out() succeeds the program should continue without an error. 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. Fixes: 2762955f72 "dsoundaudio: remove *_retries kludges" Buglink: https://bugs.launchpad.net/qemu/+bug/1699628 Signed-off-by: Volker Rümelin --- audio/dsoundaudio.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/audio/dsoundaudio.c b/audio/dsoundaudio.c index bd57082a8d..af70dd128e 100644 --- a/audio/dsoundaudio.c +++ b/audio/dsoundaudio.c @@ -280,8 +280,10 @@ static int dsound_get_status_out (LPDIRECTSOUNDBUFFER dsb, DWORD *statusp, } if (*statusp & DSERR_BUFFERLOST) { - dsound_restore_out(dsb, s); - return -1; + if (dsound_restore_out(dsb, s)) { + return -1; + } + *statusp &= ~DSERR_BUFFERLOST; } return 0; From patchwork Wed Apr 1 19:00: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: 1265317 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 48swbV0Z7Lz9sPF for ; Thu, 2 Apr 2020 06:04:04 +1100 (AEDT) Received: from localhost ([::1]:36144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJiee-00044C-Sk for incoming@patchwork.ozlabs.org; Wed, 01 Apr 2020 15:04:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58566) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJibA-0000T4-Fm for qemu-devel@nongnu.org; Wed, 01 Apr 2020 15:00:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJib9-0002Rm-1K for qemu-devel@nongnu.org; Wed, 01 Apr 2020 15:00:24 -0400 Received: from mailout09.t-online.de ([194.25.134.84]:45750) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJib8-0002R2-PN for qemu-devel@nongnu.org; Wed, 01 Apr 2020 15:00:22 -0400 Received: from fwd18.aul.t-online.de (fwd18.aul.t-online.de [172.20.26.244]) by mailout09.t-online.de (Postfix) with SMTP id 3CAF942D6891; Wed, 1 Apr 2020 21:00:21 +0200 (CEST) Received: from linpower.localnet (SgGN78ZYghq0L+ncI2t2vYTLp2j7LeBhONEwkPaRSgrPBB+UYmA+s1hGD4VQXnpgD3@[93.236.147.242]) by fwd18.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1jJib6-06E4fI0; Wed, 1 Apr 2020 21:00:20 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 5A5B620062A; Wed, 1 Apr 2020 21:00:17 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: Gerd Hoffmann Subject: [PATCH 2/3] dsoundaudio: fix "Could not lock capture buffer" warning Date: Wed, 1 Apr 2020 21:00:16 +0200 Message-Id: <20200401190017.5081-2-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <19cd6a5a-97b7-b684-f026-11d82e34dab9@t-online.de> References: <19cd6a5a-97b7-b684-f026-11d82e34dab9@t-online.de> MIME-Version: 1.0 X-ID: SgGN78ZYghq0L+ncI2t2vYTLp2j7LeBhONEwkPaRSgrPBB+UYmA+s1hGD4VQXnpgD3 X-TOI-MSGID: c567f1f0-1cd0-4719-b0e6-bf99b2daab19 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 194.25.134.84 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 af70dd128e..ea1595dcd1 100644 --- a/audio/dsoundaudio.c +++ b/audio/dsoundaudio.c @@ -544,6 +544,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 Wed Apr 1 19:00: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: 1265315 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 48swXL6JyRz9sPF for ; Thu, 2 Apr 2020 06:01:22 +1100 (AEDT) Received: from localhost ([::1]:36094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJic3-0000YN-Vq for incoming@patchwork.ozlabs.org; Wed, 01 Apr 2020 15:01:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58579) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJibC-0000VI-B9 for qemu-devel@nongnu.org; Wed, 01 Apr 2020 15:00:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJibB-0002Su-Ai for qemu-devel@nongnu.org; Wed, 01 Apr 2020 15:00:26 -0400 Received: from mailout05.t-online.de ([194.25.134.82]:45920) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jJibB-0002S9-3g for qemu-devel@nongnu.org; Wed, 01 Apr 2020 15:00:25 -0400 Received: from fwd24.aul.t-online.de (fwd24.aul.t-online.de [172.20.26.129]) by mailout05.t-online.de (Postfix) with SMTP id AB4E54204FD2; Wed, 1 Apr 2020 21:00:23 +0200 (CEST) Received: from linpower.localnet (S34u6qZerhlO6FMPJtsDHXL87lBI2i71ZdMmE3iDMAAMz2+EcWnhWJlBOMO7ls1QPS@[93.236.147.242]) by fwd24.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1jJib9-12XGeO0; Wed, 1 Apr 2020 21:00:23 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id 5B4C5200F43; Wed, 1 Apr 2020 21:00:17 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: Gerd Hoffmann Subject: [PATCH 3/3] dsoundaudio: dsound_get_buffer_in should honor *size Date: Wed, 1 Apr 2020 21:00:17 +0200 Message-Id: <20200401190017.5081-3-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <19cd6a5a-97b7-b684-f026-11d82e34dab9@t-online.de> References: <19cd6a5a-97b7-b684-f026-11d82e34dab9@t-online.de> MIME-Version: 1.0 X-ID: S34u6qZerhlO6FMPJtsDHXL87lBI2i71ZdMmE3iDMAAMz2+EcWnhWJlBOMO7ls1QPS X-TOI-MSGID: 20c42069-0717-44d3-85bc-edd298cc8e74 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" 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 ea1595dcd1..d3522f0e00 100644 --- a/audio/dsoundaudio.c +++ b/audio/dsoundaudio.c @@ -542,7 +542,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;