Thanks for watching the videos.
To get lower latency, it takes a partnership of the app developer, Android framework, OEM and SoC vendor (including audio HAL),
kernel, and testing. Here are a few of the key things for each part.
app:
Use Android native audio based on OpenSL ES.
Check for feature android.hardware.audio.low_latency
Use the recommended native buffer size and sample rate;
[the same buffer size and sample rate should be used for input also]
Usually an OpenSL ES buffer count of 1 is sufficient.
Keep your callback handlers short, without bursty CPU usage,
and no unbounded blocking. Avoid priority inversion.
You may want to consider using a non-blocking library
framework:
We've been gradually improving the framework over successive releases.
This article describes the initial design:
The article needs to be updated to describe more recent improvements
(especially on input side). I'm making a note to self to update that.
Generally, newer releases
can offer lower latency than older releases on the same device.
We expect to continue to make more improvements in future,
but I can't give a schedule.
OEM and SoC vendor, including audio HAL:
You mentioned 6 or 8 buffers in HAL. I find that usually 2 buffers is enough.
Avoid priority inversion in the HAL. Pay attention especially to mutexes.
Avoid or reduce extra audio processing in HAL such as signal "enhancements"
for lower latency use cases.
If there is a DSP after the app processor, try to keep any processing
by the DSP minimal.
I noticed you made some changes to the portable audio framework.
Those changes should not be necessary if you do the other suggestions here.
Kernel:
Reduce worst-case interrupt disable and preemption disable times.
Power management can sometimes interfere with scheduling.
Check if your DRM security kernel has any long dark times
during which the regular kernel is unable to run.
Testing:
Here are links to the test techniques and tools that I've used:
For an overview of latency issues, see