[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 03/10] hw/audio/virtio-sound: split out virtio_snd_pcm_start_stop
From: |
Volker Rümelin |
Subject: |
[PATCH 03/10] hw/audio/virtio-sound: split out virtio_snd_pcm_start_stop() |
Date: |
Thu, 4 Jan 2024 21:34:15 +0100 |
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ümelin <vr_qemu@t-online.de>
---
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_PARAMS
called for stream %"PRIu32
virtio_snd_handle_ctrl(void *vdev, void *vq) "snd %p: handle ctrl event for
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 called
for stream %"PRIu32
+virtio_snd_handle_pcm_start(uint32_t stream) "VIRTIO_SND_R_PCM_START called
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 called
for stream %"PRIu32
virtio_snd_handle_code(uint32_t val, const char *code) "ctrl code msg val =
%"PRIu32" == %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,
}
/*
- * 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 = 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 = start;
+ if (stream->info.direction == 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(VirtIOSound *s,
virtio_snd_ctrl_command *cmd,
bool start)
{
- VirtIOSoundPCMStream *stream;
virtio_snd_pcm_hdr req;
uint32_t stream_id;
size_t msg_sz = iov_to_buf(cmd->elem->out_sg,
@@ -562,24 +596,7 @@ static void virtio_snd_handle_pcm_start_stop(VirtIOSound
*s,
}
stream_id = le32_to_cpu(req.stream_id);
- cmd->resp.code = 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 = virtio_snd_pcm_get_stream(s, stream_id);
- if (stream) {
- stream->active = start;
- if (stream->info.direction == 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 = cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
- return;
- }
- stream->active = start;
+ cmd->resp.code = virtio_snd_pcm_start_stop(s, stream_id, start);
}
/*
--
2.35.3
- [PATCH 00/10] virtio-sound migration part 1, Volker Rümelin, 2024/01/04
- [PATCH 01/10] hw/audio/virtio-sound: remove command and stream mutexes, Volker Rümelin, 2024/01/04
- [PATCH 03/10] hw/audio/virtio-sound: split out virtio_snd_pcm_start_stop(),
Volker Rümelin <=
- [PATCH 02/10] hw/audio/virtio-sound: allocate all streams in advance, Volker Rümelin, 2024/01/04
- [PATCH 06/10] hw/audio/virtio-sound: introduce virtio_snd_pcm_open(), Volker Rümelin, 2024/01/04
- [PATCH 05/10] hw/audio/virtio-sound: return correct command response size, Volker Rümelin, 2024/01/04
- [PATCH 04/10] hw/audio/virtio-sound: add stream state variable, Volker Rümelin, 2024/01/04
- [PATCH 07/10] hw/audio/virtio-sound: introduce virtio_snd_set_active(), Volker Rümelin, 2024/01/04