Commit Graph

8128 Commits

Author SHA1 Message Date
Ryan C. Gordon
64fee85c69 alsa: More efficient audio thread iteration.
Now we sleep the thread in WaitDevice until ALSA reawakens it because it
needs more data, and we feed it exactly as much as it can take at that
point.

Like the recent PulseAudio changes, this is both more efficient, reliable,
and consistent.
2023-09-30 11:52:50 -04:00
Ryan C. Gordon
61e9a9dd56 pulseaudio: Just feed the device whenever it asks for any amount of data.
In practice, this seems to buffer a little upfront and then gives a pretty
consistent request flow after that of 1/4 of the requested buffer size without
variation, which is significantly better than the previous code that would
vary a little each frame.

Plus, as long as the device asks for _anything_, we won't block forever, and
if it asks for more than our expected buffer size, we'll run multiple times
to satisfy it, so this is likely more robust against dropouts in general, too.
2023-09-29 22:34:11 -04:00
Ryan C. Gordon
4f76f9b0a7 pulseaudio: Use correct buffer size of stream, wait less between fills.
The wait approach is still wonky, but this fixes the hangs on bluetooth
devices for now.
2023-09-29 22:14:54 -04:00
Simon McVittie
d95d2d7051 SDLTest_CompareSurfaces: Decode pixels correctly on big-endian platforms
Previously, if acting on a surface with less than 32 bits per pixel,
this code was placing the pixel value from the surface in the first
few bytes of the Uint32 to be decoded, and unrelated data from a
subsequent pixel in the remaining bytes.

Because SDL_GetRGBA takes the bits to be decoded from the
least-significant bits of the given value, ignoring the higher-order
bits if any, this happened to be correct on little-endian platforms,
where the first few bytes store the least-significant bits of an
integer.

However, it was incorrect on big-endian, where the first few bytes are
the most-significant bits of an integer.

The previous implementation also assumed that unaligned access to a
32-bit quantity is possible, which is not the case on all CPUs (but
happens to be true on x86).

These issues were not discovered until now because
SDLTest_CompareSurfaces() is only used in testautomation, which until
recently was not being run routinely at build-time, because it contained
other assumptions that can fail in an autobuilder or CI environment.

Resolves: https://github.com/libsdl-org/SDL/issues/8315
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-09-29 06:55:17 -07:00
Sam Lantinga
d65861f049 Do a better job of finding default ALSA devices 2023-09-28 21:25:11 -07:00
Sam Lantinga
ba65ef5ce7 Recover from -EPIPE in snd_pcm_avail() 2023-09-28 20:16:59 -07:00
Ryan C. Gordon
a2c5dc6507 pulseaudio: Added typedef needed for compat with ancient Pulse installs. 2023-09-28 12:10:16 -04:00
Ryan C. Gordon
f24551f6d1 pulseaudio: More workarounds for extremely old Pulse installs. 2023-09-28 11:53:00 -04:00
Ryan C. Gordon
441a5b707b audio: Adjusted const/static fields on some variables. 2023-09-28 10:24:42 -04:00
Ryan C. Gordon
280c2c1d7d pulseaudio: Revert "pulseaudio: Require PulseAudio 5.0 or later for SDL3."
This reverts commit 6fd0613ac8.

Turns out that the Steam Runtime is still on PulseAudio 1.1, and the only
thing we (currently) need a newer Pulse for is pa_threaded_mainloop_set_name,
so let's just go back to treating that symbol as optional.

We might need to force a higher version at some point, but it's not worth it
over this.
2023-09-28 10:19:24 -04:00
Ryan C. Gordon
4db2b968af audio: simple-copy path should check if device is paused.
Otherwise, we get into situations where all bound streams need to change
their output formats when a device pauses...and it makes the fast case
slow: when pausing a single input, it needs to silence and then convert a
silent buffer, instead of just zeroing out the device buffer and being done.
2023-09-27 16:24:33 -04:00
Ryan C. Gordon
505dc4c39c wasapi: Deal with device failures when we aren't holding the device lock.
Since these get proxied to a different thread, if we wait for that thread
to finish while holding the lock, and the management thread _also_ requests
the lock, we're screwed.

