diff --git a/virtio-snd.c b/virtio-snd.c index dfbbb3c..f7bd8d9 100644 --- a/virtio-snd.c +++ b/virtio-snd.c @@ -267,31 +267,34 @@ static void virtio_snd_read_pcm_info_handler( struct virtq_desc *vq_desc, const virtio_snd_query_info_t *query) { - /* TODO: should read the config */ + uint32_t cnt = query->count; virtio_snd_pcm_info_t *info = - (virtio_snd_pcm_info_t *) ((uintptr_t) vq_desc[2].addr); - for (uint32_t i = 0; i < query->count; i++) { - info[0].features = 0; - info[0].formats = (1 << VIRTIO_SND_PCM_FMT_S16); - info[0].rates = (1 << VIRTIO_SND_PCM_RATE_44100); - info[0].direction = VIRTIO_SND_D_OUTPUT; - info[0].channels_min = 1; - info[0].channels_max = 1; + (virtio_snd_pcm_info_t *) malloc(sizeof(virtio_snd_pcm_info_t) * cnt); + for (uint32_t i = 0; i < cnt; i++) { + info[i].features = 0; + info[i].formats = (1 << VIRTIO_SND_PCM_FMT_S16); + info[i].rates = (1 << VIRTIO_SND_PCM_RATE_44100); + info[i].direction = VIRTIO_SND_D_OUTPUT; + info[i].channels_min = 1; + info[i].channels_max = 1; memset(&info[i].padding, 0, sizeof(info[i].padding)); } + vq_desc[2].addr = (uintptr_t) info; } static void virtio_snd_read_chmap_info_handler( struct virtq_desc *vq_desc, const virtio_snd_query_info_t *query) { - virtio_snd_chmap_info_t *info = - (virtio_snd_chmap_info_t *) ((uintptr_t) vq_desc[2].addr); + uint32_t cnt = query->count; + virtio_snd_chmap_info_t *info = (virtio_snd_chmap_info_t *) malloc( + sizeof(virtio_snd_chmap_info_t) * cnt); for (uint32_t i = 0; i < query->count; i++) { info[i].direction = VIRTIO_SND_D_OUTPUT; info[i].channels = 1; info[i].positions[0] = VIRTIO_SND_CHMAP_MONO; } + vq_desc[2].addr = (uintptr_t) info; } static void virtio_snd_read_pcm_set_params(struct virtq_desc *vq_desc,