From de574e99e3b4da10964a1ecce2aa152a17bfca8a Mon Sep 17 00:00:00 2001 From: John Bradley Date: Thu, 12 Mar 2015 14:55:51 -0500 Subject: [PATCH] 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. --- deps/libff/libff/ff-timer.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/deps/libff/libff/ff-timer.c b/deps/libff/libff/ff-timer.c index 5fd9d663c..804657102 100644 --- a/deps/libff/libff/ff-timer.c +++ b/deps/libff/libff/ff-timer.c @@ -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