From a0cb079a4225340fab594fcb4346a22453af0f26 Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Sun, 21 Nov 2021 15:45:08 +0100
Subject: [PATCH] Fixed bug #4982 - Failed to open audio_device on OpenSLES /
Android 5.x with freq 96khz+
---
src/audio/openslES/SDL_openslES.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/audio/openslES/SDL_openslES.c b/src/audio/openslES/SDL_openslES.c
index ae0f6a62a6d..f888d2ac2e0 100644
--- a/src/audio/openslES/SDL_openslES.c
+++ b/src/audio/openslES/SDL_openslES.c
@@ -579,7 +579,7 @@ openslES_CreatePCMPlayer(_THIS)
failed:
- return SDL_SetError("Open device failed!");
+ return -1;
}
static int
@@ -594,8 +594,24 @@ openslES_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
LOGI("openslES_OpenDevice() %s for capture", devname);
return openslES_CreatePCMRecorder(this);
} else {
+ int ret;
LOGI("openslES_OpenDevice() %s for playing", devname);
- return openslES_CreatePCMPlayer(this);
+ ret = openslES_CreatePCMPlayer(this);
+ if (ret < 0) {
+ /* Another attempt to open the device with a lower frequency */
+ if (this->spec.freq > 48000) {
+ openslES_DestroyPCMPlayer(this);
+ this->spec.freq = 48000;
+ ret = openslES_CreatePCMPlayer(this);
+ }
+ }
+
+ if (ret == 0) {
+ return 0;
+ } else {
+ return SDL_SetError("Open device failed!");
+ }
+
}
}