[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:33:26 CEST 2018
On Fri, Jun 22, 2018 at 03:29:23PM +0200, Steve Lhomme wrote:
>
>
> On 2018-06-22 3:27 PM, Romain Vimont wrote:
> > 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
>
> You mean INT64_C(1000000000) / CLOCK_FREQ or vtk / CLOCK_FREQ ? (I suppose
> the former)
Yes:
return vtk * (INT64_C(1000000000) / CLOCK_FREQ);
(assuming 1000000000 multiple of CLOCK_FREQ)
> > 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
> > _______________________________________________
> > vlc-devel mailing list
> > To unsubscribe or modify your subscription options:
> > https://mailman.videolan.org/listinfo/vlc-devel
>
> _______________________________________________
> 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