[vlc-devel] [PATCH 04/10] vlc_tick: add helper function for explicit nanosecond to/from vlc_tick_t conversion

Romain Vimont rom1v at videolabs.io
Fri Jun 22 15:27:27 CEST 2018


On Fri, Jun 22, 2018 at 02:53:21PM +0200, Steve Lhomme wrote:
> ---
>  include/vlc_tick.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/include/vlc_tick.h b/include/vlc_tick.h
> index 66cf8ecf687..bf037087510 100644
> --- a/include/vlc_tick.h
> +++ b/include/vlc_tick.h
> @@ -73,6 +73,16 @@ static inline int64_t ms_from_vlc_tick(vlc_tick_t vtk)
>      return vtk / (CLOCK_FREQ / 1000);
>  }
>  
> +static inline vlc_tick_t vlc_tick_from_ns(int64_t nano)
> +{
> +    return nano / (INT64_C(1000000000) / CLOCK_FREQ);
> +}
> +
> +static inline int64_t ns_from_vlc_tick(vlc_tick_t vtk)
> +{
> +    return vtk * INT64_C(1000000000) / CLOCK_FREQ;

Should compute division first, to avoid overflow (UB) if vtk > 2^64/10^9
ticks, which is about 5 hours.

> +}
> +
>  /*****************************************************************************
>   * MSTRTIME_MAX_SIZE: maximum possible size of mstrtime
>   *****************************************************************************
> -- 
> 2.17.0
> 
> _______________________________________________
> 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