}
}
-static void *alsa_audio_init(Audiodev *dev)
+static void *alsa_audio_init(Audiodev *dev, Error **errp)
{
AudiodevAlsaOptions *aopts;
assert(dev->driver == AUDIODEV_DRIVER_ALSA);
#include "qapi/qapi-visit-audio.h"
#include "qapi/qapi-commands-audio.h"
#include "qemu/cutils.h"
+#include "qemu/error-report.h"
#include "qemu/log.h"
#include "qemu/module.h"
#include "qemu/help_option.h"
static int audio_driver_init(AudioState *s, struct audio_driver *drv,
bool msg, Audiodev *dev)
{
- s->drv_opaque = drv->init(dev);
+ Error *local_err = NULL;
+
+ s->drv_opaque = drv->init(dev, &local_err);
if (s->drv_opaque) {
if (!drv->pcm_ops->get_buffer_in) {
s->drv = drv;
return 0;
} else {
- if (msg) {
- dolog("Could not init `%s' audio driver\n", drv->name);
+ if (!msg) {
+ error_free(local_err);
+ } else if (local_err) {
+ error_report_err(local_err);
+ } else {
+ error_report("Could not init `%s' audio driver", drv->name);
}
return -1;
}
struct audio_driver {
const char *name;
const char *descr;
- void *(*init) (Audiodev *);
+ void *(*init) (Audiodev *, Error **);
void (*fini) (void *);
#ifdef CONFIG_GIO
void (*set_dbus_server) (AudioState *s, GDBusObjectManagerServer *manager, bool p2p);
update_device_playback_state(core);
}
-static void *coreaudio_audio_init(Audiodev *dev)
+static void *coreaudio_audio_init(Audiodev *dev, Error **errp)
{
return dev;
}
}
static void *
-dbus_audio_init(Audiodev *dev)
+dbus_audio_init(Audiodev *dev, Error **errp)
{
DBusAudio *da = g_new0(DBusAudio, 1);
g_free(s);
}
-static void *dsound_audio_init(Audiodev *dev)
+static void *dsound_audio_init(Audiodev *dev, Error **errp)
{
int err;
HRESULT hr;
}
#endif
-static void *qjack_init(Audiodev *dev)
+static void *qjack_init(Audiodev *dev, Error **errp)
{
assert(dev->driver == AUDIODEV_DRIVER_JACK);
return dev;
}
}
-static void *no_audio_init(Audiodev *dev)
+static void *no_audio_init(Audiodev *dev, Error **errp)
{
return &no_audio_init;
}
#include "qemu/main-loop.h"
#include "qemu/module.h"
#include "qemu/host-utils.h"
+#include "qapi/error.h"
#include "audio.h"
#include "trace.h"
}
}
-static void *oss_audio_init(Audiodev *dev)
+static void *oss_audio_init(Audiodev *dev, Error **errp)
{
AudiodevOssOptions *oopts;
assert(dev->driver == AUDIODEV_DRIVER_OSS);
oss_init_per_direction(oopts->in);
oss_init_per_direction(oopts->out);
- if (access(oopts->in->dev ?: "/dev/dsp", R_OK | W_OK) < 0 ||
- access(oopts->out->dev ?: "/dev/dsp", R_OK | W_OK) < 0) {
+ if (access(oopts->in->dev ?: "/dev/dsp", R_OK | W_OK) < 0) {
+ error_setg_errno(errp, errno, "%s not accessible", oopts->in->dev ?: "/dev/dsp");
+ return NULL;
+ }
+ if (access(oopts->out->dev ?: "/dev/dsp", R_OK | W_OK) < 0) {
+ error_setg_errno(errp, errno, "%s not accessible", oopts->out->dev ?: "/dev/dsp");
return NULL;
}
return dev;
#include "qemu/osdep.h"
#include "qemu/module.h"
#include "audio.h"
-#include "qapi/opts-visitor.h"
+#include "qapi/error.h"
#include <pulse/pulseaudio.h>
return NULL;
}
-static void *qpa_audio_init(Audiodev *dev)
+static void *qpa_audio_init(Audiodev *dev, Error **errp)
{
paaudio *g;
AudiodevPaOptions *popts = &dev->u.pa;
runtime = getenv("XDG_RUNTIME_DIR");
if (!runtime) {
+ error_setg(errp, "XDG_RUNTIME_DIR not set");
return NULL;
}
snprintf(pidfile, sizeof(pidfile), "%s/pulse/pid", runtime);
if (stat(pidfile, &st) != 0) {
+ error_setg_errno(errp, errno, "could not stat pidfile %s", pidfile);
return NULL;
}
}
}
if (!g->conn) {
g_free(g);
+ error_setg(errp, "could not connect to PulseAudio server");
return NULL;
}
#include "audio.h"
#include <errno.h>
#include "qemu/error-report.h"
+#include "qapi/error.h"
#include <spa/param/audio/format-utils.h>
#include <spa/utils/ringbuffer.h>
#include <spa/utils/result.h>
};
static void *
-qpw_audio_init(Audiodev *dev)
+qpw_audio_init(Audiodev *dev, Error **errp)
{
g_autofree pwaudio *pw = g_new0(pwaudio, 1);
pw->dev = dev;
pw->thread_loop = pw_thread_loop_new("PipeWire thread loop", NULL);
if (pw->thread_loop == NULL) {
- error_report("Could not create PipeWire loop: %s", g_strerror(errno));
+ error_setg_errno(errp, errno, "Could not create PipeWire loop");
goto fail;
}
pw->context =
pw_context_new(pw_thread_loop_get_loop(pw->thread_loop), NULL, 0);
if (pw->context == NULL) {
- error_report("Could not create PipeWire context: %s", g_strerror(errno));
+ error_setg_errno(errp, errno, "Could not create PipeWire context");
goto fail;
}
if (pw_thread_loop_start(pw->thread_loop) < 0) {
- error_report("Could not start PipeWire loop: %s", g_strerror(errno));
+ error_setg_errno(errp, errno, "Could not start PipeWire loop");
goto fail;
}
pw->core = pw_context_connect(pw->context, NULL, 0);
if (pw->core == NULL) {
pw_thread_loop_unlock(pw->thread_loop);
- goto fail;
+ goto fail_error;
}
if (pw_core_add_listener(pw->core, &pw->core_listener,
&core_events, pw) < 0) {
pw_thread_loop_unlock(pw->thread_loop);
- goto fail;
+ goto fail_error;
}
if (wait_resync(pw) < 0) {
pw_thread_loop_unlock(pw->thread_loop);
return g_steal_pointer(&pw);
+fail_error:
+ error_setg(errp, "Failed to initialize PW context");
fail:
- AUD_log(AUDIO_CAP, "Failed to initialize PW context");
if (pw->thread_loop) {
pw_thread_loop_stop(pw->thread_loop);
}
#include <SDL.h>
#include <SDL_thread.h>
#include "qemu/module.h"
+#include "qapi/error.h"
#include "audio.h"
#ifndef _WIN32
SDL_PauseAudioDevice(sdl->devid, !enable);
}
-static void *sdl_audio_init(Audiodev *dev)
+static void *sdl_audio_init(Audiodev *dev, Error **errp)
{
if (SDL_InitSubSystem (SDL_INIT_AUDIO)) {
- sdl_logerr ("SDL failed to initialize audio subsystem\n");
+ error_setg(errp, "SDL failed to initialize audio subsystem");
return NULL;
}
sndio_fini(self);
}
-static void *sndio_audio_init(Audiodev *dev)
+static void *sndio_audio_init(Audiodev *dev, Error **errp)
{
assert(dev->driver == AUDIODEV_DRIVER_SNDIO);
return dev;
#include "qemu/module.h"
#include "qemu/error-report.h"
#include "qemu/timer.h"
+#include "qapi/error.h"
#include "ui/qemu-spice.h"
#define AUDIO_CAP "spice"
.base.minor_version = SPICE_INTERFACE_RECORD_MINOR,
};
-static void *spice_audio_init(Audiodev *dev)
+static void *spice_audio_init(Audiodev *dev, Error **errp)
{
if (!using_spice) {
+ error_setg(errp, "Cannot use spice audio without -spice");
return NULL;
}
+
return &spice_audio_init;
}
}
}
-static void *wav_audio_init(Audiodev *dev)
+static void *wav_audio_init(Audiodev *dev, Error **errp)
{
assert(dev->driver == AUDIODEV_DRIVER_WAV);
return dev;