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

[AAudio] [Crash] App crash on AAudioStream_close #262

Closed
abhi-foss opened this issue Nov 5, 2018 · 4 comments
Closed

[AAudio] [Crash] App crash on AAudioStream_close #262

abhi-foss opened this issue Nov 5, 2018 · 4 comments
Assignees

Comments

@abhi-foss
Copy link

abhi-foss commented Nov 5, 2018

Hi,

I have this simple test app, which just basically Opens an AAudioStream AAudioStreamBuilder_openStream(streamBuilder, &audioStream);
and then simply close it
AAudioStream_close(audioStream);
without doing any processing.

This app works fine on Pixel Devices (I have tested on Pixel 1). But the application crashes on Samsung Devices (tested on Galaxy S9+) and Honor Device (Honor 7X).
The crash is not immediate, after calling the Close(), I leave the app idle, and it crashes after a minute or so. In some cases I have seen memory shooting up rapidly, but this is not a consistent behavior.

Crash Logs

A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/star2qltesq/star2qltesq:8.0.0/R16NW/G965USQU1ARBI:user/release-keys'
Revision: '14'
ABI: 'arm64'
pid: 20110, tid: 20124, name: Binder:20110_1 >>> com.example.abhishek.testaaudio <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xffffffffffffffe8
x0 0000007dda4849c0 x1 0000007dda4d0a80 x2 0000000000000001 x3 0000000000000000
11-05 12:05:23.665 20796-20796/? A/DEBUG: x4 0000000000000000 x5 0000000000000000 x6 0000000000000000 x7 0000007dc2594ec8
x8 0000007dcfa45708 x9 0000000000000000 x10 0000000000000008 x11 0000000000000000
x12 0000007dcd1eef08 x13 0000007dc25952d0 x14 0000000000000010 x15 0000000000000000
x16 0000007dde0b96e0 x17 0000007ddad2e310 x18 0000000013cc0000 x19 0000007dda4d0bc0
x20 0000000000000001 x21 0000000000000000 x22 0000000000000000 x23 0000007ddad2aeb0
x24 0000007dc2595570 x25 0000007dc2499000 x26 0000000000000000 x27 0000000000000000
x28 0000000000000000 x29 0000007dc2595380 x30 0000007dde0706d0
sp 0000007dc2595360 pc 0000007dde0706ec pstate 0000000060000000
11-05 12:05:23.691 20796-20796/? A/DEBUG: backtrace:
#00 pc 00000000000626ec /system/lib64/libbinder.so (_ZN7android14IPCThreadState20processPendingDerefsEv+128)
#1 pc 000000000006275c /system/lib64/libbinder.so (_ZN7android14IPCThreadState14joinThreadPoolEb+52)
11-05 12:05:23.692 20796-20796/? A/DEBUG: #2 pc 00000000000830e0 /system/lib64/libbinder.so (_ZN7android10PoolThread10threadLoopEv+24)
#3 pc 0000000000011674 /system/lib64/libutils.so (_ZN7android6Thread11_threadLoopEPv+280)
#4 pc 00000000000fcda4 /system/lib64/libandroid_runtime.so (_ZN7android14AndroidRuntime15javaThreadShellEPv+136)
#5 pc 0000000000068560 /system/lib64/libc.so (_ZL15__pthread_startPv+36)
#6 pc 000000000001f9f4 /system/lib64/libc.so (__start_thread+68)

Is it something which is known ?

Abhishek

@philburk
Copy link
Collaborator

philburk commented Nov 6, 2018

I have not seen this. I would like to get more information.

What do you set in the AudioStreamBuilder? I am particularly interested in the PerformanceMode.

What OS version?

How much time between open and close of the stream?

What happens if you do not close the stream?

fault addr 0xffffffffffffffe8

That address is -24. Hmmm.

I suspect the minute long delay is because the garbage collector runs and causes some native object to get killed. Try forcing a garbage collection.

@abhi-foss
Copy link
Author

  • I am not setting any thing specific in the AudioStreamBuilder, only the direction.
    Although I did try setting the PerformanceMode, the issue is still there.

  • Not much time between Open and Close, just a sleep for 2s after calling Open and then immediately Close()

    // Open Stream
    AAudioStreamBuilder *streamBuilder = nullptr;
    AAudio_createStreamBuilder(&streamBuilder);
    AAudioStreamBuilder_setDirection(streamBuilder, AAUDIO_DIRECTION_OUTPUT);
    AAudioStreamBuilder_openStream(streamBuilder, &audioStream);
    AAudioStreamBuilder_delete(streamBuilder);
    std::this_thread::sleep_for(std::chrono::seconds(sleepDuration));
    if(audioStream) {
        assert(AAudioStream_getState(audioStream) == AAUDIO_STREAM_STATE_OPEN);
        __android_log_write(ANDROID_LOG_DEBUG, "TestAAudio", "DeviceOpened");
    }
    else {
        __android_log_write(ANDROID_LOG_DEBUG, "TestAudio", "DeviceOpened:Failed");
    }
    
   
    ```
    // Close Stream
    AAudioStream_close(audioStream);
    aaudio_result_t result = AAUDIO_OK;
    aaudio_stream_state_t currentState = AAudioStream_getState(audioStream);
    aaudio_stream_state_t inputState = currentState;
    while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_CLOSED)
    {
        result = AAudioStream_waitForStateChange(audioStream,
                                                 inputState,
                                                 &currentState,
                                                 std::numeric_limits<int32_t>::max());
        inputState = currentState;
    }
    assert(AAudioStream_getState(audioStream) == AAUDIO_STREAM_STATE_CLOSED);
    __android_log_write(ANDROID_LOG_DEBUG, "TestAAudio", "DeviceClosed");
  • Things are fine if I do not close the Stream, I did not observe any crash.

  • It seems fair to suspect that crash occurs when GC is triggered, however I did try forcing GC, but could not correlate it with the crash.

  • I am facing this issue on the Samsung (S9, S9+), Honor (7X) and Sony Devices, unfortunately all of them are Android 8.0 (API 26). One Plus 6 and Pixel Devices are working fine ( both of them are running Android 9.0 API 28). I don't have a Pixel device running Android 8.0 so that I can isolate the issue.

I have attached logs from different devices I have, please see if they could be of any help for you.
AAudioDeviceIssue.log

-Abhishek

@philburk
Copy link
Collaborator

philburk commented Nov 8, 2018

unfortunately all of them are Android 8.0 (API 26).

OK, then I know what the problem is. A late change was made to Android 8.0 that unfortunately made AAudio unstable. The problem involves reference counting and object deletion in Java. It can fail on Pixel but it fails much more often on some third party phones. The bug is timing sensitive. This was fixed in Android 8.1 (OC_MR1).

This why we do not recommend using AAudio on Android 8.0.
We suggest using Oboe instead of calling AAudio directly. Oboe will use AAudio on 8.1+ and OpenSL ES on 8.0 and earlier.

Sorry about this. Please see this issue for more detail: #40

Also see:
https://github.com/google/oboe/blob/master/docs/AndroidAudioHistory.md

@philburk philburk closed this as completed Nov 8, 2018
@abhi-foss
Copy link
Author

Thanks Phil, I always wondered why Oboe uses AAudio on 8.1+ and not 8.0. I understand now.

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