SDL: Android: audio change audio assert when try to open concurrent device to a real error

From 407b85c5060b5981bb9ef18079d526e93c95d39d Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Tue, 4 Apr 2023 09:40:57 +0200
Subject: [PATCH] Android: audio change audio assert when try to open
 concurrent device to a real error

---
 src/audio/aaudio/SDL_aaudio.c        | 13 +++++++++++--
 src/audio/android/SDL_androidaudio.c | 13 +++++++++++--
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/audio/aaudio/SDL_aaudio.c b/src/audio/aaudio/SDL_aaudio.c
index 9be669ab75c3..693b5a98cd60 100644
--- a/src/audio/aaudio/SDL_aaudio.c
+++ b/src/audio/aaudio/SDL_aaudio.c
@@ -75,8 +75,17 @@ static int aaudio_OpenDevice(_THIS, const char *devname)
     aaudio_result_t res;
     LOGI(__func__);
 
-    SDL_assert((captureDevice == NULL) || !iscapture);
-    SDL_assert((audioDevice == NULL) || iscapture);
+    if (iscapture) {
+        if (captureDevice) {
+            return SDL_SetError("An audio capture device is already opened");
+        }
+    }
+
+    if (!iscapture) {
+        if (audioDevice) {
+            return SDL_SetError("An audio playback device is already opened");
+        }
+    }
 
     if (iscapture) {
         if (!Android_JNI_RequestPermission("android.permission.RECORD_AUDIO")) {
diff --git a/src/audio/android/SDL_androidaudio.c b/src/audio/android/SDL_androidaudio.c
index 33265964f95e..93ba21664170 100644
--- a/src/audio/android/SDL_androidaudio.c
+++ b/src/audio/android/SDL_androidaudio.c
@@ -40,8 +40,17 @@ static int ANDROIDAUDIO_OpenDevice(_THIS, const char *devname)
     SDL_AudioFormat test_format;
     SDL_bool iscapture = this->iscapture;
 
-    SDL_assert((captureDevice == NULL) || !iscapture);
-    SDL_assert((audioDevice == NULL) || iscapture);
+    if (iscapture) {
+        if (captureDevice) {
+            return SDL_SetError("An audio capture device is already opened");
+        }
+    }
+
+    if (!iscapture) {
+        if (audioDevice) {
+            return SDL_SetError("An audio playback device is already opened");
+        }
+    }
 
     if (iscapture) {
         captureDevice = this;