Commit Graph

1055 Commits

Author SHA1 Message Date
Sam Lantinga
4280d4b359 Fixed warning C4210: nonstandard extension used: function given file scope
Resurrected SDL_audio_c.h, we knew it would be back...
2023-10-23 17:04:14 -07:00
Ryan C. Gordon
182cfc3265 pulseaudio: Rework how we manage default devices and hotplug.
This fixes problems where Pulse callbacks don't fire in the order we expect,
or fail to fire at all, and avoids extra round trips to the Pulse server to
lookup information we could have trivially obtained already.

The end result is we would occasionally miss default device changes, etc, and
this resolves that better.
2023-10-23 19:17:50 -04:00
Ryan C. Gordon
b2ae1e835f pulseaudio: Change debug printf calls to use SDL_Log instead. 2023-10-23 19:17:49 -04: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
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
Sam Lantinga
0df888c584 Moved Android low latency audio behind a hint "SDL_ANDROID_LOW_LATENCY_AUDIO" 2023-10-19 08:54:11 -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
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
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
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
b22ffb9797 audio: Fix some logic errors in the new device hashtable code.
Fixes #8395.
2023-10-14 23:11:10 -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
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
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
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
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
Ryan C. Gordon
044046bc50 audio: Fixed assertions when capture devices have wrong audio formats.
Fixes #8376.
2023-10-11 10:37:28 -04:00
Sam Lantinga
a7ae1de9a6 Fixed warning C4028: formal parameter different from declaration 2023-10-10 16:37:17 -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
Simon McVittie
bf72704bfd audio: Disable NEON sample conversion until test failures are fixed
We need to do this early in the file, so that it will be taken into
account when deciding whether to define NEED_SCALAR_CONVERTER_FALLBACKS
and therefore provide a non-SIMD fallback.

Mitigates: https://github.com/libsdl-org/SDL/issues/8352
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-10-10 13:12:55 -04:00
Ryan C. Gordon
55a1458ed0 audio: Changes to one logical device must update all sibling logical devices.
Fixes #8226.
2023-10-09 20:28:58 -04:00
Ryan C. Gordon
49abb9c1fa aaudio: Fixed a comment. 2023-10-04 14:06:28 -04:00
Ryan C. Gordon
ff57867516 audio: Fixed copy/paste error that was checking wrong variable.
Fixes #8342.
2023-10-03 14:58:24 -04:00
Ryan C. Gordon
d2d4914ac3 audio: WaitDevice/WaitCaptureDevice now returns a result.
This is an attempt to centralize all the error handling, instead of
implicitly counting on WaitDevice implementations to disconnect the device
to report an error.
2023-10-03 10:35:18 -04:00
Ryan C. Gordon
a0820ed833 directsound: Cleaned up WaitDevice.
This should retry until GetCurrentPosition succeeds. Otherwise, we would be
going on to the next iteration too soon.

Also generally streamlined the code while I was in here.
2023-10-03 10:18:16 -04:00
Ryan C. Gordon
6c33a05bdb audio: Removed unused AllowsArbitraryDeviceNames variable. 2023-10-02 23:07:00 -04:00
Ryan C. Gordon
f1fc198278 audio: Destroy the logical audio device before sending DEVICE_REMOVED event.
This prevents catastrophe if someone tries to close the device in an event
filter in response to the event.

Note that this means SDL_GetAudioStreamDevice() for any stream on this
device will return 0 during the event filter!

Fixes #8331.
2023-10-02 22:12:28 -04:00
Ryan C. Gordon
de5068f4e4 audio: Commented out a currently-incorrect assert.
Fixes #8326.
2023-10-02 19:41:48 -04:00
Sam Lantinga
251f8fa272 Revert "Do a better job of finding default ALSA devices"
This reverts commit d65861f049.

The default device is the one with the name "default"
2023-10-01 08:49:51 -07:00
Sam Lantinga
8857b0f13a Use the device audio format for the lowest latency 2023-09-30 16:24:49 -07:00
Sam Lantinga
806e11ac00 Update sample processing bookkeeping when recovering the AAudio audio device 2023-09-30 15:04:21 -07:00