[vlc-devel] [PATCH] coreaudio: fix calculation when the clock sources are different

Marvin Scholz epirat07 at gmail.com
Mon Mar 30 14:46:16 CEST 2020


LGTM

Currently vlc_tick is sourced from the mach_time, which causes incorrect
behavior as wait.c assumes it is sourced from the monotonic time of
clock_gettime, which does not match the mach time (mach time does not
tick while the system sleeps, monotonic time does).

So this will change soon with my patchset to use posix thread code for
Darwin too.

On 30 Mar 2020, at 14:40, Thomas Guillem wrote:

> As MONOTONIC is defined by POSIX to be the one that ticks during sleep 
> while
> mach absolute time does not.
>
> For now (and for 3.0) vlc_tick_now() has the same source than the mach 
> one.
> ---
>  modules/audio_output/coreaudio_common.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/modules/audio_output/coreaudio_common.c 
> b/modules/audio_output/coreaudio_common.c
> index 900616a8aa..5f8a633bee 100644
> --- a/modules/audio_output/coreaudio_common.c
> +++ b/modules/audio_output/coreaudio_common.c
> @@ -243,9 +243,10 @@ ca_TimeGet(audio_output_t *p_aout, vlc_tick_t 
> *delay)
>          return -1;
>      }
>
> -    const vlc_tick_t i_render_time_us =
> -        HostTimeToTick(p_sys, p_sys->i_render_host_time);
> -    const vlc_tick_t i_render_delay = i_render_time_us - 
> vlc_tick_now();
> +    uint64_t i_render_delay_host_time = p_sys->i_render_host_time
> +                                      - mach_absolute_time();
> +    const vlc_tick_t i_render_delay =
> +        HostTimeToTick(p_sys, i_render_delay_host_time);
>
>      *delay = ca_GetLatencyLocked(p_aout) + i_render_delay;
>      lock_unlock(p_sys);
> @@ -307,9 +308,14 @@ ca_Play(audio_output_t * p_aout, block_t * 
> p_block, vlc_tick_t date)
>           * first (non-silence/zero) frame is rendered by the render 
> callback.
>           * Once the rendering is truly started, the date can be 
> ignored. */
>
> -        const vlc_tick_t first_render_time = date - 
> ca_GetLatencyLocked(p_aout);
> -        p_sys->i_first_render_host_time =
> -            TickToHostTime(p_sys, first_render_time);
> +        /* We can't convert date to host time directly since the 
> clock source
> +         * may be different (MONOTONIC vs continue during sleep). The 
> solution
> +         * is to convert it to a relative time and then add it to
> +         * mach_absolute_time() */
> +        const vlc_tick_t first_render_delay = date - vlc_tick_now()
> +                                            - 
> ca_GetLatencyLocked(p_aout);
> +        p_sys->i_first_render_host_time
> +            = mach_absolute_time() + TickToHostTime(p_sys, 
> first_render_delay);
>      }
>
>      do
> -- 
> 2.20.1
>
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list