Android mediaPlayer -19 error caused by a AudioFlinger init -12 error with android 12

163 views Asked by At

I rarely ask questions since there is always a post somewhere explaining my issue but in this case I am running into a rabbit hole from where I am not able to get out alone. I had a tough time trying to understand what's happening with my app.

I am getting a -19 mediaPlayer's error that is undocumented. It was hard to reproduce since the bug happens only on devices using Android 12 and I had to order a Galaxy Tab sm-200 (the same as my customer) to be able to reproduce locally. Also the error happens only after several hours (sometimes up to 8 hours) of music playing.

The -19 mediaPlayer's error is the tip of the iceberg. After being able to get full logs locally it seems obvious that it is the consequence of a -12 audio_flinger error meaning no_memory.

I deep dived in the code and end up in the c++ android code https://cs.android.com/android/platform/superproject/+/master:frameworks/av/services/audioflinger/Tracks.cpp;l=254;drc=1d88712b5b9b5083266f14ceca0de45a8f9aaea7

I am actually releasing the players correctly and I don't understand why this memory leak.

When I play tracks in my app, I need to create one player, do a fade in and when the track is going to end, I start a new playing while I am fading out the volume of the current one. When the fade out is over I always release the player. I have to do that to get a crossfade between the tracks. I should never get more that 2 players (and audio tracks) instances concurrently. But it looks like, sometimes, the audio tracks persists in memory.

I can see it with the command adb shell dumpsys media.audio_flinger | ag 'are active' that can print for instance: 5 Tracks of which 5 are active while I can only have two tracks playing at the same time.

Also the audio tracks persist even if I close my app. Does someone understand this behaviour? Is it something that can be expected at some point?

I have also opened an issue to at least get more insight about the error: https://issuetracker.google.com/issues/256576769

Thank you all for the help and let me know if there is anything I can do.

Update: I confirm that the issue does not happen with Android 11: the audio track are correctly release and I always get 1 Tracks of which 1 are active with the command adb shell dumpsys media.audio_flinger | ag 'are active'

0

There are 0 answers