From patchwork Thu Dec 19 20:06:35 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: 11304339 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2605E109A for ; Thu, 19 Dec 2019 20:07:24 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 050562465E for ; Thu, 19 Dec 2019 20:07:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 050562465E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=t-online.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ii24x-00043D-5N for patchwork-qemu-devel@patchwork.kernel.org; Thu, 19 Dec 2019 15:07:23 -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 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+patchwork-qemu-devel=patchwork.kernel.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 b831e0d6e9..03cf10bb3c 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);