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

ma_device_uninit crash on Android <= 10 #833

Open
alnitak opened this issue Mar 24, 2024 · 5 comments
Open

ma_device_uninit crash on Android <= 10 #833

alnitak opened this issue Mar 24, 2024 · 5 comments

Comments

@alnitak
Copy link

alnitak commented Mar 24, 2024

Hi, thanks for your amazing work!

I am developing a plugin with Flutter and I got crashes on Android devices and emulators with SDK <= 29.

Description:
I am using SoLoud c++ lib with miniaudio as the default audio backend.
On Android devices and emulators with SDK <= 29 (but not on Samsung Galaxy S9+ with Android 10 API 29), I get a crash when uninit the player. The relevant SoLoud source is here.

Seems related to AAudio and some buffers not freed, something similar to #466.
The crash occurs randomly when init-unint in a loop.
I tried also with the dev branch without luck.

FYI here is the plugin issue.
My workaround is to disable AAudio for SDK <= 29:

#if defined(__ANDROID__) && (__ANDROID_API__ <= 29)
#define MA_NO_AAUDIO
#endif

Hope I have given you all the info.
Thanks in advance for your time.

Here the error log with `MA_DEBUG_OUTPUT` and `MINIAUDIO_IMPLEMENTATION` defined

I/flutter (10278): [FINEST] flutter_soloud.SoLoud: init() called
I/flutter (10278): [FINEST] flutter_soloud.SoLoudLoader: initialize() called
I/flutter (10278): [FINE] flutter_soloud.SoLoudLoader: Loader has already been initialized. Not
I/flutter (10278): initializing again.
I/flutter (10278): [FINEST] flutter_soloud.SoLoud: _initEngine() called
D/miniaudio(10278): DEBUG: WASAPI backend is disabled.
D/miniaudio(10278): DEBUG: DirectSound backend is disabled.
D/miniaudio(10278): DEBUG: WinMM backend is disabled.
D/miniaudio(10278): DEBUG: Core Audio backend is disabled.
D/miniaudio(10278): DEBUG: sndio backend is disabled.
D/miniaudio(10278): DEBUG: audio(4) backend is disabled.
D/miniaudio(10278): DEBUG: OSS backend is disabled.
D/miniaudio(10278): DEBUG: PulseAudio backend is disabled.
D/miniaudio(10278): DEBUG: ALSA backend is disabled.
D/miniaudio(10278): DEBUG: JACK backend is disabled.
D/miniaudio(10278): DEBUG: Attempting to initialize AAudio backend...
D/miniaudio(10278): DEBUG: Loading library: libaaudio.so
D/miniaudio(10278): DEBUG: Loading symbol: AAudio_createStreamBuilder
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_delete
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setDeviceId
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setDirection
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setSharingMode
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setFormat
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setChannelCount
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setSampleRate
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setBufferCapacityInFrames
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setFramesPerDataCallback
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setDataCallback
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setErrorCallback
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setPerformanceMode
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setUsage
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setContentType
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setInputPreset
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_setAllowedCapturePolicy
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStreamBuilder_openStream
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_close
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_getState
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_waitForStateChange
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_getFormat
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_getChannelCount
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_getSampleRate
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_getBufferCapacityInFrames
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_getFramesPerDataCallback
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_getFramesPerBurst
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_requestStart
D/miniaudio(10278): DEBUG: Loading symbol: AAudioStream_requestStop
D/miniaudio(10278): DEBUG: System Architecture:
D/miniaudio(10278): DEBUG:   Endian: LE
D/miniaudio(10278): DEBUG:   SSE2:   NO
D/miniaudio(10278): DEBUG:   AVX2:   NO
D/miniaudio(10278): DEBUG:   NEON:   YES
I/AAudio  (10278): AAudioStreamBuilder_openStream() called ----------------------------------------
I/AudioStreamBuilder(10278): rate   =  44100, channels  = 2, format   = 5, sharing = SH, dir = OUTPUT
I/AudioStreamBuilder(10278): device =      0, sessionId = -1, perfMode = 12, callback: ON with frames = 2048
I/AudioStreamBuilder(10278): usage  =      0, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
D/        (10278): PlayerBase::PlayerBase()
D/AudioStreamTrack(10278): open(), request notificationFrames = 2048, frameCount = 6144
W/AudioTrack(10278): createTrack_l(111): AUDIO_OUTPUT_FLAG_FAST denied by server; frameCount 6144 -> 6144
W/AudioStreamTrack(10278): open() flags changed from 0x00000104 to 0x00000000
W/AudioStreamTrack(10278): open() perfMode changed from 12 to 10
I/AAudio  (10278): AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#9 ----------------
D/miniaudio(10278): INFO: [AAudio]
D/miniaudio(10278): INFO:    (Playback)
D/miniaudio(10278): INFO:     Format:      32-bit IEEE Floating Point -> 32-bit IEEE Floating Point
D/miniaudio(10278): INFO:     Channels:    2 -> 2
D/miniaudio(10278): INFO:     Sample Rate: 44100 -> 44100
D/miniaudio(10278): INFO:     Buffer Size: 2048*3 (6144)
D/miniaudio(10278): INFO:     Conversion:
D/miniaudio(10278): INFO:       Pre Format Conversion:  NO
D/miniaudio(10278): INFO:       Post Format Conversion: NO
D/miniaudio(10278): INFO:       Channel Routing:        NO
D/miniaudio(10278): INFO:       Resampling:             NO
D/miniaudio(10278): INFO:       Passthrough:            YES
D/miniaudio(10278): INFO:       Channel Map In:         {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}
D/miniaudio(10278): INFO:       Channel Map Out:        {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}
D/AAudio  (10278): AAudioStream_requestStart(s#9) called --------------
D/        (10278): PlayerBase::start() from IPlayer
D/AAudio  (10278): AAudioStream_requestStart(s#9) returned 0 ---------
D/AudioStreamLegacy(10278): onAudioDeviceUpdate() devId 3 => 3
I/flutter (10278): [FINEST] flutter_soloud.SoLoud: main isolate received: {event:
I/flutter (10278): MessageEvents.initEngine, args: (), return: PlayerErrors.noError (No error)}
I/flutter (10278): [FINEST] flutter_soloud.SoLoud: _startLoop() called
I/flutter (10278): [FINEST] flutter_soloud.SoLoud: main isolate received: {event:
I/flutter (10278): MessageEvents.startLoop, args: (), return: ()}

/************* deinit ***************/
I/flutter (10278): [FINEST] flutter_soloud.SoLoud: deinit() called
D/AAudio  (10278): AAudioStream_close(s#9) called ---------------
F/libc    (10278): /home/deimos/FLUTTER/libs/flutter_soloud/src/soloud/src/backend/miniaudio/miniaudio.h:18849: void ma_device__read_frames_from_client(ma_device *, ma_uint32, void *): assertion "frameCount > 0" failed
F/libc    (10278): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 10346 (AudioTrack), pid 10278 (.soloud.example)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'Xiaomi/nitrogen/nitrogen:10/QKQ1.190910.002/V12.0.1.0.QEDMIXM:user/release-keys'
Revision: '0'
ABI: 'arm64'
Timestamp: 2024-03-24 10:35:31+0100
pid: 10278, tid: 10346, name: AudioTrack  >>> flutter.soloud.example <<<
uid: 10978
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
Abort message: '/home/deimos/FLUTTER/libs/flutter_soloud/src/soloud/src/backend/miniaudio/miniaudio.h:18849: void ma_device__read_frames_from_client(ma_device *, ma_uint32, void *): assertion "frameCount > 0" failed'
    x0  0000000000000000  x1  000000000000286a  x2  0000000000000006  x3  0000007043a3d760
    x4  0000000000000000  x5  0000000000000000  x6  0000000000000000  x7  0000000000000040
    x8  00000000000000f0  x9  93f4f948f118562d  x10 0000000000000001  x11 0000000000000000
    x12 fffffff0fffffbdf  x13 0000000065fff3e3  x14 001f80693de3fd37  x15 00006a70bd14a6f1
    x16 000000714e6b88c0  x17 000000714e694900  x18 00000070433a8000  x19 0000000000002826
    x20 000000000000286a  x21 00000000ffffffff  x22 0000007044c95310  x23 0100804010040101
    x24 00000070c3328520  x25 00000070c33284a0  x26 00000070c3328748  x27 0000000000000421
    x28 0000000000000009  x29 0000007043a3d800
    sp  0000007043a3d740  lr  000000714e6460c4  pc  000000714e6460f0
backtrace:
      #00 pc 00000000000830f0  /apex/com.android.runtime/lib64/bionic/libc.so (abort+160) (BuildId: 328a3518945f3e056fc055f1eea1cc35)
      #01 pc 000000000008348c  /apex/com.android.runtime/lib64/bionic/libc.so (__assert2+36) (BuildId: 328a3518945f3e056fc055f1eea1cc35)
      #02 pc 0000000000112fd8  /data/app/flutter.soloud.example-k-p97bVufhg8O0OMd1yCmA==/lib/arm64/libflutter_soloud_plugin.so (BuildId: 9c9a1df707a88fba36fd15ccb91011402568062a)
      #03 pc 0000000000112554  /data/app/flutter.soloud.example-k-p97bVufhg8O0OMd1yCmA==/lib/arm64/libflutter_soloud_plugin.so (BuildId: 9c9a1df707a88fba36fd15ccb91011402568062a)
      #04 pc 0000000000155370  /data/app/flutter.soloud.example-k-p97bVufhg8O0OMd1yCmA==/lib/arm64/libflutter_soloud_plugin.so (BuildId: 9c9a1df707a88fba36fd15ccb91011402568062a)
      #05 pc 000000000001db30  /system/lib64/libaaudio.so (aaudio::AudioStream::maybeCallDataCallback(void*, int)+208) (BuildId: 3b3e2eff2488e0adaa1ff63da687463b)
      #06 pc 0000000000024714  /system/lib64/libaaudio.so (aaudio::AudioStreamLegacy::callDataCallbackFrames(unsigned char*, int)+320) (BuildId: 3b3e2eff2488e0adaa1ff63da687463b)
      #07 pc 000000000002c3cc  /system/lib64/libaaudio.so (FixedBlockReader::processVariableBlock(unsigned char*, int)+200) (BuildId: 3b3e2eff2488e0adaa1ff63da687463b)
      #08 pc 0000000000024ef4  /system/lib64/libaaudio.so (aaudio::AudioStreamLegacy::processCallbackCommon(int, void*)+1168) (BuildId: 3b3e2eff2488e0adaa1ff63da687463b)
      #09 pc 000000000007d034  /system/lib64/libaudioclient.so (android::AudioTrack::processAudioBuffer()+3044) (BuildId: 36a8c3e1296b171698432326efcd874d)
      #10 pc 000000000007c220  /system/lib64/libaudioclient.so (android::AudioTrack::AudioTrackThread::threadLoop()+484) (BuildId: 36a8c3e1296b171698432326efcd874d)
      #11 pc 00000000000135bc  /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+224) (BuildId: f52e94e6224d7e15faba92ee0326b191)
      #12 pc 00000000000c4cb8  /system/lib64/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+140) (BuildId: 58119cd499c9126f89ff7f6888912397)
      #13 pc 00000000000e6890  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+36) (BuildId: 328a3518945f3e056fc055f1eea1cc35)
      #14 pc 0000000000084b6c  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 328a3518945f3e056fc055f1eea1cc35)
Lost connection to device.

Exited.

mackron added a commit that referenced this issue Apr 28, 2024
@mackron
Copy link
Owner

mackron commented Apr 28, 2024

Sorry for the delay on this one. Unfortunately I was unable to replicate this. I tried using the "Pixel 2 XL API 27" emulator and it works fine here. However, I've pushed a potential fix to the dev branch. Are you able to give that a try without your MA_NO_AAUDIO workaround?

@alnitak
Copy link
Author

alnitak commented Apr 29, 2024

I also tried the "Pixel 2 XL API 27" emulator without any problems!

I tried with your updated dev branch and also by patching miniaudio.h in the master branch with your latest commit.
No more crashes on void ma_device__read_frames_from_client, but got a different one:

log
I/flutter (20962): [FINEST] flutter_soloud.SoLoud: _initEngine() called
D/miniaudio(20962): DEBUG: WASAPI backend is disabled.
D/miniaudio(20962): DEBUG: DirectSound backend is disabled.
D/miniaudio(20962): DEBUG: WinMM backend is disabled.
D/miniaudio(20962): DEBUG: Core Audio backend is disabled.
D/miniaudio(20962): DEBUG: sndio backend is disabled.
D/miniaudio(20962): DEBUG: audio(4) backend is disabled.
D/miniaudio(20962): DEBUG: OSS backend is disabled.
D/miniaudio(20962): DEBUG: PulseAudio backend is disabled.
D/miniaudio(20962): DEBUG: ALSA backend is disabled.
D/miniaudio(20962): DEBUG: JACK backend is disabled.
D/miniaudio(20962): DEBUG: Attempting to initialize AAudio backend...
D/miniaudio(20962): DEBUG: Loading library: libaaudio.so
D/miniaudio(20962): DEBUG: Loading symbol: AAudio_createStreamBuilder
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_delete
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setDeviceId
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setDirection
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setSharingMode
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setFormat
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setChannelCount
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setSampleRate
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setBufferCapacityInFrames
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setFramesPerDataCallback
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setDataCallback
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setErrorCallback
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setPerformanceMode
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setUsage
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setContentType
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setInputPreset
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_setAllowedCapturePolicy
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStreamBuilder_openStream
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStream_close
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStream_getState
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStream_waitForStateChange
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStream_getFormat
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStream_getChannelCount
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStream_getSampleRate
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStream_getBufferCapacityInFrames
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStream_getFramesPerDataCallback
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStream_getFramesPerBurst
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStream_requestStart
D/miniaudio(20962): DEBUG: Loading symbol: AAudioStream_requestStop
D/miniaudio(20962): DEBUG: System Architecture:
D/miniaudio(20962): DEBUG:   Endian: LE
D/miniaudio(20962): DEBUG:   SSE2:   YES
D/miniaudio(20962): DEBUG:   AVX2:   NO
D/miniaudio(20962): DEBUG:   NEON:   NO
I/AAudio  (20962): AAudioStreamBuilder_openStream() called ----------------------------------------
I/AudioStreamBuilder(20962): rate   =  44100, channels  = 2, format   = 5, sharing = SH, dir = OUTPUT
I/AudioStreamBuilder(20962): device =      0, sessionId = -1, perfMode = 12, callback: ON with frames = 2048
I/AudioStreamBuilder(20962): usage  =      0, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
D/        (20962): PlayerBase::PlayerBase()
D/AudioStreamTrack(20962): open(), request notificationFrames = 2048, frameCount = 6144
I/AudioTrack(20962): createTrack_l(1105): AUDIO_OUTPUT_FLAG_FAST successful; frameCount 6144 -> 6144
W/AudioStreamTrack(20962): open() flags changed from 0x00000104 to 0x00000004
I/AAudio  (20962): AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#19 ----------------
D/miniaudio(20962): INFO: [AAudio]
D/miniaudio(20962): INFO:    (Playback)
D/miniaudio(20962): INFO:     Format:      32-bit IEEE Floating Point -> 32-bit IEEE Floating Point
D/miniaudio(20962): INFO:     Channels:    2 -> 2
D/miniaudio(20962): INFO:     Sample Rate: 44100 -> 44100
D/miniaudio(20962): INFO:     Buffer Size: 2048*3 (6144)
D/miniaudio(20962): INFO:     Conversion:
D/miniaudio(20962): INFO:       Pre Format Conversion:  NO
D/miniaudio(20962): INFO:       Post Format Conversion: NO
D/miniaudio(20962): INFO:       Channel Routing:        NO
D/miniaudio(20962): INFO:       Resampling:             NO
D/miniaudio(20962): INFO:       Passthrough:            YES
D/miniaudio(20962): INFO:       Channel Map In:         {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}
D/miniaudio(20962): INFO:       Channel Map Out:        {CHANNEL_FRONT_LEFT CHANNEL_FRONT_RIGHT}
D/AAudio  (20962): AAudioStream_requestStart(s#19) called --------------
D/        (20962): PlayerBase::start() from IPlayer
D/AAudio  (20962): AAudioStream_requestStart(s#19) returned 0 ---------
D/AudioStreamLegacy(20962): onAudioDeviceUpdate() devId 2 => 2
I/flutter (20962): [FINEST] flutter_soloud.SoLoud: main isolate received: {event:
I/flutter (20962): MessageEvents.initEngine, args: (), return: PlayerErrors.noError (No error)}
I/flutter (20962): [FINEST] flutter_soloud.SoLoud: _startLoop() called
I/flutter (20962): [FINEST] flutter_soloud.SoLoud: main isolate received: {event:
I/flutter (20962): MessageEvents.startLoop, args: (), return: ()}
I/flutter (20962): [FINEST] flutter_soloud.SoLoud: deinit() called
D/AAudio  (20962): AAudioStream_close(s#19) called ---------------
E/libc++abi(20962): Pure virtual function called!
F/libc    (20962): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 21046 (AudioTrack), pid 20962 (.soloud.example)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'google/sdk_gphone_x86/generic_x86:10/QSR1.210802.001/7603624:userdebug/dev-keys'
Revision: '0'
ABI: 'x86'
Timestamp: 2024-04-29 12:51:13+0200
pid: 20962, tid: 21046, name: AudioTrack  >>> flutter.soloud.example <<<
uid: 10151
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
Abort message: 'Pure virtual function called!'
    eax 00000000  ebx 000051e2  ecx 00005236  edx 00000006
    edi e8cc733e  esi ad078da0
    ebp eb50eef0  esp ad078d48  eip eb50eef9
backtrace:
      #00 pc 00000ef9  [vdso] (__kernel_vsyscall+9)
      #01 pc 00092328  /apex/com.android.runtime/lib/bionic/libc.so (syscall+40) (BuildId: 471745f0fbbcedb3db1553d5bd6fcd8b)
      #02 pc 000ad651  /apex/com.android.runtime/lib/bionic/libc.so (abort+193) (BuildId: 471745f0fbbcedb3db1553d5bd6fcd8b)
      #03 pc 0004d107  /system/lib/libc++.so (abort_message+151) (BuildId: da119c8dac8dad63397846fac8d85f56)
      #04 pc 00067e03  /system/lib/libc++.so (__cxa_pure_virtual+35) (BuildId: da119c8dac8dad63397846fac8d85f56)
      #05 pc 0001c5af  /system/lib/libaaudio.so (aaudio::AudioStreamLegacy::processCallbackCommon(int, void*)+559) (BuildId: 763922c0b912534fb5c7a27226c6187a)
      #06 pc 0001e55b  /system/lib/libaaudio.so (aaudio::AudioStreamTrack::processCallback(int, void*)+59) (BuildId: 763922c0b912534fb5c7a27226c6187a)
      #07 pc 0001c177  /system/lib/libaaudio.so (AudioStreamLegacy_callback(int, void*, void*)+39) (BuildId: 763922c0b912534fb5c7a27226c6187a)
      #08 pc 0005bc46  /system/lib/libaudioclient.so (android::AudioTrack::processAudioBuffer()+2742) (BuildId: 4a182c5ae196b1b3c87306222ba09430)
      #09 pc 0005e448  /system/lib/libaudioclient.so (android::AudioTrack::AudioTrackThread::threadLoop()+184) (BuildId: 4a182c5ae196b1b3c87306222ba09430)
      #10 pc 000140fe  /system/lib/libutils.so (android::Thread::_threadLoop(void*)+238) (BuildId: 288ba3aff5b46dbd7e74be954af88b83)
      #11 pc 000b660b  /system/lib/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+171) (BuildId: 3643bee2c4fb7899d7781c565843060b)
      #12 pc 00013aa6  /system/lib/libutils.so (thread_data_t::trampoline(thread_data_t const*)+246) (BuildId: 288ba3aff5b46dbd7e74be954af88b83)
      #13 pc 0011a8e5  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+53) (BuildId: 471745f0fbbcedb3db1553d5bd6fcd8b)
      #14 pc 000af6a7  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+71) (BuildId: 471745f0fbbcedb3db1553d5bd6fcd8b)
Syncing files to device Android SDK built for x86...                55ms

Seems like an AAudio bug on API 10 that doesn't want to close itself if it never got frames delivered or it does not have the time to instantiate the virtual close() function.

Here an updated brief devices summary:

  • Test NOT passed on:

    • emulator - Android 10 API 29
    • Xiaomi Mi Max 3 - Android 10 API 29
    • Huawei P smart Z - Android 10 API 29
    • Xiaomi Mi 6 - Android 9 SDK 28
  • Test passed on:

    • emulator - Android 14 API 34
    • emulator - Android 13 API 33
    • emulator - Android 12L API 32
    • emulator - Android 12 API 31
    • emulator - Android 11 API 30
    • emulator - Android 9 API 28
    • emulator - Android 8 API 27
    • Samsung Galaxy Note20 Ultra - Android 13 API 33
    • Samsung Galaxy Note10+ - Android 12 API 31,32
    • Samsung Galaxy S9+ - Android 10 API 29

@reg31
Copy link

reg31 commented May 28, 2024

Exact same issue for me on Android 10, I decided to define MA_NO_AAUDIO and this works fine.

@mackron
Copy link
Owner

mackron commented Aug 6, 2024

I've had another look at this and I'm still unable to replicate this. I'm not using Flutter nor SoLoud, but I've replicated what SoLoud is doing. This is the exact function I'm using to test:

void crash_test_gh833()
{
    ma_device_config deviceConfig;
    ma_device device;

    deviceConfig = ma_device_config_init(ma_device_type_playback);
    deviceConfig.playback.format   = ma_format_f32;
    deviceConfig.playback.channels = 2;
    deviceConfig.sampleRate        = 44100;
    deviceConfig.dataCallback      = data_callback;
    deviceConfig.pUserData         = NULL;

    if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) {
        printf("Failed to open playback device.\n");
        return;
    }

    if (ma_device_start(&device) != MA_SUCCESS) {
        printf("Failed to start playback device.\n");
        ma_device_uninit(&device);
        return;
    }

    ma_device_uninit(&device);
}

This is the emulator I'm using through Android Studio which matches with the one you were saying wasn't working for you:
image
I'm out of ideas on things to try. You can use #define MA_AAUDIO_MIN_ANDROID_SDK_VERSION 30 if you want to restrict AAudio to SDK version 30 and above in the mean time, or you can just disable the AAudio backend completely like you're already doing.

@alnitak
Copy link
Author

alnitak commented Aug 6, 2024

I bypassed SoLoud and used almost your crash_test_gh833(). I just added the loop because I found this issue when running tests on my plugin. This crashes randomly using the emulator you used:

#include <android/log.h>
void crash_test_gh833()
{
        ma_device_config deviceConfig;
        ma_device device;

        deviceConfig = ma_device_config_init(ma_device_type_playback);
        deviceConfig.playback.format   = ma_format_f32;
        deviceConfig.playback.channels = 2;
        deviceConfig.sampleRate        = 44100;
        deviceConfig.dataCallback      = data_callback;
        deviceConfig.pUserData         = NULL;

        for (int n = 0; n < 100; n++)
        {
            __android_log_print(ANDROID_LOG_VERBOSE, "TEST NDK", "Loop %d.\n", n);
            if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS)
            {
                __android_log_print(ANDROID_LOG_VERBOSE, "TEST NDK", "Failed to open playback device %d.\n", n);
                return;
            }
            __android_log_print(ANDROID_LOG_VERBOSE, "TEST NDK", "Playback device opened.\n");

            if (ma_device_start(&device) != MA_SUCCESS) {
                __android_log_print(ANDROID_LOG_VERBOSE, "TEST NDK", "Failed to start playback device %d.\n", n);
                ma_device_uninit(&device);
                return;
            }
            __android_log_print(ANDROID_LOG_VERBOSE, "TEST NDK", "Playback device started.\n");

            ma_device_uninit(&device);
            __android_log_print(ANDROID_LOG_VERBOSE, "TEST NDK", "Playback device uninited.\n");
        }
}
This is the log happening at a random `n`:
V/TEST NDK( 7382): Loop 21. I/AAudio ( 7382): AAudioStreamBuilder_openStream() called ---------------------------------------- I/AudioStreamBuilder( 7382): rate = 44100, channels = 2, format = 5, sharing = SH, dir = OUTPUT I/AudioStreamBuilder( 7382): device = 0, sessionId = -1, perfMode = 12, callback: ON with frames = 441 I/AudioStreamBuilder( 7382): usage = 0, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0 D/ ( 7382): PlayerBase::PlayerBase() D/AudioStreamTrack( 7382): open(), request notificationFrames = 441, frameCount = 1323 I/AudioTrack( 7382): createTrack_l(499): AUDIO_OUTPUT_FLAG_FAST successful; frameCount 1323 -> 1323 W/AudioStreamTrack( 7382): open() flags changed from 0x00000104 to 0x00000004 I/AAudio ( 7382): AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#122 ---------------- V/TEST NDK( 7382): Playback device opened. D/AAudio ( 7382): AAudioStream_requestStart(s#122) called -------------- D/ ( 7382): PlayerBase::start() from IPlayer D/AAudio ( 7382): AAudioStream_requestStart(s#122) returned 0 --------- D/AudioStreamLegacy( 7382): onAudioDeviceUpdate() devId 2 => 2 V/TEST NDK( 7382): Playback device started. D/AAudio ( 7382): AAudioStream_close(s#122) called --------------- F/libc ( 7382): /home/deimos/FLUTTER/libs/flutter_soloud/src/soloud/src/backend/miniaudio/miniaudio.h:19207: void ma_device__read_frames_from_client(ma_device *, ma_uint32, void *): assertion "frameCount > 0" failed F/libc ( 7382): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 7673 (AudioTrack), pid 7382 (.soloud.example) *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** Build fingerprint: 'google/sdk_gphone_x86/generic_x86:10/QSR1.210802.001/7603624:userdebug/dev-keys' Revision: '0' ABI: 'x86' Timestamp: 2024-08-06 23:08:44+0200 pid: 7382, tid: 7673, name: AudioTrack >>> flutter.soloud.example <<< uid: 10151 signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr -------- Abort message: '/home/deimos/FLUTTER/libs/flutter_soloud/src/soloud/src/backend/miniaudio/miniaudio.h:19207: void ma_device__read_frames_from_client(ma_device *, ma_uint32, void *): assertion "frameCount > 0" failed' eax 00000000 ebx 00001cd6 ecx 00001df9 edx 00000006 edi e994a33e esi aca7dbb0 ebp eaa62ef0 esp aca7db58 eip eaa62ef9 backtrace: #00 pc 00000ef9 [vdso] (__kernel_vsyscall+9) #1 pc 00092328 /apex/com.android.runtime/lib/bionic/libc.so (syscall+40) (BuildId: 471745f0fbbcedb3db1553d5bd6fcd8b) #2 pc 000ad651 /apex/com.android.runtime/lib/bionic/libc.so (abort+193) (BuildId: 471745f0fbbcedb3db1553d5bd6fcd8b) #3 pc 000adb88 /apex/com.android.runtime/lib/bionic/libc.so (__assert2+56) (BuildId: 471745f0fbbcedb3db1553d5bd6fcd8b) #4 pc 0012eef0 /data/app/flutter.soloud.example-PLamRCiAL-81IMTFeuU2Dg==/lib/x86/libflutter_soloud_plugin.so (BuildId: 1b14ff7ccf70ed8f24f717fdf8387428bfe61f0a) #5 pc 0012e091 /data/app/flutter.soloud.example-PLamRCiAL-81IMTFeuU2Dg==/lib/x86/libflutter_soloud_plugin.so (BuildId: 1b14ff7ccf70ed8f24f717fdf8387428bfe61f0a) #6 pc 00185ed3 /data/app/flutter.soloud.example-PLamRCiAL-81IMTFeuU2Dg==/lib/x86/libflutter_soloud_plugin.so (BuildId: 1b14ff7ccf70ed8f24f717fdf8387428bfe61f0a) #7 pc 0001a035 /system/lib/libaaudio.so (aaudio::AudioStream::maybeCallDataCallback(void*, int)+69) (BuildId: 763922c0b912534fb5c7a27226c6187a) #8 pc 0001c2f6 /system/lib/libaaudio.so (aaudio::AudioStreamLegacy::onProcessFixedBlock(unsigned char*, int)+182) (BuildId: 763922c0b912534fb5c7a27226c6187a) #9 pc 0001c36c /system/lib/libaaudio.so (non-virtual thunk to aaudio::AudioStreamLegacy::onProcessFixedBlock(unsigned char*, int)+44) (BuildId: 763922c0b912534fb5c7a27226c6187a) #10 pc 0001f770 /system/lib/libaaudio.so (FixedBlockReader::processVariableBlock(unsigned char*, int)+192) (BuildId: 763922c0b912534fb5c7a27226c6187a) #11 pc 0001c5af /system/lib/libaaudio.so (aaudio::AudioStreamLegacy::processCallbackCommon(int, void*)+559) (BuildId: 763922c0b912534fb5c7a27226c6187a) #12 pc 0001e55b /system/lib/libaaudio.so (aaudio::AudioStreamTrack::processCallback(int, void*)+59) (BuildId: 763922c0b912534fb5c7a27226c6187a) #13 pc 0001c177 /system/lib/libaaudio.so (AudioStreamLegacy_callback(int, void*, void*)+39) (BuildId: 763922c0b912534fb5c7a27226c6187a) #14 pc 0005bc46 /system/lib/libaudioclient.so (android::AudioTrack::processAudioBuffer()+2742) (BuildId: 4a182c5ae196b1b3c87306222ba09430) #15 pc 0005e448 /system/lib/libaudioclient.so (android::AudioTrack::AudioTrackThread::threadLoop()+184) (BuildId: 4a182c5ae196b1b3c87306222ba09430) #16 pc 000140fe /system/lib/libutils.so (android::Thread::_threadLoop(void*)+238) (BuildId: 288ba3aff5b46dbd7e74be954af88b83) #17 pc 000b660b /system/lib/libandroid_runtime.so (android::AndroidRuntime::javaThreadShell(void*)+171) (BuildId: 3643bee2c4fb7899d7781c565843060b) #18 pc 00013aa6 /system/lib/libutils.so (thread_data_t::trampoline(thread_data_t const*)+246) (BuildId: 288ba3aff5b46dbd7e74be954af88b83) #19 pc 0011a8e5 /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+53) (BuildId: 471745f0fbbcedb3db1553d5bd6fcd8b) #20 pc 000af6a7 /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+71) (BuildId: 471745f0fbbcedb3db1553d5bd6fcd8b) Lost connection to device.

Exited.

IMHO I think that this is not a miniaudio problem, but AAudio issue on Android SDK < 30.

Thank you very much for all your support and feel free to close this issue.

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

No branches or pull requests

3 participants