audio: unify device thread naming.

main
Ryan C. Gordon 2023-07-03 20:35:58 -04:00
parent 258bc9efed
commit 8473e522e0
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
3 changed files with 12 additions and 2 deletions

View File

@ -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; 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. // this expects the device lock to be held.
static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec *inspec) 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) { if (!current_audio.impl.ProvidesOwnCallbackThread) {
const size_t stacksize = 0; // just take the system default, since audio streams might have callbacks. const size_t stacksize = 0; // just take the system default, since audio streams might have callbacks.
char threadname[64]; 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); device->thread = SDL_CreateThreadInternal(device->iscapture ? CaptureAudioThread : OutputAudioThread, threadname, stacksize, device);
if (device->thread == NULL) { if (device->thread == NULL) {

View File

@ -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. */ /* 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); 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. */ /* 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); extern void SDL_OutputAudioThreadSetup(SDL_AudioDevice *device);

View File

@ -1122,7 +1122,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
SDL_UpdatedAudioDeviceFormat(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); priv->loop = PIPEWIRE_pw_thread_loop_new(thread_name, NULL);
if (priv->loop == NULL) { if (priv->loop == NULL) {
return SDL_SetError("Pipewire: Failed to create stream loop (%i)", errno); return SDL_SetError("Pipewire: Failed to create stream loop (%i)", errno);