Skip to content

Commit

Permalink
auhal: add kAudioStreamPropertyLatency to the latency
Browse files Browse the repository at this point in the history
Fixes delay with AirPlay devices.

Internal and bluetooth devices have a valid Device Latency.
Airplay 2 devices has a valid Stream Latency.
  • Loading branch information
tguillem authored and jbkempf committed Dec 2, 2022
1 parent 1bb8234 commit a666243
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions modules/audio_output/auhal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ GetLatency(audio_output_t *p_aout, const audio_sample_format_t *fmt)
aout_sys_t *p_sys = p_aout->sys;

UInt32 i_latency_samples;
vlc_tick_t i_latency_us, i_device_latency_us = 0;
vlc_tick_t i_latency_us, i_device_latency_us = 0, i_stream_latency_us = 0;
/* Get device latency */
int ret = AO_GET1PROP(p_sys->i_selected_dev, UInt32, &i_latency_samples,
kAudioDevicePropertyLatency,
Expand All @@ -1492,10 +1492,28 @@ GetLatency(audio_output_t *p_aout, const audio_sample_format_t *fmt)
else
msg_Warn(p_aout, "failed to get kAudioDevicePropertyLatency");

i_latency_us = i_device_latency_us;
AudioStreamID sid;
/* Get stream latency */
ret = AO_GET1PROP(p_sys->i_selected_dev, AudioStreamID, &sid,
kAudioDevicePropertyStreams, kAudioObjectPropertyScopeOutput);
if (ret == VLC_SUCCESS)
{
ret = AO_GET1PROP(sid, UInt32, &i_latency_samples,
kAudioStreamPropertyLatency,
kAudioObjectPropertyScopeOutput);
if (ret == VLC_SUCCESS)
i_stream_latency_us = vlc_tick_from_samples(i_latency_samples, fmt->i_rate);
else
msg_Warn(p_aout, "failed to get kAudioStreamPropertyLatency");
}
else
msg_Warn(p_aout, "failed to get kAudioDevicePropertyStreams");

i_latency_us = i_device_latency_us + i_stream_latency_us;

msg_Dbg(p_aout, "Current device has a latency of " PRId64 " us",
i_latency_us);
msg_Dbg(p_aout, "Current device has a latency of %" PRId64 " us "
"(device: %" PRId64 " us, stream: %" PRId64 " us)", i_latency_us,
i_device_latency_us, i_stream_latency_us);

return i_latency_us;
}
Expand Down

0 comments on commit a666243

Please sign in to comment.