[vlc-devel] [PATCH 09/10] vlc_tick: add msftime_t to express 100ns time

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


On Fri, Jun 22, 2018 at 02:53:26PM +0200, Steve Lhomme wrote:
> Such values currently have a better resolution than vlc_tick_t
> Also provide conversion macros/functions to/from vlc_tick_t
> ---
>  include/vlc_tick.h | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/include/vlc_tick.h b/include/vlc_tick.h
> index 9e7f909e149..6953ba346d4 100644
> --- a/include/vlc_tick.h
> +++ b/include/vlc_tick.h
> @@ -138,6 +138,24 @@ static inline int64_t ns_from_vlc_tick(vlc_tick_t vtk)
>      return vtk * INT64_C(1000000000) / CLOCK_FREQ;
>  }
>  
> +/**
> + * Typically Microsoft time with 100ns resolutions
> + */
> +typedef int64_t msftime_t;
> +#define MSFTIME_FROM_VLC_TICK(vtk)  ((msftime_t)((vtk) * (INT64_C(10000000) / CLOCK_FREQ)))
> +#define VLC_TICK_FROM_MSFTIME(msft) ((vlc_tick_t)((msft) / (INT64_C(10000000) / CLOCK_FREQ)))
> +#define MSFTIME_FROM_SEC(sec)       ((msftime_t)((sec) * INT64_C(10000000)))  /* seconds in msftime_t */
> +
> +static inline vlc_tick_t vlc_tick_from_msftime(msftime_t t)
> +{
> +    return t * CLOCK_FREQ / INT64_C(10000000);

The order of operations is not the same as in the macro, so in theory
the results (in extreme cases) might be different.

If 10000000 is a multiple of CLOCK_FREQ, the macro implementation is
always better (less overflows). In practice, this is probably not
important.

> +}
> +
> +static inline msftime_t msftime_from_vlc_tick(vlc_tick_t vtk)
> +{
> +    return vtk * INT64_C(10000000) / CLOCK_FREQ;
> +}
> +
>  /*****************************************************************************
>   * 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