google / oboe

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

AAudio timestamps unavailable on certain devices with certain input stream configurations #1357

Closed chrismanchester closed 11 months ago

chrismanchester commented 3 years ago

Android version(s): 9 Android device(s): Xiaomi Redmi Note 8, Oppo A3s, several others Oboe version: 1.6.1 App name used for testing: OboeTester

Short description We've found several devices that are unable to produce AAudio timestamps for input streams. Some stream configurations work, others do not. For this particular device we found that using the VoiceRecognition input preset prevents latency estimates for the input stream, however we know from our analytics that there are several devices across manufacturers that aren't producing an estimate with our chosen stream parameters. On another device, the Oppo A3s, we found that requesting PCM_I16 for the input format prevented the device from producing a latency estimate.

Steps to reproduce On the "Test Input" screen of OboeTester, select InPreset: VoiceRec and start the stream.

Expected behavior timestamp.latency field in the stream state text is populated and corresponds to the estimated latency.

Actual behavior timestamp.latency field reads "?", corresponding to a failure to produce a timestamp for this stream.

Device

Xiaomi Redmi Note 8

$ for p in \
>     ro.product.brand ro.product.manufacturer ro.product.model \
>     ro.product.device ro.product.cpu.abi ro.build.description \
>     ro.hardware ro.hardware.chipname ro.arch "| grep aaudio";
>     do echo "$p = $(adb shell getprop $p)"; done
ro.product.brand = xiaomi
ro.product.manufacturer = Xiaomi
ro.product.model = Redmi Note 8
ro.product.device = ginkgo
ro.product.cpu.abi = arm64-v8a
ro.build.description = ginkgo-user 9 PKQ1.190616.001 V11.0.9.0.PCOMIXM release-keys
ro.hardware = qcom
ro.hardware.chipname = 
ro.arch = 
| grep aaudio = 

Any additional context

Reliable round-trip latency estimates are indispensable to our application. Being able to rely on AAudio providing these estimates would be a great benefit to us.

philburk commented 3 years ago

This is a known issue discussed in https://github.com/google/oboe/issues/240#issuecomment-865198818

The only known workaround is to use an estimate for the input latency. Luckily that tends to be low.

On another device, the Oppo A3s, we found that requesting PCM_I16 for the input format prevented the device from producing a latency estimate.

Requesting I16 could result in not getting a FAST input. See #276.

You can use AudioStreamBuilder::setFormatConversionAllowed() to do the conversion in Oboe.