SDL: removed QNX support.

From 5cedc2f1fffbe098a786d909205461612583f404 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Tue, 22 Nov 2022 20:23:40 +0300
Subject: [PATCH] removed QNX support.

---
 configure                               |  47 +-
 configure.ac                            |  46 +-
 include/SDL_atomic.h                    |   5 -
 include/SDL_config.h.cmake              |   2 -
 include/SDL_config.h.in                 |   2 -
 src/audio/SDL_audio.c                   |   3 -
 src/audio/SDL_sysaudio.h                |   1 -
 src/audio/qsa/SDL_qsa_audio.c           | 627 ------------------------
 src/audio/qsa/SDL_qsa_audio.h           |  54 --
 src/cpuinfo/SDL_cpuinfo.c               |   6 -
 src/dynapi/SDL_dynapi.c                 |   2 +-
 src/file/SDL_rwops.c                    |   5 -
 src/filesystem/unix/SDL_sysfilesystem.c |   6 -
 src/video/SDL_sysvideo.h                |   1 -
 src/video/SDL_video.c                   |   3 -
 src/video/qnx/gl.c                      | 285 -----------
 src/video/qnx/keyboard.c                | 133 -----
 src/video/qnx/sdl_qnx.h                 |  48 --
 src/video/qnx/video.c                   | 358 --------------
 src/video/x11/SDL_x11opengl.c           |   2 -
 test/configure                          |   5 -
 test/configure.ac                       |   5 -
 22 files changed, 5 insertions(+), 1641 deletions(-)
 delete mode 100644 src/audio/qsa/SDL_qsa_audio.c
 delete mode 100644 src/audio/qsa/SDL_qsa_audio.h
 delete mode 100644 src/video/qnx/gl.c
 delete mode 100644 src/video/qnx/keyboard.c
 delete mode 100644 src/video/qnx/sdl_qnx.h
 delete mode 100644 src/video/qnx/video.c

diff --git a/configure b/configure
index e6d16f299a37..1b86efd5dc59 100755
--- a/configure
+++ b/configure
@@ -18125,14 +18125,7 @@ case "$host" in
 esac
 
 INCLUDE="-I$srcdir/include"
-
-case "$host" in
-    *-*-nto-qnx*)
-        ;;
-    *)
-        INCLUDE="$INCLUDE -idirafter $srcdir/src/video/khronos"
-        ;;
-esac
+INCLUDE="$INCLUDE -idirafter $srcdir/src/video/khronos"
 
 case "$host" in
     *-*-haiku*)
@@ -24507,32 +24500,6 @@ printf "%s\n" "#define SDL_VIDEO_DRIVER_OFFSCREEN 1" >>confdefs.h
     fi
 }
 
-CheckQNXVideo()
-{
-    if test x$enable_video = xyes; then
-
-printf "%s\n" "#define SDL_VIDEO_DRIVER_QNX 1" >>confdefs.h
-
-        SOURCES="$SOURCES $srcdir/src/video/qnx/*.c"
-        have_video=yes
-        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lscreen -lEGL -lGLESv2"
-        SUMMARY_video="${SUMMARY_video} qnx"
-    fi
-}
-
-CheckQNXAudio()
-{
-    if test x$enable_audio = xyes; then
-
-printf "%s\n" "#define SDL_AUDIO_DRIVER_QSA 1" >>confdefs.h
-
-        SOURCES="$SOURCES $srcdir/src/audio/qsa/*.c"
-        have_audio=yes
-        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lasound"
-        SUMMARY_audio="${SUMMARY_audio} qsa"
-    fi
-}
-
 # Check whether --enable-video-opengl was given.
 if test ${enable_video_opengl+y}
 then :
@@ -25727,10 +25694,6 @@ fi
             pthread_cflags="-D_REENTRANT"
             pthread_lib=""
             ;;
-        *-*-nto*)
-            pthread_cflags="-D_REENTRANT"
-            pthread_lib=""
-            ;;
         *-*-emscripten*)
             pthread_cflags="-D_REENTRANT -pthread"
             pthread_lib="-pthread"
@@ -27201,7 +27164,7 @@ CheckEventSignals
 have_locale=no
 
 case "$host" in
-    *-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-aix*|*-*-minix*|*-*-nto*)
+    *-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-aix*|*-*-minix*)
         case "$host" in
             *-*-android*)
                 # Android
@@ -27237,9 +27200,6 @@ printf "%s\n" "#define SDL_VIDEO_DRIVER_ANDROID 1" >>confdefs.h
             *-*-hpux*)          ARCH=hpux ;;
             *-*-aix*)           ARCH=aix ;;
             *-*-minix*)         ARCH=minix ;;
-            *-*-nto*)           ARCH=nto
-                CheckQNXVideo
-                ;;
         esac
         CheckVisibilityHidden
         CheckWerror
@@ -27337,9 +27297,6 @@ printf "%s\n" "#define SDL_AUDIO_DRIVER_AAUDIO 1" >>confdefs.h
 
                 have_audio=yes
             ;;
-            nto)
-                CheckQNXAudio
-            ;;
           esac
         fi
         # Set up files for the joystick library
diff --git a/configure.ac b/configure.ac
index 8371faa2ce02..ede7e065ec19 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,15 +88,7 @@ esac
 
 dnl Set up the compiler and linker flags
 INCLUDE="-I$srcdir/include"
-
-dnl Don't use our khronos headers on QNX.
-case "$host" in
-    *-*-nto-qnx*)
-        ;;
-    *)
-        INCLUDE="$INCLUDE -idirafter $srcdir/src/video/khronos"
-        ;;
-esac
+INCLUDE="$INCLUDE -idirafter $srcdir/src/video/khronos"
 
 dnl use CXX for linker on Haiku
 case "$host" in
@@ -2162,30 +2154,6 @@ CheckOffscreenVideo()
     fi
 }
 
-dnl Set up the QNX video driver if enabled
-CheckQNXVideo()
-{
-    if test x$enable_video = xyes; then
-        AC_DEFINE(SDL_VIDEO_DRIVER_QNX, 1, [ ])
-        SOURCES="$SOURCES $srcdir/src/video/qnx/*.c"
-        have_video=yes
-        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lscreen -lEGL -lGLESv2"
-        SUMMARY_video="${SUMMARY_video} qnx"
-    fi
-}
-
-dnl Set up the QNX audio driver if enabled
-CheckQNXAudio()
-{
-    if test x$enable_audio = xyes; then
-        AC_DEFINE(SDL_AUDIO_DRIVER_QSA, 1, [ ])
-        SOURCES="$SOURCES $srcdir/src/audio/qsa/*.c"
-        have_audio=yes
-        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lasound"
-        SUMMARY_audio="${SUMMARY_audio} qsa"
-    fi
-}
-
 dnl Check to see if OpenGL support is desired
 AC_ARG_ENABLE(video-opengl,
 [AS_HELP_STRING([--enable-video-opengl], [include OpenGL support [default=yes]])],
@@ -2806,10 +2774,6 @@ dnl This is used on Linux for glibc binary compatibility (Doh!)
             pthread_cflags="-D_REENTRANT"
             pthread_lib=""
             ;;
-        *-*-nto*)
-            pthread_cflags="-D_REENTRANT"
-            pthread_lib=""
-            ;;
         *-*-emscripten*)
             pthread_cflags="-D_REENTRANT -pthread"
             pthread_lib="-pthread"
@@ -3436,7 +3400,7 @@ have_locale=no
 
 dnl Set up the configuration based on the host platform!
 case "$host" in
-    *-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-aix*|*-*-minix*|*-*-nto*)
+    *-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-aix*|*-*-minix*)
         case "$host" in
             *-*-android*)
                 # Android
@@ -3470,9 +3434,6 @@ case "$host" in
             *-*-hpux*)          ARCH=hpux ;;
             *-*-aix*)           ARCH=aix ;;
             *-*-minix*)         ARCH=minix ;;
-            *-*-nto*)           ARCH=nto
-                CheckQNXVideo
-                ;;
         esac
         CheckVisibilityHidden
         CheckWerror
@@ -3562,9 +3523,6 @@ case "$host" in
 
                 have_audio=yes
             ;;
