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

OpenSL ES buffer callbacks on Android #8

Closed
wants to merge 3 commits into from
Closed

OpenSL ES buffer callbacks on Android #8

wants to merge 3 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Apr 20, 2015

On some Android implementations of OpenSL ES the playback buffer callback can be called even after playback was stopped. This can lead to a crash when a callback happens after the buffer was freed. I could observe this behavior using the Android Emulator with API 17 and on a real device running API 19.

The Android NDK docs on OpenSL mention a similar behavior:

A corollary is that it is unspecified whether buffer queue callbacks are called upon transition to SL_PLAYSTATE_STOPPED or by BufferQueue::Clear. We recommend that you do not rely on either behavior; be prepared to receive a callback in these cases, but also do not depend on receiving one.

To prevent this crash I changed the OpenSL ES back-end to free the buffer only after the buffer queue object was destroyed. I also moved the buffer allocation from the start to the reset function. With these changes I could not observer any further crashes.

@kcat
Copy link
Owner

kcat commented Apr 20, 2015

The changes look okay, but if OpenSL allows the callback to be called after playback was stopped, that's a bigger problem that needs to be fixed. OpenAL Soft assumes its aluMixData function (which is called in the callback to mix audio) won't be called after the stop method returns. In particular, it's going to be changing the device properties, reallocating mixer buffers, calling reset, and calling start without the device lock, so the callback must be finished and must not be invoked anymore once opensl_stop_playback returns.

@ghost ghost mentioned this pull request Apr 21, 2015
@ghost
Copy link
Author

ghost commented Apr 21, 2015

I see, in that case this is not really a good solution. I created a new pull request (#9) with an alternate solution.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants