From patchwork Mon Jan 6 12:52:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 11319201 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 246D114BD for ; Mon, 6 Jan 2020 12:54:02 +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 F008E2072E for ; Mon, 6 Jan 2020 12:54:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Jwk/iMBr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F008E2072E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:51450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ioRtQ-0002Vf-K9 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 Jan 2020 07:54:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58252) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ioRsC-0000qF-Lk for qemu-devel@nongnu.org; Mon, 06 Jan 2020 07:52:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ioRsB-0000oh-Kk for qemu-devel@nongnu.org; Mon, 06 Jan 2020 07:52:44 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:51214 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ioRsB-0000my-FM for qemu-devel@nongnu.org; Mon, 06 Jan 2020 07:52:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578315162; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rUKfZuNd1Qu2lKoFCCnXZ06t/YR98pMi3balpjSIsSo=; b=Jwk/iMBrck5d2WAVbA7Bv2KYzaRSsCtOu5z6silLz4aXeoFy88VZ88Vts57hqSieZP/495 sMqzGs3kQEEvYoBpbiRiTODlzT+oR6lys8OJ1nWlPEQkoxWDffCJWfDQ/edkAEz/i0kZAz Vy1rLboWBRAt+8WDHFA3Y9nAHO3oJYw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-264-yI2feI0yMZuuG6khj3vIMQ-1; Mon, 06 Jan 2020 07:52:41 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D390800D4E; Mon, 6 Jan 2020 12:52:40 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-98.ams2.redhat.com [10.36.116.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83FEB5C57C; Mon, 6 Jan 2020 12:52:37 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id A8B7831E49; Mon, 6 Jan 2020 13:52:36 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Subject: [PULL 4/6] paaudio: try to drain the recording stream Date: Mon, 6 Jan 2020 13:52:34 +0100 Message-Id: <20200106125236.24132-5-kraxel@redhat.com> In-Reply-To: <20200106125236.24132-1-kraxel@redhat.com> References: <20200106125236.24132-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: yI2feI0yMZuuG6khj3vIMQ-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 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: =?utf-8?q?Volker_R=C3=BCmelin?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Volker RĂ¼melin 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 Message-id: 20200104091122.13971-4-vr_qemu@t-online.de Signed-off-by: Gerd Hoffmann --- audio/paaudio.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/audio/paaudio.c b/audio/paaudio.c index 7db1dc15f09e..b23274550e1c 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; - l = MIN(p->read_length, length); - memcpy(data, p->read_data, l); + 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; + } + } - p->read_data += l; - p->read_length -= l; + l = MIN(p->read_length, length - total); + memcpy((char *)data + total, p->read_data, 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"); + 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"); + } } pa_threaded_mainloop_unlock(c->mainloop); - return l; + return total; unlock_and_fail: pa_threaded_mainloop_unlock(c->mainloop);