WaitDevice never holds the lock by design, so just mark devices as failed
and clean up or recover them in there.
2023-09-27 14:33:09 -04:00
Sam Lantinga
ea5f59c234 Removed unused code
It looks like we don't need to watch for hanging writes now that we're using the callback mechanism.
2023-09-27 10:18:34 -07:00
Sam Lantinga
a6854098f7 Fixed stuttering on Android when using the AAudio driver
The audio processing thread isn't scheduled in lock-step with the audio callback so sometimes the callback would consume the same data twice and sometimes the audio processing thread would write to the same buffer twice.

Also handle variable sizes in the audio callback so the Android audio system doesn't have to do additional buffering to match our buffer size requirements.
2023-09-27 10:18:34 -07:00
Ryan C. Gordon
a5175e5ed0 audio: Fixed bug when setting up mixing formats.
Reference Issue #8226.
2023-09-27 11:50:23 -04:00
Frank Praznik
9667aa18e6 wayland: Check that the data device supports the release method before calling it 2023-09-26 11:22:33 -04:00
Frank Praznik
4454dc400b wayland: Null all Wayland manager objects after freeing 2023-09-26 11:22:33 -04:00
Ryan C. Gordon
e1789b320e video: Streamline a little deinit code.
Fixes #8290.
2023-09-25 16:26:14 -04:00
Frank Praznik
2a1058713c Bump libdecor feature check to look for 0.2.0
The version of libdecor tagged with support for the suspended event and min/max getters is 0.2.0, so update the checks to reflect this.
2023-09-25 12:07:54 -04:00
Anonymous Maarten
a84389f6bb libm: use union for infinity 2023-09-25 18:02:40 +02:00
Sam Lantinga
1375d2049d SDL_iconv_string() defaults to UTF-8
Fixes https://github.com/libsdl-org/SDL/issues/8287
2023-09-24 17:27:23 -07:00
Sam Lantinga
70a1bc6973 Check for NULL before dereferencing newly allocated memory
Fixes https://github.com/libsdl-org/SDL/issues/8289
2023-09-24 17:17:49 -07:00
Frank Praznik
752f14e5a6 wayland: Convert some memcpy calls to copyp 2023-09-24 11:44:35 -04:00
Frank Praznik
9284a03053 wayland: Remove some unnecessary helper functions 2023-09-24 11:44:35 -04:00
Sam Lantinga
34719cba96 Fixed crash in hid_init() if the HIDDeviceManager isn't available 2023-09-22 10:14:16 -07:00
Sam Lantinga
2e92e94ebb Make sure we update device->sample_frames in SDL_AudioDeviceFormatChangedAlreadyLocked()
WASAPI_GetDeviceBuf() will fail if we don't request the correct buffer size
2023-09-21 11:32:37 -07:00
Frank Praznik
9964e5c5b0 wayland: Don't retrieve the drag offer strings with every pointer motion event
Querying the drag offer with every pointer movement would require refactoring to work with the portal implementation, however, there is little point, as the event layer just discards the file name. Remove the existing code and note that a new implementation is needed if the name ever starts to be passed though.

