google / oboe

Oboe is a C++ library that makes it easy to build high-performance audio apps on Android.
Apache License 2.0
3.71k stars 569 forks source link

AAudioStream_close crashes on Android 8.1 #361

Closed loongee closed 4 years ago

loongee commented 5 years ago

It's a crash on the same app as I mentioned in #359

When DISCONNECT event raised, the error handler calls close() but close() crashed.

devices: VIVO X9s/ VIVO X20 / HUAWEI Mate 10 / Meizu 16 / etc. OS: Android 8.1 (Android 9 does not crash at all) oboe version: 1.1.1

crash rate: about 5 times / 1000 users per day.

backtrace as follows:

SIGABRT:

00 pc 0001a794 /system/lib/libc.so (abort+63) [armeabi-v7a::2a4f9449d26c102eb3273056d9f69245]

01 pc 000065ab /system/lib/liblog.so (__android_log_assert+158) [armeabi-v7a::067eccbd48c13902e69ef050b36bf01c]

02 pc 0001248f /system/lib/libaaudio.so (_ZN6aaudio11AudioStreamD1Ev+110) [armeabi-v7a::9b0e6a17c09bd1322e800f7b4913ddb7]

03 pc 00013ef5 /system/lib/libaaudio.so (_ZN6aaudio16AudioStreamTrackD0Ev+2) [armeabi-v7a::9b0e6a17c09bd1322e800f7b4913ddb7]

04 pc 00012ecb /system/lib/libaaudio.so (AAudioStream_close+42) [armeabi-v7a::9b0e6a17c09bd1322e800f7b4913ddb7]

05 pc 003a95df /data/app/com.tencent.qgame-f89jxGbwruadjLNPIpPpvw==/lib/arm/libqgplayer-lib.so (_ZN4oboe17AudioStreamAAudio5closeEv+62) [armeabi-v7a::de1dfbeb99205ca392b18fc844c4926b]

06 pc 003a9cdf /data/app/com.tencent.qgame-f89jxGbwruadjLNPIpPpvw==/lib/arm/libqgplayer-lib.so [armeabi-v7a::de1dfbeb99205ca392b18fc844c4926b]

07 pc 003a9db7 /data/app/com.tencent.qgame-f89jxGbwruadjLNPIpPpvw==/lib/arm/libqgplayer-lib.so (_ZNSt6ndk114thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEPFvPN4oboe17AudioStreamAAudioEP18AAudioStreamStructNS7_6ResultEES9_SB_SCEEEEEPvSG+30) [armeabi-v7a::de1dfbeb99205ca392b18fc844c4926b]

08 pc 0004749f /system/lib/libc.so (_ZL15__pthread_startPv+22) [armeabi-v7a::2a4f9449d26c102eb3273056d9f69245]

09 pc 0001b259 /system/lib/libc.so (__start_thread+32) [armeabi-v7a::2a4f9449d26c102eb3273056d9f69245]

log:

01-21 22:11:37.846 2784 4469 D AudioStreamLegacy: onAudioDeviceUpdate() deviceId 2 01-21 22:11:37.846 2784 4469 D AudioStreamLegacy: onAudioDeviceUpdate() DISCONNECT the stream now 01-21 22:11:37.847 2784 21566 D AAudio : AAudioStream_requestStop(0xc8c24300) 01-21 22:11:37.847 2784 21566 D : PlayerBase::stop() from IPlayer 01-21 22:11:37.847 2784 21566 D AudioTrack: stop() called with 11539204 frames delivered 01-21 22:11:37.848 2784 21566 D AAudio : AAudioStream_close(0xc8c24300) 01-21 22:11:37.848 2784 21566 V AudioTrack: ~AudioTrack, releasing session id 37097 from 2784 on behalf of 2784 01-21 22:11:37.848 2784 21566 D AAudioStream: destroying 0xc8c24300, state = AAUDIO_STREAM_STATE_STOPPED 01-21 22:11:37.848 2784 21566 F AAudioStream: aaudio stream still in use, state = AAUDIO_STREAM_STATE_STOPPED

I believe it's a system bug, but also want you to know.

philburk commented 5 years ago

@loongee can you reproduce this in your office?

This message: "AAudioStream: aaudio stream still in use, state = AAUDIO_STREAM_STATE_STOPPED" is from "frameworks/av/media/libaaudio/src/core/AudioStream.cpp" The destructor asserts if the stream is still running.

So why is the stream in STOPPED state when the destructor is called?!

Is your app calling stop?

This change in PI prevented a stream from moving from the CLOSED state to the STOPPED state. https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/av/+/3790487/3/media/libaaudio/src/core/AudioStream.cpp#245

I believe it's a system bug, but also want you to know.

Me too. I also work on AAudio. So we will look in both Oboe and AAudio for the bug.

philburk commented 4 years ago

I believe this was fixed in P. I think it can be avoided by only calling stop() and close() from the same thread. Please reopen if you are still seeing this.