-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Fix AudioStreamGenerator stopping playback after a buffer underrun #73162
Conversation
Yes that was also the first thing I tried, and based on some preliminary experiments I'd also conclude that it works. I'll do some more testing and if I find something fishy I'll report back. Thank you very much for helping out so quickly! |
Perhaps a minor observation: So far the |
That's a good catch. The lookahead buffer is used for fade-out if the playback is stopped on the boundary between two 512-sample mixing windows, so it would make sense to me to fill it with silence in the case of a buffer underrun. Filling it with the last few frames of mixed audio would mean that if it's ever used for fade-out, there will be audio played immediately after the underrun's silence, then faded out to zero, which wouldn't make much sense. |
@@ -354,7 +354,7 @@ void AudioServer::_mix_step() { | |||
playback->stream_playback->tag_used_streams(); | |||
} | |||
|
|||
if (mixed_frames != buffer_size) { | |||
if (!playback->stream_playback->is_playing()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this is the wrong solution, and it should be fixed on the side of the generator code.
From what i understand, generator never ends unless you actually stop it, so if there is an underrun and a pop resulting because of it, it should be user fault IMO, but it should not return less samples. |
Right now if there's ever a single underrun, the playback is removed and no amount of filling the buffer will ever restart playback. That's what I'm trying to fix with this change. I don't understand how we could implement this in the generator without significant changes to the audio server. |
@ellenhp IMO |
Mentioned in RocketChat too but I don't have time for a playback API change right now so this will have to wait unless somebody else wants to take it up. |
Perhaps even take it a step further and require all implementors of |
Doing that would definitely work and has benefits like reduz outlined in the comments of #71780. |
@bluenote10 @ellenhp That's how it worked originally, so I suppose we could just revert that change from #51296, but at this point I feel its something that would require some significant refactoring in the audio code. The main problem is that, if the audio stream ends by itself, it should not really require ramp down. Ramp down only makes sense if you suddendly stop the audio, but currently there is no way to discern this, so IMO we will need to really think through how everything works after 4.0 is out and do the fixes later. |
@bluenote10 managed to bisect this and found it was caused by #55846. I think it's unrelated to #51296. |
@ellenhp Yes, fully in line with what my bisecting revealed -- that's why I had pinged you on #55846 initially 😉 The exact commits I had looked at were:
If I understand it correctly: #51296 prepared the logic in the audio server to terminate streams if |
@reduz I'm just wondering if this PR wouldn't still make sense as a hotfix for 4.0. After all, audio stream generation is more or less completely unusable on 4.0 currently, if the streams get terminated immediately in the majority of cases. The hotfix seems to make them fully usable again, and unless we see a specific concern why the approach may actually break something else, it would make sense to include it in the release. We could nonetheless look for a more appropriate long term solution later after 4.0 is released. |
I think at minimum reverting to a state where AudioStreamGenerator actually functions meets users basics expectations even if, architecturally, a better solution exists on the horizon. To be sure, people do use these resources and duct tape is much appreciated over breakage. It also means less people looking for help with something effectively maintained in a broken state, which has other effects on the community. |
Fixes #65155
Tweaked repro project: generator_repro.zip
The rationale here is that the number of samples mixed by a playback doesn't give us enough information to make a decision about whether to continue with that playback. I tested this with an ogg to make sure that it doesn't break playback of other streams, but it wouldn't hurt to test with other formats.