audio: extract audio_define_default

It will be used soon to define a default audio device from the
command line.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2023-10-05 12:17:28 +02:00
parent c753bf479a
commit 8f527a3c0d
2 changed files with 13 additions and 7 deletions

View File

@ -1686,8 +1686,6 @@ static const VMStateDescription vmstate_audio = {
}
};
static void audio_validate_opts(Audiodev *dev, Error **errp);
void audio_create_default_audiodevs(void)
{
const char *drvname = getenv("QEMU_AUDIO_DRV");
@ -1706,7 +1704,6 @@ void audio_create_default_audiodevs(void)
if (audio_driver_lookup(audio_prio_list[i])) {
QDict *dict = qdict_new();
Audiodev *dev = NULL;
AudiodevListEntry *e;
Visitor *v;
qdict_put_str(dict, "driver", audio_prio_list[i]);
@ -1717,10 +1714,7 @@ void audio_create_default_audiodevs(void)
visit_type_Audiodev(v, NULL, &dev, &error_fatal);
visit_free(v);
audio_validate_opts(dev, &error_abort);
e = g_new0(AudiodevListEntry, 1);
e->dev = dev;
QSIMPLEQ_INSERT_TAIL(&default_audiodevs, e, next);
audio_define_default(dev, &error_abort);
}
}
}
@ -2165,6 +2159,17 @@ void audio_define(Audiodev *dev)
QSIMPLEQ_INSERT_TAIL(&audiodevs, e, next);
}
void audio_define_default(Audiodev *dev, Error **errp)
{
AudiodevListEntry *e;
audio_validate_opts(dev, errp);
e = g_new0(AudiodevListEntry, 1);
e->dev = dev;
QSIMPLEQ_INSERT_TAIL(&default_audiodevs, e, next);
}
void audio_init_audiodevs(void)
{
AudiodevListEntry *e;

View File

@ -169,6 +169,7 @@ void audio_sample_from_uint64(void *samples, int pos,
uint64_t left, uint64_t right);
void audio_define(Audiodev *audio);
void audio_define_default(Audiodev *dev, Error **errp);
void audio_parse_option(const char *opt);
void audio_create_default_audiodevs(void);
void audio_init_audiodevs(void);