|
2 | 2 | #include <math.h> |
3 | 3 | #include <pthread.h> |
4 | 4 | #include <stdio.h> |
5 | | -#include <string.h> |
6 | 5 | #include <stdlib.h> |
| 6 | +#include <string.h> |
7 | 7 | #define CNFA_IMPLEMENTATION |
8 | 8 | #include "CNFA_sf.h" |
9 | 9 |
|
|
13 | 13 | #include "utils.h" |
14 | 14 | #include "virtio.h" |
15 | 15 |
|
| 16 | +#define WRITEOUT 0 |
| 17 | + |
16 | 18 | #define VSND_DEV_CNT_MAX 1 |
17 | 19 |
|
18 | 20 | #define VSND_QUEUE_NUM_MAX 1024 |
|
21 | 23 | #define PRIV(x) ((virtio_snd_config_t *) x->priv) |
22 | 24 |
|
23 | 25 | #define VSND_CNFA_FRAME_SZ 2 |
| 26 | +#if WRITEOUT |
24 | 27 | FILE *outfile; |
| 28 | +#endif |
25 | 29 | enum { |
26 | 30 | VSND_QUEUE_CTRL = 0, |
27 | 31 | VSND_QUEUE_EVT = 1, |
@@ -562,7 +566,9 @@ static void virtio_snd_read_pcm_prepare(const virtio_snd_pcm_hdr_t *query, |
562 | 566 | pthread_cond_init(&props->ring.readable, NULL); |
563 | 567 | pthread_cond_init(&props->ring.writable, NULL); |
564 | 568 | INIT_LIST_HEAD(&props->buf_queue_head); |
| 569 | +#if WRITEOUT |
565 | 570 | outfile = fopen("out_enque.bin", "wb"); |
| 571 | +#endif |
566 | 572 |
|
567 | 573 | *plen = 0; |
568 | 574 | fprintf(stderr, "virtio_snd_read_pcm_prepare\n"); |
@@ -636,7 +642,9 @@ static void virtio_snd_read_pcm_release(const virtio_snd_pcm_hdr_t *query, |
636 | 642 | } |
637 | 643 |
|
638 | 644 | props->pp.hdr.hdr.code = VIRTIO_SND_R_PCM_RELEASE; |
| 645 | +#if WRITEOUT |
639 | 646 | fclose(outfile); |
| 647 | +#endif |
640 | 648 | /* Tear down the PCM ring buffer. */ |
641 | 649 | free(props->ring.buffer); |
642 | 650 | pthread_mutex_destroy(&props->ring.lock); |
@@ -714,17 +722,14 @@ static void __virtio_snd_frame_dequeue(short *out, |
714 | 722 | props->ring.cons.tail = cons_next; |
715 | 723 |
|
716 | 724 | uint32_t len = 0; |
717 | | - while ( |
718 | | - !list_empty(&props->buf_queue_head) && |
719 | | - len < n) { |
720 | | - vsnd_buf_queue_node_t *node = |
721 | | - list_first_entry(&props->buf_queue_head, vsnd_buf_queue_node_t, q); |
722 | | - list_del(&node->q); |
723 | | - memcpy(out, node->addr, node->len); |
724 | | - len += node->len; |
| 725 | + while (!list_empty(&props->buf_queue_head) && len < n) { |
| 726 | + vsnd_buf_queue_node_t *node = |
| 727 | + list_first_entry(&props->buf_queue_head, vsnd_buf_queue_node_t, q); |
| 728 | + list_del(&node->q); |
| 729 | + memcpy(out, node->addr, node->len); |
| 730 | + len += node->len; |
725 | 731 | } |
726 | 732 |
|
727 | | -finally: |
728 | 733 | props->ring.buf_ev_notity--; |
729 | 734 | pthread_cond_signal(&props->ring.writable); |
730 | 735 | pthread_mutex_unlock(&props->ring.lock); |
@@ -925,7 +930,9 @@ static void __virtio_snd_frame_enqueue(void *payload, |
925 | 930 | node->addr = payload; |
926 | 931 | node->len = n; |
927 | 932 | list_push(&node->q, &props->buf_queue_head); |
| 933 | +#if WRITEOUT |
928 | 934 | fwrite(node->addr, sizeof(void), node->len, outfile); |
| 935 | +#endif |
929 | 936 |
|
930 | 937 | uint32_t period_bytes = props->pp.period_bytes; |
931 | 938 | if (prod_next - cons_tail >= period_bytes) { |
|
0 commit comments