Commit Graph

13835 Commits (43571769f16b45ddcb9d7dd1d4c6e21cd39e691e)

Author SHA1 Message Date
Sam Lantinga a844d90942 Add missing error reporting in Android_JNI_FileOpen()
Fixes https://github.com/libsdl-org/SDL/issues/8427
2023-10-23 08:27:57 -07:00
Ryan C. Gordon 4ac38d13dd
alsa: Don't touch free'd memory in hotplug thread. 2023-10-23 00:59:40 -04:00
Ryan C. Gordon 43d41c9dcb
audio: Another attempt to make device add/remove work vs event watchers.
This patch reverts the previous reversion, and then adds code to queue up
events to be sent the next time SDL pumps the event queue. This guarantees
that the event watcher/filter _never_ runs from an SDL audio device thread
or some other backend-specific internal thread.
2023-10-23 00:38:41 -04:00
Ryan C. Gordon 9abc692156
audio: Another attempt to deal with device destruction from device thread.
This only happens when closing a device from an event watcher, when the
device reports failure from its own thread.
2023-10-22 17:01:49 -04:00
Ryan C. Gordon 33c9eeec7c
Revert "audio: Device threads don't increment physical device refcounts."
This reverts commit 76f81797b7.

This worked in the normal cases, but:

A device thread that calls SDL_DisconnectAudioDevice due to failure will fire
the disconnect event from the device thread...and if there's an event watcher
that uses that moment to close the device, we still end up in the same
situation, where the device thread tries to join on itself.

Better solutions are still pending.
2023-10-22 16:15:27 -04:00
Sam Lantinga e5a15f94e2 Revert "Check to make sure the Windows joystick device has buttons and axes"
This reverts commit 642504bc59.

We have SDL_HINT_JOYSTICK_ROG_CHAKRAM to ignore or allow the ROG Chakram X mouse to be used as a joystick.

Fixes https://github.com/libsdl-org/SDL/issues/8227
2023-10-22 09:21:07 -07:00
Sam Lantinga 70fd8e2ba2 Lock joysticks when adding gamepad mappings
Fixes https://github.com/libsdl-org/SDL/issues/8412
2023-10-19 22:36:44 -07:00
Ryan C. Gordon 76f81797b7
audio: Device threads don't increment physical device refcounts.
Otherwise, they risk the device thread joining on itself.

Now we make sure the reference is held at the logical device level until
the physical device is closed, so it can't destroy the device in normal
usage until the thread is joined, etc.
2023-10-19 15:47:29 -04:00
SDL Wiki Bot 594fda4120 Sync SDL3 wiki -> header 2023-10-19 17:13:15 +00:00
Sam Lantinga 0d7c5a2c56 Updated Android API documentation 2023-10-19 10:12:34 -07:00
Sam Lantinga 0df888c584 Moved Android low latency audio behind a hint "SDL_ANDROID_LOW_LATENCY_AUDIO" 2023-10-19 08:54:11 -07:00
SDL Wiki Bot 142366c837 Sync SDL3 wiki -> header 2023-10-19 14:03:06 +00:00
Sam Lantinga 3a4c9d6990 Fixed build error when API logging is enabled 2023-10-18 22:30:16 -07:00
Sam Lantinga 1f8f82b379 Removed redundant thread-safety information 2023-10-18 22:19:50 -07:00
SDL Wiki Bot a6edc75fe7 Sync SDL3 wiki -> header 2023-10-19 05:18:12 +00:00
Sam Lantinga 3c8edeb79b Clarified SDL property thread-safety information 2023-10-18 22:17:02 -07:00
SDL Wiki Bot 4fa821cb3e Sync SDL3 wiki -> header 2023-10-19 05:14:13 +00:00
Sam Lantinga 1c70760c0b Added thread-safety information for the new SDL properties API 2023-10-18 22:13:33 -07:00
Sam Lantinga 15533dce05 Cleaned up warnings from check_stdlib_usage.py 2023-10-18 21:38:14 -07:00
Ryan C. Gordon bf269571fc
jack: Removed FIXME comment that has since been fixed. 2023-10-18 15:47:01 -04:00
Ryan C. Gordon 797b70877d
audio: Remove stub header SDL_audio_c.h.
It was a leftover, that just included SDL_sysaudio.h, in modern times.
2023-10-18 15:46:07 -04:00
Ryan C. Gordon 9d7c57234a
audio: Cleaned out most remaining `/* */` comments for `//` style.
Fully committing to it...!

