From 3e39b3a4afcdc1b2a87c9202e6d7ddf49db09cc9 Mon Sep 17 00:00:00 2001 From: Thomas Guillem Date: Fri, 2 Dec 2022 15:31:06 +0100 Subject: [PATCH] auhal: move latency retrieval in a new function --- modules/audio_output/auhal.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/modules/audio_output/auhal.c b/modules/audio_output/auhal.c index 27662e84d3f2..db0b66590465 100644 --- a/modules/audio_output/auhal.c +++ b/modules/audio_output/auhal.c @@ -1476,6 +1476,25 @@ Stop(audio_output_t *p_aout) kAudioObjectPropertyScopeGlobal); } +static vlc_tick_t +GetLatency(audio_output_t *p_aout, const audio_sample_format_t *fmt) +{ + aout_sys_t *p_sys = p_aout->sys; + + /* get device latency */ + UInt32 i_latency_samples; + vlc_tick_t i_latency_us = 0; + int ret = AO_GET1PROP(p_sys->i_selected_dev, UInt32, &i_latency_samples, + kAudioDevicePropertyLatency, + kAudioObjectPropertyScopeOutput); + if (ret == VLC_SUCCESS) + i_latency_us += vlc_tick_from_samples(i_latency_samples, fmt->i_rate); + + msg_Dbg(p_aout, "Current device has a latency of %lld us", i_latency_us); + + return i_latency_us; +} + static int Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt) { @@ -1574,16 +1593,7 @@ Start(audio_output_t *p_aout, audio_sample_format_t *restrict fmt) kAudioDevicePropertyDeviceIsAlive, kAudioObjectPropertyScopeGlobal); - /* get device latency */ - UInt32 i_latency_samples; - vlc_tick_t i_latency_us = 0; - int ret = AO_GET1PROP(p_sys->i_selected_dev, UInt32, &i_latency_samples, - kAudioDevicePropertyLatency, - kAudioObjectPropertyScopeOutput); - if (ret == VLC_SUCCESS) - i_latency_us += vlc_tick_from_samples(i_latency_samples, fmt->i_rate); - - msg_Dbg(p_aout, "Current device has a latency of %lld us", i_latency_us); + vlc_tick_t i_latency_us = GetLatency(p_aout, fmt); /* Check for Digital mode or Analog output mode */ if (do_spdif)