All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Henningsson <david.henningsson@canonical.com>
To: Philip Spencer <pspencer@fields.utoronto.ca>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH] Wrong latency in pulseaudio plugin breaks Adobe Flash Player
Date: Fri, 17 Feb 2012 02:24:17 +0100	[thread overview]
Message-ID: <4F3DAC41.4000602@canonical.com> (raw)
In-Reply-To: <alpine.LFD.2.00.1202161015470.19707@lpc8.fields.utoronto.ca>

On 02/16/2012 04:48 PM, Philip Spencer wrote:
> When Adobe Flash player is playing a live stream in "live" (no internal
> latency) mode[1], through alsa's pulseaudio plugin, the audio is a
> half-second out of sync with the video. This is with alsa-plugins version
> 1.0.25.[2]

Hi and thanks for investigating!

> I see the problem is one already reported on the bug tracker several years
> ago (issue #3944). The plugin sets pulseaudio's target buffer length to
> match the IO buffer length, and sets the prebuffering attribute to match
> the IO buffer length less one period.
>
> In our case, the IO buffer is 500ms long, the IO period length is 20ms
> (for 16KHz Speex soud packets), and the application requests that playback
> start immediately (by setting the start_threshold software parameter very
> low).

Hmm, if you want ~20 ms of latency, why have a 500 ms long buffer in the 
first place?

> However, the plugin ignores start_threshold and sets the pulseaudio target
> buffer length to 500ms, meaning pulseaudio plays the sound with a
> half-second delay.
>
> The fix initially suggested in the bug report was to implement the
> start_threshold parameter and use it to lower the prebuffering attribute

This sounds like a reasonable thing to do.

> but this does not work: playback STARTS sooner, but when dropouts and
> underruns occur pulseaudio increases the latency to match the target
> buffer length.

Just a quick question: Are you saying there is an immediate change from 
20 to 500 ms at the first underrun, or that things gradually adapts up 
to a stable level?

> It is necessary to lower the target buffer length too.

I think this part requires more investigation though. First, I'm 
assuming you are talking about underruns between the client and 
PulseAudio, rather than underruns between PulseAudio and the hardware.

Setting a tlength of 500 ms will have PulseAudio believe you intend to 
have latency in the range of 250 - 500 ms, so you're starting with the 
buffer almost empty, and if I understand it correctly, things continue 
that way? This is usually bad and a recipe for underruns. Anyway, this 
is probably why lowering the tlength works for your particular use case.

Note though that I'm sceptic to the tlength part of the patch not mainly 
for philosophical reasons (hey, I want things to just work too!) but 
because I'm afraid it will fix some applications and break others. 
Emulating ALSA over PulseAudio is not easy due to the asynchronous 
nature of PulseAudio (among other things), and applications use and 
expect ALSA to do different things.

> [2] In 1.0.23 with low-sample-rate streams there was no sync problem but
> each sound sample was truncated, resulting in distorted and crackly sound;
> this problem has been fixed in 1.0.25 -- thanks!

Hmm, I wonder why this could be. Probably because we have changed the 
underrun handling a few times, but it always seems to improve one 
application and at the same time break another :-(

-- 
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic

  reply	other threads:[~2012-02-17  1:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-16 15:48 [PATCH] Wrong latency in pulseaudio plugin breaks Adobe Flash Player Philip Spencer
2012-02-17  1:24 ` David Henningsson [this message]
2012-02-17  4:25   ` Philip Spencer
2012-02-17  9:12     ` David Henningsson
2012-02-17 19:36       ` Philip Spencer
2012-02-17 21:15         ` Philip Spencer
2012-02-20 11:45         ` David Henningsson
2012-02-23  2:50           ` Philip Spencer
2012-02-23  8:24             ` David Henningsson
2012-02-23  9:01             ` Clemens Ladisch
2012-02-23 15:18               ` Philip Spencer

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=4F3DAC41.4000602@canonical.com \
    --to=david.henningsson@canonical.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=pspencer@fields.utoronto.ca \
    /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.