From 3ab152afb3a0d86c32b8114cee260f210b2d0f46 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 28 Jan 2026 16:33:30 +1000 Subject: [PATCH] audio(4): Failed context initialization if /dev/audioctl does not exist. This allows initialization to abort at an earlier stage which gives the fallback logic a chance to try a different backend. --- miniaudio.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index b87fc431..9d63253d 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -41181,7 +41181,17 @@ static ma_result ma_context_init__audio4(ma_context* pContext, const void* pCont const ma_context_config_audio4* pContextConfigAudio4 = (const ma_context_config_audio4*)pContextBackendConfig; ma_context_config_audio4 defaultConfigAudio4; - + /* Check if /dev/audioctl actually exists. If not, the backend cannot be used. */ + #if !defined(MA_AUDIO4_USE_NEW_API) /* Old API */ + { + struct stat stDefault; + + if (stat("/dev/audioctl", &stDefault) < 0) { + ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[audio4] Failed to open /dev/audioctl. Backend not usable."); + return MA_NO_BACKEND; + } + } + #endif if (pContextConfigAudio4 == NULL) { defaultConfigAudio4 = ma_context_config_audio4_init(); @@ -41578,11 +41588,6 @@ static ma_result ma_context_enumerate_devices__audio4(ma_context* pContext, ma_e int iDevice; struct stat stDefault; - if (stat("/dev/audioctl", &stDefault) < 0) { - ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_ERROR, "[audio4] Failed to open /dev/audioctl. Backend not usable."); - return MA_NO_BACKEND; - } - /* Every device will be named "/dev/audioN", with a "/dev/audioctlN" equivalent. We use the "/dev/audioctlN" version here since we can open it even when another process has control of the "/dev/audioN" device.