Skip to content

Commit

Permalink
Disable PCM output debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuda-Chen committed Jan 19, 2025
1 parent 038b347 commit f08721d
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions virtio-snd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <math.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#define CNFA_IMPLEMENTATION
#include "CNFA_sf.h"

Expand All @@ -13,6 +13,8 @@
#include "utils.h"
#include "virtio.h"

#define WRITEOUT 0

#define VSND_DEV_CNT_MAX 1

#define VSND_QUEUE_NUM_MAX 1024
Expand All @@ -21,7 +23,9 @@
#define PRIV(x) ((virtio_snd_config_t *) x->priv)

#define VSND_CNFA_FRAME_SZ 2
#if WRITEOUT
FILE *outfile;
#endif
enum {
VSND_QUEUE_CTRL = 0,
VSND_QUEUE_EVT = 1,
Expand Down Expand Up @@ -562,7 +566,9 @@ static void virtio_snd_read_pcm_prepare(const virtio_snd_pcm_hdr_t *query,
pthread_cond_init(&props->ring.readable, NULL);
pthread_cond_init(&props->ring.writable, NULL);
INIT_LIST_HEAD(&props->buf_queue_head);
#if WRITEOUT
outfile = fopen("out_enque.bin", "wb");
#endif

*plen = 0;
fprintf(stderr, "virtio_snd_read_pcm_prepare\n");
Expand Down Expand Up @@ -636,7 +642,9 @@ static void virtio_snd_read_pcm_release(const virtio_snd_pcm_hdr_t *query,
}

props->pp.hdr.hdr.code = VIRTIO_SND_R_PCM_RELEASE;
#if WRITEOUT
fclose(outfile);
#endif
/* Tear down the PCM ring buffer. */
free(props->ring.buffer);
pthread_mutex_destroy(&props->ring.lock);
Expand Down Expand Up @@ -714,17 +722,14 @@ static void __virtio_snd_frame_dequeue(short *out,
props->ring.cons.tail = cons_next;

uint32_t len = 0;
while (
!list_empty(&props->buf_queue_head) &&
len < n) {
vsnd_buf_queue_node_t *node =
list_first_entry(&props->buf_queue_head, vsnd_buf_queue_node_t, q);
list_del(&node->q);
memcpy(out, node->addr, node->len);
len += node->len;
while (!list_empty(&props->buf_queue_head) && len < n) {
vsnd_buf_queue_node_t *node =
list_first_entry(&props->buf_queue_head, vsnd_buf_queue_node_t, q);
list_del(&node->q);
memcpy(out, node->addr, node->len);
len += node->len;
}

finally:
props->ring.buf_ev_notity--;
pthread_cond_signal(&props->ring.writable);
pthread_mutex_unlock(&props->ring.lock);
Expand Down Expand Up @@ -925,7 +930,9 @@ static void __virtio_snd_frame_enqueue(void *payload,
node->addr = payload;
node->len = n;
list_push(&node->q, &props->buf_queue_head);
#if WRITEOUT
fwrite(node->addr, sizeof(void), node->len, outfile);
#endif

uint32_t period_bytes = props->pp.period_bytes;
if (prod_next - cons_tail >= period_bytes) {
Expand Down

0 comments on commit f08721d

Please sign in to comment.