From: Volker Rümelin <[email protected]> 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 <[email protected]> [AM: there were too many conflicts, I did `git checkout --ours -- <.>` and then reimplemented the patch idea /AM] Signed-off-by: Alexander Mikhalitsyn <[email protected]> Reviewed-by: Marc-André Lureau <[email protected]> --- v4: - minor formatting change in qemu_log_mask() - moved the trace_*() calls at the start of the function (as suggested by Manos Pitsidianakis) v3: - resurrected error_report(..) as suggested by Marc-André Lureau --- hw/audio/virtio-snd.c | 58 ++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index d51fc386593..d3fc4c30877 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -520,7 +520,43 @@ 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; + + 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) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Invalid stream id: %"PRIu32 "\n", + __func__, stream_id); + return cpu_to_le32(VIRTIO_SND_S_BAD_MSG); + } + + stream->active = start; + if (stream->info.direction == VIRTIO_SND_D_OUTPUT) { + audio_be_set_active_out(s->audio_be, stream->voice.out, start); + } else { + audio_be_set_active_in(s->audio_be, 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 @@ -530,7 +566,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, @@ -548,24 +583,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) { - audio_be_set_active_out(s->audio_be, stream->voice.out, start); - } else { - audio_be_set_active_in(s->audio_be, 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.47.3
