Skip to content

Commit 038b347

Browse files
committed
Get frames from queue in pcm_start state
1 parent 62a58cf commit 038b347

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

virtio-snd.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <pthread.h>
44
#include <stdio.h>
55
#include <string.h>
6-
6+
#include <stdlib.h>
77
#define CNFA_IMPLEMENTATION
88
#include "CNFA_sf.h"
99

@@ -21,7 +21,7 @@
2121
#define PRIV(x) ((virtio_snd_config_t *) x->priv)
2222

2323
#define VSND_CNFA_FRAME_SZ 2
24-
24+
FILE *outfile;
2525
enum {
2626
VSND_QUEUE_CTRL = 0,
2727
VSND_QUEUE_EVT = 1,
@@ -562,6 +562,7 @@ static void virtio_snd_read_pcm_prepare(const virtio_snd_pcm_hdr_t *query,
562562
pthread_cond_init(&props->ring.readable, NULL);
563563
pthread_cond_init(&props->ring.writable, NULL);
564564
INIT_LIST_HEAD(&props->buf_queue_head);
565+
outfile = fopen("out_enque.bin", "wb");
565566

566567
*plen = 0;
567568
fprintf(stderr, "virtio_snd_read_pcm_prepare\n");
@@ -635,7 +636,7 @@ static void virtio_snd_read_pcm_release(const virtio_snd_pcm_hdr_t *query,
635636
}
636637

637638
props->pp.hdr.hdr.code = VIRTIO_SND_R_PCM_RELEASE;
638-
639+
fclose(outfile);
639640
/* Tear down the PCM ring buffer. */
640641
free(props->ring.buffer);
641642
pthread_mutex_destroy(&props->ring.lock);
@@ -712,12 +713,16 @@ static void __virtio_snd_frame_dequeue(short *out,
712713

713714
props->ring.cons.tail = cons_next;
714715

715-
if (list_empty(&props->buf_queue_head))
716-
goto finally;
716+
uint32_t len = 0;
717+
while (
718+
!list_empty(&props->buf_queue_head) &&
719+
len < n) {
717720
vsnd_buf_queue_node_t *node =
718721
list_first_entry(&props->buf_queue_head, vsnd_buf_queue_node_t, q);
719722
list_del(&node->q);
720723
memcpy(out, node->addr, node->len);
724+
len += node->len;
725+
}
721726

722727
finally:
723728
props->ring.buf_ev_notity--;
@@ -920,6 +925,7 @@ static void __virtio_snd_frame_enqueue(void *payload,
920925
node->addr = payload;
921926
node->len = n;
922927
list_push(&node->q, &props->buf_queue_head);
928+
fwrite(node->addr, sizeof(void), node->len, outfile);
923929

924930
uint32_t period_bytes = props->pp.period_bytes;
925931
if (prod_next - cons_tail >= period_bytes) {

0 commit comments

Comments
 (0)