Skip to content

Commit 5da0ff3

Browse files
committed
Add buffer queue prototype
1 parent 070ea84 commit 5da0ff3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

virtio-snd.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ typedef struct {
315315
virtio_snd_ring_buffer_t ring;
316316
// PCM frame doubly-ended queue
317317
vsnd_buf_queue_node_t buf;
318+
struct list_head buf_queue_head;
318319

319320
// playback control
320321
vsnd_stream_sel_t v;
@@ -560,6 +561,7 @@ static void virtio_snd_read_pcm_prepare(const virtio_snd_pcm_hdr_t *query,
560561
pthread_mutex_init(&props->ring.lock, NULL);
561562
pthread_cond_init(&props->ring.readable, NULL);
562563
pthread_cond_init(&props->ring.writable, NULL);
564+
INIT_LIST_HEAD(&props->buf_queue_head);
563565

564566
*plen = 0;
565567
fprintf(stderr, "virtio_snd_read_pcm_prepare\n");
@@ -639,6 +641,13 @@ static void virtio_snd_read_pcm_release(const virtio_snd_pcm_hdr_t *query,
639641
pthread_mutex_destroy(&props->ring.lock);
640642
pthread_cond_destroy(&props->ring.readable);
641643
pthread_cond_destroy(&props->ring.writable);
644+
/* Tear down the PCM buffer queue */
645+
vsnd_buf_queue_node_t *tmp = NULL;
646+
vsnd_buf_queue_node_t *node;
647+
list_for_each_entry_safe (node, tmp, &props->buf_queue_head, q) {
648+
list_del(&node->q);
649+
free(node);
650+
}
642651

643652
CNFAClose(props->audio_host);
644653
fprintf(stderr, "pass CNFAclose\n");
@@ -896,6 +905,12 @@ static void __virtio_snd_frame_enqueue(void *payload,
896905
/* Update prod_tail */
897906
props->ring.prod.tail = prod_next;
898907

908+
/* Add to queue */
909+
vsnd_buf_queue_node_t *node = malloc(sizeof(*node));
910+
node->addr = (uint32_t) payload;
911+
node->len = n;
912+
list_push(&node->q, &props->buf_queue_head);
913+
899914
uint32_t period_bytes = props->pp.period_bytes;
900915
if (prod_next - cons_tail >= period_bytes) {
901916
fprintf(stderr,

0 commit comments

Comments
 (0)