From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Thomas Huth <thuth@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>,
Eric Blake <eblake@redhat.com>,
qemu-devel@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [RFC PATCH] audio: Make the AudiodevDriver enum conditional
Date: Fri, 25 Jun 2021 09:30:18 +0100 [thread overview]
Message-ID: <YNWUGh2XmQ7eXtmQ@redhat.com> (raw)
In-Reply-To: <20210624183716.515721-1-thuth@redhat.com>
On Thu, Jun 24, 2021 at 08:37:16PM +0200, Thomas Huth wrote:
> This way, the upper layers like libvirt could have the possibility
> to use QAPI to find out which audio drivers have been enabled during
> compile-time of QEMU.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> Note: Marked as RFC since it's quite a lot of ifdef'ing here...
> not sure whether I really like it...
Same as my patch here:
https://lists.gnu.org/archive/html/qemu-devel/2021-03/msg00654.html
>
> audio/audio.c | 16 +++++++++++++++
> audio/audio_legacy.c | 45 +++++++++++++++++++++++++++++-------------
> audio/audio_template.h | 16 +++++++++++++++
> qapi/audio.json | 37 ++++++++++++++++++++++++----------
> 4 files changed, 90 insertions(+), 24 deletions(-)
>
> diff --git a/audio/audio.c b/audio/audio.c
> index 59453ef856..34a0f39c29 100644
> --- a/audio/audio.c
> +++ b/audio/audio.c
> @@ -1988,14 +1988,30 @@ void audio_create_pdos(Audiodev *dev)
> break
>
> CASE(NONE, none, );
> +#if defined(CONFIG_AUDIO_ALSA)
> CASE(ALSA, alsa, Alsa);
> +#endif
> +#if defined(CONFIG_AUDIO_COREAUDIO)
> CASE(COREAUDIO, coreaudio, Coreaudio);
> +#endif
> +#if defined(CONFIG_AUDIO_DSOUND)
> CASE(DSOUND, dsound, );
> +#endif
> +#if defined(CONFIG_AUDIO_JACK)
> CASE(JACK, jack, Jack);
> +#endif
> +#if defined(CONFIG_AUDIO_OSS)
> CASE(OSS, oss, Oss);
> +#endif
> +#if defined(CONFIG_AUDIO_PA)
> CASE(PA, pa, Pa);
> +#endif
> +#if defined(CONFIG_AUDIO_SDL)
> CASE(SDL, sdl, Sdl);
> +#endif
> +#if defined(CONFIG_SPICE)
> CASE(SPICE, spice, );
> +#endif
> CASE(WAV, wav, );
>
> case AUDIODEV_DRIVER__MAX:
> diff --git a/audio/audio_legacy.c b/audio/audio_legacy.c
> index 0fe827b057..d940f77a27 100644
> --- a/audio/audio_legacy.c
> +++ b/audio/audio_legacy.c
> @@ -92,7 +92,7 @@ static void get_fmt(const char *env, AudioFormat *dst, bool *has_dst)
> }
> }
>
> -
> +#if defined(CONFIG_AUDIO_ALSA) || defined(CONFIG_AUDIO_DSOUND)
> static void get_millis_to_usecs(const char *env, uint32_t *dst, bool *has_dst)
> {
> const char *val = getenv(env);
> @@ -101,6 +101,7 @@ static void get_millis_to_usecs(const char *env, uint32_t *dst, bool *has_dst)
> *has_dst = true;
> }
> }
> +#endif
>
> static uint32_t frames_to_usecs(uint32_t frames,
> AudiodevPerDirectionOptions *pdo)
> @@ -109,7 +110,7 @@ static uint32_t frames_to_usecs(uint32_t frames,
> return (frames * 1000000 + freq / 2) / freq;
> }
>
> -
> +#if defined(CONFIG_AUDIO_COREAUDIO)
> static void get_frames_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
> AudiodevPerDirectionOptions *pdo)
> {
> @@ -119,6 +120,7 @@ static void get_frames_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
> *has_dst = true;
> }
> }
> +#endif
>
> static uint32_t samples_to_usecs(uint32_t samples,
> AudiodevPerDirectionOptions *pdo)
> @@ -127,6 +129,7 @@ static uint32_t samples_to_usecs(uint32_t samples,
> return frames_to_usecs(samples / channels, pdo);
> }
>
> +#if defined(CONFIG_AUDIO_PA) || defined(CONFIG_AUDIO_SDL)
> static void get_samples_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
> AudiodevPerDirectionOptions *pdo)
> {
> @@ -136,6 +139,7 @@ static void get_samples_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
> *has_dst = true;
> }
> }
> +#endif
>
> static uint32_t bytes_to_usecs(uint32_t bytes, AudiodevPerDirectionOptions *pdo)
> {
> @@ -144,6 +148,7 @@ static uint32_t bytes_to_usecs(uint32_t bytes, AudiodevPerDirectionOptions *pdo)
> return samples_to_usecs(bytes / bytes_per_sample, pdo);
> }
>
> +__attribute__((unused))
> static void get_bytes_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
> AudiodevPerDirectionOptions *pdo)
> {
> @@ -155,7 +160,7 @@ static void get_bytes_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
> }
>
> /* backend specific functions */
> -/* ALSA */
> +#if defined(CONFIG_AUDIO_ALSA)
> static void handle_alsa_per_direction(
> AudiodevAlsaPerDirectionOptions *apdo, const char *prefix)
> {
> @@ -200,8 +205,9 @@ static void handle_alsa(Audiodev *dev)
> get_millis_to_usecs("QEMU_ALSA_THRESHOLD",
> &aopt->threshold, &aopt->has_threshold);
> }
> +#endif
>
> -/* coreaudio */
> +#if defined(CONFIG_AUDIO_COREAUDIO)
> static void handle_coreaudio(Audiodev *dev)
> {
> get_frames_to_usecs(
> @@ -213,8 +219,9 @@ static void handle_coreaudio(Audiodev *dev)
> &dev->u.coreaudio.out->buffer_count,
> &dev->u.coreaudio.out->has_buffer_count);
> }
> +#endif
>
> -/* dsound */
> +#if defined(CONFIG_AUDIO_DSOUND)
> static void handle_dsound(Audiodev *dev)
> {
> get_millis_to_usecs("QEMU_DSOUND_LATENCY_MILLIS",
> @@ -228,8 +235,9 @@ static void handle_dsound(Audiodev *dev)
> &dev->u.dsound.in->has_buffer_length,
> dev->u.dsound.in);
> }
> +#endif
>
> -/* OSS */
> +#if defined(CONFIG_AUDIO_OSS)
> static void handle_oss_per_direction(
> AudiodevOssPerDirectionOptions *opdo, const char *try_poll_env,
> const char *dev_env)
> @@ -256,8 +264,9 @@ static void handle_oss(Audiodev *dev)
> get_bool("QEMU_OSS_EXCLUSIVE", &oopt->exclusive, &oopt->has_exclusive);
> get_int("QEMU_OSS_POLICY", &oopt->dsp_policy, &oopt->has_dsp_policy);
> }
> +#endif
>
> -/* pulseaudio */
> +#if defined(CONFIG_AUDIO_PA)
> static void handle_pa_per_direction(
> AudiodevPaPerDirectionOptions *ppdo, const char *env)
> {
> @@ -280,8 +289,9 @@ static void handle_pa(Audiodev *dev)
>
> get_str("QEMU_PA_SERVER", &dev->u.pa.server, &dev->u.pa.has_server);
> }
> +#endif
>
> -/* SDL */
> +#if defined(CONFIG_AUDIO_SDL)
> static void handle_sdl(Audiodev *dev)
> {
> /* SDL is output only */
> @@ -289,6 +299,7 @@ static void handle_sdl(Audiodev *dev)
> &dev->u.sdl.out->has_buffer_length,
> qapi_AudiodevSdlPerDirectionOptions_base(dev->u.sdl.out));
> }
> +#endif
>
> /* wav */
> static void handle_wav(Audiodev *dev)
> @@ -348,30 +359,36 @@ static AudiodevListEntry *legacy_opt(const char *drvname)
> }
>
> switch (e->dev->driver) {
> +#if defined(CONFIG_AUDIO_ALSA)
> case AUDIODEV_DRIVER_ALSA:
> handle_alsa(e->dev);
> break;
> -
> +#endif
> +#if defined(CONFIG_AUDIO_COREAUDIO)
> case AUDIODEV_DRIVER_COREAUDIO:
> handle_coreaudio(e->dev);
> break;
> -
> +#endif
> +#if defined(CONFIG_AUDIO_DSOUND)
> case AUDIODEV_DRIVER_DSOUND:
> handle_dsound(e->dev);
> break;
> -
> +#endif
> +#if defined(CONFIG_AUDIO_OSS)
> case AUDIODEV_DRIVER_OSS:
> handle_oss(e->dev);
> break;
> -
> +#endif
> +#if defined(CONFIG_AUDIO_PA)
> case AUDIODEV_DRIVER_PA:
> handle_pa(e->dev);
> break;
> -
> +#endif
> +#if defined(CONFIG_AUDIO_SDL)
> case AUDIODEV_DRIVER_SDL:
> handle_sdl(e->dev);
> break;
> -
> +#endif
> case AUDIODEV_DRIVER_WAV:
> handle_wav(e->dev);
> break;
> diff --git a/audio/audio_template.h b/audio/audio_template.h
> index c6714946aa..b808088c7b 100644
> --- a/audio/audio_template.h
> +++ b/audio/audio_template.h
> @@ -322,23 +322,39 @@ AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)(Audiodev *dev)
> switch (dev->driver) {
> case AUDIODEV_DRIVER_NONE:
> return dev->u.none.TYPE;
> +#if defined(CONFIG_AUDIO_ALSA)
> case AUDIODEV_DRIVER_ALSA:
> return qapi_AudiodevAlsaPerDirectionOptions_base(dev->u.alsa.TYPE);
> +#endif
> +#if defined(CONFIG_AUDIO_COREAUDIO)
> case AUDIODEV_DRIVER_COREAUDIO:
> return qapi_AudiodevCoreaudioPerDirectionOptions_base(
> dev->u.coreaudio.TYPE);
> +#endif
> +#if defined(CONFIG_AUDIO_DSOUND)
> case AUDIODEV_DRIVER_DSOUND:
> return dev->u.dsound.TYPE;
> +#endif
> +#if defined(CONFIG_AUDIO_JACK)
> case AUDIODEV_DRIVER_JACK:
> return qapi_AudiodevJackPerDirectionOptions_base(dev->u.jack.TYPE);
> +#endif
> +#if defined(CONFIG_AUDIO_OSS)
> case AUDIODEV_DRIVER_OSS:
> return qapi_AudiodevOssPerDirectionOptions_base(dev->u.oss.TYPE);
> +#endif
> +#if defined(CONFIG_AUDIO_PA)
> case AUDIODEV_DRIVER_PA:
> return qapi_AudiodevPaPerDirectionOptions_base(dev->u.pa.TYPE);
> +#endif
> +#if defined(CONFIG_AUDIO_SDL)
> case AUDIODEV_DRIVER_SDL:
> return qapi_AudiodevSdlPerDirectionOptions_base(dev->u.sdl.TYPE);
> +#endif
> +#if defined(CONFIG_SPICE)
> case AUDIODEV_DRIVER_SPICE:
> return dev->u.spice.TYPE;
> +#endif
> case AUDIODEV_DRIVER_WAV:
> return dev->u.wav.TYPE;
>
> diff --git a/qapi/audio.json b/qapi/audio.json
> index 9cba0df8a4..128850eba4 100644
> --- a/qapi/audio.json
> +++ b/qapi/audio.json
> @@ -386,8 +386,17 @@
> # Since: 4.0
> ##
> { 'enum': 'AudiodevDriver',
> - 'data': [ 'none', 'alsa', 'coreaudio', 'dsound', 'jack', 'oss', 'pa',
> - 'sdl', 'spice', 'wav' ] }
> + 'data': [
> + { 'name': 'none' },
> + { 'name': 'alsa', 'if': 'defined(CONFIG_AUDIO_ALSA)' },
> + { 'name': 'coreaudio', 'if': 'defined(CONFIG_AUDIO_COREAUDIO)' },
> + { 'name': 'dsound', 'if': 'defined(CONFIG_AUDIO_DSOUND)' },
> + { 'name': 'jack', 'if': 'defined(CONFIG_AUDIO_JACK)' },
> + { 'name': 'oss', 'if': 'defined(CONFIG_AUDIO_OSS)' },
> + { 'name': 'pa', 'if': 'defined(CONFIG_AUDIO_PA)' },
> + { 'name': 'sdl', 'if': 'defined(CONFIG_AUDIO_SDL)' },
> + { 'name': 'spice', 'if': 'defined(CONFIG_SPICE)' },
> + { 'name': 'wav' } ] }
>
> ##
> # @Audiodev:
> @@ -410,12 +419,20 @@
> 'discriminator': 'driver',
> 'data': {
> 'none': 'AudiodevGenericOptions',
> - 'alsa': 'AudiodevAlsaOptions',
> - 'coreaudio': 'AudiodevCoreaudioOptions',
> - 'dsound': 'AudiodevDsoundOptions',
> - 'jack': 'AudiodevJackOptions',
> - 'oss': 'AudiodevOssOptions',
> - 'pa': 'AudiodevPaOptions',
> - 'sdl': 'AudiodevSdlOptions',
> - 'spice': 'AudiodevGenericOptions',
> + 'alsa': { 'type': 'AudiodevAlsaOptions',
> + 'if': 'defined(CONFIG_AUDIO_ALSA)' },
> + 'coreaudio': { 'type': 'AudiodevCoreaudioOptions',
> + 'if': 'defined(CONFIG_AUDIO_COREAUDIO)' },
> + 'dsound': { 'type': 'AudiodevDsoundOptions',
> + 'if': 'defined(CONFIG_AUDIO_DSOUND)' },
> + 'jack': { 'type': 'AudiodevJackOptions',
> + 'if': 'defined(CONFIG_AUDIO_JACK)' },
> + 'oss': { 'type': 'AudiodevOssOptions',
> + 'if': 'defined(CONFIG_AUDIO_OSS)' },
> + 'pa': { 'type': 'AudiodevPaOptions',
> + 'if': 'defined(CONFIG_AUDIO_PA)' },
> + 'sdl': { 'type': 'AudiodevSdlOptions',
> + 'if': 'defined(CONFIG_AUDIO_SDL)' },
> + 'spice': { 'type': 'AudiodevGenericOptions',
> + 'if': 'defined(CONFIG_SPICE)' },
> 'wav': 'AudiodevWavOptions' } }
> --
> 2.27.0
>
>
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2021-06-25 8:32 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-24 18:37 [RFC PATCH] audio: Make the AudiodevDriver enum conditional Thomas Huth
2021-06-25 8:30 ` Daniel P. Berrangé [this message]
2021-06-25 8:45 ` Thomas Huth
2021-07-08 14:56 ` Markus Armbruster
2021-07-08 15:17 ` Daniel P. Berrangé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YNWUGh2XmQ7eXtmQ@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.