How to get the output latency of Bluetooth audio

I am programming an audio App using AudioUnit and AVAudioSession, and AVAudioSession is initialized as:

[[AVAudioSession sharedInstance] setCategory:audioSessionCategory withOptions:AVAudioSessionCategoryOptionAllowBluetoothA2DP | AVAudioSessionCategoryOptionMixWithOthers error:NULL];


When a Bluetooth headset is connected, I am able to get the output latency by "AVAudioSession.sharedInstance().outputLatency".

However, the value retrieved is still much smaller than the real Bluetooth audio latency.

Also, I found that such a latency is actually changing over time, sometimes, within 1 min, the latency can change from 193ms to 260ms.


I am wondering how can I query the accurate current Bluetooth audio output latency using API calls?

If not possible, is there any way to lock the output latency to a safe value using Bluetooth audio?

I do not care about the latency if it is measurable.


Thanks

Replies

Did you ever figure this out? I have the exact same question.
Have you tried using an Audio Queue Processing Tap? This allows you to intercept audio frames and it tells you the timestamp the audio will be played. By looking at the timestamp and which sample is going to be played, and comparing with how many frames you have written to the audio queue, you can figure out the latency.