From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LQ5Gn-0001Oj-3P for qemu-devel@nongnu.org; Thu, 22 Jan 2009 14:31:17 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LQ5Gk-0001Ko-C1 for qemu-devel@nongnu.org; Thu, 22 Jan 2009 14:31:14 -0500 Received: from [199.232.76.173] (port=38454 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LQ5Gj-0001KU-Lj for qemu-devel@nongnu.org; Thu, 22 Jan 2009 14:31:13 -0500 Received: from oxygen.pond.sub.org ([213.239.205.148]:60680) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LQ5Gi-0006Jo-VU for qemu-devel@nongnu.org; Thu, 22 Jan 2009 14:31:13 -0500 Received: from pike.pond.sub.org (pD9E3B496.dip.t-dialin.net [217.227.180.150]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 87989276CAE for ; Thu, 22 Jan 2009 20:31:11 +0100 (CET) From: Markus Armbruster Date: Thu, 22 Jan 2009 20:31:04 +0100 Message-Id: <1232652665-1710-8-git-send-email-armbru@redhat.com> In-Reply-To: <87ocxzrvqb.fsf@pike.pond.sub.org> References: <87ocxzrvqb.fsf@pike.pond.sub.org> Subject: [Qemu-devel] [PATCH 8/9] New option -audio as a more flexible alternative to -soundhw Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: Markus Armbruster This is in preparation of pci=... support for audio devices. -soundhw doesn't support the common name=value,... syntax. --- sysemu.h | 1 + vl.c | 94 ++++++++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 69 insertions(+), 26 deletions(-) diff --git a/sysemu.h b/sysemu.h index 79cbdf0..c47318b 100644 --- a/sysemu.h +++ b/sysemu.h @@ -199,6 +199,7 @@ void pstrcpy_targphys(target_phys_addr_t dest, int buf_size, struct soundhw { const char *name; const char *descr; + const char *opts; int enabled; int isa; union { diff --git a/vl.c b/vl.c index cf413c2..736c917 100644 --- a/vl.c +++ b/vl.c @@ -3866,6 +3866,8 @@ static void help(int exitcode) #endif #ifdef HAS_AUDIO "-audio-help print list of audio drivers and their options\n" + "-audio model=type[,name=str]\n" + " enable a sound card\n" "-soundhw c1,... enable audio support\n" " and only specified sound cards (comma separated list)\n" " use -soundhw ? to get the list of supported cards\n" @@ -4034,6 +4036,7 @@ enum { QEMU_OPTION_portrait, #ifdef HAS_AUDIO QEMU_OPTION_audio_help, + QEMU_OPTION_audio, QEMU_OPTION_soundhw, #endif @@ -4134,6 +4137,7 @@ static const QEMUOption qemu_options[] = { { "k", HAS_ARG, QEMU_OPTION_k }, #ifdef HAS_AUDIO { "audio-help", 0, QEMU_OPTION_audio_help }, + { "audio", HAS_ARG, QEMU_OPTION_audio }, { "soundhw", HAS_ARG, QEMU_OPTION_soundhw }, #endif @@ -4268,6 +4272,7 @@ struct soundhw soundhw[] = { { "pcspk", "PC speaker", + NULL, 0, 1, { .init_isa = pcspk_audio_init } @@ -4278,6 +4283,7 @@ struct soundhw soundhw[] = { { "sb16", "Creative Sound Blaster 16", + NULL, 0, 1, { .init_isa = SB16_init } @@ -4288,6 +4294,7 @@ struct soundhw soundhw[] = { { "cs4231a", "CS4231A", + NULL, 0, 1, { .init_isa = cs4231a_init } @@ -4302,6 +4309,7 @@ struct soundhw soundhw[] = { #else "Yamaha YM3812 (OPL2)", #endif + NULL, 0, 1, { .init_isa = Adlib_init } @@ -4312,6 +4320,7 @@ struct soundhw soundhw[] = { { "gus", "Gravis Ultrasound GF1", + NULL, 0, 1, { .init_isa = GUS_init } @@ -4322,6 +4331,7 @@ struct soundhw soundhw[] = { { "ac97", "Intel 82801AA AC97 Audio", + NULL, 0, 0, { .init_pci = ac97_init } @@ -4332,6 +4342,7 @@ struct soundhw soundhw[] = { { "es1370", "ENSONIQ AudioPCI ES1370", + NULL, 0, 0, { .init_pci = es1370_init } @@ -4340,60 +4351,88 @@ struct soundhw soundhw[] = { #endif /* HAS_AUDIO_CHOICE */ - { NULL, NULL, 0, 0, { NULL } } + { NULL, NULL, NULL, 0, 0, { NULL } } }; +static struct soundhw *soundhw_by_name(const char *name) +{ + struct soundhw *c; + + for (c = soundhw; c->name; c++) { + if (!strcmp (c->name, name)) + return c; + } + return NULL; +} + +static void audio_show_models(void) +{ + struct soundhw *c; + + for (c = soundhw; c->name; c++) + printf ("%-11s %s\n", c->name, c->descr); +} + +static void audio_enable(const char *optarg) +{ + char model[16]; + struct soundhw *c; + + if (!get_param_value(model, sizeof(model), "model", optarg)) { + fprintf(stderr, "FIXME need model\n"); + exit(1); + } + + if (!strcmp(model, "?")) { + audio_show_models(); + exit(0); + } + + c = soundhw_by_name(model); + if (!c) { + fprintf(stderr, "FIXME unknown model\n"); + exit(1); + } + c->enabled = 1; + c->opts = optarg; +} + static void select_soundhw (const char *optarg) { struct soundhw *c; + char buf[32]; if (*optarg == '?') { show_valid_cards: printf ("Valid sound card names (comma separated):\n"); - for (c = soundhw; c->name; ++c) { - printf ("%-11s %s\n", c->name, c->descr); - } + audio_show_models(); printf ("\n-soundhw all will enable all of the above\n"); exit (*optarg != '?'); } else { - size_t l; const char *p; - char *e; int bad_card = 0; if (!strcmp (optarg, "all")) { for (c = soundhw; c->name; ++c) { c->enabled = 1; + c->opts = NULL; } return; } p = optarg; while (*p) { - e = strchr (p, ','); - l = !e ? strlen (p) : (size_t) (e - p); - - for (c = soundhw; c->name; ++c) { - if (!strncmp (c->name, p, l)) { - c->enabled = 1; - break; - } - } - - if (!c->name) { - if (l > 80) { - fprintf (stderr, - "Unknown sound card name (too big to show)\n"); - } - else { - fprintf (stderr, "Unknown sound card name `%.*s'\n", - (int) l, p); - } + p = get_opt_value(buf, sizeof(buf), p); + c = soundhw_by_name(buf); + if (c) { + c->enabled = 1; + c->opts = NULL; + } else { + fprintf (stderr, "Unknown sound card name `%s'\n", buf); bad_card = 1; } - p += l + (e != NULL); } if (bad_card) @@ -4839,6 +4878,9 @@ int main(int argc, char **argv, char **envp) AUD_help (); exit (0); break; + case QEMU_OPTION_audio: + audio_enable(optarg); + break; case QEMU_OPTION_soundhw: select_soundhw (optarg); break; -- 1.6.0.6