From 9e06b1d03c589623498bb904c42802b42b7dcdec Mon Sep 17 00:00:00 2001 From: Cuda-Chen Date: Thu, 2 Jan 2025 17:15:58 +0800 Subject: [PATCH] Code tidy --- virtio-snd.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/virtio-snd.c b/virtio-snd.c index cba970c..4f3d39e 100644 --- a/virtio-snd.c +++ b/virtio-snd.c @@ -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) { @@ -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");