}
static int audio_driver_init(AudioState *s, struct audio_driver *drv,
- bool msg, Audiodev *dev)
+ Audiodev *dev, Error **errp)
{
Error *local_err = NULL;
s->drv = drv;
return 0;
} else {
- if (!msg) {
- error_free(local_err);
- } else if (local_err) {
- error_report_err(local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
} else {
- error_report("Could not init `%s' audio driver", drv->name);
+ error_setg(errp, "Could not init `%s' audio driver", drv->name);
}
return -1;
}
* if dev == NULL => legacy implicit initialization, return the already created
* state or create a new one
*/
-static AudioState *audio_init(Audiodev *dev)
+static AudioState *audio_init(Audiodev *dev, Error **errp)
{
static bool atexit_registered;
int done = 0;
drvname = AudiodevDriver_str(dev->driver);
driver = audio_driver_lookup(drvname);
if (driver) {
- done = !audio_driver_init(s, driver, true, dev);
+ done = !audio_driver_init(s, driver, dev, errp);
} else {
- dolog ("Unknown audio driver `%s'\n", drvname);
+ error_setg(errp, "Unknown audio driver `%s'\n", drvname);
}
if (!done) {
goto out;
for (;;) {
AudiodevListEntry *e = QSIMPLEQ_FIRST(&default_audiodevs);
if (!e) {
- dolog("no default audio driver available\n");
+ error_setg(errp, "no default audio driver available");
goto out;
}
s->dev = dev = e->dev;
drvname = AudiodevDriver_str(dev->driver);
driver = audio_driver_lookup(drvname);
- if (!audio_driver_init(s, driver, false, dev)) {
+ if (!audio_driver_init(s, driver, dev, NULL)) {
break;
}
QSIMPLEQ_REMOVE_HEAD(&default_audiodevs, next);
return NULL;
}
-void AUD_register_card (const char *name, QEMUSoundCard *card)
+bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp)
{
if (!card->state) {
if (!QTAILQ_EMPTY(&audio_states)) {
if (QSIMPLEQ_EMPTY(&default_audiodevs)) {
audio_create_default_audiodevs();
}
- card->state = audio_init(NULL);
+ card->state = audio_init(NULL, errp);
+ if (!card->state) {
+ return false;
+ }
}
}
card->name = g_strdup (name);
memset (&card->entries, 0, sizeof (card->entries));
QLIST_INSERT_HEAD(&card->state->card_head, card, entries);
+
+ return true;
}
void AUD_remove_card (QEMUSoundCard *card)
QSIMPLEQ_INSERT_TAIL(&audiodevs, e, next);
}
-bool audio_init_audiodevs(void)
+void audio_init_audiodevs(void)
{
AudiodevListEntry *e;
QSIMPLEQ_FOREACH(e, &audiodevs, next) {
- if (!audio_init(e->dev)) {
- return false;
- }
+ audio_init(e->dev, &error_fatal);
}
-
- return true;
}
audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo)
void AUD_vlog (const char *cap, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
void AUD_log (const char *cap, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
-void AUD_register_card (const char *name, QEMUSoundCard *card);
+bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp);
void AUD_remove_card (QEMUSoundCard *card);
CaptureVoiceOut *AUD_add_capture(
AudioState *s,
void audio_define(Audiodev *audio);
void audio_parse_option(const char *opt);
-bool audio_init_audiodevs(void);
+void audio_init_audiodevs(void);
void audio_help(void);
AudioState *audio_state_by_name(const char *name, Error **errp);
s->codec.card.name = g_strdup(current_machine->audiodev);
s->codec.card.state = audio_state_by_name(s->codec.card.name, &error_fatal);
}
- AUD_register_card("OMAP EAC", &s->codec.card);
+ AUD_register_card("OMAP EAC", &s->codec.card, &error_fatal);
memory_region_init_io(&s->iomem, NULL, &omap_eac_ops, s, "omap.eac",
omap_l4_region_size(ta, 0));
AC97LinkState *s = AC97(dev);
uint8_t *c = s->dev.config;
+ if (!AUD_register_card ("ac97", &s->card, errp)) {
+ return;
+ }
+
/* TODO: no need to override */
c[PCI_COMMAND] = 0x00; /* pcicmd pci command rw, ro */
c[PCI_COMMAND + 1] = 0x00;
"ac97-nabm", 256);
pci_register_bar(&s->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io_nam);
pci_register_bar(&s->dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &s->io_nabm);
- AUD_register_card("ac97", &s->card);
+
ac97_on_reset(DEVICE(s));
}
AdlibState *s = ADLIB(dev);
struct audsettings as;
+ if (!AUD_register_card ("adlib", &s->card, errp)) {
+ return;
+ }
+
s->opl = OPLCreate (3579545, s->freq);
if (!s->opl) {
error_setg (errp, "OPLCreate %d failed", s->freq);
as.fmt = AUDIO_FORMAT_S16;
as.endianness = AUDIO_HOST_ENDIANNESS;
- AUD_register_card ("adlib", &s->card);
-
s->voice = AUD_open_out (
&s->card,
s->voice,
return;
}
+ if (!AUD_register_card ("cs4231a", &s->card, errp)) {
+ return;
+ }
+
s->pic = isa_bus_get_irq(bus, s->irq);
k = ISADMA_GET_CLASS(s->isa_dma);
k->register_channel(s->isa_dma, s->dma, cs_dma_read, s);
isa_register_ioport (d, &s->ioports, s->port);
-
- AUD_register_card ("cs4231a", &s->card);
}
static Property cs4231a_properties[] = {
ES1370State *s = ES1370(dev);
uint8_t *c = s->dev.config;
+ if (!AUD_register_card ("es1370", &s->card, errp)) {
+ return;
+ }
+
c[PCI_STATUS + 1] = PCI_STATUS_DEVSEL_SLOW >> 8;
#if 0
memory_region_init_io (&s->io, OBJECT(s), &es1370_io_ops, s, "es1370", 256);
pci_register_bar (&s->dev, 0, PCI_BASE_ADDRESS_SPACE_IO, &s->io);
- AUD_register_card ("es1370", &s->card);
es1370_reset (s);
}
IsaDmaClass *k;
struct audsettings as;
+ if (!AUD_register_card ("gus", &s->card, errp)) {
+ return;
+ }
+
s->isa_dma = isa_bus_get_dma(bus, s->emu.gusdma);
if (!s->isa_dma) {
error_setg(errp, "ISA controller does not support DMA");
return;
}
- AUD_register_card ("gus", &s->card);
-
as.freq = s->freq;
as.nchannels = 2;
as.fmt = AUDIO_FORMAT_S16;
const desc_param *param;
uint32_t i, type;
+ if (!AUD_register_card("hda", &a->card, errp)) {
+ return;
+ }
+
a->desc = desc;
a->name = object_get_typename(OBJECT(a));
dprint(a, 1, "%s: cad %d\n", __func__, a->hda.cad);
- AUD_register_card("hda", &a->card);
for (i = 0; i < a->desc->nnodes; i++) {
node = a->desc->nodes + i;
param = hda_codec_find_param(node, AC_PAR_AUDIO_WIDGET_CAP);
{
struct audsettings as;
+ /* Register an audio card */
+ if (!AUD_register_card("lm4549", &s->card, errp)) {
+ return;
+ }
+
/* Store the callback and opaque pointer */
s->data_req_cb = data_req_cb;
s->opaque = opaque;
/* Init the registers */
lm4549_reset(s);
- /* Register an audio card */
- AUD_register_card("lm4549", &s->card);
-
/* Open a default voice */
as.freq = 48000;
as.nchannels = 2;
return 0;
}
- AUD_register_card(s_spk, &s->card);
-
s->voice = AUD_open_out(&s->card, s->voice, s_spk, s, pcspk_callback, &as);
if (!s->voice) {
AUD_log(s_spk, "Could not open voice\n");
isa_register_ioport(isadev, &s->ioport, s->iobase);
- if (s->card.state) {
+ if (s->card.state && AUD_register_card(s_spk, &s->card, errp)) {
pcspk_audio_init(s);
}
SB16State *s = SB16 (dev);
IsaDmaClass *k;
+ if (!AUD_register_card ("sb16", &s->card, errp)) {
+ return;
+ }
+
s->isa_hdma = isa_bus_get_dma(bus, s->hdma);
s->isa_dma = isa_bus_get_dma(bus, s->dma);
if (!s->isa_dma || !s->isa_hdma) {
k->register_channel(s->isa_dma, s->dma, SB_read_DMA, s);
s->can_write = 1;
-
- AUD_register_card ("sb16", &s->card);
}
static Property sb16_properties[] = {
ViaAC97State *s = VIA_AC97(pci_dev);
Object *o = OBJECT(s);
+ if (!AUD_register_card ("via-ac97", &s->card, errp)) {
+ return;
+ }
+
/*
* Command register Bus Master bit is documented to be fixed at 0 but it's
* needed for PCI DMA to work in QEMU. The pegasos2 firmware writes 0 here
pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &s->fm);
memory_region_init_io(&s->midi, o, &midi_ops, s, "via-ac97.midi", 4);
pci_register_bar(pci_dev, 2, PCI_BASE_ADDRESS_SPACE_IO, &s->midi);
-
- AUD_register_card ("via-ac97", &s->card);
}
static void via_ac97_exit(PCIDevice *dev)
{
WM8750State *s = WM8750(dev);
- AUD_register_card(CODEC, &s->card);
+ if (!AUD_register_card(CODEC, &s->card, errp)) {
+ return;
+ }
+
wm8750_reset(I2C_SLAVE(s));
}
DisplaySurface *surface;
struct audsettings as;
+ if (!AUD_register_card("xlnx_dp.audio", &s->aud_card, errp)) {
+ return;
+ }
+
aux_bus_realize(s->aux_bus);
qdev_realize(DEVICE(s->dpcd), BUS(s->aux_bus), &error_fatal);
as.fmt = AUDIO_FORMAT_S16;
as.endianness = 0;
- AUD_register_card("xlnx_dp.audio", &s->aud_card);
-
s->amixer_output_stream = AUD_open_out(&s->aud_card,
s->amixer_output_stream,
"xlnx_dp.audio.out",
s->card.name = g_strdup(current_machine->audiodev);
s->card.state = audio_state_by_name(s->card.name, &error_fatal);
}
- AUD_register_card(s->name, &s->card);
+ AUD_register_card(s->name, &s->card, &error_fatal);
qemu_register_reset((void *) tsc210x_reset, s);
vmstate_register(NULL, 0, vmsd, s);
USBAudioState *s = USB_AUDIO(dev);
int i;
+ if (!AUD_register_card(TYPE_USB_AUDIO, &s->card, errp)) {
+ return;
+ }
+
dev->usb_desc = s->multi ? &desc_audio_multi : &desc_audio;
usb_desc_create_serial(dev);
usb_desc_init(dev);
s->dev.opaque = s;
- AUD_register_card(TYPE_USB_AUDIO, &s->card);
s->out.altset = ALTSET_OFF;
s->out.vol.mute = false;
* setting machine properties, so they can be referred to.
*/
configure_blockdev(&bdo_queue, machine_class, snapshot);
- if (!audio_init_audiodevs()) {
- exit(1);
- }
+ audio_init_audiodevs();
}