From nobody Tue Feb 10 12:59:50 2026 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