From 3699b12ed0a25b0667b23ed18fa0a60c800ede9d Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 29 Aug 2023 10:46:14 -0400
Subject: [PATCH] audio: Fixed some "is_*" variables to be cleaner and/or more
specific.
Requested at https://github.com/libsdl-org/SDL/pull/8165#discussion_r1306700881_
---
src/audio/SDL_audio.c | 46 ++++++++++++++++++++--------------------
src/audio/SDL_audiocvt.c | 6 +++---
src/audio/SDL_sysaudio.h | 8 +++----
3 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index c2b2e0598b3d..2f2116edc871 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -336,7 +336,7 @@ void SDL_AudioDeviceDisconnected(SDL_AudioDevice *device)
SDL_LogicalAudioDevice *next = NULL;
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev != NULL; logdev = next) {
next = logdev->next;
- if (!logdev->is_default) { // if opened as a default, leave it on the zombie device for later migration.
+ if (!logdev->opened_as_default) { // if opened as a default, leave it on the zombie device for later migration.
DisconnectLogicalAudioDevice(logdev);
}
}
@@ -1043,16 +1043,16 @@ int SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec)
return SDL_InvalidParamError("spec");
}
- SDL_bool is_default = SDL_FALSE;
+ SDL_bool wants_default = SDL_FALSE;
if (devid == SDL_AUDIO_DEVICE_DEFAULT_OUTPUT) {
devid = current_audio.default_output_device_id;
- is_default = SDL_TRUE;
+ wants_default = SDL_TRUE;
} else if (devid == SDL_AUDIO_DEVICE_DEFAULT_CAPTURE) {
devid = current_audio.default_capture_device_id;
- is_default = SDL_TRUE;
+ wants_default = SDL_TRUE;
}
- if ((devid == 0) && is_default) {
+ if ((devid == 0) && wants_default) {
return SDL_SetError("No default audio device available");
}
@@ -1081,9 +1081,9 @@ static void ClosePhysicalAudioDevice(SDL_AudioDevice *device)
SDL_AtomicSet(&device->thread_alive, 0);
}
- if (device->is_opened) {
+ if (device->currently_opened) {
current_audio.impl.CloseDevice(device); // if ProvidesOwnCallbackThread, this must join on any existing device thread before returning!
- device->is_opened = SDL_FALSE;
+ device->currently_opened = SDL_FALSE;
device->hidden = NULL; // just in case.
}
@@ -1190,7 +1190,7 @@ char *SDL_GetAudioThreadName(SDL_AudioDevice *device, char *buf, size_t buflen)
// this expects the device lock to be held.
static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec *inspec)
{
- SDL_assert(!device->is_opened);
+ SDL_assert(!device->currently_opened);
SDL_assert(device->logical_devices == NULL);
// Just pretend to open a zombie device. It can still collect logical devices on the assumption they will all migrate when the default device is officially changed.
@@ -1212,7 +1212,7 @@ static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec
device->sample_frames = GetDefaultSampleFramesFromFreq(device->spec.freq);
SDL_UpdatedAudioDeviceFormat(device); // start this off sane.
- device->is_opened = SDL_TRUE; // mark this true even if impl.OpenDevice fails, so we know to clean up.
+ device->currently_opened = SDL_TRUE; // mark this true even if impl.OpenDevice fails, so we know to clean up.
if (current_audio.impl.OpenDevice(device) < 0) {
ClosePhysicalAudioDevice(device); // clean up anything the backend left half-initialized.
return -1;
@@ -1252,16 +1252,16 @@ SDL_AudioDeviceID SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSp
return 0;
}
- SDL_bool is_default = SDL_FALSE;
+ SDL_bool wants_default = SDL_FALSE;
if (devid == SDL_AUDIO_DEVICE_DEFAULT_OUTPUT) {
devid = current_audio.default_output_device_id;
- is_default = SDL_TRUE;
+ wants_default = SDL_TRUE;
} else if (devid == SDL_AUDIO_DEVICE_DEFAULT_CAPTURE) {
devid = current_audio.default_capture_device_id;
- is_default = SDL_TRUE;
+ wants_default = SDL_TRUE;
}
- if ((devid == 0) && is_default) {
+ if ((devid == 0) && wants_default) {
SDL_SetError("No default audio device available");
return 0;
}
@@ -1274,7 +1274,7 @@ SDL_AudioDeviceID SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSp
} else {
SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(devid); // this locks the physical device, too.
if (logdev) {
- is_default = logdev->is_default; // was the original logical device meant to be a default? Make this one, too.
+ wants_default = logdev->opened_as_default; // was the original logical device meant to be a default? Make this one, too.
device = logdev->physical_device;
}
}
@@ -1283,18 +1283,18 @@ SDL_AudioDeviceID SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSp
if (device) {
SDL_LogicalAudioDevice *logdev = NULL;
- if (!is_default && SDL_AtomicGet(&device->zombie)) {
+ if (!wants_default && SDL_AtomicGet(&device->zombie)) {
// uhoh, this device is undead, and just waiting for a new default device to be declared so it can hand off to it. Refuse explicit opens.
SDL_SetError("Device was already lost and can't accept new opens");
} else if ((logdev = (SDL_LogicalAudioDevice *) SDL_calloc(1, sizeof (SDL_LogicalAudioDevice))) == NULL) {
SDL_OutOfMemory();
- } else if (!device->is_opened && OpenPhysicalAudioDevice(device, spec) == -1) { // first thing using this physical device? Open at the OS level...
+ } else if (!device->currently_opened && OpenPhysicalAudioDevice(device, spec) == -1) { // first thing using this physical device? Open at the OS level...
SDL_free(logdev);
} else {
SDL_AtomicSet(&logdev->paused, 0);
retval = logdev->instance_id = assign_audio_device_instance_id(device->iscapture, /*islogical=*/SDL_TRUE);
logdev->physical_device = device;
- logdev->is_default = is_default;
+ logdev->opened_as_default = wants_default;
logdev->next = device->logical_devices;
if (device->logical_devices) {
device->logical_devices->prev = logdev;
@@ -1357,7 +1357,7 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int
return SDL_SetError("Audio streams are bound to device ids from SDL_OpenAudioDevice, not raw physical devices");
} else if ((logdev = ObtainLogicalAudioDevice(devid)) == NULL) {
return -1; // ObtainLogicalAudioDevice set the error message.
- } else if (logdev->is_simplified) {
+ } else if (logdev->simplified) {
SDL_UnlockMutex(logdev->physical_device->lock);
return SDL_SetError("Cannot change stream bindings on device opened with SDL_OpenAudioDeviceStream");
}
@@ -1464,7 +1464,7 @@ void SDL_UnbindAudioStreams(SDL_AudioStream **streams, int num_streams)
for (int i = 0; i < num_streams; i++) {
SDL_AudioStream *stream = streams[i];
// don't allow unbinding from "simplified" devices (opened with SDL_OpenAudioDeviceStream). Just ignore them.
- if (stream && stream->bound_device && !stream->bound_device->is_simplified) {
+ if (stream && stream->bound_device && !stream->bound_device->simplified) {
if (stream->bound_device->bound_streams == stream) {
SDL_assert(stream->prev_binding == NULL);
stream->bound_device->bound_streams = stream->next_binding;
@@ -1546,8 +1546,8 @@ SDL_AudioStream *SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_Au
stream = NULL;
}
- logdev->is_simplified = SDL_TRUE; // forbid further binding changes on this logical device.
- stream->is_simplified = SDL_TRUE; // so we know to close the audio device when this is destroyed.
+ logdev->simplified = SDL_TRUE; // forbid further binding changes on this logical device.
+ stream->simplified = SDL_TRUE; // so we know to close the audio device when this is destroyed.
if (callback) {
int rc;
@@ -1625,7 +1625,7 @@ void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device)
SDL_bool needs_migration = SDL_FALSE;
SDL_zero(spec);
for (SDL_LogicalAudioDevice *logdev = current_default_device->logical_devices; logdev != NULL; logdev = logdev->next) {
- if (logdev->is_default) {
+ if (logdev->opened_as_default) {
needs_migration = SDL_TRUE;
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = stream->next_binding) {
const SDL_AudioSpec *streamspec = iscapture ? &stream->dst_spec : &stream->src_spec;
@@ -1655,7 +1655,7 @@ void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device)
for (SDL_LogicalAudioDevice *logdev = current_default_device->logical_devices; logdev != NULL; logdev = next) {
next = logdev->next;
- if (!logdev->is_default) {
+ if (!logdev->opened_as_default) {
continue; // not opened as a default, leave it on the current physical device.
}
diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c
index da388d39c59d..5b3feb0448c3 100644
--- a/src/audio/SDL_audiocvt.c
+++ b/src/audio/SDL_audiocvt.c
@@ -1281,9 +1281,9 @@ int SDL_ClearAudioStream(SDL_AudioStream *stream)
void SDL_DestroyAudioStream(SDL_AudioStream *stream)
{
if (stream) {
- const SDL_bool is_simplified = stream->is_simplified;
- if (is_simplified) {
- SDL_assert(stream->bound_device->is_simplified);
+ const SDL_bool simplified = stream->simplified;
+ if (simplified) {
+ SDL_assert(stream->bound_device->simplified);
SDL_CloseAudioDevice(stream->bound_device->instance_id); // this will unbind the stream.
} else {
SDL_UnbindAudioStream(stream);
diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h
index 65e0cb89efdb..81104e594eb9 100644
--- a/src/audio/SDL_sysaudio.h
+++ b/src/audio/SDL_sysaudio.h
@@ -187,7 +187,7 @@ struct SDL_AudioStream
int packetlen;
- SDL_bool is_simplified; // SDL_TRUE if created via SDL_OpenAudioDeviceStream
+ SDL_bool simplified; // SDL_TRUE if created via SDL_OpenAudioDeviceStream
SDL_LogicalAudioDevice *bound_device;
SDL_AudioStream *next_binding;
@@ -213,10 +213,10 @@ struct SDL_LogicalAudioDevice
SDL_AudioStream *bound_streams;
// SDL_TRUE if this was opened as a default device.
- SDL_bool is_default;
+ SDL_bool opened_as_default;
// SDL_TRUE if device was opened with SDL_OpenAudioDeviceStream (so it forbids binding changes, etc).
- SDL_bool is_simplified;
+ SDL_bool simplified;
// double-linked list of opened devices on the same physical device.
SDL_LogicalAudioDevice *next;
@@ -272,7 +272,7 @@ struct SDL_AudioDevice
SDL_Thread *thread;
// SDL_TRUE if this physical device is currently opened by the backend.
- SDL_bool is_opened;
+ SDL_bool currently_opened;
// Data private to this driver
struct SDL_PrivateAudioData *hidden;