Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android openSLES mal_device_uninit deadlock #41

Closed
digitalgust opened this issue Dec 14, 2018 · 14 comments
Closed

Android openSLES mal_device_uninit deadlock #41

digitalgust opened this issue Dec 14, 2018 · 14 comments

Comments

@digitalgust
Copy link

init a playback mal_device , then playback audio success
but uninit the device encounter a deadlock:
deadlock at line.18250
if (pDevice->opensl.pAudioPlayerObj) MAL_OPENSL_OBJ(pDevice->opensl.pAudioPlayerObj)->Destroy((SLObjectItf)pDevice->opensl.pAudioPlayerObj);

12-15 02:09:27.078 30702-31005/org.minijvm.activity I/libOpenSLES: Emulating old channel mask behavior (ignoring positional mask 0x3, using default mask 0x3 based on channel count of 2)
12-15 02:09:27.084 30702-31005/org.minijvm.activity W/AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client; transfer 1, track 22050 Hz, output 48000 Hz
12-15 02:09:27.087 30702-31005/org.minijvm.activity D/AudioTrack: Client defaulted notificationFrames to 296 for frameCount 890
12-15 02:09:43.381 30702-31005/org.minijvm.activity E/libOpenSLES: Object::Destroy(0x7f68ba9000) for engine ignored; 2 total active objects
12-15 02:09:43.381 30702-31005/org.minijvm.activity E/libOpenSLES: Object::Destroy(0x7f68ba9000) for engine ignored; active object ID 2 at 0x7f68dd1000
12-15 02:09:43.381 30702-31005/org.minijvm.activity E/libOpenSLES: Object::Destroy(0x7f68ba9000) for engine ignored; active object ID 3 at 0x7f68a89c00
12-15 02:13:09.824 30702-31005/org.minijvm.activity E/libOpenSLES: frameworks/wilhelm/src/itf/IObject.c:556: pthread_mutex_lock_timeout_np returned 110
12-15 02:13:09.845 30702-31005/org.minijvm.activity E/libOpenSLES: frameworks/wilhelm/src/itf/IObject.c:556: pthread_mutex_lock_timeout_np returned 110
12-15 02:13:09.875 30702-31005/org.minijvm.activity E/libOpenSLES: frameworks/wilhelm/src/itf/IObject.c:556: pthread_mutex_lock_timeout_np returned 110
12-15 02:13:09.915 30702-31005/org.minijvm.activity E/libOpenSLES: frameworks/wilhelm/src/itf/IObject.c:556: pthread_mutex_lock_timeout_np returned 110
12-15 02:13:09.966 30702-31005/org.minijvm.activity E/libOpenSLES: frameworks/wilhelm/src/itf/IObject.c:556: pthread_mutex_lock_timeout_np returned 110
12-15 02:13:10.067 30702-31005/org.minijvm.activity E/libOpenSLES: frameworks/wilhelm/src/itf/IObject.c:556: pthread_mutex_lock_timeout_np returned 110
12-15 02:13:10.067 30702-31005/org.minijvm.activity W/libOpenSLES: frameworks/wilhelm/src/itf/IObject.c:556: pthread 0x7f6a27a450 (tid 31005) sees object 0x7f68ba9000 was locked by pthread 0x7f6a27a450 (tid 31005) at frameworks/wilhelm/src/itf/IObject.c:411

@mackron
Copy link
Owner

mackron commented Dec 14, 2018

What thread are you calling mal_device_uninit() from? What version of Android? Hardware or emulator?

EDIT: Is it happening consistently, or randomly?

@digitalgust
Copy link
Author

digitalgust commented Dec 15, 2018

both the last version of master and dev, Android 7.0 , Hardware , Xiaomi redmi , consistently.
last master line.18239
last dev line.18250

the log pthread 0x7f6a27a450 is the caller thread, a object locked by self ? or the mutexlock need a PTHREAD_MUTEX_RECURSIVE lock ?
or need call some functions to release the object

i found a android issue there:
https://grokbase.com/t/gg/android-ndk/156tayqf1c/opensl-deadlock-issue

https://groups.google.com/forum/#!searchin/android-ndk/deadlock/android-ndk/G7dLKAGGL28/xwlmjpdv2ssJ

@mackron
Copy link
Owner

mackron commented Dec 15, 2018

I'm not sure what's going on. This is the first report I've had with this. I'm wondering if it's something to do with the callback being running at the same time as Destroy() is called. Not 100% sure, though... Are you calling mal_device_uninit() from the same thread as the call to mal_device_init()? Also, make sure you're not calling it from the callback thread.

@mackron
Copy link
Owner

mackron commented Dec 15, 2018

Is it happening on any other devices or emulators?

@digitalgust
Copy link
Author

i have found lots of this issue of opensl, it's not mini_al issue , i create and destroy the device by same thread , and not call it from callback .
i test it only one device, let me test it from other device

@digitalgust
Copy link
Author

I test it in huawei 7x / android 8.0, same as xiaomi redmi4x, playback success, but when uninit device , it crash on libwilhelm.so(OpenSLES) pthread_mutex_trylock, error : SIGSEGV (signal SIGSEGV: invalid address (fault address: 0x55555555555591))
xiaomi redmi note4x : deadlock screenshot
image

@digitalgust
Copy link
Author

digitalgust commented Dec 17, 2018

Test in Xiaomi mi6 / Android 8.0, same as Xiaomi redmi note4x, deadlok.

seems ,it's not the random occue event and in less class of device , is there a solution to avoid openSLES issue?

@mackron
Copy link
Owner

mackron commented Dec 17, 2018

OpenSL|ES is the only supported backend for Android. An AAudio backend is planned, but this is only supported on later versions of Android.

This feels like a bug in mini_al somewhere. I will need to do a few experiments and get back to you.

@digitalgust
Copy link
Author

and i test in android emulator 7.0 (X86_64 without google api) ,it would deadlock too.

@mackron
Copy link
Owner

mackron commented Dec 17, 2018

OK something I just saw in your screenshot is that the variable g_malOpenSLInitCounter is set to 0. That means the mal_context object has either been uninitialized before uninitializing the device (you must uninitialize all devices before attempting to uninitialize the context) or you have not initialized the context at all. Can you please check that the context is not getting uninitialized before the device.

Some basic things to consider:

  • If you are using the onStop callback, make sure you're not uninitializing the context in onStop and then again outside of it.
  • Your tear down should look something like this:
mal_device_uninit(device); // <-- Must do this _before_ mal_context_uninit()
mal_context_uninit(context);

Meanwhile, I have pushed an update to the dev branch which checks for this and throws an assert. Can you please let me know what the outcome of that is?

@digitalgust
Copy link
Author

digitalgust commented Dec 17, 2018

Yes, it's my fault, i init mal_context before init mal_device , should be uninit mal_context after uninit mal_device , but before that , thank you point out the error .i changed that it's work. :) :) :)

@mackron
Copy link
Owner

mackron commented Dec 17, 2018

That's good to hear! So everything is working now?

@digitalgust
Copy link
Author

all ok, please close the thread.

@mackron
Copy link
Owner

mackron commented Dec 18, 2018

Great! Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants