diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index a031686ab..87c4df866 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -1191,6 +1191,13 @@ void SDL_UpdatedAudioDeviceFormat(SDL_AudioDevice *device) device->buffer_size = device->sample_frames * (SDL_AUDIO_BITSIZE(device->spec.format) / 8) * device->spec.channels; } +char *SDL_GetAudioThreadName(SDL_AudioDevice *device, char *buf, size_t buflen) +{ + (void)SDL_snprintf(buf, buflen, "SDLAudio%c%d", (device->iscapture) ? 'C' : 'P', (int) device->instance_id); + return buf; +} + + // this expects the device lock to be held. static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec *inspec) { @@ -1236,7 +1243,7 @@ static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec if (!current_audio.impl.ProvidesOwnCallbackThread) { const size_t stacksize = 0; // just take the system default, since audio streams might have callbacks. char threadname[64]; - (void)SDL_snprintf(threadname, sizeof(threadname), "SDLAudio%c%d", (device->iscapture) ? 'C' : 'P', (int) device->instance_id); + SDL_GetAudioThreadName(device, threadname, sizeof (threadname)); device->thread = SDL_CreateThreadInternal(device->iscapture ? CaptureAudioThread : OutputAudioThread, threadname, stacksize, device); if (device->thread == NULL) { diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h index ecf2fcb0a..1653ea44b 100644 --- a/src/audio/SDL_sysaudio.h +++ b/src/audio/SDL_sysaudio.h @@ -91,6 +91,9 @@ extern SDL_AudioDevice *SDL_ObtainPhysicalAudioDeviceByHandle(void *handle); /* Backends should call this if they change the device format, channels, freq, or sample_frames to keep other state correct. */ extern void SDL_UpdatedAudioDeviceFormat(SDL_AudioDevice *device); +// Backends can call this to get a standardized name for a thread to power a specific audio device. +char *SDL_GetAudioThreadName(SDL_AudioDevice *device, char *buf, size_t buflen); + /* These functions are the heart of the audio threads. Backends can call them directly if they aren't using the SDL-provided thread. */ extern void SDL_OutputAudioThreadSetup(SDL_AudioDevice *device); diff --git a/src/audio/pipewire/SDL_pipewire.c b/src/audio/pipewire/SDL_pipewire.c index eac531bf1..170b6d746 100644 --- a/src/audio/pipewire/SDL_pipewire.c +++ b/src/audio/pipewire/SDL_pipewire.c @@ -1122,7 +1122,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device) SDL_UpdatedAudioDeviceFormat(device); - (void)SDL_snprintf(thread_name, sizeof(thread_name), "SDLAudio%c%ld", (iscapture) ? 'C' : 'P', (long)device->handle); + SDL_GetAudioThreadName(device, thread_name, sizeof(thread_name)); priv->loop = PIPEWIRE_pw_thread_loop_new(thread_name, NULL); if (priv->loop == NULL) { return SDL_SetError("Pipewire: Failed to create stream loop (%i)", errno);