-            nto)
-                CheckQNXAudio
-            ;;
           esac
         fi
         # Set up files for the joystick library
diff --git a/include/SDL_atomic.h b/include/SDL_atomic.h
index f0c05f4bb84e..266b53e12ea5 100644
--- a/include/SDL_atomic.h
+++ b/include/SDL_atomic.h
@@ -200,11 +200,6 @@ extern DECLSPEC void SDLCALL SDL_MemoryBarrierAcquireFunction(void);
 typedef void (*SDL_KernelMemoryBarrierFunc)();
 #define SDL_MemoryBarrierRelease()	((SDL_KernelMemoryBarrierFunc)0xffff0fa0)()
 #define SDL_MemoryBarrierAcquire()	((SDL_KernelMemoryBarrierFunc)0xffff0fa0)()
-#elif 0 /* defined(__QNXNTO__) */
-#include <sys/cpuinline.h>
-
-#define SDL_MemoryBarrierRelease()   __cpu_membarrier()
-#define SDL_MemoryBarrierAcquire()   __cpu_membarrier()
 #else
 #if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7EM__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) || defined(__ARM_ARCH_8A__)
 #define SDL_MemoryBarrierRelease()   __asm__ __volatile__ ("dmb ish" : : : "memory")
diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
index 0176b8a8de8c..336987f7ef2f 100644
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -305,7 +305,6 @@
 #cmakedefine SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC @SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC@
 #cmakedefine SDL_AUDIO_DRIVER_PULSEAUDIO @SDL_AUDIO_DRIVER_PULSEAUDIO@
 #cmakedefine SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC @SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC@
-#cmakedefine SDL_AUDIO_DRIVER_QSA @SDL_AUDIO_DRIVER_QSA@
 #cmakedefine SDL_AUDIO_DRIVER_WASAPI @SDL_AUDIO_DRIVER_WASAPI@
 #cmakedefine SDL_AUDIO_DRIVER_VITA @SDL_AUDIO_DRIVER_VITA@
 #cmakedefine SDL_AUDIO_DRIVER_PSP @SDL_AUDIO_DRIVER_PSP@
@@ -394,7 +393,6 @@
 #cmakedefine SDL_VIDEO_DRIVER_RPI @SDL_VIDEO_DRIVER_RPI@
 #cmakedefine SDL_VIDEO_DRIVER_VIVANTE @SDL_VIDEO_DRIVER_VIVANTE@
 #cmakedefine SDL_VIDEO_DRIVER_VIVANTE_VDK @SDL_VIDEO_DRIVER_VIVANTE_VDK@
-#cmakedefine SDL_VIDEO_DRIVER_QNX @SDL_VIDEO_DRIVER_QNX@
 #cmakedefine SDL_VIDEO_DRIVER_RISCOS @SDL_VIDEO_DRIVER_RISCOS@
 #cmakedefine SDL_VIDEO_DRIVER_PSP @SDL_VIDEO_DRIVER_PSP@
 #cmakedefine SDL_VIDEO_DRIVER_PS2 @SDL_VIDEO_DRIVER_PS2@
diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in
index c9904c683f06..9a8f9e196f67 100644
--- a/include/SDL_config.h.in
+++ b/include/SDL_config.h.in
@@ -292,7 +292,6 @@
 #undef SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC
 #undef SDL_AUDIO_DRIVER_PULSEAUDIO
 #undef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC
-#undef SDL_AUDIO_DRIVER_QSA
 #undef SDL_AUDIO_DRIVER_WASAPI
 
 /* Enable various input drivers */
@@ -388,7 +387,6 @@
 #undef SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
 #undef SDL_VIDEO_DRIVER_VIVANTE
 #undef SDL_VIDEO_DRIVER_VIVANTE_VDK
-#undef SDL_VIDEO_DRIVER_QNX
 #undef SDL_VIDEO_DRIVER_RISCOS
 
 #undef SDL_VIDEO_RENDER_D3D
diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index 0916ad24a00d..2bbc73a8e800 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -45,9 +45,6 @@ static const AudioBootStrap *const bootstrap[] = {
 #if SDL_AUDIO_DRIVER_NETBSD
     &NETBSDAUDIO_bootstrap,
 #endif
-#if SDL_AUDIO_DRIVER_QSA
-    &QSAAUDIO_bootstrap,
-#endif
 #if SDL_AUDIO_DRIVER_WASAPI
     &WASAPI_bootstrap,
 #endif
diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h
index dcdc5a00b7bc..60a050912110 100644
--- a/src/audio/SDL_sysaudio.h
+++ b/src/audio/SDL_sysaudio.h
@@ -186,7 +186,6 @@ extern AudioBootStrap PULSEAUDIO_bootstrap;
 extern AudioBootStrap ALSA_bootstrap;
 extern AudioBootStrap NETBSDAUDIO_bootstrap;
 extern AudioBootStrap DSP_bootstrap;
-extern AudioBootStrap QSAAUDIO_bootstrap;
 extern AudioBootStrap WASAPI_bootstrap;
 extern AudioBootStrap DSOUND_bootstrap;
 extern AudioBootStrap WINMM_bootstrap;
diff --git a/src/audio/qsa/SDL_qsa_audio.c b/src/audio/qsa/SDL_qsa_audio.c
deleted file mode 100644
index 38db66cf092e..000000000000
--- a/src/audio/qsa/SDL_qsa_audio.c
+++ /dev/null
@@ -1,627 +0,0 @@
-/*
-  Simple DirectMedia Layer
-  Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-*/
-
-/*
- * !!! FIXME: streamline this a little by removing all the
- * !!! FIXME:  if (capture) {} else {} sections that are identical
- * !!! FIXME:  except for one flag.
- */
-
-/* !!! FIXME: can this target support hotplugging? */
-/* !!! FIXME: ...does SDL even support QNX? */
-
-#include "../../SDL_internal.h"
-
-#if SDL_AUDIO_DRIVER_QSA
-
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sched.h>
-#include <sys/select.h>
-#include <sys/neutrino.h>
-#include <sys/asoundlib.h>
-
-#include "SDL_timer.h"
-#include "SDL_audio.h"
-#include "../../core/unix/SDL_poll.h"
-#include "../SDL_audio_c.h"
-#include "SDL_qsa_audio.h"
-
-/* default channel communication parameters */
-#define DEFAULT_CPARAMS_RATE   44100
-#define DEFAULT_CPARAMS_VOICES 1
-
-#define DEFAULT_CPARAMS_FRAG_SIZE 4096
-#define DEFAULT_CPARAMS_FRAGS_MIN 1
-#define DEFAULT_CPARAMS_FRAGS_MAX 1
-
-/* List of found devices */
-#define QSA_MAX_DEVICES       32
-#define QSA_MAX_NAME_LENGTH   81+16     /* Hardcoded in QSA, can't be changed */
-
-typedef struct _QSA_Device
-{
-    char name[QSA_MAX_NAME_LENGTH];     /* Long audio device name for SDL  */
-    int cardno;
-    int deviceno;
-} QSA_Device;
-
-QSA_Device qsa_playback_device[QSA_MAX_DEVICES];
-uint32_t qsa_playback_devices;
-
-QSA_Device qsa_capture_device[QSA_MAX_DEVICES];
-uint32_t qsa_capture_devices;
-
-static SDL_INLINE int
-QSA_SetError(const char *fn, int status)
-{
-    return SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status));
-}
-
-/* !!! FIXME: does this need to be here? Does the SDL version not work? */
-static void
-QSA_ThreadInit(_THIS)
-{
-    /* Increase default 10 priority to 25 to avoid jerky sound */
-    struct sched_param param;
-    if (SchedGet(0, 0, &param) != -1) {
-        param.sched_priority = param.sched_curpriority + 15;
-        SchedSet(0, 0, SCHED_NOCHANGE, &param);
-    }
-}
-
-/* PCM channel parameters initialize function */
-static void
-QSA_InitAudioParams(snd_pcm_channel_params_t * cpars)
-{
-    SDL_zerop(cpars);
-    cpars->channel = SND_PCM_CHANNEL_PLAYBACK;
-    cpars->mode = SND_PCM_MODE_BLOCK;
-    cpars->start_mode = SND_PCM_START_DATA;
-    cpars->stop_mode = SND_PCM_STOP_STOP;
-    cpars->format.format = SND_PCM_SFMT_S16_LE;
-    cpars->format.interleave = 1;
-    cpars->format.rate = DEFAULT_CPARAMS_RATE;
-    cpars->format.voices = DEFAULT_CPARAMS_VOICES;
-    cpars->buf.block.frag_size = DEFAULT_CPARAMS_FRAG_SIZE;
-    cpars->buf.block.frags_min = DEFAULT_CPARAMS_FRAGS_MIN;
-    cpars->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX;
-}
-
-/* This function waits until it is possible to write a full sound buffer */
-static void
-QSA_WaitDevice(_THIS)
-{
-    int result;
-
-    /* Setup timeout for playing one fragment equal to 2 seconds          */
-    /* If timeout occurred than something wrong with hardware or driver    */
-    /* For example, Vortex 8820 audio driver stucks on second DAC because */
-    /* it doesn't exist !                                                 */
-    result = SDL_IOReady(this->hidden->audio_fd,
-                         this->iscapture ? SDL_IOR_READ : SDL_IOR_WRITE,
-                         2 * 1000);
-    switch (result) {
-    case -1:
-        SDL_SetError("QSA: SDL_IOReady() failed: %s", strerror(errno));
-        break;
-    case 0:
-        SDL_SetError("QSA: timeout on buffer waiting occurred");
-        this->hidden->timeout_on_wait = 1;
-        break;
-    default:
-        this->hidden->timeout_on_wait = 0;
-        break;
-    }
-}
-
-static void
-QSA_PlayDevice(_THIS)
-{
-    snd_pcm_channel_status_t cstatus;
-    int written;
-    int status;
-    int towrite;
-    void *pcmbuffer;
-
-    if (!SDL_AtomicGet(&this->enabled) || !this->hidden) {
-        return;
-    }
-
-    towrite = this->spec.size;
-    pcmbuffer = this->hidden->pcm_buf;
-
-    /* Write the audio data, checking for EAGAIN (buffer full) and underrun */
-    do {
-        written =
-            snd_pcm_plugin_write(this->hidden->audio_handle, pcmbuffer,
-                                 towrite);
-        if (written != towrite) {
-            /* Check if samples playback got stuck somewhere in hardware or in */
-            /* the audio device driver */
-            if ((errno == EAGAIN) && (written == 0)) {
-                if (this->hidden->timeout_on_wait != 0) {
-                    SDL_SetError("QSA: buffer playback timeout");
-                    return;
-                }
-            }
-
-            /* Check for errors or conditions */
-            if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
-                /* Let a little CPU time go by and try to write again */
-                SDL_Delay(1);
-
-                /* if we wrote some data */
-                towrite -= written;
-                pcmbuffer += written * this->spec.channels;
-                continue;
-            } else {
-                if ((errno == EINVAL) || (errno == EIO)) {
-                    SDL_zero(cstatus);
-                    if (!this->iscapture) {
-                        cstatus.channel = SND_PCM_CHANNEL_PLAYBACK;
-                    } else {
-                        cstatus.channel = SND_PCM_CHANNEL_CAPTURE;
-                    }
-
-                    status =
-                        snd_pcm_plugin_status(this->hidden->audio_handle,
-                                              &cstatus);
-                    if (status < 0) {
-                        QSA_SetError("snd_pcm_plugin_status", status);
-                        return;
-                    }
-
-                    if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) ||
-                        (cstatus.status == SND_PCM_STATUS_READY)) {
-                        if (!this->iscapture) {
-                            status =
-                                snd_pcm_plugin_prepare(this->hidden->
-                                                       audio_handle,
-                                                       SND_PCM_CHANNEL_PLAYBACK);
-                        } else {
-                            status =
-                                snd_pcm_plugin_prepare(this->hidden->
-                                                       audio_handle,
-                                                       SND_PCM_CHANNEL_CAPTURE);
-                        }
-                        if (status < 0) {
-                            QSA_SetError("snd_pcm_plugin_prepare", status);
-                            return;
-                        }
-                    }
-                    continue;
-                } else {
-                    return;
-                }
-            }
-        } else {
-            /* we wrote all remaining data */
-            towrite -= written;
-            pcmbuffer += written * this->spec.channels;
-        }
-    } while ((towrite > 0) && SDL_AtomicGet(&this->enabled));
-
-    /* If we couldn't write, assume fatal error for now */
-    if (towrite != 0) {
-        SDL_OpenedAudioDeviceDisconnected(this);
-    }
-}
-
-static Uint8 *
-QSA_GetDeviceBuf(_THIS)
-{
-    return this->hidden->pcm_buf;
-}
-
-static void
-QSA_CloseDevice(_THIS)
-{
-    if (this->hidden->audio_handle != NULL) {
-        if (!this->iscapture) {
-            /* Finish playing available samples */
-            snd_pcm_plugin_flush(this->hidden->audio_handle,
-                                 SND_PCM_CHANNEL_PLAYBACK);
-        } else {
-            /* Cancel unread samples during capture */
-            snd_pcm_plugin_flush(this->hidden->audio_handle,
-                                 SND_PCM_CHANNEL_CAPTURE);
-        }
-        snd_pcm_close(this->hidden->audio_handle);
-    }
-
-    SDL_free(this->hidden->pcm_buf);
-    SDL_free(this->hidden);
-}
-
-static int
-QSA_OpenDevice(_THIS, const char *devname)
-{
-    const QSA_Device *device = (const QSA_Device *) this->handle;
-    SDL_bool iscapture = this->iscapture;
-    int status = 0;
-    int format = 0;
-    SDL_AudioFormat test_format;
-    snd_pcm_channel_setup_t csetup;
-    snd_pcm_channel_params_t cparams;
-
-    /* Initialize all variables that we clean on shutdown */
-    this->hidden =
-        (struct SDL_PrivateAudioData *) SDL_calloc(1,
-                                                   (sizeof
-                                                    (struct
-                                                     SDL_PrivateAudioData)));
-    if (this->hidden == NULL) {
-        return SDL_OutOfMemory();
-    }
-
-    /* Initialize channel transfer parameters to default */
-    QSA_InitAudioParams(&cparams);
-
-    if (device != NULL) {
-        /* Open requested audio device */
-        this->hidden->deviceno = device->deviceno;
-        this->hidden->cardno = device->cardno;
-        status = snd_pcm_open(&this->hidden->audio_handle,
-                              device->cardno, device->deviceno,
-                              iscapture ? SND_PCM_OPEN_CAPTURE : SND_PCM_OPEN_PLAYBACK);
-    } else {
-        /* Open system default audio device */
-        status = snd_pcm_open_preferred(&this->hidden->audio_handle,
-                                        &this->hidden->cardno,
-                                        &this->hidden->deviceno,
-                                        iscapture ? SND_PCM_OPEN_CAPTURE : SND_PCM_OPEN_PLAYBACK);
-    }
-
-    /* Check if requested device is opened */
-    if (status < 0) {
-        this->hidden->audio_handle = NULL;
-        return QSA_SetError("snd_pcm_open", status);
-    }
-
-    /* Try for a closest match on audio format */
-    for (test_format = SDL_FirstAudioFormat(this->spec.format); test_format; test_format = SDL_NextAudioFormat()) {
-        /* if match found set format to equivalent QSA format */
-        switch (test_format) {
-        case AUDIO_U8:
-            format = SND_PCM_SFMT_U8;
-            break;
-        case AUDIO_S8:
-            format = SND_PCM_SFMT_S8;
-            break;
-        case AUDIO_S16LSB:
-            format = SND_PCM_SFMT_S16_LE;
-            break;
-        case AUDIO_S16MSB:
-            format = SND_PCM_SFMT_S16_BE;
-            break;
-        case AUDIO_U16LSB:
-            format = SND_PCM_SFMT_U16_LE;
-            break;
-        case AUDIO_U16MSB:
-            format = SND_PCM_SFMT_U16_BE;
-            break;
-        case AUDIO_S32LSB:
-            format = SND_PCM_SFMT_S32_LE;
-            break;
-        case AUDIO_S32MSB:
-            format = SND_PCM_SFMT_S32_BE;
-            break;
-        case AUDIO_F32LSB:
-            format = SND_PCM_SFMT_FLOAT_LE;
-            break;
-        case AUDIO_F32MSB:
-            format = SND_PCM_SFMT_FLOAT_BE;
-            break;
-        default:
-            continue;
-        }
-        break;
-    }
-    /* assumes test_format not 0 on success */
-    /* can't use format as SND_PCM_SFMT_U8 = 0 in qsa */
-    if (!test_format) {
-        return SDL_SetError("%s: Unsupported audio format", "qsa");
-    }
-    this->spec.format = test_format;
-
-    /* Set the audio format */
-    cparams.format.format = format;
-
-    /* Set mono/stereo/4ch/6ch/8ch audio */
-    cparams.format.voices = this->spec.channels;
-
-    /* Set rate */
-    cparams.format.rate = this->spec.freq;
-
-    /* Setup the transfer parameters according to cparams */
-    status = snd_pcm_plugin_params(this->hidden->audio_handle, &cparams);
-    if (status < 0) {
-        return QSA_SetError("snd_pcm_plugin_params", status);
-    }
-
-    /* Make sure channel is setup right one last time */
-    SDL_zero(csetup);
-    if (!this->iscapture) {
-        csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
-    } else {
-        csetup.channel = SND_PCM_CHANNEL_CAPTURE;
-    }
-
-    /* Setup an audio channel */
-    if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) {
-        return SDL_SetError("QSA: Unable to setup channel");
-    }
-
-    /* Calculate the final parameters for this audio specification */
-    SDL_CalculateAudioSpec(&this->spec);
-
-    this->hidden->pcm_len = this->spec.size;
-
-    if (this->hidden->pcm_len == 0) {
-        this->hidden->pcm_len =
-            csetup.buf.block.frag_size * this->spec.channels *
-            (snd_pcm_format_width(format) / 8);
-    }
-
-    /*
-     * Allocate memory to the audio buffer and initialize with silence
-     *  (Note that buffer size must be a multiple of fragment size, so find
-     *  closest multiple)
-     */
-    this->hidden->pcm_buf =
-        (Uint8 *) SDL_malloc(this->hidden->pcm_len);
-    if (this->hidden->pcm_buf == NULL) {
-        return SDL_OutOfMemory();
-    }
-    SDL_memset(this->hidden->pcm_buf, this->spec.silence,
-               this->hidden->pcm_len);
-
-    /* get the file descriptor */
-    if (!this->iscapture) {
-        this->hidden->audio_fd =
-            snd_pcm_file_descriptor(this->hidden->audio_handle,
-                                    SND_PCM_CHANNEL_PLAYBACK);
-    } else {
-        this->hidden->audio_fd =
-            snd_pcm_file_descriptor(this->hidden->audio_handle,
-                                    SND_PCM_CHANNEL_CAPTURE);
-    }
-
-    if (this->hidden->audio_fd < 0) {
-        return QSA_SetError("snd_pcm_file_descriptor", status);
-    }
-
-    /* Prepare an audio channel */
-    if (!this->iscapture) {
-        /* Prepare audio playback */
-        status =
-            snd_pcm_plugin_prepare(this->hidden->audio_handle,
-                                   SND_PCM_CHANNEL_PLAYBACK);
-    } else {
-        /* Prepare audio capture */
-        status =
-            snd_pcm_plugin_prepare(this->hidden->audio_handle,
-                                   SND_PCM_CHANNEL_CAPTURE);
-    }
-
-    if (status < 0) {
-        return QSA_SetError("snd_pcm_plugin_prepare", status);
-    }
-
-    /* We're really ready to rock and roll. :-) */
-    return 0;
-}
-
-static void
-QSA_DetectDevices(void)
-{
-    uint32_t it;
-    uint32_t cards;
-    uint32_t devices;
-    int32_t status;
-
-    /* Detect amount of available devices       */
-    /* this value can be changed in the runtime */
-    cards = snd_cards();
-
-    /* If io-audio manager is not running we will get 0 as number */
-    /* of available audio devices                                 */
-    if (cards == 0) {
-        /* We have no any available audio devices */
-        return;
-    }
-
-    /* !!! FIXME: code duplication */
-    /* Find requested devices by type */
-    {  /* output devices */
-        /* Playback devices enumeration requested */
-        for (it = 0; it < cards; it++) {
-            devices = 0;
-            do {
-                status =
-                    snd_card_get_longname(it,
-                                          qsa_playback_device
-                                          [qsa_playback_devices].name,
-                                          QSA_MAX_NAME_LENGTH);
-                if (status == EOK) {
-                    snd_pcm_t *handle;
-
-                    /* Add device number to device name */
-                    sprintf(qsa_playback_device[qsa_playback_devices].name +
-                            SDL_strlen(qsa_playback_device
-                                       [qsa_playback_devices].name), " d%d",
-                            devices);
-
-                    /* Store associated card number id */
-                    qsa_playback_device[qsa_playback_devices].cardno = it;
-
-                    /* Check if this device id could play anything */
-                    status =
-                        snd_pcm_open(&handle, it, devices,
-                                     SND_PCM_OPEN_PLAYBACK);
-                    if (status == EOK) {
-                        qsa_playback_device[qsa_playback_devices].deviceno =
-                            devices;
-                        status = snd_pcm_close(handle);
-                        if (status == EOK) {
-                            /* Note that spec is NULL, because we are required to open the device before
-                             * acquiring the mix format, making this information inaccessible at
-                             * enumeration time
-                             */
-                            SDL_AddAudioDevice(SDL_FALSE, qsa_playback_device[qsa_playback_devices].name, NULL, &qsa_playback_device[qsa_playback_devices]);
-                            qsa_playback_devices++;
-                        }
-                    } else {
-                        /* Check if we got end of devices list */
-                        if (status == -ENOENT) {
-                            break;
-                        }
-                    }
-                } else {
-                    break;
-                }
-
-                /* Check if we reached maximum devices count */
-                if (qsa_playback_devices >= QSA_MAX_DEVICES) {
-                    break;
-                }
-                devices++;
-            } while (1);
-
-            /* Check if we reached maximum devices count */
-            if (qsa_playback_devices >= QSA_MAX_DEVICES) {
-                break;
-            }
-        }
-    }
-
-    {  /* capture devices */
-        /* Capture devices enumeration requested */
-        for (it = 0; it < cards; it++) {
-            devices = 0;
-            do {
-                status =
-                    snd_card_get_longname(it,
-                                          qsa_capture_device
-                                          [qsa_capture_devices].name,
-                                          QSA_MAX_NAME_LENGTH);
-                if (status == EOK) {
-                    snd_pcm_t *handle;
-
-                    /* Add device number to device name */
-                    sprintf(qsa_capture_device[qsa_capture_devices].name +
-                            SDL_strlen(qsa_capture_device
-                                       [qsa_capture_devices].name), " d%d",
-                            devices);
-
-                    /* Store associated card number id */
-                    qsa_capture_device[qsa_capture_devices].cardno = it;
-
-                    /* Check if this device id could play anything */
-                    status =
-                        snd_pcm_open(&handle, it, devices,
-                                     SND_PCM_OPEN_CAPTURE);
-                    if (status == EOK) {
-                        qsa_capture_device[qsa_capture_devices].deviceno =
-                            devices;
-                        status = snd_pcm_close(handle);
-                        if (status == EOK) {
-                            /* Note that spec is NULL, because we are required to open the device before
-                             * acquiring the mix format, making this information inaccessible at
-                             * enumeration time
-                             */
-                            SDL_AddAudioDevice(SDL_TRUE, qsa_capture_device[qsa_capture_devices].name, NULL, &qsa_capture_device[qsa_capture_devices]);
-                            qsa_capture_devices++;
-                        }
-                    } else {
-                        /* Check if we got end of devices list */
-                        if (status == -ENOENT) {
-                            break;
-                        }
-                    }
-
-                    /* Check if we reached maximum devices count */
-                    if (qsa_capture_devices >= QSA_MAX_DEVICES) {
-                        break;
-                    }
-       

(Patch may be truncated, please check the link at the top of this post.)