Skip to content

Commit

Permalink
auhal: add kAudioDevicePropertySafetyOffset to the latency
Browse files Browse the repository at this point in the history
  • Loading branch information
tguillem authored and jbkempf committed Dec 2, 2022
1 parent a666243 commit 9020106
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions modules/audio_output/auhal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,8 @@ 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, i_stream_latency_us = 0;
vlc_tick_t i_latency_us, i_device_latency_us = 0, i_device_offset_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,6 +1493,15 @@ GetLatency(audio_output_t *p_aout, const audio_sample_format_t *fmt)
else
msg_Warn(p_aout, "failed to get kAudioDevicePropertyLatency");

/* Get device safety offset */
ret = AO_GET1PROP(p_sys->i_selected_dev, UInt32, &i_latency_samples,
kAudioDevicePropertySafetyOffset,
kAudioObjectPropertyScopeOutput);
if (ret == VLC_SUCCESS)
i_device_offset_us = vlc_tick_from_samples(i_latency_samples, fmt->i_rate);
else
msg_Warn(p_aout, "failed to get kAudioDevicePropertySafetyOffset");

AudioStreamID sid;
/* Get stream latency */
ret = AO_GET1PROP(p_sys->i_selected_dev, AudioStreamID, &sid,
Expand All @@ -1509,11 +1519,11 @@ GetLatency(audio_output_t *p_aout, const audio_sample_format_t *fmt)
else
msg_Warn(p_aout, "failed to get kAudioDevicePropertyStreams");

i_latency_us = i_device_latency_us + i_stream_latency_us;
i_latency_us = i_device_latency_us + i_device_offset_us + i_stream_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);
"(device: %" PRId64 " us, offset: %" PRId64 " us, stream: %" PRId64 " us)", i_latency_us,
i_device_latency_us, i_device_offset_us, i_stream_latency_us);

return i_latency_us;
}
Expand Down

0 comments on commit 9020106

Please sign in to comment.