All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zoltán Kővágó" <dirty.ice.hu@gmail.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v5 04/14] audio: -audiodev command line option basic implementation
Date: Tue, 26 Feb 2019 02:39:38 +0100	[thread overview]
Message-ID: <63250655-a4a3-ef36-5882-65188093ff57@gmail.com> (raw)
In-Reply-To: <cf14255c576fd361c6cdf941f8c637e613f6cb68.1550698466.git.DirtY.iCE.hu@gmail.com>

On 2019-02-20 22:37, Kővágó, Zoltán wrote:
[...]
> diff --git a/audio/audio.c b/audio/audio.c
> index ce8e6ea8c2..8ad8cbe559 100644
> --- a/audio/audio.c
> +++ b/audio/audio.c
[...]
> @@ -2129,3 +1866,170 @@ void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol)
>          }
>      }
>  }
> +
> +void audio_create_pdos(Audiodev *dev)
> +{
> +    switch (dev->driver) {
> +#define CASE(DRIVER, driver, pdo_name)                              \
> +    case AUDIODEV_DRIVER_##DRIVER:                                  \
> +        dev->u.driver.in = g_malloc0(                               \
> +            sizeof(Audiodev##pdo_name##PerDirectionOptions));       \
This should check has_in before overwriting. It'll work correctly when
called from audio_legacy.c, but when using -audiodev it will overwrite
the options passed by user (and leak memory) when called from
audio_validate_opts. I'll fix it in the next update.

> +        dev->u.driver.has_in = true;                                \
> +        dev->u.driver.out = g_malloc0(                              \
> +            sizeof(AudiodevAlsaPerDirectionOptions));               \
> +        dev->u.driver.has_out = true;                               \
> +        break
> +
> +        CASE(NONE, none, );
> +        CASE(ALSA, alsa, Alsa);
> +        CASE(COREAUDIO, coreaudio, Coreaudio);
> +        CASE(DSOUND, dsound, );
> +        CASE(OSS, oss, Oss);
> +        CASE(PA, pa, Pa);
> +        CASE(SDL, sdl, );
> +        CASE(SPICE, spice, );
> +        CASE(WAV, wav, );
> +
> +    case AUDIODEV_DRIVER__MAX:
> +        abort();
> +    };
> +}
> +
> +static void audio_validate_per_direction_opts(
> +    AudiodevPerDirectionOptions *pdo, Error **errp)
> +{
> +    if (!pdo->has_fixed_settings) {
> +        pdo->has_fixed_settings = true;
> +        pdo->fixed_settings = true;
> +    }
> +    if (!pdo->fixed_settings &&
> +        (pdo->has_frequency || pdo->has_channels || pdo->has_format)) {
> +        error_setg(errp,
> +                   "You can't use frequency, channels or format with fixed-settings=off");
> +        return;
> +    }
> +
> +    if (!pdo->has_frequency) {
> +        pdo->has_frequency = true;
> +        pdo->frequency = 44100;
> +    }
> +    if (!pdo->has_channels) {
> +        pdo->has_channels = true;
> +        pdo->channels = 2;
> +    }
> +    if (!pdo->has_voices) {
> +        pdo->has_voices = true;
> +        pdo->voices = 1;
> +    }
> +    if (!pdo->has_format) {
> +        pdo->has_format = true;
> +        pdo->format = AUDIO_FORMAT_S16;
> +    }
> +}
> +
> +static void audio_validate_opts(Audiodev *dev, Error **errp)
> +{
> +    Error *err = NULL;
> +
> +    audio_create_pdos(dev);
> +
> +    audio_validate_per_direction_opts(audio_get_pdo_in(dev), &err);
> +    if (err) {
> +        error_propagate(errp, err);
> +        return;
> +    }
> +
> +    audio_validate_per_direction_opts(audio_get_pdo_out(dev), &err);
> +    if (err) {
> +        error_propagate(errp, err);
> +        return;
> +    }
> +
> +    if (!dev->has_timer_period) {
> +        dev->has_timer_period = true;
> +        dev->timer_period = 10000; /* 100Hz -> 10ms */
> +    }
> +}
> +
> +void audio_parse_option(const char *opt)
> +{
> +    AudiodevListEntry *e;
> +    Audiodev *dev = NULL;
> +
> +    Visitor *v = qobject_input_visitor_new_str(opt, "driver", &error_fatal);
> +    visit_type_Audiodev(v, NULL, &dev, &error_fatal);
> +    visit_free(v);
> +
> +    audio_validate_opts(dev, &error_fatal);
> +
> +    e = g_malloc0(sizeof(AudiodevListEntry));
> +    e->dev = dev;
> +    QSIMPLEQ_INSERT_TAIL(&audiodevs, e, next);
> +}
> +
[...]

Regards,
Zoltan

  reply	other threads:[~2019-02-26  1:39 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-20 21:37 [Qemu-devel] [PATCH v5 00/14] Audio patches Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 01/14] qapi: qapi for audio backends Kővágó, Zoltán
2019-02-21 10:49   ` Gerd Hoffmann
2019-02-26  6:56   ` Markus Armbruster
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 02/14] audio: use qapi AudioFormat instead of audfmt_e Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 03/14] audio: -audiodev command line option: documentation Kővágó, Zoltán
2019-02-22 13:40   ` [Qemu-devel] [libvirt] " Daniel P. Berrangé
2019-02-22 14:09     ` Pavel Hrdina
2019-02-22 14:22     ` Gerd Hoffmann
2019-02-22 14:29       ` Daniel P. Berrangé
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 04/14] audio: -audiodev command line option basic implementation Kővágó, Zoltán
2019-02-26  1:39   ` Zoltán Kővágó [this message]
2019-03-07 15:56     ` Gerd Hoffmann
2019-03-08  0:45       ` Zoltán Kővágó
2019-03-08  7:21         ` Markus Armbruster
2019-03-08 19:40           ` Zoltán Kővágó
2019-03-11  6:42             ` Gerd Hoffmann
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 05/14] alsaaudio: port to -audiodev config Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 06/14] coreaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 07/14] dsoundaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 08/14] noaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 09/14] ossaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 10/14] paaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 11/14] sdlaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 12/14] spiceaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 13/14] wavaudio: " Kővágó, Zoltán
2019-02-20 21:37 ` [Qemu-devel] [PATCH v5 14/14] audio: -audiodev command line option: cleanup Kővágó, Zoltán

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=63250655-a4a3-ef36-5882-65188093ff57@gmail.com \
    --to=dirty.ice.hu@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=pbonzini@redhat.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 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.