From patchwork Sat Jan 4 09:11:21 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: 1217518 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 47qbdF6pM4z9s4Y for ; Sat, 4 Jan 2020 20:12:17 +1100 (AEDT) Received: from localhost ([::1]:60822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1infTj-0001pj-No for incoming@patchwork.ozlabs.org; Sat, 04 Jan 2020 04:12:15 -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_R=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 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" 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=audio0,in.mixing-engine=off 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Ă¼melin --- 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, size_t length) { PAVoiceIn *p = (PAVoiceIn *) hw; PAConnection *c = p->g->conn; - size_t l; - int r; + size_t total = 0; pa_threaded_mainloop_lock(c->mainloop); CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail, "pa_threaded_mainloop_lock failed\n"); - if (!p->read_length) { - r = pa_stream_peek(p->stream, &p->read_data, &p->read_length); - CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail, - "pa_stream_peek failed\n"); - } + while (total < length) { + size_t l; + int r; + + if (!p->read_length) { + r = pa_stream_peek(p->stream, &p->read_data, &p->read_length); + CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail, + "pa_stream_peek failed\n"); + if (!p->read_length) { + /* buffer is empty */ + break; + } + } - l = MIN(p->read_length, length); - memcpy(data, p->read_data, l); + l = MIN(p->read_length, length - total); + memcpy((char *)data + total, p->read_data, l); - p->read_data += l; - p->read_length -= l; + p->read_data += l; + p->read_length -= l; + total += l; - if (!p->read_length) { - r = pa_stream_drop(p->stream); - CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail, - "pa_stream_drop failed\n"); + if (!p->read_length) { + r = pa_stream_drop(p->stream); + CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail, + "pa_stream_drop failed\n"); + } } pa_threaded_mainloop_unlock(c->mainloop); - return l; + return total; unlock_and_fail: pa_threaded_mainloop_unlock(c->mainloop);