deps-libff: Fix bug where rel time was used instead of abs

The bug was undetected because it accidentally fell into an error case that slept the correct amount of time.  pthread_cond_timedwait takes an absolute time in the future to wait until.  The value we were passing was always in the past so it was immediately failing with a TIMEDOUT error code.
master
John Bradley 2015-03-12 14:55:51 -05:00
parent 2b3d82aeac
commit de574e99e3
1 changed files with 7 additions and 9 deletions

View File

@ -36,20 +36,18 @@ static void *timer_thread(void *opaque)
uint64_t current_time = av_gettime();
if (current_time < timer->next_wake) {
int64_t sleep_time_us = timer->next_wake - current_time;
struct timespec sleep_time;
sleep_time.tv_sec =
(long)sleep_time_us / AV_TIME_BASE;
sleep_time.tv_nsec =
(long)(sleep_time_us % AV_TIME_BASE)
* 1000;
struct timespec sleep_time = {
.tv_sec = timer->next_wake / AV_TIME_BASE,
.tv_nsec = (timer->next_wake % AV_TIME_BASE)
* 1000
};
ret = pthread_cond_timedwait(&timer->cond,
&timer->mutex, &sleep_time);
if (ret != 0) {
// failed to wait, just sleep
av_usleep((unsigned)sleep_time_us);
av_usleep((unsigned)(timer->next_wake
- current_time));
}
// we can be woken up merely to set a sooner wake time