All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@gmail.com>
To: "Volker Rümelin" <vr_qemu@t-online.de>
Cc: Gerd Hoffmann <kraxel@redhat.com>,
	qemu-devel@nongnu.org,
	 Christian Schoenebeck <qemu_oss@crudebyte.com>
Subject: Re: [PATCH 04/12] alsaaudio: reduce playback latency
Date: Tue, 27 Sep 2022 15:54:25 +0400	[thread overview]
Message-ID: <CAJ+F1CJMiMPKHMAEJyrpE3DT1VXXSN1t1nbSUk6TErtt62EHng@mail.gmail.com> (raw)
In-Reply-To: <20220923183640.8314-4-vr_qemu@t-online.de>

[-- Attachment #1: Type: text/plain, Size: 2680 bytes --]

On Fri, Sep 23, 2022 at 10:51 PM Volker Rümelin <vr_qemu@t-online.de> wrote:

> Change the buffer_get_free pcm_ops function to report the free
> ALSA playback buffer. The generic buffer becomes a temporary
> buffer and is empty after a call to audio_run_out().
>
> Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
>

lgtm
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>  audio/alsaaudio.c | 38 +++++++++++++++++++++++++++++++++++++-
>  1 file changed, 37 insertions(+), 1 deletion(-)
>
> diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
> index 4a61378cd7..7a2a94cd42 100644
> --- a/audio/alsaaudio.c
> +++ b/audio/alsaaudio.c
> @@ -602,6 +602,42 @@ static int alsa_open(bool in, struct alsa_params_req
> *req,
>      return -1;
>  }
>
> +static size_t alsa_buffer_get_free(HWVoiceOut *hw)
> +{
> +    ALSAVoiceOut *alsa = (ALSAVoiceOut *)hw;
> +    snd_pcm_sframes_t avail;
> +    size_t alsa_free, generic_free, generic_in_use;
> +
> +    avail = snd_pcm_avail_update(alsa->handle);
> +    if (avail < 0) {
> +        if (avail == -EPIPE) {
> +            if (!alsa_recover(alsa->handle)) {
> +                avail = snd_pcm_avail_update(alsa->handle);
> +            }
> +        }
> +        if (avail < 0) {
> +            alsa_logerr(avail,
> +                        "Could not obtain number of available frames\n");
> +            avail = 0;
> +        }
> +    }
> +
> +    alsa_free = avail * hw->info.bytes_per_frame;
> +    generic_free = audio_generic_buffer_get_free(hw);
> +    generic_in_use = hw->samples * hw->info.bytes_per_frame -
> generic_free;
> +    if (generic_in_use) {
> +        /*
> +         * This code can only be reached in the unlikely case that
> +         * snd_pcm_avail_update() returned a larger number of frames
> +         * than snd_pcm_writei() could write. Make sure that all
> +         * remaining bytes in the generic buffer can be written.
> +         */
> +        alsa_free = alsa_free > generic_in_use ? alsa_free -
> generic_in_use : 0;
> +    }
> +
> +    return alsa_free;
> +}
> +
>  static size_t alsa_write(HWVoiceOut *hw, void *buf, size_t len)
>  {
>      ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
> @@ -916,7 +952,7 @@ static struct audio_pcm_ops alsa_pcm_ops = {
>      .init_out = alsa_init_out,
>      .fini_out = alsa_fini_out,
>      .write    = alsa_write,
> -    .buffer_get_free = audio_generic_buffer_get_free,
> +    .buffer_get_free = alsa_buffer_get_free,
>      .run_buffer_out = audio_generic_run_buffer_out,
>      .enable_out = alsa_enable_out,
>
> --
> 2.35.3
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 3671 bytes --]

  reply	other threads:[~2022-09-27 13:38 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-23 18:34 [PATCH 00/12] audio: misc. improvements and bug fixes Volker Rümelin
2022-09-23 18:36 ` [PATCH 01/12] audio: refactor code in audio_run_out() Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 02/12] audio: fix GUS audio playback with out.mixing-engine=off Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 03/12] audio: run downstream playback queue unconditionally Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 04/12] alsaaudio: reduce playback latency Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau [this message]
2022-09-23 18:36 ` [PATCH 05/12] audio: add more audio rate control functions Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 06/12] spiceaudio: add a pcm_ops buffer_get_free function Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 07/12] spiceaudio: update comment Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 08/12] audio: swap audio_rate_get_bytes() function parameters Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 09/12] audio: rename audio_sw_bytes_free() Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 10/12] audio: refactor audio_get_avail() Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 11/12] audio: fix sw->buf size for audio recording Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-10-01 12:08     ` Volker Rümelin
2022-09-23 18:36 ` [PATCH 12/12] audio: prevent an integer overflow in resampling code Volker Rümelin
2022-10-11 13:31 ` [PATCH 00/12] audio: misc. improvements and bug fixes Gerd Hoffmann

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=CAJ+F1CJMiMPKHMAEJyrpE3DT1VXXSN1t1nbSUk6TErtt62EHng@mail.gmail.com \
    --to=marcandre.lureau@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu_oss@crudebyte.com \
    --cc=vr_qemu@t-online.de \
    /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.