summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierce Brooks <piercebrooks@rocketmail.com>2023-12-08 03:14:58 -0500
committerRémi Verschelde <rverschelde@gmail.com>2024-07-30 17:20:46 +0200
commite3482a933642210d96ad2865c57051bdae090f83 (patch)
tree19ad115f81e3e3ff160990f1908f0e39ad201620
parent3e0c10d3931afb62a30f26532a9f7709ee68bf2c (diff)
downloadredot-engine-e3482a933642210d96ad2865c57051bdae090f83.tar.gz
Android: Ensure cleanup of all subobjects in the OpenSL audio driver
-rw-r--r--platform/android/audio_driver_opensl.cpp35
-rw-r--r--platform/android/audio_driver_opensl.h18
2 files changed, 42 insertions, 11 deletions
diff --git a/platform/android/audio_driver_opensl.cpp b/platform/android/audio_driver_opensl.cpp
index 51e89c720d..ef9c51db07 100644
--- a/platform/android/audio_driver_opensl.cpp
+++ b/platform/android/audio_driver_opensl.cpp
@@ -268,6 +268,10 @@ Error AudioDriverOpenSL::init_input_device() {
}
Error AudioDriverOpenSL::input_start() {
+ if (recordItf || recordBufferQueueItf) {
+ return ERR_ALREADY_IN_USE;
+ }
+
if (OS::get_singleton()->request_permission("RECORD_AUDIO")) {
return init_input_device();
}
@@ -277,6 +281,10 @@ Error AudioDriverOpenSL::input_start() {
}
Error AudioDriverOpenSL::input_stop() {
+ if (!recordItf || !recordBufferQueueItf) {
+ return ERR_CANT_OPEN;
+ }
+
SLuint32 state;
SLresult res = (*recordItf)->GetRecordState(recordItf, &state);
ERR_FAIL_COND_V(res != SL_RESULT_SUCCESS, ERR_CANT_OPEN);
@@ -313,13 +321,36 @@ void AudioDriverOpenSL::unlock() {
}
void AudioDriverOpenSL::finish() {
- (*sl)->Destroy(sl);
+ if (recordItf) {
+ (*recordItf)->SetRecordState(recordItf, SL_RECORDSTATE_STOPPED);
+ recordItf = nullptr;
+ }
+ if (recorder) {
+ (*recorder)->Destroy(recorder);
+ recorder = nullptr;
+ }
+ if (playItf) {
+ (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED);
+ playItf = nullptr;
+ }
+ if (player) {
+ (*player)->Destroy(player);
+ player = nullptr;
+ }
+ if (OutputMix) {
+ (*OutputMix)->Destroy(OutputMix);
+ OutputMix = nullptr;
+ }
+ if (sl) {
+ (*sl)->Destroy(sl);
+ sl = nullptr;
+ }
}
void AudioDriverOpenSL::set_pause(bool p_pause) {
pause = p_pause;
- if (active) {
+ if (active && playItf) {
if (pause) {
(*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PAUSED);
} else {
diff --git a/platform/android/audio_driver_opensl.h b/platform/android/audio_driver_opensl.h
index 6ea0f77def..bcd173826a 100644
--- a/platform/android/audio_driver_opensl.h
+++ b/platform/android/audio_driver_opensl.h
@@ -54,15 +54,15 @@ class AudioDriverOpenSL : public AudioDriver {
Vector<int16_t> rec_buffer;
- SLPlayItf playItf;
- SLRecordItf recordItf;
- SLObjectItf sl;
- SLEngineItf EngineItf;
- SLObjectItf OutputMix;
- SLObjectItf player;
- SLObjectItf recorder;
- SLAndroidSimpleBufferQueueItf bufferQueueItf;
- SLAndroidSimpleBufferQueueItf recordBufferQueueItf;
+ SLPlayItf playItf = nullptr;
+ SLRecordItf recordItf = nullptr;
+ SLObjectItf sl = nullptr;
+ SLEngineItf EngineItf = nullptr;
+ SLObjectItf OutputMix = nullptr;
+ SLObjectItf player = nullptr;
+ SLObjectItf recorder = nullptr;
+ SLAndroidSimpleBufferQueueItf bufferQueueItf = nullptr;
+ SLAndroidSimpleBufferQueueItf recordBufferQueueItf = nullptr;
SLDataSource audioSource;
SLDataFormat_PCM pcm;
SLDataSink audioSink;