SDL: adjust handling of iscapture

From 1043dd8c0d8a80a2df5b7003f84713af29749db2 Mon Sep 17 00:00:00 2001
From: pionere <[EMAIL REDACTED]>
Date: Wed, 19 Jan 2022 12:58:04 +0100
Subject: [PATCH] adjust handling of iscapture - drop iscapture parameter of
 OpenDevice - use SDL_bool for iscapture

---
 src/audio/SDL_audio.c                      |  8 ++++----
 src/audio/SDL_sysaudio.h                   |  6 +++---
 src/audio/aaudio/SDL_aaudio.c              |  3 ++-
 src/audio/alsa/SDL_alsa_audio.c            |  3 ++-
 src/audio/android/SDL_androidaudio.c       |  3 ++-
 src/audio/arts/SDL_artsaudio.c             |  2 +-
 src/audio/coreaudio/SDL_coreaudio.m        |  6 +++---
 src/audio/directsound/SDL_directsound.c    |  3 ++-
 src/audio/disk/SDL_diskaudio.c             |  5 +++--
 src/audio/dsp/SDL_dspaudio.c               |  3 ++-
 src/audio/dummy/SDL_dummyaudio.c           |  2 +-
 src/audio/emscripten/SDL_emscriptenaudio.c |  3 ++-
 src/audio/esd/SDL_esdaudio.c               |  2 +-
 src/audio/fusionsound/SDL_fsaudio.c        |  2 +-
 src/audio/haiku/SDL_haikuaudio.cc          |  2 +-
 src/audio/jack/SDL_jackaudio.c             |  3 ++-
 src/audio/nacl/SDL_naclaudio.c             |  2 +-
 src/audio/nas/SDL_nasaudio.c               |  3 ++-
 src/audio/netbsd/SDL_netbsdaudio.c         |  3 ++-
 src/audio/openslES/SDL_openslES.c          |  4 ++--
 src/audio/os2/SDL_os2audio.c               |  8 ++++----
 src/audio/paudio/SDL_paudio.c              |  2 +-
 src/audio/pipewire/SDL_pipewire.c          |  3 ++-
 src/audio/psp/SDL_pspaudio.c               |  2 +-
 src/audio/pulseaudio/SDL_pulseaudio.c      |  5 +++--
 src/audio/qsa/SDL_qsa_audio.c              | 20 +++++++++-----------
 src/audio/qsa/SDL_qsa_audio.h              |  3 ---
 src/audio/sndio/SDL_sndioaudio.c           |  3 ++-
 src/audio/sun/SDL_sunaudio.c               |  3 ++-
 src/audio/vita/SDL_vitaaudio.c             |  2 +-
 src/audio/wasapi/SDL_wasapi.c              |  4 ++--
 src/audio/winmm/SDL_winmm.c                |  6 +++---
 32 files changed, 69 insertions(+), 60 deletions(-)

diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c
index ad4a201ded3..8ada21e8b80 100644
--- a/src/audio/SDL_audio.c
+++ b/src/audio/SDL_audio.c
@@ -289,7 +289,7 @@ SDL_AudioFreeDeviceHandle_Default(void *handle)
 
 
 static int
-SDL_AudioOpenDevice_Default(_THIS, void *handle, const char *devname, int iscapture)
+SDL_AudioOpenDevice_Default(_THIS, void *handle, const char *devname)
 {
     return SDL_Unsupported();
 }
@@ -458,7 +458,7 @@ free_device_list(SDL_AudioDeviceItem **devices, int *devCount)
 
 /* The audio backends call this when a new device is plugged in. */
 void
