audio: Added SDL_SetAudioIterationCallbacks(). #12763
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a hook that runs in the audio device thread, before it starts processing bound audio streams, and a second hook that runs after.
The specific need here: the SDL_mixer rewrite wants to be able to change things on multiple tracks (what SDL2_mixer calls "channels") atomically. For example, stopping multiple tracks with a fadeout should have them all start fading at the exact same time, which it can't accomplish if the device thread is halfway through processing streams when SDL_mixer tries to start the fade...some will be fading a little sooner than the rest.
A generic "lock the whole device" API wasn't feasible, since there's already a ton of locking needed to find the lock that applies to the SDL_AudioDeviceID the app would have, so when one goes to unlock the device later, we'd have to grab those initial locks again in a different order (as the app is holding the final lock at the time), risking deadlock in normal situations.