Commit 532b014a authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

mtime: Avoid overflow when using mach_absolute_time().

Switch to double, do the operations and then convert back.
This fixes the iPad video freezes.
parent 0381d383
...@@ -214,13 +214,13 @@ mtime_t mdate( void ) ...@@ -214,13 +214,13 @@ mtime_t mdate( void )
#elif defined( USE_APPLE_MACH ) #elif defined( USE_APPLE_MACH )
pthread_once(&mtime_timebase_info_once, mtime_init_timebase); pthread_once(&mtime_timebase_info_once, mtime_init_timebase);
uint64_t date = mach_absolute_time(); uint64_t date = mach_absolute_time();
mach_timebase_info_data_t tb = mtime_timebase_info;
/* Convert to nanoseconds */ /* Get the ssystem dependent factor. Switch to double to prevent overflow */
date *= mtime_timebase_info.numer; double factor = (double) tb.numer / (double) tb.denom;
date /= mtime_timebase_info.denom;
/* Convert to microseconds */ /* Convert to microseconds */
res = date / 1000; double d = (double) date * factor / 1000;
res = d;
#elif defined( WIN32 ) || defined( UNDER_CE ) #elif defined( WIN32 ) || defined( UNDER_CE )
/* We don't need the real date, just the value of a high precision timer */ /* We don't need the real date, just the value of a high precision timer */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment