Skip to content

Commit 0b5da33

Browse files
committed
Initialize CNFA driver in pcm_prepare
1 parent d312e6f commit 0b5da33

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

virtio-snd.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,18 @@ static virtio_snd_config_t vsnd_configs[VSND_DEV_CNT_MAX];
237237
static virtio_snd_prop_t vsnd_props[VSND_DEV_CNT_MAX];
238238
static int vsnd_dev_cnt = 0;
239239

240-
//static struct CNFADriver *audio_host = NULL;
240+
// static struct CNFADriver *audio_host = NULL;
241241

242242
static bool guest_playing = false;
243243

244+
/* Forward declaration */
245+
static void virtio_snd_cb(struct CNFADriver *dev,
246+
short *out,
247+
short *in,
248+
int framesp,
249+
int framesr);
250+
251+
244252
static void virtio_snd_set_fail(virtio_snd_state_t *vsnd)
245253
{
246254
vsnd->Status |= VIRTIO_STATUS__DEVICE_NEEDS_RESET;
@@ -347,23 +355,12 @@ static void virtio_snd_read_chmap_info_handler(
347355
static void virtio_snd_read_pcm_set_params(struct virtq_desc *vq_desc,
348356
const virtio_snd_query_info_t *query)
349357
{
350-
#if 0
351358
/* TODO: detect current state of stream */
352-
/* TODO: let application to set each value at will */
353359
/* TODO: check the valiability of buffer_bytes, period_bytes, channel_min,
354360
* and channel_max */
355-
info->hdr.hdr.code = VIRTIO_SND_R_PCM_SET_PARAMS;
356-
info->hdr.stream_id = 0;
357-
info->buffer_bytes = 2048;
358-
info->period_bytes = 1024;
359-
info->features = 0;
360-
info->channels = 1;
361-
info->format = (1 << VIRTIO_SND_PCM_FMT_S16);
362-
info->rate = (1 << VIRTIO_SND_PCM_RATE_44100);
363-
info->padding = 0;
364-
#endif
361+
365362
virtio_snd_pcm_set_params_t *request = query;
366-
uint32_t id = request->hdr.stream_id;
363+
uint32_t id = request->hdr.stream_id;
367364
vsnd_props[id].pp.hdr.hdr.code = VIRTIO_SND_R_PCM_SET_PARAMS;
368365
vsnd_props[id].pp.buffer_bytes = request->buffer_bytes;
369366
vsnd_props[id].pp.period_bytes = request->period_bytes;
@@ -379,13 +376,16 @@ static void virtio_snd_read_pcm_set_params(struct virtq_desc *vq_desc,
379376
static void virtio_snd_read_pcm_prepare(struct virtq_desc *vq_desc,
380377
const virtio_snd_query_info_t *query)
381378
{
382-
/* TODO: let application to set stream_id at will */
379+
virtio_snd_pcm_hdr_t *request = query;
380+
uint32_t stream_id = request->stream_id;
381+
vsnd_props[stream_id].audio_host = CNFAInit(
382+
NULL, "semu-virtio-snd", virtio_snd_cb, 44100, 0, 1, 0,
383+
vsnd_props[stream_id].pp.buffer_bytes, NULL, NULL, &guest_playing);
383384

384385
/* Control the callback to prepare the buffer */
385386
/* TODO: add lock to avoid race condition */
386387
guest_playing = false;
387388

388-
389389
fprintf(stderr, "virtio_snd_read_pcm_prepare\n");
390390
}
391391

0 commit comments

Comments
 (0)