From nobody Tue Nov 26 22:11:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704400513213243.76982600026133; Thu, 4 Jan 2024 12:35:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLUQF-0003Cs-B9; Thu, 04 Jan 2024 15:34:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLUQD-0003Bp-4L for qemu-devel@nongnu.org; Thu, 04 Jan 2024 15:34:33 -0500 Received: from mailout04.t-online.de ([194.25.134.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLUQA-0004JY-7U for qemu-devel@nongnu.org; Thu, 04 Jan 2024 15:34:32 -0500 Received: from fwd78.aul.t-online.de (fwd78.aul.t-online.de [10.223.144.104]) by mailout04.t-online.de (Postfix) with SMTP id 098A0E204; Thu, 4 Jan 2024 21:34:28 +0100 (CET) Received: from linpower.localnet ([93.236.158.98]) by fwd78.t-online.de with (TLSv1.3:TLS_AES_256_GCM_SHA384 encrypted) esmtp id 1rLUQ7-1miNsH0; Thu, 4 Jan 2024 21:34:27 +0100 Received: by linpower.localnet (Postfix, from userid 1000) id 49A9720024D; Thu, 4 Jan 2024 21:34:22 +0100 (CET) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Gerd Hoffmann , Manos Pitsidianakis , "Michael S. Tsirkin" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Cc: qemu-devel@nongnu.org Subject: [PATCH 03/10] hw/audio/virtio-sound: split out virtio_snd_pcm_start_stop() Date: Thu, 4 Jan 2024 21:34:15 +0100 Message-Id: <20240104203422.12308-3-vr_qemu@t-online.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TOI-EXPURGATEID: 150726::1704400467-5CF5D979-18D812F4/0/0 CLEAN NORMAL X-TOI-MSGID: 8a4e1b48-eb5e-4ae9-8f28-a2ef18b5e391 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: pass client-ip=194.25.134.18; envelope-from=volker.ruemelin@t-online.de; helo=mailout04.t-online.de 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.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1704400513968100001 Split out virtio_snd_pcm_start_stop(). This is a preparation for the next patch so that it doesn't become too big. Signed-off-by: Volker R=C3=BCmelin Reviewed-by: Marc-Andr=C3=A9 Lureau --- hw/audio/trace-events | 3 ++- hw/audio/virtio-snd.c | 57 ++++++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/hw/audio/trace-events b/hw/audio/trace-events index b1870ff224..7554bfcc60 100644 --- a/hw/audio/trace-events +++ b/hw/audio/trace-events @@ -50,7 +50,8 @@ virtio_snd_unrealize(void *snd) "snd %p: unrealize" virtio_snd_handle_pcm_set_params(uint32_t stream) "VIRTIO_SND_PCM_SET_PARA= MS called for stream %"PRIu32 virtio_snd_handle_ctrl(void *vdev, void *vq) "snd %p: handle ctrl event fo= r queue %p" virtio_snd_handle_pcm_info(uint32_t stream) "VIRTIO_SND_R_PCM_INFO called = for stream %"PRIu32 -virtio_snd_handle_pcm_start_stop(const char *code, uint32_t stream) "%s ca= lled for stream %"PRIu32 +virtio_snd_handle_pcm_start(uint32_t stream) "VIRTIO_SND_R_PCM_START calle= d for stream %"PRIu32 +virtio_snd_handle_pcm_stop(uint32_t stream) "VIRTIO_SND_R_PCM_STOP called = for stream %"PRIu32 virtio_snd_handle_pcm_release(uint32_t stream) "VIRTIO_SND_PCM_RELEASE cal= led for stream %"PRIu32 virtio_snd_handle_code(uint32_t val, const char *code) "ctrl code msg val = =3D %"PRIu32" =3D=3D %s" virtio_snd_handle_chmap_info(void) "VIRTIO_SND_CHMAP_INFO called" diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index 36b1bb502c..040bc32ebe 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -534,7 +534,42 @@ static void virtio_snd_handle_pcm_prepare(VirtIOSound = *s, } =20 /* - * Handles VIRTIO_SND_R_PCM_START. + * Starts/Stops a VirtIOSound card stream. + * Returns the response status code. (VIRTIO_SND_S_*). + * + * @s: VirtIOSound device + * @stream_id: stream id + * @start: whether to start or stop the stream + */ +static uint32_t virtio_snd_pcm_start_stop(VirtIOSound *s, + uint32_t stream_id, + bool start) +{ + VirtIOSoundPCMStream *stream; + + stream =3D virtio_snd_pcm_get_stream(s, stream_id); + if (!stream) { + return cpu_to_le32(VIRTIO_SND_S_BAD_MSG); + } + + if (start) { + trace_virtio_snd_handle_pcm_start(stream_id); + } else { + trace_virtio_snd_handle_pcm_stop(stream_id); + } + + stream->active =3D start; + if (stream->info.direction =3D=3D VIRTIO_SND_D_OUTPUT) { + AUD_set_active_out(stream->voice.out, start); + } else { + AUD_set_active_in(stream->voice.in, start); + } + + return cpu_to_le32(VIRTIO_SND_S_OK); +} + +/* + * Handles VIRTIO_SND_R_PCM_START and VIRTIO_SND_R_PCM_STOP. * * @s: VirtIOSound device * @cmd: The request command queue element from VirtIOSound cmdq field @@ -544,7 +579,6 @@ static void virtio_snd_handle_pcm_start_stop(VirtIOSoun= d *s, virtio_snd_ctrl_command *cmd, bool start) { - VirtIOSoundPCMStream *stream; virtio_snd_pcm_hdr req; uint32_t stream_id; size_t msg_sz =3D iov_to_buf(cmd->elem->out_sg, @@ -562,24 +596,7 @@ static void virtio_snd_handle_pcm_start_stop(VirtIOSou= nd *s, } =20 stream_id =3D le32_to_cpu(req.stream_id); - cmd->resp.code =3D cpu_to_le32(VIRTIO_SND_S_OK); - trace_virtio_snd_handle_pcm_start_stop(start ? "VIRTIO_SND_R_PCM_START= " : - "VIRTIO_SND_R_PCM_STOP", stream_id); - - stream =3D virtio_snd_pcm_get_stream(s, stream_id); - if (stream) { - stream->active =3D start; - if (stream->info.direction =3D=3D VIRTIO_SND_D_OUTPUT) { - AUD_set_active_out(stream->voice.out, start); - } else { - AUD_set_active_in(stream->voice.in, start); - } - } else { - error_report("Invalid stream id: %"PRIu32, stream_id); - cmd->resp.code =3D cpu_to_le32(VIRTIO_SND_S_BAD_MSG); - return; - } - stream->active =3D start; + cmd->resp.code =3D virtio_snd_pcm_start_stop(s, stream_id, start); } =20 /* --=20 2.35.3