From 8658fcfc27ce3e26f146b4905511d87715de52ab Mon Sep 17 00:00:00 2001 From: Cuda-Chen Date: Sun, 29 Dec 2024 15:16:16 +0800 Subject: [PATCH] Debug --- virtio-snd.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/virtio-snd.c b/virtio-snd.c index c6bc4ca..489b5e7 100644 --- a/virtio-snd.c +++ b/virtio-snd.c @@ -622,7 +622,7 @@ static void __virtio_snd_frame_dequeue(short *out, pthread_mutex_lock(&props->ring.lock); while (props->ring.buf_ev_notity < 1) { - fprintf(stderr, "---wair in deque---\n"); + fprintf(stderr, "---wait in deque---\n"); pthread_cond_wait(&props->ring.readable, &props->ring.lock); } @@ -647,9 +647,9 @@ static void __virtio_snd_frame_dequeue(short *out, uint32_t size = props->ring.cons.size; uint32_t idx = cons_head % size; fprintf(stderr, - "cons_head %" PRIu32 " cons_next %" PRIu32 " mask %" PRIu32 - " idx %" PRIu32 "\n", - cons_head, cons_next, mask, idx); + "cons_head %" PRIu32 " cons_next %" PRIu32 " prod_tail %" PRIu32 + " mask %" PRIu32 " idx %" PRIu32 "\n", + cons_head, cons_next, prod_tail, mask, idx); if (idx + n < size) { memcpy(out, props->ring.buffer + idx, n); } else { @@ -857,8 +857,13 @@ static void __virtio_snd_frame_enqueue(void *payload, /* Update prod_tail */ props->ring.prod.tail = prod_next; - props->ring.buf_ev_notity++; - pthread_cond_signal(&props->ring.readable); + uint32_t buffer_bytes = props->pp.buffer_bytes; + if (mask + cons_tail - prod_next >= buffer_bytes) { + fprintf(stderr, "buffer ready for %" PRIu32 "\n", + mask + cons_tail - prod_next); + props->ring.buf_ev_notity++; + pthread_cond_signal(&props->ring.readable); + } pthread_mutex_unlock(&props->ring.lock); }