From 62869e40af779b3dfca23db6dbd486437ce921e1 Mon Sep 17 00:00:00 2001 From: Cuda-Chen Date: Sat, 2 Nov 2024 11:42:40 +0800 Subject: [PATCH] Set response length in pcm_* --- virtio-snd.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/virtio-snd.c b/virtio-snd.c index 608ee46..d52bc7e 100644 --- a/virtio-snd.c +++ b/virtio-snd.c @@ -382,7 +382,8 @@ static void virtio_snd_read_chmap_info_handler( } static void virtio_snd_read_pcm_set_params(struct virtq_desc *vq_desc, - const virtio_snd_query_info_t *query) + const virtio_snd_query_info_t *query, + uint32_t *plen) { virtio_snd_pcm_set_params_t *request = query; uint32_t id = request->hdr.stream_id; @@ -407,11 +408,13 @@ static void virtio_snd_read_pcm_set_params(struct virtq_desc *vq_desc, vsnd_props[id].pp.rate = request->rate; vsnd_props[id].pp.padding = request->padding; + *plen = 0; fprintf(stderr, "virtio_snd_read_pcm_set_params\n"); } static void virtio_snd_read_pcm_prepare(struct virtq_desc *vq_desc, - const virtio_snd_query_info_t *query) + const virtio_snd_query_info_t *query, + uint32_t *plen) { virtio_snd_pcm_hdr_t *request = query; uint32_t stream_id = request->stream_id; @@ -440,11 +443,13 @@ static void virtio_snd_read_pcm_prepare(struct virtq_desc *vq_desc, v.stream_id = 0; pthread_mutex_unlock(&virtio_snd_mutex); + *plen = 0; fprintf(stderr, "virtio_snd_read_pcm_prepare\n"); } static void virtio_snd_read_pcm_start(struct virtq_desc *vq_desc, - const virtio_snd_query_info_t *query) + const virtio_snd_query_info_t *query, + uint32_t *plen) { virtio_snd_pcm_hdr_t *request = query; uint32_t stream_id = request->stream_id; @@ -464,11 +469,13 @@ static void virtio_snd_read_pcm_start(struct virtq_desc *vq_desc, v.guest_playing = true; pthread_mutex_unlock(&virtio_snd_mutex); + *plen = 0; fprintf(stderr, "virtio_snd_read_pcm_start\n"); } static void virtio_snd_read_pcm_stop(struct virtq_desc *vq_desc, - const virtio_snd_query_info_t *query) + const virtio_snd_query_info_t *query, + uint32_t *plen) { virtio_snd_pcm_hdr_t *request = query; uint32_t stream_id = request->stream_id; @@ -487,11 +494,13 @@ static void virtio_snd_read_pcm_stop(struct virtq_desc *vq_desc, v.guest_playing = false; pthread_mutex_lock(&virtio_snd_mutex); + *plen = 0; fprintf(stderr, "virtio_snd_read_pcm_stop\n"); } static void virtio_snd_read_pcm_release(struct virtq_desc *vq_desc, - const virtio_snd_query_info_t *query) + const virtio_snd_query_info_t *query, + uint32_t *plen) { virtio_snd_pcm_hdr_t *request = query; uint32_t stream_id = request->stream_id; @@ -513,6 +522,7 @@ static void virtio_snd_read_pcm_release(struct virtq_desc *vq_desc, CNFAClose(vsnd_props[stream_id].audio_host); free(vsnd_props[stream_id].buf); + *plen = 0; fprintf(stderr, "virtio_snd_read_pcm_release\n"); } @@ -624,19 +634,19 @@ static int virtio_snd_desc_handler(virtio_snd_state_t *vsnd, virtio_snd_read_chmap_info_handler(info, query, plen); break; case VIRTIO_SND_R_PCM_SET_PARAMS: - virtio_snd_read_pcm_set_params(vq_desc, query); + virtio_snd_read_pcm_set_params(vq_desc, query, plen); break; case VIRTIO_SND_R_PCM_PREPARE: - virtio_snd_read_pcm_prepare(vq_desc, query); + virtio_snd_read_pcm_prepare(vq_desc, query, plen); break; case VIRTIO_SND_R_PCM_RELEASE: - virtio_snd_read_pcm_release(vq_desc, query); + virtio_snd_read_pcm_release(vq_desc, query, plen); break; case VIRTIO_SND_R_PCM_START: - virtio_snd_read_pcm_start(vq_desc, query); + virtio_snd_read_pcm_start(vq_desc, query, plen); break; case VIRTIO_SND_R_PCM_STOP: - virtio_snd_read_pcm_stop(vq_desc, query); + virtio_snd_read_pcm_stop(vq_desc, query, plen); break; default: fprintf(stderr, "%d: unsupported virtio-snd operation!\n", type);