audio: Allow audio streams to be created when the subsystem isn't initialized.

You are on your own to destroy them, though!
main
Ryan C. Gordon 2023-10-11 22:42:52 -04:00
parent 1ae33f6751
commit 2bca4671a6
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 29 additions and 22 deletions

View File

@ -139,40 +139,47 @@ static int GetDefaultSampleFramesFromFreq(const int freq)
void OnAudioStreamCreated(SDL_AudioStream *stream)
{
SDL_assert(SDL_GetCurrentAudioDriver() != NULL);
SDL_assert(stream != NULL);
// this isn't really part of the "device list" but it's a convenient lock to use here.
SDL_LockRWLockForWriting(current_audio.device_list_lock);
if (current_audio.existing_streams) {
current_audio.existing_streams->prev = stream;
// NOTE that you can create an audio stream without initializing the audio subsystem,
// but it will not be automatically destroyed during a later call to SDL_Quit!
// You must explicitly destroy it yourself!
if (current_audio.device_list_lock) {
// this isn't really part of the "device list" but it's a convenient lock to use here.
SDL_LockRWLockForWriting(current_audio.device_list_lock);
if (current_audio.existing_streams) {
current_audio.existing_streams->prev = stream;
}
stream->prev = NULL;
stream->next = current_audio.existing_streams;
current_audio.existing_streams = stream;
SDL_UnlockRWLock(current_audio.device_list_lock);
}
stream->prev = NULL;
stream->next = current_audio.existing_streams;
current_audio.existing_streams = stream;
SDL_UnlockRWLock(current_audio.device_list_lock);
}
void OnAudioStreamDestroy(SDL_AudioStream *stream)
{
SDL_assert(SDL_GetCurrentAudioDriver() != NULL);
SDL_assert(stream != NULL);
// this isn't really part of the "device list" but it's a convenient lock to use here.
SDL_LockRWLockForWriting(current_audio.device_list_lock);
if (stream->prev) {
stream->prev->next = stream->next;
// NOTE that you can create an audio stream without initializing the audio subsystem,
// but it will not be automatically destroyed during a later call to SDL_Quit!
// You must explicitly destroy it yourself!
if (current_audio.device_list_lock) {
// this isn't really part of the "device list" but it's a convenient lock to use here.
SDL_LockRWLockForWriting(current_audio.device_list_lock);
if (stream->prev) {
stream->prev->next = stream->next;
}
if (stream->next) {
stream->next->prev = stream->prev;
}
if (stream == current_audio.existing_streams) {
current_audio.existing_streams = stream->next;
}
SDL_UnlockRWLock(current_audio.device_list_lock);
}
if (stream->next) {
stream->next->prev = stream->prev;
}
if (stream == current_audio.existing_streams) {
current_audio.existing_streams = stream->next;
}
SDL_UnlockRWLock(current_audio.device_list_lock);
}
// device should be locked when calling this.
static SDL_bool AudioDeviceCanUseSimpleCopy(SDL_AudioDevice *device)
{