Skip to content

Commit 274aa02

Browse files
authored
audio: Let apps save an audio stream from destruction during SDL_Quit(). (#13244)
This is a special-case piece of functionality, generally these are expected to go away during shutdown, but maybe someone is switching between audio subsystems or something...
1 parent af8bee2 commit 274aa02

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

include/SDL3/SDL_audio.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,15 @@ extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_CreateAudioStream(const SDL_Au
10641064
/**
10651065
* Get the properties associated with an audio stream.
10661066
*
1067+
* The application can hang any data it wants here, but
1068+
* the following properties are understood by SDL:
1069+
*
1070+
* - `SDL_PROP_AUDIOSTREAM_KEEP_ON_SHUTDOWN_BOOLEAN`: if true, the stream will
1071+
* not be automatically destroyed during SDL_Quit(). This property is
1072+
* ignored for streams created through SDL_OpenAudioDeviceStream(). Streams
1073+
* bound to devices that aren't destroyed will still be unbound.
1074+
* Default false. (since SDL 3.4.0)
1075+
*
10671076
* \param stream the SDL_AudioStream to query.
10681077
* \returns a valid property ID on success or 0 on failure; call
10691078
* SDL_GetError() for more information.
@@ -1074,6 +1083,9 @@ extern SDL_DECLSPEC SDL_AudioStream * SDLCALL SDL_CreateAudioStream(const SDL_Au
10741083
*/
10751084
extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetAudioStreamProperties(SDL_AudioStream *stream);
10761085

1086+
#define SDL_PROP_AUDIOSTREAM_KEEP_ON_SHUTDOWN_BOOLEAN "SDL.audiostream.keep_on_shutdown"
1087+
1088+
10771089
/**
10781090
* Query the current format of an audio stream.
10791091
*

src/audio/SDL_audio.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,16 @@ void SDL_QuitAudio(void)
10731073

10741074
current_audio.impl.DeinitializeStart();
10751075

1076-
// Destroy any audio streams that still exist...
1077-
while (current_audio.existing_streams) {
1078-
SDL_DestroyAudioStream(current_audio.existing_streams);
1076+
// Destroy any audio streams that still exist...unless app asked to keep it.
1077+
SDL_AudioStream *next = NULL;
1078+
for (SDL_AudioStream *i = current_audio.existing_streams; i; i = next) {
1079+
next = i->next;
1080+
if (i->simplified || !SDL_GetBooleanProperty(i->props, SDL_PROP_AUDIOSTREAM_KEEP_ON_SHUTDOWN_BOOLEAN, false)) {
1081+
SDL_DestroyAudioStream(i);
1082+
} else {
1083+
i->prev = NULL;
1084+
i->next = NULL;
1085+
}
10791086
}
10801087

10811088
SDL_LockRWLockForWriting(current_audio.device_hash_lock);

0 commit comments

Comments
 (0)