mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-23 08:44:04 +02:00
Add some asserts and validation checks to the OpenSL backend.
This commit is contained in:
@@ -18021,6 +18021,11 @@ mal_result mal_context_enumerate_devices__opensl(mal_context* pContext, mal_enum
|
|||||||
mal_assert(pContext != NULL);
|
mal_assert(pContext != NULL);
|
||||||
mal_assert(callback != 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.
|
// TODO: Test Me.
|
||||||
//
|
//
|
||||||
// This is currently untested, so for now we are just returning default devices.
|
// 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);
|
mal_assert(pContext != NULL);
|
||||||
(void)shareMode;
|
(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.
|
// TODO: Test Me.
|
||||||
//
|
//
|
||||||
// This is currently untested, so for now we are just returning default devices.
|
// 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(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.
|
// Uninit device.
|
||||||
if (pDevice->type == mal_device_type_playback) {
|
if (pDevice->type == mal_device_type_playback) {
|
||||||
if (pDevice->opensl.pAudioPlayerObj) {
|
if (pDevice->opensl.pAudioPlayerObj) {
|
||||||
@@ -18269,6 +18284,11 @@ mal_result mal_device_init__opensl(mal_context* pContext, mal_device_type type,
|
|||||||
{
|
{
|
||||||
(void)pContext;
|
(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
|
// 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
|
// been able to test with and I currently depend on Android-specific extensions (simple buffer
|
||||||
// queues).
|
// queues).
|
||||||
@@ -18533,6 +18553,11 @@ mal_result mal_device__start_backend__opensl(mal_device* pDevice)
|
|||||||
{
|
{
|
||||||
mal_assert(pDevice != NULL);
|
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) {
|
if (pDevice->type == mal_device_type_playback) {
|
||||||
SLresult resultSL = MAL_OPENSL_PLAY(pDevice->opensl.pAudioPlayer)->SetPlayState((SLPlayItf)pDevice->opensl.pAudioPlayer, SL_PLAYSTATE_PLAYING);
|
SLresult resultSL = MAL_OPENSL_PLAY(pDevice->opensl.pAudioPlayer)->SetPlayState((SLPlayItf)pDevice->opensl.pAudioPlayer, SL_PLAYSTATE_PLAYING);
|
||||||
if (resultSL != SL_RESULT_SUCCESS) {
|
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(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) {
|
if (pDevice->type == mal_device_type_playback) {
|
||||||
SLresult resultSL = MAL_OPENSL_PLAY(pDevice->opensl.pAudioPlayer)->SetPlayState((SLPlayItf)pDevice->opensl.pAudioPlayer, SL_PLAYSTATE_STOPPED);
|
SLresult resultSL = MAL_OPENSL_PLAY(pDevice->opensl.pAudioPlayer)->SetPlayState((SLPlayItf)pDevice->opensl.pAudioPlayer, SL_PLAYSTATE_STOPPED);
|
||||||
if (resultSL != SL_RESULT_SUCCESS) {
|
if (resultSL != SL_RESULT_SUCCESS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user