This left SDL_wave.* alone for now, since there's a ton of comments in there
and this code hasn't changed much from SDL2 so far. But as SDL2 ages out a
little more, I'll likely switch this over, too.
2023-10-18 15:39:01 -04:00
Ryan C. Gordon 0ff67dc21b
video: Fix compiler warning about SDL_ReadSurfacePixel not being declared.
(this was legal before, but the Android NDK wants to make sure we didn't mean
for this function to be marked `static` since it didn't have a formal
declaration before its definition and might only be used in the one source
file.)
2023-10-18 15:02:01 -04:00
Ryan C. Gordon 81c77396af
opensles: Patched to compile. 2023-10-18 14:56:32 -04:00
Ryan C. Gordon 442e84916a
opensles: Fixed capitalization to match other SDL backends. 2023-10-18 13:57:32 -04:00
Ryan C. Gordon 34914bfb49
alsa: Clean up device handles, now that hotplug thread cleanup is in place. 2023-10-18 13:53:42 -04:00
Sam Lantinga 48d80efb51 Fixed warning C4701: potentially uninitialized local variable 'props' used 2023-10-18 09:04:05 -07:00
Ozkan Sezer f7dc63bcc3 audio: another windows wasapi build fix. 2023-10-18 18:32:00 +03:00
Ozkan Sezer dd98330076 audio: fix windows wasapi build. 2023-10-18 18:20:00 +03:00
Ryan C. Gordon 7a52f7b3fd
audio: Split Deinitialize into two stages.
First stage happens before we destroy objects, and is generally used to
shut down hotplug. The second stage is the usual deinit, which cleans up
the lowlevel API, unloads shared libraries, etc.
2023-10-18 10:43:45 -04:00
Ryan C. Gordon e55e556f32
alsa: Fixed minor memory leak.
The default device handles aren't free'd anywhere, so don't strdup them;
everything else is managed by the hotplug thread, which does its own freeing.
2023-10-17 23:28:50 -04:00
Sam Lantinga b45a0d9016 Updated the documentation for SDL_LoadWAV_RW() 2023-10-17 20:27:49 -07:00
Cameron Gutman 435e7ce663 Check for device disconnection in HIDAPI_JoystickOpen()
HIDAPI joystick drivers may call HIDAPI_JoystickDisconnected() in their
UpdateDevice() function during HIDAPI_JoystickOpen(). If they do this
today, the opened joystick will end up partially initialized (no name,
path, mapping GUID, etc.) because HIDAPI_GetDeviceByIndex() will no
longer be able to find the SDL_HIDAPI_Device for the removed joystick.

Worse still, joystick->hwdata->device becomes a dangling freed pointer
the next time HIDAPI_UpdateDeviceList() is called. This leads to a UAF
when the application or SDL calls SDL_JoystickClose() on this joystick.

Fix all this by checking if the device no longer has any associated
joysticks after calling UpdateDevice() and failing the open call if so.
2023-10-17 21:54:09 -05:00
Ryan C. Gordon b733adb503
audio: Fix device refcounting vs ProvidesOwnCallbackThread backends. 2023-10-16 20:17:04 -04:00
Ryan C. Gordon c6f08c2553
testaudio: Removed debugging code. 2023-10-16 15:25:34 -04:00
Ryan C. Gordon d5dac0ad27
testaudio: Deal with a texture being unexpectedly NULL when scaling.
This happens to work because our current textures are all 128x128, but in
theory one shouldn't hit this case anyhow...right?!

