Bug 50024 - VLC audio track delay
Summary: VLC audio track delay
Status: RESOLVED FIXED
Alias: None
Product: PulseAudio
Classification: Unclassified
Component: core (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: pulseaudio-bugs
QA Contact: pulseaudio-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-16 12:46 UTC by Mort Yao
Modified: 2013-01-20 21:33 UTC (History)
7 users (show)

See Also:
i915 platform:
i915 features:


Attachments
vlc -vvv console output (44.23 KB, text/x-log)
2012-05-20 12:23 UTC, Gareth Hart
Details
VLC console log (22.95 KB, text/plain)
2012-06-16 19:31 UTC, Konomi
Details

Description Mort Yao 2012-05-16 12:46:29 UTC
The commit http://cgit.freedesktop.org/pulseaudio/pulseaudio/commit/?id=a813e85503355496c7ea6397e39072fd8ffedcff (sink,source: Update sample rate if possible on stream uncork) causes an audio/video synchronization issue in VLC media player (2.0.1).
The audio track always comes with a few seconds of delaying after the video starts to play (but once the video scroll bar is dragged the audio should be synchronized with the video again)
After reversed this diff the issue does not appear in VLC anymore.

The problem seems to be VLC only; Totem and MPlayer works fine with this commit.

* pulseaudio/libpulse 2.0-1
* vlc 2.0.1-1
* gnome-shell 3.4.1 on Arch x86_64
Comment 1 Gareth Hart 2012-05-20 12:23:08 UTC
Created attachment 61893 [details]
vlc -vvv console output

Also the same on my system. For your information, both VLC 2.0.1 stable package and VLC git 20120520 build show the error. I am using Arch Linux with kernel 3.3.6-1-ARCH and PulseAudio package version 2.0.1. My laptop has the Intel 6 series/C200 series chipset family high definition audio controller and the bug occurs with both the analog and IEC958 S/PDIF outputs.
Comment 2 newton.electron 2012-05-21 21:33:20 UTC
I'm also getting the same error with pulseaudio 2.0-1. I'm using kernel 3.3.6-1-ARCH.

Audio device: Intel Corporation 82801H (ICH8 Family) HD Audio Controller
Comment 3 Konomi 2012-06-16 19:31:49 UTC
Created attachment 63123 [details]
VLC console log
Comment 4 Konomi 2012-06-16 19:32:23 UTC
I am also having this problem on debian. I have not noticed a delay but it causes my audio to crackle which is very annoying.

Versions:

VLC media player 2.0.1 Twoflower (revision 2.0.1-0-gf432547)
VLC version 2.0.1 Twoflower (2.0.1-0-gf432547)
Compiled by pbuilder on www.marillat.net (May 29 2012 16:35:24)
Compiler: gcc version 4.7.0 (Debian 4.7.0-10)

pulseaudio 2.0

Here is where someone posted the bug to vlc's bug tracker: https://trac.videolan.org/vlc/ticket/6853. It has been marked as notvlc so I presume this is a pulseaudio issue.

I've attached my vlc log.
Comment 5 Konomi 2012-06-16 22:19:56 UTC
It seems the problem is intermittent and present at the start for me. For example at the start I see this and eventually it gets to 44100hz.

[0xe7f978] pulse audio output warning: too late by 63581 us
[0xe7f978] pulse audio output debug: changed sample rate to 44343 Hz
[0xe7f978] pulse audio output warning: too late by 63074 us
[0xe7f978] pulse audio output debug: changed sample rate to 44381 Hz
[0xe7f978] pulse audio output warning: too late by 62122 us
[0xe7f978] pulse audio output debug: changed sample rate to 44413 Hz
[0xe7f978] pulse audio output warning: too late by 60691 us
[0xe7f978] pulse audio output debug: changed sample rate to 44439 Hz
[0xe7f978] pulse audio output debug: changed sample rate to 44353 Hz
[0xe7f978] pulse audio output debug: changed sample rate to 44267 Hz
[0xe7f978] pulse audio output debug: changed sample rate to 44181 Hz
[0xe7f978] pulse audio output debug: changed sample rate to 44100 Hz

While the too late by x ms is happening other sounds in my system distort or crackle. Will test further on request.
Comment 6 Leszek Lesner 2012-10-17 11:58:38 UTC
Opening /etc/pulse/default.pa and disabling timerbased scheduling by replacing 
load-module module-udev-detect 
with 
load-module module-udev-detect tsched=0
solves the problem here after a reboot.
Comment 7 Yichao Zhou 2013-01-16 06:43:19 UTC
Same here.  Really annoying for VLC user.

I'm not familar with pa so I cannot say whether this patch is has something wrong or not.  !!!!!!!But this commit broken the userspace!!!!!!!   Should it be reverted?

It's 7 month after this bug has been reported.  Should the developer say something to show that this bug is not totally ignored?
Comment 8 Tanu Kaskinen 2013-01-16 15:21:20 UTC
(In reply to comment #7)
> Same here.  Really annoying for VLC user.
> 
> I'm not familar with pa so I cannot say whether this patch is has something
> wrong or not.  !!!!!!!But this commit broken the userspace!!!!!!!   Should
> it be reverted?
> 
> It's 7 month after this bug has been reported.  Should the developer say
> something to show that this bug is not totally ignored?

Sure, I can say something. The problematic commit implements a useful feature, so it probably won't be simply reverted. A better fix is needed (patches very welcome). There have been fixes related to the sample rate updating since pulseaudio 2.0, so it's worth retrying with pulseaudio 3.0, but I don't remember that those fixes would have been timing related, so don't expect too much.
Comment 9 Tanu Kaskinen 2013-01-16 15:30:03 UTC
(In reply to comment #8)
> (In reply to comment #7)
> > Same here.  Really annoying for VLC user.
> > 
> > I'm not familar with pa so I cannot say whether this patch is has something
> > wrong or not.  !!!!!!!But this commit broken the userspace!!!!!!!   Should
> > it be reverted?
> > 
> > It's 7 month after this bug has been reported.  Should the developer say
> > something to show that this bug is not totally ignored?
> 
> Sure, I can say something. The problematic commit implements a useful
> feature, so it probably won't be simply reverted. A better fix is needed
> (patches very welcome). There have been fixes related to the sample rate
> updating since pulseaudio 2.0, so it's worth retrying with pulseaudio 3.0,
> but I don't remember that those fixes would have been timing related, so
> don't expect too much.

Thinking a bit more, reverting the patch (or maybe commenting out the code would be better) is maybe the right approach after all, if nobody submits a better fix. Removing the code that was added that patch shouldn't really break anything, the only effect should be that there's sometimes unnecessary resampling, which is better than breaking the timing of applications.
Comment 10 Tanu Kaskinen 2013-01-16 15:39:06 UTC
Before removing any functionality, this must be reproducible by a pulseaudio developer, though. Otherwise there's no way to know when it's safe to add the functionality back. I can't reproduce this with vlc version 2.0.3 and pulseaudio's current development version. I'll try installing vlc 2.0.1 and pulseaudio 2.0 later today.
Comment 11 Remi Denis-Courmont 2013-01-16 16:28:53 UTC
This affects all VLC versions (however please avoid VLC version 2.0.4, which has an audio latency bug of its own), with PulseAudio 2.x.
Comment 12 Tanu Kaskinen 2013-01-18 20:20:05 UTC
Any further hints for reproducing? I have pulseaudio 2.0 installed, and since vlc version shouldn't matter, I still have vlc 2.0.3, not 2.0.1 that the original reporter used. A/V sync is just fine for me, with both pulseaudio and alsa (through pulseaudio) backends of vlc.
Comment 13 Remi Denis-Courmont 2013-01-18 20:31:24 UTC
For me, the bug strikes when all of the following conditions are met:
- The sink (Intel HDA) is inactive.
- The new sink input is created with the _same_ sample rate as the last sink input that was previous connected to the sink.
- Alternate rate is enabled (44100 and 48000).
Correlation/Reproducibility is 100%.

Then there is approximately 2 seconds delay between VLC "trigger"ing its sink input and PulseAudio actually starting playback. (Note that VLC uses manual trigger.)

The bug does NOT strike when alternating sample rate.
The bug does NOT strike when alternate rate are disabled in the configuration.
That is very confusing.
Comment 14 Tanu Kaskinen 2013-01-18 22:11:45 UTC
I was now able to reproduce this. For me this doesn't seem to happen 100% of the time (I test by running "vlc ~/misc/sync_test.mp4", observing the A/V sync, closing vlc, waiting for the sink to suspend, and trying again). The small hardware buffer size that I have (371 ms) might make noticing the delay harder, if the delay is variable, but if it's always one full hw buffer size in length, then I should be able to reliably notice it... I'll build a custom kernel next with a bigger audio buffer, and see if that changes anything.

Btw, Remi, you said that "this affects all VLC versions [...] with PulseAudio 2.x." Do you mean that this doesn't affect 3.0?
Comment 15 Remi Denis-Courmont 2013-01-18 22:27:29 UTC
Did not try PA 3.x, so far not landed in Debian unstable.
Comment 16 Tanu Kaskinen 2013-01-20 21:33:02 UTC
With bigger hw buffer I was able to reproduce the problem 100% of time on pulseaudio 2.0. With the current development version I can't reproduce the problem. Thus, resolving the bug as fixed.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.