mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-21 04:53:03 +08:00
Pointer as bool (libsdl-org#7214)
This commit is contained in:
@@ -385,7 +385,7 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO);
|
||||
if (state == NULL) {
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -448,7 +448,7 @@ main(int argc, char *argv[])
|
||||
/* Create the windows, initialize the renderers, and load the textures */
|
||||
sprites =
|
||||
(SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
|
||||
if (sprites == NULL) {
|
||||
if (!sprites) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
@@ -463,7 +463,7 @@ main(int argc, char *argv[])
|
||||
|
||||
soundname = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
|
||||
|
||||
if (soundname == NULL) {
|
||||
if (!soundname) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
window = SDL_CreateWindow("Hello SDL", 640, 480, 0);
|
||||
if (window == NULL) {
|
||||
if (!window) {
|
||||
SDL_Log("could not create window: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -557,7 +557,7 @@ int SDL_GetVersion(SDL_version *ver)
|
||||
static SDL_bool check_hint = SDL_TRUE;
|
||||
static SDL_bool legacy_version = SDL_FALSE;
|
||||
|
||||
if (ver == NULL) {
|
||||
if (!ver) {
|
||||
return SDL_InvalidParamError("ver");
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -106,11 +106,11 @@ static void SDL_GenerateAssertionReport(void)
|
||||
const SDL_AssertData *item = triggered_assertions;
|
||||
|
||||
/* only do this if the app hasn't assigned an assertion handler. */
|
||||
if ((item != NULL) && (assertion_handler != SDL_PromptAssertion)) {
|
||||
if ((item) && (assertion_handler != SDL_PromptAssertion)) {
|
||||
debug_print("\n\nSDL assertion report.\n");
|
||||
debug_print("All SDL assertions between last init/quit:\n\n");
|
||||
|
||||
while (item != NULL) {
|
||||
while (item) {
|
||||
debug_print(
|
||||
"'%s'\n"
|
||||
" * %s (%s:%d)\n"
|
||||
@@ -198,7 +198,7 @@ static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, v
|
||||
|
||||
/* let env. variable override, so unit tests won't block in a GUI. */
|
||||
envr = SDL_getenv("SDL_ASSERT");
|
||||
if (envr != NULL) {
|
||||
if (envr) {
|
||||
if (message != stack_buf) {
|
||||
SDL_free(message);
|
||||
}
|
||||
@@ -334,9 +334,9 @@ SDL_AssertState SDL_ReportAssertion(SDL_AssertData *data, const char *func, cons
|
||||
#ifndef SDL_THREADS_DISABLED
|
||||
static SDL_SpinLock spinlock = 0;
|
||||
SDL_AtomicLock(&spinlock);
|
||||
if (assertion_mutex == NULL) { /* never called SDL_Init()? */
|
||||
if (!assertion_mutex) { /* never called SDL_Init()? */
|
||||
assertion_mutex = SDL_CreateMutex();
|
||||
if (assertion_mutex == NULL) {
|
||||
if (!assertion_mutex) {
|
||||
SDL_AtomicUnlock(&spinlock);
|
||||
return SDL_ASSERTION_IGNORE; /* oh well, I guess. */
|
||||
}
|
||||
@@ -401,7 +401,7 @@ void SDL_AssertionsQuit(void)
|
||||
#if SDL_ASSERT_LEVEL > 0
|
||||
SDL_GenerateAssertionReport();
|
||||
#ifndef SDL_THREADS_DISABLED
|
||||
if (assertion_mutex != NULL) {
|
||||
if (assertion_mutex) {
|
||||
SDL_DestroyMutex(assertion_mutex);
|
||||
assertion_mutex = NULL;
|
||||
}
|
||||
@@ -429,7 +429,7 @@ void SDL_ResetAssertionReport(void)
|
||||
{
|
||||
SDL_AssertData *next = NULL;
|
||||
SDL_AssertData *item;
|
||||
for (item = triggered_assertions; item != NULL; item = next) {
|
||||
for (item = triggered_assertions; item; item = next) {
|
||||
next = (SDL_AssertData *)item->next;
|
||||
item->always_ignore = SDL_FALSE;
|
||||
item->trigger_count = 0;
|
||||
@@ -446,7 +446,7 @@ SDL_AssertionHandler SDL_GetDefaultAssertionHandler(void)
|
||||
|
||||
SDL_AssertionHandler SDL_GetAssertionHandler(void **userdata)
|
||||
{
|
||||
if (userdata != NULL) {
|
||||
if (userdata) {
|
||||
*userdata = assertion_userdata;
|
||||
}
|
||||
return assertion_handler;
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
int SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
|
||||
{
|
||||
/* Ignore call if invalid format pointer was passed */
|
||||
if (fmt != NULL) {
|
||||
if (fmt) {
|
||||
va_list ap;
|
||||
int result;
|
||||
SDL_error *error = SDL_GetErrBuf();
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ int SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID)
|
||||
static const char k_rgchHexToASCII[] = "0123456789abcdef";
|
||||
int i;
|
||||
|
||||
if (pszGUID == NULL) {
|
||||
if (!pszGUID) {
|
||||
return SDL_InvalidParamError("pszGUID");
|
||||
}
|
||||
if (cbGUID <= 0) {
|
||||
|
||||
+15
-15
@@ -53,13 +53,13 @@ SDL_HashTable *SDL_CreateHashTable(void *data, const Uint32 num_buckets, const S
|
||||
}
|
||||
|
||||
table = (SDL_HashTable *) SDL_calloc(1, sizeof (SDL_HashTable));
|
||||
if (table == NULL) {
|
||||
if (!table) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
table->table = (SDL_HashItem **) SDL_calloc(num_buckets, sizeof (SDL_HashItem *));
|
||||
if (table->table == NULL) {
|
||||
if (!table->table) {
|
||||
SDL_free(table);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
@@ -91,7 +91,7 @@ SDL_bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const vo
|
||||
|
||||
// !!! FIXME: grow and rehash table if it gets too saturated.
|
||||
item = (SDL_HashItem *) SDL_malloc(sizeof (SDL_HashItem));
|
||||
if (item == NULL) {
|
||||
if (!item) {
|
||||
SDL_OutOfMemory();
|
||||
return SDL_FALSE;
|
||||
}
|
||||
@@ -110,9 +110,9 @@ SDL_bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const
|
||||
void *data = table->data;
|
||||
SDL_HashItem *i;
|
||||
|
||||
for (i = table->table[hash]; i != NULL; i = i->next) {
|
||||
for (i = table->table[hash]; i; i = i->next) {
|
||||
if (table->keymatch(key, i->key, data)) {
|
||||
if (_value != NULL) {
|
||||
if (_value) {
|
||||
*_value = i->value;
|
||||
}
|
||||
return SDL_TRUE;
|
||||
@@ -129,9 +129,9 @@ SDL_bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key)
|
||||
SDL_HashItem *prev = NULL;
|
||||
void *data = table->data;
|
||||
|
||||
for (item = table->table[hash]; item != NULL; item = item->next) {
|
||||
for (item = table->table[hash]; item; item = item->next) {
|
||||
if (table->keymatch(key, item->key, data)) {
|
||||
if (prev != NULL) {
|
||||
if (prev) {
|
||||
prev->next = item->next;
|
||||
} else {
|
||||
table->table[hash] = item->next;
|
||||
@@ -152,7 +152,7 @@ SDL_bool SDL_IterateHashTableKey(const SDL_HashTable *table, const void *key, co
|
||||
{
|
||||
SDL_HashItem *item = *iter ? ((SDL_HashItem *) *iter)->next : table->table[calc_hash(table, key)];
|
||||
|
||||
while (item != NULL) {
|
||||
while (item) {
|
||||
if (table->keymatch(key, item->key, table->data)) {
|
||||
*_value = item->value;
|
||||
*iter = item;
|
||||
@@ -172,10 +172,10 @@ SDL_bool SDL_IterateHashTable(const SDL_HashTable *table, const void **_key, con
|
||||
SDL_HashItem *item = (SDL_HashItem *) *iter;
|
||||
Uint32 idx = 0;
|
||||
|
||||
if (item != NULL) {
|
||||
if (item) {
|
||||
const SDL_HashItem *orig = item;
|
||||
item = item->next;
|
||||
if (item == NULL) {
|
||||
if (!item) {
|
||||
idx = calc_hash(table, orig->key) + 1; // !!! FIXME: we probably shouldn't rehash each time.
|
||||
}
|
||||
}
|
||||
@@ -184,7 +184,7 @@ SDL_bool SDL_IterateHashTable(const SDL_HashTable *table, const void **_key, con
|
||||
item = table->table[idx++]; // skip empty buckets...
|
||||
}
|
||||
|
||||
if (item == NULL) { // no more matches?
|
||||
if (!item) { // no more matches?
|
||||
*_key = NULL;
|
||||
*iter = NULL;
|
||||
return SDL_FALSE;
|
||||
@@ -199,12 +199,12 @@ SDL_bool SDL_IterateHashTable(const SDL_HashTable *table, const void **_key, con
|
||||
|
||||
SDL_bool SDL_HashTableEmpty(SDL_HashTable *table)
|
||||
{
|
||||
if (table != NULL) {
|
||||
if (table) {
|
||||
Uint32 i;
|
||||
|
||||
for (i = 0; i < table->table_len; i++) {
|
||||
SDL_HashItem *item = table->table[i];
|
||||
if (item != NULL) {
|
||||
if (item) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
}
|
||||
@@ -214,13 +214,13 @@ SDL_bool SDL_HashTableEmpty(SDL_HashTable *table)
|
||||
|
||||
void SDL_DestroyHashTable(SDL_HashTable *table)
|
||||
{
|
||||
if (table != NULL) {
|
||||
if (table) {
|
||||
void *data = table->data;
|
||||
Uint32 i;
|
||||
|
||||
for (i = 0; i < table->table_len; i++) {
|
||||
SDL_HashItem *item = table->table[i];
|
||||
while (item != NULL) {
|
||||
while (item) {
|
||||
SDL_HashItem *next = item->next;
|
||||
table->nuke(item->key, item->value, data);
|
||||
SDL_free(item);
|
||||
|
||||
+17
-17
@@ -49,7 +49,7 @@ SDL_bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPr
|
||||
SDL_Hint *hint;
|
||||
SDL_HintWatch *entry;
|
||||
|
||||
if (name == NULL) {
|
||||
if (!name) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ SDL_bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPr
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if (hint->value != value &&
|
||||
(value == NULL || !hint->value || SDL_strcmp(hint->value, value) != 0)) {
|
||||
(!value || !hint->value || SDL_strcmp(hint->value, value) != 0)) {
|
||||
char *old_value = hint->value;
|
||||
|
||||
hint->value = value ? SDL_strdup(value) : NULL;
|
||||
@@ -85,7 +85,7 @@ SDL_bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPr
|
||||
|
||||
/* Couldn't find the hint, add a new one */
|
||||
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
|
||||
if (hint == NULL) {
|
||||
if (!hint) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
hint->name = SDL_strdup(name);
|
||||
@@ -103,16 +103,16 @@ SDL_bool SDL_ResetHint(const char *name)
|
||||
SDL_Hint *hint;
|
||||
SDL_HintWatch *entry;
|
||||
|
||||
if (name == NULL) {
|
||||
if (!name) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
env = SDL_getenv(name);
|
||||
for (hint = SDL_hints; hint; hint = hint->next) {
|
||||
if (SDL_strcmp(name, hint->name) == 0) {
|
||||
if ((env == NULL && hint->value != NULL) ||
|
||||
(env != NULL && hint->value == NULL) ||
|
||||
(env != NULL && SDL_strcmp(env, hint->value) != 0)) {
|
||||
if ((!env && hint->value) ||
|
||||
(env && !hint->value) ||
|
||||
(env && SDL_strcmp(env, hint->value) != 0)) {
|
||||
for (entry = hint->callbacks; entry;) {
|
||||
/* Save the next entry in case this one is deleted */
|
||||
SDL_HintWatch *next = entry->next;
|
||||
@@ -137,9 +137,9 @@ void SDL_ResetHints(void)
|
||||
|
||||
for (hint = SDL_hints; hint; hint = hint->next) {
|
||||
env = SDL_getenv(hint->name);
|
||||
if ((env == NULL && hint->value != NULL) ||
|
||||
(env != NULL && hint->value == NULL) ||
|
||||
(env != NULL && SDL_strcmp(env, hint->value) != 0)) {
|
||||
if ((!env && hint->value) ||
|
||||
(env && !hint->value) ||
|
||||
(env && SDL_strcmp(env, hint->value) != 0)) {
|
||||
for (entry = hint->callbacks; entry;) {
|
||||
/* Save the next entry in case this one is deleted */
|
||||
SDL_HintWatch *next = entry->next;
|
||||
@@ -166,7 +166,7 @@ const char *SDL_GetHint(const char *name)
|
||||
env = SDL_getenv(name);
|
||||
for (hint = SDL_hints; hint; hint = hint->next) {
|
||||
if (SDL_strcmp(name, hint->name) == 0) {
|
||||
if (env == NULL || hint->priority == SDL_HINT_OVERRIDE) {
|
||||
if (!env || hint->priority == SDL_HINT_OVERRIDE) {
|
||||
return hint->value;
|
||||
}
|
||||
break;
|
||||
@@ -177,7 +177,7 @@ const char *SDL_GetHint(const char *name)
|
||||
|
||||
int SDL_GetStringInteger(const char *value, int default_value)
|
||||
{
|
||||
if (value == NULL || !*value) {
|
||||
if (!value || !*value) {
|
||||
return default_value;
|
||||
}
|
||||
if (*value == '0' || SDL_strcasecmp(value, "false") == 0) {
|
||||
@@ -194,7 +194,7 @@ int SDL_GetStringInteger(const char *value, int default_value)
|
||||
|
||||
SDL_bool SDL_GetStringBoolean(const char *value, SDL_bool default_value)
|
||||
{
|
||||
if (value == NULL || !*value) {
|
||||
if (!value || !*value) {
|
||||
return default_value;
|
||||
}
|
||||
if (*value == '0' || SDL_strcasecmp(value, "false") == 0) {
|
||||
@@ -215,7 +215,7 @@ int SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userd
|
||||
SDL_HintWatch *entry;
|
||||
const char *value;
|
||||
|
||||
if (name == NULL || !*name) {
|
||||
if (!name || !*name) {
|
||||
return SDL_InvalidParamError("name");
|
||||
}
|
||||
if (!callback) {
|
||||
@@ -225,7 +225,7 @@ int SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userd
|
||||
SDL_DelHintCallback(name, callback, userdata);
|
||||
|
||||
entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry));
|
||||
if (entry == NULL) {
|
||||
if (!entry) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
entry->callback = callback;
|
||||
@@ -236,10 +236,10 @@ int SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userd
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hint == NULL) {
|
||||
if (!hint) {
|
||||
/* Need to add a hint entry for this watcher */
|
||||
hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
|
||||
if (hint == NULL) {
|
||||
if (!hint) {
|
||||
SDL_free(entry);
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ int SDL_ListAdd(SDL_ListNode **head, void *ent)
|
||||
{
|
||||
SDL_ListNode *node = SDL_malloc(sizeof(*node));
|
||||
|
||||
if (node == NULL) {
|
||||
if (!node) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ void SDL_ListPop(SDL_ListNode **head, void **ent)
|
||||
SDL_ListNode **ptr = head;
|
||||
|
||||
/* Invalid or empty */
|
||||
if (head == NULL || *head == NULL) {
|
||||
if (!head || !*head) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -112,7 +112,7 @@ static int SDL_android_priority[SDL_NUM_LOG_PRIORITIES] = {
|
||||
|
||||
void SDL_InitLog(void)
|
||||
{
|
||||
if (log_function_mutex == NULL) {
|
||||
if (!log_function_mutex) {
|
||||
/* if this fails we'll try to continue without it. */
|
||||
log_function_mutex = SDL_CreateMutex();
|
||||
}
|
||||
@@ -305,7 +305,7 @@ void SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va
|
||||
return;
|
||||
}
|
||||
|
||||
if (log_function_mutex == NULL) {
|
||||
if (!log_function_mutex) {
|
||||
/* this mutex creation can race if you log from two threads at startup. You should have called SDL_Init first! */
|
||||
log_function_mutex = SDL_CreateMutex();
|
||||
}
|
||||
@@ -323,7 +323,7 @@ void SDL_LogMessageV(int category, SDL_LogPriority priority, const char *fmt, va
|
||||
if (len >= sizeof(stack_buf) && SDL_size_add_overflow(len, 1, &len_plus_term) == 0) {
|
||||
/* Allocate exactly what we need, including the zero-terminator */
|
||||
message = (char *)SDL_malloc(len_plus_term);
|
||||
if (message == NULL) {
|
||||
if (!message) {
|
||||
return;
|
||||
}
|
||||
va_copy(aq, ap);
|
||||
@@ -459,7 +459,7 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
|
||||
{
|
||||
FILE *pFile;
|
||||
pFile = fopen("SDL_Log.txt", "a");
|
||||
if (pFile != NULL) {
|
||||
if (pFile) {
|
||||
(void)fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
|
||||
(void)fclose(pFile);
|
||||
}
|
||||
@@ -468,7 +468,7 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
|
||||
{
|
||||
FILE *pFile;
|
||||
pFile = fopen("ux0:/data/SDL_Log.txt", "a");
|
||||
if (pFile != NULL) {
|
||||
if (pFile) {
|
||||
(void)fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
|
||||
(void)fclose(pFile);
|
||||
}
|
||||
@@ -477,7 +477,7 @@ static void SDLCALL SDL_LogOutput(void *userdata, int category, SDL_LogPriority
|
||||
{
|
||||
FILE *pFile;
|
||||
pFile = fopen("sdmc:/3ds/SDL_Log.txt", "a");
|
||||
if (pFile != NULL) {
|
||||
if (pFile) {
|
||||
(void)fprintf(pFile, "%s: %s\n", SDL_priority_prefixes[priority], message);
|
||||
(void)fclose(pFile);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ SDL_bool SDL_AtomicTryLock(SDL_SpinLock *lock)
|
||||
/* Terrible terrible damage */
|
||||
static SDL_Mutex *_spinlock_mutex;
|
||||
|
||||
if (_spinlock_mutex == NULL) {
|
||||
if (!_spinlock_mutex) {
|
||||
/* Race condition on first lock... */
|
||||
_spinlock_mutex = SDL_CreateMutex();
|
||||
}
|
||||
|
||||
+57
-57
@@ -139,7 +139,7 @@ static int GetDefaultSampleFramesFromFreq(const int freq)
|
||||
|
||||
void OnAudioStreamCreated(SDL_AudioStream *stream)
|
||||
{
|
||||
SDL_assert(stream != NULL);
|
||||
SDL_assert(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!
|
||||
@@ -159,7 +159,7 @@ void OnAudioStreamCreated(SDL_AudioStream *stream)
|
||||
|
||||
void OnAudioStreamDestroy(SDL_AudioStream *stream)
|
||||
{
|
||||
SDL_assert(stream != NULL);
|
||||
SDL_assert(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!
|
||||
@@ -207,8 +207,8 @@ static void UpdateAudioStreamFormatsPhysical(SDL_AudioDevice *device)
|
||||
spec.format = SDL_AUDIO_F32; // mixing and postbuf operates in float32 format.
|
||||
}
|
||||
|
||||
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev != NULL; logdev = logdev->next) {
|
||||
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = stream->next_binding) {
|
||||
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev; logdev = logdev->next) {
|
||||
for (SDL_AudioStream *stream = logdev->bound_streams; stream; stream = stream->next_binding) {
|
||||
// set the proper end of the stream to the device's format.
|
||||
// SDL_SetAudioStreamFormat does a ton of validation just to memcpy an audiospec.
|
||||
SDL_LockMutex(stream->lock);
|
||||
@@ -441,7 +441,7 @@ static void DestroyLogicalAudioDevice(SDL_LogicalAudioDevice *logdev)
|
||||
|
||||
// unbind any still-bound streams...
|
||||
SDL_AudioStream *next;
|
||||
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = next) {
|
||||
for (SDL_AudioStream *stream = logdev->bound_streams; stream; stream = next) {
|
||||
SDL_LockMutex(stream->lock);
|
||||
next = stream->next_binding;
|
||||
stream->next_binding = NULL;
|
||||
@@ -463,7 +463,7 @@ static void DestroyPhysicalAudioDevice(SDL_AudioDevice *device)
|
||||
|
||||
// Destroy any logical devices that still exist...
|
||||
SDL_LockMutex(device->lock); // don't use ObtainPhysicalAudioDeviceObj because we don't want to change refcounts while destroying.
|
||||
while (device->logical_devices != NULL) {
|
||||
while (device->logical_devices) {
|
||||
DestroyLogicalAudioDevice(device->logical_devices);
|
||||
}
|
||||
SDL_UnlockMutex(device->lock); // don't use ReleaseAudioDevice because we don't want to change refcounts while destroying.
|
||||
@@ -500,7 +500,7 @@ void RefPhysicalAudioDevice(SDL_AudioDevice *device)
|
||||
|
||||
static SDL_AudioDevice *CreatePhysicalAudioDevice(const char *name, SDL_bool iscapture, const SDL_AudioSpec *spec, void *handle, SDL_AtomicInt *device_count)
|
||||
{
|
||||
SDL_assert(name != NULL);
|
||||
SDL_assert(name);
|
||||
|
||||
SDL_LockRWLockForReading(current_audio.device_hash_lock);
|
||||
const int shutting_down = SDL_AtomicGet(¤t_audio.shutting_down);
|
||||
@@ -593,8 +593,8 @@ SDL_AudioDevice *SDL_AddAudioDevice(const SDL_bool iscapture, const char *name,
|
||||
p->devid = device->instance_id;
|
||||
p->next = NULL;
|
||||
SDL_LockRWLockForWriting(current_audio.device_hash_lock);
|
||||
SDL_assert(current_audio.pending_events_tail != NULL);
|
||||
SDL_assert(current_audio.pending_events_tail->next == NULL);
|
||||
SDL_assert(current_audio.pending_events_tail);
|
||||
SDL_assert(!current_audio.pending_events_tail->next);
|
||||
current_audio.pending_events_tail->next = p;
|
||||
current_audio.pending_events_tail = p;
|
||||
SDL_UnlockRWLock(current_audio.device_hash_lock);
|
||||
@@ -642,7 +642,7 @@ void SDL_AudioDeviceDisconnected(SDL_AudioDevice *device)
|
||||
// on default devices, dump any logical devices that explicitly opened this device. Things that opened the system default can stay.
|
||||
// on non-default devices, dump everything.
|
||||
// (by "dump" we mean send a REMOVED event; the zombie will keep consuming audio data for these logical devices until explicitly closed.)
|
||||
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev != NULL; logdev = logdev->next) {
|
||||
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev; logdev = logdev->next) {
|
||||
if (!is_default_device || !logdev->opened_as_default) { // if opened as a default, leave it on the zombie device for later migration.
|
||||
SDL_PendingAudioDeviceEvent *p = (SDL_PendingAudioDeviceEvent *) SDL_malloc(sizeof (SDL_PendingAudioDeviceEvent));
|
||||
if (p) { // if this failed, no event for you, but you have deeper problems anyhow.
|
||||
@@ -670,8 +670,8 @@ void SDL_AudioDeviceDisconnected(SDL_AudioDevice *device)
|
||||
if (first_disconnect) {
|
||||
if (pending.next) { // NULL if event is disabled or disaster struck.
|
||||
SDL_LockRWLockForWriting(current_audio.device_hash_lock);
|
||||
SDL_assert(current_audio.pending_events_tail != NULL);
|
||||
SDL_assert(current_audio.pending_events_tail->next == NULL);
|
||||
SDL_assert(current_audio.pending_events_tail);
|
||||
SDL_assert(!current_audio.pending_events_tail->next);
|
||||
current_audio.pending_events_tail->next = pending.next;
|
||||
current_audio.pending_events_tail = pending_tail;
|
||||
SDL_UnlockRWLock(current_audio.device_hash_lock);
|
||||
@@ -817,26 +817,26 @@ int SDL_InitAudio(const char *driver_name)
|
||||
}
|
||||
|
||||
// Select the proper audio driver
|
||||
if (driver_name == NULL) {
|
||||
if (!driver_name) {
|
||||
driver_name = SDL_GetHint(SDL_HINT_AUDIO_DRIVER);
|
||||
}
|
||||
|
||||
SDL_bool initialized = SDL_FALSE;
|
||||
SDL_bool tried_to_init = SDL_FALSE;
|
||||
|
||||
if (driver_name != NULL && *driver_name != 0) {
|
||||
if (driver_name && *driver_name != 0) {
|
||||
char *driver_name_copy = SDL_strdup(driver_name);
|
||||
const char *driver_attempt = driver_name_copy;
|
||||
|
||||
if (driver_name_copy == NULL) {
|
||||
if (!driver_name_copy) {
|
||||
SDL_DestroyRWLock(device_hash_lock);
|
||||
SDL_DestroyHashTable(device_hash);
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
while (driver_attempt != NULL && *driver_attempt != 0 && !initialized) {
|
||||
while (driver_attempt && *driver_attempt != 0 && !initialized) {
|
||||
char *driver_attempt_end = SDL_strchr(driver_attempt, ',');
|
||||
if (driver_attempt_end != NULL) {
|
||||
if (driver_attempt_end) {
|
||||
*driver_attempt_end = '\0';
|
||||
}
|
||||
|
||||
@@ -863,7 +863,7 @@ int SDL_InitAudio(const char *driver_name)
|
||||
}
|
||||
}
|
||||
|
||||
driver_attempt = (driver_attempt_end != NULL) ? (driver_attempt_end + 1) : NULL;
|
||||
driver_attempt = (driver_attempt_end) ? (driver_attempt_end + 1) : NULL;
|
||||
}
|
||||
|
||||
SDL_free(driver_name_copy);
|
||||
@@ -940,7 +940,7 @@ void SDL_QuitAudio(void)
|
||||
current_audio.impl.DeinitializeStart();
|
||||
|
||||
// Destroy any audio streams that still exist...
|
||||
while (current_audio.existing_streams != NULL) {
|
||||
while (current_audio.existing_streams) {
|
||||
SDL_DestroyAudioStream(current_audio.existing_streams);
|
||||
}
|
||||
|
||||
@@ -955,7 +955,7 @@ void SDL_QuitAudio(void)
|
||||
SDL_UnlockRWLock(current_audio.device_hash_lock);
|
||||
|
||||
SDL_PendingAudioDeviceEvent *pending_next = NULL;
|
||||
for (SDL_PendingAudioDeviceEvent *i = pending_events; i != NULL; i = pending_next) {
|
||||
for (SDL_PendingAudioDeviceEvent *i = pending_events; i; i = pending_next) {
|
||||
pending_next = i->next;
|
||||
SDL_free(i);
|
||||
}
|
||||
@@ -1053,7 +1053,7 @@ SDL_bool SDL_OutputAudioThreadIterate(SDL_AudioDevice *device)
|
||||
|
||||
SDL_memset(final_mix_buffer, '\0', work_buffer_size); // start with silence.
|
||||
|
||||
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev != NULL; logdev = logdev->next) {
|
||||
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev; logdev = logdev->next) {
|
||||
if (SDL_AtomicGet(&logdev->paused)) {
|
||||
continue; // paused? Skip this logical device.
|
||||
}
|
||||
@@ -1065,7 +1065,7 @@ SDL_bool SDL_OutputAudioThreadIterate(SDL_AudioDevice *device)
|
||||
SDL_memset(mix_buffer, '\0', work_buffer_size); // start with silence.
|
||||
}
|
||||
|
||||
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = stream->next_binding) {
|
||||
for (SDL_AudioStream *stream = logdev->bound_streams; stream; stream = stream->next_binding) {
|
||||
// We should have updated this elsewhere if the format changed!
|
||||
SDL_assert(AUDIO_SPECS_EQUAL(stream->dst_spec, outspec));
|
||||
|
||||
@@ -1127,7 +1127,7 @@ void SDL_OutputAudioThreadShutdown(SDL_AudioDevice *device)
|
||||
static int SDLCALL OutputAudioThread(void *devicep) // thread entry point
|
||||
{
|
||||
SDL_AudioDevice *device = (SDL_AudioDevice *)devicep;
|
||||
SDL_assert(device != NULL);
|
||||
SDL_assert(device);
|
||||
SDL_assert(!device->iscapture);
|
||||
SDL_OutputAudioThreadSetup(device);
|
||||
|
||||
@@ -1164,7 +1164,7 @@ SDL_bool SDL_CaptureAudioThreadIterate(SDL_AudioDevice *device)
|
||||
|
||||
SDL_bool failed = SDL_FALSE;
|
||||
|
||||
if (device->logical_devices == NULL) {
|
||||
if (!device->logical_devices) {
|
||||
device->FlushCapture(device); // nothing wants data, dump anything pending.
|
||||
} else {
|
||||
// this SHOULD NOT BLOCK, as we are holding a lock right now. Block in WaitCaptureDevice!
|
||||
@@ -1172,7 +1172,7 @@ SDL_bool SDL_CaptureAudioThreadIterate(SDL_AudioDevice *device)
|
||||
if (br < 0) { // uhoh, device failed for some reason!
|
||||
failed = SDL_TRUE;
|
||||
} else if (br > 0) { // queue the new data to each bound stream.
|
||||
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev != NULL; logdev = logdev->next) {
|
||||
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev; logdev = logdev->next) {
|
||||
if (SDL_AtomicGet(&logdev->paused)) {
|
||||
continue; // paused? Skip this logical device.
|
||||
}
|
||||
@@ -1193,7 +1193,7 @@ SDL_bool SDL_CaptureAudioThreadIterate(SDL_AudioDevice *device)
|
||||
logdev->postmix(logdev->postmix_userdata, &outspec, device->postmix_buffer, br);
|
||||
}
|
||||
|
||||
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = stream->next_binding) {
|
||||
for (SDL_AudioStream *stream = logdev->bound_streams; stream; stream = stream->next_binding) {
|
||||
// We should have updated this elsewhere if the format changed!
|
||||
SDL_assert(stream->src_spec.format == (logdev->postmix ? SDL_AUDIO_F32 : device->spec.format));
|
||||
SDL_assert(stream->src_spec.channels == device->spec.channels);
|
||||
@@ -1233,7 +1233,7 @@ void SDL_CaptureAudioThreadShutdown(SDL_AudioDevice *device)
|
||||
static int SDLCALL CaptureAudioThread(void *devicep) // thread entry point
|
||||
{
|
||||
SDL_AudioDevice *device = (SDL_AudioDevice *)devicep;
|
||||
SDL_assert(device != NULL);
|
||||
SDL_assert(device);
|
||||
SDL_assert(device->iscapture);
|
||||
SDL_CaptureAudioThreadSetup(device);
|
||||
|
||||
@@ -1261,7 +1261,7 @@ static SDL_AudioDeviceID *GetAudioDevices(int *reqcount, SDL_bool iscapture)
|
||||
int num_devices = SDL_AtomicGet(iscapture ? ¤t_audio.capture_device_count : ¤t_audio.output_device_count);
|
||||
if (num_devices > 0) {
|
||||
retval = (SDL_AudioDeviceID *) SDL_malloc((num_devices + 1) * sizeof (SDL_AudioDeviceID));
|
||||
if (retval == NULL) {
|
||||
if (!retval) {
|
||||
num_devices = 0;
|
||||
SDL_OutOfMemory();
|
||||
} else {
|
||||
@@ -1287,7 +1287,7 @@ static SDL_AudioDeviceID *GetAudioDevices(int *reqcount, SDL_bool iscapture)
|
||||
}
|
||||
SDL_UnlockRWLock(current_audio.device_hash_lock);
|
||||
|
||||
if (reqcount != NULL) {
|
||||
if (reqcount) {
|
||||
*reqcount = num_devices;
|
||||
}
|
||||
|
||||
@@ -1384,7 +1384,7 @@ int SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec, int *
|
||||
static void ClosePhysicalAudioDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
SDL_AtomicSet(&device->shutdown, 1);
|
||||
if (device->thread != NULL) {
|
||||
if (device->thread) {
|
||||
SDL_WaitThread(device->thread, NULL);
|
||||
device->thread = NULL;
|
||||
}
|
||||
@@ -1417,7 +1417,7 @@ void SDL_CloseAudioDevice(SDL_AudioDeviceID devid)
|
||||
SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(devid, &device);
|
||||
if (logdev) {
|
||||
DestroyLogicalAudioDevice(logdev);
|
||||
close_physical = (device->logical_devices == NULL); // no more logical devices? Close the physical device, too.
|
||||
close_physical = (!device->logical_devices); // no more logical devices? Close the physical device, too.
|
||||
}
|
||||
|
||||
// !!! FIXME: we _need_ to release this lock, but doing so can cause a race condition if someone opens a device while we're closing it.
|
||||
@@ -1458,7 +1458,7 @@ static void PrepareAudioFormat(SDL_bool iscapture, SDL_AudioSpec *spec)
|
||||
spec->freq = iscapture ? DEFAULT_AUDIO_CAPTURE_FREQUENCY : DEFAULT_AUDIO_OUTPUT_FREQUENCY;
|
||||
|
||||
const char *env = SDL_getenv("SDL_AUDIO_FREQUENCY"); // !!! FIXME: should be a hint?
|
||||
if (env != NULL) {
|
||||
if (env) {
|
||||
const int val = SDL_atoi(env);
|
||||
if (val > 0) {
|
||||
spec->freq = val;
|
||||
@@ -1469,7 +1469,7 @@ static void PrepareAudioFormat(SDL_bool iscapture, SDL_AudioSpec *spec)
|
||||
if (spec->channels == 0) {
|
||||
spec->channels = iscapture ? DEFAULT_AUDIO_CAPTURE_CHANNELS : DEFAULT_AUDIO_OUTPUT_CHANNELS;;
|
||||
const char *env = SDL_getenv("SDL_AUDIO_CHANNELS");
|
||||
if (env != NULL) {
|
||||
if (env) {
|
||||
const int val = SDL_atoi(env);
|
||||
if (val > 0) {
|
||||
spec->channels = val;
|
||||
@@ -1502,7 +1502,7 @@ char *SDL_GetAudioThreadName(SDL_AudioDevice *device, char *buf, size_t buflen)
|
||||
static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec *inspec)
|
||||
{
|
||||
SDL_assert(!device->currently_opened);
|
||||
SDL_assert(device->logical_devices == NULL);
|
||||
SDL_assert(!device->logical_devices);
|
||||
|
||||
// Just pretend to open a zombie device. It can still collect logical devices on a default device under the assumption they will all migrate when the default device is officially changed.
|
||||
if (SDL_AtomicGet(&device->zombie)) {
|
||||
@@ -1541,14 +1541,14 @@ static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec
|
||||
|
||||
// Allocate a scratch audio buffer
|
||||
device->work_buffer = (Uint8 *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), device->work_buffer_size);
|
||||
if (device->work_buffer == NULL) {
|
||||
if (!device->work_buffer) {
|
||||
ClosePhysicalAudioDevice(device);
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
if (device->spec.format != SDL_AUDIO_F32) {
|
||||
device->mix_buffer = (Uint8 *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), device->work_buffer_size);
|
||||
if (device->mix_buffer == NULL) {
|
||||
if (!device->mix_buffer) {
|
||||
ClosePhysicalAudioDevice(device);
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
@@ -1561,7 +1561,7 @@ static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec
|
||||
SDL_GetAudioThreadName(device, threadname, sizeof (threadname));
|
||||
device->thread = SDL_CreateThreadInternal(device->iscapture ? CaptureAudioThread : OutputAudioThread, threadname, stacksize, device);
|
||||
|
||||
if (device->thread == NULL) {
|
||||
if (!device->thread) {
|
||||
ClosePhysicalAudioDevice(device);
|
||||
return SDL_SetError("Couldn't create audio thread");
|
||||
}
|
||||
@@ -1672,7 +1672,7 @@ int SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallbac
|
||||
if (logdev) {
|
||||
if (callback && !device->postmix_buffer) {
|
||||
device->postmix_buffer = (float *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), device->work_buffer_size);
|
||||
if (device->postmix_buffer == NULL) {
|
||||
if (!device->postmix_buffer) {
|
||||
retval = SDL_OutOfMemory();
|
||||
}
|
||||
}
|
||||
@@ -1682,7 +1682,7 @@ int SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallbac
|
||||
logdev->postmix_userdata = userdata;
|
||||
|
||||
if (device->iscapture) {
|
||||
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = stream->next_binding) {
|
||||
for (SDL_AudioStream *stream = logdev->bound_streams; stream; stream = stream->next_binding) {
|
||||
// set the proper end of the stream to the device's format.
|
||||
// SDL_SetAudioStreamFormat does a ton of validation just to memcpy an audiospec.
|
||||
SDL_LockMutex(stream->lock);
|
||||
@@ -1709,7 +1709,7 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int
|
||||
return 0; // nothing to do
|
||||
} else if (num_streams < 0) {
|
||||
return SDL_InvalidParamError("num_streams");
|
||||
} else if (streams == NULL) {
|
||||
} else if (!streams) {
|
||||
return SDL_InvalidParamError("streams");
|
||||
} else if (!islogical) {
|
||||
return SDL_SetError("Audio streams are bound to device ids from SDL_OpenAudioDevice, not raw physical devices");
|
||||
@@ -1726,16 +1726,16 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int
|
||||
// !!! FIXME: Actually, why do we allow there to be an invalid format, again?
|
||||
|
||||
// make sure start of list is sane.
|
||||
SDL_assert(!logdev->bound_streams || (logdev->bound_streams->prev_binding == NULL));
|
||||
SDL_assert(!logdev->bound_streams || (!logdev->bound_streams->prev_binding));
|
||||
|
||||
// lock all the streams upfront, so we can verify they aren't bound elsewhere and add them all in one block, as this is intended to add everything or nothing.
|
||||
for (int i = 0; i < num_streams; i++) {
|
||||
SDL_AudioStream *stream = streams[i];
|
||||
if (stream == NULL) {
|
||||
if (!stream) {
|
||||
retval = SDL_SetError("Stream #%d is NULL", i);
|
||||
} else {
|
||||
SDL_LockMutex(stream->lock);
|
||||
SDL_assert((stream->bound_device == NULL) == ((stream->prev_binding == NULL) || (stream->next_binding == NULL)));
|
||||
SDL_assert((!stream->bound_device) == ((!stream->prev_binding) || (!stream->next_binding)));
|
||||
if (stream->bound_device) {
|
||||
retval = SDL_SetError("Stream #%d is already bound to a device", i);
|
||||
} else if (stream->simplified) { // You can get here if you closed the device instead of destroying the stream.
|
||||
@@ -1830,7 +1830,7 @@ void SDL_UnbindAudioStreams(SDL_AudioStream **streams, int num_streams)
|
||||
// don't allow unbinding from "simplified" devices (opened with SDL_OpenAudioDeviceStream). Just ignore them.
|
||||
if (stream && stream->bound_device && !stream->bound_device->simplified) {
|
||||
if (stream->bound_device->bound_streams == stream) {
|
||||
SDL_assert(stream->prev_binding == NULL);
|
||||
SDL_assert(!stream->prev_binding);
|
||||
stream->bound_device->bound_streams = stream->next_binding;
|
||||
}
|
||||
if (stream->prev_binding) {
|
||||
@@ -1887,12 +1887,12 @@ SDL_AudioStream *SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_Au
|
||||
SDL_AudioStream *stream = NULL;
|
||||
SDL_AudioDevice *device = NULL;
|
||||
SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(logdevid, &device);
|
||||
if (logdev == NULL) { // this shouldn't happen, but just in case.
|
||||
if (!logdev) { // this shouldn't happen, but just in case.
|
||||
failed = SDL_TRUE;
|
||||
} else {
|
||||
SDL_AtomicSet(&logdev->paused, 1); // start the device paused, to match SDL2.
|
||||
|
||||
SDL_assert(device != NULL);
|
||||
SDL_assert(device);
|
||||
const SDL_bool iscapture = device->iscapture;
|
||||
|
||||
if (iscapture) {
|
||||
@@ -1960,7 +1960,7 @@ int SDL_GetSilenceValueForFormat(SDL_AudioFormat format)
|
||||
// called internally by backends when the system default device changes.
|
||||
void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device)
|
||||
{
|
||||
if (new_default_device == NULL) { // !!! FIXME: what should we do in this case? Maybe all devices are lost, so there _isn't_ a default?
|
||||
if (!new_default_device) { // !!! FIXME: what should we do in this case? Maybe all devices are lost, so there _isn't_ a default?
|
||||
return; // uhoh.
|
||||
}
|
||||
|
||||
@@ -2007,10 +2007,10 @@ 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) {
|
||||
for (SDL_LogicalAudioDevice *logdev = current_default_device->logical_devices; logdev; logdev = logdev->next) {
|
||||
if (logdev->opened_as_default) {
|
||||
needs_migration = SDL_TRUE;
|
||||
for (SDL_AudioStream *stream = logdev->bound_streams; stream != NULL; stream = stream->next_binding) {
|
||||
for (SDL_AudioStream *stream = logdev->bound_streams; stream; stream = stream->next_binding) {
|
||||
const SDL_AudioSpec *streamspec = iscapture ? &stream->dst_spec : &stream->src_spec;
|
||||
if (SDL_AUDIO_BITSIZE(streamspec->format) > SDL_AUDIO_BITSIZE(spec.format)) {
|
||||
spec.format = streamspec->format;
|
||||
@@ -2036,7 +2036,7 @@ void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device)
|
||||
if (needs_migration) {
|
||||
const SDL_bool spec_changed = !AUDIO_SPECS_EQUAL(current_default_device->spec, new_default_device->spec);
|
||||
SDL_LogicalAudioDevice *next = NULL;
|
||||
for (SDL_LogicalAudioDevice *logdev = current_default_device->logical_devices; logdev != NULL; logdev = next) {
|
||||
for (SDL_LogicalAudioDevice *logdev = current_default_device->logical_devices; logdev; logdev = next) {
|
||||
next = logdev->next;
|
||||
|
||||
if (!logdev->opened_as_default) {
|
||||
@@ -2083,7 +2083,7 @@ void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device)
|
||||
UpdateAudioStreamFormatsPhysical(current_default_device);
|
||||
UpdateAudioStreamFormatsPhysical(new_default_device);
|
||||
|
||||
if (current_default_device->logical_devices == NULL) { // nothing left on the current physical device, close it.
|
||||
if (!current_default_device->logical_devices) { // nothing left on the current physical device, close it.
|
||||
// !!! FIXME: we _need_ to release this lock, but doing so can cause a race condition if someone opens a device while we're closing it.
|
||||
RefPhysicalAudioDevice(current_default_device); // hold a temp ref for a moment while we release...
|
||||
ReleaseAudioDevice(current_default_device); // can't hold the lock or the audio thread will deadlock while we WaitThread it.
|
||||
@@ -2105,8 +2105,8 @@ void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device)
|
||||
|
||||
if (pending.next) {
|
||||
SDL_LockRWLockForWriting(current_audio.device_hash_lock);
|
||||
SDL_assert(current_audio.pending_events_tail != NULL);
|
||||
SDL_assert(current_audio.pending_events_tail->next == NULL);
|
||||
SDL_assert(current_audio.pending_events_tail);
|
||||
SDL_assert(!current_audio.pending_events_tail->next);
|
||||
current_audio.pending_events_tail->next = pending.next;
|
||||
current_audio.pending_events_tail = pending_tail;
|
||||
SDL_UnlockRWLock(current_audio.device_hash_lock);
|
||||
@@ -2173,7 +2173,7 @@ int SDL_AudioDeviceFormatChangedAlreadyLocked(SDL_AudioDevice *device, const SDL
|
||||
pending_tail = p;
|
||||
}
|
||||
|
||||
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev != NULL; logdev = logdev->next) {
|
||||
for (SDL_LogicalAudioDevice *logdev = device->logical_devices; logdev; logdev = logdev->next) {
|
||||
p = (SDL_PendingAudioDeviceEvent *)SDL_malloc(sizeof(SDL_PendingAudioDeviceEvent));
|
||||
if (p) { // if this failed, no event for you, but you have deeper problems anyhow.
|
||||
p->type = SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED;
|
||||
@@ -2186,8 +2186,8 @@ int SDL_AudioDeviceFormatChangedAlreadyLocked(SDL_AudioDevice *device, const SDL
|
||||
|
||||
if (pending.next) {
|
||||
SDL_LockRWLockForWriting(current_audio.device_hash_lock);
|
||||
SDL_assert(current_audio.pending_events_tail != NULL);
|
||||
SDL_assert(current_audio.pending_events_tail->next == NULL);
|
||||
SDL_assert(current_audio.pending_events_tail);
|
||||
SDL_assert(!current_audio.pending_events_tail->next);
|
||||
current_audio.pending_events_tail->next = pending.next;
|
||||
current_audio.pending_events_tail = pending_tail;
|
||||
SDL_UnlockRWLock(current_audio.device_hash_lock);
|
||||
@@ -2225,7 +2225,7 @@ void SDL_UpdateAudio(void)
|
||||
SDL_UnlockRWLock(current_audio.device_hash_lock);
|
||||
|
||||
SDL_PendingAudioDeviceEvent *pending_next = NULL;
|
||||
for (SDL_PendingAudioDeviceEvent *i = pending_events; i != NULL; i = pending_next) {
|
||||
for (SDL_PendingAudioDeviceEvent *i = pending_events; i; i = pending_next) {
|
||||
pending_next = i->next;
|
||||
if (SDL_EventEnabled(i->type)) {
|
||||
SDL_Event event;
|
||||
|
||||
+23
-23
@@ -221,8 +221,8 @@ static SDL_bool SDL_IsSupportedChannelCount(const int channels)
|
||||
void ConvertAudio(int num_frames, const void *src, SDL_AudioFormat src_format, int src_channels,
|
||||
void *dst, SDL_AudioFormat dst_format, int dst_channels, void* scratch)
|
||||
{
|
||||
SDL_assert(src != NULL);
|
||||
SDL_assert(dst != NULL);
|
||||
SDL_assert(src);
|
||||
SDL_assert(dst);
|
||||
SDL_assert(SDL_IsSupportedAudioFormat(src_format));
|
||||
SDL_assert(SDL_IsSupportedAudioFormat(dst_format));
|
||||
SDL_assert(SDL_IsSupportedChannelCount(src_channels));
|
||||
@@ -278,7 +278,7 @@ void ConvertAudio(int num_frames, const void *src, SDL_AudioFormat src_format, i
|
||||
}
|
||||
}
|
||||
|
||||
if (scratch == NULL) {
|
||||
if (!scratch) {
|
||||
scratch = dst;
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ void ConvertAudio(int num_frames, const void *src, SDL_AudioFormat src_format, i
|
||||
SDL_assert(dst_channels <= SDL_arraysize(channel_converters[0]));
|
||||
|
||||
channel_converter = channel_converters[src_channels - 1][dst_channels - 1];
|
||||
SDL_assert(channel_converter != NULL);
|
||||
SDL_assert(channel_converter);
|
||||
|
||||
// swap in some SIMD versions for a few of these.
|
||||
if (channel_converter == SDL_ConvertStereoToMono) {
|
||||
@@ -408,7 +408,7 @@ SDL_AudioStream *SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_
|
||||
SDL_SetupAudioResampler();
|
||||
|
||||
SDL_AudioStream *retval = (SDL_AudioStream *)SDL_calloc(1, sizeof(SDL_AudioStream));
|
||||
if (retval == NULL) {
|
||||
if (!retval) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -416,13 +416,13 @@ SDL_AudioStream *SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_
|
||||
retval->freq_ratio = 1.0f;
|
||||
retval->queue = SDL_CreateAudioQueue(4096);
|
||||
|
||||
if (retval->queue == NULL) {
|
||||
if (!retval->queue) {
|
||||
SDL_free(retval);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
retval->lock = SDL_CreateMutex();
|
||||
if (retval->lock == NULL) {
|
||||
if (!retval->lock) {
|
||||
SDL_free(retval->queue);
|
||||
SDL_free(retval);
|
||||
return NULL;
|
||||
@@ -632,9 +632,9 @@ int SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len)
|
||||
SDL_Log("AUDIOSTREAM: wants to put %d bytes", len);
|
||||
#endif
|
||||
|
||||
if (stream == NULL) {
|
||||
if (!stream) {
|
||||
return SDL_InvalidParamError("stream");
|
||||
} else if (buf == NULL) {
|
||||
} else if (!buf) {
|
||||
return SDL_InvalidParamError("buf");
|
||||
} else if (len < 0) {
|
||||
return SDL_InvalidParamError("len");
|
||||
@@ -669,7 +669,7 @@ int SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len)
|
||||
size_t chunk_size = SDL_GetAudioQueueChunkSize(stream->queue);
|
||||
track = SDL_CreateChunkedAudioTrack(&src_spec, buf, len, chunk_size);
|
||||
|
||||
if (track == NULL) {
|
||||
if (!track) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -680,7 +680,7 @@ int SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len)
|
||||
|
||||
int retval = 0;
|
||||
|
||||
if (track != NULL) {
|
||||
if (track) {
|
||||
SDL_AddTrackToAudioQueue(stream->queue, track);
|
||||
} else {
|
||||
retval = SDL_WriteToAudioQueue(stream->queue, &stream->src_spec, buf, len);
|
||||
@@ -701,7 +701,7 @@ int SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len)
|
||||
|
||||
int SDL_FlushAudioStream(SDL_AudioStream *stream)
|
||||
{
|
||||
if (stream == NULL) {
|
||||
if (!stream) {
|
||||
return SDL_InvalidParamError("stream");
|
||||
}
|
||||
|
||||
@@ -721,7 +721,7 @@ static Uint8 *EnsureAudioStreamWorkBufferSize(SDL_AudioStream *stream, size_t ne
|
||||
}
|
||||
|
||||
Uint8 *ptr = (Uint8 *) SDL_aligned_alloc(SDL_SIMDGetAlignment(), newlen);
|
||||
if (ptr == NULL) {
|
||||
if (!ptr) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL; // previous work buffer is still valid!
|
||||
}
|
||||
@@ -741,7 +741,7 @@ static void UpdateAudioStreamHistoryBuffer(SDL_AudioStream* stream,
|
||||
Uint8 *history_buffer = stream->history_buffer;
|
||||
int history_bytes = history_buffer_frames * SDL_AUDIO_FRAMESIZE(stream->input_spec);
|
||||
|
||||
if (left_padding != NULL) {
|
||||
if (left_padding) {
|
||||
// Fill in the left padding using the history buffer
|
||||
SDL_assert(padding_bytes <= history_bytes);
|
||||
SDL_memcpy(left_padding, history_buffer + history_bytes - padding_bytes, padding_bytes);
|
||||
@@ -835,7 +835,7 @@ static Sint64 GetAudioStreamHead(SDL_AudioStream* stream, SDL_AudioSpec* out_spe
|
||||
{
|
||||
void* iter = SDL_BeginAudioQueueIter(stream->queue);
|
||||
|
||||
if (iter == NULL) {
|
||||
if (!iter) {
|
||||
SDL_zerop(out_spec);
|
||||
*out_flushed = SDL_FALSE;
|
||||
return 0;
|
||||
@@ -1025,9 +1025,9 @@ int SDL_GetAudioStreamData(SDL_AudioStream *stream, void *voidbuf, int len)
|
||||
SDL_Log("AUDIOSTREAM: want to get %d converted bytes", len);
|
||||
#endif
|
||||
|
||||
if (stream == NULL) {
|
||||
if (!stream) {
|
||||
return SDL_InvalidParamError("stream");
|
||||
} else if (buf == NULL) {
|
||||
} else if (!buf) {
|
||||
return SDL_InvalidParamError("buf");
|
||||
} else if (len < 0) {
|
||||
return SDL_InvalidParamError("len");
|
||||
@@ -1160,7 +1160,7 @@ int SDL_GetAudioStreamQueued(SDL_AudioStream *stream)
|
||||
|
||||
int SDL_ClearAudioStream(SDL_AudioStream *stream)
|
||||
{
|
||||
if (stream == NULL) {
|
||||
if (!stream) {
|
||||
return SDL_InvalidParamError("stream");
|
||||
}
|
||||
|
||||
@@ -1177,7 +1177,7 @@ int SDL_ClearAudioStream(SDL_AudioStream *stream)
|
||||
|
||||
void SDL_DestroyAudioStream(SDL_AudioStream *stream)
|
||||
{
|
||||
if (stream == NULL) {
|
||||
if (!stream) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1214,13 +1214,13 @@ int SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec, const Uint8 *src_data
|
||||
*dst_len = 0;
|
||||
}
|
||||
|
||||
if (src_data == NULL) {
|
||||
if (!src_data) {
|
||||
return SDL_InvalidParamError("src_data");
|
||||
} else if (src_len < 0) {
|
||||
return SDL_InvalidParamError("src_len");
|
||||
} else if (dst_data == NULL) {
|
||||
} else if (!dst_data) {
|
||||
return SDL_InvalidParamError("dst_data");
|
||||
} else if (dst_len == NULL) {
|
||||
} else if (!dst_len) {
|
||||
return SDL_InvalidParamError("dst_len");
|
||||
}
|
||||
|
||||
@@ -1229,7 +1229,7 @@ int SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec, const Uint8 *src_data
|
||||
int dstlen = 0;
|
||||
|
||||
SDL_AudioStream *stream = SDL_CreateAudioStream(src_spec, dst_spec);
|
||||
if (stream != NULL) {
|
||||
if (stream) {
|
||||
if ((SDL_PutAudioStreamData(stream, src_data, src_len) == 0) && (SDL_FlushAudioStream(stream) == 0)) {
|
||||
dstlen = SDL_GetAudioStreamAvailable(stream);
|
||||
if (dstlen >= 0) {
|
||||
|
||||
@@ -80,16 +80,16 @@ static void SDL_EnumUnixAudioDevices_Internal(const SDL_bool iscapture, const SD
|
||||
const char *audiodev;
|
||||
char audiopath[1024];
|
||||
|
||||
if (test == NULL) {
|
||||
if (!test) {
|
||||
test = test_stub;
|
||||
}
|
||||
|
||||
// Figure out what our audio device is
|
||||
audiodev = SDL_getenv("SDL_PATH_DSP");
|
||||
if (audiodev == NULL) {
|
||||
if (!audiodev) {
|
||||
audiodev = SDL_getenv("AUDIODEV");
|
||||
}
|
||||
if (audiodev == NULL) {
|
||||
if (!audiodev) {
|
||||
if (classic) {
|
||||
audiodev = SDL_PATH_DEV_AUDIO;
|
||||
} else {
|
||||
|
||||
+16
-16
@@ -92,7 +92,7 @@ static SDL_AudioChunk *CreateAudioChunk(size_t chunk_size)
|
||||
{
|
||||
SDL_AudioChunk *chunk = (SDL_AudioChunk *)SDL_malloc(sizeof(*chunk) + chunk_size);
|
||||
|
||||
if (chunk == NULL) {
|
||||
if (!chunk) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -146,14 +146,14 @@ static int WriteToChunkedAudioTrack(void *ctx, const Uint8 *data, size_t len)
|
||||
SDL_AudioChunk *chunk = track->tail;
|
||||
|
||||
// Handle the first chunk
|
||||
if (chunk == NULL) {
|
||||
if (!chunk) {
|
||||
chunk = CreateAudioTrackChunk(track);
|
||||
|
||||
if (chunk == NULL) {
|
||||
if (!chunk) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
SDL_assert((track->head == NULL) && (track->tail == NULL) && (track->queued_bytes == 0));
|
||||
SDL_assert((!track->head) && (!track->tail) && (track->queued_bytes == 0));
|
||||
track->head = chunk;
|
||||
track->tail = chunk;
|
||||
}
|
||||
@@ -180,7 +180,7 @@ static int WriteToChunkedAudioTrack(void *ctx, const Uint8 *data, size_t len)
|
||||
}
|
||||
|
||||
// Roll back the changes if we couldn't write all the data
|
||||
if (chunk == NULL) {
|
||||
if (!chunk) {
|
||||
chunk = track->tail;
|
||||
|
||||
SDL_AudioChunk *next = chunk->next;
|
||||
@@ -255,7 +255,7 @@ static SDL_AudioTrack *CreateChunkedAudioTrack(const SDL_AudioSpec *spec, size_t
|
||||
{
|
||||
SDL_ChunkedAudioTrack *track = (SDL_ChunkedAudioTrack *)SDL_calloc(1, sizeof(*track));
|
||||
|
||||
if (track == NULL) {
|
||||
if (!track) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -275,7 +275,7 @@ SDL_AudioQueue *SDL_CreateAudioQueue(size_t chunk_size)
|
||||
{
|
||||
SDL_AudioQueue *queue = (SDL_AudioQueue *)SDL_calloc(1, sizeof(*queue));
|
||||
|
||||
if (queue == NULL) {
|
||||
if (!queue) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -338,7 +338,7 @@ void SDL_PopAudioQueueHead(SDL_AudioQueue *queue)
|
||||
|
||||
queue->head = track;
|
||||
|
||||
if (track == NULL) {
|
||||
if (!track) {
|
||||
queue->tail = NULL;
|
||||
}
|
||||
}
|
||||
@@ -352,7 +352,7 @@ SDL_AudioTrack *SDL_CreateChunkedAudioTrack(const SDL_AudioSpec *spec, const Uin
|
||||
{
|
||||
SDL_AudioTrack *track = CreateChunkedAudioTrack(spec, chunk_size);
|
||||
|
||||
if (track == NULL) {
|
||||
if (!track) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -390,14 +390,14 @@ int SDL_WriteToAudioQueue(SDL_AudioQueue *queue, const SDL_AudioSpec *spec, cons
|
||||
|
||||
SDL_AudioTrack *track = queue->tail;
|
||||
|
||||
if ((track != NULL) && !AUDIO_SPECS_EQUAL(track->spec, *spec)) {
|
||||
if ((track) && !AUDIO_SPECS_EQUAL(track->spec, *spec)) {
|
||||
SDL_FlushAudioTrack(track);
|
||||
}
|
||||
|
||||
if ((track == NULL) || (track->write == NULL)) {
|
||||
if ((!track) || (!track->write)) {
|
||||
SDL_AudioTrack *new_track = CreateChunkedAudioTrack(spec, queue->chunk_size);
|
||||
|
||||
if (new_track == NULL) {
|
||||
if (!new_track) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -423,7 +423,7 @@ void *SDL_BeginAudioQueueIter(SDL_AudioQueue *queue)
|
||||
size_t SDL_NextAudioQueueIter(SDL_AudioQueue *queue, void **inout_iter, SDL_AudioSpec *out_spec, SDL_bool *out_flushed)
|
||||
{
|
||||
SDL_AudioTrack *iter = *inout_iter;
|
||||
SDL_assert(iter != NULL);
|
||||
SDL_assert(iter);
|
||||
|
||||
SDL_copyp(out_spec, &iter->spec);
|
||||
|
||||
@@ -462,7 +462,7 @@ int SDL_ReadFromAudioQueue(SDL_AudioQueue *queue, Uint8 *data, size_t len)
|
||||
SDL_AudioTrack *track = queue->head;
|
||||
|
||||
for (;;) {
|
||||
if (track == NULL) {
|
||||
if (!track) {
|
||||
return SDL_SetError("Reading past end of queue");
|
||||
}
|
||||
|
||||
@@ -478,7 +478,7 @@ int SDL_ReadFromAudioQueue(SDL_AudioQueue *queue, Uint8 *data, size_t len)
|
||||
|
||||
SDL_AudioTrack *next = track->next;
|
||||
|
||||
if (next == NULL) {
|
||||
if (!next) {
|
||||
return SDL_SetError("Reading past end of incomplete track");
|
||||
}
|
||||
|
||||
@@ -495,7 +495,7 @@ int SDL_PeekIntoAudioQueue(SDL_AudioQueue *queue, Uint8 *data, size_t len)
|
||||
SDL_AudioTrack *track = queue->head;
|
||||
|
||||
for (;;) {
|
||||
if (track == NULL) {
|
||||
if (!track) {
|
||||
return SDL_SetError("Peeking past end of queue");
|
||||
}
|
||||
|
||||
|
||||
+18
-18
@@ -262,7 +262,7 @@ static void WaveDebugDumpFormat(WaveFile *file, Uint32 rifflen, Uint32 fmtlen, U
|
||||
int res;
|
||||
|
||||
dumpstr = SDL_malloc(bufsize);
|
||||
if (dumpstr == NULL) {
|
||||
if (!dumpstr) {
|
||||
return;
|
||||
}
|
||||
dumpstr[0] = 0;
|
||||
@@ -439,7 +439,7 @@ static int MS_ADPCM_Init(WaveFile *file, size_t datalength)
|
||||
|
||||
coeffdata = (MS_ADPCM_CoeffData *)SDL_malloc(sizeof(MS_ADPCM_CoeffData) + coeffcount * 4);
|
||||
file->decoderdata = coeffdata; /* Freed in cleanup. */
|
||||
if (coeffdata == NULL) {
|
||||
if (!coeffdata) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
coeffdata->coeff = &coeffdata->aligndummy;
|
||||
@@ -682,7 +682,7 @@ static int MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
||||
state.output.pos = 0;
|
||||
state.output.size = outputsize / sizeof(Sint16);
|
||||
state.output.data = (Sint16 *)SDL_calloc(1, outputsize);
|
||||
if (state.output.data == NULL) {
|
||||
if (!state.output.data) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -1073,12 +1073,12 @@ static int IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len
|
||||
state.output.pos = 0;
|
||||
state.output.size = outputsize / sizeof(Sint16);
|
||||
state.output.data = (Sint16 *)SDL_malloc(outputsize);
|
||||
if (state.output.data == NULL) {
|
||||
if (!state.output.data) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
cstate = (Sint8 *)SDL_calloc(state.channels, sizeof(Sint8));
|
||||
if (cstate == NULL) {
|
||||
if (!cstate) {
|
||||
SDL_free(state.output.data);
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
@@ -1233,7 +1233,7 @@ static int LAW_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len)
|
||||
|
||||
/* 1 to avoid allocating zero bytes, to keep static analysis happy. */
|
||||
src = (Uint8 *)SDL_realloc(chunk->data, expanded_len ? expanded_len : 1);
|
||||
if (src == NULL) {
|
||||
if (!src) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
chunk->data = NULL;
|
||||
@@ -1364,7 +1364,7 @@ static int PCM_ConvertSint24ToSint32(WaveFile *file, Uint8 **audio_buf, Uint32 *
|
||||
|
||||
/* 1 to avoid allocating zero bytes, to keep static analysis happy. */
|
||||
ptr = (Uint8 *)SDL_realloc(chunk->data, expanded_len ? expanded_len : 1);
|
||||
if (ptr == NULL) {
|
||||
if (!ptr) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -1440,7 +1440,7 @@ static WaveRiffSizeHint WaveGetRiffSizeHint(void)
|
||||
{
|
||||
const char *hint = SDL_GetHint(SDL_HINT_WAVE_RIFF_CHUNK_SIZE);
|
||||
|
||||
if (hint != NULL) {
|
||||
if (hint) {
|
||||
if (SDL_strcmp(hint, "force") == 0) {
|
||||
return RiffSizeForce;
|
||||
} else if (SDL_strcmp(hint, "ignore") == 0) {
|
||||
@@ -1459,7 +1459,7 @@ static WaveTruncationHint WaveGetTruncationHint(void)
|
||||
{
|
||||
const char *hint = SDL_GetHint(SDL_HINT_WAVE_TRUNCATION);
|
||||
|
||||
if (hint != NULL) {
|
||||
if (hint) {
|
||||
if (SDL_strcmp(hint, "verystrict") == 0) {
|
||||
return TruncVeryStrict;
|
||||
} else if (SDL_strcmp(hint, "strict") == 0) {
|
||||
@@ -1478,7 +1478,7 @@ static WaveFactChunkHint WaveGetFactChunkHint(void)
|
||||
{
|
||||
const char *hint = SDL_GetHint(SDL_HINT_WAVE_FACT_CHUNK);
|
||||
|
||||
if (hint != NULL) {
|
||||
if (hint) {
|
||||
if (SDL_strcmp(hint, "truncate") == 0) {
|
||||
return FactTruncate;
|
||||
} else if (SDL_strcmp(hint, "strict") == 0) {
|
||||
@@ -1495,7 +1495,7 @@ static WaveFactChunkHint WaveGetFactChunkHint(void)
|
||||
|
||||
static void WaveFreeChunkData(WaveChunk *chunk)
|
||||
{
|
||||
if (chunk->data != NULL) {
|
||||
if (chunk->data) {
|
||||
SDL_free(chunk->data);
|
||||
chunk->data = NULL;
|
||||
}
|
||||
@@ -1544,7 +1544,7 @@ static int WaveReadPartialChunkData(SDL_RWops *src, WaveChunk *chunk, size_t len
|
||||
|
||||
if (length > 0) {
|
||||
chunk->data = (Uint8 *)SDL_malloc(length);
|
||||
if (chunk->data == NULL) {
|
||||
if (!chunk->data) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -1610,7 +1610,7 @@ static int WaveReadFormat(WaveFile *file)
|
||||
return SDL_SetError("Data of WAVE fmt chunk too big");
|
||||
}
|
||||
fmtsrc = SDL_RWFromConstMem(chunk->data, (int)chunk->size);
|
||||
if (fmtsrc == NULL) {
|
||||
if (!fmtsrc) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -1788,7 +1788,7 @@ static int WaveLoad(SDL_RWops *src, WaveFile *file, SDL_AudioSpec *spec, Uint8 *
|
||||
SDL_zero(datachunk);
|
||||
|
||||
envchunkcountlimit = SDL_getenv("SDL_WAVE_CHUNK_LIMIT");
|
||||
if (envchunkcountlimit != NULL) {
|
||||
if (envchunkcountlimit) {
|
||||
unsigned int count;
|
||||
if (SDL_sscanf(envchunkcountlimit, "%u", &count) == 1) {
|
||||
chunkcountlimit = count <= SDL_MAX_UINT32 ? count : SDL_MAX_UINT32;
|
||||
@@ -2081,15 +2081,15 @@ int SDL_LoadWAV_RW(SDL_RWops *src, SDL_bool freesrc, SDL_AudioSpec *spec, Uint8
|
||||
WaveFile file;
|
||||
|
||||
/* Make sure we are passed a valid data source */
|
||||
if (src == NULL) {
|
||||
if (!src) {
|
||||
goto done; /* Error may come from RWops. */
|
||||
} else if (spec == NULL) {
|
||||
} else if (!spec) {
|
||||
SDL_InvalidParamError("spec");
|
||||
goto done;
|
||||
} else if (audio_buf == NULL) {
|
||||
} else if (!audio_buf) {
|
||||
SDL_InvalidParamError("audio_buf");
|
||||
goto done;
|
||||
} else if (audio_len == NULL) {
|
||||
} else if (!audio_len) {
|
||||
SDL_InvalidParamError("audio_len");
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ static int BuildAAudioStream(SDL_AudioDevice *device)
|
||||
if (res != AAUDIO_OK) {
|
||||
LOGI("SDL Failed AAudio_createStreamBuilder %d", res);
|
||||
return SDL_SetError("SDL Failed AAudio_createStreamBuilder %d", res);
|
||||
} else if (builder == NULL) {
|
||||
} else if (!builder) {
|
||||
LOGI("SDL Failed AAudio_createStreamBuilder - builder NULL");
|
||||
return SDL_SetError("SDL Failed AAudio_createStreamBuilder - builder NULL");
|
||||
}
|
||||
@@ -354,7 +354,7 @@ static int BuildAAudioStream(SDL_AudioDevice *device)
|
||||
hidden->num_buffers = 2;
|
||||
hidden->mixbuf_bytes = (hidden->num_buffers * device->buffer_size);
|
||||
hidden->mixbuf = (Uint8 *)SDL_aligned_alloc(SDL_SIMDGetAlignment(), hidden->mixbuf_bytes);
|
||||
if (hidden->mixbuf == NULL) {
|
||||
if (!hidden->mixbuf) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
hidden->processed_bytes = 0;
|
||||
@@ -384,7 +384,7 @@ static int BuildAAudioStream(SDL_AudioDevice *device)
|
||||
static int AAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
#if ALLOW_MULTIPLE_ANDROID_AUDIO_DEVICES
|
||||
SDL_assert(device->handle != NULL); // AAUDIO_UNSPECIFIED is zero, so legit devices should all be non-zero.
|
||||
SDL_assert(device->handle); // AAUDIO_UNSPECIFIED is zero, so legit devices should all be non-zero.
|
||||
#endif
|
||||
|
||||
LOGI(__func__);
|
||||
@@ -397,7 +397,7 @@ static int AAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
}
|
||||
|
||||
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -407,7 +407,7 @@ static int AAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
static SDL_bool PauseOneDevice(SDL_AudioDevice *device, void *userdata)
|
||||
{
|
||||
struct SDL_PrivateAudioData *hidden = (struct SDL_PrivateAudioData *)device->hidden;
|
||||
if (hidden != NULL) {
|
||||
if (hidden) {
|
||||
if (hidden->stream) {
|
||||
aaudio_result_t res;
|
||||
|
||||
@@ -433,7 +433,7 @@ static SDL_bool PauseOneDevice(SDL_AudioDevice *device, void *userdata)
|
||||
// Pause (block) all non already paused audio devices by taking their mixer lock
|
||||
void AAUDIO_PauseDevices(void)
|
||||
{
|
||||
if (ctx.handle != NULL) { // AAUDIO driver is used?
|
||||
if (ctx.handle) { // AAUDIO driver is used?
|
||||
(void) SDL_FindPhysicalAudioDeviceByCallback(PauseOneDevice, NULL);
|
||||
}
|
||||
}
|
||||
@@ -442,7 +442,7 @@ void AAUDIO_PauseDevices(void)
|
||||
static SDL_bool ResumeOneDevice(SDL_AudioDevice *device, void *userdata)
|
||||
{
|
||||
struct SDL_PrivateAudioData *hidden = device->hidden;
|
||||
if (hidden != NULL) {
|
||||
if (hidden) {
|
||||
if (hidden->resume) {
|
||||
hidden->resume = SDL_FALSE;
|
||||
SDL_UnlockMutex(device->lock);
|
||||
@@ -461,7 +461,7 @@ static SDL_bool ResumeOneDevice(SDL_AudioDevice *device, void *userdata)
|
||||
|
||||
void AAUDIO_ResumeDevices(void)
|
||||
{
|
||||
if (ctx.handle != NULL) { // AAUDIO driver is used?
|
||||
if (ctx.handle) { // AAUDIO driver is used?
|
||||
(void) SDL_FindPhysicalAudioDeviceByCallback(ResumeOneDevice, NULL);
|
||||
}
|
||||
}
|
||||
@@ -495,7 +495,7 @@ static SDL_bool AAUDIO_Init(SDL_AudioDriverImpl *impl)
|
||||
SDL_zero(ctx);
|
||||
|
||||
ctx.handle = SDL_LoadObject(LIB_AAUDIO_SO);
|
||||
if (ctx.handle == NULL) {
|
||||
if (!ctx.handle) {
|
||||
LOGI("SDL couldn't find " LIB_AAUDIO_SO);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ static void *alsa_handle = NULL;
|
||||
static int load_alsa_sym(const char *fn, void **addr)
|
||||
{
|
||||
*addr = SDL_LoadFunction(alsa_handle, fn);
|
||||
if (*addr == NULL) {
|
||||
if (!*addr) {
|
||||
// Don't call SDL_SetError(): SDL_LoadFunction already did.
|
||||
return 0;
|
||||
}
|
||||
@@ -165,7 +165,7 @@ static int load_alsa_syms(void)
|
||||
|
||||
static void UnloadALSALibrary(void)
|
||||
{
|
||||
if (alsa_handle != NULL) {
|
||||
if (alsa_handle) {
|
||||
SDL_UnloadObject(alsa_handle);
|
||||
alsa_handle = NULL;
|
||||
}
|
||||
@@ -174,9 +174,9 @@ static void UnloadALSALibrary(void)
|
||||
static int LoadALSALibrary(void)
|
||||
{
|
||||
int retval = 0;
|
||||
if (alsa_handle == NULL) {
|
||||
if (!alsa_handle) {
|
||||
alsa_handle = SDL_LoadObject(alsa_library);
|
||||
if (alsa_handle == NULL) {
|
||||
if (!alsa_handle) {
|
||||
retval = -1;
|
||||
// Don't call SDL_SetError(): SDL_LoadObject already did.
|
||||
} else {
|
||||
@@ -224,12 +224,12 @@ static const ALSA_Device default_capture_handle = {
|
||||
|
||||
static const char *get_audio_device(void *handle, const int channels)
|
||||
{
|
||||
SDL_assert(handle != NULL); // SDL2 used NULL to mean "default" but that's not true in SDL3.
|
||||
SDL_assert(handle); // SDL2 used NULL to mean "default" but that's not true in SDL3.
|
||||
|
||||
ALSA_Device *dev = (ALSA_Device *)handle;
|
||||
if (SDL_strcmp(dev->name, "default") == 0) {
|
||||
const char *device = SDL_getenv("AUDIODEV"); // Is there a standard variable name?
|
||||
if (device != NULL) {
|
||||
if (device) {
|
||||
return device;
|
||||
} else if (channels == 6) {
|
||||
return "plug:surround51";
|
||||
@@ -536,7 +536,7 @@ static int ALSA_OpenDevice(SDL_AudioDevice *device)
|
||||
|
||||
// Initialize all variables that we clean on shutdown
|
||||
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -682,7 +682,7 @@ static int ALSA_OpenDevice(SDL_AudioDevice *device)
|
||||
// Allocate mixing buffer
|
||||
if (!iscapture) {
|
||||
device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size);
|
||||
if (device->hidden->mixbuf == NULL) {
|
||||
if (!device->hidden->mixbuf) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size);
|
||||
@@ -705,7 +705,7 @@ static void add_device(const SDL_bool iscapture, const char *name, void *hint, A
|
||||
char *desc;
|
||||
char *ptr;
|
||||
|
||||
if (dev == NULL) {
|
||||
if (!dev) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -715,7 +715,7 @@ static void add_device(const SDL_bool iscapture, const char *name, void *hint, A
|
||||
// Make sure not to free the storage associated with desc in this case
|
||||
if (hint) {
|
||||
desc = ALSA_snd_device_name_get_hint(hint, "DESC");
|
||||
if (desc == NULL) {
|
||||
if (!desc) {
|
||||
SDL_free(dev);
|
||||
return;
|
||||
}
|
||||
@@ -723,13 +723,13 @@ static void add_device(const SDL_bool iscapture, const char *name, void *hint, A
|
||||
desc = (char *)name;
|
||||
}
|
||||
|
||||
SDL_assert(name != NULL);
|
||||
SDL_assert(name);
|
||||
|
||||
// some strings have newlines, like "HDA NVidia, HDMI 0\nHDMI Audio Output".
|
||||
// just chop the extra lines off, this seems to get a reasonable device
|
||||
// name without extra details.
|
||||
ptr = SDL_strchr(desc, '\n');
|
||||
if (ptr != NULL) {
|
||||
if (ptr) {
|
||||
*ptr = '\0';
|
||||
}
|
||||
|
||||
@@ -784,7 +784,7 @@ static void ALSA_HotplugIteration(SDL_bool *has_default_output, SDL_bool *has_de
|
||||
// if we can find a preferred prefix for the system.
|
||||
for (int i = 0; hints[i]; i++) {
|
||||
char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
|
||||
if (name == NULL) {
|
||||
if (!name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -813,16 +813,16 @@ static void ALSA_HotplugIteration(SDL_bool *has_default_output, SDL_bool *has_de
|
||||
if (match || (has_default >= 0)) { // did we find a device name prefix we like at all...?
|
||||
for (int i = 0; hints[i]; i++) {
|
||||
char *name = ALSA_snd_device_name_get_hint(hints[i], "NAME");
|
||||
if (name == NULL) {
|
||||
if (!name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// only want physical hardware interfaces
|
||||
const SDL_bool is_default = (has_default == i);
|
||||
if (is_default || (match != NULL && SDL_strncmp(name, match, match_len) == 0)) {
|
||||
if (is_default || (match && SDL_strncmp(name, match, match_len) == 0)) {
|
||||
char *ioid = ALSA_snd_device_name_get_hint(hints[i], "IOID");
|
||||
const SDL_bool isoutput = (ioid == NULL) || (SDL_strcmp(ioid, "Output") == 0);
|
||||
const SDL_bool isinput = (ioid == NULL) || (SDL_strcmp(ioid, "Input") == 0);
|
||||
const SDL_bool isoutput = (!ioid) || (SDL_strcmp(ioid, "Output") == 0);
|
||||
const SDL_bool isinput = (!ioid) || (SDL_strcmp(ioid, "Input") == 0);
|
||||
SDL_bool have_output = SDL_FALSE;
|
||||
SDL_bool have_input = SDL_FALSE;
|
||||
|
||||
@@ -942,7 +942,7 @@ static void ALSA_DeinitializeStart(void)
|
||||
ALSA_Device *next;
|
||||
|
||||
#if SDL_ALSA_HOTPLUG_THREAD
|
||||
if (ALSA_hotplug_thread != NULL) {
|
||||
if (ALSA_hotplug_thread) {
|
||||
SDL_AtomicSet(&ALSA_hotplug_shutdown, 1);
|
||||
SDL_WaitThread(ALSA_hotplug_thread, NULL);
|
||||
ALSA_hotplug_thread = NULL;
|
||||
|
||||
@@ -42,7 +42,7 @@ static SDL_AudioDevice *captureDevice = NULL;
|
||||
static int ANDROIDAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -131,13 +131,13 @@ void ANDROIDAUDIO_PauseDevices(void)
|
||||
{
|
||||
// TODO: Handle multiple devices?
|
||||
struct SDL_PrivateAudioData *hidden;
|
||||
if (audioDevice != NULL && audioDevice->hidden != NULL) {
|
||||
if (audioDevice && audioDevice->hidden) {
|
||||
hidden = (struct SDL_PrivateAudioData *)audioDevice->hidden;
|
||||
SDL_LockMutex(audioDevice->lock);
|
||||
hidden->resume = SDL_TRUE;
|
||||
}
|
||||
|
||||
if (captureDevice != NULL && captureDevice->hidden != NULL) {
|
||||
if (captureDevice && captureDevice->hidden) {
|
||||
hidden = (struct SDL_PrivateAudioData *)captureDevice->hidden;
|
||||
SDL_LockMutex(captureDevice->lock);
|
||||
hidden->resume = SDL_TRUE;
|
||||
@@ -149,7 +149,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
|
||||
{
|
||||
// TODO: Handle multiple devices?
|
||||
struct SDL_PrivateAudioData *hidden;
|
||||
if (audioDevice != NULL && audioDevice->hidden != NULL) {
|
||||
if (audioDevice && audioDevice->hidden) {
|
||||
hidden = (struct SDL_PrivateAudioData *)audioDevice->hidden;
|
||||
if (hidden->resume) {
|
||||
hidden->resume = SDL_FALSE;
|
||||
@@ -157,7 +157,7 @@ void ANDROIDAUDIO_ResumeDevices(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (captureDevice != NULL && captureDevice->hidden != NULL) {
|
||||
if (captureDevice && captureDevice->hidden) {
|
||||
hidden = (struct SDL_PrivateAudioData *)captureDevice->hidden;
|
||||
if (hidden->resume) {
|
||||
hidden->resume = SDL_FALSE;
|
||||
|
||||
@@ -62,7 +62,7 @@ static void DSOUND_Unload(void)
|
||||
pDirectSoundCaptureEnumerateW = NULL;
|
||||
pGetDeviceID = NULL;
|
||||
|
||||
if (DSoundDLL != NULL) {
|
||||
if (DSoundDLL) {
|
||||
SDL_UnloadObject(DSoundDLL);
|
||||
DSoundDLL = NULL;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ static int DSOUND_Load(void)
|
||||
DSOUND_Unload();
|
||||
|
||||
DSoundDLL = SDL_LoadObject("DSOUND.DLL");
|
||||
if (DSoundDLL == NULL) {
|
||||
if (!DSoundDLL) {
|
||||
SDL_SetError("DirectSound: failed to load DSOUND.DLL");
|
||||
} else {
|
||||
// Now make sure we have DirectX 8 or better...
|
||||
@@ -176,7 +176,7 @@ static BOOL CALLBACK FindAllDevs(LPGUID guid, LPCWSTR desc, LPCWSTR module, LPVO
|
||||
FindAllDevsData *data = (FindAllDevsData *) userdata;
|
||||
if (guid != NULL) { // skip default device
|
||||
char *str = WIN_LookupAudioDeviceName(desc, guid);
|
||||
if (str != NULL) {
|
||||
if (str) {
|
||||
LPGUID cpyguid = (LPGUID)SDL_malloc(sizeof(GUID));
|
||||
if (cpyguid) {
|
||||
SDL_copyp(cpyguid, guid);
|
||||
@@ -358,7 +358,7 @@ static int DSOUND_CaptureFromDevice(SDL_AudioDevice *device, void *buffer, int b
|
||||
}
|
||||
|
||||
SDL_assert(ptr1len == (DWORD)buflen);
|
||||
SDL_assert(ptr2 == NULL);
|
||||
SDL_assert(!ptr2);
|
||||
SDL_assert(ptr2len == 0);
|
||||
|
||||
SDL_memcpy(buffer, ptr1, ptr1len);
|
||||
@@ -384,18 +384,18 @@ static void DSOUND_FlushCapture(SDL_AudioDevice *device)
|
||||
static void DSOUND_CloseDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
if (device->hidden) {
|
||||
if (device->hidden->mixbuf != NULL) {
|
||||
if (device->hidden->mixbuf) {
|
||||
IDirectSoundBuffer_Stop(device->hidden->mixbuf);
|
||||
IDirectSoundBuffer_Release(device->hidden->mixbuf);
|
||||
}
|
||||
if (device->hidden->sound != NULL) {
|
||||
if (device->hidden->sound) {
|
||||
IDirectSound_Release(device->hidden->sound);
|
||||
}
|
||||
if (device->hidden->capturebuf != NULL) {
|
||||
if (device->hidden->capturebuf) {
|
||||
IDirectSoundCaptureBuffer_Stop(device->hidden->capturebuf);
|
||||
IDirectSoundCaptureBuffer_Release(device->hidden->capturebuf);
|
||||
}
|
||||
if (device->hidden->capture != NULL) {
|
||||
if (device->hidden->capture) {
|
||||
IDirectSoundCapture_Release(device->hidden->capture);
|
||||
}
|
||||
SDL_free(device->hidden);
|
||||
@@ -491,7 +491,7 @@ static int DSOUND_OpenDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
// Initialize all variables that we clean on shutdown
|
||||
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ static void DISKAUDIO_FlushCapture(SDL_AudioDevice *device)
|
||||
static void DISKAUDIO_CloseDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
if (device->hidden) {
|
||||
if (device->hidden->io != NULL) {
|
||||
if (device->hidden->io) {
|
||||
SDL_RWclose(device->hidden->io);
|
||||
}
|
||||
SDL_free(device->hidden->mixbuf);
|
||||
@@ -99,7 +99,7 @@ static void DISKAUDIO_CloseDevice(SDL_AudioDevice *device)
|
||||
static const char *get_filename(const SDL_bool iscapture)
|
||||
{
|
||||
const char *devname = SDL_getenv(iscapture ? DISKENVR_INFILE : DISKENVR_OUTFILE);
|
||||
if (devname == NULL) {
|
||||
if (!devname) {
|
||||
devname = iscapture ? DISKDEFAULT_INFILE : DISKDEFAULT_OUTFILE;
|
||||
}
|
||||
return devname;
|
||||
@@ -112,11 +112,11 @@ static int DISKAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
const char *envr = SDL_getenv(DISKENVR_IODELAY);
|
||||
|
||||
device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
if (envr != NULL) {
|
||||
if (envr) {
|
||||
device->hidden->io_delay = SDL_atoi(envr);
|
||||
} else {
|
||||
device->hidden->io_delay = ((device->sample_frames * 1000) / device->spec.freq);
|
||||
@@ -124,14 +124,14 @@ static int DISKAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
|
||||
// Open the "audio device"
|
||||
device->hidden->io = SDL_RWFromFile(fname, iscapture ? "rb" : "wb");
|
||||
if (device->hidden->io == NULL) {
|
||||
if (!device->hidden->io) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Allocate mixing buffer
|
||||
if (!iscapture) {
|
||||
device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size);
|
||||
if (device->hidden->mixbuf == NULL) {
|
||||
if (!device->hidden->mixbuf) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size);
|
||||
|
||||
@@ -70,7 +70,7 @@ static int DSP_OpenDevice(SDL_AudioDevice *device)
|
||||
|
||||
// Initialize all variables that we clean on shutdown
|
||||
device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ static int DSP_OpenDevice(SDL_AudioDevice *device)
|
||||
// Allocate mixing buffer
|
||||
if (!device->iscapture) {
|
||||
device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size);
|
||||
if (device->hidden->mixbuf == NULL) {
|
||||
if (!device->hidden->mixbuf) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size);
|
||||
|
||||
@@ -177,7 +177,7 @@ static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
|
||||
// Initialize all variables that we clean on shutdown
|
||||
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
|
||||
if (!device->iscapture) {
|
||||
device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size);
|
||||
if (device->hidden->mixbuf == NULL) {
|
||||
if (!device->hidden->mixbuf) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size);
|
||||
|
||||
@@ -39,7 +39,7 @@ extern "C"
|
||||
|
||||
static Uint8 *HAIKUAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||
{
|
||||
SDL_assert(device->hidden->current_buffer != NULL);
|
||||
SDL_assert(device->hidden->current_buffer);
|
||||
SDL_assert(device->hidden->current_buffer_len > 0);
|
||||
*buffer_size = device->hidden->current_buffer_len;
|
||||
return device->hidden->current_buffer;
|
||||
@@ -48,7 +48,7 @@ static Uint8 *HAIKUAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||
static int HAIKUAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size)
|
||||
{
|
||||
// We already wrote our output right into the BSoundPlayer's callback's stream. Just clean up our stuff.
|
||||
SDL_assert(device->hidden->current_buffer != NULL);
|
||||
SDL_assert(device->hidden->current_buffer);
|
||||
SDL_assert(device->hidden->current_buffer_len > 0);
|
||||
device->hidden->current_buffer = NULL;
|
||||
device->hidden->current_buffer_len = 0;
|
||||
@@ -59,7 +59,7 @@ static int HAIKUAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, i
|
||||
static void FillSound(void *data, void *stream, size_t len, const media_raw_audio_format & format)
|
||||
{
|
||||
SDL_AudioDevice *device = (SDL_AudioDevice *)data;
|
||||
SDL_assert(device->hidden->current_buffer == NULL);
|
||||
SDL_assert(!device->hidden->current_buffer);
|
||||
SDL_assert(device->hidden->current_buffer_len == 0);
|
||||
device->hidden->current_buffer = (Uint8 *) stream;
|
||||
device->hidden->current_buffer_len = (int) len;
|
||||
|
||||
@@ -57,7 +57,7 @@ static void *jack_handle = NULL;
|
||||
static int load_jack_sym(const char *fn, void **addr)
|
||||
{
|
||||
*addr = SDL_LoadFunction(jack_handle, fn);
|
||||
if (*addr == NULL) {
|
||||
if (!*addr) {
|
||||
// Don't call SDL_SetError(): SDL_LoadFunction already did.
|
||||
return 0;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ static int load_jack_sym(const char *fn, void **addr)
|
||||
|
||||
static void UnloadJackLibrary(void)
|
||||
{
|
||||
if (jack_handle != NULL) {
|
||||
if (jack_handle) {
|
||||
SDL_UnloadObject(jack_handle);
|
||||
jack_handle = NULL;
|
||||
}
|
||||
@@ -81,9 +81,9 @@ static void UnloadJackLibrary(void)
|
||||
static int LoadJackLibrary(void)
|
||||
{
|
||||
int retval = 0;
|
||||
if (jack_handle == NULL) {
|
||||
if (!jack_handle) {
|
||||
jack_handle = SDL_LoadObject(jack_library);
|
||||
if (jack_handle == NULL) {
|
||||
if (!jack_handle) {
|
||||
retval = -1;
|
||||
// Don't call SDL_SetError(): SDL_LoadObject already did.
|
||||
} else {
|
||||
@@ -296,18 +296,18 @@ static int JACK_OpenDevice(SDL_AudioDevice *device)
|
||||
|
||||
// Initialize all variables that we clean on shutdown
|
||||
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
client = JACK_jack_client_open(GetJackAppName(), JackNoStartServer, &status, NULL);
|
||||
device->hidden->client = client;
|
||||
if (client == NULL) {
|
||||
if (!client) {
|
||||
return SDL_SetError("Can't open JACK client");
|
||||
}
|
||||
|
||||
devports = JACK_jack_get_ports(client, NULL, NULL, JackPortIsPhysical | sysportflags);
|
||||
if (devports == NULL || !devports[0]) {
|
||||
if (!devports || !devports[0]) {
|
||||
return SDL_SetError("No physical JACK ports available");
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ static int JACK_OpenDevice(SDL_AudioDevice *device)
|
||||
|
||||
// Build SDL's ports, which we will connect to the device ports.
|
||||
device->hidden->sdlports = (jack_port_t **)SDL_calloc(channels, sizeof(jack_port_t *));
|
||||
if (device->hidden->sdlports == NULL) {
|
||||
if (!device->hidden->sdlports) {
|
||||
SDL_free(audio_ports);
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
@@ -414,7 +414,7 @@ static SDL_bool JACK_Init(SDL_AudioDriverImpl *impl)
|
||||
// Make sure a JACK server is running and available.
|
||||
jack_status_t status;
|
||||
jack_client_t *client = JACK_jack_client_open("SDL", JackNoStartServer, &status, NULL);
|
||||
if (client == NULL) {
|
||||
if (!client) {
|
||||
UnloadJackLibrary();
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ static int N3DSAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
float mix[12];
|
||||
|
||||
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -134,14 +134,14 @@ static int N3DSAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
}
|
||||
|
||||
device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size);
|
||||
if (device->hidden->mixbuf == NULL) {
|
||||
if (!device->hidden->mixbuf) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size);
|
||||
|
||||
data_vaddr = (Uint8 *)linearAlloc(device->buffer_size * NUM_BUFFERS);
|
||||
if (data_vaddr == NULL) {
|
||||
if (!data_vaddr) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
||||
@@ -215,7 +215,7 @@ static int NETBSDAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
|
||||
// Initialize all variables that we clean on shutdown
|
||||
device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ static int NETBSDAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
// Allocate mixing buffer
|
||||
device->hidden->mixlen = device->buffer_size;
|
||||
device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->hidden->mixlen);
|
||||
if (device->hidden->mixbuf == NULL) {
|
||||
if (!device->hidden->mixbuf) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size);
|
||||
|
||||
@@ -327,7 +327,7 @@ static int OPENSLES_CreatePCMRecorder(SDL_AudioDevice *device)
|
||||
|
||||
// Create the sound buffers
|
||||
audiodata->mixbuff = (Uint8 *)SDL_malloc(NUM_BUFFERS * device->buffer_size);
|
||||
if (audiodata->mixbuff == NULL) {
|
||||
if (!audiodata->mixbuff) {
|
||||
LOGE("mixbuffer allocate - out of memory");
|
||||
goto failed;
|
||||
}
|
||||
@@ -574,7 +574,7 @@ static int OPENSLES_CreatePCMPlayer(SDL_AudioDevice *device)
|
||||
|
||||
// Create the sound buffers
|
||||
audiodata->mixbuff = (Uint8 *)SDL_malloc(NUM_BUFFERS * device->buffer_size);
|
||||
if (audiodata->mixbuff == NULL) {
|
||||
if (!audiodata->mixbuff) {
|
||||
LOGE("mixbuffer allocate - out of memory");
|
||||
goto failed;
|
||||
}
|
||||
@@ -599,7 +599,7 @@ failed:
|
||||
static int OPENSLES_OpenDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ static void *pipewire_handle = NULL;
|
||||
static int pipewire_dlsym(const char *fn, void **addr)
|
||||
{
|
||||
*addr = SDL_LoadFunction(pipewire_handle, fn);
|
||||
if (*addr == NULL) {
|
||||
if (!*addr) {
|
||||
// Don't call SDL_SetError(): SDL_LoadFunction already did.
|
||||
return 0;
|
||||
}
|
||||
@@ -142,7 +142,7 @@ static int pipewire_dlsym(const char *fn, void **addr)
|
||||
static int load_pipewire_library(void)
|
||||
{
|
||||
pipewire_handle = SDL_LoadObject(pipewire_library);
|
||||
return pipewire_handle != NULL ? 0 : -1;
|
||||
return pipewire_handle ? 0 : -1;
|
||||
}
|
||||
|
||||
static void unload_pipewire_library(void)
|
||||
@@ -404,7 +404,7 @@ static void *node_object_new(Uint32 id, const char *type, Uint32 version, const
|
||||
|
||||
// Create the proxy object
|
||||
proxy = pw_registry_bind(hotplug_registry, id, type, version, sizeof(struct node_object));
|
||||
if (proxy == NULL) {
|
||||
if (!proxy) {
|
||||
SDL_SetError("Pipewire: Failed to create proxy object (%i)", errno);
|
||||
return NULL;
|
||||
}
|
||||
@@ -623,16 +623,16 @@ static int metadata_property(void *object, Uint32 subject, const char *key, cons
|
||||
{
|
||||
struct node_object *node = object;
|
||||
|
||||
if (subject == PW_ID_CORE && key != NULL && value != NULL) {
|
||||
if (subject == PW_ID_CORE && key && value) {
|
||||
if (!SDL_strcmp(key, "default.audio.sink")) {
|
||||
if (pipewire_default_sink_id != NULL) {
|
||||
if (pipewire_default_sink_id) {
|
||||
SDL_free(pipewire_default_sink_id);
|
||||
}
|
||||
pipewire_default_sink_id = get_name_from_json(value);
|
||||
node->persist = SDL_TRUE;
|
||||
change_default_device(pipewire_default_sink_id);
|
||||
} else if (!SDL_strcmp(key, "default.audio.source")) {
|
||||
if (pipewire_default_source_id != NULL) {
|
||||
if (pipewire_default_source_id) {
|
||||
SDL_free(pipewire_default_source_id);
|
||||
}
|
||||
pipewire_default_source_id = get_name_from_json(value);
|
||||
@@ -678,7 +678,7 @@ static void registry_event_global_callback(void *object, uint32_t id, uint32_t p
|
||||
|
||||
if (node_desc && node_path) {
|
||||
node = node_object_new(id, type, version, &interface_node_events, &interface_core_events);
|
||||
if (node == NULL) {
|
||||
if (!node) {
|
||||
SDL_SetError("Pipewire: Failed to allocate interface node");
|
||||
return;
|
||||
}
|
||||
@@ -687,7 +687,7 @@ static void registry_event_global_callback(void *object, uint32_t id, uint32_t p
|
||||
desc_buffer_len = SDL_strlen(node_desc) + 1;
|
||||
path_buffer_len = SDL_strlen(node_path) + 1;
|
||||
node->userdata = io = SDL_calloc(1, sizeof(struct io_node) + desc_buffer_len + path_buffer_len);
|
||||
if (io == NULL) {
|
||||
if (!io) {
|
||||
node_object_destroy(node);
|
||||
SDL_OutOfMemory();
|
||||
return;
|
||||
@@ -708,7 +708,7 @@ static void registry_event_global_callback(void *object, uint32_t id, uint32_t p
|
||||
}
|
||||
} else if (!SDL_strcmp(type, PW_TYPE_INTERFACE_Metadata)) {
|
||||
node = node_object_new(id, type, version, &metadata_node_events, &metadata_core_events);
|
||||
if (node == NULL) {
|
||||
if (!node) {
|
||||
SDL_SetError("Pipewire: Failed to allocate metadata node");
|
||||
return;
|
||||
}
|
||||
@@ -736,22 +736,22 @@ static int hotplug_loop_init(void)
|
||||
spa_list_init(&hotplug_io_list);
|
||||
|
||||
hotplug_loop = PIPEWIRE_pw_thread_loop_new("SDLAudioHotplug", NULL);
|
||||
if (hotplug_loop == NULL) {
|
||||
if (!hotplug_loop) {
|
||||
return SDL_SetError("Pipewire: Failed to create hotplug detection loop (%i)", errno);
|
||||
}
|
||||
|
||||
hotplug_context = PIPEWIRE_pw_context_new(PIPEWIRE_pw_thread_loop_get_loop(hotplug_loop), NULL, 0);
|
||||
if (hotplug_context == NULL) {
|
||||
if (!hotplug_context) {
|
||||
return SDL_SetError("Pipewire: Failed to create hotplug detection context (%i)", errno);
|
||||
}
|
||||
|
||||
hotplug_core = PIPEWIRE_pw_context_connect(hotplug_context, NULL, 0);
|
||||
if (hotplug_core == NULL) {
|
||||
if (!hotplug_core) {
|
||||
return SDL_SetError("Pipewire: Failed to connect hotplug detection context (%i)", errno);
|
||||
}
|
||||
|
||||
hotplug_registry = pw_core_get_registry(hotplug_core, PW_VERSION_REGISTRY, 0);
|
||||
if (hotplug_registry == NULL) {
|
||||
if (!hotplug_registry) {
|
||||
return SDL_SetError("Pipewire: Failed to acquire hotplug detection registry (%i)", errno);
|
||||
}
|
||||
|
||||
@@ -783,11 +783,11 @@ static void hotplug_loop_destroy(void)
|
||||
hotplug_init_complete = SDL_FALSE;
|
||||
hotplug_events_enabled = SDL_FALSE;
|
||||
|
||||
if (pipewire_default_sink_id != NULL) {
|
||||
if (pipewire_default_sink_id) {
|
||||
SDL_free(pipewire_default_sink_id);
|
||||
pipewire_default_sink_id = NULL;
|
||||
}
|
||||
if (pipewire_default_source_id != NULL) {
|
||||
if (pipewire_default_source_id) {
|
||||
SDL_free(pipewire_default_source_id);
|
||||
pipewire_default_source_id = NULL;
|
||||
}
|
||||
@@ -826,10 +826,10 @@ static void PIPEWIRE_DetectDevices(SDL_AudioDevice **default_output, SDL_AudioDe
|
||||
|
||||
spa_list_for_each (io, &hotplug_io_list, link) {
|
||||
SDL_AudioDevice *device = SDL_AddAudioDevice(io->is_capture, io->name, &io->spec, PW_ID_TO_HANDLE(io->id));
|
||||
if (pipewire_default_sink_id != NULL && SDL_strcmp(io->path, pipewire_default_sink_id) == 0) {
|
||||
if (pipewire_default_sink_id && SDL_strcmp(io->path, pipewire_default_sink_id) == 0) {
|
||||
SDL_assert(!io->is_capture);
|
||||
*default_output = device;
|
||||
} else if (pipewire_default_source_id != NULL && SDL_strcmp(io->path, pipewire_default_source_id) == 0) {
|
||||
} else if (pipewire_default_source_id && SDL_strcmp(io->path, pipewire_default_source_id) == 0) {
|
||||
SDL_assert(io->is_capture);
|
||||
*default_capture = device;
|
||||
}
|
||||
@@ -965,7 +965,7 @@ static void PIPEWIRE_FlushCapture(SDL_AudioDevice *device)
|
||||
{
|
||||
struct pw_stream *stream = device->hidden->stream;
|
||||
struct pw_buffer *pw_buf = PIPEWIRE_pw_stream_dequeue_buffer(stream);
|
||||
if (pw_buf != NULL) { // just requeue it without any further thought.
|
||||
if (pw_buf) { // just requeue it without any further thought.
|
||||
PIPEWIRE_pw_stream_queue_buffer(stream, pw_buf);
|
||||
}
|
||||
}
|
||||
@@ -1062,7 +1062,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
|
||||
struct SDL_PrivateAudioData *priv;
|
||||
struct pw_properties *props;
|
||||
const char *app_name, *app_id, *stream_name, *stream_role, *error;
|
||||
Uint32 node_id = device->handle == NULL ? PW_ID_ANY : PW_HANDLE_TO_ID(device->handle);
|
||||
Uint32 node_id = !device->handle ? PW_ID_ANY : PW_HANDLE_TO_ID(device->handle);
|
||||
const SDL_bool iscapture = device->iscapture;
|
||||
int res;
|
||||
|
||||
@@ -1071,9 +1071,9 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
|
||||
|
||||
// Get the hints for the application name, stream name and role
|
||||
app_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_APP_NAME);
|
||||
if (app_name == NULL || *app_name == '\0') {
|
||||
if (!app_name || *app_name == '\0') {
|
||||
app_name = SDL_GetHint(SDL_HINT_APP_NAME);
|
||||
if (app_name == NULL || *app_name == '\0') {
|
||||
if (!app_name || *app_name == '\0') {
|
||||
app_name = "SDL Application";
|
||||
}
|
||||
}
|
||||
@@ -1082,7 +1082,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
|
||||
app_id = SDL_GetHint(SDL_HINT_APP_ID);
|
||||
|
||||
stream_name = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_NAME);
|
||||
if (stream_name == NULL || *stream_name == '\0') {
|
||||
if (!stream_name || *stream_name == '\0') {
|
||||
stream_name = "Audio Stream";
|
||||
}
|
||||
|
||||
@@ -1091,20 +1091,20 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
|
||||
* but 'Game' seems more appropriate for the majority of SDL applications.
|
||||
*/
|
||||
stream_role = SDL_GetHint(SDL_HINT_AUDIO_DEVICE_STREAM_ROLE);
|
||||
if (stream_role == NULL || *stream_role == '\0') {
|
||||
if (!stream_role || *stream_role == '\0') {
|
||||
stream_role = "Game";
|
||||
}
|
||||
|
||||
// Initialize the Pipewire stream info from the SDL audio spec
|
||||
initialize_spa_info(&device->spec, &spa_info);
|
||||
params = spa_format_audio_raw_build(&b, SPA_PARAM_EnumFormat, &spa_info);
|
||||
if (params == NULL) {
|
||||
if (!params) {
|
||||
return SDL_SetError("Pipewire: Failed to set audio format parameters");
|
||||
}
|
||||
|
||||
priv = SDL_calloc(1, sizeof(struct SDL_PrivateAudioData));
|
||||
device->hidden = priv;
|
||||
if (priv == NULL) {
|
||||
if (!priv) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -1119,23 +1119,23 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
|
||||
|
||||
SDL_GetAudioThreadName(device, thread_name, sizeof(thread_name));
|
||||
priv->loop = PIPEWIRE_pw_thread_loop_new(thread_name, NULL);
|
||||
if (priv->loop == NULL) {
|
||||
if (!priv->loop) {
|
||||
return SDL_SetError("Pipewire: Failed to create stream loop (%i)", errno);
|
||||
}
|
||||
|
||||
// Load the realtime module so Pipewire can set the loop thread to the appropriate priority.
|
||||
props = PIPEWIRE_pw_properties_new(PW_KEY_CONFIG_NAME, "client-rt.conf", NULL);
|
||||
if (props == NULL) {
|
||||
if (!props) {
|
||||
return SDL_SetError("Pipewire: Failed to create stream context properties (%i)", errno);
|
||||
}
|
||||
|
||||
priv->context = PIPEWIRE_pw_context_new(PIPEWIRE_pw_thread_loop_get_loop(priv->loop), props, 0);
|
||||
if (priv->context == NULL) {
|
||||
if (!priv->context) {
|
||||
return SDL_SetError("Pipewire: Failed to create stream context (%i)", errno);
|
||||
}
|
||||
|
||||
props = PIPEWIRE_pw_properties_new(NULL, NULL);
|
||||
if (props == NULL) {
|
||||
if (!props) {
|
||||
return SDL_SetError("Pipewire: Failed to create stream properties (%i)", errno);
|
||||
}
|
||||
|
||||
@@ -1143,7 +1143,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
|
||||
PIPEWIRE_pw_properties_set(props, PW_KEY_MEDIA_CATEGORY, iscapture ? "Capture" : "Playback");
|
||||
PIPEWIRE_pw_properties_set(props, PW_KEY_MEDIA_ROLE, stream_role);
|
||||
PIPEWIRE_pw_properties_set(props, PW_KEY_APP_NAME, app_name);
|
||||
if (app_id != NULL) {
|
||||
if (app_id) {
|
||||
PIPEWIRE_pw_properties_set(props, PW_KEY_APP_ID, app_id);
|
||||
}
|
||||
PIPEWIRE_pw_properties_set(props, PW_KEY_NODE_NAME, stream_name);
|
||||
@@ -1165,7 +1165,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
|
||||
|
||||
PIPEWIRE_pw_thread_loop_lock(hotplug_loop);
|
||||
node = io_list_get_by_id(node_id);
|
||||
if (node != NULL) {
|
||||
if (node) {
|
||||
PIPEWIRE_pw_properties_set(props, PW_KEY_TARGET_OBJECT, node->path);
|
||||
}
|
||||
PIPEWIRE_pw_thread_loop_unlock(hotplug_loop);
|
||||
@@ -1177,7 +1177,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device)
|
||||
// Create the new stream
|
||||
priv->stream = PIPEWIRE_pw_stream_new_simple(PIPEWIRE_pw_thread_loop_get_loop(priv->loop), stream_name, props,
|
||||
iscapture ? &stream_input_events : &stream_output_events, device);
|
||||
if (priv->stream == NULL) {
|
||||
if (!priv->stream) {
|
||||
return SDL_SetError("Pipewire: Failed to create stream (%i)", errno);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
static int PS2AUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ static int PS2AUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
64, so spec->size should be a multiple of 64 as well. */
|
||||
const int mixlen = device->buffer_size * NUM_BUFFERS;
|
||||
device->hidden->rawbuf = (Uint8 *)SDL_aligned_alloc(64, mixlen);
|
||||
if (device->hidden->rawbuf == NULL) {
|
||||
if (!device->hidden->rawbuf) {
|
||||
return SDL_SetError("Couldn't allocate mixing buffer");
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ static void PS2AUDIO_CloseDevice(SDL_AudioDevice *device)
|
||||
device->hidden->channel = -1;
|
||||
}
|
||||
|
||||
if (device->hidden->rawbuf != NULL) {
|
||||
if (device->hidden->rawbuf) {
|
||||
SDL_aligned_free(device->hidden->rawbuf);
|
||||
device->hidden->rawbuf = NULL;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ static inline SDL_bool isBasicAudioConfig(const SDL_AudioSpec *spec)
|
||||
static int PSPAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ static int PSPAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
64, so spec->size should be a multiple of 64 as well. */
|
||||
const int mixlen = device->buffer_size * NUM_BUFFERS;
|
||||
device->hidden->rawbuf = (Uint8 *)SDL_aligned_alloc(64, mixlen);
|
||||
if (device->hidden->rawbuf == NULL) {
|
||||
if (!device->hidden->rawbuf) {
|
||||
return SDL_SetError("Couldn't allocate mixing buffer");
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ static void PSPAUDIO_CloseDevice(SDL_AudioDevice *device)
|
||||
device->hidden->channel = -1;
|
||||
}
|
||||
|
||||
if (device->hidden->rawbuf != NULL) {
|
||||
if (device->hidden->rawbuf) {
|
||||
SDL_aligned_free(device->hidden->rawbuf);
|
||||
device->hidden->rawbuf = NULL;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ static void *pulseaudio_handle = NULL;
|
||||
static int load_pulseaudio_sym(const char *fn, void **addr)
|
||||
{
|
||||
*addr = SDL_LoadFunction(pulseaudio_handle, fn);
|
||||
if (*addr == NULL) {
|
||||
if (!*addr) {
|
||||
// Don't call SDL_SetError(): SDL_LoadFunction already did.
|
||||
return 0;
|
||||
}
|
||||
@@ -150,7 +150,7 @@ static int load_pulseaudio_sym(const char *fn, void **addr)
|
||||
|
||||
static void UnloadPulseAudioLibrary(void)
|
||||
{
|
||||
if (pulseaudio_handle != NULL) {
|
||||
if (pulseaudio_handle) {
|
||||
SDL_UnloadObject(pulseaudio_handle);
|
||||
pulseaudio_handle = NULL;
|
||||
}
|
||||
@@ -159,9 +159,9 @@ static void UnloadPulseAudioLibrary(void)
|
||||
static int LoadPulseAudioLibrary(void)
|
||||
{
|
||||
int retval = 0;
|
||||
if (pulseaudio_handle == NULL) {
|
||||
if (!pulseaudio_handle) {
|
||||
pulseaudio_handle = SDL_LoadObject(pulseaudio_library);
|
||||
if (pulseaudio_handle == NULL) {
|
||||
if (!pulseaudio_handle) {
|
||||
retval = -1;
|
||||
// Don't call SDL_SetError(): SDL_LoadObject already did.
|
||||
} else {
|
||||
@@ -275,7 +275,7 @@ static const char *getAppName(void)
|
||||
} else {
|
||||
const char *verstr = PULSEAUDIO_pa_get_library_version();
|
||||
retval = "SDL Application"; // the "oh well" default.
|
||||
if (verstr != NULL) {
|
||||
if (verstr) {
|
||||
int maj, min, patch;
|
||||
if (SDL_sscanf(verstr, "%d.%d.%d", &maj, &min, &patch) == 3) {
|
||||
if (squashVersion(maj, min, patch) >= squashVersion(0, 9, 15)) {
|
||||
@@ -297,13 +297,13 @@ static void OperationStateChangeCallback(pa_operation *o, void *userdata)
|
||||
static void WaitForPulseOperation(pa_operation *o)
|
||||
{
|
||||
// This checks for NO errors currently. Either fix that, check results elsewhere, or do things you don't care about.
|
||||
SDL_assert(pulseaudio_threaded_mainloop != NULL);
|
||||
SDL_assert(pulseaudio_threaded_mainloop);
|
||||
if (o) {
|
||||
// note that if PULSEAUDIO_pa_operation_set_state_callback == NULL, then `o` must have a callback that will signal pulseaudio_threaded_mainloop.
|
||||
// If not, on really old (earlier PulseAudio 4.0, from the year 2013!) installs, this call will block forever.
|
||||
// On more modern installs, we won't ever block forever, and maybe be more efficient, thanks to pa_operation_set_state_callback.
|
||||
// WARNING: at the time of this writing: the Steam Runtime is still on PulseAudio 1.1!
|
||||
if (PULSEAUDIO_pa_operation_set_state_callback != NULL) {
|
||||
if (PULSEAUDIO_pa_operation_set_state_callback) {
|
||||
PULSEAUDIO_pa_operation_set_state_callback(o, OperationStateChangeCallback, NULL);
|
||||
}
|
||||
while (PULSEAUDIO_pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
|
||||
@@ -315,7 +315,7 @@ static void WaitForPulseOperation(pa_operation *o)
|
||||
|
||||
static void DisconnectFromPulseServer(void)
|
||||
{
|
||||
if (pulseaudio_threaded_mainloop != NULL) {
|
||||
if (pulseaudio_threaded_mainloop) {
|
||||
PULSEAUDIO_pa_threaded_mainloop_stop(pulseaudio_threaded_mainloop);
|
||||
}
|
||||
if (pulseaudio_context) {
|
||||
@@ -323,7 +323,7 @@ static void DisconnectFromPulseServer(void)
|
||||
PULSEAUDIO_pa_context_unref(pulseaudio_context);
|
||||
pulseaudio_context = NULL;
|
||||
}
|
||||
if (pulseaudio_threaded_mainloop != NULL) {
|
||||
if (pulseaudio_threaded_mainloop) {
|
||||
PULSEAUDIO_pa_threaded_mainloop_free(pulseaudio_threaded_mainloop);
|
||||
pulseaudio_threaded_mainloop = NULL;
|
||||
}
|
||||
@@ -339,8 +339,8 @@ static int ConnectToPulseServer(void)
|
||||
pa_mainloop_api *mainloop_api = NULL;
|
||||
int state = 0;
|
||||
|
||||
SDL_assert(pulseaudio_threaded_mainloop == NULL);
|
||||
SDL_assert(pulseaudio_context == NULL);
|
||||
SDL_assert(!pulseaudio_threaded_mainloop);
|
||||
SDL_assert(!pulseaudio_context);
|
||||
|
||||
// Set up a new main loop
|
||||
if (!(pulseaudio_threaded_mainloop = PULSEAUDIO_pa_threaded_mainloop_new())) {
|
||||
@@ -363,7 +363,7 @@ static int ConnectToPulseServer(void)
|
||||
SDL_assert(mainloop_api); // this never fails, right?
|
||||
|
||||
pulseaudio_context = PULSEAUDIO_pa_context_new(mainloop_api, getAppName());
|
||||
if (pulseaudio_context == NULL) {
|
||||
if (!pulseaudio_context) {
|
||||
SDL_SetError("pa_context_new() failed");
|
||||
goto failed;
|
||||
}
|
||||
@@ -480,7 +480,7 @@ static int PULSEAUDIO_WaitCaptureDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
struct SDL_PrivateAudioData *h = device->hidden;
|
||||
|
||||
if (h->capturebuf != NULL) {
|
||||
if (h->capturebuf) {
|
||||
return 0; // there's still data available to read.
|
||||
}
|
||||
|
||||
@@ -500,7 +500,7 @@ static int PULSEAUDIO_WaitCaptureDevice(SDL_AudioDevice *device)
|
||||
size_t nbytes = 0;
|
||||
PULSEAUDIO_pa_stream_peek(h->stream, &data, &nbytes);
|
||||
SDL_assert(nbytes > 0);
|
||||
if (data == NULL) { // If NULL, then the buffer had a hole, ignore that
|
||||
if (!data) { // If NULL, then the buffer had a hole, ignore that
|
||||
PULSEAUDIO_pa_stream_drop(h->stream); // drop this fragment.
|
||||
} else {
|
||||
// store this fragment's data for use with CaptureFromDevice
|
||||
@@ -521,7 +521,7 @@ static int PULSEAUDIO_CaptureFromDevice(SDL_AudioDevice *device, void *buffer, i
|
||||
{
|
||||
struct SDL_PrivateAudioData *h = device->hidden;
|
||||
|
||||
if (h->capturebuf != NULL) {
|
||||
if (h->capturebuf) {
|
||||
const int cpy = SDL_min(buflen, h->capturelen);
|
||||
if (cpy > 0) {
|
||||
//SDL_Log("PULSEAUDIO: fed %d captured bytes", cpy);
|
||||
@@ -549,7 +549,7 @@ static void PULSEAUDIO_FlushCapture(SDL_AudioDevice *device)
|
||||
|
||||
PULSEAUDIO_pa_threaded_mainloop_lock(pulseaudio_threaded_mainloop);
|
||||
|
||||
if (h->capturebuf != NULL) {
|
||||
if (h->capturebuf) {
|
||||
PULSEAUDIO_pa_stream_drop(h->stream);
|
||||
h->capturebuf = NULL;
|
||||
h->capturelen = 0;
|
||||
@@ -578,7 +578,7 @@ static void PULSEAUDIO_CloseDevice(SDL_AudioDevice *device)
|
||||
PULSEAUDIO_pa_threaded_mainloop_lock(pulseaudio_threaded_mainloop);
|
||||
|
||||
if (device->hidden->stream) {
|
||||
if (device->hidden->capturebuf != NULL) {
|
||||
if (device->hidden->capturebuf) {
|
||||
PULSEAUDIO_pa_stream_drop(device->hidden->stream);
|
||||
}
|
||||
PULSEAUDIO_pa_stream_disconnect(device->hidden->stream);
|
||||
@@ -609,12 +609,12 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
int format = PA_SAMPLE_INVALID;
|
||||
int retval = 0;
|
||||
|
||||
SDL_assert(pulseaudio_threaded_mainloop != NULL);
|
||||
SDL_assert(pulseaudio_context != NULL);
|
||||
SDL_assert(pulseaudio_threaded_mainloop);
|
||||
SDL_assert(pulseaudio_context);
|
||||
|
||||
// Initialize all variables that we clean on shutdown
|
||||
h = device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -663,7 +663,7 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
// Allocate mixing buffer
|
||||
if (!iscapture) {
|
||||
h->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size);
|
||||
if (h->mixbuf == NULL) {
|
||||
if (!h->mixbuf) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(h->mixbuf, device->silence_value, device->buffer_size);
|
||||
@@ -694,7 +694,7 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
&pacmap // channel map
|
||||
);
|
||||
|
||||
if (h->stream == NULL) {
|
||||
if (!h->stream) {
|
||||
retval = SDL_SetError("Could not set up PulseAudio stream");
|
||||
} else {
|
||||
int rc;
|
||||
|
||||
@@ -176,7 +176,7 @@ static Uint8 *QSA_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||
static void QSA_CloseDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
if (device->hidden) {
|
||||
if (device->hidden->audio_handle != NULL) {
|
||||
if (device->hidden->audio_handle) {
|
||||
#if _NTO_VERSION < 710
|
||||
// Finish playing available samples or cancel unread samples during capture
|
||||
snd_pcm_plugin_flush(device->hidden->audio_handle, device->iscapture ? SND_PCM_CHANNEL_CAPTURE : SND_PCM_CHANNEL_PLAYBACK);
|
||||
|
||||
@@ -71,7 +71,7 @@ static void *sndio_handle = NULL;
|
||||
static int load_sndio_sym(const char *fn, void **addr)
|
||||
{
|
||||
*addr = SDL_LoadFunction(sndio_handle, fn);
|
||||
if (*addr == NULL) {
|
||||
if (!*addr) {
|
||||
return 0; // Don't call SDL_SetError(): SDL_LoadFunction already did.
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ static int load_sndio_syms(void)
|
||||
|
||||
static void UnloadSNDIOLibrary(void)
|
||||
{
|
||||
if (sndio_handle != NULL) {
|
||||
if (sndio_handle) {
|
||||
SDL_UnloadObject(sndio_handle);
|
||||
sndio_handle = NULL;
|
||||
}
|
||||
@@ -119,9 +119,9 @@ static void UnloadSNDIOLibrary(void)
|
||||
static int LoadSNDIOLibrary(void)
|
||||
{
|
||||
int retval = 0;
|
||||
if (sndio_handle == NULL) {
|
||||
if (!sndio_handle) {
|
||||
sndio_handle = SDL_LoadObject(sndio_library);
|
||||
if (sndio_handle == NULL) {
|
||||
if (!sndio_handle) {
|
||||
retval = -1; // Don't call SDL_SetError(): SDL_LoadObject already did.
|
||||
} else {
|
||||
retval = load_sndio_syms();
|
||||
@@ -213,7 +213,7 @@ static Uint8 *SNDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||
static void SNDIO_CloseDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
if (device->hidden) {
|
||||
if (device->hidden->dev != NULL) {
|
||||
if (device->hidden->dev) {
|
||||
SNDIO_sio_stop(device->hidden->dev);
|
||||
SNDIO_sio_close(device->hidden->dev);
|
||||
}
|
||||
@@ -227,7 +227,7 @@ static void SNDIO_CloseDevice(SDL_AudioDevice *device)
|
||||
static int SNDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -235,14 +235,14 @@ static int SNDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
const char *audiodev = SDL_getenv("AUDIODEV");
|
||||
|
||||
// Capture devices must be non-blocking for SNDIO_FlushCapture
|
||||
device->hidden->dev = SNDIO_sio_open(audiodev != NULL ? audiodev : SIO_DEVANY,
|
||||
device->hidden->dev = SNDIO_sio_open(audiodev ? audiodev : SIO_DEVANY,
|
||||
device->iscapture ? SIO_REC : SIO_PLAY, device->iscapture);
|
||||
if (device->hidden->dev == NULL) {
|
||||
if (!device->hidden->dev) {
|
||||
return SDL_SetError("sio_open() failed");
|
||||
}
|
||||
|
||||
device->hidden->pfd = SDL_malloc(sizeof(struct pollfd) * SNDIO_sio_nfds(device->hidden->dev));
|
||||
if (device->hidden->pfd == NULL) {
|
||||
if (!device->hidden->pfd) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ static int SNDIO_OpenDevice(SDL_AudioDevice *device)
|
||||
|
||||
// Allocate mixing buffer
|
||||
device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size);
|
||||
if (device->hidden->mixbuf == NULL) {
|
||||
if (!device->hidden->mixbuf) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size);
|
||||
|
||||
@@ -63,7 +63,7 @@ static int VITAAUD_OpenDevice(SDL_AudioDevice *device)
|
||||
|
||||
device->hidden = (struct SDL_PrivateAudioData *)
|
||||
SDL_malloc(sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SDL_memset(device->hidden, 0, sizeof(*device->hidden));
|
||||
@@ -95,7 +95,7 @@ static int VITAAUD_OpenDevice(SDL_AudioDevice *device)
|
||||
64, so spec->size should be a multiple of 64 as well. */
|
||||
mixlen = device->buffer_size * NUM_BUFFERS;
|
||||
device->hidden->rawbuf = (Uint8 *)SDL_aligned_alloc(64, mixlen);
|
||||
if (device->hidden->rawbuf == NULL) {
|
||||
if (!device->hidden->rawbuf) {
|
||||
return SDL_SetError("Couldn't allocate mixing buffer");
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ static void VITAAUD_CloseDevice(SDL_AudioDevice *device)
|
||||
device->hidden->port = -1;
|
||||
}
|
||||
|
||||
if (!device->iscapture && device->hidden->rawbuf != NULL) {
|
||||
if (!device->iscapture && device->hidden->rawbuf) {
|
||||
SDL_aligned_free(device->hidden->rawbuf); // this uses SDL_aligned_alloc(), not SDL_malloc()
|
||||
device->hidden->rawbuf = NULL;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ static void ManagementThreadMainloop(void)
|
||||
int WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, int *wait_on_result)
|
||||
{
|
||||
// We want to block for a result, but we are already running from the management thread! Just run the task now so we don't deadlock.
|
||||
if ((wait_on_result != NULL) && (SDL_ThreadID() == SDL_GetThreadID(ManagementThread))) {
|
||||
if ((wait_on_result) && (SDL_ThreadID() == SDL_GetThreadID(ManagementThread))) {
|
||||
*wait_on_result = task(userdata);
|
||||
return 0; // completed!
|
||||
}
|
||||
@@ -124,11 +124,11 @@ int WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, in
|
||||
|
||||
// add to end of task list.
|
||||
ManagementThreadPendingTask *prev = NULL;
|
||||
for (ManagementThreadPendingTask *i = SDL_AtomicGetPtr((void **) &ManagementThreadPendingTasks); i != NULL; i = i->next) {
|
||||
for (ManagementThreadPendingTask *i = SDL_AtomicGetPtr((void **) &ManagementThreadPendingTasks); i; i = i->next) {
|
||||
prev = i;
|
||||
}
|
||||
|
||||
if (prev != NULL) {
|
||||
if (prev) {
|
||||
prev->next = pending;
|
||||
} else {
|
||||
SDL_AtomicSetPtr((void **) &ManagementThreadPendingTasks, pending);
|
||||
@@ -413,7 +413,7 @@ static Uint8 *WASAPI_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||
|
||||
if (device->hidden->render) {
|
||||
if (WasapiFailed(device, IAudioRenderClient_GetBuffer(device->hidden->render, device->sample_frames, &buffer))) {
|
||||
SDL_assert(buffer == NULL);
|
||||
SDL_assert(!buffer);
|
||||
if (device->hidden->device_lost) { // just use an available buffer, we won't be playing it anyhow.
|
||||
*buffer_size = 0; // we'll recover during WaitDevice and try again.
|
||||
}
|
||||
@@ -425,7 +425,7 @@ static Uint8 *WASAPI_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size)
|
||||
|
||||
static int WASAPI_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen)
|
||||
{
|
||||
if (device->hidden->render != NULL) { // definitely activated?
|
||||
if (device->hidden->render) { // definitely activated?
|
||||
// WasapiFailed() will mark the device for reacquisition or removal elsewhere.
|
||||
WasapiFailed(device, IAudioRenderClient_ReleaseBuffer(device->hidden->render, device->sample_frames, 0));
|
||||
}
|
||||
@@ -542,7 +542,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
|
||||
const AUDCLNT_SHAREMODE sharemode = AUDCLNT_SHAREMODE_SHARED;
|
||||
|
||||
IAudioClient *client = device->hidden->client;
|
||||
SDL_assert(client != NULL);
|
||||
SDL_assert(client);
|
||||
|
||||
#if defined(__WINRT__) || defined(__GDK__) // CreateEventEx() arrived in Vista, so we need an #ifdef for XP.
|
||||
device->hidden->event = CreateEventEx(NULL, NULL, 0, EVENT_ALL_ACCESS);
|
||||
@@ -550,7 +550,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
|
||||
device->hidden->event = CreateEventW(NULL, 0, 0, NULL);
|
||||
#endif
|
||||
|
||||
if (device->hidden->event == NULL) {
|
||||
if (!device->hidden->event) {
|
||||
return WIN_SetError("WASAPI can't create an event handle");
|
||||
}
|
||||
|
||||
@@ -561,7 +561,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
|
||||
if (FAILED(ret)) {
|
||||
return WIN_SetErrorFromHRESULT("WASAPI can't determine mix format", ret);
|
||||
}
|
||||
SDL_assert(waveformat != NULL);
|
||||
SDL_assert(waveformat);
|
||||
device->hidden->waveformat = waveformat;
|
||||
|
||||
SDL_AudioSpec newspec;
|
||||
@@ -642,7 +642,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
|
||||
return WIN_SetErrorFromHRESULT("WASAPI can't get capture client service", ret);
|
||||
}
|
||||
|
||||
SDL_assert(capture != NULL);
|
||||
SDL_assert(capture);
|
||||
device->hidden->capture = capture;
|
||||
ret = IAudioClient_Start(client);
|
||||
if (FAILED(ret)) {
|
||||
@@ -657,7 +657,7 @@ static int mgmtthrtask_PrepDevice(void *userdata)
|
||||
return WIN_SetErrorFromHRESULT("WASAPI can't get render client service", ret);
|
||||
}
|
||||
|
||||
SDL_assert(render != NULL);
|
||||
SDL_assert(render);
|
||||
device->hidden->render = render;
|
||||
ret = IAudioClient_Start(client);
|
||||
if (FAILED(ret)) {
|
||||
@@ -679,7 +679,7 @@ static int WASAPI_OpenDevice(SDL_AudioDevice *device)
|
||||
{
|
||||
// Initialize all variables that we clean on shutdown
|
||||
device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden));
|
||||
if (device->hidden == NULL) {
|
||||
if (!device->hidden) {
|
||||
return SDL_OutOfMemory();
|
||||
} else if (ActivateWasapiDevice(device) < 0) {
|
||||
return -1; // already set error.
|
||||
|
||||
@@ -164,11 +164,11 @@ int WASAPI_ActivateDevice(SDL_AudioDevice *device)
|
||||
IMMDevice_Release(immdevice);
|
||||
|
||||
if (FAILED(ret)) {
|
||||
SDL_assert(device->hidden->client == NULL);
|
||||
SDL_assert(!device->hidden->client);
|
||||
return WIN_SetErrorFromHRESULT("WASAPI can't activate audio endpoint", ret);
|
||||
}
|
||||
|
||||
SDL_assert(device->hidden->client != NULL);
|
||||
SDL_assert(device->hidden->client);
|
||||
if (WASAPI_PrepDevice(device) == -1) { // not async, fire it right away.
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ SDL_RunApp(int argc, char* argv[], SDL_main_func mainFunction, void * reserved)
|
||||
|
||||
(void)reserved;
|
||||
|
||||
if(argv == NULL)
|
||||
if(!argv)
|
||||
{
|
||||
argc = 0;
|
||||
/* make sure argv isn't NULL, in case some user code doesn't like that */
|
||||
|
||||
@@ -434,12 +434,12 @@ JNIEnv *Android_JNI_GetEnv(void)
|
||||
{
|
||||
/* Get JNIEnv from the Thread local storage */
|
||||
JNIEnv *env = pthread_getspecific(mThreadKey);
|
||||
if (env == NULL) {
|
||||
if (!env) {
|
||||
/* If it fails, try to attach ! (e.g the thread isn't created with SDL_CreateThread() */
|
||||
int status;
|
||||
|
||||
/* There should be a JVM */
|
||||
if (mJavaVM == NULL) {
|
||||
if (!mJavaVM) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed, there is no JavaVM");
|
||||
return NULL;
|
||||
}
|
||||
@@ -468,7 +468,7 @@ int Android_JNI_SetupThread(void)
|
||||
int status;
|
||||
|
||||
/* There should be a JVM */
|
||||
if (mJavaVM == NULL) {
|
||||
if (!mJavaVM) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed, there is no JavaVM");
|
||||
return 0;
|
||||
}
|
||||
@@ -494,7 +494,7 @@ static void Android_JNI_ThreadDestroyed(void *value)
|
||||
{
|
||||
/* The thread is being destroyed, detach it from the Java VM and set the mThreadKey value to NULL as required */
|
||||
JNIEnv *env = (JNIEnv *)value;
|
||||
if (env != NULL) {
|
||||
if (env) {
|
||||
(*mJavaVM)->DetachCurrentThread(mJavaVM);
|
||||
Android_JNI_SetEnv(NULL);
|
||||
}
|
||||
@@ -520,7 +520,7 @@ static void Android_JNI_CreateKey_once(void)
|
||||
static void register_methods(JNIEnv *env, const char *classname, JNINativeMethod *methods, int nb)
|
||||
{
|
||||
jclass clazz = (*env)->FindClass(env, classname);
|
||||
if (clazz == NULL || (*env)->RegisterNatives(env, clazz, methods, nb) < 0) {
|
||||
if (!clazz || (*env)->RegisterNatives(env, clazz, methods, nb) < 0) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed to register methods of %s", classname);
|
||||
return;
|
||||
}
|
||||
@@ -582,28 +582,28 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl
|
||||
/* Save JNIEnv of SDLActivity */
|
||||
Android_JNI_SetEnv(env);
|
||||
|
||||
if (mJavaVM == NULL) {
|
||||
if (!mJavaVM) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "SDL", "failed to found a JavaVM");
|
||||
}
|
||||
|
||||
/* Use a mutex to prevent concurrency issues between Java Activity and Native thread code, when using 'Android_Window'.
|
||||
* (Eg. Java sending Touch events, while native code is destroying the main SDL_Window. )
|
||||
*/
|
||||
if (Android_ActivityMutex == NULL) {
|
||||
if (!Android_ActivityMutex) {
|
||||
Android_ActivityMutex = SDL_CreateMutex(); /* Could this be created twice if onCreate() is called a second time ? */
|
||||
}
|
||||
|
||||
if (Android_ActivityMutex == NULL) {
|
||||
if (!Android_ActivityMutex) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "SDL", "failed to create Android_ActivityMutex mutex");
|
||||
}
|
||||
|
||||
Android_PauseSem = SDL_CreateSemaphore(0);
|
||||
if (Android_PauseSem == NULL) {
|
||||
if (!Android_PauseSem) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "SDL", "failed to create Android_PauseSem semaphore");
|
||||
}
|
||||
|
||||
Android_ResumeSem = SDL_CreateSemaphore(0);
|
||||
if (Android_ResumeSem == NULL) {
|
||||
if (!Android_ResumeSem) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "SDL", "failed to create Android_ResumeSem semaphore");
|
||||
}
|
||||
|
||||
@@ -1614,7 +1614,7 @@ int Android_JNI_OpenAudioDevice(SDL_AudioDevice *device)
|
||||
__android_log_print(ANDROID_LOG_VERBOSE, "SDL", "SDL audio: opening device for output");
|
||||
result = (*env)->CallStaticObjectMethod(env, mAudioManagerClass, midAudioOpen, spec->freq, audioformat, spec->channels, device->sample_frames, device_id);
|
||||
}
|
||||
if (result == NULL) {
|
||||
if (!result) {
|
||||
/* Error during audio initialization, error printed from Java */
|
||||
return SDL_SetError("Java-side initialization failed");
|
||||
}
|
||||
@@ -1675,7 +1675,7 @@ int Android_JNI_OpenAudioDevice(SDL_AudioDevice *device)
|
||||
return SDL_SetError("Unexpected audio format from Java: %d\n", audioformat);
|
||||
}
|
||||
|
||||
if (jbufobj == NULL) {
|
||||
if (!jbufobj) {
|
||||
__android_log_print(ANDROID_LOG_WARN, "SDL", "SDL audio: could not allocate an audio buffer");
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
@@ -1946,7 +1946,7 @@ static void Internal_Android_Create_AssetManager()
|
||||
javaAssetManagerRef = (*env)->NewGlobalRef(env, javaAssetManager);
|
||||
asset_manager = AAssetManager_fromJava(env, javaAssetManagerRef);
|
||||
|
||||
if (asset_manager == NULL) {
|
||||
if (!asset_manager) {
|
||||
(*env)->DeleteGlobalRef(env, javaAssetManagerRef);
|
||||
Android_JNI_ExceptionOccurred(SDL_TRUE);
|
||||
}
|
||||
@@ -1970,16 +1970,16 @@ int Android_JNI_FileOpen(SDL_RWops *ctx,
|
||||
AAsset *asset = NULL;
|
||||
ctx->hidden.androidio.asset = NULL;
|
||||
|
||||
if (asset_manager == NULL) {
|
||||
if (!asset_manager) {
|
||||
Internal_Android_Create_AssetManager();
|
||||
}
|
||||
|
||||
if (asset_manager == NULL) {
|
||||
if (!asset_manager) {
|
||||
return SDL_SetError("Couldn't create asset manager");
|
||||
}
|
||||
|
||||
asset = AAssetManager_open(asset_manager, fileName, AASSET_MODE_UNKNOWN);
|
||||
if (asset == NULL) {
|
||||
if (!asset) {
|
||||
return SDL_SetError("Couldn't open asset '%s'", fileName);
|
||||
}
|
||||
|
||||
@@ -2051,7 +2051,7 @@ char *Android_JNI_GetClipboardText(void)
|
||||
(*env)->DeleteLocalRef(env, string);
|
||||
}
|
||||
|
||||
return (text == NULL) ? SDL_strdup("") : text;
|
||||
return (!text) ? SDL_strdup("") : text;
|
||||
}
|
||||
|
||||
SDL_bool Android_JNI_HasClipboardText(void)
|
||||
@@ -2371,7 +2371,7 @@ void *SDL_AndroidGetActivity(void)
|
||||
/* See SDL_system.h for caveats on using this function. */
|
||||
|
||||
JNIEnv *env = Android_JNI_GetEnv();
|
||||
if (env == NULL) {
|
||||
if (!env) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -2425,7 +2425,7 @@ const char *SDL_AndroidGetInternalStoragePath(void)
|
||||
{
|
||||
static char *s_AndroidInternalFilesPath = NULL;
|
||||
|
||||
if (s_AndroidInternalFilesPath == NULL) {
|
||||
if (!s_AndroidInternalFilesPath) {
|
||||
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
|
||||
jmethodID mid;
|
||||
jobject context;
|
||||
@@ -2524,7 +2524,7 @@ const char *SDL_AndroidGetExternalStoragePath(void)
|
||||
{
|
||||
static char *s_AndroidExternalFilesPath = NULL;
|
||||
|
||||
if (s_AndroidExternalFilesPath == NULL) {
|
||||
if (!s_AndroidExternalFilesPath) {
|
||||
struct LocalReferenceHolder refs = LocalReferenceHolder_Setup(__FUNCTION__);
|
||||
jmethodID mid;
|
||||
jobject context;
|
||||
@@ -2680,16 +2680,16 @@ int Android_JNI_GetLocale(char *buf, size_t buflen)
|
||||
/* Need to re-create the asset manager if locale has changed (SDL_EVENT_LOCALE_CHANGED) */
|
||||
Internal_Android_Destroy_AssetManager();
|
||||
|
||||
if (asset_manager == NULL) {
|
||||
if (!asset_manager) {
|
||||
Internal_Android_Create_AssetManager();
|
||||
}
|
||||
|
||||
if (asset_manager == NULL) {
|
||||
if (!asset_manager) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cfg = AConfiguration_new();
|
||||
if (cfg == NULL) {
|
||||
if (!cfg) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ static void kbd_cleanup(void)
|
||||
{
|
||||
struct mouse_info mData;
|
||||
SDL_EVDEV_keyboard_state *kbd = kbd_cleanup_state;
|
||||
if (kbd == NULL) {
|
||||
if (!kbd) {
|
||||
return;
|
||||
}
|
||||
kbd_cleanup_state = NULL;
|
||||
@@ -178,7 +178,7 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state *kbd)
|
||||
{
|
||||
int tabidx;
|
||||
|
||||
if (kbd_cleanup_state != NULL) {
|
||||
if (kbd_cleanup_state) {
|
||||
return;
|
||||
}
|
||||
kbd_cleanup_state = kbd;
|
||||
@@ -230,7 +230,7 @@ SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void)
|
||||
SDL_zero(mData);
|
||||
mData.operation = MOUSE_HIDE;
|
||||
kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(SDL_EVDEV_keyboard_state));
|
||||
if (kbd == NULL) {
|
||||
if (!kbd) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ void SDL_EVDEV_kbd_quit(SDL_EVDEV_keyboard_state *kbd)
|
||||
{
|
||||
struct mouse_info mData;
|
||||
|
||||
if (kbd == NULL) {
|
||||
if (!kbd) {
|
||||
return;
|
||||
}
|
||||
SDL_zero(mData);
|
||||
@@ -486,7 +486,7 @@ void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *kbd, unsigned int keycode,
|
||||
unsigned int final_key_state;
|
||||
unsigned int map_from_key_sym;
|
||||
|
||||
if (kbd == NULL) {
|
||||
if (!kbd) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -108,13 +108,13 @@ static int StartBeLooper()
|
||||
{
|
||||
if (!be_app) {
|
||||
SDL_AppThread = SDL_CreateThreadInternal(StartBeApp, "SDLApplication", 0, NULL);
|
||||
if (SDL_AppThread == NULL) {
|
||||
if (!SDL_AppThread) {
|
||||
return SDL_SetError("Couldn't create BApplication thread");
|
||||
}
|
||||
|
||||
do {
|
||||
SDL_Delay(10);
|
||||
} while ((be_app == NULL) || be_app->IsLaunching());
|
||||
} while ((!be_app) || be_app->IsLaunching());
|
||||
}
|
||||
|
||||
/* Change working directory to that of executable */
|
||||
@@ -167,7 +167,7 @@ void SDL_QuitBeApp(void)
|
||||
SDL_Looper->Lock();
|
||||
SDL_Looper->Quit();
|
||||
SDL_Looper = NULL;
|
||||
if (SDL_AppThread != NULL) {
|
||||
if (SDL_AppThread) {
|
||||
if (be_app != NULL) { /* Not tested */
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
|
||||
+10
-10
@@ -96,7 +96,7 @@ static int LoadDBUSSyms(void)
|
||||
|
||||
static void UnloadDBUSLibrary(void)
|
||||
{
|
||||
if (dbus_handle != NULL) {
|
||||
if (dbus_handle) {
|
||||
SDL_UnloadObject(dbus_handle);
|
||||
dbus_handle = NULL;
|
||||
}
|
||||
@@ -105,9 +105,9 @@ static void UnloadDBUSLibrary(void)
|
||||
static int LoadDBUSLibrary(void)
|
||||
{
|
||||
int retval = 0;
|
||||
if (dbus_handle == NULL) {
|
||||
if (!dbus_handle) {
|
||||
dbus_handle = SDL_LoadObject(dbus_library);
|
||||
if (dbus_handle == NULL) {
|
||||
if (!dbus_handle) {
|
||||
retval = -1;
|
||||
/* Don't call SDL_SetError(): SDL_LoadObject already did. */
|
||||
} else {
|
||||
@@ -199,7 +199,7 @@ void SDL_DBus_Quit(void)
|
||||
|
||||
SDL_DBusContext *SDL_DBus_GetContext(void)
|
||||
{
|
||||
if (dbus_handle == NULL || !dbus.session_conn) {
|
||||
if (!dbus_handle || !dbus.session_conn) {
|
||||
SDL_DBus_Init();
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ SDL_bool SDL_DBus_QueryProperty(const char *node, const char *path, const char *
|
||||
|
||||
void SDL_DBus_ScreensaverTickle(void)
|
||||
{
|
||||
if (screensaver_cookie == 0 && inhibit_handle == NULL) { /* no need to tickle if we're inhibiting. */
|
||||
if (screensaver_cookie == 0 && !inhibit_handle) { /* no need to tickle if we're inhibiting. */
|
||||
/* org.gnome.ScreenSaver is the legacy interface, but it'll either do nothing or just be a second harmless tickle on newer systems, so we leave it for now. */
|
||||
SDL_DBus_CallVoidMethod("org.gnome.ScreenSaver", "/org/gnome/ScreenSaver", "org.gnome.ScreenSaver", "SimulateUserActivity", DBUS_TYPE_INVALID);
|
||||
SDL_DBus_CallVoidMethod("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver", "org.freedesktop.ScreenSaver", "SimulateUserActivity", DBUS_TYPE_INVALID);
|
||||
@@ -428,7 +428,7 @@ SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
|
||||
{
|
||||
const char *default_inhibit_reason = "Playing a game";
|
||||
|
||||
if ((inhibit && (screensaver_cookie != 0 || inhibit_handle != NULL)) || (!inhibit && (screensaver_cookie == 0 && inhibit_handle == NULL))) {
|
||||
if ((inhibit && (screensaver_cookie != 0 || inhibit_handle)) || (!inhibit && (screensaver_cookie == 0 && !inhibit_handle))) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
@@ -452,12 +452,12 @@ SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
|
||||
const char *key = "reason";
|
||||
const char *reply = NULL;
|
||||
const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
|
||||
if (reason == NULL || !reason[0]) {
|
||||
if (!reason || !reason[0]) {
|
||||
reason = default_inhibit_reason;
|
||||
}
|
||||
|
||||
msg = dbus.message_new_method_call(bus_name, path, interface, "Inhibit");
|
||||
if (msg == NULL) {
|
||||
if (!msg) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -496,10 +496,10 @@ SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
|
||||
if (inhibit) {
|
||||
const char *app = SDL_GetHint(SDL_HINT_APP_NAME);
|
||||
const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME);
|
||||
if (app == NULL || !app[0]) {
|
||||
if (!app || !app[0]) {
|
||||
app = "My SDL application";
|
||||
}
|
||||
if (reason == NULL || !reason[0]) {
|
||||
if (!reason || !reason[0]) {
|
||||
reason = default_inhibit_reason;
|
||||
}
|
||||
|
||||
|
||||
+19
-19
@@ -167,9 +167,9 @@ static void SDL_EVDEV_UpdateKeyboardMute(void)
|
||||
|
||||
int SDL_EVDEV_Init(void)
|
||||
{
|
||||
if (_this == NULL) {
|
||||
if (!_this) {
|
||||
_this = (SDL_EVDEV_PrivateData *)SDL_calloc(1, sizeof(*_this));
|
||||
if (_this == NULL) {
|
||||
if (!_this) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ int SDL_EVDEV_Init(void)
|
||||
|
||||
void SDL_EVDEV_Quit(void)
|
||||
{
|
||||
if (_this == NULL) {
|
||||
if (!_this) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -244,14 +244,14 @@ void SDL_EVDEV_Quit(void)
|
||||
#endif /* SDL_USE_LIBUDEV */
|
||||
|
||||
/* Remove existing devices */
|
||||
while (_this->first != NULL) {
|
||||
while (_this->first) {
|
||||
SDL_EVDEV_device_removed(_this->first->path);
|
||||
}
|
||||
|
||||
SDL_EVDEV_kbd_quit(_this->kbd);
|
||||
|
||||
SDL_assert(_this->first == NULL);
|
||||
SDL_assert(_this->last == NULL);
|
||||
SDL_assert(!_this->first);
|
||||
SDL_assert(!_this->last);
|
||||
SDL_assert(_this->num_devices == 0);
|
||||
|
||||
SDL_free(_this);
|
||||
@@ -263,7 +263,7 @@ void SDL_EVDEV_Quit(void)
|
||||
static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_class,
|
||||
const char *dev_path)
|
||||
{
|
||||
if (dev_path == NULL) {
|
||||
if (!dev_path) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ int SDL_EVDEV_GetDeviceCount(int device_class)
|
||||
SDL_evdevlist_item *item;
|
||||
int count = 0;
|
||||
|
||||
for (item = _this->first; item != NULL; item = item->next) {
|
||||
for (item = _this->first; item; item = item->next) {
|
||||
if ((item->udev_class & device_class) == device_class) {
|
||||
++count;
|
||||
}
|
||||
@@ -331,7 +331,7 @@ void SDL_EVDEV_Poll(void)
|
||||
|
||||
mouse = SDL_GetMouse();
|
||||
|
||||
for (item = _this->first; item != NULL; item = item->next) {
|
||||
for (item = _this->first; item; item = item->next) {
|
||||
while ((len = read(item->fd, events, sizeof(events))) > 0) {
|
||||
len /= sizeof(events[0]);
|
||||
for (i = 0; i < len; ++i) {
|
||||
@@ -643,7 +643,7 @@ static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
|
||||
}
|
||||
|
||||
item->touchscreen_data = SDL_calloc(1, sizeof(*item->touchscreen_data));
|
||||
if (item->touchscreen_data == NULL) {
|
||||
if (!item->touchscreen_data) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -654,7 +654,7 @@ static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
|
||||
}
|
||||
|
||||
item->touchscreen_data->name = SDL_strdup(name);
|
||||
if (item->touchscreen_data->name == NULL) {
|
||||
if (!item->touchscreen_data->name) {
|
||||
SDL_free(item->touchscreen_data);
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
@@ -709,7 +709,7 @@ static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class)
|
||||
item->touchscreen_data->slots = SDL_calloc(
|
||||
item->touchscreen_data->max_slots,
|
||||
sizeof(*item->touchscreen_data->slots));
|
||||
if (item->touchscreen_data->slots == NULL) {
|
||||
if (!item->touchscreen_data->slots) {
|
||||
SDL_free(item->touchscreen_data->name);
|
||||
SDL_free(item->touchscreen_data);
|
||||
return SDL_OutOfMemory();
|
||||
@@ -770,7 +770,7 @@ static void SDL_EVDEV_sync_device(SDL_evdevlist_item *item)
|
||||
sizeof(*mt_req_values) * item->touchscreen_data->max_slots;
|
||||
|
||||
mt_req_code = SDL_calloc(1, mt_req_size);
|
||||
if (mt_req_code == NULL) {
|
||||
if (!mt_req_code) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -875,14 +875,14 @@ static int SDL_EVDEV_device_added(const char *dev_path, int udev_class)
|
||||
unsigned long relbit[NBITS(REL_MAX)] = { 0 };
|
||||
|
||||
/* Check to make sure it's not already in list. */
|
||||
for (item = _this->first; item != NULL; item = item->next) {
|
||||
for (item = _this->first; item; item = item->next) {
|
||||
if (SDL_strcmp(dev_path, item->path) == 0) {
|
||||
return -1; /* already have this one */
|
||||
}
|
||||
}
|
||||
|
||||
item = (SDL_evdevlist_item *)SDL_calloc(1, sizeof(SDL_evdevlist_item));
|
||||
if (item == NULL) {
|
||||
if (!item) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -893,7 +893,7 @@ static int SDL_EVDEV_device_added(const char *dev_path, int udev_class)
|
||||
}
|
||||
|
||||
item->path = SDL_strdup(dev_path);
|
||||
if (item->path == NULL) {
|
||||
if (!item->path) {
|
||||
close(item->fd);
|
||||
SDL_free(item);
|
||||
return SDL_OutOfMemory();
|
||||
@@ -928,7 +928,7 @@ static int SDL_EVDEV_device_added(const char *dev_path, int udev_class)
|
||||
}
|
||||
}
|
||||
|
||||
if (_this->last == NULL) {
|
||||
if (!_this->last) {
|
||||
_this->first = _this->last = item;
|
||||
} else {
|
||||
_this->last->next = item;
|
||||
@@ -947,10 +947,10 @@ static int SDL_EVDEV_device_removed(const char *dev_path)
|
||||
SDL_evdevlist_item *item;
|
||||
SDL_evdevlist_item *prev = NULL;
|
||||
|
||||
for (item = _this->first; item != NULL; item = item->next) {
|
||||
for (item = _this->first; item; item = item->next) {
|
||||
/* found it, remove it. */
|
||||
if (SDL_strcmp(dev_path, item->path) == 0) {
|
||||
if (prev != NULL) {
|
||||
if (prev) {
|
||||
prev->next = item->next;
|
||||
} else {
|
||||
SDL_assert(_this->first == item);
|
||||
|
||||
@@ -173,7 +173,7 @@ static int fatal_signals[] = {
|
||||
static void kbd_cleanup(void)
|
||||
{
|
||||
SDL_EVDEV_keyboard_state *kbd = kbd_cleanup_state;
|
||||
if (kbd == NULL) {
|
||||
if (!kbd) {
|
||||
return;
|
||||
}
|
||||
kbd_cleanup_state = NULL;
|
||||
@@ -258,7 +258,7 @@ static void kbd_register_emerg_cleanup(SDL_EVDEV_keyboard_state *kbd)
|
||||
{
|
||||
int tabidx;
|
||||
|
||||
if (kbd_cleanup_state != NULL) {
|
||||
if (kbd_cleanup_state) {
|
||||
return;
|
||||
}
|
||||
kbd_cleanup_state = kbd;
|
||||
@@ -428,7 +428,7 @@ SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void)
|
||||
char shift_state[sizeof(long)] = { TIOCL_GETSHIFTSTATE, 0 };
|
||||
|
||||
kbd = (SDL_EVDEV_keyboard_state *)SDL_calloc(1, sizeof(*kbd));
|
||||
if (kbd == NULL) {
|
||||
if (!kbd) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -464,7 +464,7 @@ SDL_EVDEV_keyboard_state *SDL_EVDEV_kbd_init(void)
|
||||
|
||||
void SDL_EVDEV_kbd_set_muted(SDL_EVDEV_keyboard_state *state, SDL_bool muted)
|
||||
{
|
||||
if (state == NULL) {
|
||||
if (!state) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -892,7 +892,7 @@ void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode
|
||||
unsigned short *key_map;
|
||||
unsigned short keysym;
|
||||
|
||||
if (state == NULL) {
|
||||
if (!state) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -900,7 +900,7 @@ void SDL_EVDEV_kbd_keycode(SDL_EVDEV_keyboard_state *state, unsigned int keycode
|
||||
|
||||
shift_final = (state->shift_state | state->slockstate) ^ state->lockstate;
|
||||
key_map = state->key_maps[shift_final];
|
||||
if (key_map == NULL) {
|
||||
if (!key_map) {
|
||||
/* Unsupported shift state (e.g. ctrl = 4, alt = 8), just reset to the default state */
|
||||
state->shift_state = 0;
|
||||
state->slockstate = 0;
|
||||
|
||||
@@ -419,7 +419,7 @@ void SDL_Fcitx_UpdateTextRect(const SDL_Rect *rect)
|
||||
}
|
||||
|
||||
focused_win = SDL_GetKeyboardFocus();
|
||||
if (focused_win == NULL) {
|
||||
if (!focused_win) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+15
-15
@@ -112,7 +112,7 @@ static SDL_bool IBus_EnterVariant(DBusConnection *conn, DBusMessageIter *iter, S
|
||||
}
|
||||
|
||||
dbus->message_iter_get_basic(inside, &struct_id);
|
||||
if (struct_id == NULL || SDL_strncmp(struct_id, struct_id, id_size) != 0) {
|
||||
if (!struct_id || SDL_strncmp(struct_id, struct_id, id_size) != 0) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
return SDL_TRUE;
|
||||
@@ -291,7 +291,7 @@ static char *IBus_ReadAddressFromFile(const char *file_path)
|
||||
FILE *addr_file;
|
||||
|
||||
addr_file = fopen(file_path, "r");
|
||||
if (addr_file == NULL) {
|
||||
if (!addr_file) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ static char *IBus_GetDBusAddressFilename(void)
|
||||
}
|
||||
|
||||
dbus = SDL_DBus_GetContext();
|
||||
if (dbus == NULL) {
|
||||
if (!dbus) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ static char *IBus_GetDBusAddressFilename(void)
|
||||
and look up the address from a filepath using all those bits, eek. */
|
||||
disp_env = SDL_getenv("DISPLAY");
|
||||
|
||||
if (disp_env == NULL || !*disp_env) {
|
||||
if (!disp_env || !*disp_env) {
|
||||
display = SDL_strdup(":0.0");
|
||||
} else {
|
||||
display = SDL_strdup(disp_env);
|
||||
@@ -360,7 +360,7 @@ static char *IBus_GetDBusAddressFilename(void)
|
||||
disp_num = SDL_strrchr(display, ':');
|
||||
screen_num = SDL_strrchr(display, '.');
|
||||
|
||||
if (disp_num == NULL) {
|
||||
if (!disp_num) {
|
||||
SDL_free(display);
|
||||
return NULL;
|
||||
}
|
||||
@@ -374,7 +374,7 @@ static char *IBus_GetDBusAddressFilename(void)
|
||||
|
||||
if (!*host) {
|
||||
const char *session = SDL_getenv("XDG_SESSION_TYPE");
|
||||
if (session != NULL && SDL_strcmp(session, "wayland") == 0) {
|
||||
if (session && SDL_strcmp(session, "wayland") == 0) {
|
||||
host = "unix-wayland";
|
||||
} else {
|
||||
host = "unix";
|
||||
@@ -388,7 +388,7 @@ static char *IBus_GetDBusAddressFilename(void)
|
||||
SDL_strlcpy(config_dir, conf_env, sizeof(config_dir));
|
||||
} else {
|
||||
const char *home_env = SDL_getenv("HOME");
|
||||
if (home_env == NULL || !*home_env) {
|
||||
if (!home_env || !*home_env) {
|
||||
SDL_free(display);
|
||||
return NULL;
|
||||
}
|
||||
@@ -397,7 +397,7 @@ static char *IBus_GetDBusAddressFilename(void)
|
||||
|
||||
key = SDL_DBus_GetLocalMachineId();
|
||||
|
||||
if (key == NULL) {
|
||||
if (!key) {
|
||||
SDL_free(display);
|
||||
return NULL;
|
||||
}
|
||||
@@ -458,7 +458,7 @@ static SDL_bool IBus_SetupConnection(SDL_DBusContext *dbus, const char *addr)
|
||||
ibus_input_interface = IBUS_INPUT_INTERFACE;
|
||||
ibus_conn = dbus->connection_open_private(addr, NULL);
|
||||
|
||||
if (ibus_conn == NULL) {
|
||||
if (!ibus_conn) {
|
||||
return SDL_FALSE; /* oh well. */
|
||||
}
|
||||
|
||||
@@ -498,7 +498,7 @@ static SDL_bool IBus_SetupConnection(SDL_DBusContext *dbus, const char *addr)
|
||||
|
||||
static SDL_bool IBus_CheckConnection(SDL_DBusContext *dbus)
|
||||
{
|
||||
if (dbus == NULL) {
|
||||
if (!dbus) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -518,7 +518,7 @@ static SDL_bool IBus_CheckConnection(SDL_DBusContext *dbus)
|
||||
struct inotify_event *event = (struct inotify_event *)p;
|
||||
if (event->len > 0) {
|
||||
char *addr_file_no_path = SDL_strrchr(ibus_addr_file, '/');
|
||||
if (addr_file_no_path == NULL) {
|
||||
if (!addr_file_no_path) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
@@ -555,12 +555,12 @@ SDL_bool SDL_IBus_Init(void)
|
||||
char *addr;
|
||||
char *addr_file_dir;
|
||||
|
||||
if (addr_file == NULL) {
|
||||
if (!addr_file) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
addr = IBus_ReadAddressFromFile(addr_file);
|
||||
if (addr == NULL) {
|
||||
if (!addr) {
|
||||
SDL_free(addr_file);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
@@ -646,7 +646,7 @@ static void IBus_SimpleMessage(const char *method)
|
||||
{
|
||||
SDL_DBusContext *dbus = SDL_DBus_GetContext();
|
||||
|
||||
if ((input_ctx_path != NULL) && (IBus_CheckConnection(dbus))) {
|
||||
if ((input_ctx_path) && (IBus_CheckConnection(dbus))) {
|
||||
SDL_DBus_CallVoidMethodOnConnection(ibus_conn, ibus_service, input_ctx_path, ibus_input_interface, method, DBUS_TYPE_INVALID);
|
||||
}
|
||||
}
|
||||
@@ -696,7 +696,7 @@ void SDL_IBus_UpdateTextRect(const SDL_Rect *rect)
|
||||
}
|
||||
|
||||
focused_win = SDL_GetKeyboardFocus();
|
||||
if (focused_win == NULL) {
|
||||
if (!focused_win) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,9 +56,9 @@ static void InitIME(void)
|
||||
|
||||
/* See if fcitx IME support is being requested */
|
||||
#ifdef HAVE_FCITX
|
||||
if (SDL_IME_Init_Real == NULL &&
|
||||
if (!SDL_IME_Init_Real &&
|
||||
((im_module && SDL_strcmp(im_module, "fcitx") == 0) ||
|
||||
(im_module == NULL && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
|
||||
(!im_module && xmodifiers && SDL_strstr(xmodifiers, "@im=fcitx") != NULL))) {
|
||||
SDL_IME_Init_Real = SDL_Fcitx_Init;
|
||||
SDL_IME_Quit_Real = SDL_Fcitx_Quit;
|
||||
SDL_IME_SetFocus_Real = SDL_Fcitx_SetFocus;
|
||||
@@ -71,7 +71,7 @@ static void InitIME(void)
|
||||
|
||||
/* default to IBus */
|
||||
#ifdef HAVE_IBUS_IBUS_H
|
||||
if (SDL_IME_Init_Real == NULL) {
|
||||
if (!SDL_IME_Init_Real) {
|
||||
SDL_IME_Init_Real = SDL_IBus_Init;
|
||||
SDL_IME_Quit_Real = SDL_IBus_Quit;
|
||||
SDL_IME_SetFocus_Real = SDL_IBus_SetFocus;
|
||||
|
||||
@@ -115,12 +115,12 @@ SDL_bool SDL_SystemTheme_Init(void)
|
||||
|
||||
system_theme_data.theme = SDL_SYSTEM_THEME_UNKNOWN;
|
||||
system_theme_data.dbus = dbus;
|
||||
if (dbus == NULL) {
|
||||
if (!dbus) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
msg = dbus->message_new_method_call(PORTAL_DESTINATION, PORTAL_PATH, PORTAL_INTERFACE, PORTAL_METHOD);
|
||||
if (msg != NULL) {
|
||||
if (msg) {
|
||||
if (dbus->message_append_args(msg, DBUS_TYPE_STRING, &namespace, DBUS_TYPE_STRING, &key, DBUS_TYPE_INVALID)) {
|
||||
DBusMessage *reply = dbus->connection_send_with_reply_and_block(dbus->session_conn, msg, 300, NULL);
|
||||
if (reply) {
|
||||
|
||||
@@ -111,19 +111,19 @@ static void rtkit_initialize(void)
|
||||
dbus_conn = get_rtkit_dbus_connection();
|
||||
|
||||
/* Try getting minimum nice level: this is often greater than PRIO_MIN (-20). */
|
||||
if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MinNiceLevel",
|
||||
if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MinNiceLevel",
|
||||
DBUS_TYPE_INT32, &rtkit_min_nice_level)) {
|
||||
rtkit_min_nice_level = -20;
|
||||
}
|
||||
|
||||
/* Try getting maximum realtime priority: this can be less than the POSIX default (99). */
|
||||
if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MaxRealtimePriority",
|
||||
if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MaxRealtimePriority",
|
||||
DBUS_TYPE_INT32, &rtkit_max_realtime_priority)) {
|
||||
rtkit_max_realtime_priority = 99;
|
||||
}
|
||||
|
||||
/* Try getting maximum rttime allowed by rtkit: exceeding this value will result in SIGKILL */
|
||||
if (dbus_conn == NULL || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "RTTimeUSecMax",
|
||||
if (!dbus_conn || !SDL_DBus_QueryPropertyOnConnection(dbus_conn, rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "RTTimeUSecMax",
|
||||
DBUS_TYPE_INT64, &rtkit_max_rttime_usec)) {
|
||||
rtkit_max_rttime_usec = 200000;
|
||||
}
|
||||
@@ -202,7 +202,7 @@ static SDL_bool rtkit_setpriority_nice(pid_t thread, int nice_level)
|
||||
nice = rtkit_min_nice_level;
|
||||
}
|
||||
|
||||
if (dbus_conn == NULL || !SDL_DBus_CallMethodOnConnection(dbus_conn,
|
||||
if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn,
|
||||
rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadHighPriorityWithPID",
|
||||
DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_INT32, &nice, DBUS_TYPE_INVALID,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
@@ -233,7 +233,7 @@ static SDL_bool rtkit_setpriority_realtime(pid_t thread, int rt_priority)
|
||||
// go through to determine whether it really needs to fail or not.
|
||||
rtkit_initialize_realtime_thread();
|
||||
|
||||
if (dbus_conn == NULL || !SDL_DBus_CallMethodOnConnection(dbus_conn,
|
||||
if (!dbus_conn || !SDL_DBus_CallMethodOnConnection(dbus_conn,
|
||||
rtkit_dbus_node, rtkit_dbus_path, rtkit_dbus_interface, "MakeThreadRealtimeWithPID",
|
||||
DBUS_TYPE_UINT64, &pid, DBUS_TYPE_UINT64, &tid, DBUS_TYPE_UINT32, &priority, DBUS_TYPE_INVALID,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
|
||||
+45
-45
@@ -47,7 +47,7 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev);
|
||||
static SDL_bool SDL_UDEV_load_sym(const char *fn, void **addr)
|
||||
{
|
||||
*addr = SDL_LoadFunction(_this->udev_handle, fn);
|
||||
if (*addr == NULL) {
|
||||
if (!*addr) {
|
||||
/* Don't call SDL_SetError(): SDL_LoadFunction already did. */
|
||||
return SDL_FALSE;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ static int SDL_UDEV_load_syms(void)
|
||||
|
||||
static SDL_bool SDL_UDEV_hotplug_update_available(void)
|
||||
{
|
||||
if (_this->udev_mon != NULL) {
|
||||
if (_this->udev_mon) {
|
||||
const int fd = _this->syms.udev_monitor_get_fd(_this->udev_mon);
|
||||
if (SDL_IOReady(fd, SDL_IOR_READ, 0)) {
|
||||
return SDL_TRUE;
|
||||
@@ -109,9 +109,9 @@ int SDL_UDEV_Init(void)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (_this == NULL) {
|
||||
if (!_this) {
|
||||
_this = (SDL_UDEV_PrivateData *)SDL_calloc(1, sizeof(*_this));
|
||||
if (_this == NULL) {
|
||||
if (!_this) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -126,13 +126,13 @@ int SDL_UDEV_Init(void)
|
||||
*/
|
||||
|
||||
_this->udev = _this->syms.udev_new();
|
||||
if (_this->udev == NULL) {
|
||||
if (!_this->udev) {
|
||||
SDL_UDEV_Quit();
|
||||
return SDL_SetError("udev_new() failed");
|
||||
}
|
||||
|
||||
_this->udev_mon = _this->syms.udev_monitor_new_from_netlink(_this->udev, "udev");
|
||||
if (_this->udev_mon == NULL) {
|
||||
if (!_this->udev_mon) {
|
||||
SDL_UDEV_Quit();
|
||||
return SDL_SetError("udev_monitor_new_from_netlink() failed");
|
||||
}
|
||||
@@ -152,7 +152,7 @@ int SDL_UDEV_Init(void)
|
||||
|
||||
void SDL_UDEV_Quit(void)
|
||||
{
|
||||
if (_this == NULL) {
|
||||
if (!_this) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -160,17 +160,17 @@ void SDL_UDEV_Quit(void)
|
||||
|
||||
if (_this->ref_count < 1) {
|
||||
|
||||
if (_this->udev_mon != NULL) {
|
||||
if (_this->udev_mon) {
|
||||
_this->syms.udev_monitor_unref(_this->udev_mon);
|
||||
_this->udev_mon = NULL;
|
||||
}
|
||||
if (_this->udev != NULL) {
|
||||
if (_this->udev) {
|
||||
_this->syms.udev_unref(_this->udev);
|
||||
_this->udev = NULL;
|
||||
}
|
||||
|
||||
/* Remove existing devices */
|
||||
while (_this->first != NULL) {
|
||||
while (_this->first) {
|
||||
SDL_UDEV_CallbackList *item = _this->first;
|
||||
_this->first = _this->first->next;
|
||||
SDL_free(item);
|
||||
@@ -188,12 +188,12 @@ int SDL_UDEV_Scan(void)
|
||||
struct udev_list_entry *devs = NULL;
|
||||
struct udev_list_entry *item = NULL;
|
||||
|
||||
if (_this == NULL) {
|
||||
if (!_this) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
enumerate = _this->syms.udev_enumerate_new(_this->udev);
|
||||
if (enumerate == NULL) {
|
||||
if (!enumerate) {
|
||||
SDL_UDEV_Quit();
|
||||
return SDL_SetError("udev_enumerate_new() failed");
|
||||
}
|
||||
@@ -206,7 +206,7 @@ int SDL_UDEV_Scan(void)
|
||||
for (item = devs; item; item = _this->syms.udev_list_entry_get_next(item)) {
|
||||
const char *path = _this->syms.udev_list_entry_get_name(item);
|
||||
struct udev_device *dev = _this->syms.udev_device_new_from_syspath(_this->udev, path);
|
||||
if (dev != NULL) {
|
||||
if (dev) {
|
||||
device_event(SDL_UDEV_DEVICEADDED, dev);
|
||||
_this->syms.udev_device_unref(dev);
|
||||
}
|
||||
@@ -223,12 +223,12 @@ SDL_bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16
|
||||
struct udev_list_entry *item = NULL;
|
||||
SDL_bool found = SDL_FALSE;
|
||||
|
||||
if (_this == NULL) {
|
||||
if (!_this) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
enumerate = _this->syms.udev_enumerate_new(_this->udev);
|
||||
if (enumerate == NULL) {
|
||||
if (!enumerate) {
|
||||
SDL_SetError("udev_enumerate_new() failed");
|
||||
return SDL_FALSE;
|
||||
}
|
||||
@@ -238,7 +238,7 @@ SDL_bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16
|
||||
for (item = devs; item && !found; item = _this->syms.udev_list_entry_get_next(item)) {
|
||||
const char *path = _this->syms.udev_list_entry_get_name(item);
|
||||
struct udev_device *dev = _this->syms.udev_device_new_from_syspath(_this->udev, path);
|
||||
if (dev != NULL) {
|
||||
if (dev) {
|
||||
const char *val = NULL;
|
||||
const char *existing_path;
|
||||
|
||||
@@ -247,17 +247,17 @@ SDL_bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16
|
||||
found = SDL_TRUE;
|
||||
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_VENDOR_ID");
|
||||
if (val != NULL) {
|
||||
if (val) {
|
||||
*vendor = (Uint16)SDL_strtol(val, NULL, 16);
|
||||
}
|
||||
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_MODEL_ID");
|
||||
if (val != NULL) {
|
||||
if (val) {
|
||||
*product = (Uint16)SDL_strtol(val, NULL, 16);
|
||||
}
|
||||
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_REVISION");
|
||||
if (val != NULL) {
|
||||
if (val) {
|
||||
*version = (Uint16)SDL_strtol(val, NULL, 16);
|
||||
}
|
||||
}
|
||||
@@ -271,11 +271,11 @@ SDL_bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16
|
||||
|
||||
void SDL_UDEV_UnloadLibrary(void)
|
||||
{
|
||||
if (_this == NULL) {
|
||||
if (!_this) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_this->udev_handle != NULL) {
|
||||
if (_this->udev_handle) {
|
||||
SDL_UnloadObject(_this->udev_handle);
|
||||
_this->udev_handle = NULL;
|
||||
}
|
||||
@@ -285,7 +285,7 @@ int SDL_UDEV_LoadLibrary(void)
|
||||
{
|
||||
int retval = 0, i;
|
||||
|
||||
if (_this == NULL) {
|
||||
if (!_this) {
|
||||
return SDL_SetError("UDEV not initialized");
|
||||
}
|
||||
|
||||
@@ -296,9 +296,9 @@ int SDL_UDEV_LoadLibrary(void)
|
||||
|
||||
#ifdef SDL_UDEV_DYNAMIC
|
||||
/* Check for the build environment's libudev first */
|
||||
if (_this->udev_handle == NULL) {
|
||||
if (!_this->udev_handle) {
|
||||
_this->udev_handle = SDL_LoadObject(SDL_UDEV_DYNAMIC);
|
||||
if (_this->udev_handle != NULL) {
|
||||
if (_this->udev_handle) {
|
||||
retval = SDL_UDEV_load_syms();
|
||||
if (retval < 0) {
|
||||
SDL_UDEV_UnloadLibrary();
|
||||
@@ -307,10 +307,10 @@ int SDL_UDEV_LoadLibrary(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_this->udev_handle == NULL) {
|
||||
if (!_this->udev_handle) {
|
||||
for (i = 0; i < SDL_arraysize(SDL_UDEV_LIBS); i++) {
|
||||
_this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]);
|
||||
if (_this->udev_handle != NULL) {
|
||||
if (_this->udev_handle) {
|
||||
retval = SDL_UDEV_load_syms();
|
||||
if (retval < 0) {
|
||||
SDL_UDEV_UnloadLibrary();
|
||||
@@ -320,7 +320,7 @@ int SDL_UDEV_LoadLibrary(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (_this->udev_handle == NULL) {
|
||||
if (!_this->udev_handle) {
|
||||
retval = -1;
|
||||
/* Don't call SDL_SetError(): SDL_LoadObject already did. */
|
||||
}
|
||||
@@ -339,7 +339,7 @@ static void get_caps(struct udev_device *dev, struct udev_device *pdev, const ch
|
||||
|
||||
SDL_memset(bitmask, 0, bitmask_len * sizeof(*bitmask));
|
||||
value = _this->syms.udev_device_get_sysattr_value(pdev, attr);
|
||||
if (value == NULL) {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ static int guess_device_class(struct udev_device *dev)
|
||||
while (pdev && !_this->syms.udev_device_get_sysattr_value(pdev, "capabilities/ev")) {
|
||||
pdev = _this->syms.udev_device_get_parent_with_subsystem_devtype(pdev, "input", NULL);
|
||||
}
|
||||
if (pdev == NULL) {
|
||||
if (!pdev) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
|
||||
SDL_UDEV_CallbackList *item;
|
||||
|
||||
path = _this->syms.udev_device_get_devnode(dev);
|
||||
if (path == NULL) {
|
||||
if (!path) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -411,23 +411,23 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
|
||||
/* udev rules reference: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c */
|
||||
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_JOYSTICK");
|
||||
if (val != NULL && SDL_strcmp(val, "1") == 0) {
|
||||
if (val && SDL_strcmp(val, "1") == 0) {
|
||||
devclass |= SDL_UDEV_DEVICE_JOYSTICK;
|
||||
}
|
||||
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_ACCELEROMETER");
|
||||
if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE) &&
|
||||
val != NULL && SDL_strcmp(val, "1") == 0) {
|
||||
val && SDL_strcmp(val, "1") == 0) {
|
||||
devclass |= SDL_UDEV_DEVICE_JOYSTICK;
|
||||
}
|
||||
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_MOUSE");
|
||||
if (val != NULL && SDL_strcmp(val, "1") == 0) {
|
||||
if (val && SDL_strcmp(val, "1") == 0) {
|
||||
devclass |= SDL_UDEV_DEVICE_MOUSE;
|
||||
}
|
||||
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_TOUCHSCREEN");
|
||||
if (val != NULL && SDL_strcmp(val, "1") == 0) {
|
||||
if (val && SDL_strcmp(val, "1") == 0) {
|
||||
devclass |= SDL_UDEV_DEVICE_TOUCHSCREEN;
|
||||
}
|
||||
|
||||
@@ -438,19 +438,19 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
|
||||
Ref: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-input_id.c#n183
|
||||
*/
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_KEY");
|
||||
if (val != NULL && SDL_strcmp(val, "1") == 0) {
|
||||
if (val && SDL_strcmp(val, "1") == 0) {
|
||||
devclass |= SDL_UDEV_DEVICE_HAS_KEYS;
|
||||
}
|
||||
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD");
|
||||
if (val != NULL && SDL_strcmp(val, "1") == 0) {
|
||||
if (val && SDL_strcmp(val, "1") == 0) {
|
||||
devclass |= SDL_UDEV_DEVICE_KEYBOARD;
|
||||
}
|
||||
|
||||
if (devclass == 0) {
|
||||
/* Fall back to old style input classes */
|
||||
val = _this->syms.udev_device_get_property_value(dev, "ID_CLASS");
|
||||
if (val != NULL) {
|
||||
if (val) {
|
||||
if (SDL_strcmp(val, "joystick") == 0) {
|
||||
devclass = SDL_UDEV_DEVICE_JOYSTICK;
|
||||
} else if (SDL_strcmp(val, "mouse") == 0) {
|
||||
@@ -470,7 +470,7 @@ static void device_event(SDL_UDEV_deviceevent type, struct udev_device *dev)
|
||||
}
|
||||
|
||||
/* Process callbacks */
|
||||
for (item = _this->first; item != NULL; item = item->next) {
|
||||
for (item = _this->first; item; item = item->next) {
|
||||
item->callback(type, devclass, path);
|
||||
}
|
||||
}
|
||||
@@ -480,13 +480,13 @@ void SDL_UDEV_Poll(void)
|
||||
struct udev_device *dev = NULL;
|
||||
const char *action = NULL;
|
||||
|
||||
if (_this == NULL) {
|
||||
if (!_this) {
|
||||
return;
|
||||
}
|
||||
|
||||
while (SDL_UDEV_hotplug_update_available()) {
|
||||
dev = _this->syms.udev_monitor_receive_device(_this->udev_mon);
|
||||
if (dev == NULL) {
|
||||
if (!dev) {
|
||||
break;
|
||||
}
|
||||
action = _this->syms.udev_device_get_action(dev);
|
||||
@@ -507,13 +507,13 @@ int SDL_UDEV_AddCallback(SDL_UDEV_Callback cb)
|
||||
{
|
||||
SDL_UDEV_CallbackList *item;
|
||||
item = (SDL_UDEV_CallbackList *)SDL_calloc(1, sizeof(SDL_UDEV_CallbackList));
|
||||
if (item == NULL) {
|
||||
if (!item) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
item->callback = cb;
|
||||
|
||||
if (_this->last == NULL) {
|
||||
if (!_this->last) {
|
||||
_this->first = _this->last = item;
|
||||
} else {
|
||||
_this->last->next = item;
|
||||
@@ -528,14 +528,14 @@ void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb)
|
||||
SDL_UDEV_CallbackList *item;
|
||||
SDL_UDEV_CallbackList *prev = NULL;
|
||||
|
||||
if (_this == NULL) {
|
||||
if (!_this) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (item = _this->first; item != NULL; item = item->next) {
|
||||
for (item = _this->first; item; item = item->next) {
|
||||
/* found it, remove it. */
|
||||
if (item->callback == cb) {
|
||||
if (prev != NULL) {
|
||||
if (prev) {
|
||||
prev->next = item->next;
|
||||
} else {
|
||||
SDL_assert(_this->first == item);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user