Added handlers for VIRTIO_SND_PCM_START and VIRTIO_SND_PCM_STOP. Signed-off-by: Shreyansh Chouhan <chouhan.shreyansh2...@gmail.com> --- hw/audio/virtio-snd.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index b74c9e4a1f..1b3e1f75f4 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -828,6 +828,36 @@ static uint32_t virtio_snd_handle_pcm_prepare(VirtIOSound *s, return sz; } +/* + * Handles VIRTIO_SND_R_PCM_START. + * The function writes the response to the virtqueue element. + * Returns the used size in bytes. + * + * @s: VirtIOSound card + * @elem: The request element from control queue + */ +static uint32_t virtio_snd_handle_pcm_start_stop(VirtIOSound *s, + VirtQueueElement *elem, + bool start) +{ + virtio_snd_pcm_hdr req; + size_t sz; + + sz = iov_to_buf(elem->out_sg, elem->out_num, 0, &req, sizeof(req)); + assert(sz == sizeof(virtio_snd_pcm_hdr)); + + virtio_snd_hdr resp; + resp.code = VIRTIO_SND_S_OK; + + virtio_snd_pcm_stream *st = virtio_snd_pcm_get_stream(s, req.stream_id); + if (st->direction == VIRTIO_SND_D_OUTPUT) + AUD_set_active_out(st->voice.out, start); + + sz = iov_from_buf(elem->in_sg, elem->in_num, 0, &resp, sizeof(resp)); + assert(sz == sizeof(virtio_snd_hdr)); + return sz; +} + /* The control queue handler. Pops an element from the control virtqueue, * checks the header and performs the requested action. Finally marks the * element as used. @@ -882,9 +912,10 @@ static void virtio_snd_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) sz = virtio_snd_handle_pcm_prepare(s, elem); goto done; } else if (ctrl.code == VIRTIO_SND_R_PCM_START) { - virtio_snd_log("VIRTIO_SND_R_PCM_START"); + sz = virtio_snd_handle_pcm_start_stop(s, elem, true); + goto done; } else if (ctrl.code == VIRTIO_SND_R_PCM_STOP) { - virtio_snd_log("VIRTIO_SND_R_PCM_STOP"); + sz = virtio_snd_handle_pcm_start_stop(s, elem, false); } else if (ctrl.code == VIRTIO_SND_R_PCM_RELEASE) { virtio_snd_log("VIRTIO_SND_R_PCM_RELEASE"); } else if (ctrl.code == VIRTIO_SND_R_CHMAP_INFO) { -- 2.31.1