From 2407933fb8c34e9ee02181a97a96aecbac4fe6f4 Mon Sep 17 00:00:00 2001 From: David Reid Date: Mon, 17 Dec 2018 20:27:54 +1000 Subject: [PATCH] Add some asserts and validation checks to the OpenSL backend. --- mini_al.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/mini_al.h b/mini_al.h index 813126a3..005bfa10 100644 --- a/mini_al.h +++ b/mini_al.h @@ -18021,6 +18021,11 @@ mal_result mal_context_enumerate_devices__opensl(mal_context* pContext, mal_enum mal_assert(pContext != NULL); mal_assert(callback != NULL); + mal_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it and then attempted to enumerate devices. */ + if (g_malOpenSLInitCounter == 0) { + return MAL_INVALID_OPERATION; + } + // TODO: Test Me. // // This is currently untested, so for now we are just returning default devices. @@ -18121,6 +18126,11 @@ mal_result mal_context_get_device_info__opensl(mal_context* pContext, mal_device mal_assert(pContext != NULL); (void)shareMode; + mal_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it and then attempted to get device info. */ + if (g_malOpenSLInitCounter == 0) { + return MAL_INVALID_OPERATION; + } + // TODO: Test Me. // // This is currently untested, so for now we are just returning default devices. @@ -18248,6 +18258,11 @@ void mal_device_uninit__opensl(mal_device* pDevice) { mal_assert(pDevice != NULL); + mal_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it before uninitializing the device. */ + if (g_malOpenSLInitCounter == 0) { + return; + } + // Uninit device. if (pDevice->type == mal_device_type_playback) { if (pDevice->opensl.pAudioPlayerObj) { @@ -18269,6 +18284,11 @@ mal_result mal_device_init__opensl(mal_context* pContext, mal_device_type type, { (void)pContext; + mal_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it and then attempted to initialize a new device. */ + if (g_malOpenSLInitCounter == 0) { + return MAL_INVALID_OPERATION; + } + // For now, only supporting Android implementations of OpenSL|ES since that's the only one I've // been able to test with and I currently depend on Android-specific extensions (simple buffer // queues). @@ -18533,6 +18553,11 @@ mal_result mal_device__start_backend__opensl(mal_device* pDevice) { mal_assert(pDevice != NULL); + mal_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it and then attempted to start the device. */ + if (g_malOpenSLInitCounter == 0) { + return MAL_INVALID_OPERATION; + } + if (pDevice->type == mal_device_type_playback) { SLresult resultSL = MAL_OPENSL_PLAY(pDevice->opensl.pAudioPlayer)->SetPlayState((SLPlayItf)pDevice->opensl.pAudioPlayer, SL_PLAYSTATE_PLAYING); if (resultSL != SL_RESULT_SUCCESS) { @@ -18573,6 +18598,11 @@ mal_result mal_device__stop_backend__opensl(mal_device* pDevice) { mal_assert(pDevice != NULL); + mal_assert(g_malOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it before stopping/uninitializing the device. */ + if (g_malOpenSLInitCounter == 0) { + return MAL_INVALID_OPERATION; + } + if (pDevice->type == mal_device_type_playback) { SLresult resultSL = MAL_OPENSL_PLAY(pDevice->opensl.pAudioPlayer)->SetPlayState((SLPlayItf)pDevice->opensl.pAudioPlayer, SL_PLAYSTATE_STOPPED); if (resultSL != SL_RESULT_SUCCESS) {