Commit Graph

8168 Commits

Author SHA1 Message Date
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
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
Sam Lantinga
2bd478ae65 Added SDL_GetTextureDXGIResource() to get the DXGI resource associated with a render texture.
Also switched the D3D11 and D3D12 renderers to use real NV12 textures for NV12 data.

The combination of these two changes allows us to implement 0-copy video decode and playback for D3D11 in testffmpeg without any access to the renderer internals.
2023-10-10 03:32:46 -07:00
Simon McVittie
04edb38cdf shape: Use SDL[Test]_ReadSurfacePixel
This avoids assuming that the pixels are suitably aligned for direct
access, which there's no guarantee that they are; in particular,
3-bytes-per-pixel RGB images are likely to have 3 out of 4 pixels
misaligned. On x86, dereferencing a misaligned pointer does what you
would expect, but on other architectures it's undefined whether it will
work, crash with SIGBUS, or silently give a wrong answer.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-10-10 03:23:20 -07:00
Simon McVittie
f5745c3a67 surface: Add a private SDL_ReadSurfacePixel
This shares its implementation with SDLTest_ReadSurfacePixel: the same
code is compiled twice, to get it into the static test library and also
the public shared library.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-10-10 03:23:20 -07:00
Simon McVittie
0d68f45879 test: Extract SDLTest_ReadSurfacePixel
This is essentially the same as was added in d95d2d70, but with clearer
error handling. It's implemented in a private header file so that it
can be shared with SDL_shape, which also wants this functionality.

Resolves: https://github.com/libsdl-org/SDL/issues/8319
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-10-10 03:23:20 -07: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
8e03ea4383 hashtable: Use Create/Destroy naming, in the SDL3 style. 2023-10-09 19:20:43 -04:00
Ryan C. Gordon
568902b64e hashtable: Added src/SDL_hashtable.[ch].
Reference Issue #7799.
2023-10-09 19:19:01 -04:00
Frank Praznik
836927edf8 wayland: Try to skip the Wayland driver if not connecting to or in a Wayland session
When initializing the Wayland driver, check if the application is being started in, or trying to connect to, a Wayland session and skip to another driver if not. If neither WAYLAND_DISPLAY nor XDG_SESSION_TYPE are set, try to start anyway, and if the Wayland library is missing or no Wayland sessions are started, initialization will fail later in the process as it previously did.

This fixes the case where a Wayland session is running on a different VT, but an application wishes to run via KMSDRM on the current VT.
2023-10-09 12:47:11 -04:00
Etaash Mathamsetty
2a9480c815 wayland: Add null check for zenity version string 2023-10-06 14:51:55 -07:00
Mathieu Eyraud
f30392da5b Fix assertion in LINUX_JoystickSetSensorsEnabled()
Calling LINUX_JoystickSetSensorsEnabled() after the joystick is unplugged will trigger this assertion.
2023-10-05 13:06:48 -07:00
Simon McVittie
4e59bf6cb9 SDLTest_CompareSurfaces: Output RGBA values of first differing pixel
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-10-05 15:10:32 +02:00
Simon McVittie
b2ddfbbec3 SDLTest_CompareSurfaces: If surfaces differ, log their formats
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-10-05 15:10:32 +02:00
Simon McVittie
b028fd9604 SDLTest_CompareSurfaces: Log better messages if NULL or different sizes
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-10-05 15:10:32 +02:00
Anonymous Maarten
4f0642bf47 triangle: don't read destination pixel when you're going to discard it anyways 2023-10-05 13:40:09 +02:00
Anonymous Maarten
4cd0c13823 blit_slow: don't read destination pixel when you're going to discard it anyways 2023-10-04 19:41:50 -07:00
Ryan C. Gordon
49abb9c1fa aaudio: Fixed a comment. 2023-10-04 14:06:28 -04:00
Mathieu Eyraud
0eb8651d5e Do not report gyro/accelerometer if we can't read axes info 2023-10-04 08:43:39 -07: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
Ryan C. Gordon
482c238953 aaudio: Deal with device recovery.
Android claims to work with multiple devices, but doesn't actually appear to
(at least, afaict), and it will report tons of devices that all just seem
to play to the current default output, so for now, turn this off and only
expose a default device.

And then, with that default output, attempt to recover on errors by throwing
away the current AAudioStream and building a new one.

This let me plug/unplug a set of headphones from the headphone jack and audio
would switch correctly to the new output.
2023-09-30 16:41:31 -04:00
Ryan C. Gordon
a8813b58a6 aaudio: Change an int to an SDL_bool. 2023-09-30 16:41:31 -04:00
Sam Lantinga
8923305f34 We don't need to wait a full 10 ms, just delay a bit 2023-09-30 12:14:09 -07:00
Sam Lantinga
6a152676bb Wait a bit when snd_pcm_avail() returns 0
The hardware might report that it's ready and still need a bit of time to start processing samples
2023-09-30 10:48:44 -07:00
Ryan C. Gordon
b4372de186 alsa: Cleaned up remaining debug logging. 2023-09-30 12:35:46 -04:00
Ryan C. Gordon
a063c943dc pulseaudio: Use pa_stream_begin_write to avoid an extra buffer copy. 2023-09-30 12:31:45 -04:00
Ryan C. Gordon
0471a93706 alsa: Simplified PlayDevice and CaptureFromDevice. 2023-09-30 12:23:28 -04:00
Ryan C. Gordon
776d9d0ee3 alsa: Convert /* */ comments to // comments. 2023-09-30 12:02:51 -04:00
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