-SDL_AddAudioDevice(const int iscapture, const char *name, SDL_AudioSpec *spec, void *handle)
+SDL_AddAudioDevice(const SDL_bool iscapture, const char *name, SDL_AudioSpec *spec, void *handle)
 {
     const int device_index = iscapture ? add_capture_device(name, spec, handle) : add_output_device(name, spec, handle);
     if (device_index != -1) {
@@ -520,7 +520,7 @@ mark_device_removed(void *handle, SDL_AudioDeviceItem *devices, SDL_bool *remove
 
 /* The audio backends call this when a device is removed from the system. */
 void
-SDL_RemoveAudioDevice(const int iscapture, void *handle)
+SDL_RemoveAudioDevice(const SDL_bool iscapture, void *handle)
 {
     int device_index;
     SDL_AudioDevice *device = NULL;
@@ -1398,7 +1398,7 @@ open_audio_device(const char *devname, int iscapture,
         }
     }
 
-    if (current_audio.impl.OpenDevice(device, handle, devname, iscapture) < 0) {
+    if (current_audio.impl.OpenDevice(device, handle, devname) < 0) {
         close_audio_device(device);
         return 0;
     }
diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h
index 0ed4da92a50..0bedfbb52a0 100644
--- a/src/audio/SDL_sysaudio.h
+++ b/src/audio/SDL_sysaudio.h
@@ -39,11 +39,11 @@ typedef struct SDL_AudioDevice SDL_AudioDevice;
 /* Audio targets should call this as devices are added to the system (such as
    a USB headset being plugged in), and should also be called for
    for every device found during DetectDevices(). */
-extern void SDL_AddAudioDevice(const int iscapture, const char *name, SDL_AudioSpec *spec, void *handle);
+extern void SDL_AddAudioDevice(const SDL_bool iscapture, const char *name, SDL_AudioSpec *spec, void *handle);
 
 /* Audio targets should call this as devices are removed, so SDL can update
    its list of available devices. */
-extern void SDL_RemoveAudioDevice(const int iscapture, void *handle);
+extern void SDL_RemoveAudioDevice(const SDL_bool iscapture, void *handle);
 
 /* Audio targets should call this if an opened audio device is lost while
    being used. This can happen due to i/o errors, or a device being unplugged,
@@ -65,7 +65,7 @@ extern void SDL_OpenedAudioDeviceDisconnected(SDL_AudioDevice *device);
 typedef struct SDL_AudioDriverImpl
 {
     void (*DetectDevices) (void);
-    int (*OpenDevice) (_THIS, void *handle, const char *devname, int iscapture);
+    int (*OpenDevice) (_THIS, void *handle, const char *devname);
     void (*ThreadInit) (_THIS); /* Called by audio thread at start */
     void (*ThreadDeinit) (_THIS); /* Called by audio thread at end */
     void (*WaitDevice) (_THIS);
diff --git a/src/audio/aaudio/SDL_aaudio.c b/src/audio/aaudio/SDL_aaudio.c
index 0412e0d5581..63382104e32 100644
--- a/src/audio/aaudio/SDL_aaudio.c
+++ b/src/audio/aaudio/SDL_aaudio.c
@@ -71,9 +71,10 @@ void aaudio_errorCallback( AAudioStream *stream, void *userData, aaudio_result_t
 #define LIB_AAUDIO_SO "libaaudio.so"
 
 static int
-aaudio_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+aaudio_OpenDevice(_THIS, void *handle, const char *devname)
 {
     struct SDL_PrivateAudioData *private;
+    SDL_bool iscapture = this->iscapture;
     aaudio_result_t res;
     LOGI(__func__);
 
diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c
index 83649c24b73..c42b73045d5 100644
--- a/src/audio/alsa/SDL_alsa_audio.c
+++ b/src/audio/alsa/SDL_alsa_audio.c
@@ -543,9 +543,10 @@ ALSA_set_buffer_size(_THIS, snd_pcm_hw_params_t *params)
 }
 
 static int
-ALSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+ALSA_OpenDevice(_THIS, void *handle, const char *devname)
 {
     int status = 0;
+    SDL_bool iscapture = this->iscapture;
     snd_pcm_t *pcm_handle = NULL;
     snd_pcm_hw_params_t *hwparams = NULL;
     snd_pcm_sw_params_t *swparams = NULL;
diff --git a/src/audio/android/SDL_androidaudio.c b/src/audio/android/SDL_androidaudio.c
index 31f256a60de..cdf494897d4 100644
--- a/src/audio/android/SDL_androidaudio.c
+++ b/src/audio/android/SDL_androidaudio.c
@@ -36,9 +36,10 @@ static SDL_AudioDevice* audioDevice = NULL;
 static SDL_AudioDevice* captureDevice = NULL;
 
 static int
-ANDROIDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+ANDROIDAUDIO_OpenDevice(_THIS, void *handle, const char *devname)
 {
     SDL_AudioFormat test_format;
+    SDL_bool iscapture = this->iscapture;
 
     SDL_assert((captureDevice == NULL) || !iscapture);
     SDL_assert((audioDevice == NULL) || iscapture);
diff --git a/src/audio/arts/SDL_artsaudio.c b/src/audio/arts/SDL_artsaudio.c
index c85cc0b6533..6806b1b4a29 100644
--- a/src/audio/arts/SDL_artsaudio.c
+++ b/src/audio/arts/SDL_artsaudio.c
@@ -216,7 +216,7 @@ ARTS_Suspend(void)
 }
 
 static int
-ARTS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+ARTS_OpenDevice(_THIS, void *handle, const char *devname)
 {
     int rc = 0;
     int bits = 0, frag_spec = 0;
diff --git a/src/audio/coreaudio/SDL_coreaudio.m b/src/audio/coreaudio/SDL_coreaudio.m
index c72ce1e40d8..95823e03e32 100644
--- a/src/audio/coreaudio/SDL_coreaudio.m
+++ b/src/audio/coreaudio/SDL_coreaudio.m
@@ -1015,11 +1015,11 @@ output device (in which case we'll try again). */
 }
 
 static int
-COREAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+COREAUDIO_OpenDevice(_THIS, void *handle, const char *devname)
 {
     AudioStreamBasicDescription *strdesc;
     SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
-    int valid_datatype = 0;
+    SDL_bool valid_datatype = SDL_FALSE, iscapture = this->iscapture;
     SDL_AudioDevice **new_open_devices;
 
     /* Initialize all variables that we clean on shutdown */
@@ -1088,7 +1088,7 @@ output device (in which case we'll try again). */
         case AUDIO_S32MSB:
         case AUDIO_F32LSB:
         case AUDIO_F32MSB:
-            valid_datatype = 1;
+            valid_datatype = SDL_TRUE;
             strdesc->mBitsPerChannel = SDL_AUDIO_BITSIZE(this->spec.format);
             if (SDL_AUDIO_ISBIGENDIAN(this->spec.format))
                 strdesc->mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
diff --git a/src/audio/directsound/SDL_directsound.c b/src/audio/directsound/SDL_directsound.c
index 65b33a2b9f9..11430272395 100644
--- a/src/audio/directsound/SDL_directsound.c
+++ b/src/audio/directsound/SDL_directsound.c
@@ -473,12 +473,13 @@ CreateCaptureBuffer(_THIS, const DWORD bufsize, WAVEFORMATEX *wfmt)
 }
 
 static int
-DSOUND_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+DSOUND_OpenDevice(_THIS, void *handle, const char *devname)
 {
     const DWORD numchunks = 8;
     HRESULT result;
     SDL_bool valid_format = SDL_FALSE;
     SDL_bool tried_format = SDL_FALSE;
+    SDL_bool iscapture = this->iscapture;
     SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
     LPGUID guid = (LPGUID) handle;
     DWORD bufsize;
diff --git a/src/audio/disk/SDL_diskaudio.c b/src/audio/disk/SDL_diskaudio.c
index 5368df1e40b..9eec2e849a0 100644
--- a/src/audio/disk/SDL_diskaudio.c
+++ b/src/audio/disk/SDL_diskaudio.c
@@ -114,7 +114,7 @@ DISKAUDIO_CloseDevice(_THIS)
 
 
 static const char *
-get_filename(const int iscapture, const char *devname)
+get_filename(const SDL_bool iscapture, const char *devname)
 {
     if (devname == NULL) {
         devname = SDL_getenv(iscapture ? DISKENVR_INFILE : DISKENVR_OUTFILE);
@@ -126,9 +126,10 @@ get_filename(const int iscapture, const char *devname)
 }
 
 static int
-DISKAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+DISKAUDIO_OpenDevice(_THIS, void *handle, const char *devname)
 {
     /* handle != NULL means "user specified the placeholder name on the fake detected device list" */
+    SDL_bool iscapture = _this->iscapture;
     const char *fname = get_filename(iscapture, handle ? NULL : devname);
     const char *envr = SDL_getenv(DISKENVR_IODELAY);
 
diff --git a/src/audio/dsp/SDL_dspaudio.c b/src/audio/dsp/SDL_dspaudio.c
index b0ca0f6594c..0176da9e4e4 100644
--- a/src/audio/dsp/SDL_dspaudio.c
+++ b/src/audio/dsp/SDL_dspaudio.c
@@ -68,8 +68,9 @@ DSP_CloseDevice(_THIS)
 
 
 static int
-DSP_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+DSP_OpenDevice(_THIS, void *handle, const char *devname)
 {
+    SDL_bool iscapture = this->iscapture;
     const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
     int format;
     int value;
diff --git a/src/audio/dummy/SDL_dummyaudio.c b/src/audio/dummy/SDL_dummyaudio.c
index 4383243e897..e2b7bc6d01e 100644
--- a/src/audio/dummy/SDL_dummyaudio.c
+++ b/src/audio/dummy/SDL_dummyaudio.c
@@ -28,7 +28,7 @@
 #include "SDL_dummyaudio.h"
 
 static int
-DUMMYAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+DUMMYAUDIO_OpenDevice(_THIS, void *handle, const char *devname)
 {
     _this->hidden = (void *) 0x1;  /* just something non-NULL */
     return 0;                   /* always succeeds. */
diff --git a/src/audio/emscripten/SDL_emscriptenaudio.c b/src/audio/emscripten/SDL_emscriptenaudio.c
index 0652c414272..764c8e1b4af 100644
--- a/src/audio/emscripten/SDL_emscriptenaudio.c
+++ b/src/audio/emscripten/SDL_emscriptenaudio.c
@@ -192,10 +192,11 @@ EMSCRIPTENAUDIO_CloseDevice(_THIS)
 }
 
 static int
-EMSCRIPTENAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+EMSCRIPTENAUDIO_OpenDevice(_THIS, void *handle, const char *devname)
 {
     SDL_bool valid_format = SDL_FALSE;
     SDL_AudioFormat test_format;
+    SDL_bool iscapture = this->iscapture;
     int result;
 
     /* based on parts of library_sdl.js */
diff --git a/src/audio/esd/SDL_esdaudio.c b/src/audio/esd/SDL_esdaudio.c
index 14035bdc3ce..15210051989 100644
--- a/src/audio/esd/SDL_esdaudio.c
+++ b/src/audio/esd/SDL_esdaudio.c
@@ -208,7 +208,7 @@ get_progname(void)
 
 
 static int
-ESD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+ESD_OpenDevice(_THIS, void *handle, const char *devname)
 {
     esd_format_t format = (ESD_STREAM | ESD_PLAY);
     SDL_AudioFormat test_format = 0;
diff --git a/src/audio/fusionsound/SDL_fsaudio.c b/src/audio/fusionsound/SDL_fsaudio.c
index af376a92a3b..89affb61508 100644
--- a/src/audio/fusionsound/SDL_fsaudio.c
+++ b/src/audio/fusionsound/SDL_fsaudio.c
@@ -174,7 +174,7 @@ SDL_FS_CloseDevice(_THIS)
 
 
 static int
-SDL_FS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+SDL_FS_OpenDevice(_THIS, void *handle, const char *devname)
 {
     int bytes;
     SDL_AudioFormat test_format = 0, format = 0;
diff --git a/src/audio/haiku/SDL_haikuaudio.cc b/src/audio/haiku/SDL_haikuaudio.cc
index fe07b6994ec..9e3724799b7 100644
--- a/src/audio/haiku/SDL_haikuaudio.cc
+++ b/src/audio/haiku/SDL_haikuaudio.cc
@@ -120,7 +120,7 @@ UnmaskSignals(sigset_t * omask)
 
 
 static int
-HAIKUAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+HAIKUAUDIO_OpenDevice(_THIS, void *handle, const char *devname)
 {
     int valid_datatype = 0;
     media_raw_audio_format format;
diff --git a/src/audio/jack/SDL_jackaudio.c b/src/audio/jack/SDL_jackaudio.c
index 9f68a31dff1..649077c87d6 100644
--- a/src/audio/jack/SDL_jackaudio.c
+++ b/src/audio/jack/SDL_jackaudio.c
@@ -280,12 +280,13 @@ JACK_CloseDevice(_THIS)
 }
 
 static int
-JACK_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+JACK_OpenDevice(_THIS, void *handle, const char *devname)
 {
     /* Note that JACK uses "output" for capture devices (they output audio
         data to us) and "input" for playback (we input audio data to them).
         Likewise, SDL's playback port will be "output" (we write data out)
         and capture will be "input" (we read data in). */
+    SDL_bool iscapture = this->iscapture;
     const unsigned long sysportflags = iscapture ? JackPortIsOutput : JackPortIsInput;
     const unsigned long sdlportflags = iscapture ? JackPortIsInput : JackPortIsOutput;
     const JackProcessCallback callback = iscapture ? jackProcessCaptureCallback : jackProcessPlaybackCallback;
diff --git a/src/audio/nacl/SDL_naclaudio.c b/src/audio/nacl/SDL_naclaudio.c
index 9d698adc694..14fcf9da0d0 100644
--- a/src/audio/nacl/SDL_naclaudio.c
+++ b/src/audio/nacl/SDL_naclaudio.c
@@ -99,7 +99,7 @@ static void NACLAUDIO_CloseDevice(SDL_AudioDevice *device) {
 }
 
 static int
-NACLAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture) {
+NACLAUDIO_OpenDevice(_THIS, void *handle, const char *devname) {
     PP_Instance instance = PSGetInstanceId();
     const PPB_Audio *ppb_audio = PSInterfaceAudio();
     const PPB_AudioConfig *ppb_audiocfg = PSInterfaceAudioConfig();
diff --git a/src/audio/nas/SDL_nasaudio.c b/src/audio/nas/SDL_nasaudio.c
index d19c150e6ee..a6ef419b38c 100644
--- a/src/audio/nas/SDL_nasaudio.c
+++ b/src/audio/nas/SDL_nasaudio.c
@@ -331,10 +331,11 @@ find_device(_THIS)
 }
 
 static int
-NAS_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+NAS_OpenDevice(_THIS, void *handle, const char *devname)
 {
     AuElement elms[3];
     int buffer_size;
+    SDL_bool iscapture = this->iscapture;
     SDL_AudioFormat test_format, format;
 
     /* Initialize all variables that we clean on shutdown */
diff --git a/src/audio/netbsd/SDL_netbsdaudio.c b/src/audio/netbsd/SDL_netbsdaudio.c
index 2a62f943d82..13556b78365 100644
--- a/src/audio/netbsd/SDL_netbsdaudio.c
+++ b/src/audio/netbsd/SDL_netbsdaudio.c
@@ -202,8 +202,9 @@ NETBSDAUDIO_CloseDevice(_THIS)
 }
 
 static int
-NETBSDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+NETBSDAUDIO_OpenDevice(_THIS, void *handle, const char *devname)
 {
+    SDL_bool iscapture = this->iscapture;
     SDL_AudioFormat format = 0;
     audio_info_t info, hwinfo;
     struct audio_prinfo *prinfo = iscapture ? &info.record : &info.play;
diff --git a/src/audio/openslES/SDL_openslES.c b/src/audio/openslES/SDL_openslES.c
index e7743a5f7a4..d0c37697cea 100644
--- a/src/audio/openslES/SDL_openslES.c
+++ b/src/audio/openslES/SDL_openslES.c
@@ -583,14 +583,14 @@ openslES_CreatePCMPlayer(_THIS)
 }
 
 static int
-openslES_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+openslES_OpenDevice(_THIS, void *handle, const char *devname)
 {
     this->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, (sizeof *this->hidden));
     if (this->hidden == NULL) {
         return SDL_OutOfMemory();
     }
 
-    if (iscapture) {
+    if (this->iscapture) {
         LOGI("openslES_OpenDevice() %s for capture", devname);
         return openslES_CreatePCMRecorder(this);
     } else {
diff --git a/src/audio/os2/SDL_os2audio.c b/src/audio/os2/SDL_os2audio.c
index e8f431e33f8..9decfe9ab84 100644
--- a/src/audio/os2/SDL_os2audio.c
+++ b/src/audio/os2/SDL_os2audio.c
@@ -248,8 +248,7 @@ static void OS2_CloseDevice(_THIS)
     SDL_free(pAData);
 }
 
-static int OS2_OpenDevice(_THIS, void *handle, const char *devname,
-                          int iscapture)
+static int OS2_OpenDevice(_THIS, void *handle, const char *devname)
 {
     SDL_PrivateAudioData *pAData;
     SDL_AudioFormat       SDLAudioFmt;
@@ -258,6 +257,7 @@ static int OS2_OpenDevice(_THIS, void *handle, const char *devname,
     ULONG                 ulRC;
     ULONG                 ulIdx;
     BOOL                  new_freq;
+    SDL_bool              iscapture = _this->iscapture;
 
     new_freq = FALSE;
     SDL_zero(stMCIAmpOpen);
@@ -298,7 +298,7 @@ static int OS2_OpenDevice(_THIS, void *handle, const char *devname,
     }
     pAData->usDeviceId = stMCIAmpOpen.usDeviceID;
 
-    if (iscapture != 0) {
+    if (iscapture) {
         MCI_CONNECTOR_PARMS stMCIConnector;
         MCI_AMP_SET_PARMS   stMCIAmpSet;
         BOOL                fLineIn = _getEnvULong("SDL_AUDIO_LINEIN", 1, 0);
@@ -346,7 +346,7 @@ static int OS2_OpenDevice(_THIS, void *handle, const char *devname,
     pAData->stMCIMixSetup.ulSamplesPerSec = _this->spec.freq;
     pAData->stMCIMixSetup.ulChannels      = _this->spec.channels;
     pAData->stMCIMixSetup.ulDeviceType    = MCI_DEVTYPE_WAVEFORM_AUDIO;
-    if (iscapture == 0) {
+    if (!iscapture) {
         pAData->stMCIMixSetup.ulFormatMode= MCI_PLAY;
         pAData->stMCIMixSetup.pmixEvent   = cbAudioWriteEvent;
     } else {
diff --git a/src/audio/paudio/SDL_paudio.c b/src/audio/paudio/SDL_paudio.c
index b630ae9704b..aaadedae80f 100644
--- a/src/audio/paudio/SDL_paudio.c
+++ b/src/audio/paudio/SDL_paudio.c
@@ -223,7 +223,7 @@ PAUDIO_CloseDevice(_THIS)
 }
 
 static int
-PAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+PAUDIO_OpenDevice(_THIS, void *handle, const char *devname)
 {
     const char *workaround = SDL_getenv("SDL_DSP_NOSELECT");
     char audiodev[1024];
diff --git a/src/audio/pipewire/SDL_pipewire.c b/src/audio/pipewire/SDL_pipewire.c
index 893d0c4ee02..171c408491e 100644
--- a/src/audio/pipewire/SDL_pipewire.c
+++ b/src/audio/pipewire/SDL_pipewire.c
@@ -1027,7 +1027,7 @@ static const struct pw_stream_events stream_input_events  = { PW_VERSION_STREAM_
                                                              .process       = input_callback };
 
 static int
-PIPEWIRE_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+PIPEWIRE_OpenDevice(_THIS, void *handle, const char *devname)
 {
     /*
      * NOTE: The PW_STREAM_FLAG_RT_PROCESS flag can be set to call the stream
@@ -1048,6 +1048,7 @@ PIPEWIRE_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
     const char *                 app_name, *stream_name, *stream_role, *error;
     const Uint32                 node_id = this->handle == NULL ? PW_ID_ANY : PW_HANDLE_TO_ID(this->handle);
     enum pw_stream_state         state;
+    SDL_bool                     iscapture = this->iscapture;
     int                          res;
 
     /* Clamp the period size to sane values */
diff --git a/src/audio/psp/SDL_pspaudio.c b/src/audio/psp/SDL_pspaudio.c
index cbceaf40ca4..25ef44282bc 100644
--- a/src/audio/psp/SDL_pspaudio.c
+++ b/src/audio/psp/SDL_pspaudio.c
@@ -42,7 +42,7 @@
 #define PSPAUDIO_DRIVER_NAME    "psp"
 
 static int
-PSPAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+PSPAUDIO_OpenDevice(_THIS, void *handle, const char *devname)
 {
     int format, mixlen, i;
 
diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c
index dfa38d04413..07825d08e6d 100644
--- a/src/audio/pulseaudio/SDL_pulseaudio.c
+++ b/src/audio/pulseaudio/SDL_pulseaudio.c
@@ -522,7 +522,7 @@ SourceDeviceNameCallback(pa_context *c, const pa_source_info *i, int is_last, vo
 }
 
 static SDL_bool
-FindDeviceName(struct SDL_PrivateAudioData *h, const int iscapture, void *handle)
+FindDeviceName(struct SDL_PrivateAudioData *h, const SDL_bool iscapture, void *handle)
 {
     const uint32_t idx = ((uint32_t) ((size_t) handle)) - 1;
 
@@ -544,7 +544,7 @@ FindDeviceName(struct SDL_PrivateAudioData *h, const int iscapture, void *handle
 }
 
 static int
-PULSEAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+PULSEAUDIO_OpenDevice(_THIS, void *handle, const char *devname)
 {
     struct SDL_PrivateAudioData *h = NULL;
     Uint16 test_format = 0;
@@ -553,6 +553,7 @@ PULSEAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
     pa_channel_map pacmap;
     pa_stream_flags_t flags = 0;
     const char *name = NULL;
+    SDL_bool iscapture = this->iscapture;
     int state = 0;
     int rc = 0;
 
diff --git a/src/audio/qsa/SDL_qsa_audio.c b/src/audio/qsa/SDL_qsa_audio.c
index ca439079769..b2a864c26f6 100644
--- a/src/audio/qsa/SDL_qsa_audio.c
+++ b/src/audio/qsa/SDL_qsa_audio.c
@@ -121,7 +121,7 @@ QSA_WaitDevice(_THIS)
     /* For example, Vortex 8820 audio driver stucks on second DAC because */
     /* it doesn't exist !                                                 */
     result = SDL_IOReady(this->hidden->audio_fd,
-                         this->hidden->iscapture ? SDL_IOR_READ : SDL_IOR_WRITE,
+                         this->iscapture ? SDL_IOR_READ : SDL_IOR_WRITE,
                          2 * 1000);
     switch (result) {
     case -1:
@@ -180,7 +180,7 @@ QSA_PlayDevice(_THIS)
             } else {
                 if ((errno == EINVAL) || (errno == EIO)) {
                     SDL_zero(cstatus);
-                    if (!this->hidden->iscapture) {
+                    if (!this->iscapture) {
                         cstatus.channel = SND_PCM_CHANNEL_PLAYBACK;
                     } else {
                         cstatus.channel = SND_PCM_CHANNEL_CAPTURE;
@@ -196,7 +196,7 @@ QSA_PlayDevice(_THIS)
 
                     if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) ||
                         (cstatus.status == SND_PCM_STATUS_READY)) {
-                        if (!this->hidden->iscapture) {
+                        if (!this->iscapture) {
                             status =
                                 snd_pcm_plugin_prepare(this->hidden->
                                                        audio_handle,
@@ -240,7 +240,7 @@ static void
 QSA_CloseDevice(_THIS)
 {
     if (this->hidden->audio_handle != NULL) {
-        if (!this->hidden->iscapture) {
+        if (!this->iscapture) {
             /* Finish playing available samples */
             snd_pcm_plugin_flush(this->hidden->audio_handle,
                                  SND_PCM_CHANNEL_PLAYBACK);
@@ -257,9 +257,10 @@ QSA_CloseDevice(_THIS)
 }
 
 static int
-QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+QSA_OpenDevice(_THIS, void *handle, const char *devname)
 {
     const QSA_Device *device = (const QSA_Device *) handle;
+    SDL_Bool iscapture = this->iscapture;
     int status = 0;
     int format = 0;
     SDL_AudioFormat test_format = 0;
@@ -280,9 +281,6 @@ QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
     /* Initialize channel transfer parameters to default */
     QSA_InitAudioParams(&cparams);
 
-    /* Initialize channel direction: capture or playback */
-    this->hidden->iscapture = iscapture ? SDL_TRUE : SDL_FALSE;
-
     if (device != NULL) {
         /* Open requested audio device */
         this->hidden->deviceno = device->deviceno;
@@ -407,7 +405,7 @@ QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
 
     /* Make sure channel is setup right one last time */
     SDL_zero(csetup);
-    if (!this->hidden->iscapture) {
+    if (!this->iscapture) {
         csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
     } else {
         csetup.channel = SND_PCM_CHANNEL_CAPTURE;
@@ -443,7 +441,7 @@ QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
                this->hidden->pcm_len);
 
     /* get the file descriptor */
-    if (!this->hidden->iscapture) {
+    if (!this->iscapture) {
         this->hidden->audio_fd =
             snd_pcm_file_descriptor(this->hidden->audio_handle,
                                     SND_PCM_CHANNEL_PLAYBACK);
@@ -458,7 +456,7 @@ QSA_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
     }
 
     /* Prepare an audio channel */
-    if (!this->hidden->iscapture) {
+    if (!this->iscapture) {
         /* Prepare audio playback */
         status =
             snd_pcm_plugin_prepare(this->hidden->audio_handle,
diff --git a/src/audio/qsa/SDL_qsa_audio.h b/src/audio/qsa/SDL_qsa_audio.h
index 7f5e9d3a462..e4845c9eb1e 100644
--- a/src/audio/qsa/SDL_qsa_audio.h
+++ b/src/audio/qsa/SDL_qsa_audio.h
@@ -33,9 +33,6 @@
 
 struct SDL_PrivateAudioData
 {
-    /* SDL capture state */
-    SDL_bool iscapture;
-
     /* The audio device handle */
     int cardno;
     int deviceno;
diff --git a/src/audio/sndio/SDL_sndioaudio.c b/src/audio/sndio/SDL_sndioaudio.c
index 4656f378bf0..9dc53d44b55 100644
--- a/src/audio/sndio/SDL_sndioaudio.c
+++ b/src/audio/sndio/SDL_sndioaudio.c
@@ -237,10 +237,11 @@ SNDIO_CloseDevice(_THIS)
 }
 
 static int
-SNDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+SNDIO_OpenDevice(_THIS, void *handle, const char *devname)
 {
     SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
     struct sio_par par;
+    SDL_bool iscapture = this->iscapture;
     int status;
 
     this->hidden = (struct SDL_PrivateAudioData *)
diff --git a/src/audio/sun/SDL_sunaudio.c b/src/audio/sun/SDL_sunaudio.c
index 7a461d20752..f2680ebc34e 100644
--- a/src/audio/sun/SDL_sunaudio.c
+++ b/src/audio/sun/SDL_sunaudio.c
@@ -188,11 +188,12 @@ SUNAUDIO_CloseDevice(_THIS)
 }
 
 static int
-SUNAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+SUNAUDIO_OpenDevice(_THIS, void *handle, const char *devname)
 {
 #ifdef AUDIO_SETINFO
     int enc;
 #endif
+    SDL_bool iscapture = this->iscapture;
     int desired_freq = 0;
     const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
     SDL_AudioFormat format = 0;
diff --git a/src/audio/vita/SDL_vitaaudio.c b/src/audio/vita/SDL_vitaaudio.c
index 62b4a39e8b4..8dd54e28da1 100644
--- a/src/audio/vita/SDL_vitaaudio.c
+++ b/src/audio/vita/SDL_vitaaudio.c
@@ -45,7 +45,7 @@
 #define VITAAUD_DRIVER_NAME     "vita"
 
 static int
-VITAAUD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+VITAAUD_OpenDevice(_THIS, void *handle, const char *devname)
 {
     int format, mixlen, i, port = SCE_AUDIO_OUT_PORT_TYPE_MAIN;
     int vols[2] = {SCE_AUDIO_MAX_VOLUME, SCE_AUDIO_MAX_VOLUME};
diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c
index d80ecf622bc..bfb82f0b177 100644
--- a/src/audio/wasapi/SDL_wasapi.c
+++ b/src/audio/wasapi/SDL_wasapi.c
@@ -641,7 +641,7 @@ WASAPI_PrepDevice(_THIS, const SDL_bool updatestream)
 
 
 static int
-WASAPI_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+WASAPI_OpenDevice(_THIS, void *handle, const char *devname)
 {
     LPCWSTR devid = (LPCWSTR) handle;
 
@@ -656,7 +656,7 @@ WASAPI_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
     WASAPI_RefDevice(this);   /* so CloseDevice() will unref to zero. */
 
     if (!devid) {  /* is default device? */
-        this->hidden->default_device_generation = SDL_AtomicGet(iscapture ? &WASAPI_DefaultCaptureGeneration : &WASAPI_DefaultPlaybackGeneration);
+        this->hidden->default_device_generation = SDL_AtomicGet(this->iscapture ? &WASAPI_DefaultCaptureGeneration : &WASAPI_DefaultPlaybackGeneration);
     } else {
         this->hidden->devid = SDL_wcsdup(devid);
         if (!this->hidden->devid) {
diff --git a/src/audio/winmm/SDL_winmm.c b/src/audio/winmm/SDL_winmm.c
index d74120a6c1a..e1baf0472cd 100644
--- a/src/audio/winmm/SDL_winmm.c
+++ b/src/audio/winmm/SDL_winmm.c
@@ -283,10 +283,10 @@ PrepWaveFormat(_THIS, UINT devId, WAVEFORMATEX *pfmt, const int iscapture)
 }
 
 static int
-WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+WINMM_OpenDevice(_THIS, void *handle, const char *devname)
 {
     SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
-    int valid_datatype = 0;
+    SDL_bool valid_datatype = SDL_FALSE, iscapture = this->iscapture;
     MMRESULT result;
     WAVEFORMATEX waveformat;
     UINT devId = WAVE_MAPPER;  /* WAVE_MAPPER == choose system's default */
@@ -321,7 +321,7 @@ WINMM_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
         case AUDIO_F32:
             this->spec.format = test_format;
             if (PrepWaveFormat(this, devId, &waveformat, iscapture)) {
-                valid_datatype = 1;
+                valid_datatype = SDL_TRUE;
             } else {
                 test_format = SDL_NextAudioFormat();
             }