Commit Graph

8213 Commits

Author SHA1 Message Date
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
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
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
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
Ryan C. Gordon
8df68b4120 hashtable: Moved over to single-line comments. 2023-10-15 15:41:04 -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
7f408e57ee audio: Keep all available devices in a hashtable instead of linked lists.
All devices are in a single hash, whether playback or capture, or physical
or logical. Lookups are keyed on device ID and map to either
`SDL_AudioDevice *` for physical devices or `SDL_LogicalAudioDevice *` for
logical devices (as an implementation detail, you can determine which object
type you have by checking a specific bit in the device ID).

This simplifies a bunch of code, makes some cases significantly more
efficient, and solves the problem of having to lock each physical
device while the device list rwlock is held to find logical devices by ID.

Device IDs hash perfectly evenly, too, being incrementing integers.
2023-10-14 13:34:42 -04:00
Ryan C. Gordon
0aba2c97db hashtable: SDL_IterateHashTable might as well provide both key and value.
And SDL_IterateHashTableKey is only necessary for stackable hashtables, since
non-stackable ones can either iterate each unique key/value pair with
SDL_IterateHashTable, or get a specific key/value pair by using
SDL_FindInHashTable.
2023-10-14 13:23:03 -04:00
Ryan C. Gordon
95a9271dbf audio: Never lock a device while holding the device_list_lock.
Fixes various not-necessarily-corner cases ending in deadlock.
2023-10-13 14:18:21 -04:00
Frank Praznik
72034b9a07 wayland: Fix primary selection handling when the protocol isn't supported
The primary selection protocol is optional, so the function pointers to the internal Wayland functions should only be set if the protocol is supported. This allows graceful fall-back to the generic SDL implementation in other cases.

Fixes the clipboard tests under Weston.
2023-10-12 12:32:27 -04:00
kanjitalk755
e152129787 Fixes #8190.
From #7249, reverted the hunks other than #7239.
2023-10-12 07:17:32 -07:00
Sam Lantinga
b79db0a6ea Fixed potential wraparound issue with property IDs 2023-10-12 06:22:34 -07:00
Anonymous Maarten
c9ccf0670c Add unsupported functions to dynapi 2023-10-12 14:00:47 +02:00
Anonymous Maarten
25ce87979d Always provide an implementation for all SDL3 symbols 2023-10-12 14:00:47 +02:00
Anonymous Maarten
0efa196989 dynapi: implement SDL_DYNAPI_entry even when building SDL without dynapi support 2023-10-12 14:00:47 +02:00
Sam Lantinga
4368f70ff9 Added properties to various SDL objects
The following objects now have properties that can be user modified:
* SDL_AudioStream
* SDL_Gamepad
* SDL_Joystick
* SDL_RWops
* SDL_Renderer
* SDL_Sensor
* SDL_Surface
* SDL_Texture
* SDL_Window
2023-10-11 22:38:00 -07:00
Sam Lantinga
973c8b3273 Added SDL properties API
Fixes https://github.com/libsdl-org/SDL/issues/7799
2023-10-11 22:38:00 -07:00
Ryan C. Gordon
2bca4671a6 audio: Allow audio streams to be created when the subsystem isn't initialized.
You are on your own to destroy them, though!
2023-10-11 22:43:53 -04:00
Sam Lantinga
0d5cad91b1 We need audio converters initialized in SDL_InitAudio()
These are used separately from audio streams, e.g. SDL_OutputAudioThreadIterate(), so they should always be initialized when audio is initialized.
2023-10-11 15:11:34 -07:00
Ryan C. Gordon
1c3a0ade74 audio: Whoops, this stream format change is only for capture devices. 2023-10-11 15:11:20 -04:00
Ryan C. Gordon
10fab3a39e pulseaudio: Stop the threaded mainloop before destroying the context.
Otherwise, we might trigger an assertion in libpulse.

Reference Issue #8348.
2023-10-11 14:32:47 -04:00
Sam Lantinga
0b71898cb1 Make it clear that the string comparison isn't a boolean check 2023-10-11 10:18:12 -07:00
Sam Lantinga
6c8ad975c7 Like mutexes, operations on NULL rwlocks are no-ops
Fixes a crash when performing operations on a NULL rwlock before rwlock implementation is chosen
2023-10-11 09:49:44 -07:00
Sam Lantinga
c552cc6847 We don't require the audio system to be initialized for audio format conversion
This is helpful for tools pipelines where audio devices are never used.
2023-10-11 09:23:23 -07:00
Frank Praznik
9a5f7b17c6 Use SDL wrapped getenv function 2023-10-11 11:23:24 -04:00
Ryan C. Gordon
044046bc50 audio: Fixed assertions when capture devices have wrong audio formats.
Fixes #8376.
2023-10-11 10:37:28 -04:00
Ryan C. Gordon
82f54af617 x11: Properly check for XInput2 support before using it.
This specifically fixes a crash in X11_WarpMouseInternal if XInput2 was
missing at runtime, but also cleans up a few other existing checks.

Fixes #8378.
2023-10-11 01:01:07 -04:00
Sam Lantinga
b654427537 Added support for the PowerA Nintendo Switch Nano Wired Controller 2023-10-10 17:04:00 -07:00
Sam Lantinga
dc2a5f6ab2 Fixed error C2054: expected '(' to follow 'inline' 2023-10-10 16:38:12 -07:00
Sam Lantinga
a7ae1de9a6 Fixed warning C4028: formal parameter different from declaration 2023-10-10 16:37:17 -07:00
Sam Lantinga
3a47fb7208 The sensor and joystick instance ID generator isn't guarded by a lock. 2023-10-10 15:46:46 -07:00
Sam Lantinga
99fa0d6cae Disable low latency audio by default when using AAudio on Android
Some devices have flat sounding audio when low latency mode is enabled. In particular this was reported on the Samsung SM-T290 running Android 11.
2023-10-10 15:17:58 -07:00
Sam Lantinga
2d62c65a75 Fixed build warning 2023-10-10 12:37:38 -07:00