In the event that this is reimplemented, it should cache the filenames, as otherwise, this could potentially hammer the DBus interface hundreds or even thousands of times per second.
2023-09-21 14:05:16 -04:00
Sam Lantinga
bac7eeaaae Added missing include 2023-09-20 14:13:50 -07:00
Ryan C. Gordon
a541e2ac10 audio: Change a few SDL_memcpy calls to SDL_copyp. 2023-09-20 17:02:44 -04:00
Ryan C. Gordon
54125c1408 audio: Only update bound audiostreams' formats when necessary.
Saves locks and copies during audio thread iteration. We've added asserts
that can evaporate out in release mode to make sure everything stays in sync.
2023-09-20 17:02:44 -04:00
Frank Praznik
2f3deec245 wayland: Don't process drag & drop events from surfaces not owned by SDL
Libdecor creates subsurfaces of the primary SDL surface, but events from these surfaces should be ignored, or applications will get drag & drop events when dragged over drop shadows and such.
2023-09-20 15:00:40 -04:00
Frank Praznik
42bdced05d events: Log file drop position events and print the pointer coordinates 2023-09-20 15:00:40 -04:00
Frank Praznik
c10d93d3a0 wayland: Replace magic constant with define 2023-09-20 15:00:40 -04:00
Ryan C. Gordon
5008521538 emscripten: Restore compatibility with existing emsdk releases. 2023-09-20 14:32:41 -04:00
Jaswant Panchumarti
953b55dd6d Use EM_ASM_PTR when the return value is a pointer
- closes https://github.com/libsdl-org/SDL/issues/8241
2023-09-20 14:25:35 -04:00
Ryan C. Gordon
a4541a255e audio: SDL_GetAudioStreamQueued now returns bytes, not frames.
Reference #8266.
2023-09-20 14:15:47 -04:00
Colin Kinloch
99421b64d0 linux: Add portal drag and drop 2023-09-20 11:41:48 -04:00
Michael Bradshaw
952c5059b5 Remove stray Â
Presumably this is an accidental character due to the copyright symbol and conversion to/from different encodings. The *.c file does not have this character.
2023-09-20 08:32:53 -07:00
Simon McVittie
eebd5d18a2 linux: Handle upower's UP_DEVICE_STATE_PENDING_CHARGE, PENDING_DISCHARGE
On my laptop, the battery is configured to stop charging at around 80%
most of the time, to increase the overall useful lifetime of the battery.
When in that state, upower reports UP_DEVICE_STATE_PENDING_CHARGE
(numeric value 5), which SDL previously mapped to SDL_POWERSTATE_UNKNOWN.
This made the platform_testGetPowerInfo automated test fail, because
it assumes that SDL_POWERSTATE_UNKNOWN means no battery is connected,
and does not expect to see a percentage.

Map UP_DEVICE_STATE_PENDING_CHARGE (5) to SDL_POWERSTATE_CHARGED, which
seems close enough.

Also map UP_DEVICE_STATE_PENDING_DISCHARGE (6) to
SDL_POWERSTATE_ON_BATTERY, which matches how at least GNOME presents it.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-09-20 08:32:03 -07:00
Ryan C. Gordon
f8fdb20d8f audio: Destroy all existing SDL_AudioStreams on shutdown. 2023-09-20 10:47:11 -04:00
Ryan C. Gordon
62d4459972 audio: Removed declarations of functions that don't exist anymore. 2023-09-20 10:21:03 -04:00
Ryan C. Gordon
34b931f7eb audio: Added SDL_GetAudioStreamQueued 2023-09-20 10:15:03 -04:00
Ryan C. Gordon
23206b9e3f audio: Added SDL_EVENT_AUDIO_DEVICE_FORMAT_CHANGED
This fires if an opened device changes formats (which it can on Windows,
if the user changes this in the system control panel, and WASAPI can
report), or if a default device migrates to new hardware and the format
doesn't match.

This will fire for all logical devices on a physical device (and if it's
a format change and not a default device change, it'll fire for the
physical device too, but that's honestly not that useful and might change).

Fixes #8267.
2023-09-20 10:12:10 -04:00
Ryan C. Gordon
c7e6d7a1f7 audio: Changed debug logging output.
("preconverted bytes" makes it sounds like we already converted them before
the call instead of "bytes that haven't yet hit the stage where we convert
them. Just dump the wording completely.)
2023-09-20 10:04:23 -04:00
Ryan C. Gordon
87ec6acf2d audio: Added a FIXME 2023-09-20 10:04:19 -04:00
Ryan C. Gordon
ac88ffb7ea audio: don't allocate buffer in SDL_SetAudioPostmixCallback for NULL callback. 2023-09-20 10:03:02 -04:00
Ryan C. Gordon
2a950f6ae6 audio: Replace some SDL_memcpy calls with SDL_copyp. 2023-09-20 10:01:52 -04:00
Ryan C. Gordon
0dc0434a3e audio: Fixed race condition in subsystem shutdown.
This makes sure new devices can't be created when we're in the process of
shutting down.
2023-09-20 10:00:44 -04:00
Ryan C. Gordon
23f60203a3 audio: precalculate if we can use simple copies instead of the full mixer.
This just saves a bunch of conditionals (and an atomic get!) per iteration
of the audio thread.
2023-09-20 09:58:27 -04:00
Ryan C. Gordon
36b0f11414 audio: Optimize setting device formats during audio thread iteration.
The API entry point does a ton of unnecessary validation just to eventually
do a memcpy().
2023-09-20 09:09:15 -04:00