From nobody Sun May 5 19:28:16 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=1576785818; cv=none; d=zohomail.com; s=zohoarc; b=LzJArA+GTZ2kjk7cWP7Bip8yVXtvsWM/36f+DVzjSqv9hubRoasDvZMeal7WYmMF/6KvAxX5aRU/byM+y3vfYwQcMPT4L6oOhM4yg0sYgGNG7EgZX2+S6/RUeVKJJXAMTYF43jEIkphJ9o+gb1Yjahvl//FEPIID9H9YWiJXMfU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576785818; 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=Tm8W/LktEhN2U1Balix+nCrImG6tA4LDQM20KNMH+YxOYG1o5YGMG9SOrtakSTQF5QHcYV0AE3SIvd31E6nVM8IwwzGuM3RLq6OGDiIyS73UEUW81n9vdKOqEK/1pSa8n5D1LCxEKsvpIN0bmwn/0Ot4/X72P4DWXCh3mLKK3yg= 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 1576785818122310.27940790271055; Thu, 19 Dec 2019 12:03:38 -0800 (PST) Received: from localhost ([::1]:47304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii21J-0007uA-1X for importer@patchew.org; Thu, 19 Dec 2019 15:03:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42984) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii20R-0007T8-OW for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:02:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii20Q-0002uM-Gp for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:02:43 -0500 Received: from mailout07.t-online.de ([194.25.134.83]:43240) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ii20Q-0002l0-9L for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:02:42 -0500 Received: from fwd17.aul.t-online.de (fwd17.aul.t-online.de [172.20.27.64]) by mailout07.t-online.de (Postfix) with SMTP id 0494D424FF80; Thu, 19 Dec 2019 21:02:40 +0100 (CET) Received: from [192.168.211.200] (ZZRWJ-ZBghl4kMXOpLip6IQ485LcTk0fXQ4pIegyr19fKWnM8Q74G5VZ5xn+AbhQIW@[46.86.55.2]) by fwd17.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1ii20N-1kl7J20; Thu, 19 Dec 2019 21:02:39 +0100 Subject: [PATCH 1/5] hda-codec: fix playback rate control From: =?UTF-8?Q?Volker_R=c3=bcmelin?= To: Gerd Hoffmann References: Message-ID: <494a02d8-c4de-958a-6fd6-c6df95943293@t-online.de> Date: Thu, 19 Dec 2019 21:02:39 +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: ZZRWJ-ZBghl4kMXOpLip6IQ485LcTk0fXQ4pIegyr19fKWnM8Q74G5VZ5xn+AbhQIW X-TOI-MSGID: 0662df15-6a1c-4f08-87c5-9098d0c10c74 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.83 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+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 Sun May 5 19:28:16 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=1576785912; cv=none; d=zohomail.com; s=zohoarc; b=nZZGCskA6CwKWpcHgpYoWQohHm/nCisbaW5U9wNzEuZKTtn+tAxaM8XEuXMnegLlCVg4Nt1umvsrb8ucOi+8+Cj1Hk9JDh4+gRgUG8s56ggh5bkM4stRm5uNGsxIukavgC0q8RCVChCBogkbgD28BnlfXiZgjKMk2ZzrPZZQLuQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576785912; h=Content-Type: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=38Mk5q4ROeG9K/yMidcZEFERSggPBRy2zFsI/4KUnkQ=; b=kEgidI1JyXETFZ7jYaS4NxcPyTRjdPNHyL2wt8PJT0fikQYMiSCVIxdAg+azkh6d045WA84IZ2RTK5R/p8znRucGrN4omuzjwCizSKoFTUiTZLuAgu2K85iD/FAbxOOOGusjR5cuQEVBwlPLEsGqgqwmpRehdq98b3trfpLtqXE= 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 1576785912640311.8200652933168; Thu, 19 Dec 2019 12:05:12 -0800 (PST) Received: from localhost ([::1]:47324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii22p-0000TF-DO for importer@patchew.org; Thu, 19 Dec 2019 15:05:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49995) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii223-0008OP-01 for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:04:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii221-0001oN-Qx for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:04:22 -0500 Received: from mailout11.t-online.de ([194.25.134.85]:52208) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ii221-0001fn-Gz for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:04:21 -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 03819422183B; Thu, 19 Dec 2019 21:04:20 +0100 (CET) Received: from [192.168.211.200] (SUGkSqZ1whffNCN1h7XYDfYU8mnY17v7cTj4PoJWrz18QKJbU7CyNfJkRWir9jzgAn@[46.86.55.2]) by fwd02.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1ii21x-2Fkh4S0; Thu, 19 Dec 2019 21:04:17 +0100 Subject: [PATCH 2/5] hda-codec: fix recording rate control From: =?UTF-8?Q?Volker_R=c3=bcmelin?= To: Gerd Hoffmann References: Message-ID: <08ea1c13-aa53-31f4-4495-ff4e455ae3ad@t-online.de> Date: Thu, 19 Dec 2019 21:04:16 +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-Type: multipart/alternative; boundary="------------96E699F27F3941B227FB4792" Content-Language: de-DE X-ID: SUGkSqZ1whffNCN1h7XYDfYU8mnY17v7cTj4PoJWrz18QKJbU7CyNfJkRWir9jzgAn X-TOI-MSGID: e54a930e-1124-4056-8d16-d18c99b7771d 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" This is a multi-part message in MIME format. --------------96E699F27F3941B227FB4792 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 --------------96E699F27F3941B227FB4792 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Apply previous commit to hda_audio_input_cb for the same
reasons.

