Skip to content

Commit

Permalink
Code tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuda-Chen committed Jan 2, 2025
1 parent 111dc23 commit 9e06b1d
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions virtio-snd.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ static void virtio_snd_read_pcm_prepare(const virtio_snd_pcm_hdr_t *query,
{
const virtio_snd_pcm_hdr_t *request = query;
uint32_t stream_id = request->stream_id;
uint32_t code = vsnd_props[stream_id].pp.hdr.hdr.code;
virtio_snd_prop_t *props = &vsnd_props[stream_id];
uint32_t code = props->pp.hdr.hdr.code;
if (code != VIRTIO_SND_R_PCM_RELEASE &&
code != VIRTIO_SND_R_PCM_SET_PARAMS &&
code != VIRTIO_SND_R_PCM_PREPARE) {
Expand All @@ -505,30 +506,29 @@ static void virtio_snd_read_pcm_prepare(const virtio_snd_pcm_hdr_t *query,
v.guest_playing = 0;
v.stream_id = stream_id;
// pthread_mutex_unlock(&virtio_snd_mutex);
vsnd_props[stream_id].pp.hdr.hdr.code = VIRTIO_SND_R_PCM_PREPARE;
uint32_t period_bytes = vsnd_props[stream_id].pp.period_bytes;
props->pp.hdr.hdr.code = VIRTIO_SND_R_PCM_PREPARE;
uint32_t period_bytes = props->pp.period_bytes;

/* The buffer size in frames when calling CNFAInit()
* is actually period size (i.e., period size then divide
* the length of frame). */
/* CNFA only accept frame with signed 16-bit data in little-endian. */
vsnd_props[stream_id].audio_host =
CNFAInit(NULL, "semu-virtio-snd", virtio_snd_cb,
pcm_rate_tbl[vsnd_props[stream_id].pp.rate], 0, vsnd_props[stream_id].pp.channels, 0,
period_bytes / sizeof(short), NULL, NULL, &v);
props->audio_host = CNFAInit(
NULL, "semu-virtio-snd", virtio_snd_cb, pcm_rate_tbl[props->pp.rate], 0,
props->pp.channels, 0, period_bytes / sizeof(short), NULL, NULL, &v);
uint32_t sz = period_bytes * 3;
vsnd_props[stream_id].ring.buffer = (void *) malloc(sizeof(void) * sz);
vsnd_props[stream_id].ring.prod.head = 0;
vsnd_props[stream_id].ring.prod.tail = 0;
vsnd_props[stream_id].ring.cons.head = 0;
vsnd_props[stream_id].ring.cons.tail = 0;
vsnd_props[stream_id].ring.prod.size = sz;
vsnd_props[stream_id].ring.cons.size = sz;
vsnd_props[stream_id].ring.prod.mask = sz - 1;
vsnd_props[stream_id].ring.cons.mask = sz - 1;
pthread_mutex_init(&vsnd_props[stream_id].ring.lock, NULL);
pthread_cond_init(&vsnd_props[stream_id].ring.readable, NULL);
pthread_cond_init(&vsnd_props[stream_id].ring.writable, NULL);
props->ring.buffer = (void *) malloc(sizeof(void) * sz);
props->ring.prod.head = 0;
props->ring.prod.tail = 0;
props->ring.cons.head = 0;
props->ring.cons.tail = 0;
props->ring.prod.size = sz;
props->ring.cons.size = sz;
props->ring.prod.mask = sz - 1;
props->ring.cons.mask = sz - 1;
pthread_mutex_init(&props->ring.lock, NULL);
pthread_cond_init(&props->ring.readable, NULL);
pthread_cond_init(&props->ring.writable, NULL);

*plen = 0;
fprintf(stderr, "virtio_snd_read_pcm_prepare\n");
Expand Down

0 comments on commit 9e06b1d

Please sign in to comment.