[vlc-devel] [PATCH 03/15] vlc_common: add helper functions to convert (milli)seconds to/from mtime_t

Steve Lhomme robux4 at ycbcr.xyz
Sat Jun 16 10:03:57 CEST 2018


On 2018-06-16 9:32 AM, Steve Lhomme wrote:
>
>
> On 2018-06-15 7:35 PM, Romain Vimont wrote:
>> On Fri, Jun 15, 2018 at 05:09:14PM +0200, Steve Lhomme wrote:
>>> ---
>>>   include/vlc_common.h | 21 +++++++++++++++++++++
>>>   1 file changed, 21 insertions(+)
>>>
>>> diff --git a/include/vlc_common.h b/include/vlc_common.h
>>> index 3d17d8e6a63..d4186883df6 100644
>>> --- a/include/vlc_common.h
>>> +++ b/include/vlc_common.h
>>> @@ -294,6 +294,27 @@ typedef int64_t mtime_t;
>>>   #define SEC_FROM_VTICK(mt)  ((mt) / CLOCK_FREQ)      /* mtime_t in 
>>> seconds */
>>>   #define VTICK_FROM_SEC(sec) ((mtime_t)((sec) * CLOCK_FREQ)) /* 
>>> seconds in mtime_t */
>>>   +static inline mtime_t vtick_from_sec(int64_t sec)
>>> +{
>>> +    return sec * CLOCK_FREQ;
>>> +}
>>> +
>>> +static inline int64_t sec_from_vtick(mtime_t mt)
>>> +{
>>> +    return mt / CLOCK_FREQ;
>>> +}
>>> +
>>> +static inline mtime_t vtick_from_milli(int64_t ms)
>>> +{
>>> +    /* TODO refine if CLOCK_FREQ is not a multiple of 1000 */
>>> +    return ms * (CLOCK_FREQ / 1000);
>>> +}
>>> +
>>> +static inline int64_t milli_from_vtick(mtime_t mt)
>>> +{
>>> +    /* TODO refine if CLOCK_FREQ is not a multiple of 1000 */
>>> +    return mt / (CLOCK_FREQ / 1000);
>>> +}
>> Just for info, why static inline functions in addition to macros?
>
> That's for variables (ie not hardcoded values) so the parameter is 
> only evaluated once. It may also be tweaked to handle overflow (at 
> least cap the values as it's done in some places). Or do extra 
> processing like rounding to the upper value. Some places use llround 
> but it requires math.h, not sure we want that in common.h
>
> It might be good to create a vlc_tick.h so the vlc_tick_t is not in 
> vlc_common anymore and possibly export some of the functions in 
> libvlccore for the ones we don't want to expose for all file in a header.

We may want to put static_assert in there too, I don't know if that's 
overkill in a header.

One of the goals of having a more flexible CLOCK_FREQ is that we can 
seek to frame precision in any format. Right now it's not possible with 
all formats. Going nanoseconds may be overkill for the player but it may 
be good for purpose built libvlc apps. Same thing with 100ns based 
formats. We'd need to expose this in in libvlc though. Right now 
libvlc_time_t is in milliseconds.

>
>>
>>>     /**
>>>    * The vlc_fourcc_t type.
>>> -- 
>>> 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