Skip to content

Commit

Permalink
Initialize CNFA driver in pcm_prepare
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuda-Chen committed Oct 22, 2024
1 parent d312e6f commit 0b5da33
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions virtio-snd.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,18 @@ static virtio_snd_config_t vsnd_configs[VSND_DEV_CNT_MAX];
static virtio_snd_prop_t vsnd_props[VSND_DEV_CNT_MAX];
static int vsnd_dev_cnt = 0;

//static struct CNFADriver *audio_host = NULL;
// static struct CNFADriver *audio_host = NULL;

static bool guest_playing = false;

/* Forward declaration */
static void virtio_snd_cb(struct CNFADriver *dev,
short *out,
short *in,
int framesp,
int framesr);


static void virtio_snd_set_fail(virtio_snd_state_t *vsnd)
{
vsnd->Status |= VIRTIO_STATUS__DEVICE_NEEDS_RESET;
Expand Down Expand Up @@ -347,23 +355,12 @@ static void virtio_snd_read_chmap_info_handler(
static void virtio_snd_read_pcm_set_params(struct virtq_desc *vq_desc,
const virtio_snd_query_info_t *query)
{
#if 0
/* TODO: detect current state of stream */
/* TODO: let application to set each value at will */
/* TODO: check the valiability of buffer_bytes, period_bytes, channel_min,
* and channel_max */
info->hdr.hdr.code = VIRTIO_SND_R_PCM_SET_PARAMS;
info->hdr.stream_id = 0;
info->buffer_bytes = 2048;
info->period_bytes = 1024;
info->features = 0;
info->channels = 1;
info->format = (1 << VIRTIO_SND_PCM_FMT_S16);
info->rate = (1 << VIRTIO_SND_PCM_RATE_44100);
info->padding = 0;
#endif

virtio_snd_pcm_set_params_t *request = query;
uint32_t id = request->hdr.stream_id;
uint32_t id = request->hdr.stream_id;
vsnd_props[id].pp.hdr.hdr.code = VIRTIO_SND_R_PCM_SET_PARAMS;
vsnd_props[id].pp.buffer_bytes = request->buffer_bytes;
vsnd_props[id].pp.period_bytes = request->period_bytes;
Expand All @@ -379,13 +376,16 @@ static void virtio_snd_read_pcm_set_params(struct virtq_desc *vq_desc,
static void virtio_snd_read_pcm_prepare(struct virtq_desc *vq_desc,
const virtio_snd_query_info_t *query)
{
/* TODO: let application to set stream_id at will */
virtio_snd_pcm_hdr_t *request = query;
uint32_t stream_id = request->stream_id;
vsnd_props[stream_id].audio_host = CNFAInit(
NULL, "semu-virtio-snd", virtio_snd_cb, 44100, 0, 1, 0,
vsnd_props[stream_id].pp.buffer_bytes, NULL, NULL, &guest_playing);

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


fprintf(stderr, "virtio_snd_read_pcm_prepare\n");
}

Expand Down

0 comments on commit 0b5da33

Please sign in to comment.