Skip to content

Commit ca440b9

Browse files
authored
Update SDL2 bindings to release 2.24.0 (#246)
* Update bindings for 2.24.0 * Update CI runners for 2.24.0 * Fix silly _create_window bug * Try fixing renderer tests w/ dummy on Windows * Try workaround for weird ctypes issue * Update news.rst
1 parent 1a51888 commit ca440b9

File tree

17 files changed

+253
-88
lines changed

17 files changed

+253
-88
lines changed

.ci/getsdl2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
}
3535

3636
libversions = {
37-
'2.0.22.post1': { # NOTE: Temporary until SDL2 2.24.0 is released
38-
'SDL2': '2.0.22',
37+
'2.24.0': {
38+
'SDL2': '2.24.0',
3939
'SDL2_mixer': '2.6.0',
4040
'SDL2_ttf': '2.20.0',
4141
'SDL2_image': '2.6.0',

.github/workflows/run_tests.yml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
python-version: ['2.7', '3.6', '3.7', '3.8', '3.9', '3.10']
26-
sdl2: ['2.0.22']
26+
sdl2: ['2.24.0']
2727
name-prefix: ['Linux (Python ']
2828
include:
2929
- python-version: 'pypy-2.7'
30-
sdl2: '2.0.22'
30+
sdl2: '2.24.0'
3131
name-prefix: 'Experimental / Linux ('
3232
- python-version: 'pypy-3.7'
33-
sdl2: '2.0.22'
33+
sdl2: '2.24.0'
3434
name-prefix: 'Experimental / Linux ('
3535

3636
env:
37+
PYSDL2_DLL_VERSION: ${{ matrix.sdl2 }}
3738
SDL_VIDEODRIVER: dummy
3839
SDL_AUDIODRIVER: dummy
3940
SDL_RENDER_DRIVER: software
@@ -51,7 +52,7 @@ jobs:
5152
run: |
5253
python -m pip install --upgrade pip
5354
python -m pip install numpy pytest pillow
54-
python -m pip install pysdl2-dll
55+
python -m pip install pysdl2-dll==$PYSDL2_DLL_VERSION
5556
5657
- name: Install and test PySDL2
5758
run: |
@@ -71,11 +72,11 @@ jobs:
7172
fail-fast: false
7273
matrix:
7374
python-version: [3.9]
74-
sdl2: ['2.0.22.post1', '2.0.20', '2.0.16']
75+
sdl2: ['2.24.0', '2.0.22', '2.0.20']
7576
name-prefix: ['macOS (Python ']
7677
include:
7778
- python-version: '2.7'
78-
sdl2: '2.0.22.post1'
79+
sdl2: '2.24.0'
7980
name-prefix: 'macOS (Python '
8081
- python-version: '3.9'
8182
sdl2: 'from Homebrew'
@@ -127,21 +128,27 @@ jobs:
127128
matrix:
128129
python-version: [3.9]
129130
architecture: ['x64']
130-
sdl2: ['2.0.22.post1', '2.0.20', '2.0.18', '2.0.16', '2.0.14', '2.0.12',
131-
'2.0.10', '2.0.9', '2.0.8', '2.0.7', '2.0.6', '2.0.5']
131+
sdl2: [
132+
'2.24.0', '2.0.22', '2.0.20', '2.0.18', '2.0.16', '2.0.14', '2.0.12',
133+
'2.0.10', '2.0.9', '2.0.8', '2.0.7', '2.0.6', '2.0.5'
134+
]
132135
name-prefix: ['Windows (Python ']
133136
include:
134137
- python-version: '2.7'
135138
architecture: 'x64'
136-
sdl2: '2.0.22.post1'
139+
sdl2: '2.24.0'
137140
name-prefix: 'Windows (Python '
138141
- python-version: '2.7'
139142
architecture: 'x86'
140-
sdl2: '2.0.22.post1'
143+
sdl2: '2.24.0'
141144
name-prefix: 'Windows 32-bit (Python '
142145
- python-version: '3.9'
143146
architecture: 'x86'
144-
sdl2: '2.0.22.post1'
147+
sdl2: '2.24.0'
148+
name-prefix: 'Windows 32-bit (Python '
149+
- python-version: '2.7'
150+
architecture: 'x86'
151+
sdl2: '2.0.22'
145152
name-prefix: 'Windows 32-bit (Python '
146153
- python-version: '2.7'
147154
architecture: 'x86'

doc/news.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ New Features:
1515
individually using keyword arguments (e.g. ``sdl2.ext.init(audio=True)`` to
1616
initialize the audio subsystem as well as the default video subsystem).
1717
Previously, this function only initailized the video subsystem.
18+
* Updated to wrap new functions and constants in SDL2 2.24.0 (PR #246).
19+
20+
Fixed Bugs:
21+
22+
* Fixed broken behaviour (and potential segfaults) with usage of
23+
:func:`sdl2.SDL_GUIDToString` on Python 3.6 and older (PR #246).
1824

1925

2026
0.9.13

sdl2/audio.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ class SDL_AudioStream(c_void_p):
186186
SDLFunc("SDL_GetNumAudioDevices", [c_int], c_int),
187187
SDLFunc("SDL_GetAudioDeviceName", [c_int, c_int], c_char_p),
188188
SDLFunc("SDL_GetAudioDeviceSpec", [c_int, c_int, _P(SDL_AudioSpec)], c_int, added='2.0.16'),
189+
SDLFunc("SDL_GetDefaultAudioInfo",
190+
[_P(c_char_p), _P(SDL_AudioSpec), c_int],
191+
returns = c_int, added = '2.24.0'
192+
),
189193
SDLFunc("SDL_OpenAudioDevice",
190194
[c_char_p, c_int, _P(SDL_AudioSpec), _P(SDL_AudioSpec), c_int],
191195
returns = SDL_AudioDeviceID
@@ -243,6 +247,7 @@ class SDL_AudioStream(c_void_p):
243247
SDL_GetNumAudioDevices = _ctypes["SDL_GetNumAudioDevices"]
244248
SDL_GetAudioDeviceName = _ctypes["SDL_GetAudioDeviceName"]
245249
SDL_GetAudioDeviceSpec = _ctypes["SDL_GetAudioDeviceSpec"]
250+
SDL_GetDefaultAudioInfo = _ctypes["SDL_GetDefaultAudioInfo"]
246251
SDL_OpenAudioDevice = _ctypes["SDL_OpenAudioDevice"]
247252
SDL_GetAudioStatus = _ctypes["SDL_GetAudioStatus"]
248253
SDL_GetAudioDeviceStatus = _ctypes["SDL_GetAudioDeviceStatus"]

sdl2/gamecontroller.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@
7272
SDL_CONTROLLER_TYPE_PS5 = 7
7373
SDL_CONTROLLER_TYPE_AMAZON_LUNA = 8
7474
SDL_CONTROLLER_TYPE_GOOGLE_STADIA = 9
75+
SDL_CONTROLLER_TYPE_NVIDIA_SHIELD = 10
76+
SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT = 11
77+
SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT = 12
78+
SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_PAIR = 13
7579

7680
SDL_GameControllerAxis = c_int
7781
SDL_CONTROLLER_AXIS_INVALID = -1

sdl2/guid.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from ctypes import Structure, c_int, c_char, c_char_p
2-
from ctypes import POINTER as _P
1+
import sys
2+
from ctypes import c_int, c_char_p
33
from .dll import _bind, SDLFunc, AttributeDict
44
from .stdinc import Uint8
5+
from .joystick import SDL_JoystickGUID
56

67
__all__ = [
78
# Defines
@@ -11,21 +12,26 @@
1112

1213
# Constants & typedefs
1314

14-
class SDL_GUID(Structure):
15-
_fields_ = [("data", (Uint8 * 16))]
15+
SDL_GUID = SDL_JoystickGUID
1616

1717

1818
# Raw ctypes function definitions
1919

2020
_funcdefs = [
21-
SDLFunc("SDL_GUIDToString", [SDL_GUID, _P(c_char), c_int], None, added='2.23.1'),
21+
SDLFunc("SDL_GUIDToString", [SDL_GUID, c_char_p, c_int], None, added='2.23.1'),
2222
SDLFunc("SDL_GUIDFromString", [c_char_p], SDL_GUID, added='2.23.1'),
2323
]
2424
_ctypes = AttributeDict()
2525
for f in _funcdefs:
2626
_ctypes[f.name] = _bind(f.name, f.args, f.returns, f.added)
2727
__all__.append(f.name) # Add all bound functions to module namespace
2828

29+
# Workaround for bizarre ctypes bug with older Python versions
30+
# (The joystick function here is a thin wrapper around SDL_GUIDToString)
31+
if sys.version_info < (3, 7, 0):
32+
from .joystick import SDL_JoystickGetGUIDString
33+
_ctypes["SDL_GUIDToString"] = SDL_JoystickGetGUIDString
34+
2935

3036
# Aliases for ctypes bindings
3137

sdl2/hints.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@
4848
"SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE",
4949
"SDL_HINT_JOYSTICK_GAMECUBE_RUMBLE_BRAKE",
5050
"SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS",
51+
"SDL_HINT_JOYSTICK_HIDAPI_COMBINE_JOY_CONS",
5152
"SDL_HINT_JOYSTICK_HIDAPI_LUNA",
53+
"SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC",
54+
"SDL_HINT_JOYSTICK_HIDAPI_SHIELD",
5255
"SDL_HINT_JOYSTICK_HIDAPI_PS4",
5356
"SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE",
5457
"SDL_HINT_JOYSTICK_HIDAPI_PS5",
@@ -58,6 +61,8 @@
5861
"SDL_HINT_JOYSTICK_HIDAPI_STEAM",
5962
"SDL_HINT_JOYSTICK_HIDAPI_SWITCH",
6063
"SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED",
64+
"SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED",
65+
"SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED",
6166
"SDL_HINT_JOYSTICK_HIDAPI_XBOX",
6267
"SDL_HINT_JOYSTICK_RAWINPUT",
6368
"SDL_HINT_JOYSTICK_RAWINPUT_CORRELATE_XINPUT",
@@ -72,6 +77,7 @@
7277
"SDL_HINT_LINUX_JOYSTICK_DEADZONES",
7378
"SDL_HINT_MAC_BACKGROUND_APP",
7479
"SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK",
80+
"SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH",
7581
"SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS",
7682
"SDL_HINT_MOUSE_DOUBLE_CLICK_TIME",
7783
"SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH",
@@ -80,6 +86,7 @@
8086
"SDL_HINT_MOUSE_RELATIVE_MODE_WARP",
8187
"SDL_HINT_MOUSE_RELATIVE_SCALING",
8288
"SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE",
89+
"SDL_HINT_MOUSE_RELATIVE_WARP_MOTION",
8390
"SDL_HINT_MOUSE_TOUCH_EVENTS",
8491
"SDL_HINT_MOUSE_AUTO_CAPTURE",
8592
"SDL_HINT_NO_SIGNAL_HANDLERS",
@@ -257,6 +264,7 @@
257264
SDL_HINT_MOUSE_RELATIVE_MODE_WARP = b"SDL_MOUSE_RELATIVE_MODE_WARP"
258265
SDL_HINT_MOUSE_RELATIVE_SCALING = b"SDL_MOUSE_RELATIVE_SCALING"
259266
SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE = b"SDL_MOUSE_RELATIVE_SPEED_SCALE"
267+
SDL_HINT_MOUSE_RELATIVE_WARP_MOTION = b"SDL_MOUSE_RELATIVE_WARP_MOTION"
260268
SDL_HINT_MOUSE_TOUCH_EVENTS = b"SDL_MOUSE_TOUCH_EVENTS"
261269
SDL_HINT_TOUCH_MOUSE_EVENTS = b"SDL_TOUCH_MOUSE_EVENTS"
262270

@@ -278,7 +286,10 @@
278286
SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE = b"SDL_JOYSTICK_HIDAPI_GAMECUBE"
279287
SDL_HINT_JOYSTICK_GAMECUBE_RUMBLE_BRAKE = b"SDL_JOYSTICK_GAMECUBE_RUMBLE_BRAKE"
280288
SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS = b"SDL_JOYSTICK_HIDAPI_JOY_CONS"
289+
SDL_HINT_JOYSTICK_HIDAPI_COMBINE_JOY_CONS = b"SDL_JOYSTICK_HIDAPI_COMBINE_JOY_CONS"
281290
SDL_HINT_JOYSTICK_HIDAPI_LUNA = b"SDL_JOYSTICK_HIDAPI_LUNA"
291+
SDL_HINT_JOYSTICK_HIDAPI_NINTENDO_CLASSIC = b"SDL_JOYSTICK_HIDAPI_NINTENDO_CLASSIC"
292+
SDL_HINT_JOYSTICK_HIDAPI_SHIELD = b"SDL_JOYSTICK_HIDAPI_SHIELD"
282293
SDL_HINT_JOYSTICK_HIDAPI_PS4 = b"SDL_JOYSTICK_HIDAPI_PS4"
283294
SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE = b"SDL_JOYSTICK_HIDAPI_PS4_RUMBLE"
284295
SDL_HINT_JOYSTICK_HIDAPI_PS5 = b"SDL_JOYSTICK_HIDAPI_PS5"
@@ -288,6 +299,8 @@
288299
SDL_HINT_JOYSTICK_HIDAPI_STEAM = b"SDL_JOYSTICK_HIDAPI_STEAM"
289300
SDL_HINT_JOYSTICK_HIDAPI_SWITCH = b"SDL_JOYSTICK_HIDAPI_SWITCH"
290301
SDL_HINT_JOYSTICK_HIDAPI_SWITCH_HOME_LED = b"SDL_JOYSTICK_HIDAPI_SWITCH_HOME_LED"
302+
SDL_HINT_JOYSTICK_HIDAPI_JOYCON_HOME_LED = b"SDL_JOYSTICK_HIDAPI_JOYCON_HOME_LED"
303+
SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED = b"SDL_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED"
291304
SDL_HINT_JOYSTICK_HIDAPI_XBOX = b"SDL_JOYSTICK_HIDAPI_XBOX"
292305
SDL_HINT_JOYSTICK_RAWINPUT = b"SDL_JOYSTICK_RAWINPUT"
293306
SDL_HINT_JOYSTICK_RAWINPUT_CORRELATE_XINPUT = b"SDL_JOYSTICK_RAWINPUT_CORRELATE_XINPUT"
@@ -307,6 +320,7 @@
307320
SDL_HINT_LINUX_JOYSTICK_DEADZONES = b"SDL_LINUX_JOYSTICK_DEADZONES"
308321
SDL_HINT_MAC_BACKGROUND_APP = b"SDL_MAC_BACKGROUND_APP"
309322
SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK = b"SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK"
323+
SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH = b"SDL_MAC_OPENGL_ASYNC_DISPATCH"
310324
SDL_HINT_RPI_VIDEO_LAYER = b"SDL_RPI_VIDEO_LAYER"
311325
SDL_HINT_RENDER_DIRECT3D11_DEBUG = b"SDL_RENDER_DIRECT3D11_DEBUG"
312326
SDL_HINT_RENDER_DIRECT3D_THREADSAFE = b"SDL_RENDER_DIRECT3D_THREADSAFE"

sdl2/joystick.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from ctypes import POINTER as _P
44
from .dll import _bind, SDLFunc, AttributeDict
55
from .stdinc import Sint16, Sint32, Uint32, Uint16, Uint8, SDL_bool
6-
from .guid import SDL_GUID
76

87
__all__ = [
98
# Structs & Opaque Types
@@ -72,7 +71,9 @@
7271
# Structs & typedefs
7372

7473
SDL_JoystickID = Sint32
75-
SDL_JoystickGUID = SDL_GUID
74+
75+
class SDL_JoystickGUID(Structure):
76+
_fields_ = [("data", (Uint8 * 16))]
7677

7778
class SDL_Joystick(c_void_p):
7879
pass

sdl2/keyboard.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class SDL_Keysym(Structure):
2929
_funcdefs = [
3030
SDLFunc("SDL_GetKeyboardFocus", None, _P(SDL_Window)),
3131
SDLFunc("SDL_GetKeyboardState", [_P(c_int)], _P(Uint8)),
32+
SDLFunc("SDL_ResetKeyboard", None, None, added='2.24.0'),
3233
SDLFunc("SDL_GetModState", None, SDL_Keymod),
3334
SDLFunc("SDL_SetModState", [SDL_Keymod]),
3435
SDLFunc("SDL_GetKeyFromScancode", [SDL_Scancode], SDL_Keycode),
@@ -56,6 +57,7 @@ class SDL_Keysym(Structure):
5657

5758
SDL_GetKeyboardFocus = _ctypes["SDL_GetKeyboardFocus"]
5859
SDL_GetKeyboardState = _ctypes["SDL_GetKeyboardState"]
60+
SDL_ResetKeyboard = _ctypes["SDL_ResetKeyboard"]
5961
SDL_GetModState = _ctypes["SDL_GetModState"]
6062
SDL_SetModState = _ctypes["SDL_SetModState"]
6163
SDL_GetKeyFromScancode = _ctypes["SDL_GetKeyFromScancode"]

sdl2/test/audio_test.py

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def with_sdl_audio():
2020
if original_driver:
2121
os.environ["SDL_AUDIODRIVER"] = original_driver
2222
# Initialize SDL2 with video and audio subsystems
23+
sdl2.SDL_Quit()
2324
sdl2.SDL_ClearError()
2425
ret = sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO | sdl2.SDL_INIT_AUDIO)
2526
assert sdl2.SDL_GetError() == b""
@@ -31,6 +32,23 @@ def with_sdl_audio():
3132
if original_driver:
3233
os.environ["SDL_AUDIODRIVER"] = original_driver
3334

35+
@pytest.fixture
36+
def with_default_driver(with_sdl_audio):
37+
driver = sdl2.SDL_GetCurrentAudioDriver()
38+
if driver == None or sdl2.SDL_GetNumAudioDevices(False) == 0:
39+
sdl2.SDL_QuitSubSystem(SDL_INIT_AUDIO)
40+
os.environ["SDL_AUDIODRIVER"] = b'dummy'
41+
sdl2.SDL_InitSubSystem(SDL_INIT_AUDIO)
42+
driver = sdl2.SDL_GetCurrentAudioDriver()
43+
yield driver
44+
45+
def _get_audio_drivers():
46+
drivers = []
47+
for index in range(sdl2.SDL_GetNumAudioDrivers()):
48+
name = sdl2.SDL_GetAudioDriver(index)
49+
drivers.append(name.decode('utf-8'))
50+
return drivers
51+
3452

3553
# Test macro functions
3654

@@ -227,11 +245,10 @@ def test_SDL_GetAudioDeviceName(with_sdl_audio):
227245
# Reset audio subsystem
228246
SDL_Quit()
229247
SDL_Init(0)
230-
for index in range(sdl2.SDL_GetNumAudioDrivers()):
248+
for drivername in _get_audio_drivers():
231249
# Get input/output device names for each audio driver
232-
drivername = sdl2.SDL_GetAudioDriver(index)
233-
backends.append(drivername.decode("utf-8"))
234-
os.environ["SDL_AUDIODRIVER"] = drivername.decode("utf-8")
250+
backends.append(drivername)
251+
os.environ["SDL_AUDIODRIVER"] = drivername
235252
# Need to reinitialize subsystem for each driver
236253
SDL_InitSubSystem(SDL_INIT_AUDIO)
237254
driver = sdl2.SDL_GetCurrentAudioDriver()
@@ -258,24 +275,13 @@ def test_SDL_GetAudioDeviceName(with_sdl_audio):
258275
print(" - output: {0}".format(str(devices[driver]['output'])))
259276

260277
@pytest.mark.skipif(sdl2.dll.version < 2016, reason="not available")
261-
def test_SDL_GetAudioDeviceSpec(with_sdl_audio):
262-
# Reset audio subsystem
263-
SDL_Quit()
264-
SDL_Init(0)
265-
# Find an audio driver with at least one output
266-
SDL_InitSubSystem(SDL_INIT_AUDIO)
267-
driver = sdl2.SDL_GetCurrentAudioDriver()
268-
if driver == None or sdl2.SDL_GetNumAudioDevices(False) == 0:
269-
SDL_QuitSubSystem(SDL_INIT_AUDIO)
270-
os.environ["SDL_AUDIODRIVER"] = b'dummy'
271-
SDL_InitSubSystem(SDL_INIT_AUDIO)
272-
driver = sdl2.SDL_GetCurrentAudioDriver()
278+
def test_SDL_GetAudioDeviceSpec(with_default_driver):
279+
driver = with_default_driver
273280
drivername = driver.decode('utf-8')
274281
# Get name and spec of first output device
275282
outspec = sdl2.SDL_AudioSpec(0, 0, 0, 0)
276283
outname = sdl2.SDL_GetAudioDeviceName(0, False).decode('utf-8')
277284
ret = sdl2.SDL_GetAudioDeviceSpec(0, False, ctypes.byref(outspec))
278-
SDL_QuitSubSystem(SDL_INIT_AUDIO)
279285
assert ret == 0
280286
# Validate frequency and channel count were set
281287
hz = outspec.freq
@@ -291,6 +297,32 @@ def test_SDL_GetAudioDeviceSpec(with_sdl_audio):
291297
print(msg.format(outname, drivername))
292298
print(msg2.format(hz, chans, fmt, bufsize))
293299

300+
@pytest.mark.skipif(sdl2.dll.version < 2240, reason="not available")
301+
def test_SDL_GetDefaultAudioInfo(with_default_driver):
302+
driver = with_default_driver
303+
drivername = driver.decode('utf-8')
304+
# Get name and spec of first output device
305+
outspec = sdl2.SDL_AudioSpec(0, 0, 0, 0)
306+
outname = ctypes.c_char_p()
307+
ret = sdl2.SDL_GetDefaultAudioInfo(ctypes.byref(outname), ctypes.byref(outspec), 0)
308+
# If method isn't implemented for the current back end, just skip
309+
if ret < 0 and b"not supported" in sdl2.SDL_GetError():
310+
pytest.skip("not supported by driver")
311+
assert ret == 0
312+
# Validate frequency and channel count were set
313+
hz = outspec.freq
314+
fmt = FORMAT_NAME_MAP[outspec.format] if outspec.format > 0 else 'unknown'
315+
chans = outspec.channels
316+
bufsize = outspec.samples if outspec.samples > 0 else 'unknown'
317+
assert hz > 0
318+
assert chans > 0
319+
# Print out device spec info
320+
outname = outname.value.decode('utf-8')
321+
msg = "Default audio spec for {0} with '{1}' driver:"
322+
msg2 = "{0} Hz, {1} channels, {2} format, {3} sample buffer size"
323+
print(msg.format(outname, drivername))
324+
print(msg2.format(hz, chans, fmt, bufsize))
325+
294326
def test_SDL_OpenCloseAudioDevice(with_sdl_audio):
295327
#TODO: Add tests for callback
296328
fmt = sdl2.AUDIO_F32 if sys.platform == "darwin" else sdl2.AUDIO_U16

0 commit comments

Comments
 (0)