Reference Issue #8344.
2023-10-16 14:03:58 -04:00
Ryan C. Gordon b19e68c8ec
testaudio: Properly display playback progress, regardless of data source. 2023-10-16 13:56:43 -04:00
Ryan C. Gordon 8c39269279
audio: Fix audio stream format when binding to a capture device.
Fixes #8402.
2023-10-16 13:34:40 -04:00
Ryan C. Gordon f26b838a3e
jack: Check for sample rate and buffer size changes from the server.
Reference Issue #8344.
2023-10-16 13:10:54 -04:00
Ryan C. Gordon 063cb0df6b
audio: Fixed comment typo. "deref" should be "unref" 2023-10-16 13:09:55 -04:00
Ryan C. Gordon 354611a0c6
testaudio: Fixed some bugs Valgrind pointed out. 2023-10-16 10:04:02 -04:00
Ryan C. Gordon a17f3ba916
audio: Reworked audio device disconnect management.
- No more tapdance to either join the audio device thread or have it detach
itself. Significant simplication of and fixes to the locking code to prevent
deadlocks.
- Physical devices now keep a refcount. Each logical device increments it,
as does the existence of a device thread, etc. Last unref destroys the
device and takes it out of the device_hash. Since there's a lot of moving
parts that might be holding a reference to a physical device, this seemed
like a safer way to protect the object.
- Disconnected devices now continue to function as zombie devices. Playback
devices will still consume data (and just throw it away), and capture devices
will continue to produce data (which always be silence). This helps apps
that don't handle disconnect events; the device still stops playing/capturing,
but bound audio streams will still consume data so they don't allocate more
data infinitely, and apps that depend on an audio callback firing regularly
to make progress won't hang.

Please note that disconnected audio devices must now be explicitly closed!
They always _should_ have been, but before this commit, SDL3 would destroy the
disconnected device for you (and manually closing afterwards was a safe no-op).

Reference Issue #8331.
Fixes #8386.

(and probably others).
2023-10-16 10:04:02 -04:00
Zhile Zhu 6ddd96a4d0 Fix some wrong gamepad/controller event enums 2023-10-16 08:35:54 -04:00
Ryan C. Gordon 8df68b4120
hashtable: Moved over to single-line comments. 2023-10-15 15:41:04 -04:00
Ryan C. Gordon 1c6d996108
testaudio: if the SDL_Renderer is already gone, don't destroy SDL_Textures. 2023-10-14 23:17:59 -04:00
Ryan C. Gordon b22ffb9797
audio: Fix some logic errors in the new device hashtable code.
Fixes #8395.
2023-10-14 23:11:10 -04:00
Anonymous Maarten e526dc64bd Don't set unused variable 2023-10-15 01:36:49 +02:00
Ryan C. Gordon 6664437748
hashtable: Don't rearrange bucket elements during SDL_FindInHashTable.
This is a race condition if the hashtable isn't protected by a mutex, and it
makes a read/write operation out of something what appears to be read-only,
which is dangerously surprising from an interface viewpoint.

The downside is that if you have an item that is frequently accessed that
isn't in the first slot of a bucket, each find operation will take longer
instead of common items bubbling to the front of the bucket. Then again,
if you have several common things being looked up in rotation, they'll just
be doing unnecessary shuffling here. In this case, it might be better to
just use a larger hashtable or a better hashing function (or just look up the
thing you need once instead of multiple times).

Fixes #8391.
2023-10-14 13:56:56 -04:00
Ryan C. Gordon 8ac5c84ad1
audio: device thread shouldn't touch `thread_alive` after object is free'd.
Reference Issue #8386.
2023-10-14 13:49:08 -04:00
Ryan C. Gordon b17151eb16
testaudio: Don't crash if renderer is NULL (happens during shutdown). 2023-10-14 13:43:22 -04:00