qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>, qemu-devel@nongnu.org
Cc: Michael Roth <michael.roth@amd.com>,
	Markus Armbruster <armbru@redhat.com>,
	Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [PATCH 2/3] qapi, audio: respect build time conditions in audio schema
Date: Mon, 12 Dec 2022 17:53:21 +0100	[thread overview]
Message-ID: <62940e7f-60dc-86d7-6007-da0e89dfc6ff@redhat.com> (raw)
In-Reply-To: <20210302175524.1290840-3-berrange@redhat.com>

On 02/03/2021 18.55, Daniel P. Berrangé wrote:
> Currently the -audiodev accepts any audiodev type regardless of what is
> built in to QEMU. An error only occurs later at runtime when a sound
> device tries to use the audio backend.
> 
> With this change QEMU will immediately reject -audiodev args that are
> not compiled into the binary. The QMP schema will also be introspectable
> to identify what is compiled in.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   audio/audio.c          | 16 +++++++++++++++
>   audio/audio_legacy.c   | 41 ++++++++++++++++++++++++++++++++++++++-
>   audio/audio_template.h | 16 +++++++++++++++
>   qapi/audio.json        | 44 ++++++++++++++++++++++++++++++++----------
>   4 files changed, 106 insertions(+), 11 deletions(-)

  Hi Daniel!

Would you have time to respin this patch for QEMU 8.0 ?

  Thomas


