mirror of https://github.com/godotengine/godot
Merge pull request #85955 from PierceLBrooks/plb/fix-opensl-audio-driver-closure
Android: Ensure cleanup of all subobjects in the OpenSL audio driver
This commit is contained in:
commit
f763962aed
|
|
@ -268,6 +268,10 @@ Error AudioDriverOpenSL::init_input_device() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Error AudioDriverOpenSL::input_start() {
|
Error AudioDriverOpenSL::input_start() {
|
||||||
|
if (recordItf || recordBufferQueueItf) {
|
||||||
|
return ERR_ALREADY_IN_USE;
|
||||||
|
}
|
||||||
|
|
||||||
if (OS::get_singleton()->request_permission("RECORD_AUDIO")) {
|
if (OS::get_singleton()->request_permission("RECORD_AUDIO")) {
|
||||||
return init_input_device();
|
return init_input_device();
|
||||||
}
|
}
|
||||||
|
|
@ -277,6 +281,10 @@ Error AudioDriverOpenSL::input_start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Error AudioDriverOpenSL::input_stop() {
|
Error AudioDriverOpenSL::input_stop() {
|
||||||
|
if (!recordItf || !recordBufferQueueItf) {
|
||||||
|
return ERR_CANT_OPEN;
|
||||||
|
}
|
||||||
|
|
||||||
SLuint32 state;
|
SLuint32 state;
|
||||||
SLresult res = (*recordItf)->GetRecordState(recordItf, &state);
|
SLresult res = (*recordItf)->GetRecordState(recordItf, &state);
|
||||||
ERR_FAIL_COND_V(res != SL_RESULT_SUCCESS, ERR_CANT_OPEN);
|
ERR_FAIL_COND_V(res != SL_RESULT_SUCCESS, ERR_CANT_OPEN);
|
||||||
|
|
@ -313,13 +321,36 @@ void AudioDriverOpenSL::unlock() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioDriverOpenSL::finish() {
|
void AudioDriverOpenSL::finish() {
|
||||||
|
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)->Destroy(sl);
|
||||||
|
sl = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioDriverOpenSL::set_pause(bool p_pause) {
|
void AudioDriverOpenSL::set_pause(bool p_pause) {
|
||||||
pause = p_pause;
|
pause = p_pause;
|
||||||
|
|
||||||
if (active) {
|
if (active && playItf) {
|
||||||
if (pause) {
|
if (pause) {
|
||||||
(*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PAUSED);
|
(*playItf)->SetPlayState(playItf, SL_PLAYSTATE_PAUSED);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -54,15 +54,15 @@ class AudioDriverOpenSL : public AudioDriver {
|
||||||
|
|
||||||
Vector<int16_t> rec_buffer;
|
Vector<int16_t> rec_buffer;
|
||||||
|
|
||||||
SLPlayItf playItf;
|
SLPlayItf playItf = nullptr;
|
||||||
SLRecordItf recordItf;
|
SLRecordItf recordItf = nullptr;
|
||||||
SLObjectItf sl;
|
SLObjectItf sl = nullptr;
|
||||||
SLEngineItf EngineItf;
|
SLEngineItf EngineItf = nullptr;
|
||||||
SLObjectItf OutputMix;
|
SLObjectItf OutputMix = nullptr;
|
||||||
SLObjectItf player;
|
SLObjectItf player = nullptr;
|
||||||
SLObjectItf recorder;
|
SLObjectItf recorder = nullptr;
|
||||||
SLAndroidSimpleBufferQueueItf bufferQueueItf;
|
SLAndroidSimpleBufferQueueItf bufferQueueItf = nullptr;
|
||||||
SLAndroidSimpleBufferQueueItf recordBufferQueueItf;
|
SLAndroidSimpleBufferQueueItf recordBufferQueueItf = nullptr;
|
||||||
SLDataSource audioSource;
|
SLDataSource audioSource;
|
||||||
SLDataFormat_PCM pcm;
|
SLDataFormat_PCM pcm;
|
||||||
SLDataSink audioSink;
|
SLDataSink audioSink;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue