@@ -268,6 +268,10 @@ Error AudioDriverOpenSL::init_input_device() {
268268}
269269
270270Error AudioDriverOpenSL::input_start () {
271+ if (recordItf || recordBufferQueueItf) {
272+ return ERR_ALREADY_IN_USE;
273+ }
274+
271275 if (OS::get_singleton ()->request_permission (" RECORD_AUDIO" )) {
272276 return init_input_device ();
273277 }
@@ -277,6 +281,10 @@ Error AudioDriverOpenSL::input_start() {
277281}
278282
279283Error AudioDriverOpenSL::input_stop () {
284+ if (!recordItf || !recordBufferQueueItf) {
285+ return ERR_CANT_OPEN;
286+ }
287+
280288 SLuint32 state;
281289 SLresult res = (*recordItf)->GetRecordState (recordItf, &state);
282290 ERR_FAIL_COND_V (res != SL_RESULT_SUCCESS, ERR_CANT_OPEN);
@@ -313,13 +321,36 @@ void AudioDriverOpenSL::unlock() {
313321}
314322
315323void AudioDriverOpenSL::finish () {
316- (*sl)->Destroy (sl);
324+ if (recordItf) {
325+ (*recordItf)->SetRecordState (recordItf, SL_RECORDSTATE_STOPPED);
326+ recordItf = nullptr ;
327+ }
328+ if (recorder) {
329+ (*recorder)->Destroy (recorder);
330+ recorder = nullptr ;
331+ }
332+ if (playItf) {
333+ (*playItf)->SetPlayState (playItf, SL_PLAYSTATE_STOPPED);
334+ playItf = nullptr ;
335+ }
336+ if (player) {
337+ (*player)->Destroy (player);
338+ player = nullptr ;
339+ }
340+ if (OutputMix) {
341+ (*OutputMix)->Destroy (OutputMix);
342+ OutputMix = nullptr ;
343+ }
344+ if (sl) {
345+ (*sl)->Destroy (sl);
346+ sl = nullptr ;
347+ }
317348}
318349
319350void AudioDriverOpenSL::set_pause (bool p_pause) {
320351 pause = p_pause;
321352
322- if (active) {
353+ if (active && playItf ) {
323354 if (pause) {
324355 (*playItf)->SetPlayState (playItf, SL_PLAYSTATE_PAUSED);
325356 } else {
0 commit comments