> diff --git a/audio/audio.c b/audio/audio.c
> index 40a4bbd7ce..53434fc674 100644
> --- a/audio/audio.c
> +++ b/audio/audio.c
> @@ -1989,14 +1989,30 @@ void audio_create_pdos(Audiodev *dev)
>           break
>   
>           CASE(NONE, none, );
> +#ifdef CONFIG_AUDIO_ALSA
>           CASE(ALSA, alsa, Alsa);
> +#endif
> +#ifdef CONFIG_AUDIO_COREAUDIO
>           CASE(COREAUDIO, coreaudio, Coreaudio);
> +#endif
> +#ifdef CONFIG_AUDIO_DSOUND
>           CASE(DSOUND, dsound, );
> +#endif
> +#ifdef CONFIG_AUDIO_JACK
>           CASE(JACK, jack, Jack);
> +#endif
> +#ifdef CONFIG_AUDIO_OSS
>           CASE(OSS, oss, Oss);
> +#endif
> +#ifdef CONFIG_AUDIO_PA
>           CASE(PA, pa, Pa);
> +#endif
> +#ifdef CONFIG_AUDIO_SDL
>           CASE(SDL, sdl, Sdl);
> +#endif
> +#ifdef 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..bb2268f2b2 100644
> --- a/audio/audio_legacy.c
> +++ b/audio/audio_legacy.c
> @@ -93,6 +93,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,15 +102,20 @@ static void get_millis_to_usecs(const char *env, uint32_t *dst, bool *has_dst)
>           *has_dst = true;
>       }
>   }
> +#endif
>   
> +#if defined(CONFIG_AUDIO_ALSA) || defined(CONFIG_AUDIO_COREAUDIO) || \
> +    defined(CONFIG_AUDIO_PA) || defined(CONFIG_AUDIO_SDL) || \
> +    defined(CONFIG_AUDIO_DSOUND) || defined(CONFIG_AUDIO_OSS)
>   static uint32_t frames_to_usecs(uint32_t frames,
>                                   AudiodevPerDirectionOptions *pdo)
>   {
>       uint32_t freq = pdo->has_frequency ? pdo->frequency : 44100;
>       return (frames * 1000000 + freq / 2) / freq;
>   }
> +#endif
>   
> -
> +#ifdef CONFIG_AUDIO_COREAUDIO
>   static void get_frames_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
>                                   AudiodevPerDirectionOptions *pdo)
>   {
> @@ -119,14 +125,19 @@ static void get_frames_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
>           *has_dst = true;
>       }
>   }
> +#endif
>   
> +#if defined(CONFIG_AUDIO_PA) || defined(CONFIG_AUDIO_SDL) || \
> +    defined(CONFIG_AUDIO_DSOUND) || defined(CONFIG_AUDIO_OSS)
>   static uint32_t samples_to_usecs(uint32_t samples,
>                                    AudiodevPerDirectionOptions *pdo)
>   {
>       uint32_t channels = pdo->has_channels ? pdo->channels : 2;
>       return frames_to_usecs(samples / channels, pdo);
>   }
> +#endif
>   
> +#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,7 +147,9 @@ static void get_samples_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
>           *has_dst = true;
>       }
>   }
> +#endif
>   
> +#if defined(CONFIG_AUDIO_DSOUND) || defined(CONFIG_AUDIO_OSS)
>   static uint32_t bytes_to_usecs(uint32_t bytes, AudiodevPerDirectionOptions *pdo)
>   {
>       AudioFormat fmt = pdo->has_format ? pdo->format : AUDIO_FORMAT_S16;
> @@ -153,8 +166,11 @@ static void get_bytes_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
>           *has_dst = true;
>       }
>   }
> +#endif
>   
>   /* backend specific functions */
> +
> +#ifdef CONFIG_AUDIO_ALSA
>   /* ALSA */
>   static void handle_alsa_per_direction(
>       AudiodevAlsaPerDirectionOptions *apdo, const char *prefix)
> @@ -200,7 +216,9 @@ static void handle_alsa(Audiodev *dev)
>       get_millis_to_usecs("QEMU_ALSA_THRESHOLD",
>                           &aopt->threshold, &aopt->has_threshold);
>   }
> +#endif
>   
> +#ifdef CONFIG_AUDIO_COREAUDIO
>   /* coreaudio */
>   static void handle_coreaudio(Audiodev *dev)
>   {
> @@ -213,7 +231,9 @@ static void handle_coreaudio(Audiodev *dev)
>               &dev->u.coreaudio.out->buffer_count,
>               &dev->u.coreaudio.out->has_buffer_count);
>   }
> +#endif
>   
> +#ifdef CONFIG_AUDIO_DSOUND
>   /* dsound */
>   static void handle_dsound(Audiodev *dev)
>   {
> @@ -228,7 +248,9 @@ static void handle_dsound(Audiodev *dev)
>                          &dev->u.dsound.in->has_buffer_length,
>                          dev->u.dsound.in);
>   }
> +#endif
>   
> +#ifdef CONFIG_AUDIO_OSS
>   /* OSS */
>   static void handle_oss_per_direction(
>       AudiodevOssPerDirectionOptions *opdo, const char *try_poll_env,
> @@ -256,7 +278,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
>   
> +#ifdef CONFIG_AUDIO_PA
>   /* pulseaudio */
>   static void handle_pa_per_direction(
>       AudiodevPaPerDirectionOptions *ppdo, const char *env)
> @@ -280,7 +304,9 @@ static void handle_pa(Audiodev *dev)
>   
>       get_str("QEMU_PA_SERVER", &dev->u.pa.server, &dev->u.pa.has_server);
>   }
> +#endif
>   
> +#ifdef CONFIG_AUDIO_SDL
>   /* SDL */
>   static void handle_sdl(Audiodev *dev)
>   {
> @@ -289,6 +315,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,29 +375,41 @@ static AudiodevListEntry *legacy_opt(const char *drvname)
>       }
>   
>       switch (e->dev->driver) {
> +#ifdef CONFIG_AUDIO_ALSA
>       case AUDIODEV_DRIVER_ALSA:
>           handle_alsa(e->dev);
>           break;
> +#endif
>   
> +#ifdef CONFIG_AUDIO_COREAUDIO
>       case AUDIODEV_DRIVER_COREAUDIO:
>           handle_coreaudio(e->dev);
>           break;
> +#endif
>   
> +#ifdef CONFIG_AUDIO_DSOUND
>       case AUDIODEV_DRIVER_DSOUND:
>           handle_dsound(e->dev);
>           break;
> +#endif
>   
> +#ifdef CONFIG_AUDIO_OSS
>       case AUDIODEV_DRIVER_OSS:
>           handle_oss(e->dev);
>           break;
> +#endif
>   
> +#ifdef CONFIG_AUDIO_PA
>       case AUDIODEV_DRIVER_PA:
>           handle_pa(e->dev);
>           break;
> +#endif
>   
> +#ifdef CONFIG_AUDIO_SDL
>       case AUDIODEV_DRIVER_SDL:
>           handle_sdl(e->dev);
>           break;
> +#endif
>   
>       case AUDIODEV_DRIVER_WAV:
>           handle_wav(e->dev);
> diff --git a/audio/audio_template.h b/audio/audio_template.h
> index c6714946aa..0847b643be 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;
> +#ifdef CONFIG_AUDIO_ALSA
>       case AUDIODEV_DRIVER_ALSA:
>           return qapi_AudiodevAlsaPerDirectionOptions_base(dev->u.alsa.TYPE);
> +#endif
> +#ifdef CONFIG_AUDIO_COREAUDIO
>       case AUDIODEV_DRIVER_COREAUDIO:
>           return qapi_AudiodevCoreaudioPerDirectionOptions_base(
>               dev->u.coreaudio.TYPE);
> +#endif
> +#ifdef CONFIG_AUDIO_DSOUND
>       case AUDIODEV_DRIVER_DSOUND:
>           return dev->u.dsound.TYPE;
> +#endif
> +#ifdef CONFIG_AUDIO_JACK
>       case AUDIODEV_DRIVER_JACK:
>           return qapi_AudiodevJackPerDirectionOptions_base(dev->u.jack.TYPE);
> +#endif
> +#ifdef CONFIG_AUDIO_OSS
>       case AUDIODEV_DRIVER_OSS:
>           return qapi_AudiodevOssPerDirectionOptions_base(dev->u.oss.TYPE);
> +#endif
> +#ifdef CONFIG_AUDIO_PA
>       case AUDIODEV_DRIVER_PA:
>           return qapi_AudiodevPaPerDirectionOptions_base(dev->u.pa.TYPE);
> +#endif
> +#ifdef CONFIG_AUDIO_SDL
>       case AUDIODEV_DRIVER_SDL:
>           return qapi_AudiodevSdlPerDirectionOptions_base(dev->u.sdl.TYPE);
> +#endif
> +#ifdef 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 d7b91230d7..9af1b8140c 100644
> --- a/qapi/audio.json
> +++ b/qapi/audio.json
> @@ -386,8 +386,24 @@
>   # Since: 4.0
>   ##
>   { 'enum': 'AudiodevDriver',
> -  'data': [ 'none', 'alsa', 'coreaudio', 'dsound', 'jack', 'oss', 'pa',
> -            'sdl', 'spice', 'wav' ] }
> +  'data': [ '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)' },
> +            'wav' ] }
>   
>   ##
>   # @Audiodev:
> @@ -410,14 +426,22 @@
>     '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' } }
>   
>   ##



  parent reply	other threads:[~2022-12-12 16:53 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-02 17:55 [PATCH 0/3] audio: make audiodev introspectable by mgmt apps Daniel P. Berrangé
2021-03-02 17:55 ` [PATCH 1/3] qapi, audio: add query-audiodev command Daniel P. Berrangé
2021-03-02 19:03   ` Eric Blake
2021-03-02 21:10   ` Philippe Mathieu-Daudé
2021-03-02 21:12     ` Philippe Mathieu-Daudé
2021-03-03 10:07       ` Daniel P. Berrangé
2021-03-03 10:08     ` Daniel P. Berrangé
2021-03-05 13:01   ` Markus Armbruster
2021-03-11 11:00     ` Daniel P. Berrangé
2021-03-02 17:55 ` [PATCH 2/3] qapi, audio: respect build time conditions in audio schema Daniel P. Berrangé
2021-03-02 19:05   ` Eric Blake
2021-03-03 10:09     ` Daniel P. Berrangé
2021-03-03  7:00   ` Gerd Hoffmann
2021-03-03 10:11     ` Daniel P. Berrangé
2021-03-05 10:56       ` Markus Armbruster
2021-03-11 11:04         ` Daniel P. Berrangé
2021-03-05 12:12   ` Markus Armbruster
2022-12-12 16:53   ` Thomas Huth [this message]
2022-12-14 11:28     ` Daniel P. Berrangé
2021-03-02 17:55 ` [PATCH 3/3] qapi: provide a friendly string representation of QAPI classes Daniel P. Berrangé
2021-03-02 19:06   ` Eric Blake
2021-03-02 21:02   ` Philippe Mathieu-Daudé
2021-03-05 13:18   ` Markus Armbruster

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=62940e7f-60dc-86d7-6007-da0e89dfc6ff@redhat.com \
    --to=thuth@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=michael.roth@amd.com \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).