-
Notifications
You must be signed in to change notification settings - Fork 572
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
AudioStreamAAudio::write crashes if callback is not set #359
Comments
It looks like the DISCONNECT is happening immediately. Why? Please provide more information about the devices, OS and Oboe versions, and the app. 01-21 12:26:54.985 12208 14284 D AAudio : AAudioStream_requestStart(0xbef21d40) returned 0 In Oboe, the errorCallback is enabled even is the data callback is not enabled. If the error callback is called while the apps writing thread is running then it will crash. That is a problem. It will result in a call to onErrorInThread(), which closes the stream. oboe/src/aaudio/AudioStreamAAudio.cpp Line 259 in 6fa2a1a
We will fix this. The easiest fix may be to not set the error callback if there is no data callback. Thanks for reporting this. |
This log is extracted from the following device:
Our app can be obtained via: http://dldir1.qq.com//egame/qgame/4.3.0/408/qgame_4.3.0.370.755_r836e9a_firstgray_release.apk After analyzing several users' log who have the same crash, DISCONNECT happening immediately after open() is not the common situation, it's much more like a coincidence. Disable error callback when data callback is absent is a good idea, because the close() will set stream pointer to null, that will cause write() returning ErrorClosed, ErrorDisconnected is missed. |
Thanks for the info. Is the crash associated with a DISCONNECT event? Like unplugging headphones? Can you consistently reproduce the crash in your office? Or do you only get reports from users? If you can reproduce it, please try moving the setting of the error callback into the conditional, like this:
We are considering this fix. But we also need to look more carefully at protecting the stream pointer from close(). |
Yes, almost every crash is related with DISCONNECT event.
but no crash happened. |
@philburk to implement workaround for this bug. This bug points out a larger problem which is the "use after close" issue. We should consider separating the data callback from the error callback interface. |
That can close a stream that is in use by the app thread that is writing the stream. See issue #359
There is a pending fix at #364 |
loongee wrote:
Yes, or something to prevent write() and close() from colliding, |
I believe that #364 solves this particular problem. There is also a problem if an app closes a stream from one thread while writing from another thread. That is a different problem that can and should be prevented by the app. So I will close this. |
See also related bug #519 |
It would be more helpful to debug if you explain why and when onAudioDeviceUpdate() method will be triggered ? 2019-01-23 10:47:58.291 23556-1578/com.xxx.xxx D/AudioStreamLegacy: onAudioDeviceUpdate() deviceId 2 Thanks |
onAudioDeviceUpdate() is an internal method inside AAudio. It is called when there is a routing change, for example when a headset is plugged in or unplugged. It can also happen if "playback capture" is initiated. onAudioDeviceUpdate() is part of the Legacy data path. For MMAP, it can also happen if an EXCLUSIVE stream is converted to a SHARED stream because another app needs low latency. That can happen on R and later. |
On Android R we are facing AAudio stream disconnection issue. Bluetooth will be playing initially(which uses AAudio). AAudio stream is being disconnected as soon as we switched from Bluetooth to radio. Therefore there is no audio available once after we switched back from radio to Bluetooth. 03-29 13:31:21.374 3555 6534 W APM_AudioPolicyManager: disconnectAudioSource source has neither SW nor HW output our system property configurations are as below it's an always issue and we can reproduce it anytime. could you please explain what's going wrong here ? |
@darshanbr - You are adding a new bug to an issue that is already closed. For new bugs please start a new Issue at: https://github.com/google/oboe/issues/new/choose |
In my own project, the oboe library is used as follows:
Many crashes reported from different devices with Android 8.1 and Android 9 as follows:
and logcat:
The reason (not 100% sure):
In
AudioStreamAAudio
's error handler, it calls close()but in write function:
The problem is:
If I use error callbacks to prevent freeing resource when writing, then
write
function is useless (onDataReady callback is set at the same time);if not using callbacks,
write
is not safe.Solution:
Maybe a lock guard is needed in
write
function,or error callback and dataReady callback can be split into different callback.
The text was updated successfully, but these errors were encountered: