Possibility of improving/enabling AUDIOTRACK_HW_LATENCY in the AudioTrack output module?
I originally posted this in the forum, but got a suggestion to create an issue here instead.
It looks like VLC's output driver has code for supporting the AudioTrack.getTimestamp method of estimating and compensating for the audio output delay. The functionality is currently gated behind the AUDIOTRACK_HW_LATENCY
ifdef in the audiotrack module. Unfortunately, it seems that enabling AUDIOTRACK_HW_LATENCY
does not work correctly (incorrect delay compensation with internal speakers and garbled audio with bluetooth). I've been trying to debug it for a couple days, but I'm a bit stumped. From a cursory look at the code, it seems that VLC generally follows what's documented at https://developer.amazon.com/docs/fire-tv/audio-video-synchronization.html#21-audiotrackgettimestamp-api-level-19 and also what Google's ExoPlayer does:
(though VLC falls back to AudioSystem.getOutputLatency()
instead of AudioTrack.getLatency()
).
It would be nice to see VLC's a/v sync working well on Android. At least on my test device (Galaxy Tab S7+), the OS reports the latency pretty accurately for both the internal speakers (<50ms) and bluetooth headsets (200-300ms, reported via AVDTP 1.3 delay reports and recognized by the bluetooth stack). Both MediaPlayer and ExoPlayer based apps perform a/v sync well, but VLC unfortunately does not.
Is this something that the maintainers would be interested in looking at? I'm willing to offer any help, both coding and testing, though I only have limited experience with AudioTrack (and OpenSL ES) and no experience with VLC's internals.