From nobody Mon Feb 9 13:22:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=reject dis=none) header.from=hostfission.com ARC-Seal: i=1; a=rsa-sha256; t=1592107999; cv=none; d=zohomail.com; s=zohoarc; b=HusGZ6KU6pfJuCZOVvMBk+xgWmrs1h4wfVLkILUoUfNzeceXgeLOu6doHMufNi7qDDUcjekkagwd3PM//1Bm2tPDWlxcK7HwF7F61ZeZLBPnHC2xO1HV0+4t40PPZPYEmPoRxN7aGogKanVv/cg3ZC62pA8tQaw667XJmbkcAK0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592107999; h=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=syQ7cVBdjSwvfcjXNx6bbkvtoo3Jh+rME40M5u0Mhcg=; b=cFGfgCARWwklz7kADU3j94gcoGkpEYCMk1NLJ9osSv/9Zj17K3NJiKsnc87/RBX9WwmlHMUXLy8HxPgIu4Mk7icFVlyi5SezauTq0uk61DoOB234jVl+1q05FkKovG+bGiCjySooVFLN+RTXFQ5WKsKFuXnCVU/Sq4xtp4/k/ck= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1592107999608887.4834432882917; Sat, 13 Jun 2020 21:13:19 -0700 (PDT) Received: from localhost ([::1]:59934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jkK1F-0005xx-Df for importer@patchew.org; Sun, 14 Jun 2020 00:13:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jkK0b-0005ZT-TX for qemu-devel@nongnu.org; Sun, 14 Jun 2020 00:12:37 -0400 Received: from mail1.hostfission.com ([139.99.139.48]:57166) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jkK0Z-0000Wv-6g for qemu-devel@nongnu.org; Sun, 14 Jun 2020 00:12:37 -0400 Received: from moya.office.hostfission.com (office.hostfission.com [220.233.29.71]) by mail1.hostfission.com (Postfix) with ESMTP id F40CE445F5; Sat, 13 Jun 2020 14:06:03 +1000 (AEST) Received: by moya.office.hostfission.com (Postfix, from userid 0) id DEEF23A0A09; Sat, 13 Jun 2020 14:06:03 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hostfission.com; s=mail; t=1592021164; bh=OdRJm45Q4UNv6+P+Ib6qm82RVr++vAH8VUG3t1Sh9As=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EQ6RRkbTradms1c0z8CjTkJwEhZCGlifW+0zK7nIftNw4xvLHlCAfgzq1RoPUTVXA +AAEe3GSWdDPDt0h3FwlCRAoXG5Jt9dxHGER6X9MCCVn7I5JvCtWo7dcIb0xImPQKU HxNYSfgxKO6bsuFxtME/KslpjAOgduxzOMlJb5P0= From: Geoffrey McRae To: qemu-devel@nongnu.org Cc: kraxel@redhat.com, geoff@hostfission.com Subject: [PATCH 5/6] audio/jack: honour the enable state of the audio device Date: Sat, 13 Jun 2020 14:05:17 +1000 Message-Id: <20200613040518.38172-6-geoff@hostfission.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200613040518.38172-1-geoff@hostfission.com> References: <20200613040518.38172-1-geoff@hostfission.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: none client-ip=139.99.139.48; envelope-from=root@moya.office.hostfission.com; helo=mail1.hostfission.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/13 00:05:57 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=_AUTOLEARN 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @hostfission.com) Content-Type: text/plain; charset="utf-8" When the guest closes the audio device we must start dropping input samples from JACK and zeroing the output buffer samples. Failure to do so causes sound artifacts during operations such as guest OS reboot, and causes a hang of the input pipeline breaking it until QEMU is restated. Closing and reconnecting to JACK was tested during these enable/disable calls which works well for Linux guests, however Windows re-opens the audio hardware repeatedly even when doing simple tasks like playing a system sounds. As such it was decided it is better to feed silence to JACK while the device is disabled. Signed-off-by: Geoffrey McRae --- audio/jackaudio.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/audio/jackaudio.c b/audio/jackaudio.c index 249cbd3265..b2b53985ae 100644 --- a/audio/jackaudio.c +++ b/audio/jackaudio.c @@ -56,7 +56,7 @@ typedef struct QJackClient { AudiodevJackPerDirectionOptions *opt; =20 bool out; - bool finished; + bool enabled; bool connect_ports; int packets; =20 @@ -271,9 +271,17 @@ static int qjack_process(jack_nframes_t nframes, void = *arg) } =20 if (c->out) { - qjack_buffer_read_l(&c->fifo, buffers, nframes); + if (likely(c->enabled)) { + qjack_buffer_read_l(&c->fifo, buffers, nframes); + } else { + for(int i =3D 0; i < c->nchannels; ++i) { + memset(buffers[i], 0, nframes * sizeof(float)); + } + } } else { - qjack_buffer_write_l(&c->fifo, buffers, nframes); + if (likely(c->enabled)) { + qjack_buffer_write_l(&c->fifo, buffers, nframes); + } } =20 return 0; @@ -314,8 +322,8 @@ static void qjack_client_recover(QJackClient *c) if (c->state =3D=3D QJACK_STATE_DISCONNECTED && c->packets % 100 =3D=3D 0) { =20 - /* if not finished then attempt to recover */ - if (!c->finished) { + /* if enabled then attempt to recover */ + if (c->enabled) { dolog("attempting to reconnect to server\n"); qjack_client_init(c); } @@ -387,7 +395,6 @@ static int qjack_client_init(QJackClient *c) char client_name[jack_client_name_size()]; jack_options_t options =3D JackNullOption; =20 - c->finished =3D false; c->connect_ports =3D true; =20 snprintf(client_name, sizeof(client_name), "%s-%s", @@ -483,8 +490,10 @@ static int qjack_init_out(HWVoiceOut *hw, struct audse= ttings *as, } =20 jo->c.out =3D true; + jo->c.enabled =3D false; jo->c.nchannels =3D as->nchannels; jo->c.opt =3D dev->u.jack.out; + int ret =3D qjack_client_init(&jo->c); if (ret !=3D 0) { return ret; @@ -519,8 +528,10 @@ static int qjack_init_in(HWVoiceIn *hw, struct audsett= ings *as, } =20 ji->c.out =3D false; + ji->c.enabled =3D false; ji->c.nchannels =3D as->nchannels; ji->c.opt =3D dev->u.jack.in; + int ret =3D qjack_client_init(&ji->c); if (ret !=3D 0) { return ret; @@ -568,23 +579,25 @@ static void qjack_client_fini(QJackClient *c) static void qjack_fini_out(HWVoiceOut *hw) { QJackOut *jo =3D (QJackOut *)hw; - jo->c.finished =3D true; qjack_client_fini(&jo->c); } =20 static void qjack_fini_in(HWVoiceIn *hw) { QJackIn *ji =3D (QJackIn *)hw; - ji->c.finished =3D true; qjack_client_fini(&ji->c); } =20 static void qjack_enable_out(HWVoiceOut *hw, bool enable) { + QJackOut *jo =3D (QJackOut *)hw; + jo->c.enabled =3D enable; } =20 static void qjack_enable_in(HWVoiceIn *hw, bool enable) { + QJackIn *ji =3D (QJackIn *)hw; + ji->c.enabled =3D enable; } =20 static int qjack_thread_creator(jack_native_thread_t *thread, --=20 2.20.1