Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio glitchiness in Firefox after its been left open for a while #50

Closed
trlkly opened this issue Apr 10, 2017 · 10 comments
Closed

Audio glitchiness in Firefox after its been left open for a while #50

trlkly opened this issue Apr 10, 2017 · 10 comments

Comments

@trlkly
Copy link

trlkly commented Apr 10, 2017

I don't know if the problem is with Firefox (as it has similar problems on Windows), but I thought I'd try here first.

I tend leave Firefox open for long periods of time. I find that, when I come back after a long period (12 hours or more) and then load a video, the audio is all glitchy and stuttery, as if there is not enough memory and it is having to cache to disk. But my I don't use a swap partition on my Linux distro, so that's not it. I also hear similar problems when a process is running the CPU at 100%, but that is also not the case with this bug.

The Windows issue I mention earlier often clears up as the video continues playing. But, with this bug, only restarting Firefox works to fix it.

If I have left Firefox on a particular video tab, sometimes that video's audio is fine. But any other videos (whether from another tab or loading from somewhere else) is quite glitchy sounding.

So, tl;dr version: Firefox (52.0.2) audio stutters really badly on videos if I have left Firefox open for a long period of time (>12 hours). Restarting Firefox fixes the problem.

The stuttering is similar to what happens when the CPU is overtaxed, or when the computer is running out of memory, but neither is the case for this bug.

@i-rinat
Copy link
Owner

i-rinat commented Apr 10, 2017

This will be hard to reproduce (for me), as I tend to do the opposite: close and start browser quite often.

By the way, when audio glitches appear, do they appear if you run some other audio application too? In other words, if you experience audio stuttering, try to mute all Firefox tabs, and start audio player. Does it play audio fine? It's also worth to try run audio player through both ALSA and apulse, and compare results. Perhaps, there is something wrong in the way apulse handles audio.

@i-rinat
Copy link
Owner

i-rinat commented Apr 10, 2017

Also, runtime power management may interfere. You can use powertop utility to find out whenever power management is enabled for various devices. It's in "Tunables" tab.

If PM was enabled, try to disable it and test again.

@trlkly
Copy link
Author

trlkly commented Apr 19, 2017

Sorry it took me so long, but it took a while for the problem to crop up again.

There are no problems with ALSA using VLC. There are problems playing audio in any other tab. And powertop only reports on my CPU, where I've actually turned off throttling due to other issues. That said, it seems that Firefox's content process is using up more CPU on idle than I would expect. It seems to be maxing out one of my cores.

Since restarting the content process fixes it, I don't think my CPU is being throttled down. It may be a runaway thread in Firefox. I didn't have them back when I was using the ALSA backend, but that was a different version of Firefox.

Since I have no real need to use my computer right now, I can try to leave it in its current condition, so I can test anything else you want to offer.

That said, I am aware the problem may have nothing to do with apulse. I do have a similar problem on my Windows computer sometimes. Though it seems to happen without any cores being maxed out.

@i-rinat
Copy link
Owner

i-rinat commented Apr 19, 2017

so I can test anything else you want to offer

Sorry, I have no ideas left. I could guess there are buffer underruns/overruns, they sound like clicks or stuttering. But that hypothesis doesn't explain why one need to keep application running for so long to make the bug appear.

Recently, I've added some code that handles x-runs and prevents them: ec575ce...86f0841. Main part of the fix is the code which calculates buffer_size. It turned out that on the current machine I have a limit of 940 frames. Periods can't be shorter than that. So if application asks for 300 frames period and 1200 frames buffer, which is completely fine with buffer having four periods, it gets 940 frames period and 1200 frames buffer. That made buffer x-run happen almost immediately.

Now buffer sizes are enlarged as needed. So it's worth to try v0.1.10, which have changes mentioned above.

@h1z1
Copy link

h1z1 commented Apr 19, 2017

What soundcard / driver are you using? What kernel version? What is firefox actually doing? (strace or gdb backtrace). And, by "ALSA works using VLC", do you mean playing a file for 12 hours or leaving it running ?

Could very well be the sound card is going into powersave and not coming out properly. Off the top of my head I don't recall if VLC leaves the card open while not in use. Firefox should be closing it when not in use specifically to allow power save.

@trlkly
Copy link
Author

trlkly commented Apr 20, 2017 via email

@Alexander--
Copy link

Alexander-- commented Apr 20, 2017

@trlkly have you had a look at powertop? The corresponding option is "Enable Audio codec power management" ("Bad" means, that power optimisations are disabled). If you have a USB audio card, have a glance at USB powersaving options too.

@trlkly
Copy link
Author

trlkly commented Apr 20, 2017 via email

@i-rinat
Copy link
Owner

i-rinat commented Apr 20, 2017

Firefox's content process is constantly pegging one of my CPU cores, even when I'm not playing audio

If I had similar issue, first step was to try to run perf top first while running distribution-supplied Firefox version, to find out where CPU time is spent. Next step is to try the same with Firefox built from source with debug information enabled. That could reduce scope of suspected code.

@trlkly
Copy link
Author

trlkly commented May 12, 2017

I've not encountered this for a while, so I'm going to tentatively close it.

If I know my luck, if it's gonna come back, it will come up now that I've done so. So I might as well hurry it along.

@trlkly trlkly closed this as completed May 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants