def set_items(self): if not SDL_WasInit(SDL_INIT_VIDEO): SDL_InitSubSystem(SDL_INIT_VIDEO) self.get_opts(), self.get_keys() self.set_opts(), self.set_keys() if SDL_WasInit(SDL_INIT_VIDEO): SDL_QuitSubSystem(SDL_INIT_VIDEO)
def test_SDL_GetAudioDeviceName(self): devices = {} # Reset audio subsystem SDL_Quit() SDL_Init(0) for index in range(audio.SDL_GetNumAudioDrivers()): # Get input/output device names for each audio driver drivername = audio.SDL_GetAudioDriver(index) os.environ["SDL_AUDIODRIVER"] = drivername.decode("utf-8") # Need to reinitialize subsystem for each driver SDL_InitSubSystem(SDL_INIT_AUDIO) driver = audio.SDL_GetCurrentAudioDriver() if driver is not None: driver = driver.decode("utf-8") devices[driver] = {'input': [], 'output': []} outnum = audio.SDL_GetNumAudioDevices(False) innum = audio.SDL_GetNumAudioDevices(True) for x in range(outnum): name = audio.SDL_GetAudioDeviceName(x, False) assert name is not None devices[driver]['output'].append(name.decode('utf-8')) for x in range(innum): name = audio.SDL_GetAudioDeviceName(x, True) assert name is not None devices[driver]['input'].append(name.decode('utf-8')) SDL_QuitSubSystem(SDL_INIT_AUDIO) print("Available audio drivers and devices:") for driver in devices.keys(): print(driver) print(" - input: {0}".format(str(devices[driver]['input']))) print(" - output: {0}".format(str(devices[driver]['output'])))
def test_SDL_GetNumAudioDevices(self): os.environ["SDL_AUDIODRIVER"] = "dummy" SDL_InitSubSystem(SDL_INIT_AUDIO) outnum = audio.SDL_GetNumAudioDevices(False) self.assertGreaterEqual(outnum, 1) innum = audio.SDL_GetNumAudioDevices(True) self.assertGreaterEqual(innum, 0) SDL_QuitSubSystem(SDL_INIT_AUDIO)
def init(self): if not SDL_WasInit(SDL_INIT_JOYSTICK): if SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0: for i in range(SDL_NumJoysticks()): self.joystick_names.append(SDL_JoystickNameForIndex(i)) self.joystick_timer.timeout.connect(self.process_events) else: log.info("couldn't initialize SDL joystick support")
def test_SDL_GetNumAudioDevices(self): os.environ["SDL_AUDIODRIVER"] = "dummy" if SDL_InitSubSystem(SDL_INIT_AUDIO) != 0: self.skipTest('Audio subsystem not supported') outnum = audio.SDL_GetNumAudioDevices(False) self.assertGreaterEqual(outnum, 1) innum = audio.SDL_GetNumAudioDevices(True) self.assertGreaterEqual(innum, 0) SDL_QuitSubSystem(SDL_INIT_AUDIO)
def test_SDL_GetCurrentAudioDriver(self): if SDL_InitSubSystem(SDL_INIT_AUDIO) != 0: self.skipTest('Audio subsystem not supported') SDL_QuitSubSystem(SDL_INIT_AUDIO) success = 0 for index in range(audio.SDL_GetNumAudioDrivers()): drivername = audio.SDL_GetAudioDriver(index) os.environ["SDL_AUDIODRIVER"] = drivername.decode("utf-8") # Certain drivers fail without bringing up the correct # return value, such as the esd, if it is not running. SDL_InitSubSystem(SDL_INIT_AUDIO) driver = audio.SDL_GetCurrentAudioDriver() # Do not handle wrong return values. if driver is not None: self.assertEqual(drivername, driver) success += 1 SDL_QuitSubSystem(SDL_INIT_AUDIO) self.assertGreaterEqual(success, 1, "Could not initialize any sound driver")
def init(self): if not SDL_WasInit(SDL_INIT_JOYSTICK): if SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0: for i in range(SDL_NumJoysticks()): joystick_name = SDL_JoystickNameForIndex(i) if isinstance(joystick_name, bytes): joystick_name = joystick_name.decode() self.joystick_names.append(joystick_name.strip()) self.joystick_timer.timeout.connect(self.process_events) else: log.info("couldn't initialize SDL joystick support")
def test_SDL_OpenAudio(self): os.environ["SDL_AUDIODRIVER"] = "dummy" SDL_InitSubSystem(SDL_INIT_AUDIO) reqspec = audio.SDL_AudioSpec(44100, audio.AUDIO_U16SYS, 2, 8192, self.audiocallback, None) spec = audio.SDL_AudioSpec(0, 0, 0, 0) ret = audio.SDL_OpenAudio(reqspec, ctypes.byref(spec)) self.assertEqual(ret, 0) self.assertEqual(spec.format, reqspec.format) self.assertEqual(spec.freq, reqspec.freq) self.assertEqual(spec.channels, reqspec.channels) audio.SDL_CloseAudio() SDL_QuitSubSystem(SDL_INIT_AUDIO)
def test_SDL_GetAudioDeviceName(self): os.environ["SDL_AUDIODRIVER"] = "dummy" SDL_InitSubSystem(SDL_INIT_AUDIO) outnum = audio.SDL_GetNumAudioDevices(False) for x in range(outnum): name = audio.SDL_GetAudioDeviceName(x, False) self.assertIsNotNone(name) innum = audio.SDL_GetNumAudioDevices(True) for x in range(innum): name = audio.SDL_GetAudioDeviceName(x, True) self.assertIsNotNone(name) # self.assertRaises(SDLError, audio.get_audio_device_name, -1) # self.assertRaises(SDLError, audio.get_audio_device_name, -1, True) SDL_QuitSubSystem(SDL_INIT_AUDIO)
def test_SDL_GetCurrentAudioDriver(self): success = 0 # Reset audio subsystem SDL_Quit() SDL_Init(0) for index in range(audio.SDL_GetNumAudioDrivers()): drivername = audio.SDL_GetAudioDriver(index) os.environ["SDL_AUDIODRIVER"] = drivername.decode("utf-8") # Certain drivers fail without bringing up the correct # return value, such as the esd, if it is not running. SDL_InitSubSystem(SDL_INIT_AUDIO) driver = audio.SDL_GetCurrentAudioDriver() SDL_QuitSubSystem(SDL_INIT_AUDIO) # Do not handle wrong return values. if driver is not None: assert drivername == driver success += 1 assert success >= 1
def test_SDL_OpenCloseAudioDevice(self): os.environ["SDL_AUDIODRIVER"] = "dummy" SDL_InitSubSystem(SDL_INIT_AUDIO) reqspec = audio.SDL_AudioSpec(44100, audio.AUDIO_U16SYS, 2, 8192, self.audiocallback, None) outnum = audio.SDL_GetNumAudioDevices(0) for x in range(outnum): spec = audio.SDL_AudioSpec() name = audio.SDL_GetAudioDeviceName(x, 0) self.assertIsNotNone(name) deviceid = audio.SDL_OpenAudioDevice(None, 0, reqspec, ctypes.byref(spec), 1) self.assertGreaterEqual(deviceid, 2) self.assertIsInstance(spec, audio.SDL_AudioSpec) self.assertEqual(spec.format, reqspec.format) self.assertEqual(spec.freq, reqspec.freq) self.assertEqual(spec.channels, reqspec.channels) audio.SDL_CloseAudioDevice(deviceid) SDL_QuitSubSystem(SDL_INIT_AUDIO)
def test_SDL_GetAudioDriver(self): if SDL_InitSubSystem(SDL_INIT_AUDIO) != 0: self.skipTest('Audio subsystem not supported') founddummy = False drivercount = audio.SDL_GetNumAudioDrivers() for index in range(drivercount): drivername = audio.SDL_GetAudioDriver(index) self.assertIsInstance(drivername, (str, bytes)) if drivername == b"dummy": founddummy = True self.assertTrue(founddummy, "could not find dummy driver") # self.assertRaises(SDLError, audio.SDL_GetAudioDriver, -1) # self.assertRaises(SDLError, audio.get_audio_driver, # drivercount + 1) self.assertRaises((ctypes.ArgumentError, TypeError), audio.SDL_GetAudioDriver, "Test") self.assertRaises((ctypes.ArgumentError, TypeError), audio.SDL_GetAudioDriver, None) SDL_QuitSubSystem(SDL_INIT_AUDIO)
def test_SDL_InitQuitAudio(): SDL_Init(0) ret = SDL_InitSubSystem(SDL_INIT_AUDIO) SDL_Quit() assert ret == 0
from OpenGL import GL glimport = True except: glimport = False from PyQt5.QtOpenGL import QGLFormat from sdl2 import SDL_WasInit, SDL_InitSubSystem, SDL_QuitSubSystem, SDL_INIT_VIDEO from sdl2 import SDL_GetNumDisplayModes, SDL_DisplayMode, SDL_GetDisplayMode from m64py.core.defs import * from m64py.frontend.log import log try: if not SDL_WasInit(SDL_INIT_VIDEO): SDL_InitSubSystem(SDL_INIT_VIDEO) MODES = [] display = SDL_DisplayMode() for mode in range(SDL_GetNumDisplayModes(0)): ret = SDL_GetDisplayMode(0, mode, ctypes.byref(display)) if (display.w, display.h) not in MODES: MODES.append((display.w, display.h)) if SDL_WasInit(SDL_INIT_VIDEO): SDL_QuitSubSystem(SDL_INIT_VIDEO) except Exception as err: log.warn(str(err)) class Video(): """Mupen64Plus video extension""" def __init__(self):
def test_SDL_GetNumAudioDrivers(self): if SDL_InitSubSystem(SDL_INIT_AUDIO) != 0: self.skipTest('Audio subsystem not supported') count = audio.SDL_GetNumAudioDrivers() self.assertGreaterEqual(count, 1) SDL_QuitSubSystem(SDL_INIT_AUDIO)