qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH 20/27] virtio-snd: Add VIRITO_SND_R_PCM_START handler


From: Shreyansh Chouhan
Subject: [RFC PATCH 20/27] virtio-snd: Add VIRITO_SND_R_PCM_START handler
Date: Thu, 29 Apr 2021 17:34:38 +0530

Signed-off-by: Shreyansh Chouhan <chouhan.shreyansh2702@gmail.com>
---
 hw/audio/virtio-snd.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index e5042caf9c..65104baba8 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -732,6 +732,34 @@ 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(VirtIOSound *s,
+                                            VirtQueueElement *elem)
+{
+    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);
+    AUD_set_active_out(st->voice.out, true);
+
+    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.
@@ -786,7 +814,8 @@ 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(s, elem);
+            goto done;
         } else if (ctrl.code == VIRTIO_SND_R_PCM_STOP) {
             virtio_snd_log("VIRTIO_SND_R_PCM_STOP");
         } else if (ctrl.code == VIRTIO_SND_R_PCM_RELEASE) {
-- 
2.25.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]