Signed-off-by: Volker R=C3=BCmelin <vr_qemu@t-online.de>
---
 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 avai=
l)
=20
     int64_t to_transfer =3D MIN(B_SIZE - (wpos - rpos), avail);
=20
-    hda_timer_sync_adjust(st, -((wpos - rpos) + to_transfer - (B_SIZE &g=
t;> 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 avai=
l)
             break;
         }
     }
+
+    hda_timer_sync_adjust(st, -((wpos - rpos) - (B_SIZE >> 1)));
 }
=20
 static void hda_audio_output_timer(void *opaque)
--=20
2.16.4

--------------96E699F27F3941B227FB4792-- From nobody Sun May 5 19:28:16 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=1576786007; cv=none; d=zohomail.com; s=zohoarc; b=Abg9jYvwiLSy6eGRXax/2TceOwxUj/9IIgIG5/ExRlD9rXmMX6JkcO286/7nkcUQMcdnRlnC2q11h9pPGfc7wvvLrYVQM8rE9ojyqR7fY6jH1sglhr5wgFGqQ4yof945PnW1cyGBmOtfQbHvFv9QqryzZVCADHiqnu6fcwyLmc0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576786007; 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=I21RZaLZoAHPa5pwwJLNHbrmo7CsRhlk8KNLG83rbBU=; b=hxhg9wP7p/clxDMJLmqrOBI7qTDNokiHBTHdVYBJgzOHdxgY6L5ZmsySiDRnJeslx3vgUCN0hcaAGaW5Sv3WLUHt9k3+tGFhJXuEQCJiyDAz57ozjOEySnBZ0KlIIjyAQcHEoR4GARL/qqyQT+fbsVhtNVGqzWN1t9wncIhwGzE= 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 1576786007558530.7039361361149; Thu, 19 Dec 2019 12:06:47 -0800 (PST) Received: from localhost ([::1]:47346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii24M-0002GJ-0I for importer@patchew.org; Thu, 19 Dec 2019 15:06:46 -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 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?B?Wm9sdMOhbiBLxZF2w6Fnw7M=?= 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..b831e0d6e9 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_peek 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 Sun May 5 19:28:16 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=1576786057; cv=none; d=zohomail.com; s=zohoarc; b=mQK6b7Rp6ai5UIogspHV4gu6CC0vLdhfRnwpirN1tExCUlOyV8512NeGVFUCFMLnb7JRWdg0bhS57IiEF0Dci6a0PaCFTpiVbE+LwN3qhDaoP6nVtSYL6Z5pHowa+KOsWyLOujgNGAh8yufru2IQ+hTv9WQgjP5GNTafmq+nQ5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576786057; 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=URu5qgk7Eib352EC9ichtoQOASbNm98ylnqP/D6NFy4=; b=Eb0hGPzwmxlO+oYNpR7vESpmPjMfPE4xyCVfb096kQU+K04DuHrc6C5qfl+RReV2KKZdhWFsbZYLPahKroE3ZO+lX3kh1RXv345LOkox6OVvz+19lTjqpocqr1yHhVU0wI16S0eEQNCB77Zt+HOjsDWdBnf/Li/mu+up9vlksv0= 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 1576786057194819.8436229559102; Thu, 19 Dec 2019 12:07:37 -0800 (PST) Received: from localhost ([::1]:47364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii25A-00043D-2I for importer@patchew.org; Thu, 19 Dec 2019 15:07:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60283) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii24G-0002kn-VG for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:06:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii24F-0003Po-HY for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:06:40 -0500 Received: from mailout12.t-online.de ([194.25.134.22]:44240) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ii24D-0003NL-PK for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:06:39 -0500 Received: from fwd22.aul.t-online.de (fwd22.aul.t-online.de [172.20.26.127]) by mailout12.t-online.de (Postfix) with SMTP id B7EE741AFDC5; Thu, 19 Dec 2019 21:06:35 +0100 (CET) Received: from [192.168.211.200] (VUAwt-ZEQhwNXPnMw2O1Qyw1MSFReu12g51ON5DA-AVon5Sft86uNVO8SS2K-yygwM@[46.86.55.2]) by fwd22.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1ii24B-1NVevw0; Thu, 19 Dec 2019 21:06:35 +0100 Subject: [PATCH 4/5] paaudio: try to drain the recording stream From: =?UTF-8?Q?Volker_R=c3=bcmelin?= To: Gerd Hoffmann References: Message-ID: <4c416617-26ce-f8ac-ac13-10b803308204@t-online.de> Date: Thu, 19 Dec 2019 21:06:35 +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: VUAwt-ZEQhwNXPnMw2O1Qyw1MSFReu12g51ON5DA-AVon5Sft86uNVO8SS2K-yygwM X-TOI-MSGID: e612b01a-ca9d-4a36-96e7-e1f429f46cc0 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?B?Wm9sdMOhbiBLxZF2w6Fnw7M=?= 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 b831e0d6e9..03cf10bb3c 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 Sun May 5 19:28:16 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=1576786128; cv=none; d=zohomail.com; s=zohoarc; b=m76s1oOjNgns+DaoS46CuX1s1KwoWOM5ug60DK8Y8h39yMGjCBd909m9g0cgK6uQRx/Jt3rltV278sh+eF9zf/ZjmJpKrakW72rmM4E+VddFCJw2K64yC+CZna21DCOQKKlCvJpiRwi10IjKiDA2+U8Mto4PsXbjEK4+cjUg6fg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576786128; 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=Wvn5PKzIDDgrDrS09qZXRktIwEhlResdedpy7io52mc=; b=EQWzGIos0mIwmWKcAfLjsoH5DfntghiU1l4rT+THSoj+b2F9CMatq+uV9RJf066bIzgRnfmIB9RS03KquOPqUOKxxO48YMPQex65dfynlFN4G/2IYvnc+GR5GraIgJmVQzUqbkkKhohkyrpYNx7IcbjmUh5YUEH80VW4bdvRPqs= 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 1576786128873752.279003192332; Thu, 19 Dec 2019 12:08:48 -0800 (PST) Received: from localhost ([::1]:47370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii26J-00058P-F6 for importer@patchew.org; Thu, 19 Dec 2019 15:08:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37739) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii25T-0004Zn-Ab for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:07:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ii25S-0000bV-7E for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:07:55 -0500 Received: from mailout03.t-online.de ([194.25.134.81]:54232) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ii25R-0000UY-UR for qemu-devel@nongnu.org; Thu, 19 Dec 2019 15:07:54 -0500 Received: from fwd13.aul.t-online.de (fwd13.aul.t-online.de [172.20.27.62]) by mailout03.t-online.de (Postfix) with SMTP id 5020342A320C; Thu, 19 Dec 2019 21:07:52 +0100 (CET) Received: from [192.168.211.200] (GD7AcuZrZhKODslQh75k-GKlCninl-DFx7aufMgAhtrGOegIiy71jnGYJEUxQ+Hwu3@[46.86.55.2]) by fwd13.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1ii25K-1F4MrY0; Thu, 19 Dec 2019 21:07:46 +0100 Subject: [PATCH 5/5] paaudio: wait until the recording stream is ready From: =?UTF-8?Q?Volker_R=c3=bcmelin?= To: Gerd Hoffmann References: Message-ID: Date: Thu, 19 Dec 2019 21:07:46 +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: GD7AcuZrZhKODslQh75k-GKlCninl-DFx7aufMgAhtrGOegIiy71jnGYJEUxQ+Hwu3 X-TOI-MSGID: 09e120e7-5a6c-4bea-960f-31fe89364f37 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.81 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+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 03cf10bb3c..bb4150bc34 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