From patchwork Sun Sep 20 17:17:23 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: 11787935 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 AA82959D for ; Sun, 20 Sep 2020 17:19:19 +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 68565207BB for ; Sun, 20 Sep 2020 17:19:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68565207BB 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]:47762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kK2zd-0005dy-Dh for patchwork-qemu-devel@patchwork.kernel.org; Sun, 20 Sep 2020 13:19:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kK2y3-00040u-Eq for qemu-devel@nongnu.org; Sun, 20 Sep 2020 13:17:39 -0400 Received: from mailout08.t-online.de ([194.25.134.20]:56150) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kK2y1-0006Fd-Nd for qemu-devel@nongnu.org; Sun, 20 Sep 2020 13:17:39 -0400 Received: from fwd20.aul.t-online.de (fwd20.aul.t-online.de [172.20.26.140]) by mailout08.t-online.de (Postfix) with SMTP id 07E2941E61DF; Sun, 20 Sep 2020 19:17:36 +0200 (CEST) Received: from linpower.localnet (G54emqZHYhtqxL8jXYmVtop8pYMDyAFBZ-bbdLrqWFyzWCBFxEoBEQcOotHyBf6wlm@[93.236.144.216]) by fwd20.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1kK2xz-0t19hA0; Sun, 20 Sep 2020 19:17:35 +0200 Received: by linpower.localnet (Postfix, from userid 1000) id EF210335504; Sun, 20 Sep 2020 19:17:29 +0200 (CEST) From: =?utf-8?q?Volker_R=C3=BCmelin?= To: Gerd Hoffmann Subject: [PATCH 3/9] audio/spiceaudio: always rate limit playback stream Date: Sun, 20 Sep 2020 19:17:23 +0200 Message-Id: <20200920171729.15861-3-vr_qemu@t-online.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <84f1c61a-8399-c75e-96c2-febfc2dd5fab@t-online.de> References: <84f1c61a-8399-c75e-96c2-febfc2dd5fab@t-online.de> MIME-Version: 1.0 X-ID: G54emqZHYhtqxL8jXYmVtop8pYMDyAFBZ-bbdLrqWFyzWCBFxEoBEQcOotHyBf6wlm X-TOI-EXPURGATEID: 150726::1600622255-000053CC-410D1DA5/0/0 CLEAN NORMAL X-TOI-MSGID: c27bc480-7caa-410e-a3f0-2339759c4744 Received-SPF: none client-ip=194.25.134.20; envelope-from=volker.ruemelin@t-online.de; helo=mailout08.t-online.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/20 13:17:36 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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-devel , =?utf-8?b?Wm9sdMOhbiBLxZF2w6Fnw7M=?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The playback rate with the spiceaudio backend is currently too fast if there's no spice client connected or the spice client can't play audio. Rate limit the audio playback stream in all cases. To calculate the rate correctly the limiter has to know the maximum buffer size. Fixes: 8c198ff065 ("spiceaudio: port to the new audio backend api") Signed-off-by: Volker RĂ¼melin --- audio/audio.c | 3 ++- audio/spiceaudio.c | 10 ++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/audio/audio.c b/audio/audio.c index ad3f57b4c4..ba52259050 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -1089,7 +1089,8 @@ static size_t audio_pcm_hw_run_out(HWVoiceOut *hw, size_t live) size_t clipped = 0; while (live) { - size_t size, decr, proc; + size_t size = live * hw->info.bytes_per_frame; + size_t decr, proc; void *buf = hw->pcm_ops->get_buffer_out(hw, &size); if (size == 0) { diff --git a/audio/spiceaudio.c b/audio/spiceaudio.c index c8d81ba442..c062742622 100644 --- a/audio/spiceaudio.c +++ b/audio/spiceaudio.c @@ -130,13 +130,11 @@ static void *line_out_get_buffer(HWVoiceOut *hw, size_t *size) } if (out->frame) { - *size = audio_rate_get_bytes( - &hw->info, &out->rate, - (out->fsize - out->fpos) * hw->info.bytes_per_frame); - } else { - audio_rate_start(&out->rate); - *size = LINE_OUT_SAMPLES << 2; + *size = MIN((out->fsize - out->fpos) << 2, *size); } + + *size = audio_rate_get_bytes(&hw->info, &out->rate, *size); + return out->frame + out->fpos; }