From patchwork Thu Dec 19 20:05:31 2019 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: 1213686 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 47f2v54kc4z9sPJ for ; Fri, 20 Dec 2019 07:06:09 +1100 (AEDT) Received: from localhost ([::1]:47342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii23j-0001Lg-EA for incoming@patchwork.ozlabs.org; Thu, 19 Dec 2019 15:06:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55967) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii23F-0001Gy-R6 for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:05:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii23C-0007Gf-VY for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:05:37 -0500 Received: from mailout04.t-online.de ([194.25.134.18]:42982) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ii23C-00079g-OF for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:05:34 -0500 Received: from fwd16.aul.t-online.de (fwd16.aul.t-online.de [172.20.26.243]) by mailout04.t-online.de (Postfix) with SMTP id 6597341F5AE1; Thu, 19 Dec 2019 21:05:33 +0100 (CET) Received: from [192.168.211.200] (VOcBouZTrhWZkVw5BBLrch8uvHDMJpk4IXsLeO4yYELVMU6ZX3FOqxUuaHfHCXmgsW@[46.86.55.2]) by fwd16.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1ii239-3OJfBg0; Thu, 19 Dec 2019 21:05:31 +0100 Subject: [PATCH 3/5] paaudio: drop recording stream in qpa_fini_in From: =?utf-8?q?Volker_R=C3=BCmelin?= To: Gerd Hoffmann References: Message-ID: <6f2e756e-f498-4dea-03f8-089010624b64@t-online.de> Date: Thu, 19 Dec 2019 21:05:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: Content-Language: de-DE X-ID: VOcBouZTrhWZkVw5BBLrch8uvHDMJpk4IXsLeO4yYELVMU6ZX3FOqxUuaHfHCXmgsW X-TOI-MSGID: c18584e3-5378-41ab-923e-aea545c5c500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 194.25.134.18 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" Every call to pa_stream_peek which returns a data length > 0 should have a corresponding pa_stream_drop. A call to qpa_read does not necessarily call pa_stream_drop immediately after a call to pa_stream_peek. Test in qpa_fini_in if a last pa_stream_drop is needed. This prevents following messages in the libvirt log file after a recording stream gets closed and a new one opened. pulseaudio: pa_stream_drop failed pulseaudio: Reason: Bad state pulseaudio: pa_stream_drop failed pulseaudio: Reason: Bad state To reproduce start qemu with -audiodev pa,id=audio0,in.mixing-engine=off and in the guest start and stop Audacity several times. Signed-off-by: Volker RĂ¼melin --- audio/paaudio.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/audio/paaudio.c b/audio/paaudio.c index 55a91f8980..b831e0d6e9 100644 --- a/audio/paaudio.c +++ b/audio/paaudio.c @@ -536,7 +536,6 @@ static void qpa_simple_disconnect(PAConnection *c, pa_stream *stream) { int err; - pa_threaded_mainloop_lock(c->mainloop); /* * wait until actually connects. workaround pa bug #247 * https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/247 @@ -550,7 +549,6 @@ static void qpa_simple_disconnect(PAConnection *c, pa_stream *stream) dolog("Failed to disconnect! err=%d\n", err); } pa_stream_unref(stream); - pa_threaded_mainloop_unlock(c->mainloop); } static void qpa_fini_out (HWVoiceOut *hw) @@ -558,8 +556,12 @@ static void qpa_fini_out (HWVoiceOut *hw) PAVoiceOut *pa = (PAVoiceOut *) hw; if (pa->stream) { - qpa_simple_disconnect(pa->g->conn, pa->stream); + PAConnection *c = pa->g->conn; + + pa_threaded_mainloop_lock(c->mainloop); + qpa_simple_disconnect(c, pa->stream); pa->stream = NULL; + pa_threaded_mainloop_unlock(c->mainloop); } } @@ -568,8 +570,20 @@ static void qpa_fini_in (HWVoiceIn *hw) PAVoiceIn *pa = (PAVoiceIn *) hw; if (pa->stream) { - qpa_simple_disconnect(pa->g->conn, pa->stream); + PAConnection *c = pa->g->conn; + + pa_threaded_mainloop_lock(c->mainloop); + if (pa->read_length) { + int r = pa_stream_drop(pa->stream); + if (r) { + qpa_logerr(pa_context_errno(c->context), + "pa_stream_peek failed\n"); + } + pa->read_length = 0; + } + qpa_simple_disconnect(c, pa->stream); pa->stream = NULL; + pa_threaded_mainloop_unlock(c->mainloop); } }