From nobody Fri May 10 11:55:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1578129161; cv=none; d=zohomail.com; s=zohoarc; b=Jhz68j+TnKb5sv0urvdN0e6lOrrWaGrdrTQRBHpJWrCDzv0IcuiOGtmMyazMdU4QonIwAkGogECnLeNNoPMe/kfdOeCzaN35hnw/t95HZqav5Ep0hN2M12ZMZS82ekTlG1tsbmhJr5lmTUBCy1Wrl2uHD3+3BCX2Wj6BzA3iJq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578129161; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/TDZ7XL0Ugf9k8IEN4IxjtddNjyfeQDZ7O/uYJAcW8Y=; b=PJSEEQAp9YU1KsseXp3zGQ4SmVPttbkTykYWbjJ7AlkafqEQPfPr2WQq1cfbJtX/rGg62Pa3+7h93tSeJ44xK5ho4KkgJl/f+8vfeboYuqeUJ+mCuFopYE+x7kLv+BJY75PmB03FWIUFOIcdyTuM6iwzAlkpVGrgo0mMjSzOGpg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1578129161674437.81919084428296; Sat, 4 Jan 2020 01:12:41 -0800 (PST) Received: from localhost ([::1]:60826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1infU8-0002ao-3E for importer@patchew.org; Sat, 04 Jan 2020 04:12:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33886) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1infT0-0001dw-IK for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1infSz-0006cv-HY for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:30 -0500 Received: from mailout11.t-online.de ([194.25.134.85]:37216) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1infSz-0006X7-AW for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:29 -0500 Received: from fwd02.aul.t-online.de (fwd02.aul.t-online.de [172.20.26.148]) by mailout11.t-online.de (Postfix) with SMTP id C0DB74219D70; Sat, 4 Jan 2020 10:11:27 +0100 (CET) Received: from linpower.localnet (S35q5cZeZhEXu1VJsEw1KA85QBzJrQwS6BBDazoNoZ+TH9RtsE7vs2KQhJXHcsKQjb@[46.86.52.107]) by fwd02.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1infSs-2OuX440; Sat, 4 Jan 2020 10:11:22 +0100 Received: by linpower.localnet (Postfix, from userid 1000) id 1F83420278D; Sat, 4 Jan 2020 10:11:22 +0100 (CET) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Gerd Hoffmann Subject: [PATCH v2 1/5] hda-codec: fix playback rate control Date: Sat, 4 Jan 2020 10:11:18 +0100 Message-Id: <20200104091122.13971-1-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <07d61da6-51fb-8599-ea27-dae828fbdb3c@t-online.de> References: <07d61da6-51fb-8599-ea27-dae828fbdb3c@t-online.de> MIME-Version: 1.0 X-ID: S35q5cZeZhEXu1VJsEw1KA85QBzJrQwS6BBDazoNoZ+TH9RtsE7vs2KQhJXHcsKQjb X-TOI-MSGID: 093d079c-19aa-4f43-ae6b-b23b89f952ef Content-Transfer-Encoding: quoted-printable 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?q?Zolt=C3=A1n=20K=C5=91v=C3=A1g=C3=B3?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Since commit 1930616b98 "audio: make mixeng optional" the function hda_audio_output_cb can no longer assume the function parameter avail contains the free buffer size. With the playback mixing-engine turned off this leads to a broken playback rate control and playback buffer drops in regular intervals. This patch moves down the rate calculation, so the correct buffer fill level is used for the calculation. Signed-off-by: Volker R=C3=BCmelin --- hw/audio/hda-codec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c index f17e8d8dce..768ba31e79 100644 --- a/hw/audio/hda-codec.c +++ b/hw/audio/hda-codec.c @@ -338,8 +338,6 @@ static void hda_audio_output_cb(void *opaque, int avail) return; } =20 - hda_timer_sync_adjust(st, (wpos - rpos) - to_transfer - (B_SIZE >> 1)); - while (to_transfer) { uint32_t start =3D (uint32_t) (rpos & B_MASK); uint32_t chunk =3D (uint32_t) MIN(B_SIZE - start, to_transfer); @@ -351,6 +349,8 @@ static void hda_audio_output_cb(void *opaque, int avail) break; } } + + hda_timer_sync_adjust(st, (wpos - rpos) - (B_SIZE >> 1)); } =20 static void hda_audio_compat_input_cb(void *opaque, int avail) --=20 2.16.4 From nobody Fri May 10 11:55:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1578129290; cv=none; d=zohomail.com; s=zohoarc; b=YCHboaUyslAhQPnlHzMxM4ZEbXL7U274z6YdredfsoWAsXhQiJZaly3JiltQDn6YT2Wz/fi4p+yXoC+OH+LZpUEEz1Ne75tg/GoLZXabOfTSM/pxsDq0m1EJyMEXxiUxK/kOSQlpnnnsve73eWq0Vcuu4QHt47xxUB8P12BEzFU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578129290; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eYhQQ7oeLlIxUixlUx+qY5I+Fcd+4TOyC/jgI47jqd0=; b=OdJ4pd86Olc8NdLh8czra5Q85Veb+mi+RwlrYDbYpiEWf6dZWe1Yv2yoreeLeIs/uBSgF6OZIpm+h/9WZAQnQCNx/Ea4KCfUotccyIresNnGFlJqeI04AWGKtTgAHyX3fU26AOH23VL5xV/SE1NI/GTwYfGNCzV8ecrK3Enz7xg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157812929018531.152783394088942; Sat, 4 Jan 2020 01:14:50 -0800 (PST) Received: from localhost ([::1]:60848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1infWC-0005rB-UK for importer@patchew.org; Sat, 04 Jan 2020 04:14:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34041) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1infT4-0001fu-5i for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1infT3-0006tL-5q for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:34 -0500 Received: from mailout09.t-online.de ([194.25.134.84]:50330) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1infT2-0006oY-VJ for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:33 -0500 Received: from fwd24.aul.t-online.de (fwd24.aul.t-online.de [172.20.26.129]) by mailout09.t-online.de (Postfix) with SMTP id C935D42B0144; Sat, 4 Jan 2020 10:11:31 +0100 (CET) Received: from linpower.localnet (Vsp7dwZE8hpwRej46NpLTFiWFvj2SK016rerHX+lsK5vuuPi5AfAJTyyhjou9r7Qhm@[46.86.52.107]) by fwd24.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1infSv-3aVadM0; Sat, 4 Jan 2020 10:11:25 +0100 Received: by linpower.localnet (Postfix, from userid 1000) id 2155220278E; Sat, 4 Jan 2020 10:11:22 +0100 (CET) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Gerd Hoffmann Subject: [PATCH v2 2/5] hda-codec: fix recording rate control Date: Sat, 4 Jan 2020 10:11:19 +0100 Message-Id: <20200104091122.13971-2-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <07d61da6-51fb-8599-ea27-dae828fbdb3c@t-online.de> References: <07d61da6-51fb-8599-ea27-dae828fbdb3c@t-online.de> MIME-Version: 1.0 X-ID: Vsp7dwZE8hpwRej46NpLTFiWFvj2SK016rerHX+lsK5vuuPi5AfAJTyyhjou9r7Qhm X-TOI-MSGID: e3c19cee-8fcb-4b34-a0a0-7925696ff78a Content-Transfer-Encoding: quoted-printable 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?q?Zolt=C3=A1n=20K=C5=91v=C3=A1g=C3=B3?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Apply previous commit to hda_audio_input_cb for the same reasons. Signed-off-by: Volker R=C3=BCmelin --- hw/audio/hda-codec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c index 768ba31e79..e711a99a41 100644 --- a/hw/audio/hda-codec.c +++ b/hw/audio/hda-codec.c @@ -265,8 +265,6 @@ static void hda_audio_input_cb(void *opaque, int avail) =20 int64_t to_transfer =3D MIN(B_SIZE - (wpos - rpos), avail); =20 - hda_timer_sync_adjust(st, -((wpos - rpos) + to_transfer - (B_SIZE >> 1= ))); - while (to_transfer) { uint32_t start =3D (uint32_t) (wpos & B_MASK); uint32_t chunk =3D (uint32_t) MIN(B_SIZE - start, to_transfer); @@ -278,6 +276,8 @@ static void hda_audio_input_cb(void *opaque, int avail) break; } } + + hda_timer_sync_adjust(st, -((wpos - rpos) - (B_SIZE >> 1))); } =20 static void hda_audio_output_timer(void *opaque) --=20 2.16.4 From nobody Fri May 10 11:55:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1578129240; cv=none; d=zohomail.com; s=zohoarc; b=PIzZXG2QuJVdXyYv0SEEM4QyBtaQ+5xUio/IUAI+imqqZylf3S0WZ+XJcX00/vfKXHwMlFHqAhDvZXEnO6eqrdRANrxd04tkJL+HQ4CDILQHNY4Ks+0Il6oD/OWrKv0U8o52NCppUy0IfRQieSbsS4lsFppl3z7XppvXf4Hqvbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578129240; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+f0pg3iAYwQiGuINZ93fiQfTh+6WwZA23pQD1GQQXt8=; b=RQW0Vx914n09UIGddRqihdTQor1wd3PtY5+rMwfNQy9HwQfqkbg/4A7Pt0ISneg/2nF8TyGWwmavRMj/enAjW0LIRFrNi2HiNdhWhlsmlYg6HkMXzIrLUfCuxcOjw+szaCtbr/QxxnUVjEB2/tEd3uvZr/uJp7uoMgfZL02fhD0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 157812924005365.16238429157193; Sat, 4 Jan 2020 01:14:00 -0800 (PST) Received: from localhost ([::1]:60842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1infVO-0004lq-B3 for importer@patchew.org; Sat, 04 Jan 2020 04:13:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33911) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1infT1-0001dx-2R for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1infSz-0006eg-V6 for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:31 -0500 Received: from mailout06.t-online.de ([194.25.134.19]:33414) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1infSz-0006XP-OV for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:29 -0500 Received: from fwd16.aul.t-online.de (fwd16.aul.t-online.de [172.20.26.243]) by mailout06.t-online.de (Postfix) with SMTP id B3A4E41657D5; Sat, 4 Jan 2020 10:11:27 +0100 (CET) Received: from linpower.localnet (GQTK2EZXrhlnmiexBFeuF+mabf9XMAlavyrrRvkacjs49ed+hGEgecOY+zv+ghbZgF@[46.86.52.107]) by fwd16.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1infSx-1UhxJI0; Sat, 4 Jan 2020 10:11:27 +0100 Received: by linpower.localnet (Postfix, from userid 1000) id 22F0F20278F; Sat, 4 Jan 2020 10:11:22 +0100 (CET) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Gerd Hoffmann Subject: [PATCH v2 3/5] paaudio: drop recording stream in qpa_fini_in Date: Sat, 4 Jan 2020 10:11:20 +0100 Message-Id: <20200104091122.13971-3-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <07d61da6-51fb-8599-ea27-dae828fbdb3c@t-online.de> References: <07d61da6-51fb-8599-ea27-dae828fbdb3c@t-online.de> MIME-Version: 1.0 X-ID: GQTK2EZXrhlnmiexBFeuF+mabf9XMAlavyrrRvkacjs49ed+hGEgecOY+zv+ghbZgF X-TOI-MSGID: 7468035e-a24f-4e18-8a4b-0f3a9eb2e8aa Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 194.25.134.19 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?q?Zolt=C3=A1n=20K=C5=91v=C3=A1g=C3=B3?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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=3Daudio0,in.mixing-engine=3Doff and in the guest start and stop Audacity several times. Signed-off-by: Volker R=C3=BCmelin --- audio/paaudio.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/audio/paaudio.c b/audio/paaudio.c index 55a91f8980..7db1dc15f0 100644 --- a/audio/paaudio.c +++ b/audio/paaudio.c @@ -536,7 +536,6 @@ static void qpa_simple_disconnect(PAConnection *c, pa_s= tream *stream) { int err; =20 - 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_s= tream *stream) dolog("Failed to disconnect! err=3D%d\n", err); } pa_stream_unref(stream); - pa_threaded_mainloop_unlock(c->mainloop); } =20 static void qpa_fini_out (HWVoiceOut *hw) @@ -558,8 +556,12 @@ static void qpa_fini_out (HWVoiceOut *hw) PAVoiceOut *pa =3D (PAVoiceOut *) hw; =20 if (pa->stream) { - qpa_simple_disconnect(pa->g->conn, pa->stream); + PAConnection *c =3D pa->g->conn; + + pa_threaded_mainloop_lock(c->mainloop); + qpa_simple_disconnect(c, pa->stream); pa->stream =3D NULL; + pa_threaded_mainloop_unlock(c->mainloop); } } =20 @@ -568,8 +570,20 @@ static void qpa_fini_in (HWVoiceIn *hw) PAVoiceIn *pa =3D (PAVoiceIn *) hw; =20 if (pa->stream) { - qpa_simple_disconnect(pa->g->conn, pa->stream); + PAConnection *c =3D pa->g->conn; + + pa_threaded_mainloop_lock(c->mainloop); + if (pa->read_length) { + int r =3D pa_stream_drop(pa->stream); + if (r) { + qpa_logerr(pa_context_errno(c->context), + "pa_stream_drop failed\n"); + } + pa->read_length =3D 0; + } + qpa_simple_disconnect(c, pa->stream); pa->stream =3D NULL; + pa_threaded_mainloop_unlock(c->mainloop); } } =20 --=20 2.16.4 From nobody Fri May 10 11:55:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1578129180; cv=none; d=zohomail.com; s=zohoarc; b=YVFnoHBVFPPSvLyNw1xBxWZK4ko6ZlHC5zXsAaz4yQPHfDRniBQbryF71V1k2NEu4x92WS2gSHAl34CEb0RoJBfw4w0bx6W7IbmIEi5IbjzJxpzCtCn3WAqYBNDE+UcB5U/xB8C2XuludIgRta5CEf8RnpqpsIewJStBVH5o7b0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578129180; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SQa7QgpuAAQSD1rLarbVuhj+rInGuQLWy0Bg+AwZyD0=; b=QGz89rTWONWeITzAtsDaJwhamteI4Ep6smerO6lbe2xyI+2kfU/iAubDqL/VrGJCgRqBUZtsmZOx8u3MQjG1SEKrxISmwcK2qMdmZX97oiyU8zZGgCQQJaLDWiPKQELyWF5UtmBJXwq3d4we6m/lvRGPXlwJ43y/nVY3KgoOnHQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1578129180851164.37621868080464; Sat, 4 Jan 2020 01:13:00 -0800 (PST) Received: from localhost ([::1]:60828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1infUR-00033L-Hx for importer@patchew.org; Sat, 04 Jan 2020 04:12:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34273) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1infT9-0001ng-VC for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1infT8-0007K7-S5 for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:39 -0500 Received: from mailout04.t-online.de ([194.25.134.18]:36306) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1infT8-0007DX-HE for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:38 -0500 Received: from fwd12.aul.t-online.de (fwd12.aul.t-online.de [172.20.26.241]) by mailout04.t-online.de (Postfix) with SMTP id 203DB41904F8; Sat, 4 Jan 2020 10:11:37 +0100 (CET) Received: from linpower.localnet (S93r+EZ-rh-NNDYjO-bIx-zLrYiS54V1ea7AhDvk1yee-NeM98CGnSyInM5z20RgXm@[46.86.52.107]) by fwd12.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1infT0-3tz2O00; Sat, 4 Jan 2020 10:11:30 +0100 Received: by linpower.localnet (Postfix, from userid 1000) id 25102202790; Sat, 4 Jan 2020 10:11:22 +0100 (CET) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Gerd Hoffmann Subject: [PATCH v2 4/5] paaudio: try to drain the recording stream Date: Sat, 4 Jan 2020 10:11:21 +0100 Message-Id: <20200104091122.13971-4-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <07d61da6-51fb-8599-ea27-dae828fbdb3c@t-online.de> References: <07d61da6-51fb-8599-ea27-dae828fbdb3c@t-online.de> MIME-Version: 1.0 X-ID: S93r+EZ-rh-NNDYjO-bIx-zLrYiS54V1ea7AhDvk1yee-NeM98CGnSyInM5z20RgXm X-TOI-MSGID: 3d60a767-2304-4d89-9883-635d1e7acd36 Content-Transfer-Encoding: quoted-printable 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?q?Zolt=C3=A1n=20K=C5=91v=C3=A1g=C3=B3?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" There is no guarantee a single call to pa_stream_peek every timer_period microseconds can read a recording stream faster than the data gets produced at the source. Let qpa_read try to drain the recording stream. To reproduce the problem: Start qemu with -audiodev pa,id=3Daudio0,in.mixing-engine=3Doff On the host connect the qemu recording stream to the monitor of a hardware output device. While the problem can also be seen with a hardware input device, it's obvious with the monitor of a hardware output device. In the guest start audio recording with audacity and notice the slow recording data rate. Signed-off-by: Volker R=C3=BCmelin --- audio/paaudio.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/audio/paaudio.c b/audio/paaudio.c index 7db1dc15f0..b23274550e 100644 --- a/audio/paaudio.c +++ b/audio/paaudio.c @@ -156,34 +156,43 @@ static size_t qpa_read(HWVoiceIn *hw, void *data, siz= e_t length) { PAVoiceIn *p =3D (PAVoiceIn *) hw; PAConnection *c =3D p->g->conn; - size_t l; - int r; + size_t total =3D 0; =20 pa_threaded_mainloop_lock(c->mainloop); =20 CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail, "pa_threaded_mainloop_lock failed\n"); =20 - if (!p->read_length) { - r =3D pa_stream_peek(p->stream, &p->read_data, &p->read_length); - CHECK_SUCCESS_GOTO(c, r =3D=3D 0, unlock_and_fail, - "pa_stream_peek failed\n"); - } + while (total < length) { + size_t l; + int r; + + if (!p->read_length) { + r =3D pa_stream_peek(p->stream, &p->read_data, &p->read_length= ); + CHECK_SUCCESS_GOTO(c, r =3D=3D 0, unlock_and_fail, + "pa_stream_peek failed\n"); + if (!p->read_length) { + /* buffer is empty */ + break; + } + } =20 - l =3D MIN(p->read_length, length); - memcpy(data, p->read_data, l); + l =3D MIN(p->read_length, length - total); + memcpy((char *)data + total, p->read_data, l); =20 - p->read_data +=3D l; - p->read_length -=3D l; + p->read_data +=3D l; + p->read_length -=3D l; + total +=3D l; =20 - if (!p->read_length) { - r =3D pa_stream_drop(p->stream); - CHECK_SUCCESS_GOTO(c, r =3D=3D 0, unlock_and_fail, - "pa_stream_drop failed\n"); + if (!p->read_length) { + r =3D pa_stream_drop(p->stream); + CHECK_SUCCESS_GOTO(c, r =3D=3D 0, unlock_and_fail, + "pa_stream_drop failed\n"); + } } =20 pa_threaded_mainloop_unlock(c->mainloop); - return l; + return total; =20 unlock_and_fail: pa_threaded_mainloop_unlock(c->mainloop); --=20 2.16.4 From nobody Fri May 10 11:55:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1578129182; cv=none; d=zohomail.com; s=zohoarc; b=NOOzQIbqCIuCOkTs1PY4Qwyc031BjJ3Ypv4W4NouYjIOx8+2ihW64yUuMboM4WjXft/D+dy2QSRcwc/H4fu2MIvYldBL92lyergrg0RlrCuvVwiOxH1Z0IMOO2679ZstvKvhYRQIG4nKD2ngVYaDv/PfCkuaPny34JhHc4sbaEA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578129182; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OhXDPhKnRqH75QMWGx8RkZuxqrmfSWZf7CsRQp2FtwE=; b=O/9znNuu8GpSZ/gUMPoKQ1hcF+xfKBpb1SbCexZbyW33CqQILRSKDoX0Y0c3+v84tS0UtY2Dyc67I/SkuhZe6E+zSqX1uIwLfU3Mw/nmGv6T6k3FHMJDkj6bfaW0s6r2pAk+MHTAyeMytFbzozYiRlNE71PvoAs4aJ5lhDUxtlM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1578129182604960.8598789531596; Sat, 4 Jan 2020 01:13:02 -0800 (PST) Received: from localhost ([::1]:60830 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1infUT-00038F-3c for importer@patchew.org; Sat, 04 Jan 2020 04:13:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34368) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1infTC-0001qR-5o for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1infTA-0007TL-R2 for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:42 -0500 Received: from mailout12.t-online.de ([194.25.134.22]:33140) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1infTA-0007NT-Jc for qemu-devel@nongnu.org; Sat, 04 Jan 2020 04:11:40 -0500 Received: from fwd21.aul.t-online.de (fwd21.aul.t-online.de [172.20.27.66]) by mailout12.t-online.de (Postfix) with SMTP id 30B6A41E652F; Sat, 4 Jan 2020 10:11:39 +0100 (CET) Received: from linpower.localnet (EZWeFBZfghF69dEMnIqJRorvOHbAgVQGZh4eOH2FBL4NRM7JDnFHVw+xIron87bgSS@[46.86.52.107]) by fwd21.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1infT2-0fp5CC0; Sat, 4 Jan 2020 10:11:32 +0100 Received: by linpower.localnet (Postfix, from userid 1000) id 2723E202791; Sat, 4 Jan 2020 10:11:22 +0100 (CET) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Gerd Hoffmann Subject: [PATCH v2 5/5] paaudio: wait until the recording stream is ready Date: Sat, 4 Jan 2020 10:11:22 +0100 Message-Id: <20200104091122.13971-5-vr_qemu@t-online.de> X-Mailer: git-send-email 2.16.4 In-Reply-To: <07d61da6-51fb-8599-ea27-dae828fbdb3c@t-online.de> References: <07d61da6-51fb-8599-ea27-dae828fbdb3c@t-online.de> MIME-Version: 1.0 X-ID: EZWeFBZfghF69dEMnIqJRorvOHbAgVQGZh4eOH2FBL4NRM7JDnFHVw+xIron87bgSS X-TOI-MSGID: adab2745-9ac0-43f4-9e76-d06ad377268a Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 194.25.134.22 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?q?Zolt=C3=A1n=20K=C5=91v=C3=A1g=C3=B3?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Don't call pa_stream_peek before the recording stream is ready. Information to reproduce the problem. Start and stop Audacity in the guest several times because the problem is racy. libvirt log file: -audiodev pa,id=3Daudio0,server=3Dlocalhost,out.latency=3D30000, out.mixing-engine=3Doff,in.mixing-engine=3Doff \ -sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny, resourcecontrol=3Ddeny \ -msg timestamp=3Don : Domain id=3D4 is tainted: custom-argv char device redirected to /dev/pts/1 (label charserial0) audio: Device pcspk: audiodev default parameter is deprecated, please specify audiodev=3Daudio0 audio: Device hda: audiodev default parameter is deprecated, please specify audiodev=3Daudio0 pulseaudio: pa_stream_peek failed pulseaudio: Reason: Bad state pulseaudio: pa_stream_peek failed pulseaudio: Reason: Bad state Signed-off-by: Volker R=C3=BCmelin --- audio/paaudio.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/audio/paaudio.c b/audio/paaudio.c index b23274550e..dbfe48c03a 100644 --- a/audio/paaudio.c +++ b/audio/paaudio.c @@ -162,6 +162,10 @@ static size_t qpa_read(HWVoiceIn *hw, void *data, size= _t length) =20 CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail, "pa_threaded_mainloop_lock failed\n"); + if (pa_stream_get_state(p->stream) !=3D PA_STREAM_READY) { + /* wait for stream to become ready */ + goto unlock; + } =20 while (total < length) { size_t l; @@ -191,6 +195,7 @@ static size_t qpa_read(HWVoiceIn *hw, void *data, size_= t length) } } =20 +unlock: pa_threaded_mainloop_unlock(c->mainloop); return total; =20 --=20 2.16.4