[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 09:32:56 CEST 2018



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.

>
>>   
>>   /**
>>    * 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



More information about the vlc-devel mailing list