audio: return Error ** from audio_state_by_name
Remove duplicate error formatting code. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
f6061733a9
commit
176adafca7
|
@ -26,6 +26,7 @@
|
||||||
#include "audio/audio.h"
|
#include "audio/audio.h"
|
||||||
#include "monitor/hmp.h"
|
#include "monitor/hmp.h"
|
||||||
#include "monitor/monitor.h"
|
#include "monitor/monitor.h"
|
||||||
|
#include "qapi/error.h"
|
||||||
#include "qapi/qmp/qdict.h"
|
#include "qapi/qmp/qdict.h"
|
||||||
|
|
||||||
static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
|
static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
|
||||||
|
@ -65,10 +66,11 @@ void hmp_wavcapture(Monitor *mon, const QDict *qdict)
|
||||||
int nchannels = qdict_get_try_int(qdict, "nchannels", 2);
|
int nchannels = qdict_get_try_int(qdict, "nchannels", 2);
|
||||||
const char *audiodev = qdict_get_str(qdict, "audiodev");
|
const char *audiodev = qdict_get_str(qdict, "audiodev");
|
||||||
CaptureState *s;
|
CaptureState *s;
|
||||||
AudioState *as = audio_state_by_name(audiodev);
|
Error *local_err = NULL;
|
||||||
|
AudioState *as = audio_state_by_name(audiodev, &local_err);
|
||||||
|
|
||||||
if (!as) {
|
if (!as) {
|
||||||
monitor_printf(mon, "Audiodev '%s' not found\n", audiodev);
|
error_report_err(local_err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2260,7 +2260,7 @@ int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
|
||||||
audioformat_bytes_per_sample(as->fmt);
|
audioformat_bytes_per_sample(as->fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioState *audio_state_by_name(const char *name)
|
AudioState *audio_state_by_name(const char *name, Error **errp)
|
||||||
{
|
{
|
||||||
AudioState *s;
|
AudioState *s;
|
||||||
QTAILQ_FOREACH(s, &audio_states, list) {
|
QTAILQ_FOREACH(s, &audio_states, list) {
|
||||||
|
@ -2269,6 +2269,7 @@ AudioState *audio_state_by_name(const char *name)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
error_setg(errp, "audiodev '%s' not found", name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,7 +174,7 @@ bool audio_init_audiodevs(void);
|
||||||
void audio_help(void);
|
void audio_help(void);
|
||||||
void audio_legacy_help(void);
|
void audio_legacy_help(void);
|
||||||
|
|
||||||
AudioState *audio_state_by_name(const char *name);
|
AudioState *audio_state_by_name(const char *name, Error **errp);
|
||||||
const char *audio_get_id(QEMUSoundCard *card);
|
const char *audio_get_id(QEMUSoundCard *card);
|
||||||
|
|
||||||
#define DEFINE_AUDIO_PROPERTIES(_s, _f) \
|
#define DEFINE_AUDIO_PROPERTIES(_s, _f) \
|
||||||
|
|
|
@ -480,24 +480,16 @@ static void set_audiodev(Object *obj, Visitor *v, const char* name,
|
||||||
Property *prop = opaque;
|
Property *prop = opaque;
|
||||||
QEMUSoundCard *card = object_field_prop_ptr(obj, prop);
|
QEMUSoundCard *card = object_field_prop_ptr(obj, prop);
|
||||||
AudioState *state;
|
AudioState *state;
|
||||||
int err = 0;
|
g_autofree char *str = NULL;
|
||||||
char *str;
|
|
||||||
|
|
||||||
if (!visit_type_str(v, name, &str, errp)) {
|
if (!visit_type_str(v, name, &str, errp)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = audio_state_by_name(str);
|
state = audio_state_by_name(str, errp);
|
||||||
|
if (state) {
|
||||||
if (!state) {
|
card->state = state;
|
||||||
err = -ENOENT;
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
card->state = state;
|
|
||||||
|
|
||||||
out:
|
|
||||||
error_set_from_qdev_prop_error(errp, err, obj, name, str);
|
|
||||||
g_free(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const PropertyInfo qdev_prop_audiodev = {
|
const PropertyInfo qdev_prop_audiodev = {
|
||||||
|
|
|
@ -220,9 +220,8 @@ dbus_display_complete(UserCreatable *uc, Error **errp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dd->audiodev && *dd->audiodev) {
|
if (dd->audiodev && *dd->audiodev) {
|
||||||
AudioState *audio_state = audio_state_by_name(dd->audiodev);
|
AudioState *audio_state = audio_state_by_name(dd->audiodev, errp);
|
||||||
if (!audio_state) {
|
if (!audio_state) {
|
||||||
error_setg(errp, "Audiodev '%s' not found", dd->audiodev);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!g_str_equal(audio_state->drv->name, "dbus")) {
|
if (!g_str_equal(audio_state->drv->name, "dbus")) {
|
||||||
|
|
3
ui/vnc.c
3
ui/vnc.c
|
@ -4181,9 +4181,8 @@ void vnc_display_open(const char *id, Error **errp)
|
||||||
|
|
||||||
audiodev = qemu_opt_get(opts, "audiodev");
|
audiodev = qemu_opt_get(opts, "audiodev");
|
||||||
if (audiodev) {
|
if (audiodev) {
|
||||||
vd->audio_state = audio_state_by_name(audiodev);
|
vd->audio_state = audio_state_by_name(audiodev, errp);
|
||||||
if (!vd->audio_state) {
|
if (!vd->audio_state) {
|
||||||
error_setg(errp, "Audiodev '%s' not found", audiodev);
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue