audio: add help option for -audio and -audiodev
PATCH v2 1/1 audio: add help option for -audio and -audiodev
add a simple help option for -audio and -audiodev to show the list of available drivers, and document them.
--- audio/audio.c | 20 ++++++++++++++++++++ audio/audio.h | 1 + qemu-options.hx | 10 ++++++---- softmmu/vl.c | 9 +++++++-- 4 files changed, 34 insertions(+), 6 deletions(-)
v1 -> v2: also extend the help to -audio.
-audio help
-audio driver=help
-audiodev help
will all show the same results.
audio/audio.c +20 -0
@@ -32,6 +32,7 @@#include "qapi/qapi-visit-audio.h" #include "qemu/cutils.h" #include "qemu/module.h" +#include "qemu/help_option.h" #include "sysemu/sysemu.h" #include "sysemu/replay.h" #include "sysemu/runstate.h"
@@ -2105,10 +2106,29 @@ static void audio_validate_opts(Audiodev *dev, Error **errp) } } +void audio_help (void ) +{ +int i; + +printf ("Available audio drivers:\n" ); +printf ("none\n" ); + +for (i =0 ; audio_prio_list[i]; i++) { +audio_driver *driver =audio_driver_lookup (audio_prio_list[i]); +if (driver) { +printf ("%s\n" , driver->name); + } + } +} +void audio_parse_option (const char *opt) {Audiodev *dev =NULL ; +if (is_help_option (opt)) { +audio_help (); +exit (EXIT_SUCCESS ); + }Visitor *v =qobject_input_visitor_new_str (opt,"driver" , &error_fatal);visit_type_Audiodev (v,NULL , &dev, &error_fatal);visit_free (v);
audio/audio.h +1 -0
@@ -171,6 +171,7 @@ void audio_sample_from_uint64(void *samples, int pos,void audio_define (Audiodev *audio);void audio_parse_option (const char *opt);bool audio_init_audiodevs (void ); +void audio_help (void );void audio_legacy_help (void );AudioState *audio_state_by_name (const char *name);
qemu-options.hx +6 -4
@@ -704,10 +704,11 @@ SRST ``-audio [driver=]driver,model=value[,prop[=value][,...]]`` This option is a shortcut for configuring both the guest audio hardware and the host audio backend in one go. - The host backend options are the same as with the corresponding - ``-audiodev`` options below. The guest hardware model can be set with - ``model=modelname``. Use ``model=help`` to list the available device - types. + The driver option is the same as with the corresponding ``-audiodev`` option below. + The guest hardware model can be set with ``model=modelname``. + + Use ``driver=help`` to list the available drivers, + and ``model=help`` to list the available device types. The following two example do exactly the same, to show how ``-audio`` can be used to shorten the command line length:
@@ -721,6 +722,7 @@ ERST DEF("audiodev", HAS_ARG, QEMU_OPTION_audiodev, "-audiodev [driver=]driver,id=id[,prop[=value][,...]]\n" " specifies the audio backend to use\n" + " Use ``-audiodev help`` to list the available drivers\n" " id= identifier of the backend\n" " timer-period= timer period in microseconds\n" " in|out.mixing-engine= use mixing engine to mix streams inside QEMU\n"
softmmu/vl.c +7 -2
@@ -2842,11 +2842,16 @@ void qemu_init(int argc, char **argv, char **envp)audio_parse_option (optarg);break ;case QEMU_OPTION_audio: { -QDict *dict =keyval_parse (optarg,"driver" ,NULL , &error_fatal); +bool help;char *model;Audiodev *dev =NULL ;Visitor *v; - +QDict *dict =keyval_parse (optarg,"driver" , &help, &error_fatal); +if (help || (qdict_haskey (dict,"driver" ) && +is_help_option (qdict_get_str (dict,"driver" )))) { +audio_help (); +exit (EXIT_SUCCESS ); + }if (!qdict_haskey (dict,"id" )) {qdict_put_str (dict,"id" ,"audiodev0" ); }
Signature · 1 line
2.26.2
Am 07.09.22 um 19:30 schrieb Claudio Fontana:
Quoted 34 lines
add a simple help option for -audio and -audiodev to show the list of available drivers, and document them.
Signed-off-by Claudio Fontana <[email protected]>--- audio/audio.c | 20 ++++++++++++++++++++ audio/audio.h | 1 + qemu-options.hx | 10 ++++++---- softmmu/vl.c | 9 +++++++-- 4 files changed, 34 insertions(+), 6 deletions(-)v1 -> v2: also extend the help to -audio.
-audio help
-audio driver=help
-audiodev helpwill all show the same results.
audio/audio.c +1
-0@@ -32,6 +32,7 @@#include "qapi/qapi-visit-audio.h" #include "qemu/cutils.h" #include "qemu/module.h" +#include "qemu/help_option.h" #include "sysemu/sysemu.h" #include "sysemu/replay.h" #include "sysemu/runstate.h" @@ -2105,10 +2106,29 @@ static void audio_validate_opts(Audiodev *dev, Error **errp) } }
audio/audio.c static void audio_validate_opts(Audiodev *dev, Error **errp) · line 2117
Quoted 10 lines
audio/audio.c +9
-0+void audio_help (void ) +{ +int i; + +printf ("Available audio drivers:\n" ); +printf ("none\n" ); + +for (i =0 ; audio_prio_list[i]; i++) { +audio_driver *driver =audio_driver_lookup (audio_prio_list[i]);
Hi Claudio,
there is no guarantee that the audio_prio_list contains all audio backend drivers. I would use this
+ for (i = 0; i < AUDIODEV_DRIVER__MAX; i++) { + const char *name = AudiodevDriver_str(i); + audio_driver *driver = audio_driver_lookup(name);
to enumerate all audio backend drivers.
With best regards,
Volker
Quoted 7 lines
audio/audio.c +6
-0+if (driver) { +printf ("%s\n" , driver->name); + } + } +} +
Quoted 49 lines · Volker Rümelin
Am 07.09.22 um 19:30 schrieb Claudio Fontana:
Quoted 34 lines
add a simple help option for -audio and -audiodev to show the list of available drivers, and document them.
Signed-off-by Claudio Fontana <[email protected]>--- audio/audio.c | 20 ++++++++++++++++++++ audio/audio.h | 1 + qemu-options.hx | 10 ++++++---- softmmu/vl.c | 9 +++++++-- 4 files changed, 34 insertions(+), 6 deletions(-)v1 -> v2: also extend the help to -audio.
-audio help
-audio driver=help
-audiodev helpwill all show the same results.
audio/audio.c +1
-0@@ -32,6 +32,7 @@#include "qapi/qapi-visit-audio.h" #include "qemu/cutils.h" #include "qemu/module.h" +#include "qemu/help_option.h" #include "sysemu/sysemu.h" #include "sysemu/replay.h" #include "sysemu/runstate.h" @@ -2105,10 +2106,29 @@ static void audio_validate_opts(Audiodev *dev, Error **errp) } }audio/audio.c static void audio_validate_opts(Audiodev *dev, Error **errp) · line 2117
Quoted 10 lines
audio/audio.c +9
-0+void audio_help (void ) +{ +int i; + +printf ("Available audio drivers:\n" ); +printf ("none\n" ); + +for (i =0 ; audio_prio_list[i]; i++) { +audio_driver *driver =audio_driver_lookup (audio_prio_list[i]);Hi Claudio,
Quoted 8 lines
there is no guarantee that the
audio_prio_listcontains all audio backend drivers. I would use this+ for (i = 0; i <
AUDIODEV_DRIVER__MAX; i++) { + const char *name =AudiodevDriver_str(i); +audio_driver*driver =audio_driver_lookup(name);to enumerate all audio backend drivers.
Thanks Volker, will update accordingly.
Claudio
Quoted 12 lines
With best regards,
VolkerQuoted 7 lines
audio/audio.c +6
-0+if (driver) { +printf ("%s\n" , driver->name); + } + } +} +