Skip to content

Commit e2f3b40

Browse files
committed
Release CNFA driver in pcm_release
1 parent 0b5da33 commit e2f3b40

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

virtio-snd.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ static void virtio_snd_read_pcm_prepare(struct virtq_desc *vq_desc,
378378
{
379379
virtio_snd_pcm_hdr_t *request = query;
380380
uint32_t stream_id = request->stream_id;
381+
vsnd_props[stream_id].pp.hdr.hdr.code = VIRTIO_SND_R_PCM_PREPARE;
381382
vsnd_props[stream_id].audio_host = CNFAInit(
382383
NULL, "semu-virtio-snd", virtio_snd_cb, 44100, 0, 1, 0,
383384
vsnd_props[stream_id].pp.buffer_bytes, NULL, NULL, &guest_playing);
@@ -416,7 +417,14 @@ static void virtio_snd_read_pcm_stop(struct virtq_desc *vq_desc,
416417
static void virtio_snd_read_pcm_release(struct virtq_desc *vq_desc,
417418
const virtio_snd_query_info_t *query)
418419
{
419-
/* TODO: let application to set stream_id at will */
420+
/* Control the callback to stop playing */
421+
/* TODO: add lock to avoid race condition */
422+
guest_playing = false;
423+
424+
virtio_snd_pcm_hdr_t *request = query;
425+
uint32_t stream_id = request->stream_id;
426+
vsnd_props[stream_id].pp.hdr.hdr.code = VIRTIO_SND_R_PCM_RELEASE;
427+
CNFAClose(vsnd_props[stream_id].audio_host);
420428

421429
fprintf(stderr, "virtio_snd_read_pcm_release\n");
422430
}

0 commit comments

Comments
 (0)