Commit 5a005c66 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont Committed by Derk-Jan Hartman

Forwardport 5ead92ffd58088828ed802173d963b2571f0cd69

mtime: Use mach_absolute_time on Mac OS X instead of gettimeofday.

mach_absolute_time() is a monotic clock, whereas gettimeofday() is not. For that reason setting your computer time while playing a movie won't halt playback anymore.

Seems to fix the dropped frame issue on Mac OS X.
Signed-off-by: default avatarDerk-Jan Hartman <hartman@videolan.org>
parent 4a49ce09
......@@ -56,6 +56,11 @@
# include <sys/time.h>
#endif
#ifdef __APPLE__
# include <mach/mach.h>
# include <mach/mach_time.h>
#endif
#if !defined(HAVE_STRUCT_TIMESPEC)
struct timespec
{
......@@ -168,6 +173,15 @@ static inline unsigned mprec( void )
#endif
}
#ifdef __APPLE__
static mach_timebase_info_data_t mtime_timebase_info;
static pthread_once_t mtime_timebase_info_once = PTHREAD_ONCE_INIT;
static void mtime_init_timebase(void)
{
mach_timebase_info(&mtime_timebase_info);
}
#endif
/**
* Return high precision date
*
......@@ -193,6 +207,16 @@ mtime_t mdate( void )
#elif defined( HAVE_KERNEL_OS_H )
res = real_time_clock_usecs();
#elif defined( __APPLE__ )
pthread_once(&mtime_timebase_info_once, mtime_init_timebase);
uint64_t date = mach_absolute_time();
/* Convert to nanoseconds */
date *= mtime_timebase_info.numer;
date /= mtime_timebase_info.denom;
/* Convert to microseconds */
res = date / 1000;
#elif defined( WIN32 ) || defined( UNDER_CE )
/* We don't need the real date, just the value of a high precision timer */
static mtime_t freq = INT64_C(-1);
......@@ -299,6 +323,11 @@ mtime_t mdate( void )
i_previous_time = res;
LeaveCriticalSection( &date_lock );
}
#elif defined( __APPLE__ ) /* The version that should be used, if it was cancelable */
pthread_once(&mtime_timebase_info_once, mtime_init_timebase);
uint64_t mach_time = date * 1000 * mtime_timebase_info.denom / mtime_timebase_info.numer;
mach_wait_until(mach_time);
#else
struct timeval tv_date;
......@@ -395,6 +424,11 @@ void msleep( mtime_t delay )
while( nanosleep( &ts_delay, &ts_delay ) && ( errno == EINTR ) );
#elif defined( __APPLE__ ) /* The version that should be used, if it was cancelable */
pthread_once(&mtime_timebase_info_once, mtime_init_timebase);
uint64_t mach_time = delay * 1000 * mtime_timebase_info.denom / mtime_timebase_info.numer;
mach_wait_until(mach_time + mach_absolute_time());
#else
struct timeval tv_delay;
......
......@@ -52,6 +52,10 @@ static vlc_threadvar_t cancel_key;
# include <execinfo.h>
#endif
#ifdef __APPLE__
# include <sys/time.h> /* gettimeofday in vlc_cond_timedwait */
#endif
/**
* Print a backtrace to the standard error for debugging purpose.
*/
......@@ -556,6 +560,16 @@ int vlc_cond_timedwait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex,
mtime_t deadline)
{
#if defined(LIBVLC_USE_PTHREAD)
#ifdef __APPLE__
/* mdate() is mac_absolute_time on osx, which we must convert to do
* the same base than gettimeofday() on which pthread_cond_timedwait
* counts on. */
mtime_t oldbase = mdate();
struct timeval tv;
gettimeofday(&tv, NULL);
mtime_t newbase = (mtime_t)tv.tv_sec * 1000000 + (mtime_t) tv.tv_usec;
deadline = deadline - oldbase + newbase;
#endif
lldiv_t d = lldiv( deadline, CLOCK_FREQ );
struct timespec ts = { d.quot, d.rem * (1000000000 / CLOCK_FREQ) };
......
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